Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / TableRowsOperations.java @ 6238

History | View | Annotate | Download (3.85 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.View;
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.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
        View v = PluginServices.getMDIManager().getActiveView();
46

    
47
        if (v != null) {
48
            if (v.getClass() == Table.class) {
49
                Table table = (Table) v;
50

    
51
                showsSelectedRows(table);
52
            }
53
        }
54
    }
55

    
56
    private void showsSelectedRows(Table table) {
57
            long[] mapping=null;
58
                try {
59
                        mapping = new long[table.getModel().getModelo().getRowCount()];
60

    
61
                FBitSet selectedRows=table.getModel().getModelo().getSelection();
62
                int m=0;
63
                for (int i = selectedRows.nextSetBit(0); i >= 0;
64
                 i = selectedRows.nextSetBit(i + 1)) {
65
                        mapping[m]=i;
66
                        m++;
67
                }
68
                for (int i = 0; i < mapping.length;
69
                     i++) {
70
                        if (!selectedRows.get(i)) {
71
                                mapping[m]=i;
72
                                m++;
73
                        }
74
                }
75
                table.setOrder(mapping);
76
                } catch (DriverIOException e) {
77
                        e.printStackTrace();
78
                } catch (IOException e) {
79
                        e.printStackTrace();
80
                }
81

    
82
        }
83
    /**
84
     * DOCUMENT ME!
85
     *
86
     * @return DOCUMENT ME!
87
     */
88
    public boolean isEnabled() {
89
        View v = PluginServices.getMDIManager().getActiveView();
90

    
91
        if (v == null) {
92
            return false;
93
        }
94

    
95
        if (v.getClass() == Table.class) {
96
            Table table = (Table) v;
97

    
98
            return table.getModel().getModelo().getSelection().cardinality()>0;
99
        }
100

    
101
        return false;
102
    }
103

    
104
    protected boolean doIsEnabled(Table table) {
105
        try {
106
            BitSet indices = table.getSelectedFieldIndices();
107

    
108
            System.out.println("TableNumericFieldOperations.isEnabled: Tabla: " +
109
                table.getModel().getModelo().getRecordset().getName());
110

    
111
            if (indices.cardinality() == 1) {
112
                try {
113
                    int type = table.getModel().getModelo().getRecordset()
114
                                    .getFieldType(indices.nextSetBit(0));
115

    
116
                    if ((type == Types.BIGINT) || (type == Types.DECIMAL) ||
117
                            (type == Types.DOUBLE) || (type == Types.FLOAT) ||
118
                            (type == Types.INTEGER) ||
119
                            (type == Types.SMALLINT) ||
120
                            (type == Types.TINYINT) || (type == Types.REAL) ||
121
                            (type == Types.NUMERIC)) {
122
                        return true;
123
                    }
124
                } catch (DriverException e) {
125
                    return false;
126
                }
127
            }
128
        } catch (DriverLoadException e1) {
129
            // TODO Auto-generated catch block
130
            e1.printStackTrace();
131
        }
132

    
133
        return false;
134
    }
135

    
136
    /**
137
     * DOCUMENT ME!
138
     *
139
     * @return DOCUMENT ME!
140
     */
141
    public boolean isVisible() {
142
        View v = PluginServices.getMDIManager().getActiveView();
143

    
144
        if (v == null) {
145
            return false;
146
        }
147

    
148
        if (v instanceof Table) {
149
            return true;
150
        }
151

    
152
        return false;
153
    }
154
}