Revision 760 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 | ||
---|---|---|
12 | 12 |
import java.util.List; |
13 | 13 |
import java.util.Set; |
14 | 14 |
import javax.swing.DefaultComboBoxModel; |
15 |
import javax.swing.DefaultListSelectionModel; |
|
15 | 16 |
import javax.swing.ImageIcon; |
16 | 17 |
import javax.swing.JComponent; |
17 | 18 |
import javax.swing.JMenuItem; |
18 | 19 |
import javax.swing.JPopupMenu; |
19 | 20 |
import javax.swing.JTable; |
21 |
import javax.swing.ListSelectionModel; |
|
20 | 22 |
import javax.swing.SwingUtilities; |
21 | 23 |
import javax.swing.event.ChangeEvent; |
22 | 24 |
import javax.swing.event.ChangeListener; |
... | ... | |
70 | 72 |
implements JTopologyReport { |
71 | 73 |
|
72 | 74 |
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultJTopologyReport.class); |
75 |
private ListSelectionModel selection; |
|
73 | 76 |
|
74 |
|
|
75 | 77 |
private class TopologyRuleActionParametersListener implements ActionListener { |
76 | 78 |
|
77 | 79 |
private final TopologyRule rule; |
... | ... | |
97 | 99 |
} |
98 | 100 |
} |
99 | 101 |
|
100 |
|
|
101 | 102 |
private class TopologyRuleActionListener implements ActionListener { |
102 | 103 |
|
103 | 104 |
private final TopologyRule rule; |
... | ... | |
116 | 117 |
|
117 | 118 |
@Override |
118 | 119 |
public void actionPerformed(ActionEvent e) { |
119 |
if ( this.action.hasParameters() ) {
|
|
120 |
if (this.action.hasParameters()) {
|
|
120 | 121 |
doShowActionParametersPanel(this.rule, this.lines, this.action); |
121 | 122 |
} else { |
122 | 123 |
doExecuteRuleAction(rule, lines, action, null); |
123 | 124 |
} |
124 | 125 |
} |
125 | 126 |
} |
126 |
|
|
127 |
|
|
127 | 128 |
private ReportTable linesModel; |
128 | 129 |
private final TopologySwingServices services; |
129 | 130 |
private TaskStatusController taskStatusController; |
... | ... | |
137 | 138 |
|
138 | 139 |
private void initComponents() { |
139 | 140 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
141 |
this.selection = this.tblErrors.getSelectionModel(); |
|
140 | 142 |
this.linesModel = new ReportTable(); |
143 |
|
|
141 | 144 |
this.workingAreaChangedListener = new WorkingAreaChangedListener() { |
142 | 145 |
@Override |
143 | 146 |
public void workingAreaChanged(Envelope workingArea) { |
... | ... | |
146 | 149 |
}; |
147 | 150 |
this.tblErrors.setModel(this.linesModel); |
148 | 151 |
this.tblErrors.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); |
152 |
|
|
149 | 153 |
this.btnZoomGeometry.addActionListener(new ActionListener() { |
150 | 154 |
@Override |
151 | 155 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
185 | 189 |
this.tblErrors.addMouseListener(new MouseAdapter() { |
186 | 190 |
@Override |
187 | 191 |
public void mouseClicked(MouseEvent e) { |
188 |
if( e.getButton()==MouseEvent.BUTTON1 && e.getClickCount()==2 ) {
|
|
192 |
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
|
|
189 | 193 |
doCenterError(); |
190 | 194 |
} |
191 | 195 |
} |
192 | 196 |
}); |
193 |
|
|
197 |
|
|
194 | 198 |
this.btnActions.addActionListener(new ActionListener() { |
195 | 199 |
@Override |
196 | 200 |
public void actionPerformed(ActionEvent e) { |
... | ... | |
237 | 241 |
} |
238 | 242 |
}); |
239 | 243 |
DefaultComboBoxModel<ListElement<TopologyRuleFactory>> modelRules = new DefaultComboBoxModel<>(); |
240 |
modelRules.addElement(new ListElement<>(i18n.getTranslation("_Any_rule"), (TopologyRuleFactory)null)); |
|
244 |
modelRules.addElement(new ListElement<>(i18n.getTranslation("_Any_rule"), (TopologyRuleFactory) null));
|
|
241 | 245 |
List<TopologyRuleFactory> factories = TopologyLocator.getTopologyManager().getRuleFactories(); |
242 | 246 |
for (TopologyRuleFactory factory : factories) { |
243 | 247 |
modelRules.addElement(new ListElement<>(factory.getName(), factory)); |
... | ... | |
269 | 273 |
this.btnShowErrors.setSelected(false); |
270 | 274 |
this.btnShowExceptions.setSelected(false); |
271 | 275 |
this.btnVisibleExtentOnly.setSelected(false); |
272 |
|
|
276 |
|
|
273 | 277 |
this.tabData.setEnabledAt(1, false); |
274 | 278 |
|
275 | 279 |
} |
276 |
|
|
280 |
|
|
277 | 281 |
@Override |
278 | 282 |
public ImageIcon loadImage(String imageName) { |
279 | 283 |
String name = FilenameUtils.getBaseName(imageName); |
... | ... | |
281 | 285 |
if (theme.exists(name)) { |
282 | 286 |
return theme.get(name); |
283 | 287 |
} |
284 |
URL url = this.getClass().getResource("/"+imageName);
|
|
288 |
URL url = this.getClass().getResource("/" + imageName);
|
|
285 | 289 |
if (url == null) { |
286 | 290 |
return null; |
287 | 291 |
} |
... | ... | |
332 | 336 |
private String getFilter() { |
333 | 337 |
ExpressionBuilder builder = ExpressionEvaluatorLocator.getManager().createExpressionBuilder(); |
334 | 338 |
TopologyRuleFactory ruleFactory = (TopologyRuleFactory) ListElement.getSelected(cboRules); |
335 |
if( ruleFactory != null ) {
|
|
339 |
if (ruleFactory != null) {
|
|
336 | 340 |
builder.setValue( |
337 |
builder.eq( |
|
338 |
builder.column(TopologyReport.RULE_ID), |
|
339 |
builder.constant(ruleFactory.getId()) |
|
340 |
) |
|
341 |
builder.eq(
|
|
342 |
builder.column(TopologyReport.RULE_ID),
|
|
343 |
builder.constant(ruleFactory.getId())
|
|
344 |
)
|
|
341 | 345 |
); |
342 | 346 |
} |
343 |
if( this.btnShowErrors.isSelected() ) {
|
|
344 |
if( btnShowExceptions.isSelected()) {
|
|
347 |
if (this.btnShowErrors.isSelected()) {
|
|
348 |
if (btnShowExceptions.isSelected()) {
|
|
345 | 349 |
builder.and( |
346 | 350 |
builder.or( |
347 |
builder.column(TopologyReport.IS_ERROR),
|
|
348 |
builder.column(TopologyReport.IS_EXCEPTION) |
|
351 |
builder.column(TopologyReport.IS_ERROR),
|
|
352 |
builder.column(TopologyReport.IS_EXCEPTION)
|
|
349 | 353 |
) |
350 | 354 |
); |
351 | 355 |
} else { |
352 | 356 |
builder.and( |
353 |
builder.column(TopologyReport.IS_ERROR) |
|
357 |
builder.column(TopologyReport.IS_ERROR)
|
|
354 | 358 |
); |
355 | 359 |
} |
356 |
} else if( btnShowExceptions.isSelected()) {
|
|
360 |
} else if (btnShowExceptions.isSelected()) {
|
|
357 | 361 |
builder.and( |
358 |
builder.column(TopologyReport.IS_EXCEPTION) |
|
362 |
builder.column(TopologyReport.IS_EXCEPTION)
|
|
359 | 363 |
); |
360 | 364 |
} |
361 |
if( this.btnVisibleExtentOnly.isSelected() ) {
|
|
365 |
if (this.btnVisibleExtentOnly.isSelected()) {
|
|
362 | 366 |
Envelope workingArea = this.services.getWorkingArea(); |
363 |
if( workingArea!=null ) {
|
|
367 |
if (workingArea != null) {
|
|
364 | 368 |
builder.and( |
365 | 369 |
builder.ST_Intersects( |
366 |
builder.column(TopologyReport.GEOMETRY),
|
|
370 |
builder.column(TopologyReport.GEOMETRY), |
|
367 | 371 |
builder.geometry(workingArea.getGeometry()) |
368 | 372 |
) |
369 | 373 |
); |
... | ... | |
372 | 376 |
} else { |
373 | 377 |
this.services.removeWorkingAreaChangedListener(this.workingAreaChangedListener); |
374 | 378 |
} |
375 |
if( builder.getValue()==null ) {
|
|
379 |
if (builder.getValue() == null) {
|
|
376 | 380 |
return null; |
377 | 381 |
} |
378 | 382 |
return builder.toString(); |
379 | 383 |
} |
380 |
|
|
384 |
|
|
381 | 385 |
private void doExecutePlan() { |
382 | 386 |
Thread th = new Thread(new Runnable() { |
383 | 387 |
@Override |
... | ... | |
401 | 405 |
return; |
402 | 406 |
} |
403 | 407 |
TaskStatus taskStatus = (TaskStatus) observable; |
404 |
if (taskStatus==null || !taskStatus.isRunning()) {
|
|
408 |
if (taskStatus == null || !taskStatus.isRunning()) {
|
|
405 | 409 |
this.lblTaskStatusTitle.setVisible(false); |
406 | 410 |
this.lblTaskStatusMessage.setVisible(false); |
407 | 411 |
this.pbTaskStatusProgress.setVisible(false); |
408 | 412 |
this.btnTaskStatusCancel.setVisible(false); |
409 | 413 |
this.btnRefresh.setEnabled(true); |
410 | 414 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
411 |
message(i18n.getTranslation("_Errors")+": "+this.linesModel.getRowCount());
|
|
415 |
message(i18n.getTranslation("_Errors") + ": " + this.linesModel.getRowCount());
|
|
412 | 416 |
return; |
413 | 417 |
} |
414 | 418 |
if (!this.pbTaskStatusProgress.isVisible()) { |
... | ... | |
424 | 428 |
this.lblTaskStatusTitle.setText(msg); |
425 | 429 |
this.lblTaskStatusTitle.setVisible(true); |
426 | 430 |
} |
427 |
|
|
431 |
|
|
428 | 432 |
private void doSelectAction() { |
429 | 433 |
int n = this.tblErrors.getSelectedRow(); |
430 | 434 |
if (n < 0) { |
... | ... | |
435 | 439 |
List<TopologyRuleAction> actions = rule.getActions(); |
436 | 440 |
if (actions == null || actions.isEmpty()) { |
437 | 441 |
return; |
438 |
}
|
|
439 |
List<TopologyReportLine>lines = new ArrayList<>(); |
|
442 |
} |
|
443 |
List<TopologyReportLine> lines = new ArrayList<>();
|
|
440 | 444 |
for (int selectedRow : selectedRows) { |
441 | 445 |
TopologyReportLine line = this.linesModel.getLine(selectedRow); |
442 |
if( line.getRule()==rule ) {
|
|
446 |
if (line.getRule() == rule) {
|
|
443 | 447 |
lines.add(line); |
444 | 448 |
} |
445 | 449 |
} |
446 | 450 |
JPopupMenu menu = new JPopupMenu(); |
447 | 451 |
for (TopologyRuleAction action : actions) { |
448 | 452 |
JMenuItem item; |
449 |
if( action.hasParameters() ) {
|
|
450 |
item = new JMenuItem(action.getName()+"...");
|
|
453 |
if (action.hasParameters()) {
|
|
454 |
item = new JMenuItem(action.getName() + "...");
|
|
451 | 455 |
} else { |
452 |
item = new JMenuItem(action.getName());
|
|
456 |
item = new JMenuItem(action.getName()); |
|
453 | 457 |
} |
454 | 458 |
item.addActionListener(new TopologyRuleActionListener(rule, lines, action)); |
455 |
if( lines.size()>1 && action.hasParameters() ) {
|
|
459 |
if (lines.size() > 1 && action.hasParameters()) {
|
|
456 | 460 |
item.setEnabled(false); |
457 | 461 |
} |
458 | 462 |
menu.add(item); |
... | ... | |
467 | 471 |
JDynForm form |
468 | 472 |
) { |
469 | 473 |
DynObject parameters = null; |
470 |
if( form!=null ) {
|
|
474 |
if (form != null) {
|
|
471 | 475 |
parameters = action.createParameters(); |
472 |
if( parameters!=null ) {
|
|
476 |
if (parameters != null) {
|
|
473 | 477 |
form.getValues(parameters); |
474 | 478 |
} |
475 | 479 |
} |
... | ... | |
496 | 500 |
try { |
497 | 501 |
JDynForm form = null; |
498 | 502 |
this.lblActionTitle.setText( |
499 |
"<html>" +
|
|
500 |
i18n.getTranslation("_Rule") + ": <b>" +
|
|
501 |
rule.getName() + "</b>, " +
|
|
502 |
i18n.getTranslation("_Action") + ": <b>" +
|
|
503 |
action.getName() + "</b></html>" |
|
503 |
"<html>" |
|
504 |
+ i18n.getTranslation("_Rule") + ": <b>"
|
|
505 |
+ rule.getName() + "</b>, "
|
|
506 |
+ i18n.getTranslation("_Action") + ": <b>"
|
|
507 |
+ action.getName() + "</b></html>"
|
|
504 | 508 |
); |
505 |
this.lblActionDescription.setText("<html>"+action.getShortDescription()+"</html>");
|
|
509 |
this.lblActionDescription.setText("<html>" + action.getShortDescription() + "</html>");
|
|
506 | 510 |
DynObject parameters = action.createParameters(); |
507 |
if( parameters!=null ) {
|
|
511 |
if (parameters != null) {
|
|
508 | 512 |
form = DynFormLocator.getDynFormManager().createJDynForm(parameters); |
509 |
if( form!=null ) {
|
|
513 |
if (form != null) {
|
|
510 | 514 |
this.pnlParameters.setLayout(new BorderLayout()); |
511 | 515 |
this.pnlParameters.removeAll(); |
512 | 516 |
this.pnlParameters.add(form.asJComponent(), BorderLayout.CENTER); |
... | ... | |
515 | 519 |
} |
516 | 520 |
} |
517 | 521 |
this.btnParametersAccept.addActionListener( |
518 |
new TopologyRuleActionParametersListener(rule, lines, action, form) |
|
522 |
new TopologyRuleActionParametersListener(rule, lines, action, form)
|
|
519 | 523 |
); |
520 | 524 |
} catch (Exception ex) { |
521 |
LOGGER.warn("Can't show action parameters panel.",ex); |
|
525 |
LOGGER.warn("Can't show action parameters panel.", ex);
|
|
522 | 526 |
} |
523 | 527 |
} |
524 | 528 |
|
... | ... | |
539 | 543 |
} |
540 | 544 |
TopologyReportLine line = this.linesModel.getLine(n); |
541 | 545 |
Geometry geom = line.getError(); |
542 |
if( geom == null ) {
|
|
546 |
if (geom == null) {
|
|
543 | 547 |
geom = line.getGeometry(); |
544 | 548 |
services.addError(null); |
545 | 549 |
} else { |
... | ... | |
570 | 574 |
} |
571 | 575 |
TopologyReportLine line = this.linesModel.getLine(n); |
572 | 576 |
Geometry geom = line.getError(); |
573 |
if( geom == null ) {
|
|
577 |
if (geom == null) {
|
|
574 | 578 |
geom = line.getGeometry(); |
575 | 579 |
services.addError(null); |
576 | 580 |
} else { |
... | ... | |
601 | 605 |
} |
602 | 606 |
} |
603 | 607 |
|
604 |
private static class ReportTable implements TableModel {
|
|
608 |
private class ReportTable implements TableModel { |
|
605 | 609 |
|
606 | 610 |
private TopologyReport report; |
607 | 611 |
private TopologyReportLineSet lines; |
... | ... | |
633 | 637 |
this.reportListener = new ChangeListener() { |
634 | 638 |
@Override |
635 | 639 |
public void stateChanged(final ChangeEvent e) { |
636 |
if( !SwingUtilities.isEventDispatchThread() ) {
|
|
640 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
637 | 641 |
SwingUtilities.invokeLater(new Runnable() { |
638 | 642 |
@Override |
639 | 643 |
public void run() { |
... | ... | |
657 | 661 |
} |
658 | 662 |
|
659 | 663 |
public void setFilter(String filter) { |
660 |
if( StringUtils.equals(filter, this.lastFilter) ) {
|
|
664 |
if (StringUtils.equals(filter, this.lastFilter)) {
|
|
661 | 665 |
return; |
662 | 666 |
} |
663 | 667 |
this.lines = this.report.getLineSet(filter); |
... | ... | |
665 | 669 |
this.lastFilter = filter; |
666 | 670 |
this.fireTableChanged(); |
667 | 671 |
} |
668 |
|
|
672 |
|
|
669 | 673 |
public TopologyReport getReport() { |
670 | 674 |
return this.report; |
671 | 675 |
} |
... | ... | |
738 | 742 |
} |
739 | 743 |
|
740 | 744 |
private void fireTableChanged() { |
745 |
saveCurrentSelection(); |
|
741 | 746 |
for (TableModelListener tableListener : this.tableListeners) { |
742 | 747 |
tableListener.tableChanged(new TableModelEvent(this)); |
743 | 748 |
} |
749 |
restoreCurrentSelection(); |
|
744 | 750 |
} |
745 | 751 |
|
746 | 752 |
public TopologyReportLine getLine(int lineNum) { |
... | ... | |
748 | 754 |
} |
749 | 755 |
|
750 | 756 |
} |
757 |
|
|
758 |
private void saveCurrentSelection() { |
|
759 |
this.tblErrors.setSelectionModel(new DefaultListSelectionModel()); |
|
760 |
} |
|
761 |
|
|
762 |
private void restoreCurrentSelection() { |
|
763 |
this.tblErrors.setSelectionModel(this.selection); |
|
764 |
} |
|
751 | 765 |
} |
Also available in: Unified diff