Revision 25842

View differences:

branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/FeatureTable.java
29 29
import java.awt.Color;
30 30

  
31 31
import javax.swing.JTable;
32
import javax.swing.event.TableModelEvent;
32 33
import javax.swing.table.TableColumnModel;
33 34
import javax.swing.table.TableModel;
34 35

  
......
140 141
    }
141 142

  
142 143
    @Override
144
    public void tableChanged(TableModelEvent e) {
145
        super.tableChanged(e);
146
        headerCellRenderer.deselectAll();
147
    }
148

  
149
    @Override
143 150
    protected void initializeLocalVars() {
144 151
        super.initializeLocalVars();
145 152
        // Add a cell renderer for Geometries and Features
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/table/FeatureTableModel.java
218 218
     * @throws DataException
219 219
     *             if there is an error loading the data
220 220
     */
221
    public void setFeatureType(FeatureType featureType) throws DataException {
221
    public void setFeatureType(FeatureType featureType) {
222 222
        getFeatureQuery().setFeatureType(featureType);
223
        getHelper().reload();
223
        reloadFeatures();
224 224
        fireTableStructureChanged();
225 225
    }
226 226

  
......
229 229
                && notification instanceof FeatureStoreNotification) {
230 230
            FeatureStoreNotification fsNotification = (FeatureStoreNotification) notification;
231 231
            String type = fsNotification.getType();
232
            try {
233
                // Is any data is changed in the FeatureStore, notify the model
234
                // listeners. Ignore the case where the updated feature is
235
                // changed through us.
236
                if (editableFeature == null
237
                        || !editableFeature.equals(fsNotification.getFeature())) {
238 232

  
239
                    // Notify only about new, updated or deleted features
240
                    if (FeatureStoreNotification.AFTER_DELETE.equals(type)
241
                            | FeatureStoreNotification.AFTER_INSERT
242
                                    .equals(type)
243
                            | FeatureStoreNotification.AFTER_UPDATE
244
                                    .equals(type)) {
245
                        getHelper().reload();
246
                        fireTableDataChanged();
247
                    }
248
                }
249
            } catch (DataException ex) {
250
                throw new FeaturesDataReloadException(ex);
233
            // If there are new, updated or deleted features
234
            // reload the table data
235
            if (FeatureStoreNotification.AFTER_DELETE.equals(type)
236
                    || FeatureStoreNotification.AFTER_INSERT.equals(type)
237
                    || FeatureStoreNotification.AFTER_UPDATE.equals(type)) {
238

  
239
                reloadIfFeatureChanged(fsNotification.getFeature());
240

  
241
            } else if (FeatureStoreNotification.AFTER_UPDATE_TYPE.equals(type)) {
242

  
243
                reloadIfTypeChanged(fsNotification.getFeatureType());
244

  
245
            } else if (FeatureStoreNotification.TRANSFORM_CHANGE.equals(type)) {
246

  
247
                reloadIfTypeTransformed(fsNotification.getFeatureType());
251 248
            }
249

  
252 250
        }
253 251
    }
254 252

  
......
336 334
    private FeatureType getFeatureType() {
337 335
        return getFeatureQuery().getFeatureType();
338 336
    }
337

  
338
    /**
339
     * Reloads the table data if a feature has been changed, not through the
340
     * table.
341
     */
342
    private void reloadIfFeatureChanged(Feature feature) {
343
        // Is any data is changed in the FeatureStore, notify the model
344
        // listeners. Ignore the case where the updated feature is
345
        // changed through us.
346
        if (editableFeature == null || !editableFeature.equals(feature)) {
347
            reloadFeatures();
348
            fireTableDataChanged();
349
        }
350
    }
351

  
352
    /**
353
     * Reloads data and structure if the {@link FeatureType} of the features
354
     * being shown has changed.
355
     */
356
    private void reloadIfTypeChanged(FeatureType updatedType) {
357
        // If the updated featured type is the one currently being
358
        // shown, reload the table.
359
        if (updatedType != null && updatedType.equals(getFeatureType())) {
360
            setFeatureType(updatedType);
361
        }
362
    }
363

  
364
    /**
365
     * Reloads data and structure if the {@link FeatureType} of the features
366
     * being shown has been transformed.
367
     */
368
    private void reloadIfTypeTransformed(FeatureType transformedType) {
369
        // TODO: verify this is correct, at least we should check the
370
        // transformed type is the one we are showing
371
        setFeatureType(transformedType);
372
    }
373

  
374
    /**
375
     * Reloads the features shown on the table.
376
     */
377
    private void reloadFeatures() {
378
        try {
379
            getHelper().reload();
380
        } catch (DataException ex) {
381
            throw new FeaturesDataReloadException(ex);
382
        }
383
    }
339 384
}
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/table/JToggleButtonHeaderCellRenderer.java
60 60
    // Component to render on each header cell
61 61
    private JToggleButton button;
62 62

  
63
    private FeatureTable table;
64

  
63 65
    /**
64 66
     * Create a new JToggleButtonCellRenderer for a JTable.
65 67
     */
66
    public JToggleButtonHeaderCellRenderer(JTable table) {
68
    public JToggleButtonHeaderCellRenderer(FeatureTable table) {
69
        this.table = table;
67 70
        JTableHeader header = table.getTableHeader();
68 71
        header.addMouseListener(this);
69 72
        button = new JToggleButton();
......
105 108
        return button;
106 109
    }
107 110

  
111
    public void deselectAll() {
112
        selectedColumns.clear();
113
        notifyObservers(new ColumnHeaderSelectionChangeNotification(table));
114
    }
115

  
108 116
    public void mouseClicked(MouseEvent event) {
109 117
        // Look for the clicked column
110
        JTable table = ((JTableHeader) event.getSource()).getTable();
111
        int columnViewIndex = table.columnAtPoint(event.getPoint());
112
        int columnModelIndex = table.convertColumnIndexToModel(columnViewIndex);
118
        JTable jtable = ((JTableHeader) event.getSource()).getTable();
119
        if (jtable.equals(table)) {
120
            int columnViewIndex = table.columnAtPoint(event.getPoint());
121
            int columnModelIndex = table
122
                    .convertColumnIndexToModel(columnViewIndex);
113 123

  
114
        // Set or add the selected column, depending on the CTRL key being
115
        // pressed or not
116
        if (ctrlKeyPressed(event)) {
117
            reverseSelection((FeatureTable) table, columnModelIndex);
118
        } else {
119
            setSelection((FeatureTable) table, columnModelIndex);
124
            // Set or add the selected column, depending on the CTRL key being
125
            // pressed or not
126
            if (ctrlKeyPressed(event)) {
127
                reverseSelection(columnModelIndex);
128
            } else {
129
                setSelection(columnModelIndex);
130
            }
120 131
        }
121 132
    }
122 133

  
......
144 155
    /**
145 156
     * Sets the selection to only the given column.
146 157
     */
147
    private void setSelection(FeatureTable table, int column) {
158
    private void setSelection(int column) {
148 159
        selectedColumns.clear();
149 160
        selectedColumns.set(column);
150 161

  
......
154 165
    /**
155 166
     * Reverses the selection of a column.
156 167
     */
157
    private void reverseSelection(FeatureTable table, int column) {
168
    private void reverseSelection(int column) {
158 169
        selectedColumns.flip(column);
159 170

  
160 171
        notifyObservers(new ColumnHeaderSelectionChangeNotification(table));

Also available in: Unified diff