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