Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / TableRowsOperations.java @ 8745

History | View | Annotate | Download (4.47 KB)

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