svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / TableRowsOperations.java @ 33379
History | View | Annotate | Download (2.64 KB)
1 |
package org.gvsig.app.extension; |
---|---|
2 |
|
3 |
import org.gvsig.andami.PluginServices; |
4 |
import org.gvsig.andami.messages.NotificationManager; |
5 |
import org.gvsig.andami.plugins.Extension; |
6 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
7 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
10 |
|
11 |
/**
|
12 |
* DOCUMENT ME!
|
13 |
*
|
14 |
* @author Vicente Caballero Navarro
|
15 |
* @author gvSIG team
|
16 |
*/
|
17 |
public class TableRowsOperations extends Extension { |
18 |
|
19 |
/**
|
20 |
* DOCUMENT ME!
|
21 |
*/
|
22 |
public void initialize() { |
23 |
registerIcons(); |
24 |
} |
25 |
|
26 |
private void registerIcons(){ |
27 |
PluginServices.getIconTheme().registerDefault( |
28 |
"table-selection-up",
|
29 |
this.getClass().getClassLoader().getResource("images/selectionUp.png") |
30 |
); |
31 |
|
32 |
PluginServices.getIconTheme().registerDefault( |
33 |
"table-invert",
|
34 |
this.getClass().getClassLoader().getResource("images/invertSelection.png") |
35 |
); |
36 |
} |
37 |
|
38 |
/**
|
39 |
* DOCUMENT ME!
|
40 |
*
|
41 |
* @param actionCommand DOCUMENT ME!
|
42 |
*/
|
43 |
public void execute(String actionCommand) { |
44 |
FeatureTableDocumentPanel tableDocument = getTableDocument(); |
45 |
if (actionCommand.compareTo("SELECTIONUP") == 0) { |
46 |
showsSelectedRows(tableDocument); |
47 |
} |
48 |
if (actionCommand.compareTo("INVERTSELECTION") == 0) { |
49 |
invertSelection(tableDocument); |
50 |
} |
51 |
tableDocument.getModel().setModified(true);
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Flip the selection (inverts selection)
|
56 |
* @param table
|
57 |
*/
|
58 |
private void invertSelection(FeatureTableDocumentPanel table) { |
59 |
try {
|
60 |
FeatureStore fs = getTableDocument().getModel().getStore(); |
61 |
fs.getFeatureSelection().reverse(); |
62 |
} catch (DataException e) {
|
63 |
e.printStackTrace(); |
64 |
NotificationManager.addError(e); |
65 |
} |
66 |
} |
67 |
|
68 |
private void showsSelectedRows(FeatureTableDocumentPanel table) { |
69 |
table.setSelectionUp(true);
|
70 |
} |
71 |
|
72 |
/**
|
73 |
* DOCUMENT ME!
|
74 |
*
|
75 |
* @return DOCUMENT ME!
|
76 |
*/
|
77 |
public boolean isEnabled() { |
78 |
FeatureTableDocumentPanel tableDocument = getTableDocument(); |
79 |
|
80 |
if (tableDocument != null) { |
81 |
try {
|
82 |
return !tableDocument.getModel()
|
83 |
.getStore() |
84 |
.getFeatureSelection() |
85 |
.isEmpty(); |
86 |
} catch (DataException e) {
|
87 |
NotificationManager.addError(e); |
88 |
} |
89 |
} |
90 |
|
91 |
return false; |
92 |
} |
93 |
|
94 |
/**
|
95 |
* DOCUMENT ME!
|
96 |
*
|
97 |
* @return DOCUMENT ME!
|
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 |
} |