Revision 27382

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/ShowTable.java
154 154
					}
155 155
					projectTable.setStore(fs);
156 156
					FeatureTableDocumentPanel t = new FeatureTableDocumentPanel(projectTable);
157
					if (fs.isEditing()) {
158
						// FIXME ???
159
//						fs.addObserver(t);
160
					}
161
					fs.addObserver(t);
162 157
					t.getModel().setModified(true);
163 158
					PluginServices.getMDIManager().addWindow(t);
164 159
				}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/FeatureTableDocumentPanel.java
31 31
import javax.swing.JButton;
32 32
import javax.swing.JLabel;
33 33
import javax.swing.JPanel;
34
import javax.swing.event.ListSelectionEvent;
35
import javax.swing.event.ListSelectionListener;
36
import javax.swing.event.TableModelEvent;
37
import javax.swing.event.TableModelListener;
34 38

  
35 39
import org.gvsig.fmap.dal.exception.DataException;
36 40
import org.gvsig.fmap.dal.feature.FeatureSelection;
37 41
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
39 42
import org.gvsig.fmap.data.feature.swing.FeatureTypesTablePanel;
43
import org.gvsig.fmap.data.feature.swing.table.notification.ColumnHeaderSelectionChangeNotification;
40 44
import org.gvsig.project.document.table.FeatureTableDocument;
41 45
import org.gvsig.tools.observer.Observable;
42 46
import org.gvsig.tools.observer.Observer;
......
52 56
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
53 57
 */
