root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableRowsOperations.java @ 22932
History | View | Annotate | Download (4.62 KB)
1 |
package com.iver.cit.gvsig; |
---|---|
2 |
|
3 |
import java.sql.Types; |
4 |
import java.util.BitSet; |
5 |
import java.util.Iterator; |
6 |
|
7 |
import org.gvsig.fmap.data.DataException; |
8 |
import org.gvsig.fmap.data.ReadException; |
9 |
import org.gvsig.fmap.data.feature.Feature; |
10 |
import org.gvsig.fmap.data.feature.FeatureCollection; |
11 |
import org.gvsig.fmap.data.feature.FeatureStore; |
12 |
import org.gvsig.fmap.data.feature.MemoryFeatureCollection; |
13 |
import org.gvsig.fmap.mapcontext.layers.FBitSet; |
14 |
|
15 |
import com.iver.andami.PluginServices; |
16 |
import com.iver.andami.messages.NotificationManager; |
17 |
import com.iver.andami.plugins.Extension; |
18 |
import com.iver.andami.ui.mdiManager.IWindow; |
19 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
20 |
|
21 |
|
22 |
/**
|
23 |
* DOCUMENT ME!
|
24 |
*
|
25 |
* @author Vicente Caballero Navarro
|
26 |
*/
|
27 |
public class TableRowsOperations extends Extension { |
28 |
/**
|
29 |
* DOCUMENT ME!
|
30 |
*/
|
31 |
public void initialize() { |
32 |
registerIcons(); |
33 |
} |
34 |
|
35 |
private void registerIcons(){ |
36 |
PluginServices.getIconTheme().registerDefault( |
37 |
"table-selection-up",
|
38 |
this.getClass().getClassLoader().getResource("images/selectionUp.png") |
39 |
); |
40 |
|
41 |
PluginServices.getIconTheme().registerDefault( |
42 |
"table-invert",
|
43 |
this.getClass().getClassLoader().getResource("images/invertSelection.png") |
44 |
); |
45 |
} |
46 |
|
47 |
/**
|
48 |
* DOCUMENT ME!
|
49 |
*
|
50 |
* @param actionCommand DOCUMENT ME!
|
51 |
*/
|
52 |
public void execute(String actionCommand) { |
53 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
54 |
|
55 |
if (v != null) { |
56 |
if (v.getClass() == Table.class) {
|
57 |
Table table = (Table) v; |
58 |
if (actionCommand.compareTo("SELECTIONUP") == 0) |
59 |
showsSelectedRows(table); |
60 |
if (actionCommand.compareTo("INVERTSELECTION") == 0) |
61 |
invertSelection(table); |
62 |
table.getModel().setModified(true);
|
63 |
} |
64 |
} |
65 |
} |
66 |
|
67 |
/**
|
68 |
* Flip the selection (inverts selection)
|
69 |
* @param table
|
70 |
*/
|
71 |
private void invertSelection(Table table) { |
72 |
try {
|
73 |
FeatureStore fs = table.getModel().getModel(); |
74 |
FeatureCollection selection=(FeatureCollection)fs.getSelection(); |
75 |
FeatureCollection fCollection=(FeatureCollection)fs.getDataCollection(); |
76 |
fCollection.removeAll(selection); |
77 |
fs.setSelection(fCollection); |
78 |
} catch (ReadException e) {
|
79 |
e.printStackTrace(); |
80 |
NotificationManager.addError(e); |
81 |
} catch (DataException e) {
|
82 |
e.printStackTrace(); |
83 |
NotificationManager.addError(e); |
84 |
} |
85 |
} |
86 |
|
87 |
private void showsSelectedRows(Table table) { |
88 |
long[] mapping=null; |
89 |
try {
|
90 |
FeatureStore fs=table.getModel().getModel(); |
91 |
mapping = new long[fs.getDataCollection().size()]; |
92 |
|
93 |
FeatureCollection selectedRows=(FeatureCollection)fs.getSelection(); |
94 |
|
95 |
int m=0; |
96 |
for (int i = selectedRows.nextSetBit(0); i >= 0; |
97 |
i = selectedRows.nextSetBit(i + 1)) {
|
98 |
mapping[m]=i; |
99 |
m++; |
100 |
} |
101 |
for (int i = 0; i < mapping.length; |
102 |
i++) { |
103 |
if (!selectedRows.get(i)) {
|
104 |
mapping[m]=i; |
105 |
m++; |
106 |
} |
107 |
} |
108 |
table.setOrder(mapping); |
109 |
} catch (ReadException e) {
|
110 |
e.printStackTrace(); |
111 |
} |
112 |
|
113 |
} |
114 |
/**
|
115 |
* DOCUMENT ME!
|
116 |
*
|
117 |
* @return DOCUMENT ME!
|
118 |
*/
|
119 |
public boolean isEnabled() { |
120 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
121 |
|
122 |
if (v == null) { |
123 |
return false; |
124 |
} |
125 |
|
126 |
if (v.getClass() == Table.class) {
|
127 |
Table table = (Table) v; |
128 |
|
129 |
// try {
|
130 |
return !table.getModel().getModel().getSelection().isEmpty();
|
131 |
// } catch (ReadException e) {
|
132 |
// e.printStackTrace();
|
133 |
// }
|
134 |
} |
135 |
|
136 |
return false; |
137 |
} |
138 |
|
139 |
// protected boolean doIsEnabled(Table table) {
|
140 |
// try {
|
141 |
// BitSet indices = table.getSelectedFieldIndices();
|
142 |
//
|
143 |
// System.out.println("TableNumericFieldOperations.isEnabled: Tabla: "
|
144 |
// + table.getModel().getModelo().getName());
|
145 |
//
|
146 |
// if (indices.cardinality() == 1) {
|
147 |
// int type = table.getModel().getModelo().getRecordset()
|
148 |
// .getFieldType(indices.nextSetBit(0));
|
149 |
// if ((type == Types.BIGINT) || (type == Types.DECIMAL)
|
150 |
// || (type == Types.DOUBLE) || (type == Types.FLOAT)
|
151 |
// || (type == Types.INTEGER) || (type == Types.SMALLINT)
|
152 |
// || (type == Types.TINYINT) || (type == Types.REAL)
|
153 |
// || (type == Types.NUMERIC)) {
|
154 |
// return true;
|
155 |
// }
|
156 |
//
|
157 |
// }
|
158 |
// } catch (ReadException e) {
|
159 |
// e.printStackTrace();
|
160 |
// }
|
161 |
//
|
162 |
// return false;
|
163 |
// }
|
164 |
|
165 |
/**
|
166 |
* DOCUMENT ME!
|
167 |
*
|
168 |
* @return DOCUMENT ME!
|
169 |
*/
|
170 |
public boolean isVisible() { |
171 |
IWindow v = PluginServices.getMDIManager().getActiveWindow(); |
172 |
|
173 |
if (v == null) { |
174 |
return false; |
175 |
} |
176 |
|
177 |
if (v instanceof Table) { |
178 |
return true; |
179 |
} |
180 |
|
181 |
return false; |
182 |
} |
183 |
} |