root / branches / v2_0_0_prep / libraries / libFMap_controls / src / org / gvsig / fmap / mapcontrol / dal / feature / swing / FeatureTypesTablePanel.java @ 33205
History | View | Annotate | Download (8.23 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.JLabel; |
28 |
import javax.swing.JPanel; |
29 |
import javax.swing.JSplitPane; |
30 |
import javax.swing.event.ListSelectionEvent; |
31 |
import javax.swing.event.TableModelEvent; |
32 |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
34 |
import org.gvsig.fmap.dal.feature.Feature; |
35 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
36 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
37 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
38 |
import org.gvsig.fmap.dal.feature.FeatureType; |
39 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.ConfigurableFeatureTableModel; |
40 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTypeChangeListener; |
41 |
import org.gvsig.fmap.mapcontrol.dal.feature.swing.table.FeatureTypesControl; |
42 |
import org.gvsig.i18n.Messages; |
43 |
import org.gvsig.tools.exception.BaseException; |
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
/**
|
48 |
* Panel to show a table of Features. It is able to take into account the
|
49 |
* availability of many FeatureTypes, and if it is the case, allows the user to
|
50 |
* select the {@link FeatureType} of the {@link Feature}s to show.
|
51 |
*
|
52 |
* @author 2005- Vicente Caballero
|
53 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
54 |
*/
|
55 |
public class FeatureTypesTablePanel extends JPanel implements |
56 |
FeatureTypeChangeListener { |
57 |
|
58 |
private static final long serialVersionUID = 5857146295213412304L; |
59 |
private static final Logger LOG = |
60 |
LoggerFactory.getLogger(FeatureTypesTablePanel.class); |
61 |
private FeatureTablePanel tablePanel;
|
62 |
private FeatureTypesControl typesControl;
|
63 |
private JSplitPane jSplitPane = null; |
64 |
private JLabel jLabel; |
65 |
private JPanel jPanel; |
66 |
|
67 |
/**
|
68 |
* Constructs a Panel to show a table with the features of a FeatureStore.
|
69 |
*
|
70 |
* @param featureStore
|
71 |
* to extract the features from
|
72 |
* @throws DataException
|
73 |
* if there is an error reading data from the FeatureStore
|
74 |
*/
|
75 |
public FeatureTypesTablePanel(FeatureStore featureStore)
|
76 |
throws DataException {
|
77 |
this(featureStore, true); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Constructs a Panel to show a table with the features of a FeatureStore.
|
82 |
*
|
83 |
* @param featureStore
|
84 |
* to extract the features from
|
85 |
* @param isDoubleBuffered
|
86 |
* a boolean, true for double-buffering, which uses additional
|
87 |
* memory space to achieve fast, flicker-free updates
|
88 |
* @throws DataException
|
89 |
* if there is an error reading data from the FeatureStore
|
90 |
*/
|
91 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
92 |
boolean isDoubleBuffered) throws DataException { |
93 |
this(featureStore, null, isDoubleBuffered); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* @throws DataException
|
98 |
*
|
99 |
*/
|
100 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
101 |
FeatureQuery featureQuery) throws DataException {
|
102 |
this(featureStore, featureQuery, true); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* @param isDoubleBuffered
|
107 |
* @throws DataException
|
108 |
*/
|
109 |
public FeatureTypesTablePanel(FeatureStore featureStore,
|
110 |
FeatureQuery featureQuery, boolean isDoubleBuffered)
|
111 |
throws DataException {
|
112 |
this(
|
113 |
new FeatureTablePanel(featureStore, featureQuery,
|
114 |
isDoubleBuffered), isDoubleBuffered); |
115 |
} |
116 |
|
117 |
public FeatureTypesTablePanel(ConfigurableFeatureTableModel tableModel)
|
118 |
throws DataException {
|
119 |
this(tableModel, true); |
120 |
} |
121 |
|
122 |
public FeatureTypesTablePanel(ConfigurableFeatureTableModel tableModel,
|
123 |
boolean isDoubleBuffered) throws DataException { |
124 |
this(new FeatureTablePanel(tableModel, isDoubleBuffered), |
125 |
isDoubleBuffered); |
126 |
} |
127 |
|
128 |
private FeatureTypesTablePanel(FeatureTablePanel tablePanel,
|
129 |
boolean isDoubleBuffered) throws DataException { |
130 |
super(isDoubleBuffered);
|
131 |
this.tablePanel = tablePanel;
|
132 |
typesControl = new FeatureTypesControl(tablePanel.getFeatureStore());
|
133 |
this.initializeUI();
|
134 |
} |
135 |
|
136 |
private boolean hasManyFeatureTypes() throws DataException { |
137 |
return tablePanel.getFeatureStore().getFeatureTypes().size() > 1; |
138 |
} |
139 |
|
140 |
/**
|
141 |
* @return
|
142 |
* @see org.gvsig.fmap.mapcontrol.dal.feature.swing.FeatureTablePanel#createConfigurationPanel()
|
143 |
*/
|
144 |
public JPanel createConfigurationPanel() { |
145 |
return tablePanel.createConfigurationPanel();
|
146 |
} |
147 |
|
148 |
public void change(FeatureStore featureStore, FeatureType featureType, |
149 |
boolean isDoubleBuffered) throws DataException { |
150 |
FeatureQuery featureQuery = featureStore.createFeatureQuery(); |
151 |
featureQuery.setFeatureType(featureType); |
152 |
tablePanel = |
153 |
new FeatureTablePanel(featureStore, featureQuery,
|
154 |
isDoubleBuffered); |
155 |
getJSplitPane().setRightComponent(tablePanel); |
156 |
} |
157 |
|
158 |
public FeatureTablePanel getTablePanel() {
|
159 |
return tablePanel;
|
160 |
} |
161 |
|
162 |
public FeatureTypesControl getTypesControl() {
|
163 |
return typesControl;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
* Returns the internal Table Model for the Features of the FeatureStore.
|
168 |
*
|
169 |
* @return the internal Table Model
|
170 |
*/
|
171 |
protected ConfigurableFeatureTableModel getTableModel() {
|
172 |
return getTablePanel().getTableModel();
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* This method initializes jPanel
|
177 |
*
|
178 |
* @return javax.swing.JPanel
|
179 |
*/
|
180 |
private void initializeUI() { |
181 |
this.setLayout(new BorderLayout()); |
182 |
this.setSize(new Dimension(331, 251)); |
183 |
this.add(getJSplitPane(), BorderLayout.CENTER); |
184 |
try {
|
185 |
add(getJPanel(), BorderLayout.SOUTH);
|
186 |
} catch (BaseException ex) {
|
187 |
LOG.error("Error creating the panel for the selection count", ex);
|
188 |
} |
189 |
} |
190 |
|
191 |
/**
|
192 |
* This method initializes jSplitPane
|
193 |
*
|
194 |
* @return javax.swing.JSplitPane
|
195 |
*/
|
196 |
private JSplitPane getJSplitPane() { |
197 |
if (jSplitPane == null) { |
198 |
jSplitPane = |
199 |
new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, |
200 |
getTypesControl(), getTablePanel()); |
201 |
jSplitPane.setOneTouchExpandable(true);
|
202 |
jSplitPane.setDividerLocation(0.0d);
|
203 |
try {
|
204 |
if (hasManyFeatureTypes()) {
|
205 |
jSplitPane.setDividerLocation(0.2d);
|
206 |
} |
207 |
} catch (DataException ex) {
|
208 |
LOG.error("Error getting the number of feature types", ex);
|
209 |
} |
210 |
} |
211 |
return jSplitPane;
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* This method initializes jPanel
|
216 |
*
|
217 |
* @return javax.swing.JPanel
|
218 |
* @throws DataException
|
219 |
*/
|
220 |
private JPanel getJPanel() throws BaseException { |
221 |
if (jPanel == null) { |
222 |
|
223 |
jLabel = new JLabel(); |
224 |
// jLabel.setText(Messages.getText("seleccionados") + ": ");
|
225 |
FeatureSelection selection = getFeatureSelection(); |
226 |
jLabel.setText(selection.getSize() + " / "
|
227 |
+ getTableModel().getHelper().getTotalSize() + " "
|
228 |
+ Messages.getText("registros_seleccionados_total") + "."); |
229 |
jPanel = new JPanel(); |
230 |
|
231 |
jPanel.add(jLabel, BorderLayout.EAST);
|
232 |
} |
233 |
return jPanel;
|
234 |
} |
235 |
|
236 |
public void updateSelection() { |
237 |
try {
|
238 |
FeatureSelection selection = |
239 |
(FeatureSelection) getFeatureSelection(); |
240 |
jLabel.setText(selection.getSize() + " / "
|
241 |
+ getTableModel().getRowCount() + " "
|
242 |
+ Messages.getText("registros_seleccionados_total") + "."); |
243 |
} catch (DataException e) {
|
244 |
LOG.error("Unable to update the table selection count", e);
|
245 |
} |
246 |
} |
247 |
|
248 |
private FeatureSelection getFeatureSelection() throws DataException { |
249 |
return getFeatureStore().getFeatureSelection();
|
250 |
} |
251 |
|
252 |
private FeatureStore getFeatureStore() {
|
253 |
return getTableModel().getFeatureStore();
|
254 |
} |
255 |
|
256 |
public void valueChanged(ListSelectionEvent e) { |
257 |
updateSelection(); |
258 |
updateUI(); |
259 |
|
260 |
} |
261 |
|
262 |
public void tableChanged(TableModelEvent e) { |
263 |
updateSelection(); |
264 |
updateUI(); |
265 |
} |
266 |
|
267 |
} |