svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / TableRowsOperations.java @ 41630
History | View | Annotate | Download (4.23 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | *
|
||
6 | 40435 | jjdelcerro | * This program is free software; you can redistribute it and/or
|
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | 40558 | jjdelcerro | *
|
11 | 40435 | jjdelcerro | * This program is distributed in the hope that it will be useful,
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | 40558 | jjdelcerro | *
|
16 | 40435 | jjdelcerro | * You should have received a copy of the GNU General Public License
|
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 40435 | jjdelcerro | * MA 02110-1301, USA.
|
20 | 40558 | jjdelcerro | *
|
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | package org.gvsig.app.extension; |
||
25 | |||
26 | 41013 | jldominguez | import javax.swing.JOptionPane; |
27 | |||
28 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
29 | import org.gvsig.andami.PluginServices; |
||
30 | import org.gvsig.andami.messages.NotificationManager; |
||
31 | import org.gvsig.andami.plugins.Extension; |
||
32 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
33 | 41013 | jldominguez | import org.gvsig.app.ApplicationLocator; |
34 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
35 | import org.gvsig.fmap.dal.exception.DataException; |
||
36 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
37 | 41013 | jldominguez | import org.gvsig.i18n.Messages; |
38 | 40435 | jjdelcerro | |
39 | public class TableRowsOperations extends Extension { |
||
40 | |||
41 | public void initialize() { |
||
42 | registerIcons(); |
||
43 | } |
||
44 | |||
45 | private void registerIcons() { |
||
46 | IconThemeHelper.registerIcon("action", "selection-move-up", this); |
||
47 | 41630 | jjdelcerro | IconThemeHelper.registerIcon("action", "selection-disable-move-up", this); |
48 | 40435 | jjdelcerro | IconThemeHelper.registerIcon("action", "selection-reverse", this); |
49 | } |
||
50 | |||
51 | public void execute(String actionCommand) { |
||
52 | FeatureTableDocumentPanel tableDocument = getTableDocument(); |
||
53 | 41630 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-disable-move-up") ) { |
54 | tableDocument.setSelectionUp(false);
|
||
55 | } |
||
56 | 40435 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-move-up") ) { |
57 | 41630 | jjdelcerro | // if (thereIsSelection(tableDocument)) {
|
58 | tableDocument.setSelectionUp(true);
|
||
59 | 41013 | jldominguez | tableDocument.getModel().setModified(true);
|
60 | 41630 | jjdelcerro | // } else {
|
61 | // JOptionPane.showMessageDialog(
|
||
62 | // ApplicationLocator.getManager().getRootComponent(),
|
||
63 | // Messages.getText("_There_are_no_selected_rows"),
|
||
64 | // Messages.getText("_Move_up_selection"),
|
||
65 | // JOptionPane.INFORMATION_MESSAGE);
|
||
66 | // }
|
||
67 | 41013 | jldominguez | |
68 | 40435 | jjdelcerro | } |
69 | if (actionCommand.equalsIgnoreCase("selection-reverse") ) { |
||
70 | invertSelection(tableDocument); |
||
71 | 41013 | jldominguez | tableDocument.getModel().setModified(true);
|
72 | 40435 | jjdelcerro | } |
73 | 41013 | jldominguez | |
74 | 40435 | jjdelcerro | } |
75 | |||
76 | /**
|
||
77 | * Flip the selection (inverts selection)
|
||
78 | *
|
||
79 | * @param table
|
||
80 | */
|
||
81 | private void invertSelection(FeatureTableDocumentPanel table) { |
||
82 | try {
|
||
83 | FeatureStore fs = getTableDocument().getModel().getStore(); |
||
84 | fs.getFeatureSelection().reverse(); |
||
85 | } catch (DataException e) {
|
||
86 | e.printStackTrace(); |
||
87 | NotificationManager.addError(e); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | 41630 | jjdelcerro | // private void showsSelectedRows(FeatureTableDocumentPanel table) {
|
92 | // table.setSelectionUp(true);
|
||
93 | // }
|
||
94 | 40435 | jjdelcerro | |
95 | public boolean isEnabled() { |
||
96 | 41013 | jldominguez | return getTableDocument() != null; |
97 | 40435 | jjdelcerro | } |
98 | |||
99 | public boolean isVisible() { |
||
100 | return getTableDocument() != null; |
||
101 | } |
||
102 | |||
103 | private FeatureTableDocumentPanel getTableDocument() {
|
||
104 | IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
||
105 | if (v != null && v instanceof FeatureTableDocumentPanel) { |
||
106 | return (FeatureTableDocumentPanel) v;
|
||
107 | } |
||
108 | return null; |
||
109 | } |
||
110 | 41013 | jldominguez | |
111 | private boolean thereIsSelection(FeatureTableDocumentPanel tabledoc) { |
||
112 | |||
113 | if (tabledoc != null) { |
||
114 | try {
|
||
115 | return !tabledoc.getModel().getStore()
|
||
116 | .getFeatureSelection().isEmpty(); |
||
117 | } catch (DataException e) {
|
||
118 | NotificationManager.addError(e); |
||
119 | } |
||
120 | } |
||
121 | return false; |
||
122 | |||
123 | } |
||
124 | 40435 | jjdelcerro | } |