root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / table / FeatureTypeListModel.java @ 38564
History | View | Annotate | Download (4.56 KB)
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.mapcontrol.dal.feature.swing.table; |
23 |
|
24 |
import java.util.List; |
25 |
|
26 |
import javax.swing.AbstractListModel; |
27 |
|
28 |
import org.gvsig.fmap.dal.exception.DataException; |
29 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
31 |
import org.gvsig.fmap.dal.feature.FeatureStoreNotification; |
32 |
import org.gvsig.fmap.dal.feature.FeatureType; |
33 |
import org.gvsig.tools.observer.Observable; |
34 |
import org.gvsig.tools.observer.Observer; |
35 |
|
36 |
/**
|
37 |
* Model to be used by components showing a list of {@link FeatureType}s.
|
38 |
*
|
39 |
* @author gvSIG Team
|
40 |
* @version $Id$
|
41 |
*/
|
42 |
public class FeatureTypeListModel extends AbstractListModel implements Observer { |
43 |
|
44 |
private static final long serialVersionUID = -4274815135770376868L; |
45 |
private final FeatureStore featureStore; |
46 |
private final FeatureQuery featureQuery; |
47 |
|
48 |
/**
|
49 |
* Constructs a {@link FeatureTypeListModel}.
|
50 |
*
|
51 |
* @param featureStore
|
52 |
* to get the {@link FeatureType}s from
|
53 |
* @param featureQuery
|
54 |
* to get the FeatureType to filter if any
|
55 |
*/
|
56 |
public FeatureTypeListModel(FeatureStore featureStore,
|
57 |
FeatureQuery featureQuery) { |
58 |
this.featureStore = featureStore;
|
59 |
this.featureQuery = featureQuery;
|
60 |
this.featureStore.addObserver(this); |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Returns the number of {@link FeatureType} to show.
|
65 |
*/
|
66 |
public int getSize() { |
67 |
return queryHasFeatureType() ? 1 : getFeatureTypes().size(); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Returns if the query has a {@link FeatureType} to filter with.
|
72 |
*
|
73 |
* @return if the query has a {@link FeatureType} to filter with
|
74 |
*/
|
75 |
private boolean queryHasFeatureType() { |
76 |
return featureQuery != null && featureQuery.getFeatureTypeId() != null; |
77 |
} |
78 |
|
79 |
@SuppressWarnings("unchecked") |
80 |
private List<FeatureType> getFeatureTypes() { |
81 |
try {
|
82 |
return featureStore.getFeatureTypes();
|
83 |
} catch (DataException e) {
|
84 |
throw new RuntimeException( |
85 |
"Error getting the feature types of the FeatureStore: "
|
86 |
+ featureStore, e); |
87 |
} |
88 |
} |
89 |
|
90 |
public Object getElementAt(int index) { |
91 |
return queryHasFeatureType() ? featureQuery.getFeatureTypeId()
|
92 |
: getFeatureTypes().get(index).getId(); |
93 |
} |
94 |
|
95 |
public void update(Observable observable, Object notification) { |
96 |
if (observable.equals(this.featureStore) |
97 |
&& notification instanceof FeatureStoreNotification) {
|
98 |
FeatureStoreNotification fsNotification = |
99 |
(FeatureStoreNotification) notification; |
100 |
String type = fsNotification.getType();
|
101 |
|
102 |
if (FeatureStoreNotification.AFTER_UPDATE_TYPE.equals(type)) {
|
103 |
if (queryHasFeatureType()) {
|
104 |
fireContentsChanged(this, 0, 0); |
105 |
} else {
|
106 |
FeatureType featureType = fsNotification.getFeatureType(); |
107 |
int index = getFeatureTypes().indexOf(featureType);
|
108 |
fireContentsChanged(this, index, index);
|
109 |
} |
110 |
} |
111 |
} |
112 |
} |
113 |
|
114 |
/**
|
115 |
*
|
116 |
* Returns the {@link FeatureStore}
|
117 |
*
|
118 |
* @return the featureStore
|
119 |
*/
|
120 |
public FeatureStore getFeatureStore() {
|
121 |
return featureStore;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Returns the {@link FeatureType} with the given identifier.
|
126 |
*
|
127 |
* @param featureTypeId
|
128 |
* identifier of the {@link FeatureType}
|
129 |
* @return a {@link FeatureType}
|
130 |
*/
|
131 |
public FeatureType getFeatureType(String featureTypeId) { |
132 |
try {
|
133 |
return featureStore.getFeatureType(featureTypeId);
|
134 |
} catch (DataException e) {
|
135 |
throw new FeatureTypeListException(e); |
136 |
} |
137 |
} |
138 |
|
139 |
} |