Revision 33378

View differences:

branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/ConfigurableFeatureTableModel.java
33 33
import java.util.List;
34 34
import java.util.Map;
35 35

  
36
import javax.swing.event.TableModelEvent;
37

  
36 38
import org.gvsig.fmap.dal.DataTypes;
37 39
import org.gvsig.fmap.dal.exception.DataException;
38 40
import org.gvsig.fmap.dal.feature.EditableFeature;
......
224 226
        order.clear();
225 227
        order.add(name, ascending);
226 228
        getHelper().reload();
227
        fireTableDataChanged();
229
		fireTableChanged(new TableModelEvent(this, 0, getRowCount() - 1));
228 230
    }
229 231

  
230 232
    @Override
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/FeatureTableModel.java
26 26
 */
27 27
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table;
28 28

  
29
import javax.swing.event.TableModelEvent;
29 30
import javax.swing.table.AbstractTableModel;
30 31

  
32
import org.gvsig.fmap.dal.DALLocator;
31 33
import org.gvsig.fmap.dal.exception.DataException;
32 34
import org.gvsig.fmap.dal.feature.EditableFeature;
33 35
import org.gvsig.fmap.dal.feature.Feature;
......
38 40
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
39 41
import org.gvsig.fmap.dal.feature.FeatureType;
40 42
import org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper;
41
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl;
42 43
import org.gvsig.tools.exception.BaseException;
43 44
import org.gvsig.tools.observer.Observable;
44 45
import org.gvsig.tools.observer.Observer;
......
72 73
     * @throws DataException
73 74
     *             if there is an error reading data from the FeatureStore
74 75
     */
75
    public FeatureTableModel(FeatureStore featureStore,
76
            FeatureQuery featureQuery) throws DataException {
77
        this(featureStore, featureQuery, FeaturePagingHelper.DEFAULT_PAGE_SIZE);
78
    }
76
	public FeatureTableModel(FeatureStore featureStore,
77
			FeatureQuery featureQuery) throws DataException {
78
		this(featureStore, featureQuery, FeaturePagingHelper.DEFAULT_PAGE_SIZE);
79
	}
79 80

  
80 81
    /**
81 82
     * Constructs a TableModel from the features of a FeatureStore, with the
......
90 91
     * @throws DataException
91 92
     *             if there is an error reading data from the FeatureStore
92 93
     */
93
    public FeatureTableModel(FeatureStore featureStore,
94
            FeatureQuery featureQuery, int pageSize) throws DataException {
95
        this(new FeaturePagingHelperImpl(featureStore, featureQuery, pageSize));
96
    }
94
	public FeatureTableModel(FeatureStore featureStore,
95
			FeatureQuery featureQuery, int pageSize) throws DataException {
96
		this(DALLocator.getDataManager().createFeaturePagingHelper(
97
				featureStore, featureQuery, pageSize));
98
	}
97 99

  
98 100
    /**
99 101
     * Constructs a TableModel from a FeatureCollection and a Paging helper.
......
235 237
        fireTableStructureChanged();
236 238
    }
237 239

  
240
	/**
241
	 * Sets that the selected Features get returned first.
242
	 */
243
	public void setSelectionUp(boolean selectionUp) {
244
		getHelper().setSelectionUp(selectionUp);
245
		fireTableChanged(new TableModelEvent(this, 0, getRowCount() - 1));
246
	}
