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