Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / TableRowsOperations.java @ 24759

History | View | Annotate | Download (4.1 KB)

1
package com.iver.cit.gvsig;
2

    
3
import org.gvsig.fmap.dal.exception.DataException;
4
import org.gvsig.fmap.dal.feature.FeatureStore;
5

    
6
import com.iver.andami.PluginServices;
7
import com.iver.andami.messages.NotificationManager;
8
import com.iver.andami.plugins.Extension;
9
import com.iver.andami.ui.mdiManager.IWindow;
10
import com.iver.cit.gvsig.project.documents.table.gui.Table;
11

    
12

    
13
/**
14
 * DOCUMENT ME!
15
 *
16
 * @author Vicente Caballero Navarro
17
 */
18
public class TableRowsOperations extends Extension {
19
    /**
20
     * DOCUMENT ME!
21
     */
22
    public void initialize() {
23
            registerIcons();
24
    }
25

    
26
    private void registerIcons(){
27
            PluginServices.getIconTheme().registerDefault(
28
                                "table-selection-up",
29
                                this.getClass().getClassLoader().getResource("images/selectionUp.png")
30
                        );
31

    
32
            PluginServices.getIconTheme().registerDefault(
33
                                "table-invert",
34
                                this.getClass().getClassLoader().getResource("images/invertSelection.png")
35
                        );
36
    }
37

    
38
    /**
39
     * DOCUMENT ME!
40
     *
41
     * @param actionCommand DOCUMENT ME!
42
     */
43
    public void execute(String actionCommand) {
44
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
45

    
46
        if (v != null) {
47
            if (v.getClass() == Table.class) {
48
                Table table = (Table) v;
49
                if (actionCommand.compareTo("SELECTIONUP") == 0) {
50
                                        showsSelectedRows(table);
51
                                }
52
                if (actionCommand.compareTo("INVERTSELECTION") == 0) {
53
                                        invertSelection(table);
54
                                }
55
                table.getModel().setModified(true);
56
            }
57
        }
58
    }
59

    
60
    /**
61
     * Flip the selection (inverts selection)
62
     * @param table
63
     */
64
    private void invertSelection(Table table) {
65
            try {
66
                    FeatureStore fs = table.getModel().getModel();
67
                    fs.getFeatureSelection().reverse();
68
            } catch (DataException e) {
69
                        e.printStackTrace();
70
                        NotificationManager.addError(e);
71
                }
72
    }
73

    
74
        private void showsSelectedRows(Table table) {
75
//            long[] mapping=null;
76
//                try {
77
//                        FeatureStore fs=table.getModel().getModel();
78
//                        mapping = new long[fs.getDataCollection().size()];
79
//
80
//                FeatureCollection selectedRows=(FeatureCollection)fs.getSelection();
81
//
82
//
83
//                int m=0;
84
//                for (int i = selectedRows.nextSetBit(0); i >= 0;
85
//                 i = selectedRows.nextSetBit(i + 1)) {
86
//                        mapping[m]=i;
87
//                        m++;
88
//                }
89
//                for (int i = 0; i < mapping.length;
90
//                     i++) {
91
//                        if (!selectedRows.get(i)) {
92
//                                mapping[m]=i;
93
//                                m++;
94
//                        }
95
//                }
96
                table.setOrder("SELECTEDUP");
97
//                } catch (ReadException e) {
98
//                        e.printStackTrace();
99
//                }
100

    
101
        }
102
    /**
103
     * DOCUMENT ME!
104
     *
105
     * @return DOCUMENT ME!
106
     */
107
    public boolean isEnabled() {
108
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
109

    
110
        if (v == null) {
111
            return false;
112
        }
113

    
114
        if (v.getClass() == Table.class) {
115
            Table table = (Table) v;
116

    
117
            try {
118
                                return !table.getModel().getModel().getFeatureSelection().isEmpty();
119
                        } catch (DataException e) {
120
                                NotificationManager.addError(e);
121
                        }
122
        }
123

    
124
        return false;
125
    }
126

    
127
//    protected boolean doIsEnabled(Table table) {
128
//                try {
129
//                        BitSet indices = table.getSelectedFieldIndices();
130
//
131
//                        System.out.println("TableNumericFieldOperations.isEnabled: Tabla: "
132
//                                        + table.getModel().getModelo().getName());
133
//
134
//                        if (indices.cardinality() == 1) {
135
//                                int type = table.getModel().getModelo().getRecordset()
136
//                                                .getFieldType(indices.nextSetBit(0));
137
//                                if ((type == Types.BIGINT) || (type == Types.DECIMAL)
138
//                                                || (type == Types.DOUBLE) || (type == Types.FLOAT)
139
//                                                || (type == Types.INTEGER) || (type == Types.SMALLINT)
140
//                                                || (type == Types.TINYINT) || (type == Types.REAL)
141
//                                                || (type == Types.NUMERIC)) {
142
//                                        return true;
143
//                                }
144
//
145
//                        }
146
//                } catch (ReadException e) {
147
//                        e.printStackTrace();
148
//                }
149
//
150
//                return false;
151
//        }
152

    
153
    /**
154
         * DOCUMENT ME!
155
         *
156
         * @return DOCUMENT ME!
157
         */
158
    public boolean isVisible() {
159
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
160

    
161
        if (v == null) {
162
            return false;
163
        }
164

    
165
        if (v instanceof Table) {
166
            return true;
167
        }
168

    
169
        return false;
170
    }
171
}