247

  
238 248
    public void update(Observable observable, Object notification) {
239 249
        if (observable.equals(getFeatureStore())
240 250
                && notification instanceof FeatureStoreNotification) {
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureTypesTablePanel.java
164 164
	}
165 165

  
166 166
	/**
167
	 * Sets that the selected Features to be viewed first.
168
	 */
169
	public void setSelectionUp(boolean selectionUp) {
170
		getTablePanel().setSelectionUp(selectionUp);
171
	}
172

  
173
	/**
167 174
	 * Returns the internal Table Model for the Features of the FeatureStore.
168 175
	 * 
169 176
	 * @return the internal Table Model
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureSelectionModelNew.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.mapcontrol.dal.feature.swing;
28

  
29
import javax.swing.ListSelectionModel;
30
import javax.swing.event.EventListenerList;
31
import javax.swing.event.ListSelectionEvent;
32
import javax.swing.event.ListSelectionListener;
33

  
34
import org.gvsig.fmap.dal.exception.DataException;
35
import org.gvsig.fmap.dal.feature.Feature;
36
import org.gvsig.fmap.dal.feature.FeatureSelection;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.fmap.dal.feature.FeatureStoreNotification;
39
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTableModel;
40
import org.gvsig.tools.observer.Observable;
41
import org.gvsig.tools.observer.Observer;
42

  
43
/**
44
 * @author 2010- C?sar Ordi?ana - gvSIG team
45
 */
46
public class FeatureSelectionModelNew implements ListSelectionModel, Observer {
47

  
48
	protected EventListenerList listenerList = new EventListenerList();
49

  
50
	private final FeatureTableModel featureTableModel;
51

  
52
	private int selectionMode = SINGLE_INTERVAL_SELECTION;
53

  
54
	private boolean isAdjusting = false;
55

  
56
	private int anchor = -1;
57

  
58
	private int lead = -1;
59

  
60
	/**
61
	 * Creates a new {@link FeatureSelectionModelNew} with a
62
	 * {@link FeatureTableModel} used to get the {@link Feature}s by position in
63
	 * the table.
64
	 * 
65
	 * @param featureTableModel
66
	 *            to get Features from
67
	 * @throws DataException
68
	 *             if there is an error getting the store selection
69
	 */
70
	public FeatureSelectionModelNew(FeatureTableModel featureTableModel)
71
			throws DataException {
72
		this.featureTableModel = featureTableModel;
73
		this.featureTableModel.getFeatureStore().addObserver(this);
74
	}
75

  
76
	public int getAnchorSelectionIndex() {
77
		return anchor;
78
	}
79

  
80
	public int getLeadSelectionIndex() {
81
		return lead;
82
	}
83

  
84
	public int getMaxSelectionIndex() {
85
		FeatureSelection selection = getFeatureSelection();
86
		try {
87
			if (!selection.isEmpty()) {
88
				for (int i = featureTableModel.getRowCount() - 1; i >= 0; i--) {
89
					if (selection.isSelected(featureTableModel.getFeatureAt(i))) {
90
						return i;
91
					}
92
				}
93
			}
94
		} catch (DataException e) {
95
			throw new SelectionChangeException(e);
96
		}
97
		return -1;
98
	}
99

  
100
	public int getMinSelectionIndex() {
101
		FeatureSelection selection = getFeatureSelection();
102
		try {
103
			if (!selection.isEmpty()) {
104
				for (int i = 0; i < featureTableModel.getRowCount(); i++) {
105
					if (selection.isSelected(featureTableModel.getFeatureAt(i))) {
106
						return i;
107
					}
108
				}
109
			}
110
		} catch (DataException e) {
111
			throw new SelectionChangeException(e);
112
		}
113
		return -1;
114
	}
115

  
116
	public void insertIndexInterval(int index, int length, boolean before) {
117
		// Nothing to do
118
	}
119

  
120
	public void removeIndexInterval(int index0, int index1) {
121
		// Nothing to do
122
	}
123

  
124
	public void setAnchorSelectionIndex(int index) {
125
		this.anchor = index;
126
	}
127

  
128
	public void setLeadSelectionIndex(int index) {
129
		this.lead = index;
130
	}
131

  
132
	public void addSelectionInterval(int index0, int index1) {
133
		doWithSelection(new FeatureSelectionOperation() {
134

  
135
			public void doWithSelection(FeatureSelection selection, int first,
136
					int last) throws DataException {
137
				for (int i = first; i <= last; i++) {
138
					Feature feature = getFeature(i);
139
					if (!selection.isSelected(feature)) {
140
						selection.select(feature);
141
					}
142
				}
143
			}
144

  
145
		}, index0, index1, true);
146
	}
147

  
148
	public void setSelectionInterval(int index0, int index1) {
149
		doWithSelection(new FeatureSelectionOperation() {
150

  
151
			public void doWithSelection(FeatureSelection selection, int first,
152
					int last) throws DataException {
153
				selection.deselectAll();
154
				for (int i = first; i <= last; i++) {
155
					Feature feature = getFeature(i);
156
					selection.select(feature);
157
				}
158
			}
159

  
160
		}, index0, index1, true);
161
	}
162

  
163
	public void removeSelectionInterval(int index0, int index1) {
164
		doWithSelection(new FeatureSelectionOperation() {
165

  
166
			public void doWithSelection(FeatureSelection selection, int first,
167
					int last) throws DataException {
168
				for (int i = first; i <= last; i++) {
169
					Feature feature = getFeature(i);
170
					if (selection.isSelected(feature)) {
171
						selection.deselect(feature);
172
					}
173
				}
174
			}
175

  
176
		}, index0, index1, false);
177
	}
178

  
179
	public void clearSelection() {
180
		try {
181
			getFeatureSelection().deselectAll();
182
		} catch (DataException e) {
183
			throw new SelectionChangeException(e);
184
		}
185
	}
186

  
187
	public boolean isSelectedIndex(int index) {
188
		if (index == -1) {
189
			return false;
190
		}
191
		Feature feature = featureTableModel.getFeatureAt(index);
192
		return getFeatureSelection().isSelected(feature);
193
	}
194

  
195
	public boolean isSelectionEmpty() {
196
		try {
197
			return getFeatureSelection().isEmpty();
198
		} catch (DataException ex) {
199
			throw new SelectionChangeException(ex);
200
		}
201
	}
202

  
203
	public boolean getValueIsAdjusting() {
204
		return isAdjusting;
205
	}
206

  
207
	public void setValueIsAdjusting(boolean valueIsAdjusting) {
208
		if (this.isAdjusting != valueIsAdjusting) {
209
			this.isAdjusting = valueIsAdjusting;
210
			if (this.isAdjusting) {
211
				getFeatureSelection().beginComplexNotification();
212
			} else {
213
				getFeatureSelection().endComplexNotification();
214
			}
215
		}
216
	}
217

  
218
	public int getSelectionMode() {
219
		return selectionMode;
220
	}
221

  
222
	public void setSelectionMode(int selectionMode) {
223
		this.selectionMode = selectionMode;
224
	}
225

  
226
	public void addListSelectionListener(ListSelectionListener listener) {
227
		listenerList.add(ListSelectionListener.class, listener);
228
	}
229

  
230
	public void removeListSelectionListener(ListSelectionListener listener) {
231
		listenerList.remove(ListSelectionListener.class, listener);
232
	}
233

  
234
	public void update(Observable observable, Object notification) {
235
		if (notification instanceof FeatureStoreNotification) {
236
			FeatureStoreNotification fnotification =
237
					(FeatureStoreNotification) notification;
238
			if (!fnotification.getSource().equals(getFeatureStore())) {
239
				return;
240
			}
241
			if (FeatureStoreNotification.SELECTION_CHANGE.equals(fnotification.getType())) {
242
				fireValueChanged(-1, -1, false);
243
			}
244
		}
245
	}
246

  
247
	private FeatureSelection getFeatureSelection() {
248
		try {
249
			return (FeatureSelection) getFeatureStore().getSelection();
250
		} catch (DataException ex) {
251
			throw new SelectionChangeException(ex);
252
		}
253
	}
254

  
255
	/**
256
	 * @param operation
257
	 * @param index0
258
	 * @param index1
259
	 */
260
	private void doWithSelection(FeatureSelectionOperation operation,
261
			int index0, int index1, boolean select) {
262
		// Set the anchor and lead
263
		anchor = index0;
264
		lead = index1;
265

  
266
		// As index0 <= index1 is no guaranteed, calculate the first and second
267
		// values
268
		int first = (index0 <= index1) ? index0 : index1;
269
		int last = (index0 <= index1) ? index1 : index0;
270

  
271
		FeatureSelection selection = getFeatureSelection();
272

  
273
		// Perform the selection operation into a complex notification
274
		selection.beginComplexNotification();
275
		try {
276
			// Is a full select or deselect
277
			if (first == 00 && last == featureTableModel.getRowCount() - 1) {
278
				if (select) {
279
					selection.selectAll();
280
				} else {
281
					selection.deselectAll();
282
				}
283
			} else {
284
				operation.doWithSelection(selection, first, last);
285
			}
286
		} catch (DataException e) {
287
			throw new SelectionChangeException(e);
288
		} finally {
289
			selection.endComplexNotification();
290
		}
291

  
292
		fireValueChanged(first, last, isAdjusting);
293
	}
294

  
295
	/**
296
	 * Returns a Feature by table row position.
297
	 */
298
	private Feature getFeature(int index) {
299
		return featureTableModel.getFeatureAt(index);
300
	}
301

  
302
	/**
303
	 * Returns the FeatureStore.
304
	 */
305
	private FeatureStore getFeatureStore() {
306
		return featureTableModel.getFeatureStore();
307
	}
308

  
309
	/**
310
	 * @param firstIndex
311
	 *            the first index in the interval
312
	 * @param lastIndex
313
	 *            the last index in the interval
314
	 * @param isAdjusting
315
	 *            true if this is the final change in a series of adjustments
316
	 * @see EventListenerList
317
	 */
318
	protected void fireValueChanged(int firstIndex, int lastIndex,
319
			boolean isAdjusting) {
320
		Object[] listeners = listenerList.getListenerList();
321
		ListSelectionEvent e = null;
322

  
323
		for (int i = listeners.length - 2; i >= 0; i -= 2) {
324
			if (listeners[i] == ListSelectionListener.class) {
325
				if (e == null) {
326
					e =
327
							new ListSelectionEvent(this, firstIndex, lastIndex,
328
									isAdjusting);
329
				}
330
				((ListSelectionListener) listeners[i + 1]).valueChanged(e);
331
			}
332
		}
333
	}
334

  
335
	private interface FeatureSelectionOperation {
336
		void doWithSelection(FeatureSelection selection, int first, int last)
337
				throws DataException;
338
	}
339
}
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureSelectionModel.java
145 145
                    throw new SelectionChangeException(ex);
146 146
                }
