30 |
30 |
import java.util.List;
|
31 |
31 |
|
32 |
32 |
import javax.swing.Action;
|
|
33 |
import javax.swing.ComboBoxModel;
|
33 |
34 |
import javax.swing.JButton;
|
34 |
35 |
import javax.swing.JComboBox;
|
35 |
36 |
import javax.swing.JLabel;
|
36 |
37 |
import javax.swing.JPanel;
|
37 |
38 |
import javax.swing.JScrollPane;
|
38 |
39 |
import javax.swing.border.EmptyBorder;
|
|
40 |
import javax.swing.event.ListDataListener;
|
39 |
41 |
import javax.swing.event.ListSelectionEvent;
|
40 |
42 |
import javax.swing.event.ListSelectionListener;
|
41 |
43 |
|
42 |
44 |
import org.gvsig.app.ApplicationLocator;
|
43 |
45 |
import org.gvsig.app.ApplicationManager;
|
|
46 |
import org.gvsig.app.project.Project;
|
44 |
47 |
import org.gvsig.app.project.documents.Document;
|
|
48 |
import org.gvsig.app.project.documents.table.TableDocument;
|
|
49 |
import org.gvsig.app.project.documents.table.TableManager;
|
45 |
50 |
import org.gvsig.app.project.documents.view.ViewDocument;
|
46 |
51 |
import org.gvsig.app.project.documents.view.ViewManager;
|
47 |
52 |
import org.gvsig.daltransform.DataTransformLocator;
|
... | ... | |
63 |
68 |
|
64 |
69 |
private static final long serialVersionUID = 8666781163497235054L;
|
65 |
70 |
private JDataTransformList transforms = null;
|
66 |
|
private FLayer[] layers;
|
67 |
|
private FLyrVect layer;
|
|
71 |
// private FLayer[] layers;
|
|
72 |
// private FLyrVect layer;
|
68 |
73 |
|
69 |
74 |
private JButton botonEliminar;
|
70 |
75 |
private JButton botonCerrar;
|
... | ... | |
76 |
81 |
createGUI();
|
77 |
82 |
}
|
78 |
83 |
|
79 |
|
private void initComponents() {
|
|
84 |
private class MyComboBoxItem {
|
|
85 |
private String label;
|
|
86 |
private FeatureStore store;
|
80 |
87 |
|
81 |
|
ApplicationManager application = ApplicationLocator.getManager();
|
82 |
|
Document doc = application.getActiveDocument(ViewManager.TYPENAME);
|
83 |
|
ViewDocument viewDocument = (ViewDocument) doc;
|
|
88 |
MyComboBoxItem(String label, FeatureStore store) {
|
|
89 |
this.label = label;
|
|
90 |
this.store = store;
|
|
91 |
}
|
|
92 |
|
|
93 |
public String toString() {
|
|
94 |
return label;
|
|
95 |
}
|
|
96 |
|
|
97 |
public FeatureStore getStore() {
|
|
98 |
return this.store;
|
|
99 |
}
|
|
100 |
}
|
|
101 |
|
|
102 |
|
|
103 |
private class MyComboBoxModel implements ComboBoxModel {
|
84 |
104 |
|
85 |
|
layers = viewDocument.getMapContext().getLayers().getVisibles();
|
|
105 |
private List<MyComboBoxItem> items = new ArrayList<MyComboBoxItem>();
|
|
106 |
private MyComboBoxItem selected = null;
|
|
107 |
|
|
108 |
public MyComboBoxModel(List<MyComboBoxItem> items) {
|
|
109 |
this.items.addAll(items);
|
|
110 |
}
|
|
111 |
|
|
112 |
public Object getSelectedItem() {
|
|
113 |
return this.selected;
|
|
114 |
}
|
86 |
115 |
|
87 |
|
List<String> lista = new ArrayList<String>();
|
|
116 |
public MyComboBoxItem getSelected() {
|
|
117 |
return this.selected;
|
|
118 |
}
|
88 |
119 |
|
89 |
|
if (layers.length > 0) {
|
90 |
|
for (int i = 1; i < layers.length; i++) {
|
91 |
|
lista.add(layers[i].getName());
|
92 |
|
}
|
|
120 |
public void setSelectedItem(Object arg0) {
|
|
121 |
this.selected = (MyComboBoxItem) arg0;
|
93 |
122 |
}
|
94 |
123 |
|
95 |
|
comboBox = new JComboBox(lista.toArray());
|
|
124 |
public Object getElementAt(int arg0) {
|
|
125 |
return this.items.get(arg0);
|
|
126 |
}
|
96 |
127 |
|
|
128 |
public MyComboBoxItem get(int arg0) {
|
|
129 |
return this.items.get(arg0);
|
|
130 |
}
|
|
131 |
|
|
132 |
public int getSize() {
|
|
133 |
return this.items.size();
|
|
134 |
}
|
|
135 |
|
|
136 |
public void removeListDataListener(ListDataListener arg0) {
|
|
137 |
// TODO Auto-generated method stub
|
|
138 |
|
|
139 |
}
|
|
140 |
|
|
141 |
public void addListDataListener(ListDataListener arg0) {
|
|
142 |
// TODO Auto-generated method stub
|
|
143 |
|
|
144 |
}
|
|
145 |
|
|
146 |
}
|
|
147 |
|
|
148 |
private void initComponents() {
|
|
149 |
MyComboBoxModel comboModel = new MyComboBoxModel(getAllStores());
|
|
150 |
|
|
151 |
comboBox = new JComboBox(comboModel);
|
|
152 |
|
97 |
153 |
comboBox.addActionListener(new ActionListener() {
|
98 |
154 |
|
99 |
155 |
public void actionPerformed(ActionEvent e) {
|
100 |
156 |
JComboBox jcmbType = (JComboBox) e.getSource();
|
101 |
|
int selectedIndex = jcmbType.getSelectedIndex();
|
102 |
|
layer = (FLyrVect) layers[selectedIndex + 1];
|
103 |
|
updatePanel();
|
|
157 |
MyComboBoxModel model = (MyComboBoxModel) jcmbType.getModel();
|
|
158 |
updatePanel(model.getSelected().getStore());
|
104 |
159 |
}
|
105 |
160 |
});
|
106 |
161 |
|
107 |
162 |
comboBox.setName(getName());
|
108 |
163 |
|
109 |
|
if (layers.length > 1) {
|
110 |
|
layer = (FLyrVect) layers[1];
|
|
164 |
if (comboModel.getSize() > 1) {
|
111 |
165 |
transforms =
|
112 |
166 |
DataTransformLocator.getDataTransformManager()
|
113 |
|
.createJDataTransformList(
|
114 |
|
(FeatureStore) layer.getDataStore());
|
|
167 |
.createJDataTransformList(comboModel.get(1).getStore());
|
115 |
168 |
}
|
116 |
169 |
if (transforms != null) {
|
117 |
170 |
transforms.addListSelectionListener(new ListSelectionHandler());
|
118 |
171 |
}
|
119 |
172 |
}
|
120 |
173 |
|
|
174 |
private List<MyComboBoxItem> getAllStores() {
|
|
175 |
List<MyComboBoxItem> stores = new ArrayList<MyComboBoxItem>();
|
|
176 |
ApplicationManager application = ApplicationLocator.getManager();
|
|
177 |
Project project = application.getCurrentProject();
|
|
178 |
|
|
179 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME);
|
|
180 |
for (Document doc : views) {
|
|
181 |
ViewDocument viewDocument = (ViewDocument) doc;
|
|
182 |
|
|
183 |
FLayer[] layers = viewDocument.getMapContext().getLayers().getVisibles();
|
|
184 |
if (layers.length > 0) {
|
|
185 |
for (int i = 1; i < layers.length; i++) {
|
|
186 |
if( layers[i] instanceof FLyrVect) {
|
|
187 |
FLyrVect layer = (FLyrVect) layers[i];
|
|
188 |
stores.add(new MyComboBoxItem(layer.getName(), layer.getFeatureStore()));
|
|
189 |
}
|
|
190 |
}
|
|
191 |
}
|
|
192 |
}
|
|
193 |
List<Document> tables = project.getDocuments(TableManager.TYPENAME);
|
|
194 |
for (Document doc : tables) {
|
|
195 |
TableDocument tableDocument = (TableDocument) doc;
|
|
196 |
stores.add(new MyComboBoxItem(doc.getName(), tableDocument.getStore()));
|
|
197 |
}
|
|
198 |
|
|
199 |
return stores ;
|
|
200 |
}
|
|
201 |
|
|
202 |
|
121 |
203 |
private void createGUI() {
|
122 |
204 |
|
123 |
205 |
java.awt.GridBagConstraints gridBagConstraints;
|
... | ... | |
197 |
279 |
|
198 |
280 |
botonEliminar.setEnabled(false);
|
199 |
281 |
|
200 |
|
updatePanel();
|
|
282 |
updatePanel(null);
|
201 |
283 |
}
|
202 |
284 |
|
203 |
285 |
class ListSelectionHandler implements ListSelectionListener {
|
... | ... | |
253 |
335 |
this.parent.transforms.remove(this.parent.transforms
|
254 |
336 |
.getSelected());
|
255 |
337 |
}
|
256 |
|
updatePanel();
|
|
338 |
updatePanel(null);
|
257 |
339 |
}
|
258 |
340 |
|
259 |
341 |
}
|
... | ... | |
292 |
374 |
|
293 |
375 |
}
|
294 |
376 |
|
295 |
|
public void updatePanel() {
|
296 |
|
if (layer != null) {
|
297 |
|
FeatureStoreTransforms layerTransforms =
|
298 |
|
layer.getFeatureStore().getTransforms();
|
|
377 |
private void updatePanel(FeatureStore store) {
|
299 |
378 |
|
300 |
|
transforms.changeStore(layer.getFeatureStore());
|
301 |
|
transforms.removeAllTransforms();
|
302 |
|
transforms.addTransforms(layerTransforms);
|
303 |
|
}
|
|
379 |
if (transforms != null) {
|
304 |
380 |
|
305 |
|
// disable the remove button if the transforms list is empty
|
306 |
|
if (transforms != null) {
|
|
381 |
if (store != null) {
|
|
382 |
FeatureStoreTransforms layerTransforms = store.getTransforms();
|
|
383 |
|
|
384 |
transforms.changeStore(store);
|
|
385 |
transforms.removeAllTransforms();
|
|
386 |
transforms.addTransforms(layerTransforms);
|
|
387 |
}
|
|
388 |
|
|
389 |
// disable the remove button if the transforms list is empty
|
|
390 |
// if (transforms != null) {
|
307 |
391 |
if (transforms.getSelected() != null) {
|
308 |
392 |
botonEliminar.setEnabled(transforms.getTransformsCount() > 0);
|
309 |
393 |
}
|
|
394 |
|
310 |
395 |
} else {
|
311 |
396 |
botonEliminar.setEnabled(false);
|
312 |
397 |
}
|