Changeset 1839 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-07-25T17:18:21+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/dialogs/relation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r1832 r1839 20 20 import java.awt.event.WindowAdapter; 21 21 import java.awt.event.WindowEvent; 22 import java.beans.PropertyChangeEvent; 23 import java.beans.PropertyChangeListener; 22 24 import java.io.IOException; 23 25 import java.util.ArrayList; 24 26 import java.util.Collection; 27 import java.util.Collections; 28 import java.util.HashSet; 29 import java.util.Iterator; 30 import java.util.List; 25 31 import java.util.logging.Logger; 26 32 … … 40 46 import javax.swing.KeyStroke; 41 47 import javax.swing.SwingUtilities; 48 import javax.swing.event.AncestorEvent; 49 import javax.swing.event.AncestorListener; 42 50 import javax.swing.event.ChangeEvent; 43 51 import javax.swing.event.ChangeListener; … … 60 68 import org.openstreetmap.josm.data.osm.RelationMember; 61 69 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 70 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 62 71 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 72 import org.openstreetmap.josm.gui.PrimitiveNameFormatter; 63 73 import org.openstreetmap.josm.gui.SideButton; 64 74 import org.openstreetmap.josm.gui.dialogs.relation.ac.AutoCompletionCache; … … 310 320 */ 311 321 protected JPanel buildMemberEditorPanel() { 312 JPanel pnl = new JPanel();322 final JPanel pnl = new JPanel(); 313 323 pnl.setLayout(new GridBagLayout()); 314 324 // setting up the member table … … 403 413 } 404 414 }); 415 405 416 406 417 JPanel pnl3 = new JPanel(); … … 617 628 } 618 629 619 class AddSelectedAtStartAction extends AbstractAction implements TableModelListener { 630 class AddAbortException extends Exception { 631 } 632 633 abstract class AddFromSelectionAction extends AbstractAction { 634 private PrimitiveNameFormatter nameFormatter = new PrimitiveNameFormatter(); 635 636 protected boolean isPotentialDuplicate(OsmPrimitive primitive) { 637 return memberTableModel.hasMembersReferringTo(Collections.singleton(primitive)); 638 } 639 640 protected boolean confirmAddingPrimtive(OsmPrimitive primitive) throws AddAbortException { 641 String msg = tr("<html>This relation already has one or more members referring to<br>" 642 + "the primitive ''{0}''<br>" 643 + "<br>" 644 + "Do you really want to add another relation member?</html>", 645 nameFormatter.getName(primitive) 646 ); 647 int ret = ConditionalOptionPaneUtil.showOptionDialog( 648 "add_primitive_to_relation", 649 Main.parent, 650 msg, 651 tr("Multiple members referring to same primitive"), 652 JOptionPane.YES_NO_CANCEL_OPTION, 653 JOptionPane.WARNING_MESSAGE, 654 null, 655 null 656 ); 657 switch(ret) { 658 case ConditionalOptionPaneUtil.DIALOG_DISABLED_OPTION : return true; 659 case JOptionPane.YES_OPTION: return true; 660 case JOptionPane.NO_OPTION: return false; 661 case JOptionPane.CLOSED_OPTION: return false; 662 case JOptionPane.CANCEL_OPTION: throw new AddAbortException(); 663 } 664 // should not happen 665 return false; 666 } 667 668 protected List<OsmPrimitive> filterConfirmedPrimitives(List<OsmPrimitive> primitives) throws AddAbortException { 669 if (primitives == null || primitives.isEmpty()) 670 return primitives; 671 ArrayList<OsmPrimitive> ret = new ArrayList<OsmPrimitive>(); 672 Iterator<OsmPrimitive> it = primitives.iterator(); 673 while(it.hasNext()) { 674 OsmPrimitive primitive = it.next(); 675 if (isPotentialDuplicate(primitive) && confirmAddingPrimtive(primitive)) { 676 ret.add(primitive); 677 } 678 } 679 return ret; 680 } 681 } 682 683 class AddSelectedAtStartAction extends AddFromSelectionAction implements TableModelListener { 620 684 public AddSelectedAtStartAction() { 621 685 putValue(SHORT_DESCRIPTION, … … 631 695 632 696 public void actionPerformed(ActionEvent e) { 633 memberTableModel.addMembersAtBeginning(selectionTableModel.getSelection()); 697 try { 698 List<OsmPrimitive> toAdd = filterConfirmedPrimitives(selectionTableModel.getSelection()); 699 memberTableModel.addMembersAtBeginning(toAdd); 700 } catch(AddAbortException ex) { 701 // do nothing 702 } 634 703 } 635 704 … … 639 708 } 640 709 641 class AddSelectedAtEndAction extends A bstractAction implements TableModelListener {710 class AddSelectedAtEndAction extends AddFromSelectionAction implements TableModelListener { 642 711 public AddSelectedAtEndAction() { 643 712 putValue(SHORT_DESCRIPTION, tr("Add all primitives selected in the current dataset after the last member")); … … 652 721 653 722 public void actionPerformed(ActionEvent e) { 654 memberTableModel.addMembersAtEnd(selectionTableModel.getSelection()); 723 try { 724 List<OsmPrimitive> toAdd = filterConfirmedPrimitives(selectionTableModel.getSelection()); 725 memberTableModel.addMembersAtEnd(toAdd); 726 } catch(AddAbortException ex) { 727 // do nothing 728 } 655 729 } 656 730 … … 660 734 } 661 735 662 class AddSelectedBeforeSelection extends A bstractAction implements TableModelListener, ListSelectionListener {736 class AddSelectedBeforeSelection extends AddFromSelectionAction implements TableModelListener, ListSelectionListener { 663 737 public AddSelectedBeforeSelection() { 664 738 putValue(SHORT_DESCRIPTION, … … 675 749 676 750 public void actionPerformed(ActionEvent e) { 677 memberTableModel.addMembersBeforeIdx(selectionTableModel.getSelection(), memberTableModel 678 .getSelectionModel().getMinSelectionIndex()); 751 try { 752 List<OsmPrimitive> toAdd = filterConfirmedPrimitives(selectionTableModel.getSelection()); 753 memberTableModel.addMembersBeforeIdx(toAdd, memberTableModel 754 .getSelectionModel().getMinSelectionIndex()); 755 } catch(AddAbortException ex) { 756 // do nothing 757 } 758 759 679 760 } 680 761 … … 688 769 } 689 770 690 class AddSelectedAfterSelection extends A bstractAction implements TableModelListener, ListSelectionListener {771 class AddSelectedAfterSelection extends AddFromSelectionAction implements TableModelListener, ListSelectionListener { 691 772 public AddSelectedAfterSelection() { 692 773 putValue(SHORT_DESCRIPTION, … … 703 784 704 785 public void actionPerformed(ActionEvent e) { 705 memberTableModel.addMembersAfterIdx(selectionTableModel.getSelection(), memberTableModel 706 .getSelectionModel().getMaxSelectionIndex()); 786 try { 787 List<OsmPrimitive> toAdd = filterConfirmedPrimitives(selectionTableModel.getSelection()); 788 memberTableModel.addMembersAfterIdx(toAdd, memberTableModel 789 .getSelectionModel().getMaxSelectionIndex()); 790 } catch(AddAbortException ex) { 791 // do nothing 792 } 707 793 } 708 794 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java
r1831 r1839 250 250 } 251 251 252 public void addMembersAtBeginning(List< ? extendsOsmPrimitive> primitives) {252 public void addMembersAtBeginning(List<OsmPrimitive> primitives) { 253 253 if (primitives == null) 254 254 return; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/SelectionTableModel.java
r1801 r1839 90 90 } 91 91 92 public List< ? extendsOsmPrimitive> getSelection() {92 public List<OsmPrimitive> getSelection() { 93 93 return cache; 94 94 }
Note:
See TracChangeset
for help on using the changeset viewer.