147 147
            } else {
148
            	FeatureSelection selection;
148
				FeatureSelection selection = getSelection();
149
				selection.beginComplexNotification();
149 150
				try {
150
					selection = this.getFeatureStore().createFeatureSelection();
151
					selection.deselectAll();
152
					for (int i = first; i <= last; i++) {
153
						selectFeatureAt(i, select, selection);
154
					}
151 155
				} catch (DataException e) {
152 156
					throw new SelectionChangeException(e);
153 157
				}
154
				for (int i = first; i <= last; i++) {
155
					selectFeatureAt(i, select, selection);
156
                }
157
				try {
158
					this.getFeatureStore().setSelection(selection);
159
				} catch (DataException e) {
160
					throw new SelectionChangeException(e);
161
				}
158
				selection.endComplexNotification();
162 159
            }
163 160
        }
164 161
    }
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureTable.java
150 150
        headerCellRenderer.deleteObservers();
151 151
    }
152 152

  
153
	/**
154
	 * Sets that the selected Features to be viewed first.
155
	 */
156
	public void setSelectionUp(boolean selectionUp) {
157
		((FeatureTableModel) getModel()).setSelectionUp(selectionUp);
158
		scrollRectToVisible(getCellRect(0, 0, true));
159
	}
160

  
153 161
    // @Override
154 162
    // public void tableChanged(TableModelEvent e) {
155 163
    // super.tableChanged(e);
......
182 190
        // through the FeatureTableModel
183 191
        setRowSelectionAllowed(true);
184 192
        setColumnSelectionAllowed(false);
185
        setSelectionModel(new FeatureSelectionModel(featureTableModel));
193
		//setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
194
		setSelectionModel(new FeatureSelectionModelNew(featureTableModel));
195
		// setSelectionModel(new FeatureSelectionModel(featureTableModel));
186 196

  
187 197
		headerCellRenderer = new JToggleButtonHeaderCellRenderer(this);
188 198
		getTableHeader().setDefaultRenderer(headerCellRenderer);
branches/v2_0_0_prep/libraries/libFMap_controls/src/org/gvsig/fmap/mapcontrol/dal/feature/swing/FeatureTablePanel.java
136 136
		return getTableModel().getFeatureStore();
137 137
	}
138 138

  
139
	/**
140
	 * Sets that the selected Features to be viewed first.
141
	 */
142
	public void setSelectionUp(boolean selectionUp) {
143
		try {
144
			getTable().setSelectionUp(selectionUp);
145
		} catch (DataException e) {
146
			// TODO: create and throw a SetSelectionUpException
147
			e.printStackTrace();
148
		}
149
	}
150

  
139 151
	private static ConfigurableFeatureTableModel createModel(
140 152
			FeatureStore featureStore, FeatureQuery featureQuery)
