svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / FeatureTypesTablePanel.java @ 38564
History | View | Annotate | Download (7.65 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; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
|
27 |
import javax.swing.JPanel; |
28 |
import javax.swing.JSplitPane; |
29 |
|
30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.dal.feature.Feature; |
32 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel; |
36 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureStoreModel; |
37 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTypeList; |
38 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.SelectedFeatureTypeChangeListener; |
39 |
import org.gvsig.tools.exception.BaseException; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
/**
|
44 |
* Panel to show a table of Features. It is able to take into account the
|
45 |
* availability of many FeatureTypes, and if it is the case, allows the user to
|
46 |
* select the {@link FeatureType} of the {@link Feature}s to show.
|
47 |
*
|
48 |
* @author 2005- Vicente Caballero
|
49 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
50 |
*/
|
51 |
public class FeatureTypesTablePanel extends JPanel implements |
52 |
SelectedFeatureTypeChangeListener { |
53 |
|
54 |
private static final long serialVersionUID = 5857146295213412304L; |
55 |
private static final Logger LOG = LoggerFactory |
56 |
.getLogger(FeatureTypesTablePanel.class); |
57 |
private FeatureTablePanel tablePanel;
|
58 |
private FeatureTypeList typesControl;
|
59 |
private JSplitPane jSplitPane = null; |
60 |
private final FeatureStoreModel model; |
61 |
|
62 |
/**
|
63 |
* Constructs a Panel to show a table with the features of a FeatureStore.
|
64 |
*
|
65 |
* @param featureStore
|
66 |
* to extract the features from
|
67 |
* @throws BaseException
|
68 |
* if there is an error reading data from the FeatureStore
|
69 |
*/
|
70 |
public FeatureTypesTablePanel(FeatureStore featureStore)
|
71 |
throws BaseException {
|
72 |
this(featureStore, true); |
73 |
} |
74 |
|
75 |
/**
|
76 |
* Constructs a Panel to show a table with the features of a FeatureStore.
|
77 |
*
|
78 |
* @param featureStore
|
79 |
* to extract the features from
|
80 |
* @param isDoubleBuffered
|
81 |
* a boolean, true for double-buffering, which uses additional
|
82 |
* memory space to achieve fast, flicker-free updates
|
83 |
* @throws BaseException
|
84 |
* if there is an error reading data from the FeatureStore
|
85 |
*/
|
86 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
87 |
boolean isDoubleBuffered) throws BaseException { |
88 |
this(featureStore, null, isDoubleBuffered); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* @throws BaseException
|
93 |
*
|
94 |
*/
|
95 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
96 |
FeatureQuery featureQuery) throws BaseException {
|
97 |
this(featureStore, featureQuery, true); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* @param isDoubleBuffered
|
102 |
* @throws BaseException
|
103 |
*/
|
104 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
105 |
FeatureQuery featureQuery, boolean isDoubleBuffered)
|
106 |
throws BaseException {
|
107 |
this(new FeatureStoreModel(featureStore, featureQuery), |
108 |
isDoubleBuffered); |
109 |
} |
110 |
|
111 |
public FeatureTypesTablePanel(FeatureStoreModel model) throws DataException { |
112 |
this(model, true); |
113 |
} |
114 |
|
115 |
public FeatureTypesTablePanel(FeatureStoreModel model,
|
116 |
boolean isDoubleBuffered) throws DataException { |
117 |
super(isDoubleBuffered);
|
118 |
this.model = model;
|
119 |
typesControl = |
120 |
new FeatureTypeList(model.getFeatureStore(),
|
121 |
model.getFeatureQuery()); |
122 |
this.initializeUI();
|
123 |
// Add a listener to change the selection
|
124 |
typesControl.addSelectedFeatureTypeChangeListener(this);
|
125 |
} |
126 |
|
127 |
private boolean hasManyFeatureTypes() throws DataException { |
128 |
return typesControl.getFeatureTypesSize() > 1; |
129 |
} |
130 |
|
131 |
/**
|
132 |
* @return
|
133 |
* @see org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTablePanel#createConfigurationPanel()
|
134 |
*/
|
135 |
public JPanel createConfigurationPanel() { |
136 |
return tablePanel.createConfigurationPanel();
|
137 |
} |
138 |
|
139 |
public void change(FeatureStore featureStore, FeatureType featureType) { |
140 |
if (featureType != null) { |
141 |
showFeatureTypeData(featureType); |
142 |
} |
143 |
} |
144 |
|
145 |
private void showFeatureTypeData(FeatureType featureType) { |
146 |
showFeatureTypeData(featureType.getId()); |
147 |
} |
148 |
|
149 |
private void showFeatureTypeData(String typeId) { |
150 |
this.model.setCurrentFeatureTypeId(typeId);
|
151 |
try {
|
152 |
tablePanel = |
153 |
new FeatureTablePanel(this.model.getCurrentFeatureTableModel()); |
154 |
} catch (BaseException e) {
|
155 |
throw new RuntimeException( |
156 |
"Error creating a new FeatureTablePanel to show "
|
157 |
+ "the selected FeatureType with id: " + typeId, e);
|
158 |
} |
159 |
getJSplitPane().setRightComponent(tablePanel); |
160 |
} |
161 |
|
162 |
public FeatureTablePanel getTablePanel() {
|
163 |
return tablePanel;
|
164 |
} |
165 |
|
166 |
public FeatureTypeList getTypesControl() {
|
167 |
return typesControl;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Sets that the selected Features to be viewed first.
|
172 |
*/
|
173 |
public void setSelectionUp(boolean selectionUp) { |
174 |
getTablePanel().setSelectionUp(selectionUp); |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Returns the internal Table Model for the Features of the FeatureStore.
|
179 |
*
|
180 |
* @return the internal Table Model
|
181 |
*/
|
182 |
protected ConfigurableFeatureTableModel getTableModel() {
|
183 |
return getTablePanel().getTableModel();
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* This method initializes jPanel
|
188 |
*
|
189 |
* @return javax.swing.JPanel
|
190 |
*/
|
191 |
private void initializeUI() { |
192 |
this.setLayout(new BorderLayout()); |
193 |
this.setSize(new Dimension(331, 251)); |
194 |
this.add(getJSplitPane(), BorderLayout.CENTER); |
195 |
showFeatureTypeData(model.getCurrentFeatureTypeId()); |
196 |
} |
197 |
|
198 |
/**
|
199 |
* This method initializes jSplitPane
|
200 |
*
|
201 |
* @return javax.swing.JSplitPane
|
202 |
*/
|
203 |
private JSplitPane getJSplitPane() { |
204 |
if (jSplitPane == null) { |
205 |
jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); |
206 |
jSplitPane.setLeftComponent(getTypesControl()); |
207 |
jSplitPane.setOneTouchExpandable(true);
|
208 |
try {
|
209 |
if (hasManyFeatureTypes()) {
|
210 |
jSplitPane.setDividerLocation(0.2d);
|
211 |
} else {
|
212 |
jSplitPane.setDividerLocation(0.0d);
|
213 |
} |
214 |
} catch (DataException ex) {
|
215 |
LOG.error("Error getting the number of feature types", ex);
|
216 |
} |
217 |
} |
218 |
return jSplitPane;
|
219 |
} |
220 |
|
221 |
} |