gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.groupby / src / main / java / org / gvsig / geoprocess / algorithm / groupby / GroupByParametersPanel.java @ 357
History | View | Annotate | Download (21.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 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 |
* 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.geoprocess.algorithm.groupby; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Color; |
28 |
import java.awt.Component; |
29 |
import java.awt.Dimension; |
30 |
import java.awt.GridBagConstraints; |
31 |
import java.awt.GridBagLayout; |
32 |
import java.awt.Insets; |
33 |
import java.awt.event.ActionEvent; |
34 |
import java.awt.event.ActionListener; |
35 |
import java.awt.event.MouseEvent; |
36 |
import java.awt.event.MouseListener; |
37 |
import java.util.ArrayList; |
38 |
import java.util.List; |
39 |
|
40 |
import javax.swing.BorderFactory; |
41 |
import javax.swing.ButtonGroup; |
42 |
import javax.swing.ComboBoxModel; |
43 |
import javax.swing.DefaultComboBoxModel; |
44 |
import javax.swing.DefaultListModel; |
45 |
import javax.swing.JButton; |
46 |
import javax.swing.JComboBox; |
47 |
import javax.swing.JLabel; |
48 |
import javax.swing.JList; |
49 |
import javax.swing.JPanel; |
50 |
import javax.swing.JRadioButton; |
51 |
import javax.swing.JScrollPane; |
52 |
import javax.swing.JTable; |
53 |
import javax.swing.ListSelectionModel; |
54 |
import javax.swing.table.DefaultTableModel; |
55 |
import javax.swing.table.TableCellEditor; |
56 |
import javax.swing.table.TableCellRenderer; |
57 |
import javax.swing.table.TableColumn; |
58 |
|
59 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
60 |
import org.gvsig.geoprocess.sextante.gui.algorithm.AlgorithmOutputPanel; |
61 |
import org.gvsig.gui.beans.Messages; |
62 |
import org.gvsig.gui.beans.swing.treeTable.AbstractCellEditor; |
63 |
import org.gvsig.timesupport.Instant; |
64 |
|
65 |
import es.unex.sextante.core.GeoAlgorithm; |
66 |
import es.unex.sextante.core.ObjectAndDescription; |
67 |
import es.unex.sextante.core.OutputObjectsSet; |
68 |
import es.unex.sextante.core.ParametersSet; |
69 |
import es.unex.sextante.core.Sextante; |
70 |
import es.unex.sextante.dataObjects.IVectorLayer; |
71 |
import es.unex.sextante.gui.algorithm.GeoAlgorithmParametersPanel; |
72 |
import es.unex.sextante.gui.algorithm.OutputChannelSelectionPanel; |
73 |
import es.unex.sextante.gui.core.SextanteGUI; |
74 |
import es.unex.sextante.outputs.Output; |
75 |
|
76 |
/**
|
77 |
* Panel for dissolve algorithm
|
78 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
79 |
*/
|
80 |
public class GroupByParametersPanel extends GeoAlgorithmParametersPanel implements ActionListener, MouseListener { |
81 |
private static final long serialVersionUID = 1L; |
82 |
private GeoAlgorithm m_Algorithm = null; |
83 |
private JButton buttonAdd = null; |
84 |
private JButton buttonDel = null; |
85 |
private JComboBox groupingField = null; |
86 |
private JComboBox timeField = null; |
87 |
private JComboBox layersCombo = null; |
88 |
private JList fieldList = null; |
89 |
private JScrollPane jlistScroll = null; |
90 |
private AlgorithmOutputPanel output = null; |
91 |
private String[] opList = null; |
92 |
private final String[] columnNames = { Messages.getText("Field"), Messages.getText("Function") }; |
93 |
private JTable table = null; |
94 |
private JScrollPane jtableScroll = null; |
95 |
private JRadioButton firstGeom = null; |
96 |
private JRadioButton multiGeom = null; |
97 |
private JRadioButton spatialFusion = null; |
98 |
private OutputChannelSelectionPanel outputChannelSelectionPanel;
|
99 |
private JPanel outputPanel; |
100 |
|
101 |
public class GroupByTableModel extends DefaultTableModel { |
102 |
final private static long serialVersionUID = -3370601314380922368L; |
103 |
private List<JComboBox> combos = null; |
104 |
|
105 |
public GroupByTableModel(String[] columnNames, List<JComboBox> c) { |
106 |
super(new Object[0][columnNames.length], columnNames); |
107 |
this.combos = c;
|
108 |
} |
109 |
|
110 |
public Object[] getNewLine() { |
111 |
return new Object[] { "", new Integer(0)}; |
112 |
} |
113 |
|
114 |
public boolean isCellEditable(int row, int col) { |
115 |
return (col == 1) ? true : false; |
116 |
} |
117 |
|
118 |
public void addRow(Object[] list) { |
119 |
if(list.length <= 2 && list[1] instanceof Integer && list[0] instanceof String) { |
120 |
super.addRow(list);
|
121 |
} |
122 |
} |
123 |
|
124 |
public Object getValueAt(int row, int column) { |
125 |
Object obj = super.getValueAt(row, column); |
126 |
if(column == 1) |
127 |
if(row < combos.size())
|
128 |
return combos.get(row).getSelectedIndex();
|
129 |
return obj;
|
130 |
} |
131 |
} |
132 |
|
133 |
class GroupByEditor extends AbstractCellEditor implements TableCellEditor { |
134 |
private List<JComboBox> combos = null; |
135 |
|
136 |
public GroupByEditor(List<JComboBox> c) { |
137 |
combos = c; |
138 |
} |
139 |
|
140 |
private void loadCombo(JComboBox combo) { |
141 |
for (int i = 0; i < opList.length; i++) { |
142 |
combo.addItem(opList[i]); |
143 |
} |
144 |
} |
145 |
|
146 |
public Component getTableCellEditorComponent(JTable table, |
147 |
Object value, boolean isSelected, int row, int column) { |
148 |
if(value instanceof Integer) { |
149 |
if(row < combos.size()) {
|
150 |
JComboBox c = combos.get(row);
|
151 |
c.setSelectedIndex((Integer)value);
|
152 |
return c;
|
153 |
} else {
|
154 |
int dist = row - (combos.size() - 1); |
155 |
for (int i = 0; i < dist; i++) { |
156 |
JComboBox c = new JComboBox(); |
157 |
loadCombo(c); |
158 |
combos.add(c); |
159 |
c.setSelectedIndex((Integer)value);
|
160 |
} |
161 |
JComboBox c = combos.get(row);
|
162 |
c.setSelectedIndex((Integer)value);
|
163 |
return c;
|
164 |
} |
165 |
} |
166 |
return null; |
167 |
} |
168 |
|
169 |
} |
170 |
|
171 |
class GroupByRenderer extends JComboBox implements TableCellRenderer { |
172 |
private static final long serialVersionUID = 1L; |
173 |
|
174 |
public GroupByRenderer() {
|
175 |
for (int i = 0; i < opList.length; i++) { |
176 |
this.addItem(opList[i]);
|
177 |
} |
178 |
} |
179 |
|
180 |
public Component getTableCellRendererComponent(JTable table, |
181 |
Object value, boolean isSelected, boolean hasFocus, int row, |
182 |
int column) {
|
183 |
return this; |
184 |
} |
185 |
} |
186 |
|
187 |
public GroupByParametersPanel() {
|
188 |
super();
|
189 |
} |
190 |
|
191 |
public void init(GeoAlgorithm algorithm) { |
192 |
m_Algorithm = algorithm; |
193 |
loadOperationListArray(0);
|
194 |
initGUI(); |
195 |
} |
196 |
|
197 |
private void initGUI() { |
198 |
GridBagLayout gbl = new GridBagLayout(); |
199 |
this.setLayout(gbl);
|
200 |
this.setBorder(BorderFactory.createLineBorder(Color.gray)); |
201 |
|
202 |
GridBagConstraints gbc = new GridBagConstraints(); |
203 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
204 |
gbc.weightx = 1.0;
|
205 |
gbc.gridx = 0;
|
206 |
gbc.insets = new Insets(0, 4, 4, 4); |
207 |
|
208 |
gbc.gridy = 0;
|
209 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("grouping_layer"), getLayers1Combo()), gbc); |
210 |
|
211 |
gbc.gridy = 1;
|
212 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("grouping_field"), getFields1Combo()), gbc); |
213 |
|
214 |
gbc.gridy = 2;
|
215 |
this.add(getComboPanel(GeoProcessLocator.getGeoProcessManager().getTranslation("time_field"), getFields2Combo()), gbc); |
216 |
|
217 |
gbc.gridy = 3;
|
218 |
gbc.fill = GridBagConstraints.BOTH;
|
219 |
gbc.weighty = 1.0;
|
220 |
this.add(getTablePanel(), gbc);
|
221 |
|
222 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
223 |
gbc.weighty = 0;
|
224 |
gbc.gridy = 4;
|
225 |
this.add(getGeometryPanel(), gbc);
|
226 |
|
227 |
gbc.gridy = 5;
|
228 |
this.add(getOutputChannelSelectionPanel(), gbc);
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Gets the output panel (SEXTANTE)
|
233 |
* @return
|
234 |
*/
|
235 |
private JPanel getOutputChannelSelectionPanel() { |
236 |
if(outputPanel == null) { |
237 |
try {
|
238 |
outputPanel = new JPanel(); |
239 |
outputPanel.setLayout(new BorderLayout()); |
240 |
final OutputObjectsSet ooSet = m_Algorithm.getOutputObjects();
|
241 |
final Output out = ooSet.getOutput(GroupByAlgorithm.RESULT);
|
242 |
outputChannelSelectionPanel = new OutputChannelSelectionPanel(out, m_Algorithm.getParameters());
|
243 |
outputPanel.add(new JLabel("GroupBy [Vectorial] "), BorderLayout.WEST); |
244 |
outputPanel.add(outputChannelSelectionPanel, BorderLayout.CENTER);
|
245 |
} catch (final Exception e) { |
246 |
Sextante.addErrorToLog(e); |
247 |
} |
248 |
} |
249 |
return outputPanel;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
* Gets the output panel (DAL)
|
254 |
* @return
|
255 |
*/
|
256 |
@SuppressWarnings("unused") |
257 |
private AlgorithmOutputPanel getAlgorithmOutputPanel() {
|
258 |
if(output == null) { |
259 |
output = new AlgorithmOutputPanel();
|
260 |
} |
261 |
return output;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* Gets a new JPanel with the text and JComboBox
|
266 |
* @param text
|
267 |
* @param combo
|
268 |
* @return
|
269 |
*/
|
270 |
public JPanel getComboPanel(String text, JComboBox combo) { |
271 |
JPanel panel = new JPanel(); |
272 |
GridBagLayout gbl = new GridBagLayout(); |
273 |
panel.setLayout(gbl); |
274 |
|
275 |
GridBagConstraints gbc = new GridBagConstraints(); |
276 |
gbc.fill = GridBagConstraints.NONE;
|
277 |
gbc.weightx = 0;
|
278 |
gbc.gridx = 0;
|
279 |
gbc.insets = new Insets(0, 2, 0, 5); |
280 |
JLabel label = new JLabel(text); |
281 |
label.setPreferredSize(new Dimension(180, 18)); |
282 |
panel.add(label, gbc); |
283 |
|
284 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
285 |
gbc.weightx = 1.0;
|
286 |
gbc.gridx = 1;
|
287 |
gbc.anchor = GridBagConstraints.EAST;
|
288 |
gbc.insets = new Insets(0, 2, 0, 0); |
289 |
panel.add(combo, gbc); |
290 |
return panel;
|
291 |
} |
292 |
|
293 |
/**
|
294 |
* Gets a ComboBox
|
295 |
* @return
|
296 |
*/
|
297 |
public JComboBox getFields1Combo() { |
298 |
if(groupingField == null) { |
299 |
groupingField = new JComboBox(); |
300 |
groupingField.setPreferredSize(new Dimension(0, 18)); |
301 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getFieldList()); |
302 |
groupingField.setModel(comboModel); |
303 |
groupingField.addActionListener(this);
|
304 |
} |
305 |
return groupingField;
|
306 |
} |
307 |
|
308 |
/**
|
309 |
* Gets a ComboBox
|
310 |
* @return
|
311 |
*/
|
312 |
public JComboBox getFields2Combo() { |
313 |
if(timeField == null) { |
314 |
timeField = new JComboBox(); |
315 |
timeField.setPreferredSize(new Dimension(0, 18)); |
316 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getTimeFieldList().toArray()); |
317 |
timeField.setModel(comboModel); |
318 |
timeField.addActionListener(this);
|
319 |
} |
320 |
return timeField;
|
321 |
} |
322 |
|
323 |
public JPanel getTablePanel() { |
324 |
JPanel p = new JPanel(); |
325 |
p.setLayout(new GridBagLayout()); |
326 |
|
327 |
GridBagConstraints gbc = new GridBagConstraints(); |
328 |
gbc.fill = GridBagConstraints.BOTH;
|
329 |
gbc.weighty = 1.0;
|
330 |
gbc.weightx = 1.0;
|
331 |
gbc.gridx = 0;
|
332 |
p.add(getJList(), gbc); |
333 |
|
334 |
gbc.gridx = 2;
|
335 |
p.add(getJTable(), gbc); |
336 |
|
337 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
338 |
gbc.weightx = 0;
|
339 |
gbc.gridx = 1;
|
340 |
p.add(getButtonsPanel(), gbc); |
341 |
|
342 |
return p;
|
343 |
} |
344 |
|
345 |
/**
|
346 |
* Gets a ComboBox
|
347 |
* @return
|
348 |
*/
|
349 |
public JComboBox getLayers1Combo() { |
350 |
if(layersCombo == null) { |
351 |
layersCombo = new JComboBox(); |
352 |
layersCombo.setPreferredSize(new Dimension(0, 18)); |
353 |
ComboBoxModel comboModel = new DefaultComboBoxModel(getLayerList()); |
354 |
layersCombo.setModel(comboModel); |
355 |
layersCombo.addActionListener(this);
|
356 |
} |
357 |
return layersCombo;
|
358 |
} |
359 |
|
360 |
private JPanel getButtonsPanel() { |
361 |
JPanel p = new JPanel(); |
362 |
p.setLayout(new GridBagLayout()); |
363 |
GridBagConstraints gbc = new GridBagConstraints(); |
364 |
gbc.fill = GridBagConstraints.NONE;
|
365 |
gbc.gridx = 0;
|
366 |
gbc.gridy = 0;
|
367 |
p.add(getButtonAdd(), gbc); |
368 |
gbc.gridx = 0;
|
369 |
gbc.gridy = 1;
|
370 |
p.add(getButtonDel(), gbc); |
371 |
return p;
|
372 |
} |
373 |
|
374 |
public JButton getButtonAdd() { |
375 |
if(buttonAdd == null) { |
376 |
buttonAdd = new JButton(">>"); |
377 |
buttonAdd.setPreferredSize(new Dimension(32, 32)); |
378 |
buttonAdd.addActionListener(this);
|
379 |
} |
380 |
return buttonAdd;
|
381 |
} |
382 |
|
383 |
public JButton getButtonDel() { |
384 |
if(buttonDel == null) { |
385 |
buttonDel = new JButton("<<"); |
386 |
buttonDel.setPreferredSize(new Dimension(32, 32)); |
387 |
buttonDel.addActionListener(this);
|
388 |
} |
389 |
return buttonDel;
|
390 |
} |
391 |
|
392 |
public JScrollPane getJTable() { |
393 |
if (table == null) { |
394 |
List<JComboBox> combos = new ArrayList<JComboBox>(); |
395 |
GroupByTableModel model = new GroupByTableModel(columnNames, combos);
|
396 |
table = new JTable(model); |
397 |
table.setRowHeight(24);
|
398 |
jtableScroll = new JScrollPane(table); |
399 |
TableColumn column = table.getColumnModel().getColumn(1); |
400 |
GroupByRenderer render = new GroupByRenderer();
|
401 |
column.setCellRenderer(render); |
402 |
column.setCellEditor(new GroupByEditor(combos));
|
403 |
} |
404 |
return jtableScroll;
|
405 |
} |
406 |
|
407 |
|
408 |
public JScrollPane getJList() { |
409 |
if (fieldList == null) { |
410 |
fieldList = new JList(); |
411 |
fieldList.setModel(new DefaultListModel()); |
412 |
jlistScroll = new JScrollPane(fieldList); |
413 |
fieldList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
414 |
fieldList.addMouseListener(this);
|
415 |
String[] list = getFieldList(); |
416 |
for (int i = 0; i < list.length; i++) { |
417 |
((DefaultListModel)this.fieldList.getModel()).addElement(list[i]); |
418 |
} |
419 |
} |
420 |
return jlistScroll;
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* Gets a new JPanel with the text and JComboBox
|
425 |
* @param text
|
426 |
* @param combo
|
427 |
* @return
|
428 |
*/
|
429 |
public JPanel getGeometryPanel() { |
430 |
ButtonGroup group = new ButtonGroup(); |
431 |
group.add(getButtonFirstGeom()); |
432 |
group.add(getButtonMultiGeom()); |
433 |
group.add(getButtonSpatialFusion()); |
434 |
|
435 |
JPanel panel = new JPanel(); |
436 |
String text = GeoProcessLocator.getGeoProcessManager().getTranslation("geom"); |
437 |
panel.setBorder(BorderFactory.createTitledBorder(text));
|
438 |
GridBagLayout gbl = new GridBagLayout(); |
439 |
panel.setLayout(gbl); |
440 |
|
441 |
GridBagConstraints gbc = new GridBagConstraints(); |
442 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
443 |
gbc.weightx = 1.0;
|
444 |
gbc.insets = new Insets(0, 2, 4, 0); |
445 |
panel.add(getButtonFirstGeom(), gbc); |
446 |
|
447 |
gbc.gridy = 1;
|
448 |
panel.add(getButtonMultiGeom(), gbc); |
449 |
|
450 |
gbc.gridy = 2;
|
451 |
panel.add(getButtonSpatialFusion(), gbc); |
452 |
|
453 |
return panel;
|
454 |
} |
455 |
|
456 |
private JRadioButton getButtonFirstGeom() { |
457 |
if(firstGeom == null) { |
458 |
String text = GeoProcessLocator.getGeoProcessManager().getTranslation("first_geom"); |
459 |
firstGeom = new JRadioButton(text); |
460 |
} |
461 |
return firstGeom;
|
462 |
} |
463 |
|
464 |
private JRadioButton getButtonMultiGeom() { |
465 |
if(multiGeom == null) { |
466 |
String text = GeoProcessLocator.getGeoProcessManager().getTranslation("multi_geom"); |
467 |
multiGeom = new JRadioButton(text); |
468 |
} |
469 |
return multiGeom;
|
470 |
} |
471 |
|
472 |
private JRadioButton getButtonSpatialFusion() { |
473 |
if(spatialFusion == null) { |
474 |
String text = GeoProcessLocator.getGeoProcessManager().getTranslation("spatial_fusion"); |
475 |
spatialFusion = new JRadioButton(text); |
476 |
} |
477 |
return spatialFusion;
|
478 |
} |
479 |
|
480 |
|
481 |
//------------------------------------------------------------
|
482 |
|
483 |
private void reloadFields() { |
484 |
for (int i = ((DefaultTableModel)table.getModel()).getRowCount() - 1; i >= 0 ; i--) { |
485 |
((DefaultTableModel)table.getModel()).removeRow(i);
|
486 |
} |
487 |
String[] list = getFieldList(); |
488 |
groupingField.removeAllItems(); |
489 |
((DefaultListModel)this.fieldList.getModel()).clear(); |
490 |
for (int i = 0; i < list.length; i++) { |
491 |
((DefaultListModel)this.fieldList.getModel()).addElement(list[i]); |
492 |
groupingField.addItem(list[i]); |
493 |
} |
494 |
|
495 |
loadOperationListArray(getLayers1Combo().getSelectedIndex()); |
496 |
|
497 |
List<JComboBox> combos = new ArrayList<JComboBox>(); |
498 |
GroupByTableModel model = new GroupByTableModel(columnNames, combos);
|
499 |
table.setModel(model); |
500 |
TableColumn column = table.getColumnModel().getColumn(1); |
501 |
GroupByRenderer render = new GroupByRenderer();
|
502 |
column.setCellRenderer(render); |
503 |
column.setCellEditor(new GroupByEditor(combos));
|
504 |
|
505 |
getFields2Combo().removeAllItems(); |
506 |
List<String> timeFieldList = getTimeFieldList(); |
507 |
for (int i = 0; i < timeFieldList.size(); i++) { |
508 |
getFields2Combo().addItem(timeFieldList.get(i)); |
509 |
} |
510 |
|
511 |
IVectorLayer layer = getSelectedVectorLayer(); |
512 |
if(layer.getShapeType() != IVectorLayer.SHAPE_TYPE_POLYGON)
|
513 |
getButtonSpatialFusion().setEnabled(false);
|
514 |
} |
515 |
|
516 |
/**
|
517 |
* Gets the selected vector layer in the JComboBox
|
518 |
* @return
|
519 |
*/
|
520 |
private IVectorLayer getSelectedVectorLayer() {
|
521 |
if(layersCombo.getSelectedItem() != null) |
522 |
return (IVectorLayer)((ObjectAndDescription)layersCombo.getSelectedItem()).getObject();
|
523 |
return null; |
524 |
} |
525 |
|
526 |
/*
|
527 |
* (non-Javadoc)
|
528 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
529 |
*/
|
530 |
public void actionPerformed(ActionEvent e) { |
531 |
if(e.getSource() == getLayers1Combo()) {
|
532 |
reloadFields(); |
533 |
} |
534 |
|
535 |
if(e.getSource() == getButtonAdd()) {
|
536 |
addRowToTable(); |
537 |
} |
538 |
|
539 |
if(e.getSource() == getButtonDel()) {
|
540 |
int row = table.getSelectedRow();
|
541 |
if(row >= 0 && row < table.getRowCount()) { |
542 |
((GroupByTableModel)table.getModel()).removeRow(row); |
543 |
} |
544 |
} |
545 |
} |
546 |
|
547 |
|
548 |
@Override
|
549 |
public void assignParameters() { |
550 |
try {
|
551 |
ParametersSet params = m_Algorithm.getParameters(); |
552 |
params.getParameter(GroupByAlgorithm.LAYER_NAME).setParameterValue("GroupBy_Layer");
|
553 |
params.getParameter(GroupByAlgorithm.LAYER).setParameterValue(getSelectedVectorLayer()); |
554 |
params.getParameter(GroupByAlgorithm.FIELD).setParameterValue(getFields1Combo().getSelectedIndex()); |
555 |
params.getParameter(GroupByAlgorithm.FIELD_DATE).setParameterValue(getFields2Combo().getSelectedIndex()); |
556 |
params.getParameter(GroupByAlgorithm.FIELD_LIST).setParameterValue(getFieldStringList()); |
557 |
params.getParameter(GroupByAlgorithm.FUNCTION_LIST).setParameterValue(getFunctionStringList()); |
558 |
int geom = getButtonFirstGeom().isSelected() ? 0 : getButtonMultiGeom().isSelected() ? 1 : getButtonSpatialFusion().isSelected() ? 2 : -1; |
559 |
params.getParameter(GroupByAlgorithm.GEOM_OPTION).setParameterValue(geom); |
560 |
|
561 |
OutputObjectsSet ooSet = m_Algorithm.getOutputObjects(); |
562 |
Output out = ooSet.getOutput(GroupByAlgorithm.RESULT); |
563 |
|
564 |
//Reponer estas l?neas para cambiar el panel de salida y comentar la siguiente
|
565 |
//AlgorithmOutputPanel fsp = getAlgorithmOutputPanel();
|
566 |
//out.setOutputChannel(new CompositeSourceOutputChannel(fsp.getOutputParameters()));
|
567 |
out.setOutputChannel(outputChannelSelectionPanel.getOutputChannel()); |
568 |
} catch (Exception e) { |
569 |
Sextante.addErrorToLog(e); |
570 |
} |
571 |
} |
572 |
|
573 |
private String getFunctionStringList() { |
574 |
if(table != null) { |
575 |
String value = ""; |
576 |
for (int i = 0; i < ((GroupByTableModel)table.getModel()).getRowCount(); i++) { |
577 |
Object obj = ((GroupByTableModel)table.getModel()).getValueAt(i, 1); |
578 |
if(obj instanceof Integer) { |
579 |
if(value.compareTo("") == 0) |
580 |
value = opList[(Integer)obj];
|
581 |
else
|
582 |
value += ";" + opList[(Integer)obj]; |
583 |
} |
584 |
} |
585 |
return value;
|
586 |
} |
587 |
return null; |
588 |
} |
589 |
|
590 |
private String getFieldStringList() { |
591 |
if(table != null) { |
592 |
String value = ""; |
593 |
for (int i = 0; i < ((GroupByTableModel)table.getModel()).getRowCount(); i++) { |
594 |
Object obj = ((GroupByTableModel)table.getModel()).getValueAt(i, 0); |
595 |
if(obj instanceof String) { |
596 |
String[] fList = getFieldList(); |
597 |
for (int j = 0; j < fList.length; j++) { |
598 |
if(fList[j].compareTo((String)obj) == 0) { |
599 |
if(value.compareTo("") == 0) |
600 |
value = j + "";
|
601 |
else
|
602 |
value += ";" + j;
|
603 |
} |
604 |
} |
605 |
} |
606 |
} |
607 |
return value;
|
608 |
} |
609 |
return null; |
610 |
} |
611 |
|
612 |
@Override
|
613 |
public void setOutputValue(String arg0, String arg1) { |
614 |
|
615 |
} |
616 |
|
617 |
@Override
|
618 |
public void setParameterValue(String arg0, String arg1) { |
619 |
|
620 |
} |
621 |
; |
622 |
/**
|
623 |
* Gets the input layer list
|
624 |
* @return
|
625 |
*/
|
626 |
private ObjectAndDescription[] getLayerList() { |
627 |
IVectorLayer[] layers = SextanteGUI.getInputFactory()
|
628 |
.getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG); |
629 |
ObjectAndDescription[] oad = new ObjectAndDescription[layers.length]; |
630 |
for (int i = 0; i < layers.length; i++) |
631 |
oad[i] = new ObjectAndDescription(layers[i].getName(), layers[i]);
|
632 |
return oad;
|
633 |
} |
634 |
|
635 |
/**
|
636 |
* Gets the field list of the selected layer
|
637 |
* @return
|
638 |
*/
|
639 |
public String[] getFieldList() { |
640 |
IVectorLayer layer = getSelectedVectorLayer(); |
641 |
String[] data = new String[layer.getFieldCount()]; |
642 |
for (int i = 0; i < layer.getFieldCount(); i++) |
643 |
data[i] = layer.getFieldName(i); |
644 |
return data;
|
645 |
} |
646 |
|
647 |
/**
|
648 |
* Gets the field list of the selected layer of time data type
|
649 |
* @return
|
650 |
*/
|
651 |
@SuppressWarnings("unchecked") |
652 |
public List<String> getTimeFieldList() { |
653 |
IVectorLayer layer = getSelectedVectorLayer(); |
654 |
List<String> data = new ArrayList<String>(); |
655 |
for (int i = 0; i < layer.getFieldCount(); i++) { |
656 |
Class type = layer.getFieldType(i);
|
657 |
if(Instant.class.isAssignableFrom(type))
|
658 |
data.add(layer.getFieldName(i)); |
659 |
} |
660 |
return data;
|
661 |
} |
662 |
|
663 |
private void addRowToTable() { |
664 |
Object[] values = fieldList.getSelectedValues(); |
665 |
for (int i = 0; i < values.length; i++) { |
666 |
((GroupByTableModel)table.getModel()).addRow(new Object[]{values[i], 0}); |
667 |
} |
668 |
} |
669 |
|
670 |
public void mouseClicked(MouseEvent e) { |
671 |
if(e.getClickCount() == 2) { |
672 |
addRowToTable(); |
673 |
} |
674 |
} |
675 |
|
676 |
@SuppressWarnings("unchecked") |
677 |
private void loadOperationListArray(int positionLayer) { |
678 |
IVectorLayer[] layers = SextanteGUI.getInputFactory().getVectorLayers(IVectorLayer.SHAPE_TYPE_WRONG);
|
679 |
if(layers != null && layers.length > 0) { |
680 |
boolean existsTimeField = false; |
681 |
for (int i = 0; i < layers[positionLayer].getFieldCount(); i++) { |
682 |
Class type = layers[positionLayer].getFieldType(i);
|
683 |
if(Instant.class.isAssignableFrom(type))
|
684 |
existsTimeField = true;
|
685 |
} |
686 |
|
687 |
if(layers[positionLayer].getShapeType() != IVectorLayer.SHAPE_TYPE_POLYGON)
|
688 |
getButtonSpatialFusion().setEnabled(false);
|
689 |
|
690 |
if(existsTimeField)
|
691 |
opList = new String[]{ "first", "sum", "average", "max", "min", "last"}; |
692 |
else
|
693 |
opList = new String[]{ "first", "sum", "average", "max", "min"}; |
694 |
} |
695 |
} |
696 |
|
697 |
public void mouseEntered(MouseEvent e) { |
698 |
} |
699 |
|
700 |
public void mouseExited(MouseEvent e) { |
701 |
} |
702 |
|
703 |
public void mousePressed(MouseEvent e) { |
704 |
} |
705 |
|
706 |
public void mouseReleased(MouseEvent e) { |
707 |
} |
708 |
|
709 |
} |