141 153
			throws DataException {
branches/v2_0_0_prep/libraries/libFMap_dal/pom.xml
27 27
			<groupId>org.gvsig</groupId>
28 28
			<artifactId>org.gvsig.tools.lib</artifactId>
29 29
		</dependency>
30
        <dependency>
31
            <groupId>org.gvsig</groupId>
32
            <artifactId>org.gvsig.compat</artifactId>
33
            <version>2.0-SNAPSHOT</version>
34
        </dependency>
30 35
		<dependency>
31 36
			<groupId>org.gvsig</groupId>
32 37
			<artifactId>org.gvsig.metadata</artifactId>
......
60 65
			<classifier>tests</classifier>
61 66
			<scope>test</scope>
62 67
		</dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.compat</artifactId>
71
            <version>2.0-SNAPSHOT</version>
72
            <classifier>se</classifier>
73
            <scope>test</scope>
74
        </dependency>
63 75
		<dependency>
64 76
			<groupId>org.gvsig</groupId>
65 77
			<artifactId>org.gvsig.metadata</artifactId>
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/paging/FeaturePagingHelperTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 {DiSiD Technologies}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.paging;
28

  
29
import org.easymock.MockControl;
30
import org.gvsig.fmap.dal.feature.FeatureQuery;
31
import org.gvsig.fmap.dal.feature.FeatureSet;
32
import org.gvsig.fmap.dal.feature.FeatureStore;
33
import org.gvsig.fmap.dal.feature.FeatureType;
34
import org.gvsig.fmap.dal.feature.paging.impl.FeaturePagingHelperImpl;
35
import org.gvsig.tools.dynobject.DynObjectPagingHelper;
36
import org.gvsig.tools.dynobject.DynObjectPagingHelperTest;
37

  
38
/**
39
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
40
 */
41
public class FeaturePagingHelperTest extends DynObjectPagingHelperTest {
42

  
43
	private MockControl fsetControl;
44
	private FeatureSet fsetMock;
45
	private MockControl storeControl;
46
	private FeatureStore storeMock;
47
	private MockControl queryControl;
48
	private FeatureQuery queryMock;
49
	private FeatureType featureTypeMock;
50
	private MockControl fTypeControl;
51

  
52
	protected DynObjectPagingHelper createDynObjectPagingHelper()
53
			throws Exception {
54
		fsetControl = MockControl.createNiceControl(FeatureSet.class);
55
		fsetMock = (FeatureSet) fsetControl.getMock();
56
		storeControl = MockControl.createNiceControl(FeatureStore.class);
57
		storeMock = (FeatureStore) storeControl.getMock();
58
		queryControl = MockControl.createNiceControl(FeatureQuery.class);
59
		queryMock = (FeatureQuery) queryControl.getMock();
60
		fTypeControl = MockControl.createNiceControl(FeatureType.class);
61
		featureTypeMock = (FeatureType) fTypeControl.getMock();
62

  
63
		storeControl.expectAndReturn(storeMock.getDefaultFeatureType(),
64
				featureTypeMock);
65
		storeControl.expectAndReturn(storeMock.createFeatureQuery(), queryMock,
66
				MockControl.ZERO_OR_MORE);
67
		storeControl.expectAndReturn(storeMock.getFeatureSet(queryMock),
68
				fsetMock, MockControl.ZERO_OR_MORE);
69
		fsetControl.expectAndReturn(fsetMock.getSize(), 10,
70
				MockControl.ZERO_OR_MORE);
71
		storeControl.replay();
72
		fsetControl.replay();
73

  
74
		return new FeaturePagingHelperImpl(storeMock);
75
	}
76

  
77
	protected void tearDown() throws Exception {
78
		super.tearDown();
79
	}
80

  
81
	/**
82
	 * Test method for
83
	 * {@link org.gvsig.fmap.dal.feature.paging.FeaturePagingHelper#getTotalSize()}
84
	 * .
85
	 */
86
	public void testGetTotalSize() throws Exception {
87

  
88
		assertEquals("El n? total de features no es el de la Colecci?n", 10,
89
				getHelper().getTotalSize());
90

  
91
		storeControl.verify();
92
		fsetControl.verify();
93
	}
94

  
95
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/paging/impl/OneSubsetOneSetPagingCalculatorTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22

  
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2010 {}  {{Task}}
26
 */
27
package org.gvsig.fmap.dal.feature.paging.impl;
28

  
29

  
30
/**
31
 * Unit tests for the {@link OneSubsetOneSetPagingCalculator} class.
32
 * 
33
 * @author 2010- C?sar Ordi?ana - gvSIG team
34
 */
35
public class OneSubsetOneSetPagingCalculatorTest extends AbstractPagingCalculatorTest {
36

  
37
	private static final int MAX_PAGE_SIZE = 4;
38

  
39
	private TestSizeable sizeable1 = new TestSizeable(6);
40
	private TestSizeable sizeable2 = new TestSizeable(17);
41

  
42
	private OneSubsetOneSetPagingCalculator calculator;
43

  
44
	protected void setUp() throws Exception {
45
		super.setUp();
46
		calculator =
47
				new OneSubsetOneSetPagingCalculator(MAX_PAGE_SIZE, sizeable1, sizeable2);
48
	}
49

  
50
	/**
51
	 * Test method for
52
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetSize()}
53
	 * .
54
	 */
55
	public void testGetFirstSetSize() {
56
		assertEquals(sizeable1.getSize(), calculator.getFirstSetSize());
57
	}
58

  
59
	/**
60
	 * Test method for
61
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetSize()}
62
	 * .
63
	 */
64
	public void testGetSecondSetSize() {
65
		assertEquals(sizeable2.getSize() - sizeable1.getSize(), calculator.getSecondSetSize());
66
	}
67

  
68
	/**
69
	 * Test method for
70
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetInitialIndex()}
71
	 * .
72
	 */
73
	public void testGetFirstSetInitialIndex() {
74
		calculator.setCurrentPage(0);
75
		assertEquals(0, calculator.getFirstSetInitialIndex());
76

  
77
		calculator.setCurrentPage(1);
78
		assertEquals(0 + MAX_PAGE_SIZE, calculator.getFirstSetInitialIndex());
79

  
80
		calculator.setCurrentPage(2);
81
		assertEquals(-1, calculator.getFirstSetInitialIndex());
82

  
83
		calculator.setCurrentPage(3);
84
		assertEquals(-1, calculator.getFirstSetInitialIndex());
85

  
86
		calculator.setCurrentPage(calculator.getNumPages() - 1);
87
		assertEquals(-1, calculator.getFirstSetInitialIndex());
88

  
89
		// Change values so all data fits into a single page
90
		sizeable1.setSize(1l);
91
		sizeable2.setSize(15l);
92
		calculator.setMaxPageSize(20);
93

  
94
		calculator.setCurrentPage(0);
95
		assertEquals(0, calculator.getFirstSetInitialIndex());
96
	}
97

  
98
	/**
99
	 * Test method for
100
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetInitialIndex()}
101
	 * .
102
	 */
103
	public void testGetSecondSetInitialIndex() {
104
		calculator.setCurrentPage(0);
105
		assertEquals(-1, calculator.getSecondSetInitialIndex());
106

  
107
		calculator.setCurrentPage(1);
108
		assertEquals(0, calculator.getSecondSetInitialIndex());
109

  
110
		calculator.setCurrentPage(2);
111
		assertEquals(2, calculator.getSecondSetInitialIndex());
112

  
113
		calculator.setCurrentPage(3);
114
		assertEquals(2 + MAX_PAGE_SIZE, calculator.getSecondSetInitialIndex());
115

  
116
		calculator.setCurrentPage(calculator.getNumPages() - 1);
117
		assertEquals(2 + ((calculator.getNumPages() - 3) * MAX_PAGE_SIZE),
118
				calculator.getSecondSetInitialIndex());
119

  
120
		// Change values so all data fits into a single page
121
		sizeable1.setSize(1l);
122
		sizeable2.setSize(15l);
123
		calculator.setMaxPageSize(20);
124

  
125
		calculator.setCurrentPage(0);
126
		assertEquals(0, calculator.getSecondSetInitialIndex());
127

  
128
		// Set the two sets equal, so all elements in the first set are
129
		// contained in the second one
130
		sizeable1.setSize(15l);
131
		sizeable2.setSize(15l);
132
		calculator.setMaxPageSize(4);
133

  
134
		calculator.setCurrentPage(0);
135
		assertEquals(-1, calculator.getSecondSetInitialIndex());
136

  
137
		calculator.setCurrentPage(1);
138
		assertEquals(-1, calculator.getSecondSetInitialIndex());
139

  
140
		calculator.setCurrentPage(2);
141
		assertEquals(-1, calculator.getSecondSetInitialIndex());
142

  
143
		calculator.setCurrentPage(3);
144
		assertEquals(-1, calculator.getSecondSetInitialIndex());
145
	}
146

  
147
	/**
148
	 * Test method for
149
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getFirstSetHowMany()}
150
	 * .
151
	 */
152
	public void testGetFirstSetHowMany() {
153
		calculator.setCurrentPage(0);
154
		assertEquals(MAX_PAGE_SIZE, calculator.getFirstSetHowMany());
155

  
156
		calculator.setCurrentPage(1);
157
		assertEquals(2, calculator.getFirstSetHowMany());
158

  
159
		calculator.setCurrentPage(2);
160
		assertEquals(0, calculator.getFirstSetHowMany());
161

  
162
		calculator.setCurrentPage(3);
163
		assertEquals(0, calculator.getFirstSetHowMany());
164

  
165
		calculator.setCurrentPage(calculator.getNumPages() - 1);
166
		assertEquals(0, calculator.getFirstSetHowMany());
167

  
168
		// Change values so all data fits into a single page
169
		sizeable1.setSize(1l);
170
		sizeable2.setSize(15l);
171
		calculator.setMaxPageSize(20);
172

  
173
		calculator.setCurrentPage(0);
174
		assertEquals(1, calculator.getFirstSetHowMany());
175

  
176
		// Change values so all data is available into the first set
177
		sizeable1.setSize(25l);
178
		sizeable2.setSize(25l);
179
		calculator.setMaxPageSize(20);
180

  
181
		calculator.setCurrentPage(0);
182
		assertEquals(20, calculator.getFirstSetHowMany());
183

  
184
		calculator.setCurrentPage(1);
185
		assertEquals(5, calculator.getFirstSetHowMany());
186
	}
187

  
188
	/**
189
	 * Test method for
190
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#getSecondSetHowMany()}
191
	 * .
192
	 */
193
	public void testGetSecondSetHowMany() {
194
		calculator.setCurrentPage(0);
195
		assertEquals(0l, calculator.getSecondSetHowMany());
196

  
197
		calculator.setCurrentPage(1);
198
		assertEquals(2l, calculator.getSecondSetHowMany());
199

  
200
		calculator.setCurrentPage(2);
201
		assertEquals(MAX_PAGE_SIZE, calculator.getSecondSetHowMany());
202

  
203
		calculator.setCurrentPage(3);
204
		assertEquals(MAX_PAGE_SIZE, calculator.getSecondSetHowMany());
205

  
206
		calculator.setCurrentPage(calculator.getNumPages() - 1);
207
		assertEquals(1l, calculator.getSecondSetHowMany());
208

  
209
		// Change values so all data fits into a single page
210
		sizeable1.setSize(1l);
211
		sizeable2.setSize(15l);
212
		calculator.setMaxPageSize(20);
213

  
214
		calculator.setCurrentPage(0);
215
		assertEquals(14l, calculator.getSecondSetHowMany());
216

  
217
		// Set the two sets equal, so all elements in the first set are
218
		// contained in the second one
219
		sizeable1.setSize(15l);
220
		sizeable2.setSize(15l);
221
		calculator.setMaxPageSize(4);
222

  
223
		calculator.setCurrentPage(0);
224
		assertEquals(0l, calculator.getSecondSetHowMany());
225

  
226
		calculator.setCurrentPage(1);
227
		assertEquals(0l, calculator.getSecondSetHowMany());
228

  
229
		calculator.setCurrentPage(2);
230
		assertEquals(0l, calculator.getSecondSetHowMany());
231

  
232
		calculator.setCurrentPage(3);
233
		assertEquals(0l, calculator.getSecondSetHowMany());
234
	}
235

  
236
	/**
237
	 * Test method for
238
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAllValuesInFirstSet()}
239
	 * .
240
	 */
241
	public void testHasCurrentPageAllValuesInFirstSet() {
242
		calculator.setCurrentPage(0);
243
		assertTrue(calculator.hasCurrentPageAllValuesInFirstSet());
244

  
245
		calculator.setCurrentPage(1);
246
		assertFalse(calculator.hasCurrentPageAllValuesInFirstSet());
247

  
248
		calculator.setCurrentPage(2);
249
		assertFalse(calculator.hasCurrentPageAllValuesInFirstSet());
250

  
251
		calculator.setCurrentPage(3);
252
		assertFalse(calculator.hasCurrentPageAllValuesInFirstSet());
253

  
254
		calculator.setCurrentPage(calculator.getNumPages() - 1);
255
		assertFalse(calculator.hasCurrentPageAllValuesInFirstSet());
256

  
257
		// Change values so all data fits into a single page
258
		sizeable1.setSize(1l);
259
		sizeable2.setSize(15l);
260
		calculator.setMaxPageSize(20);
261

  
262
		calculator.setCurrentPage(0);
263
		assertFalse(calculator.hasCurrentPageAllValuesInFirstSet());
264
	}
265

  
266
	/**
267
	 * Test method for
268
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAnyValuesInFirstSet()}
269
	 * .
270
	 */
271
	public void testHasCurrentPageAnyValuesInFirstSet() {
272
		calculator.setCurrentPage(0);
273
		assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet());
274

  
275
		calculator.setCurrentPage(1);
276
		assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet());
277

  
278
		calculator.setCurrentPage(2);
279
		assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet());
280

  
281
		calculator.setCurrentPage(3);
282
		assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet());
