svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / TableRowsOperations.java @ 36443
History | View | Annotate | Download (3.85 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.app.extension; |
23 |
|
24 |
import org.gvsig.andami.PluginServices; |
25 |
import org.gvsig.andami.messages.NotificationManager; |
26 |
import org.gvsig.andami.plugins.Extension; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
28 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
29 |
import org.gvsig.fmap.dal.exception.DataException; |
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
31 |
|
32 |
/**
|
33 |
* DOCUMENT ME!
|
34 |
*
|
35 |
* @author Vicente Caballero Navarro
|
36 |
* @author gvSIG team
|
37 |
*/
|
38 |
public class TableRowsOperations extends Extension { |
39 |
|
40 |
/**
|
41 |
* DOCUMENT ME!
|
42 |
*/
|
43 |
public void initialize() { |
44 |
registerIcons(); |
45 |
} |
46 |
|
47 |
private void registerIcons() { |
48 |
PluginServices.getIconTheme().registerDefault( |
49 |
"table-selection-up",
|
50 |
this.getClass().getClassLoader()
|
51 |
.getResource("images/selectionUp.png"));
|
52 |
|
53 |
PluginServices.getIconTheme().registerDefault( |
54 |
"table-invert",
|
55 |
this.getClass().getClassLoader()
|
56 |
.getResource("images/invertSelection.png"));
|
57 |
} |
58 |
|
59 |
/**
|
60 |
* DOCUMENT ME!
|
61 |
*
|
62 |
* @param actionCommand
|
63 |
* DOCUMENT ME!
|
64 |
*/
|
65 |
public void execute(String actionCommand) { |
66 |
FeatureTableDocumentPanel tableDocument = getTableDocument(); |
67 |
if (actionCommand.compareTo("SELECTIONUP") == 0) { |
68 |
showsSelectedRows(tableDocument); |
69 |
} |
70 |
if (actionCommand.compareTo("INVERTSELECTION") == 0) { |
71 |
invertSelection(tableDocument); |
72 |
} |
73 |
tableDocument.getModel().setModified(true);
|
74 |
} |
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 |
private void showsSelectedRows(FeatureTableDocumentPanel table) { |
92 |
table.setSelectionUp(true);
|
93 |
} |
94 |
|
95 |
/**
|
96 |
* DOCUMENT ME!
|
97 |
*
|
98 |
* @return DOCUMENT ME!
|
99 |
*/
|
100 |
public boolean isEnabled() { |
101 |
FeatureTableDocumentPanel tableDocument = getTableDocument(); |
102 |
|
103 |
if (tableDocument != null) { |
104 |
try {
|
105 |
return !tableDocument.getModel().getStore()
|
106 |
.getFeatureSelection().isEmpty(); |
107 |
} catch (DataException e) {
|
108 |
NotificationManager.addError(e); |
109 |
} |
110 |
} |
111 |
|
112 |
return false; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* DOCUMENT ME!
|
117 |
*
|
118 |
* @return DOCUMENT ME!
|
119 |
*/
|
120 |
public boolean isVisible() { |
121 |
return getTableDocument() != null; |
122 |
} |
123 |
|
124 |
private FeatureTableDocumentPanel getTableDocument() {
|
125 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
126 |
if (v != null && v instanceof FeatureTableDocumentPanel) { |
127 |
return (FeatureTableDocumentPanel) v;
|
128 |
} |
129 |
return null; |
130 |
} |
131 |
} |