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