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