54 58
public class FeatureTableDocumentPanel extends FeatureTypesTablePanel implements
55
        SingletonWindow, IWindowTransform, Observer {
59
        SingletonWindow, IWindowTransform, Observer, ListSelectionListener,
60
		TableModelListener {
56 61
    private boolean showTypes=false;
57 62
    private static final long serialVersionUID = -1003263265311764630L;
58 63

  
......
71 76
	private JLabel jLabel;
72 77

  
73 78
	private JButton bShowFeatureTypes = null;
74
	private JPanel jPanel1 = null;
75 79

  
76 80
	public FeatureTableDocumentPanel(FeatureTableDocument document)
77 81
			throws DataException {
......
130 134
	}
131 135

  
132 136
	public void update(Observable arg0, Object arg1) {
133
		if (this.model.getStore().equals(arg0)) {
134
			FeatureStoreNotification event = (FeatureStoreNotification) arg1;
135
			if (event.getType() == FeatureStoreNotification.TRANSFORM_CHANGE
136
					|| event.getType() == FeatureStoreNotification.RESOURCE_CHANGED) {
137 137

  
138
				//FIXME!!! que hacemos
139
				return;
140
			}
141
			updateSelection();
142
			repaint();
138
		if (arg1 instanceof ColumnHeaderSelectionChangeNotification) {
139
			PluginServices.getMainFrame().enableControls();
143 140

  
144 141
		}
145
		PluginServices.getMainFrame().enableControls();
142

  
146 143
	}
147 144

  
148 145
	public void updateSelection() {
......
191 188
		}
192 189
		return jPanel;
193 190
	}
194
	private void initialize(){
191
	private void initialize() throws DataException {
195 192
		add(getJPanel(),BorderLayout.SOUTH);
196
		try {
197
			getTablePanel().getTable().addObserver(this);
198
		} catch (DataException e) {
199
			e.printStackTrace();
200
		}
193
		getTablePanel().getTable().addObserver(this);
194
		getTablePanel().getTable().getSelectionModel()
195
				.addListSelectionListener(this);
196
		getTableModel().addTableModelListener(this);
201 197
	}
202 198

  
203 199
	/**
......
229 225
		return WindowInfo.EDITOR_PROFILE;
230 226
	}
231 227

  
232
//	/**
233
//	 * This method initializes jPanel1
234
//	 *
235
//	 * @return javax.swing.JPanel
236
//	 */
237
//	private JPanel getJPanel1() {
238
//		if (jPanel1 == null) {
239
//			jPanel1 = new JPanel();
240
//			jPanel1.setLayout(new GridBagLayout());
241
//			jPanel1.add(getBShowFeatureTypes(), null);
242
//		}
243
//		return jPanel1;
244
//	}
228
	public void valueChanged(ListSelectionEvent e) {
229
		this.updateSelection();
230
		this.updateUI();
231

  
232
	}
233

  
234
	public void tableChanged(TableModelEvent e) {
235
		this.updateSelection();
236
		this.updateUI();
237
	}
245 238
}
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/table/FeatureTableModel.java
241 241
            FeatureStoreNotification fsNotification = (FeatureStoreNotification) notification;
242 242
            String type = fsNotification.getType();
243 243

  
244
            System.out.println("FeatureTableModel.update(): " + type);
244 245
            // If there are new, updated or deleted features
245 246
            // reload the table data
246 247
            if (FeatureStoreNotification.AFTER_DELETE.equals(type)
......
256 257
            } else if (FeatureStoreNotification.TRANSFORM_CHANGE.equals(type)) {
257 258
                reloadIfTypeTransformed();
258 259

  
259
            } else if (FeatureStoreNotification.AFTER_FINISHEDITING.equals(type)) {
260
            	reloadFeatures();
260
            } else if (FeatureStoreNotification.AFTER_FINISHEDITING
261
					.equals(type)
262
					|| FeatureStoreNotification.AFTER_CANCELEDITING
263
							.equals(type)) {
264
            	reloadIfTypeTransformed();
261 265
            }
262 266

  
263 267
        }
......
354 358
     */
355 359
    private void reloadIfFeatureChanged(Feature feature) {
356 360
        // Is any data is changed in the FeatureStore, notify the model
357
        // listeners. Ignore the case where the updated feature is
358
        // changed through us.
359
        if (editableFeature == null || !editableFeature.equals(feature)) {
360
            reloadFeatures();
361
            fireTableDataChanged();
362
        }
361
		// listeners. Ignore the case where the updated feature is
362
		// changed through us.
363
		if (editableFeature == null || !editableFeature.equals(feature)) {
364
			reloadFeatures();
365
			fireTableDataChanged();
366
		}
363 367
    }
364 368

  
365 369
    /**
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/data/feature/swing/FeatureSelectionModel.java
32 32
import org.gvsig.fmap.dal.feature.Feature;
33 33
import org.gvsig.fmap.dal.feature.FeatureSelection;
34 34
import org.gvsig.fmap.dal.feature.FeatureStore;
35
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
35 36
import org.gvsig.fmap.data.feature.swing.table.FeatureTableModel;
37
import org.gvsig.tools.observer.Observable;
38
import org.gvsig.tools.observer.Observer;
36 39

  
37 40
/**
38 41
 * ListSelectionModel implementation based on the FeatureSelection of a
......
40 43
 *
41 44
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
42 45
 */
43
public class FeatureSelectionModel extends DefaultListSelectionModel {
46
public class FeatureSelectionModel extends DefaultListSelectionModel implements
47
		Observer {
44 48

  
45 49
    private static final long serialVersionUID = 7643472991526133823L;
46 50

  
47
    private final FeatureSelection selection;
48 51
    private final FeatureTableModel featureTableModel;
49 52

  
50 53
    /**
......
59 62
    public FeatureSelectionModel(FeatureTableModel featureTableModel)
60 63
            throws DataException {
61 64
        this.featureTableModel = featureTableModel;
62
        FeatureStore store = getFeatureStore();
63
        this.selection = store.getFeatureSelection();
65
        this.featureTableModel.getFeatureStore().addObserver(this);
64 66
    }
65 67

  
66 68
    @Override
......
72 74
    		return false;
73 75
    	}
74 76
        Feature feature = featureTableModel.getFeatureAt(index);
75
        return selection.isSelected(feature);
77
        return getSelection().isSelected(feature);
76 78
        // }
77 79
    }
78 80

  
......
80 82
    public void setSelectionInterval(int index0, int index1) {
81 83
        // if (!getValueIsAdjusting()) {
82 84
        try {
83
            selection.deselectAll();
85
        	getSelection().deselectAll();
84 86
        } catch (DataException ex) {
85 87
            throw new SelectionChangeException(ex);
86 88
        }
......
125 127
    private void selectFeatureInterval(int index0, int index1, boolean select) {
126 128
        // If only single selection is allowed, the valid value is index1
127 129
        if (getSelectionMode() == SINGLE_SELECTION) {
128
            selectFeatureAt(index1, select);
130
            selectFeatureAt(index1, select, getSelection());
129 131
        } else {
130 132
            // index0 < index1 is not guaranteed
131 133
            int first = index0 <= index1 ? index0 : index1;
......
135 137
            if (first == 0 && last == featureTableModel.getRowCount() - 1) {
136 138
                try {
137 139
                    if (select) {
138
                        selection.selectAll();
140
                    	getSelection().selectAll();
139 141
                    } else {
140
                        selection.deselectAll();
142
                    	getSelection().deselectAll();
141 143
                    }
142 144
                } catch (DataException ex) {
143 145
                    throw new SelectionChangeException(ex);
144 146
                }
145 147
            } else {
146
                for (int i = first; i <= last; i++) {
147
                    selectFeatureAt(i, select);
148
            	FeatureSelection selection;
149
				try {
150
					selection = this.getFeatureStore().createFeatureSelection();
151
				} catch (DataException e) {
152
					throw new SelectionChangeException(e);
153
				}
154
				for (int i = first; i <= last; i++) {
155
					selectFeatureAt(i, select, selection);
148 156
                }
157
				try {
158
					this.getFeatureStore().setSelection(selection);
159
				} catch (DataException e) {
160
					throw new SelectionChangeException(e);
161
				}
149 162
            }
150 163
        }
151 164
    }
152 165

  
153
    /**
154
     * Selects a feature at a row position.
155
     *
156
     * @param index
157
     *            the Feature row index
158
     * @param select
159
     *            if to select or deselect
160
     */
161
    private void selectFeatureAt(int index, boolean select) {
166
	/**
167
	 * Selects a feature at a row position.
168
	 *
169
	 * @param index
170
	 *            the Feature row index
171
	 * @param select
172
	 *            if to select or deselect
173
	 * @param selection
174
	 *            selection instance to use
175
	 */
176
    private void selectFeatureAt(int index, boolean select,
177
			FeatureSelection selection) {
162 178
        Feature feature = getFeature(index);
163 179
        if (select) {
164 180
            selection.select(feature);
165 181
        } else {
166
            selection.deselect(feature);
182
        	selection.deselect(feature);
167 183
        }
168 184
    }
169 185

  
......
180 196
    private FeatureStore getFeatureStore() {
181 197
        return featureTableModel.getFeatureStore();
182 198
    }
199

  
200
    /**
201
	 * Returns the FeatureStore.
202
	 */
203
	private FeatureSelection getSelection() {
204
        try {
205
			return (FeatureSelection) getFeatureStore().getSelection();
206
		} catch (DataException ex) {
207
			throw new SelectionChangeException(ex);
208
		}
209
	}
210

  
211
	public void update(Observable observable, Object notification) {
212
		if (notification instanceof FeatureStoreNotification) {
213
			FeatureStoreNotification fnotification = (FeatureStoreNotification) notification;
214
			if (!fnotification.getSource().equals(getFeatureStore())) {
215
				return;
216
			}
217
			if (FeatureStoreNotification.SELECTION_CHANGE.equals(fnotification
218
					.getType())) {
219
				this.fireValueChanged(-1, -1, false);
220

  
221
			}
222
		}
223

  
224
	}
225

  
183 226
}

Also available in: Unified diff