283

  
284
		calculator.setCurrentPage(calculator.getNumPages() - 1);
285
		assertFalse(calculator.hasCurrentPageAnyValuesInFirstSet());
286

  
287
		// Change values so all data fits into a single page
288
		sizeable1.setSize(1l);
289
		sizeable2.setSize(15l);
290
		calculator.setMaxPageSize(20);
291

  
292
		calculator.setCurrentPage(0);
293
		assertTrue(calculator.hasCurrentPageAnyValuesInFirstSet());
294
	}
295

  
296
	/**
297
	 * Test method for
298
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.OneSubsetOneSetPagingCalculator#hasCurrentPageAnyValuesInSecondSet()}
299
	 * .
300
	 */
301
	public void testHasCurrentPageAnyValuesInSecondSet() {
302
		calculator.setCurrentPage(0);
303
		assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet());
304

  
305
		calculator.setCurrentPage(1);
306
		assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet());
307

  
308
		calculator.setCurrentPage(2);
309
		assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet());
310

  
311
		calculator.setCurrentPage(3);
312
		assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet());
313

  
314
		calculator.setCurrentPage(calculator.getNumPages() - 1);
315
		assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet());
316

  
317
		// Change values so all data fits into a single page
318
		sizeable1.setSize(1l);
