root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / table / FeatureStoreModel.java @ 38564
History | View | Annotate | Download (5.48 KB)
1 | 36479 | cordinyana | /* 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.HashMap; |
||
25 | import java.util.Map; |
||
26 | |||
27 | import javax.swing.table.TableModel; |
||
28 | |||
29 | import org.gvsig.fmap.dal.exception.DataException; |
||
30 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
31 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
32 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
33 | import org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTypesTablePanel; |
||
34 | import org.gvsig.tools.exception.BaseException; |
||
35 | |||
36 | /**
|
||
37 | * A model for the {@link FeatureTypesTablePanel} which unifies the access
|
||
38 | * to the different models needed by the components included into it.
|
||
39 | *
|
||
40 | * @author gvSIG Team
|
||
41 | * @version $Id$
|
||
42 | */
|
||
43 | public class FeatureStoreModel { |
||
44 | |||
45 | private final FeatureStore featureStore; |
||
46 | private final FeatureQuery featureQuery; |
||
47 | private final FeatureTypeListModel featureTypeListModel; |
||
48 | private final Map<String, ConfigurableFeatureTableModel> type2TableModel = |
||
49 | new HashMap<String, ConfigurableFeatureTableModel>(); |
||
50 | private String currentFeatureTypeId; |
||
51 | |||
52 | /**
|
||
53 | * Constructor.
|
||
54 | *
|
||
55 | * @param store
|
||
56 | * the FeatureStore to get data from
|
||
57 | * @param query
|
||
58 | * the FeatureQuery to use to get data
|
||
59 | * @throws DataException
|
||
60 | * if there is an error getting the default {@link FeatureType}
|
||
61 | */
|
||
62 | public FeatureStoreModel(FeatureStore store, FeatureQuery query)
|
||
63 | throws DataException {
|
||
64 | this.featureStore = store;
|
||
65 | this.featureQuery = query;
|
||
66 | this.featureTypeListModel = new FeatureTypeListModel(store, query); |
||
67 | |||
68 | this.currentFeatureTypeId =
|
||
69 | query.getFeatureTypeId() == null ? store.getDefaultFeatureType()
|
||
70 | .getId() : query.getFeatureTypeId(); |
||
71 | } |
||
72 | |||
73 | /**
|
||
74 | * Constructor.
|
||
75 | *
|
||
76 | * @param store
|
||
77 | * the FeatureStore to get data from
|
||
78 | * @throws DataException
|
||
79 | * if there is an error getting the default {@link FeatureType}
|
||
80 | */
|
||
81 | public FeatureStoreModel(FeatureStore store) throws DataException { |
||
82 | this(store, null); |
||
83 | } |
||
84 | |||
85 | /**
|
||
86 | * Returns the {@link FeatureTypeListModel} to show a list of available
|
||
87 | * {@link FeatureType}s.
|
||
88 | *
|
||
89 | * @return the {@link FeatureTypeListModel} to show a list of available
|
||
90 | * {@link FeatureType}s
|
||
91 | */
|
||
92 | public FeatureTypeListModel getFeatureTypeListModel() {
|
||
93 | return featureTypeListModel;
|
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * Returns the {@link TableModel} to use to show data of the current feature
|
||
98 | * type.
|
||
99 | *
|
||
100 | * @return the TableModel to use
|
||
101 | */
|
||
102 | public ConfigurableFeatureTableModel getCurrentFeatureTableModel() {
|
||
103 | return getFeatureTableModel(this.currentFeatureTypeId); |
||
104 | } |
||
105 | |||
106 | /**
|
||
107 | * Returns the {@link TableModel} to use to show data of a
|
||
108 | * {@link FeatureType}.
|
||
109 | *
|
||
110 | * @param type
|
||
111 | * to use to filter the data
|
||
112 | * @return the TableModel to use
|
||
113 | */
|
||
114 | public ConfigurableFeatureTableModel getFeatureTableModel(FeatureType type) {
|
||
115 | return getFeatureTableModel(type.getId());
|
||
116 | } |
||
117 | |||
118 | /**
|
||
119 | * Returns the {@link TableModel} to use to show data of a
|
||
120 | * {@link FeatureType}.
|
||
121 | *
|
||
122 | * @param typeId
|
||
123 | * the id of the {@link FeatureType} to use to filter the data
|
||
124 | * @return the TableModel to use
|
||
125 | */
|
||
126 | public ConfigurableFeatureTableModel getFeatureTableModel(String typeId) { |
||
127 | ConfigurableFeatureTableModel tableModel = type2TableModel.get(typeId); |
||
128 | if (tableModel == null) { |
||
129 | try {
|
||
130 | tableModel = |
||
131 | new ConfigurableFeatureTableModel(featureStore,
|
||
132 | featureQuery); |
||
133 | type2TableModel.put(typeId, tableModel); |
||
134 | } catch (BaseException e) {
|
||
135 | throw new RuntimeException("Error creating a table model", e); |
||
136 | } |
||
137 | } |
||
138 | return tableModel;
|
||
139 | } |
||
140 | |||
141 | /**
|
||
142 | * Sets the id of the current {@link FeatureType}.
|
||
143 | *
|
||
144 | * @param currentFeatureTypeId
|
||
145 | * the id of the current {@link FeatureType}
|
||
146 | */
|
||
147 | public void setCurrentFeatureTypeId(String currentFeatureTypeId) { |
||
148 | this.currentFeatureTypeId = currentFeatureTypeId;
|
||
149 | } |
||
150 | |||
151 | /**
|
||
152 | * Returns the id of the current {@link FeatureType}.
|
||
153 | *
|
||
154 | * @return the id of the current {@link FeatureType}
|
||
155 | */
|
||
156 | public String getCurrentFeatureTypeId() { |
||
157 | return currentFeatureTypeId;
|
||
158 | } |
||
159 | |||
160 | /**
|
||
161 | * @return the featureQuery
|
||
162 | */
|
||
163 | public FeatureQuery getFeatureQuery() {
|
||
164 | return featureQuery;
|
||
165 | } |
||
166 | |||
167 | /**
|
||
168 | * @return the featureStore
|
||
169 | */
|
||
170 | public FeatureStore getFeatureStore() {
|
||
171 | return featureStore;
|
||
172 | } |
||
173 | } |