Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / TableRowsOperations.java @ 29596

History | View | Annotate | Download (3.75 KB)

1
package org.gvsig.app.extension;
2

    
3
import org.gvsig.andami.PluginServices;
4
import org.gvsig.andami.messages.NotificationManager;
5
import org.gvsig.andami.plugins.Extension;
6
import org.gvsig.andami.ui.mdiManager.IWindow;
7
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
8
import org.gvsig.fmap.dal.exception.DataException;
9
import org.gvsig.fmap.dal.feature.FeatureStore;
10

    
11

    
12

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

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

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

    
39
    /**
40
     * DOCUMENT ME!
41
     *
42
     * @param actionCommand DOCUMENT ME!
43
     */
44
    public void execute(String actionCommand) {
45
            if (actionCommand.compareTo("SELECTIONUP") == 0) {
46
                    showsSelectedRows(table);
47
            }
48
            if (actionCommand.compareTo("INVERTSELECTION") == 0) {
49
                    invertSelection(table);
50
            }
51
            table.getModel().setModified(true);
52
    }
53

    
54
    /**
55
     * Flip the selection (inverts selection)
56
     * @param table
57
     */
58
    private void invertSelection(FeatureTableDocumentPanel table) {
59
            try {
60
                    FeatureStore fs = table.getModel().getStore();
61
                    fs.getFeatureSelection().reverse();
62
            } catch (DataException e) {
63
                        e.printStackTrace();
64
                        NotificationManager.addError(e);
65
                }
66
    }
67

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

    
96
        }
97
    /**
98
     * DOCUMENT ME!
99
     *
100
     * @return DOCUMENT ME!
101
     */
102
        public boolean isEnabled() {
103
                try {
104
                        return !table.getModel().getStore().getFeatureSelection().isEmpty();
105
                } catch (DataException e) {
106
                        NotificationManager.addError(e);
107
                }
108

    
109
                return false;
110
        }
111

    
112
//    protected boolean doIsEnabled(Table table) {
113
//                try {
114
//                        BitSet indices = table.getSelectedFieldIndices();
115
//
116
//                        System.out.println("TableNumericFieldOperations.isEnabled: Tabla: "
117
//                                        + table.getModel().getModelo().getName());
118
//
119
//                        if (indices.cardinality() == 1) {
120
//                                int type = table.getModel().getModelo().getRecordset()
121
//                                                .getFieldType(indices.nextSetBit(0));
122
//                                if ((type == Types.BIGINT) || (type == Types.DECIMAL)
123
//                                                || (type == Types.DOUBLE) || (type == Types.FLOAT)
124
//                                                || (type == Types.INTEGER) || (type == Types.SMALLINT)
125
//                                                || (type == Types.TINYINT) || (type == Types.REAL)
126
//                                                || (type == Types.NUMERIC)) {
127
//                                        return true;
128
//                                }
129
//
130
//                        }
131
//                } catch (ReadException e) {
132
//                        e.printStackTrace();
133
//                }
134
//
135
//                return false;
136
//        }
137

    
138
    /**
139
         * DOCUMENT ME!
140
         *
141
         * @return DOCUMENT ME!
142
         */
143
    public boolean isVisible() {
144
        IWindow v = PluginServices.getMDIManager().getActiveWindow();
145
        if (v != null && v instanceof FeatureTableDocumentPanel) {
146
            table=(FeatureTableDocumentPanel)v;
147
                return true;
148
        }
149

    
150
        return false;
151
    }
152
}