319
		sizeable2.setSize(15l);
320
		calculator.setMaxPageSize(20);
321

  
322
		calculator.setCurrentPage(0);
323
		assertTrue(calculator.hasCurrentPageAnyValuesInSecondSet());
324

  
325
		// Set the two sets equal, so all elements in the first set are
326
		// contained in the second one
327
		sizeable1.setSize(15l);
328
		sizeable2.setSize(15l);
329
		calculator.setMaxPageSize(4);
330

  
331
		calculator.setCurrentPage(0);
332
		assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet());
333

  
334
		calculator.setCurrentPage(1);
335
		assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet());
336

  
337
		calculator.setCurrentPage(2);
338
		assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet());
339

  
340
		calculator.setCurrentPage(3);
341
		assertFalse(calculator.hasCurrentPageAnyValuesInSecondSet());
342
	}
343

  
344
	private class TestSizeable implements PagingCalculator.Sizeable {
345

  
346
		private long size;
347

  
348
		public TestSizeable(long size) {
349
			this.size = size;
350
		}
351

  
352
		public long getSize() {
353
			return size;
354
		}
355

  
356
		public void setSize(long size) {
357
			this.size = size;
358
		}
359
	}
360
}
branches/v2_0_0_prep/libraries/libFMap_dal/src-test/org/gvsig/fmap/dal/feature/paging/impl/AbstractPagingCalculatorTest.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.fmap.dal.feature.paging.impl;
23

  
24
import junit.framework.TestCase;
25

  
26
/**
27
 * Unit tests for the {@link AbstractPagingCalculator} class.
28
 * 
29
 * @author 2010- C?sar Ordi?ana - gvSIG team
30
 */
31
public class AbstractPagingCalculatorTest extends TestCase {
32

  
33
	private AbstractPagingCalculator calculator;
34

  
35
	private static final long SIZE = 22;
36

  
37
	private static final int MAX_PAGE_SIZE = 4;
38

  
39
	protected void setUp() throws Exception {
40
		super.setUp();
41
		calculator = createCalculator();
42
	}
43

  
44
	protected AbstractPagingCalculator createCalculator() {
45
		return new TestPagingCalculator(MAX_PAGE_SIZE, SIZE);
46
	}
47

  
48
	/**
49
	 * Test method for
50
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#getMaxPageSize()}
51
	 * and
52
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#setMaxPageSize(int)}
53
	 * .
54
	 */
55
	public void testMaxPageSize() {
56
		assertEquals(MAX_PAGE_SIZE, calculator.getMaxPageSize());
57

  
58
		calculator.setMaxPageSize(100);
59
		assertEquals(100, calculator.getMaxPageSize());
60

  
61
		try {
62
			calculator.setMaxPageSize(-10);
63
			fail("Calculator accepts a negative max page size value");
64
		} catch (Exception ex) {
65
			// works as expected
66
		}
67
	}
68

  
69
	/**
70
	 * Test method for
71
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#getCurrentPage()}
72
	 * and
73
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#setCurrentPage(long)}
74
	 * .
75
	 */
76
	public void testCurrentPage() {
77
		assertEquals(0, calculator.getCurrentPage());
78

  
79
		long page = calculator.getNumPages() - 1;
80
		calculator.setCurrentPage(page);
81

  
82
		assertEquals(page, calculator.getCurrentPage());
83

  
84
		try {
85
			calculator.setCurrentPage(-10);
86
			fail("Calculator accepts a negative current page value");
87
		} catch (Exception ex) {
88
			// works as expected
89
		}
90
	}
91

  
92
	/**
93
	 * Test method for
94
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#getInitialIndex()}
95
	 * .
96
	 */
97
	public void testGetInitialIndex() {
98
		calculator.setCurrentPage(0l);
99
		assertEquals(0, calculator.getInitialIndex());
100

  
101
		calculator.setCurrentPage(2);
102
		assertEquals(2 * calculator.getMaxPageSize(),
103
				calculator.getInitialIndex());
104
	}
105

  
106
	/**
107
	 * Test method for
108
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#getNumPages()}
109
	 * .
110
	 */
111
	public void testGetNumPages() {
112
		assertEquals(6, calculator.getNumPages());
113
	}
114

  
115
	/**
116
	 * Test method for
117
	 * {@link org.gvsig.fmap.dal.feature.paging.impl.AbstractPagingCalculator#getCurrentPageSize()}
118
	 * .
119
	 */
120
	public void testGetCurrentPageSize() {
121
		for (int i = 0; i < calculator.getNumPages() - 1; i++) {
122
			calculator.setCurrentPage(i);
123
			assertEquals(MAX_PAGE_SIZE, calculator.getCurrentPageSize());			
124
		}
125
		calculator.setCurrentPage(calculator.getNumPages() - 1);
126
		assertEquals(SIZE % MAX_PAGE_SIZE, calculator.getCurrentPageSize());
127
	}
128

  
129
	private class TestPagingCalculator extends AbstractPagingCalculator {
130

  
131
		private final long size;
132

  
133
		public TestPagingCalculator(int maxPageSize, long size) {
134
			super(maxPageSize);
135
			this.size = size;
136
		}
137

  
138
		public TestPagingCalculator(int maxPageSize, long currentPage, long size) {
139
			super(maxPageSize, currentPage);
140
			this.size = size;
141
		}
142

  
143
		public long getTotalSize() {
144
			return size;
145
		}
146

  
147
	}
148

  
149
}
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/FeatureReferenceSelection.java
30 30

  
31 31
import org.gvsig.fmap.dal.DataSelection;
32 32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.tools.observer.ComplexObservable;
33 34
import org.gvsig.tools.observer.Observer;
34 35
import org.gvsig.tools.observer.WeakReferencingObservable;
35 36
import org.gvsig.tools.persistence.Persistent;
......
41 42
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
42 43
 */
