Revision 727 org.gvsig.topology/trunk/org.gvsig.topology/org.gvsig.topology.swing/org.gvsig.topology.swing.impl/src/main/java/org/gvsig/topology/swing/impl/DefaultJTopologyReport.java
DefaultJTopologyReport.java | ||
---|---|---|
6 | 6 |
import java.awt.event.ActionListener; |
7 | 7 |
import java.awt.event.MouseAdapter; |
8 | 8 |
import java.awt.event.MouseEvent; |
9 |
import java.net.URL; |
|
10 |
import java.util.ArrayList; |
|
9 | 11 |
import java.util.HashSet; |
10 | 12 |
import java.util.List; |
11 | 13 |
import java.util.Set; |
12 | 14 |
import javax.swing.DefaultComboBoxModel; |
15 |
import javax.swing.ImageIcon; |
|
13 | 16 |
import javax.swing.JComponent; |
14 | 17 |
import javax.swing.JMenuItem; |
15 | 18 |
import javax.swing.JPopupMenu; |
... | ... | |
22 | 25 |
import javax.swing.event.TableModelEvent; |
23 | 26 |
import javax.swing.event.TableModelListener; |
24 | 27 |
import javax.swing.table.TableModel; |
28 |
import org.apache.commons.io.FilenameUtils; |
|
25 | 29 |
import org.apache.commons.lang3.StringUtils; |
26 | 30 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
27 | 31 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
... | ... | |
39 | 43 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
40 | 44 |
import org.gvsig.tools.swing.api.ToolsSwingManager; |
41 | 45 |
import org.gvsig.tools.swing.api.task.TaskStatusController; |
46 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
|
42 | 47 |
import org.gvsig.tools.task.TaskStatus; |
43 | 48 |
import org.gvsig.topology.lib.api.TopologyLocator; |
44 | 49 |
import org.gvsig.topology.lib.api.TopologyPlan; |
... | ... | |
70 | 75 |
private class TopologyRuleActionParametersListener implements ActionListener { |
71 | 76 |
|
72 | 77 |
private final TopologyRule rule; |
73 |
private final TopologyReportLine line;
|
|
78 |
private final List<TopologyReportLine> lines;
|
|
74 | 79 |
private final TopologyRuleAction action; |
75 | 80 |
private final JDynForm form; |
76 | 81 |
|
77 | 82 |
public TopologyRuleActionParametersListener( |
78 | 83 |
TopologyRule rule, |
79 |
TopologyReportLine line,
|
|
84 |
List<TopologyReportLine> lines,
|
|
80 | 85 |
TopologyRuleAction action, |
81 | 86 |
JDynForm form |
82 | 87 |
) { |
83 | 88 |
this.action = action; |
84 |
this.line = line;
|
|
89 |
this.lines = lines;
|
|
85 | 90 |
this.rule = rule; |
86 | 91 |
this.form = form; |
87 | 92 |
} |
88 | 93 |
|
89 | 94 |
@Override |
90 | 95 |
public void actionPerformed(ActionEvent e) { |
91 |
doExecuteRuleAction(rule, line, action, form); |
|
96 |
doExecuteRuleAction(rule, lines, action, form);
|
|
92 | 97 |
} |
93 | 98 |
} |
94 | 99 |
|
... | ... | |
96 | 101 |
private class TopologyRuleActionListener implements ActionListener { |
97 | 102 |
|
98 | 103 |
private final TopologyRule rule; |
99 |
private final TopologyReportLine line;
|
|
104 |
private final List<TopologyReportLine> lines;
|
|
100 | 105 |
private final TopologyRuleAction action; |
101 | 106 |
|
102 | 107 |
public TopologyRuleActionListener( |
103 | 108 |
TopologyRule rule, |
104 |
TopologyReportLine line,
|
|
109 |
List<TopologyReportLine> lines,
|
|
105 | 110 |
TopologyRuleAction action |
106 | 111 |
) { |
107 | 112 |
this.action = action; |
108 |
this.line = line;
|
|
113 |
this.lines = lines;
|
|
109 | 114 |
this.rule = rule; |
110 | 115 |
} |
111 | 116 |
|
112 | 117 |
@Override |
113 | 118 |
public void actionPerformed(ActionEvent e) { |
114 | 119 |
if ( this.action.hasParameters() ) { |
115 |
doShowActionParametersPanel(this.rule, this.line, this.action); |
|
120 |
doShowActionParametersPanel(this.rule, this.lines, this.action);
|
|
116 | 121 |
} else { |
117 |
doExecuteRuleAction(rule, line, action, null); |
|
122 |
doExecuteRuleAction(rule, lines, action, null);
|
|
118 | 123 |
} |
119 | 124 |
} |
120 | 125 |
} |
... | ... | |
141 | 146 |
}; |
142 | 147 |
this.tblErrors.setModel(this.linesModel); |
143 | 148 |
this.tblErrors.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
144 |
this.btnZoom.addActionListener(new ActionListener() { |
|
149 |
this.btnZoomGeometry.addActionListener(new ActionListener() {
|
|
145 | 150 |
@Override |
146 | 151 |
public void actionPerformed(ActionEvent e) { |
147 |
doZoom(); |
|
152 |
doZoomGeometry();
|
|
148 | 153 |
} |
149 | 154 |
}); |
150 |
this.btnCenter.addActionListener(new ActionListener() {
|
|
155 |
this.btnZoomError.addActionListener(new ActionListener() {
|
|
151 | 156 |
@Override |
152 | 157 |
public void actionPerformed(ActionEvent e) { |
153 |
doCenter();
|
|
158 |
doZoomError();
|
|
154 | 159 |
} |
155 | 160 |
}); |
161 |
this.btnCenterGeometry.addActionListener(new ActionListener() { |
|
162 |
@Override |
|
163 |
public void actionPerformed(ActionEvent e) { |
|
164 |
doCenterGeometry(); |
|
165 |
} |
|
166 |
}); |
|
167 |
this.btnCenterError.addActionListener(new ActionListener() { |
|
168 |
@Override |
|
169 |
public void actionPerformed(ActionEvent e) { |
|
170 |
doCenterError(); |
|
171 |
} |
|
172 |
}); |
|
156 | 173 |
this.btnRefresh.addActionListener(new ActionListener() { |
157 | 174 |
@Override |
158 | 175 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
169 | 186 |
@Override |
170 | 187 |
public void mouseClicked(MouseEvent e) { |
171 | 188 |
if( e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2 ) { |
172 |
doCenter(); |
|
189 |
doCenterError();
|
|
173 | 190 |
} |
174 | 191 |
} |
175 | 192 |
}); |
... | ... | |
207 | 224 |
doUpdateFilter(); |
208 | 225 |
} |
209 | 226 |
}); |
227 |
this.btnShowForm.addActionListener(new ActionListener() { |
|
228 |
@Override |
|
229 |
public void actionPerformed(ActionEvent e) { |
|
230 |
services.setShowFormWhenEdit(btnShowForm.isSelected()); |
|
231 |
} |
|
232 |
}); |
|
233 |
this.btnEraseErrorMarks.addActionListener(new ActionListener() { |
|
234 |
@Override |
|
235 |
public void actionPerformed(ActionEvent e) { |
|
236 |
services.addError(null); |
|
237 |
} |
|
238 |
}); |
|
210 | 239 |
DefaultComboBoxModel<ListElement<TopologyRuleFactory>> modelRules = new DefaultComboBoxModel<>(); |
211 | 240 |
modelRules.addElement(new ListElement<>(i18n.getTranslation("_Any_rule"), (TopologyRuleFactory)null)); |
212 | 241 |
List<TopologyRuleFactory> factories = TopologyLocator.getTopologyManager().getRuleFactories(); |
... | ... | |
244 | 273 |
this.tabData.setEnabledAt(1, false); |
245 | 274 |
|
246 | 275 |
} |
276 |
|
|
277 |
@Override |
|
278 |
public ImageIcon loadImage(String imageName) { |
|
279 |
String name = FilenameUtils.getBaseName(imageName); |
|
280 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
281 |
if (theme.exists(name)) { |
|
282 |
return theme.get(name); |
|
283 |
} |
|
284 |
URL url = this.getClass().getResource("/"+imageName); |
|
285 |
if (url == null) { |
|
286 |
return null; |
|
287 |
} |
|
288 |
return new ImageIcon(url); |
|
289 |
} |
|
247 | 290 |
|
248 | 291 |
private void translate() { |
249 | 292 |
ToolsSwingManager tsm = ToolsSwingLocator.getToolsSwingManager(); |
250 | 293 |
tsm.translate(this.btnActions); |
251 |
tsm.translate(this.btnCenter); |
|
294 |
tsm.translate(this.btnCenterError); |
|
295 |
tsm.translate(this.btnCenterGeometry); |
|
252 | 296 |
tsm.translate(this.btnRefresh); |
253 | 297 |
tsm.translate(this.btnShowErrors); |
254 | 298 |
tsm.translate(this.btnShowExceptions); |
255 |
tsm.translate(this.btnZoom); |
|
299 |
tsm.translate(this.btnZoomError); |
|
300 |
tsm.translate(this.btnZoomGeometry); |
|
301 |
tsm.translate(this.btnEraseErrorMarks); |
|
256 | 302 |
tsm.translate(this.btnVisibleExtentOnly); |
257 | 303 |
tsm.translate(this.btnParametersAccept); |
258 | 304 |
tsm.translate(this.btnParametersCancel); |
305 |
tsm.translate(this.btnShowForm); |
|
259 | 306 |
tsm.translate(this.lblShow); |
260 | 307 |
tsm.translate(this.tabData); |
261 | 308 |
} |
... | ... | |
383 | 430 |
if (n < 0) { |
384 | 431 |
return; |
385 | 432 |
} |
386 |
TopologyReportLine line = this.linesModel.getLine(n);
|
|
387 |
TopologyRule rule = line.getRule();
|
|
433 |
int[] selectedRows = this.tblErrors.getSelectedRows();
|
|
434 |
TopologyRule rule = this.linesModel.getLine(selectedRows[0]).getRule();
|
|
388 | 435 |
List<TopologyRuleAction> actions = rule.getActions(); |
389 | 436 |
if (actions == null || actions.isEmpty()) { |
390 | 437 |
return; |
438 |
} |
|
439 |
List<TopologyReportLine>lines = new ArrayList<>(); |
|
440 |
for (int selectedRow : selectedRows) { |
|
441 |
TopologyReportLine line = this.linesModel.getLine(selectedRow); |
|
442 |
if( line.getRule()==rule ) { |
|
443 |
lines.add(line); |
|
444 |
} |
|
391 | 445 |
} |
392 | 446 |
JPopupMenu menu = new JPopupMenu(); |
393 | 447 |
for (TopologyRuleAction action : actions) { |
... | ... | |
397 | 451 |
} else { |
398 | 452 |
item = new JMenuItem(action.getName()); |
399 | 453 |
} |
400 |
item.addActionListener(new TopologyRuleActionListener(rule, line, action)); |
|
454 |
item.addActionListener(new TopologyRuleActionListener(rule, lines, action)); |
|
455 |
if( lines.size()>1 && action.hasParameters() ) { |
|
456 |
item.setEnabled(false); |
|
457 |
} |
|
401 | 458 |
menu.add(item); |
402 | 459 |
} |
403 | 460 |
menu.show(this.btnActions, 0, this.btnActions.getHeight()); |
... | ... | |
405 | 462 |
|
406 | 463 |
private void doExecuteRuleAction( |
407 | 464 |
TopologyRule rule, |
408 |
TopologyReportLine line,
|
|
465 |
List<TopologyReportLine> lines,
|
|
409 | 466 |
TopologyRuleAction action, |
410 | 467 |
JDynForm form |
411 | 468 |
) { |
... | ... | |
416 | 473 |
form.getValues(parameters); |
417 | 474 |
} |
418 | 475 |
} |
419 |
action.execute(rule, line, parameters); |
|
476 |
for (TopologyReportLine line : lines) { |
|
477 |
action.execute(rule, line, parameters); |
|
478 |
} |
|
420 | 479 |
this.tabData.setEnabledAt(0, true); |
421 | 480 |
this.tabData.setEnabledAt(1, false); |
422 | 481 |
this.tabData.setSelectedIndex(0); |
423 | 482 |
this.pnlParameters.removeAll(); |
424 |
this.services.refreshView();
|
|
483 |
this.services.addError(null);
|
|
425 | 484 |
} |
426 | 485 |
|
427 | 486 |
private void doShowActionParametersPanel( |
428 | 487 |
TopologyRule rule, |
429 |
TopologyReportLine line,
|
|
488 |
List<TopologyReportLine> lines,
|
|
430 | 489 |
TopologyRuleAction action |
431 | 490 |
) { |
432 | 491 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
... | ... | |
456 | 515 |
} |
457 | 516 |
} |
458 | 517 |
this.btnParametersAccept.addActionListener( |
459 |
new TopologyRuleActionParametersListener(rule, line, action, form) |
|
518 |
new TopologyRuleActionParametersListener(rule, lines, action, form)
|
|
460 | 519 |
); |
461 | 520 |
} catch (Exception ex) { |
462 | 521 |
LOGGER.warn("Can't show action parameters panel.",ex); |
463 | 522 |
} |
464 | 523 |
} |
465 | 524 |
|
466 |
private void doZoom() { |
|
525 |
private void doZoomGeometry() {
|
|
467 | 526 |
int n = this.tblErrors.getSelectedRow(); |
468 | 527 |
if (n < 0) { |
469 | 528 |
return; |
... | ... | |
473 | 532 |
this.services.zoomTo(geom.getEnvelope()); |
474 | 533 |
} |
475 | 534 |
|
476 |
private void doCenter() { |
|
535 |
private void doZoomError() { |
|
536 |
int n = this.tblErrors.getSelectedRow(); |
|
537 |
if (n < 0) { |
|
538 |
return; |
|
539 |
} |
|
540 |
TopologyReportLine line = this.linesModel.getLine(n); |
|
541 |
Geometry geom = line.getError(); |
|
542 |
if( geom == null ) { |
|
543 |
geom = line.getGeometry(); |
|
544 |
services.addError(null); |
|
545 |
} else { |
|
546 |
services.addError(geom); |
|
547 |
} |
|
548 |
this.services.zoomTo(geom.getEnvelope()); |
|
549 |
} |
|
550 |
|
|
551 |
private void doCenterGeometry() { |
|
477 | 552 |
try { |
478 | 553 |
int n = this.tblErrors.getSelectedRow(); |
479 | 554 |
if (n < 0) { |
... | ... | |
487 | 562 |
} |
488 | 563 |
} |
489 | 564 |
|
565 |
private void doCenterError() { |
|
566 |
try { |
|
567 |
int n = this.tblErrors.getSelectedRow(); |
|
568 |
if (n < 0) { |
|
569 |
return; |
|
570 |
} |
|
571 |
TopologyReportLine line = this.linesModel.getLine(n); |
|
572 |
Geometry geom = line.getError(); |
|
573 |
if( geom == null ) { |
|
574 |
geom = line.getGeometry(); |
|
575 |
services.addError(null); |
|
576 |
} else { |
|
577 |
services.addError(geom); |
|
578 |
} |
|
579 |
this.services.centerTo(geom.centroid()); |
|
580 |
} catch (Exception ex) { |
|
581 |
LOGGER.warn("Can't center topology error", ex); |
|
582 |
} |
|
583 |
} |
|
584 |
|
|
490 | 585 |
private void doRowSelected() { |
491 | 586 |
try { |
492 | 587 |
int n = this.tblErrors.getSelectedRow(); |
... | ... | |
497 | 592 |
if (line.getFeature1() == null) { |
498 | 593 |
return; |
499 | 594 |
} |
500 |
FeatureSelection selection = line.getDataSet1().getStore().getFeatureSelection(); |
|
595 |
this.services.addError(null); |
|
596 |
FeatureSelection selection = line.getDataSet1().getFeatureStore().getFeatureSelection(); |
|
501 | 597 |
selection.deselectAll(); |
502 | 598 |
selection.select(line.getFeature1()); |
503 | 599 |
} catch (Exception ex) { |
Also available in: Unified diff