gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.app / org.gvsig.vectorediting.app.mainplugin / src / main / java / org / gvsig / project / documents / view / gui / GridLayersPanel.java @ 2289
History | View | Annotate | Download (11 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.project.documents.view.gui; |
7 |
|
8 |
import java.awt.Dimension; |
9 |
import java.awt.GridBagConstraints; |
10 |
import java.awt.GridBagLayout; |
11 |
import java.awt.Insets; |
12 |
import java.awt.event.ActionEvent; |
13 |
import java.awt.event.ActionListener; |
14 |
import java.awt.event.MouseAdapter; |
15 |
import java.awt.event.MouseEvent; |
16 |
import java.util.ArrayList; |
17 |
import java.util.Collection; |
18 |
import java.util.Iterator; |
19 |
import java.util.List; |
20 |
import javax.swing.Action; |
21 |
import javax.swing.DefaultComboBoxModel; |
22 |
import javax.swing.JButton; |
23 |
import javax.swing.JComboBox; |
24 |
import javax.swing.JComponent; |
25 |
import javax.swing.JLabel; |
26 |
import javax.swing.JOptionPane; |
27 |
import javax.swing.JPanel; |
28 |
import javax.swing.JScrollPane; |
29 |
import static org.exolab.castor.xml.util.DOMEventProducer.process; |
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.export.ExportLocator; |
32 |
import org.gvsig.export.ExportManager; |
33 |
import org.gvsig.export.ExportProcess; |
34 |
import org.gvsig.export.swing.ExportSwingLocator; |
35 |
import org.gvsig.export.swing.ExportSwingManager; |
36 |
import org.gvsig.export.swing.JExportProcessPanel; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.swing.DALActionFactory; |
39 |
import org.gvsig.fmap.dal.swing.DALSwingLocator; |
40 |
import org.gvsig.fmap.dal.swing.impl.searchpanel.DefaultSearchPanel; |
41 |
import org.gvsig.fmap.mapcontext.MapContext; |
42 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
43 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
44 |
import org.gvsig.tools.ToolsLocator; |
45 |
import org.gvsig.tools.i18n.I18nManager; |
46 |
import org.gvsig.tools.swing.api.Component; |
47 |
import org.gvsig.tools.swing.api.DropDown; |
48 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
49 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
50 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
51 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager_v2; |
52 |
import org.gvsig.tools.swing.impl.DropDownLabel; |
53 |
import org.gvsig.tools.util.LabeledValue; |
54 |
import org.gvsig.tools.util.LabeledValueImpl; |
55 |
import org.gvsig.vectorediting.app.mainplugin.EditingExtension; |
56 |
import org.slf4j.Logger; |
57 |
import org.slf4j.LoggerFactory; |
58 |
|
59 |
/**
|
60 |
*
|
61 |
* @author jovivas
|
62 |
*/
|
63 |
public class GridLayersPanel extends JPanel implements Component { |
64 |
|
65 |
private static final int OPTION_SAVE = 0; |
66 |
private static final int OPTION_DISMISS = 1; |
67 |
private static final int OPTION_CONTINUE = 2; |
68 |
private static final int OPTION_EXPORT = 3; |
69 |
|
70 |
private static final Logger LOGGER = LoggerFactory.getLogger(EditingExtension.class); |
71 |
|
72 |
private static class Row { |
73 |
|
74 |
private final FLyrVect layer; |
75 |
private final DropDown dropDownOptions; |
76 |
private final JButton jButtonExport; |
77 |
private final LabeledValue[] options; |
78 |
|
79 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
80 |
private final JLabel dropDownComponent; |
81 |
|
82 |
public Row(FLyrVect layer) {
|
83 |
this.layer = layer;
|
84 |
|
85 |
options = new LabeledValue[]{ |
86 |
new LabeledValueImpl(i18n.getTranslation("_save"),OPTION_SAVE), |
87 |
new LabeledValueImpl(i18n.getTranslation("_dismiss"), OPTION_DISMISS), |
88 |
new LabeledValueImpl(i18n.getTranslation("_continue"), OPTION_CONTINUE), |
89 |
new LabeledValueImpl(i18n.getTranslation("_export"), OPTION_EXPORT)}; |
90 |
|
91 |
DefaultComboBoxModel modelJComboBoxOptions = new DefaultComboBoxModel(); |
92 |
for (LabeledValue option : options) {
|
93 |
modelJComboBoxOptions.addElement(option); |
94 |
} |
95 |
|
96 |
ToolsSwingManager toolSwingmanager = ToolsSwingLocator.getToolsSwingManager(); |
97 |
this.dropDownComponent = new JLabel(); |
98 |
this.dropDownOptions = toolSwingmanager.createDropDown(dropDownComponent);
|
99 |
this.dropDownOptions.setModel(modelJComboBoxOptions);
|
100 |
if (this.layer.getFeatureStore().allowWrite()) { |
101 |
this.dropDownOptions.setSelectedIndex(OPTION_SAVE);
|
102 |
} else {
|
103 |
this.dropDownOptions.setSelectedIndex(OPTION_EXPORT);
|
104 |
} |
105 |
this.dropDownOptions.setVisibleDropdownArrow(true); |
106 |
|
107 |
this.jButtonExport = new JButton(i18n.getTranslation("_export")); |
108 |
|
109 |
this.jButtonExport.addActionListener(new ActionListener() { |
110 |
@Override
|
111 |
public void actionPerformed(ActionEvent e) { |
112 |
WindowManager_v2 windowManager = (WindowManager_v2) ToolsSwingLocator.getWindowManager(); |
113 |
ExportManager exportManager = ExportLocator.getManager(); |
114 |
ExportSwingManager exportSwingManager = ExportSwingLocator.getSwingManager(); |
115 |
ExportProcess process = exportManager.createProcess(layer.getFeatureStore()); |
116 |
JExportProcessPanel panel = exportSwingManager.createJExportProcessPanel(process); |
117 |
windowManager.showWindow(panel.asJComponent(), "_export", WindowManager.MODE.WINDOW);
|
118 |
} |
119 |
//en algun lugar de aqui hay que especificar que tras pulsar el boton la opci?n cambia a dismiss
|
120 |
}); |
121 |
} |
122 |
|
123 |
public FLyrVect getLayer() {
|
124 |
return this.layer; |
125 |
} |
126 |
|
127 |
public JLabel getJLabel() { |
128 |
String layerName = this.layer.getName(); |
129 |
JLabel layerNameJLabel = new JLabel(layerName); |
130 |
return layerNameJLabel;
|
131 |
} |
132 |
|
133 |
public JComponent getJDropDown() { |
134 |
return this.dropDownComponent; |
135 |
} |
136 |
|
137 |
public JButton getJButton() { |
138 |
return this.jButtonExport; |
139 |
} |
140 |
|
141 |
public int getJComboBoxOption() { |
142 |
LabeledValue<Integer> optionSelected = (LabeledValue) this.dropDownOptions.getSelectedItem(); |
143 |
return optionSelected.getValue();
|
144 |
} |
145 |
} |
146 |
|
147 |
private List<Row> rows; |
148 |
private final MapContext mapContext; |
149 |
|
150 |
public GridLayersPanel(MapContext mapContext) {
|
151 |
rows = new ArrayList<>(); |
152 |
this.mapContext = mapContext;
|
153 |
this.initComponents();
|
154 |
} |
155 |
|
156 |
public Row getRow(int rowIndex) { |
157 |
Row row = this.rows.get(rowIndex);
|
158 |
return row;
|
159 |
} |
160 |
|
161 |
public void addLayer(FLayer layer) { |
162 |
if (layer instanceof FLyrVect) { |
163 |
FLyrVect layerVect = (FLyrVect) layer; |
164 |
this.rows.add(new Row(layerVect)); |
165 |
} |
166 |
} |
167 |
|
168 |
public void build() { |
169 |
this.removeAll();
|
170 |
this.setLayout(new GridBagLayout()); |
171 |
int rownum = 0; |
172 |
for (Row row : rows) {
|
173 |
addComponent(rownum, 0, row.getJLabel());
|
174 |
addComponent(rownum, 1, row.getJDropDown());
|
175 |
addComponent(rownum, 2, row.getJButton());
|
176 |
rownum++; |
177 |
} |
178 |
GridBagConstraints c = new GridBagConstraints(); |
179 |
c.fill = GridBagConstraints.BOTH;
|
180 |
c.weighty = 0.9;
|
181 |
c.weightx = 0.9;
|
182 |
c.gridx = 1;
|
183 |
c.gridy = rownum; |
184 |
this.add(new JLabel(""), c); |
185 |
|
186 |
} |
187 |
|
188 |
private void addComponent(int gridY, int gridX, JComponent component) { |
189 |
GridBagConstraints c = new GridBagConstraints(); |
190 |
c.insets = new Insets(5, 5, 5, 5); |
191 |
c.fill = GridBagConstraints.HORIZONTAL;
|
192 |
c.ipadx = 2;
|
193 |
c.ipady = 2;
|
194 |
c.gridx = gridX; |
195 |
c.gridy = gridY; |
196 |
this.add(component, c);
|
197 |
} |
198 |
|
199 |
private void initComponents() { |
200 |
Iterator<FLayer> layers = mapContext.deepiterator();
|
201 |
while (layers.hasNext()) {
|
202 |
FLayer layer = layers.next(); |
203 |
if (layer.isEditing()) {
|
204 |
this.addLayer(layer);
|
205 |
} |
206 |
} |
207 |
this.build();
|
208 |
|
209 |
// this.addMouseListener(new MouseAdapter() {
|
210 |
// @Override
|
211 |
// public void mouseClicked(MouseEvent e) {
|
212 |
// checkExportLayers();
|
213 |
// }
|
214 |
// });
|
215 |
|
216 |
|
217 |
|
218 |
} |
219 |
|
220 |
public boolean checkExportLayers() { |
221 |
boolean exportLayer = false; |
222 |
// List exportLayers = new ArrayList();
|
223 |
for (int i = 0; i < this.rows.size(); i++) { |
224 |
Row row = this.getRow(i);
|
225 |
if (row.getJComboBoxOption() == OPTION_EXPORT) {
|
226 |
exportLayer = true;
|
227 |
// exportLayers.add(row.getLayer().getName());
|
228 |
} |
229 |
// if (exportLayer) {
|
230 |
// I18nManager i18n = ToolsLocator.getI18nManager();
|
231 |
// StringBuilder message = new StringBuilder();
|
232 |
// message.append(i18n.getTranslation("_The_following_layers_must_be_exported"));
|
233 |
// String title = i18n.getTranslation("_Need_export_layers");
|
234 |
// ToolsSwingLocator.getThreadSafeDialogsManager().messageDialog (message.toString(),
|
235 |
// title,
|
236 |
// JOptionPane.WARNING_MESSAGE);
|
237 |
// }
|
238 |
} |
239 |
return exportLayer;
|
240 |
} |
241 |
|
242 |
public void doApplyChanges() { |
243 |
// SnappingTableModel model = (SnappingTableModel) this.tableSnapping.getModel();
|
244 |
// ArrayList<FLyrVect> layersToSnap = new ArrayList<>();
|
245 |
for (int i = 0; i < this.rows.size(); i++) { |
246 |
Row row = this.getRow(i);
|
247 |
if (row.getJComboBoxOption() == OPTION_SAVE) {
|
248 |
try {
|
249 |
row.getLayer().getFeatureStore().finishEditing(); |
250 |
} catch (DataException ex) {
|
251 |
LOGGER.error(PluginServices.getText(this, ""), ex); |
252 |
// Logger.getLogger(GridLayersPanel.class.getName()).log(Level.SEVERE, null, ex);
|
253 |
} |
254 |
} else if (row.getJComboBoxOption() == OPTION_DISMISS) { |
255 |
try {
|
256 |
row.getLayer().getFeatureStore().cancelEditing(); |
257 |
} catch (DataException ex) {
|
258 |
LOGGER.error(PluginServices.getText(this, ""), ex); |
259 |
// Logger.getLogger(GridLayersPanel.class.getName()).log(Level.SEVERE, null, ex);
|
260 |
} |
261 |
} |
262 |
|
263 |
|
264 |
// row.getLayerOption().setMaxFeaturesInEditionCache(row.getCacheFeatures());
|
265 |
// if (row.isSelected()) {
|
266 |
// row.getLayer().getSpatialCache().setEnabled(true);
|
267 |
// layersToSnap.add(row.getLayer());
|
268 |
// } else {
|
269 |
// row.getLayer().getSpatialCache().setEnabled(false);
|
270 |
// }
|
271 |
} |
272 |
// this.mapContext.setLayersToSnap(layersToSnap);
|
273 |
//
|
274 |
// try {
|
275 |
// MapControlLocator.getMapControlManager().setTolerance(Integer.parseInt(this.textFieldTolSnapping.getText()));
|
276 |
//
|
277 |
// } catch (Exception e) {
|
278 |
// LOGGER.error(PluginServices.getText(this, "tolerancia_incorrecta"), e);
|
279 |
//
|
280 |
// }
|
281 |
// this.mapContext.invalidate();
|
282 |
} |
283 |
|
284 |
@Override
|
285 |
public JComponent asJComponent() { |
286 |
ToolsSwingManager toolSwingmanager = ToolsSwingLocator.getToolsSwingManager(); |
287 |
|
288 |
this.build();
|
289 |
this.setPreferredSize(new Dimension(400, 200)); |
290 |
|
291 |
JScrollPane scrollPanel = new JScrollPane(); |
292 |
scrollPanel.setPreferredSize(new Dimension(420, 220)); |
293 |
scrollPanel.setViewportView(this);
|
294 |
|
295 |
toolSwingmanager.removeBorder(this);
|
296 |
return scrollPanel;
|
297 |
} |
298 |
|
299 |
|
300 |
|
301 |
} |