43 44
public interface FeatureReferenceSelection extends DataSelection, Observer,
44
        WeakReferencingObservable, Persistent {
45
		WeakReferencingObservable, ComplexObservable, Persistent {
45 46

  
46 47
    /**
47 48
     * Adds a feature to the selection.
branches/v2_0_0_prep/libraries/libFMap_dal/src/org/gvsig/fmap/dal/feature/impl/DefaultFeatureSelection.java
49 49
import org.gvsig.tools.persistence.PersistenceManager;
50 50
import org.gvsig.tools.persistence.PersistentState;
51 51
import org.gvsig.tools.persistence.exception.PersistenceException;
52
import org.gvsig.tools.visitor.VisitCanceledException;
52 53
import org.gvsig.tools.visitor.Visitor;
53 54
import org.slf4j.Logger;
54 55
import org.slf4j.LoggerFactory;
......
56 57
/**
57 58
 * Default implementation of the FeatureSelection interface. Internally, only
58 59
 * FeatureReference values are stored.
59
 *
60
 * 
60 61
 * This implementation performs better if used with the selection related
61 62
 * methods: select, deselect and isSelected ones.
62
 *
63
 * 
63 64
 * @author <a href="mailto:cordin@disid.com">C?sar Ordi?ana</a>
64 65
 */
65 66
public class DefaultFeatureSelection extends DefaultFeatureReferenceSelection
66
        implements FeatureSelection {
67
		implements FeatureSelection {
67 68

  
68
    private static final Logger LOGGER = LoggerFactory
69
            .getLogger(DefaultFeatureSelection.class);
69
	private static final Logger LOG = LoggerFactory
70
			.getLogger(DefaultFeatureSelection.class);
70 71

  
71
    private Map featureTypeCounts = new HashMap(1);
72
	private Map featureTypeCounts = new HashMap(1);
72 73

  
73
    /**
74
     * Creates a DefaultFeatureSelection, with a FeatureStore.
75
     *
76
     * @param featureStore
77
     *            the FeatureStore to load Features from
78
     * @throws DataException
79
     *             if there is an error while getting the total number of
80
     *             Features of the Store.
81
     * @see AbstractSetBasedDataSelection#DefaultSelection(int)
82
     */
83
    public DefaultFeatureSelection(DefaultFeatureStore featureStore)
84
            throws DataException {
85
        super(featureStore);
86
    }
74
	/**
75
	 * Creates a DefaultFeatureSelection, with a FeatureStore.
76
	 * 
77
	 * @param featureStore
78
	 *            the FeatureStore to load Features from
79
	 * @throws DataException
80
	 *             if there is an error while getting the total number of
81
	 *             Features of the Store.
82
	 * @see AbstractSetBasedDataSelection#DefaultSelection(int)
83
	 */
84
	public DefaultFeatureSelection(DefaultFeatureStore featureStore)
85
			throws DataException {
86
		super(featureStore);
87
	}
87 88

  
88
    /**
89
     * Creates a new Selection with the total size of Features from which the
90
     * selection will be performed.
91
     *
92
     * @param featureStore
93
     *            the FeatureStore of the selected FeatureReferences
94
     * @param helper
95
     *            to get some information of the Store
96
     * @throws DataException
97
     *             if there is an error while getting the total number of
98
     *             Features of the Store.
99
     */
100
    public DefaultFeatureSelection(FeatureStore featureStore,
101
            FeatureSelectionHelper helper) throws DataException {
102
        super(featureStore, helper);
103
    }
89
	/**
90
	 * Creates a new Selection with the total size of Features from which the
91
	 * selection will be performed.
92
	 * 
93
	 * @param featureStore
94
	 *            the FeatureStore of the selected FeatureReferences
95
	 * @param helper
96
	 *            to get some information of the Store
97
	 * @throws DataException
98
	 *             if there is an error while getting the total number of
99
	 *             Features of the Store.
100
	 */
101
	public DefaultFeatureSelection(FeatureStore featureStore,
102
			FeatureSelectionHelper helper) throws DataException {
103
		super(featureStore, helper);
104
	}
104 105

  
105 106
	/**
106 107
	 * Constructor used by the persistence manager. Don't use directly. After to
......
112 113
		super();
113 114
	}
114 115

  
115
    public boolean select(Feature feature) {
116
        return select(feature, true);
117
    }
116
	public boolean select(Feature feature) {
117
		return select(feature, true);
118
	}
118 119

  
119
    /**
120
     * @see #select(Feature)
121
     * @param undoable
122
     *            if the action must be undoable
123
     */
124
    public boolean select(Feature feature, boolean undoable) {
125
        // TODO: should we check if the feature is from the same FeatureStore??
126
        if (feature == null) {
127
            return false;
128
        }
120
	/**
121
	 * @see #select(Feature)
122
	 * @param undoable
123
	 *            if the action must be undoable
124
	 */
125
	public boolean select(Feature feature, boolean undoable) {
126
		// TODO: should we check if the feature is from the same FeatureStore??
127
		if (feature == null) {
128
			return false;
129
		}
129 130

  
130
//        LOGGER.debug("Selected feature: {}", feature);
131
		// LOGGER.debug("Selected feature: {}", feature);
131 132

  
132
        if (isReversed()) {
133
            removeFeatureTypeCount(feature.getType());
134
        } else {
135
            addFeatureTypeCount(feature.getType());
136
        }
137
        return select(feature.getReference(), undoable);
138
    }
133
		if (isReversed()) {
134
			removeFeatureTypeCount(feature.getType());
135
		} else {
136
			addFeatureTypeCount(feature.getType());
137
		}
138
		return select(feature.getReference(), undoable);
139
	}
139 140

  
140
    public boolean select(FeatureSet features) throws DataException {
141
        return select(features, true);
142
    }
141
	public boolean select(FeatureSet features) throws DataException {
142
		return select(features, true);
143
	}
143 144

  
144
    /**
145
     * @see #select(FeatureSet)
146
     * @param undoable
147
     *            if the action must be undoable
148
     */
149
    public boolean select(FeatureSet features, boolean undoable)
150
            throws DataException {
151
        boolean change = false;
152
        boolean inComplex = false;
153
        if (undoable && getFeatureStore().isEditing()
145
	/**
146
	 * @see #select(FeatureSet)
147
	 * @param undoable
148
	 *            if the action must be undoable
149
	 */
150
	public boolean select(FeatureSet features, boolean undoable)
151
			throws DataException {
152
		boolean change = false;
153
		boolean inComplex = false;
154
		if (undoable && getFeatureStore().isEditing()
154 155
				&& !getCommands().inComplex()) {
155 156
			inComplex = getCommands().inComplex();
156 157
			getCommands().startComplex("_selectionSelectFeatureSet");
157
        }
158
		}
158 159

  
159
        disableNotifications();
160
		disableNotifications();
160 161
		DisposableIterator iter = null;
161 162
		try {
162 163
			for (iter = features.fastIterator(); iter.hasNext();) {
......
164 165
			}
165 166
		} finally {
166 167
			dispose(iter);
167
        }
168
        enableNotifications();
169
        if (undoable && getFeatureStore().isEditing() && !inComplex) {
170
            getCommands().endComplex();
171
        }
172
        if (change) {
173
            notifyObservers(DataStoreNotification.SELECTION_CHANGE);
174
        }
175
        return change;
176
    }
168
		}
169
		enableNotifications();
170
		if (undoable && getFeatureStore().isEditing() && !inComplex) {
171
			getCommands().endComplex();
172
		}
173
		if (change) {
174
			notifyObservers(DataStoreNotification.SELECTION_CHANGE);
175
		}
176
		return change;
177
	}
177 178

  
178
    public boolean deselect(Feature feature) {
179
        return deselect(feature, true);
180
    }
179
	public boolean deselect(Feature feature) {
180
		return deselect(feature, true);
181
	}
181 182

  
182
    /**
183
     * @see #deselect(Feature)
184
     * @param undoable
185
     *            if the action must be undoable
186
     */
187
    public boolean deselect(Feature feature, boolean undoable) {
188
        if (feature == null) {
189
            return false;
190
        }
183
	/**
184
	 * @see #deselect(Feature)
185
	 * @param undoable
186
	 *            if the action must be undoable
187
	 */
188
	public boolean deselect(Feature feature, boolean undoable) {
189
		if (feature == null) {
190
			return false;
191
		}
191 192

  
192
        LOGGER.debug("Deselected feature: {}", feature);
193
		LOG.debug("Deselected feature: {}", feature);
193 194

  
194
        if (isReversed()) {
195
            addFeatureTypeCount(feature.getType());
196
        } else {
197
            removeFeatureTypeCount(feature.getType());
198
        }
199
        return deselect(feature.getReference(), undoable);
200
    }
195
		if (isReversed()) {
196
			addFeatureTypeCount(feature.getType());
197
		} else {
198
			removeFeatureTypeCount(feature.getType());
199
		}
200
		return deselect(feature.getReference(), undoable);
201
	}
201 202

  
202
    public boolean deselect(FeatureSet features) throws DataException {
203
        return deselect(features, true);
204
    }
203
	public boolean deselect(FeatureSet features) throws DataException {
204
		return deselect(features, true);
205
	}
205 206

  
206
    /**
207
     * @see #deselect(FeatureSet)
208
     * @param undoable
209
     *            if the action must be undoable
210
     */
211
    public boolean deselect(FeatureSet features, boolean undoable)
212
            throws DataException {
213
        boolean change = false;
214
        if (undoable && getFeatureStore().isEditing()) {
215
            getCommands().startComplex("_selectionDeselectFeatureSet");
216
        }
217
        disableNotifications();
207
	/**
208
	 * @see #deselect(FeatureSet)
209
	 * @param undoable
210
	 *            if the action must be undoable
211
	 */
212
	public boolean deselect(FeatureSet features, boolean undoable)
213
			throws DataException {
214
		boolean change = false;
215
		if (undoable && getFeatureStore().isEditing()) {
216
			getCommands().startComplex("_selectionDeselectFeatureSet");
217
		}
218
		disableNotifications();
218 219
		DisposableIterator iter = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff