root / branches / v2_0_0_prep / extensions / org.gvsig.daltransform.app.mainplugin / src / main / java / org / gvsig / daltransform / swing / impl / DefaultJDialogDataTransformList.java @ 38552
History | View | Annotate | Download (13 KB)
1 | 35519 | nfrancisco | /* 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.daltransform.swing.impl; |
||
23 | |||
24 | 35605 | nfrancisco | import java.awt.Dimension; |
25 | import java.awt.FlowLayout; |
||
26 | import java.awt.event.ActionEvent; |
||
27 | 36000 | nfrancisco | import java.awt.event.ActionListener; |
28 | 35605 | nfrancisco | import java.beans.PropertyChangeListener; |
29 | 36000 | nfrancisco | import java.util.ArrayList; |
30 | import java.util.List; |
||
31 | 35605 | nfrancisco | |
32 | import javax.swing.Action; |
||
33 | 36674 | nfrancisco | import javax.swing.ComboBoxModel; |
34 | 35605 | nfrancisco | import javax.swing.JButton; |
35 | 36000 | nfrancisco | import javax.swing.JComboBox; |
36 | 36185 | nfrancisco | import javax.swing.JLabel; |
37 | 35605 | nfrancisco | import javax.swing.JPanel; |
38 | 36185 | nfrancisco | import javax.swing.JScrollPane; |
39 | 35740 | nfrancisco | import javax.swing.border.EmptyBorder; |
40 | 36674 | nfrancisco | import javax.swing.event.ListDataListener; |
41 | 36000 | nfrancisco | import javax.swing.event.ListSelectionEvent; |
42 | import javax.swing.event.ListSelectionListener; |
||
43 | 35519 | nfrancisco | |
44 | 36000 | nfrancisco | import org.gvsig.app.ApplicationLocator; |
45 | import org.gvsig.app.ApplicationManager; |
||
46 | 36674 | nfrancisco | import org.gvsig.app.project.Project; |
47 | 36000 | nfrancisco | import org.gvsig.app.project.documents.Document; |
48 | 36674 | nfrancisco | import org.gvsig.app.project.documents.table.TableDocument; |
49 | import org.gvsig.app.project.documents.table.TableManager; |
||
50 | 36000 | nfrancisco | import org.gvsig.app.project.documents.view.ViewDocument; |
51 | import org.gvsig.app.project.documents.view.ViewManager; |
||
52 | 35605 | nfrancisco | import org.gvsig.daltransform.DataTransformLocator; |
53 | import org.gvsig.daltransform.swing.JDataTransformList; |
||
54 | 35519 | nfrancisco | import org.gvsig.daltransform.swing.JDialogDataTransformList; |
55 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
56 | 36000 | nfrancisco | import org.gvsig.fmap.dal.feature.FeatureStoreTransforms; |
57 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
58 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
59 | 37817 | jpiera | import org.gvsig.i18n.Messages; |
60 | 35605 | nfrancisco | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
61 | import org.gvsig.tools.swing.api.usability.UsabilitySwingManager; |
||
62 | 35519 | nfrancisco | |
63 | /**
|
||
64 | * @author gvSIG Team
|
||
65 | * @version $Id$
|
||
66 | *
|
||
67 | */
|
||
68 | public class DefaultJDialogDataTransformList extends JDialogDataTransformList { |
||
69 | |||
70 | 35605 | nfrancisco | private static final long serialVersionUID = 8666781163497235054L; |
71 | 36000 | nfrancisco | private JDataTransformList transforms = null; |
72 | 36185 | nfrancisco | |
73 | private JButton botonEliminar; |
||
74 | 36000 | nfrancisco | private JButton botonCerrar; |
75 | private JComboBox comboBox; |
||
76 | 35740 | nfrancisco | |
77 | 36000 | nfrancisco | public DefaultJDialogDataTransformList() {
|
78 | 35519 | nfrancisco | super();
|
79 | initComponents(); |
||
80 | 36000 | nfrancisco | createGUI(); |
81 | 35519 | nfrancisco | } |
82 | |||
83 | 36674 | nfrancisco | private class MyComboBoxItem { |
84 | 36743 | nfrancisco | |
85 | 36674 | nfrancisco | private String label; |
86 | private FeatureStore store;
|
||
87 | 35740 | nfrancisco | |
88 | 36674 | nfrancisco | MyComboBoxItem(String label, FeatureStore store) {
|
89 | this.label = label;
|
||
90 | this.store = store;
|
||
91 | } |
||
92 | 36743 | nfrancisco | |
93 | @Override
|
||
94 | 36674 | nfrancisco | public String toString() { |
95 | return label;
|
||
96 | } |
||
97 | 36743 | nfrancisco | |
98 | 36674 | nfrancisco | public FeatureStore getStore() {
|
99 | 36743 | nfrancisco | return this.store; |
100 | 36674 | nfrancisco | } |
101 | } |
||
102 | 36743 | nfrancisco | |
103 | 36674 | nfrancisco | private class MyComboBoxModel implements ComboBoxModel { |
104 | 35740 | nfrancisco | |
105 | 36674 | nfrancisco | private List<MyComboBoxItem> items = new ArrayList<MyComboBoxItem>(); |
106 | private MyComboBoxItem selected = null; |
||
107 | 36743 | nfrancisco | |
108 | 36674 | nfrancisco | public MyComboBoxModel(List<MyComboBoxItem> items) { |
109 | this.items.addAll(items);
|
||
110 | } |
||
111 | 36743 | nfrancisco | |
112 | 36674 | nfrancisco | public Object getSelectedItem() { |
113 | return this.selected; |
||
114 | } |
||
115 | 35740 | nfrancisco | |
116 | 36674 | nfrancisco | public MyComboBoxItem getSelected() {
|
117 | return this.selected; |
||
118 | } |
||
119 | 36000 | nfrancisco | |
120 | 36674 | nfrancisco | public void setSelectedItem(Object arg0) { |
121 | this.selected = (MyComboBoxItem) arg0;
|
||
122 | 36000 | nfrancisco | } |
123 | |||
124 | 36674 | nfrancisco | public Object getElementAt(int arg0) { |
125 | return this.items.get(arg0); |
||
126 | } |
||
127 | 36000 | nfrancisco | |
128 | 36674 | nfrancisco | public MyComboBoxItem get(int arg0) { |
129 | return this.items.get(arg0); |
||
130 | } |
||
131 | 36743 | nfrancisco | |
132 | 36674 | nfrancisco | public int getSize() { |
133 | return this.items.size(); |
||
134 | } |
||
135 | |||
136 | public void removeListDataListener(ListDataListener arg0) { |
||
137 | // TODO Auto-generated method stub
|
||
138 | 36743 | nfrancisco | |
139 | 36674 | nfrancisco | } |
140 | 36743 | nfrancisco | |
141 | 36674 | nfrancisco | public void addListDataListener(ListDataListener arg0) { |
142 | // TODO Auto-generated method stub
|
||
143 | 36743 | nfrancisco | |
144 | 36674 | nfrancisco | } |
145 | |||
146 | } |
||
147 | 36743 | nfrancisco | |
148 | 36674 | nfrancisco | private void initComponents() { |
149 | MyComboBoxModel comboModel = new MyComboBoxModel(getAllStores());
|
||
150 | 36743 | nfrancisco | |
151 | 36674 | nfrancisco | comboBox = new JComboBox(comboModel); |
152 | 36743 | nfrancisco | |
153 | 36000 | nfrancisco | comboBox.addActionListener(new ActionListener() { |
154 | |||
155 | public void actionPerformed(ActionEvent e) { |
||
156 | JComboBox jcmbType = (JComboBox) e.getSource(); |
||
157 | 36674 | nfrancisco | MyComboBoxModel model = (MyComboBoxModel) jcmbType.getModel(); |
158 | updatePanel(model.getSelected().getStore()); |
||
159 | 36000 | nfrancisco | } |
160 | }); |
||
161 | |||
162 | 36742 | nfrancisco | if (comboModel.getSize() > 0) { |
163 | 36000 | nfrancisco | transforms = |
164 | DataTransformLocator.getDataTransformManager() |
||
165 | 36742 | nfrancisco | .createJDataTransformList(comboModel.get(0).getStore());
|
166 | 36743 | nfrancisco | comboModel.setSelectedItem(comboModel.get(0));
|
167 | } |
||
168 | 36185 | nfrancisco | if (transforms != null) { |
169 | transforms.addListSelectionListener(new ListSelectionHandler());
|
||
170 | } |
||
171 | } |
||
172 | 36000 | nfrancisco | |
173 | 36674 | nfrancisco | private List<MyComboBoxItem> getAllStores() { |
174 | List<MyComboBoxItem> stores = new ArrayList<MyComboBoxItem>(); |
||
175 | ApplicationManager application = ApplicationLocator.getManager(); |
||
176 | Project project = application.getCurrentProject(); |
||
177 | |||
178 | List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
||
179 | for (Document doc : views) { |
||
180 | ViewDocument viewDocument = (ViewDocument) doc; |
||
181 | |||
182 | 36743 | nfrancisco | FLayer[] layers =
|
183 | viewDocument.getMapContext().getLayers().getVisibles(); |
||
184 | 36742 | nfrancisco | if (layers.length > 1) { |
185 | 36674 | nfrancisco | for (int i = 1; i < layers.length; i++) { |
186 | 36743 | nfrancisco | if (layers[i] instanceof FLyrVect) { |
187 | 36674 | nfrancisco | FLyrVect layer = (FLyrVect) layers[i]; |
188 | 36743 | nfrancisco | stores.add(new MyComboBoxItem(layer.getName(), layer
|
189 | .getFeatureStore())); |
||
190 | 36674 | nfrancisco | } |
191 | } |
||
192 | } |
||
193 | } |
||
194 | List<Document> tables = project.getDocuments(TableManager.TYPENAME); |
||
195 | for (Document doc : tables) { |
||
196 | TableDocument tableDocument = (TableDocument) doc; |
||
197 | 36743 | nfrancisco | stores.add(new MyComboBoxItem(doc.getName(), tableDocument
|
198 | .getStore())); |
||
199 | 36674 | nfrancisco | } |
200 | 36743 | nfrancisco | |
201 | return stores;
|
||
202 | 36674 | nfrancisco | } |
203 | 36743 | nfrancisco | |
204 | 36185 | nfrancisco | private void createGUI() { |
205 | 36000 | nfrancisco | |
206 | 36185 | nfrancisco | java.awt.GridBagConstraints gridBagConstraints; |
207 | this.setLayout(new java.awt.GridBagLayout()); |
||
208 | |||
209 | // Add an empty margin
|
||
210 | this.setBorder(new EmptyBorder(15, 15, 15, 15)); |
||
211 | |||
212 | 36000 | nfrancisco | UsabilitySwingManager usabilitymanager = |
213 | ToolsSwingLocator.getUsabilitySwingManager(); |
||
214 | 36185 | nfrancisco | |
215 | 37817 | jpiera | JLabel layerText = new JLabel(Messages.getText("select_layer")); |
216 | JLabel transformText = new JLabel(Messages.getText("select_transform")); |
||
217 | 35605 | nfrancisco | JPanel botones = new JPanel(); |
218 | 36185 | nfrancisco | |
219 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
220 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
||
221 | gridBagConstraints.gridx = 0;
|
||
222 | gridBagConstraints.gridy = 0;
|
||
223 | gridBagConstraints.weightx = 0.0;
|
||
224 | gridBagConstraints.weighty = 0.0;
|
||
225 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
||
226 | this.add(layerText, gridBagConstraints);
|
||
227 | |||
228 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
229 | gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
230 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
||
231 | gridBagConstraints.gridx = 0;
|
||
232 | gridBagConstraints.gridy = 1;
|
||
233 | 37817 | jpiera | gridBagConstraints.weightx = 1.0;
|
234 | 36185 | nfrancisco | gridBagConstraints.weighty = 0.0;
|
235 | gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5); |
||
236 | this.add(comboBox, gridBagConstraints);
|
||
237 | |||
238 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
239 | gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; |
||
240 | gridBagConstraints.gridx = 0;
|
||
241 | gridBagConstraints.gridy = 2;
|
||
242 | gridBagConstraints.weightx = 0.0;
|
||
243 | gridBagConstraints.weighty = 0.0;
|
||
244 | gridBagConstraints.insets = new java.awt.Insets(10, 2, 5, 2); |
||
245 | this.add(transformText, gridBagConstraints);
|
||
246 | |||
247 | gridBagConstraints = new java.awt.GridBagConstraints();
|
||
248 | gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; |
||
249 | gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; |
||
250 | gridBagConstraints.gridx = 0;
|
||
251 | gridBagConstraints.gridy = 3;
|
||
252 | 37817 | jpiera | gridBagConstraints.weightx = 1.0;
|
253 | 36185 | nfrancisco | gridBagConstraints.weighty = 1.0;
|
254 | gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2); |
||
255 | if (transforms != null) { |
||
256 | JScrollPane scroller = new JScrollPane(transforms); |
||
257 | this.add(scroller, gridBagConstraints);
|
||
258 | } else {
|
||
259 | JPanel emptyPanel = new JPanel(); |
||
260 | this.add(emptyPanel, gridBagConstraints);
|
||
261 | } |
||
262 | |||
263 | 35740 | nfrancisco | botones.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 0)); |
264 | 36185 | nfrancisco | botonCerrar = usabilitymanager.createJButton(new ActionClose(this)); |
265 | 37817 | jpiera | botonCerrar.setText(Messages.getText("close"));
|
266 | 35740 | nfrancisco | botonEliminar = usabilitymanager.createJButton(new ActionRemove(this)); |
267 | 37817 | jpiera | botonEliminar.setText(Messages.getText("remove"));
|
268 | 35605 | nfrancisco | botones.add(botonEliminar); |
269 | botones.add(botonCerrar); |
||
270 | 36000 | nfrancisco | botonEliminar.setEnabled(false);
|
271 | |||
272 | 36185 | nfrancisco | gridBagConstraints = new java.awt.GridBagConstraints();
|
273 | gridBagConstraints.gridx = 0;
|
||
274 | gridBagConstraints.gridy = 4;
|
||
275 | gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH; |
||
276 | gridBagConstraints.weightx = 0.0;
|
||
277 | gridBagConstraints.weighty = 0.0;
|
||
278 | gridBagConstraints.insets = new java.awt.Insets(10, 2, 2, 2); |
||
279 | this.add(botones, gridBagConstraints);
|
||
280 | |||
281 | botonEliminar.setEnabled(false);
|
||
282 | |||
283 | 36674 | nfrancisco | updatePanel(null);
|
284 | 35605 | nfrancisco | } |
285 | 35519 | nfrancisco | |
286 | 36000 | nfrancisco | class ListSelectionHandler implements ListSelectionListener { |
287 | |||
288 | public void valueChanged(ListSelectionEvent e) { |
||
289 | |||
290 | if ((transforms != null) && (transforms.getSelected() != null)) { |
||
291 | if (transforms.isLastTransform(transforms.getSelected())) {
|
||
292 | botonEliminar.setEnabled(true);
|
||
293 | return;
|
||
294 | } |
||
295 | } |
||
296 | botonEliminar.setEnabled(false);
|
||
297 | } |
||
298 | |||
299 | } |
||
300 | |||
301 | @Override
|
||
302 | 35605 | nfrancisco | public Dimension getPreferredSize() { |
303 | return new Dimension(250, 300); |
||
304 | } |
||
305 | 35740 | nfrancisco | |
306 | 35605 | nfrancisco | private class ActionRemove implements Action { |
307 | 35519 | nfrancisco | |
308 | 35605 | nfrancisco | private DefaultJDialogDataTransformList parent;
|
309 | 35519 | nfrancisco | |
310 | 35605 | nfrancisco | public ActionRemove(DefaultJDialogDataTransformList parent) {
|
311 | this.parent = parent;
|
||
312 | } |
||
313 | 35740 | nfrancisco | |
314 | 35605 | nfrancisco | public void addPropertyChangeListener(PropertyChangeListener listener) { |
315 | } |
||
316 | 35519 | nfrancisco | |
317 | 35605 | nfrancisco | public Object getValue(String key) { |
318 | return null; |
||
319 | } |
||
320 | 35519 | nfrancisco | |
321 | 35605 | nfrancisco | public boolean isEnabled() { |
322 | 36000 | nfrancisco | return true; |
323 | 35605 | nfrancisco | } |
324 | |||
325 | public void putValue(String key, Object value) { |
||
326 | } |
||
327 | |||
328 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
||
329 | } |
||
330 | |||
331 | public void setEnabled(boolean b) { |
||
332 | } |
||
333 | |||
334 | public void actionPerformed(ActionEvent e) { |
||
335 | 35740 | nfrancisco | if (this.parent.transforms.getSelected() != null) { |
336 | this.parent.transforms.remove(this.parent.transforms |
||
337 | .getSelected()); |
||
338 | } |
||
339 | 36674 | nfrancisco | updatePanel(null);
|
340 | 35605 | nfrancisco | } |
341 | 35740 | nfrancisco | |
342 | 35519 | nfrancisco | } |
343 | 35740 | nfrancisco | |
344 | 35605 | nfrancisco | private class ActionClose implements Action { |
345 | 35519 | nfrancisco | |
346 | 35605 | nfrancisco | private DefaultJDialogDataTransformList parent;
|
347 | |||
348 | public ActionClose(DefaultJDialogDataTransformList parent) {
|
||
349 | this.parent = parent;
|
||
350 | } |
||
351 | 35740 | nfrancisco | |
352 | 35605 | nfrancisco | public void addPropertyChangeListener(PropertyChangeListener listener) { |
353 | } |
||
354 | |||
355 | public Object getValue(String key) { |
||
356 | return null; |
||
357 | } |
||
358 | |||
359 | public boolean isEnabled() { |
||
360 | return true; |
||
361 | } |
||
362 | |||
363 | public void putValue(String key, Object value) { |
||
364 | } |
||
365 | |||
366 | public void removePropertyChangeListener(PropertyChangeListener listener) { |
||
367 | } |
||
368 | |||
369 | public void setEnabled(boolean b) { |
||
370 | } |
||
371 | |||
372 | public void actionPerformed(ActionEvent e) { |
||
373 | this.parent.setVisible(false); |
||
374 | } |
||
375 | 35740 | nfrancisco | |
376 | 35605 | nfrancisco | } |
377 | 35740 | nfrancisco | |
378 | 36674 | nfrancisco | private void updatePanel(FeatureStore store) { |
379 | 36000 | nfrancisco | |
380 | 36674 | nfrancisco | if (transforms != null) { |
381 | 36000 | nfrancisco | |
382 | 36674 | nfrancisco | if (store != null) { |
383 | FeatureStoreTransforms layerTransforms = store.getTransforms(); |
||
384 | |||
385 | transforms.changeStore(store); |
||
386 | transforms.removeAllTransforms(); |
||
387 | transforms.addTransforms(layerTransforms); |
||
388 | } |
||
389 | |||
390 | // disable the remove button if the transforms list is empty
|
||
391 | 36000 | nfrancisco | if (transforms.getSelected() != null) { |
392 | botonEliminar.setEnabled(transforms.getTransformsCount() > 0);
|
||
393 | } |
||
394 | 36674 | nfrancisco | |
395 | 36000 | nfrancisco | } else {
|
396 | botonEliminar.setEnabled(false);
|
||
397 | } |
||
398 | |||
399 | 35519 | nfrancisco | } |
400 | |||
401 | 36000 | nfrancisco | @Override
|
402 | 35740 | nfrancisco | public void setDeleteButton(boolean active) { |
403 | botonEliminar.setEnabled(active); |
||
404 | 35519 | nfrancisco | } |
405 | |||
406 | } |