- Timestamp:
- 2018-07-12T23:02:02+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 32 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditor.java
r13761 r14027 24 24 import java.awt.event.WindowEvent; 25 25 import java.util.ArrayList; 26 import java.util.Arrays; 26 27 import java.util.Collection; 27 28 import java.util.Collections; … … 49 50 50 51 import org.openstreetmap.josm.Main; 51 import org.openstreetmap.josm.actions.ExpertToggleAction;52 52 import org.openstreetmap.josm.actions.JosmAction; 53 53 import org.openstreetmap.josm.command.ChangeCommand; … … 76 76 import org.openstreetmap.josm.gui.dialogs.relation.actions.DuplicateRelationAction; 77 77 import org.openstreetmap.josm.gui.dialogs.relation.actions.EditAction; 78 import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionAccess; 79 import org.openstreetmap.josm.gui.dialogs.relation.actions.IRelationEditorActionGroup; 78 80 import org.openstreetmap.josm.gui.dialogs.relation.actions.MoveDownAction; 79 81 import org.openstreetmap.josm.gui.dialogs.relation.actions.MoveUpAction; … … 93 95 import org.openstreetmap.josm.gui.help.HelpUtil; 94 96 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 97 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 95 98 import org.openstreetmap.josm.gui.tagging.TagEditorPanel; 96 99 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; … … 221 224 selectionTable.setRowHeight(ce.getEditor().getPreferredSize().height); 222 225 223 leftButtonToolbar = new LeftButtonToolbar( memberTable, memberTableModel, this);226 leftButtonToolbar = new LeftButtonToolbar(new RelationEditorActionAccess()); 224 227 tfRole = buildRoleTextField(this); 225 228 226 229 JSplitPane pane = buildSplitPane( 227 230 buildTagEditorPanel(tagEditorPanel), 228 buildMemberEditorPanel( memberTable, memberTableModel, selectionTable, selectionTableModel, this, leftButtonToolbar, tfRole),231 buildMemberEditorPanel(leftButtonToolbar, new RelationEditorActionAccess()), 229 232 this); 230 233 pane.setPreferredSize(new Dimension(100, 100)); … … 248 251 } 249 252 }); 250 251 refreshAction = new RefreshAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 252 applyAction = new ApplyAction(memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this); 253 selectAction = new SelectAction(getLayer(), this); 254 duplicateAction = new DuplicateRelationAction(memberTableModel, tagEditorPanel.getModel(), getLayer()); 255 deleteAction = new DeleteCurrentRelationAction(getLayer(), this); 253 254 IRelationEditorActionAccess actionAccess = new RelationEditorActionAccess(); 255 256 refreshAction = new RefreshAction(actionAccess); 257 applyAction = new ApplyAction(actionAccess); 258 selectAction = new SelectAction(actionAccess); 259 duplicateAction = new DuplicateRelationAction(actionAccess); 260 deleteAction = new DeleteCurrentRelationAction(actionAccess); 256 261 addPropertyChangeListener(deleteAction); 257 262 258 okAction = new OKAction( memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole);259 cancelAction = new CancelAction( memberTable, memberTableModel, tagEditorPanel.getModel(), getLayer(), this, tfRole);263 okAction = new OKAction(actionAccess); 264 cancelAction = new CancelAction(actionAccess); 260 265 261 266 getContentPane().add(buildToolBar(refreshAction, applyAction, selectAction, duplicateAction, deleteAction), BorderLayout.NORTH); … … 288 293 if (key != null) { 289 294 // handle uncommon situation, that user has no keystroke assigned to paste 290 registerCopyPasteAction(new PasteMembersAction(memberTable, getLayer(), this) { 291 @Override 295 registerCopyPasteAction(new PasteMembersAction(actionAccess) { 296 private static final long serialVersionUID = 1L; 297 298 @Override 292 299 public void actionPerformed(ActionEvent e) { 293 300 super.actionPerformed(e); … … 299 306 if (key != null) { 300 307 // handle uncommon situation, that user has no keystroke assigned to copy 301 registerCopyPasteAction(new CopyMembersAction( memberTableModel, getLayer(), this),308 registerCopyPasteAction(new CopyMembersAction(actionAccess), 302 309 "COPY_MEMBERS", key, getRootPane(), memberTable, selectionTable); 303 310 } … … 447 454 /** 448 455 * builds the panel for the relation member editor 449 * @param memberTable member table450 * @param memberTableModel member table model451 * @param selectionTable selection table452 * @param selectionTableModel selection table model453 * @param re relation editor454 456 * @param leftButtonToolbar left button toolbar 455 * @param tfRole role text field457 * @param editorAccess The relation editor 456 458 * 457 459 * @return the panel for the relation member editor 458 460 */ 459 protected static JPanel buildMemberEditorPanel(final MemberTable memberTable, MemberTableModel memberTableModel, 460 SelectionTable selectionTable, SelectionTableModel selectionTableModel, IRelationEditor re, 461 LeftButtonToolbar leftButtonToolbar, final AutoCompletingTextField tfRole) { 461 protected static JPanel buildMemberEditorPanel( 462 LeftButtonToolbar leftButtonToolbar, IRelationEditorActionAccess editorAccess) { 462 463 final JPanel pnl = new JPanel(new GridBagLayout()); 463 final JScrollPane scrollPane = new JScrollPane( memberTable);464 final JScrollPane scrollPane = new JScrollPane(editorAccess.getMemberTable()); 464 465 465 466 GridBagConstraints gc = new GridBagConstraints(); … … 495 496 JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT)); 496 497 p3.add(new JLabel(tr("Apply Role:"))); 497 p3.add( tfRole);498 SetRoleAction setRoleAction = new SetRoleAction( memberTable, memberTableModel, tfRole);499 memberTableModel.getSelectionModel().addListSelectionListener(setRoleAction);500 tfRole.getDocument().addDocumentListener(setRoleAction);501 tfRole.addActionListener(setRoleAction);502 memberTableModel.getSelectionModel().addListSelectionListener(503 e -> tfRole.setEnabled(memberTable.getSelectedRowCount() > 0)498 p3.add(editorAccess.getTextFieldRole()); 499 SetRoleAction setRoleAction = new SetRoleAction(editorAccess); 500 editorAccess.getMemberTableModel().getSelectionModel().addListSelectionListener(setRoleAction); 501 editorAccess.getTextFieldRole().getDocument().addDocumentListener(setRoleAction); 502 editorAccess.getTextFieldRole().addActionListener(setRoleAction); 503 editorAccess.getMemberTableModel().getSelectionModel().addListSelectionListener( 504 e -> editorAccess.getTextFieldRole().setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0) 504 505 ); 505 tfRole.setEnabled(memberTable.getSelectedRowCount() > 0);506 editorAccess.getTextFieldRole().setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0); 506 507 JButton btnApply = new JButton(setRoleAction); 507 508 btnApply.setPreferredSize(new Dimension(20, 20)); … … 537 538 gc.weightx = 0.0; 538 539 gc.weighty = 1.0; 539 pnl2.add(new ScrollViewport(buildSelectionControlButtonToolbar( memberTable, memberTableModel, selectionTableModel, re),540 pnl2.add(new ScrollViewport(buildSelectionControlButtonToolbar(editorAccess), 540 541 ScrollViewport.VERTICAL_DIRECTION), gc); 541 542 … … 545 546 gc.weighty = 1.0; 546 547 gc.fill = GridBagConstraints.BOTH; 547 pnl2.add(buildSelectionTablePanel( selectionTable), gc);548 pnl2.add(buildSelectionTablePanel(editorAccess.getSelectionTable()), gc); 548 549 549 550 final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); … … 551 552 splitPane.setRightComponent(pnl2); 552 553 splitPane.setOneTouchExpandable(false); 553 if ( reinstanceof Window) {554 ((Window) re).addWindowListener(new WindowAdapter() {554 if (editorAccess.getEditor() instanceof Window) { 555 ((Window) editorAccess.getEditor()).addWindowListener(new WindowAdapter() { 555 556 @Override 556 557 public void windowOpened(WindowEvent e) { … … 608 609 */ 609 610 static class LeftButtonToolbar extends JToolBar { 610 611 /** 612 * Button for performing the {@link org.openstreetmap.josm.gui.dialogs.relation.actions.SortBelowAction}. 613 */ 614 final JButton sortBelowButton; 615 616 /** 611 private static final long serialVersionUID = 1L; 612 613 /** 617 614 * Constructs a new {@code LeftButtonToolbar}. 618 * @param memberTable member table619 * @param memberTableModel member table model620 615 * @param re relation editor 621 616 */ 622 LeftButtonToolbar( MemberTable memberTable, MemberTableModel memberTableModel, IRelationEditor re) {617 LeftButtonToolbar(IRelationEditorActionAccess editorAccess) { 623 618 setOrientation(JToolBar.VERTICAL); 624 619 setFloatable(false); 625 620 626 // -- move up action 627 MoveUpAction moveUpAction = new MoveUpAction(memberTable, memberTableModel, "moveUp"); 628 memberTableModel.getSelectionModel().addListSelectionListener(moveUpAction); 629 add(moveUpAction); 630 631 // -- move down action 632 MoveDownAction moveDownAction = new MoveDownAction(memberTable, memberTableModel, "moveDown"); 633 memberTableModel.getSelectionModel().addListSelectionListener(moveDownAction); 634 add(moveDownAction); 635 636 addSeparator(); 637 638 // -- edit action 639 EditAction editAction = new EditAction(memberTable, memberTableModel, re.getLayer()); 640 memberTableModel.getSelectionModel().addListSelectionListener(editAction); 641 add(editAction); 642 643 // -- delete action 644 RemoveAction removeSelectedAction = new RemoveAction(memberTable, memberTableModel, "removeSelected"); 645 memberTable.getSelectionModel().addListSelectionListener(removeSelectedAction); 646 add(removeSelectedAction); 647 648 addSeparator(); 649 // -- sort action 650 SortAction sortAction = new SortAction(memberTable, memberTableModel); 651 memberTableModel.addTableModelListener(sortAction); 652 add(sortAction); 653 final SortBelowAction sortBelowAction = new SortBelowAction(memberTable, memberTableModel); 654 memberTableModel.addTableModelListener(sortBelowAction); 655 memberTableModel.getSelectionModel().addListSelectionListener(sortBelowAction); 656 sortBelowButton = add(sortBelowAction); 657 658 // -- reverse action 659 ReverseAction reverseAction = new ReverseAction(memberTable, memberTableModel); 660 memberTableModel.addTableModelListener(reverseAction); 661 add(reverseAction); 662 663 addSeparator(); 664 665 // -- download action 666 DownloadIncompleteMembersAction downloadIncompleteMembersAction = new DownloadIncompleteMembersAction( 667 memberTable, memberTableModel, "downloadIncomplete", re.getLayer(), re); 668 memberTable.getModel().addTableModelListener(downloadIncompleteMembersAction); 669 add(downloadIncompleteMembersAction); 670 671 // -- download selected action 672 DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembersAction = new DownloadSelectedIncompleteMembersAction( 673 memberTable, memberTableModel, null, re.getLayer(), re); 674 memberTable.getModel().addTableModelListener(downloadSelectedIncompleteMembersAction); 675 memberTable.getSelectionModel().addListSelectionListener(downloadSelectedIncompleteMembersAction); 676 add(downloadSelectedIncompleteMembersAction); 677 678 InputMap inputMap = memberTable.getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 679 inputMap.put((KeyStroke) removeSelectedAction.getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected"); 680 inputMap.put((KeyStroke) moveUpAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveUp"); 681 inputMap.put((KeyStroke) moveDownAction.getValue(AbstractAction.ACCELERATOR_KEY), "moveDown"); 682 inputMap.put((KeyStroke) downloadIncompleteMembersAction.getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete"); 621 List<IRelationEditorActionGroup> groups = new ArrayList<>(); 622 // Move 623 groups.add(buildNativeGroup(10, 624 new MoveUpAction(editorAccess, "moveUp"), 625 new MoveDownAction(editorAccess, "moveDown") 626 )); 627 // Edit 628 groups.add(buildNativeGroup(20, 629 new EditAction(editorAccess), 630 new RemoveAction(editorAccess, "removeSelected") 631 )); 632 // Sort 633 groups.add(buildNativeGroup(30, 634 new SortAction(editorAccess), 635 new SortBelowAction(editorAccess) 636 )); 637 // Reverse 638 groups.add(buildNativeGroup(40, 639 new ReverseAction(editorAccess) 640 )); 641 // Download 642 groups.add(buildNativeGroup(50, 643 new DownloadIncompleteMembersAction(editorAccess, "downloadIncomplete"), 644 new DownloadSelectedIncompleteMembersAction(editorAccess) 645 )); 646 groups.addAll(RelationEditorHooks.getMemberActions()); 647 648 IRelationEditorActionGroup.fillToolbar(this, groups, editorAccess); 649 650 651 InputMap inputMap = editorAccess.getMemberTable().getInputMap(MemberTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 652 inputMap.put((KeyStroke) new RemoveAction(editorAccess, "removeSelected").getValue(AbstractAction.ACCELERATOR_KEY), "removeSelected"); 653 inputMap.put((KeyStroke) new MoveUpAction(editorAccess, "moveUp").getValue(AbstractAction.ACCELERATOR_KEY), "moveUp"); 654 inputMap.put((KeyStroke) new MoveDownAction(editorAccess, "moveDown").getValue(AbstractAction.ACCELERATOR_KEY), "moveDown"); 655 inputMap.put((KeyStroke) new DownloadIncompleteMembersAction( 656 editorAccess, "downloadIncomplete").getValue(AbstractAction.ACCELERATOR_KEY), "downloadIncomplete"); 683 657 } 684 658 } … … 693 667 * @return control buttons panel for selection/members 694 668 */ 695 protected static JToolBar buildSelectionControlButtonToolbar(MemberTable memberTable, 696 MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor re) { 669 protected static JToolBar buildSelectionControlButtonToolbar(IRelationEditorActionAccess editorAccess) { 697 670 JToolBar tb = new JToolBar(JToolBar.VERTICAL); 698 671 tb.setFloatable(false); 699 672 700 // -- add at start action 701 AddSelectedAtStartAction addSelectionAction = new AddSelectedAtStartAction( 702 memberTableModel, selectionTableModel, re); 703 selectionTableModel.addTableModelListener(addSelectionAction); 704 tb.add(addSelectionAction); 705 706 // -- add before selected action 707 AddSelectedBeforeSelection addSelectedBeforeSelectionAction = new AddSelectedBeforeSelection( 708 memberTableModel, selectionTableModel, re); 709 selectionTableModel.addTableModelListener(addSelectedBeforeSelectionAction); 710 memberTableModel.getSelectionModel().addListSelectionListener(addSelectedBeforeSelectionAction); 711 tb.add(addSelectedBeforeSelectionAction); 712 713 // -- add after selected action 714 AddSelectedAfterSelection addSelectedAfterSelectionAction = new AddSelectedAfterSelection( 715 memberTableModel, selectionTableModel, re); 716 selectionTableModel.addTableModelListener(addSelectedAfterSelectionAction); 717 memberTableModel.getSelectionModel().addListSelectionListener(addSelectedAfterSelectionAction); 718 tb.add(addSelectedAfterSelectionAction); 719 720 // -- add at end action 721 AddSelectedAtEndAction addSelectedAtEndAction = new AddSelectedAtEndAction( 722 memberTableModel, selectionTableModel, re); 723 selectionTableModel.addTableModelListener(addSelectedAtEndAction); 724 tb.add(addSelectedAtEndAction); 725 726 tb.addSeparator(); 727 728 // -- select members action 729 SelectedMembersForSelectionAction selectMembersForSelectionAction = new SelectedMembersForSelectionAction( 730 memberTableModel, selectionTableModel, re.getLayer()); 731 selectionTableModel.addTableModelListener(selectMembersForSelectionAction); 732 memberTableModel.addTableModelListener(selectMembersForSelectionAction); 733 tb.add(selectMembersForSelectionAction); 734 735 // -- select action 736 SelectPrimitivesForSelectedMembersAction selectAction = new SelectPrimitivesForSelectedMembersAction( 737 memberTable, memberTableModel, re.getLayer()); 738 memberTable.getSelectionModel().addListSelectionListener(selectAction); 739 tb.add(selectAction); 740 741 tb.addSeparator(); 742 743 // -- remove selected action 744 RemoveSelectedAction removeSelectedAction = new RemoveSelectedAction(memberTableModel, selectionTableModel, re.getLayer()); 745 selectionTableModel.addTableModelListener(removeSelectedAction); 746 tb.add(removeSelectedAction); 747 673 List<IRelationEditorActionGroup> groups = new ArrayList<>(); 674 groups.add(buildNativeGroup(10, 675 new AddSelectedAtStartAction(editorAccess), 676 new AddSelectedBeforeSelection(editorAccess), 677 new AddSelectedAfterSelection(editorAccess), 678 new AddSelectedAtEndAction(editorAccess) 679 )); 680 groups.add(buildNativeGroup(20, 681 new SelectedMembersForSelectionAction(editorAccess), 682 new SelectPrimitivesForSelectedMembersAction(editorAccess) 683 )); 684 groups.add(buildNativeGroup(30, 685 new RemoveSelectedAction(editorAccess) 686 )); 687 groups.addAll(RelationEditorHooks.getSelectActions()); 688 689 IRelationEditorActionGroup.fillToolbar(tb, groups, editorAccess); 748 690 return tb; 691 } 692 693 private static IRelationEditorActionGroup buildNativeGroup(int order, AbstractRelationEditorAction... actions) { 694 return new IRelationEditorActionGroup() { 695 @Override 696 public int order() { 697 return order; 698 } 699 700 @Override 701 public List<AbstractRelationEditorAction> getActions(IRelationEditorActionAccess editorAccess) { 702 return Arrays.asList(actions); 703 } 704 }; 749 705 } 750 706 … … 765 721 Clipboard clipboard = ClipboardUtils.getClipboard(); 766 722 if (visible) { 767 leftButtonToolbar.sortBelowButton.setVisible(ExpertToggleAction.isExpert());768 723 RelationDialogManager.getRelationDialogManager().positionOnScreen(this); 769 724 if (windowMenuItem == null) { … … 806 761 tr("Focus Relation Editor with relation ''{0}'' in layer ''{1}''", name, layerName), 807 762 null, false, false) { 808 @Override 763 private static final long serialVersionUID = 1L; 764 765 @Override 809 766 public void actionPerformed(ActionEvent e) { 810 767 ((RelationEditor) getValue("relationEditor")).setVisible(true); … … 988 945 public void mouseClicked(MouseEvent e) { 989 946 if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { 990 new EditAction(memberTable, memberTableModel, getLayer()).actionPerformed(null); 991 } 992 } 947 new EditAction(new RelationEditorActionAccess()).actionPerformed(null); 948 } 949 } 950 } 951 952 private class RelationEditorActionAccess implements IRelationEditorActionAccess { 953 954 @Override 955 public MemberTable getMemberTable() { 956 return memberTable; 957 } 958 959 @Override 960 public MemberTableModel getMemberTableModel() { 961 return memberTableModel; 962 } 963 964 @Override 965 public SelectionTable getSelectionTable() { 966 return selectionTable; 967 } 968 969 @Override 970 public SelectionTableModel getSelectionTableModel() { 971 return selectionTableModel; 972 } 973 974 @Override 975 public IRelationEditor getEditor() { 976 return GenericRelationEditor.this; 977 } 978 979 @Override 980 public TagEditorModel getTagModel() { 981 return tagEditorPanel.getModel(); 982 } 983 984 @Override 985 public AutoCompletingTextField getTextFieldRole() { 986 return tfRole; 987 } 988 993 989 } 994 990 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java
r12620 r14027 6 6 import java.beans.PropertyChangeListener; 7 7 import java.beans.PropertyChangeSupport; 8 import java.lang.reflect.Method;9 import java.util.ArrayList;10 8 import java.util.Collection; 11 import java.util.List;12 9 13 10 import org.openstreetmap.josm.Main; … … 17 14 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 18 15 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 import org.openstreetmap.josm.tools.Logging;20 16 21 17 /** … … 24 20 */ 25 21 public abstract class RelationEditor extends ExtendedDialog implements IRelationEditor { 22 private static final long serialVersionUID = 1L; 26 23 27 24 /** the property name for the current relation. 28 25 * @see #setRelation(Relation) 29 26 * @see #getRelation() … … 35 32 */ 36 33 public static final String RELATION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".relationSnapshot"; 37 38 /** the list of registered relation editor classes */39 private static List<Class<RelationEditor>> editors = new ArrayList<>();40 34 41 35 /** The relation that this editor is working on. */ … … 71 65 72 66 /** 73 * Registers a relation editor class. Depending on the type of relation to be edited74 * {@link #getEditor(OsmDataLayer, Relation, Collection)} will create an instance of75 * this class.76 *77 * @param clazz the class78 */79 public void registerRelationEditor(Class<RelationEditor> clazz) {80 if (clazz != null && !editors.contains(clazz)) {81 editors.add(clazz);82 }83 }84 85 /**86 67 * This is a factory method that creates an appropriate RelationEditor instance suitable for editing the relation 87 68 * that was passed in as an argument. 88 69 * 89 * This method is guaranteed to return a working RelationEditor. If no specific editor has been registered for the 90 * type of relation, then a generic editor will be returned. 91 * 92 * Editors can be registered by adding their class to the static list "editors" in the RelationEditor class. 93 * When it comes to editing a relation, all registered editors are queried via their static "canEdit" method whether 94 * they feel responsible for that kind of relation, and if they return true then an instance of that class will be used. 70 * This method is guaranteed to return a working RelationEditor. 95 71 * 96 72 * @param layer the data layer the relation is a member of … … 100 76 */ 101 77 public static RelationEditor getEditor(OsmDataLayer layer, Relation r, Collection<RelationMember> selectedMembers) { 102 for (Class<RelationEditor> e : editors) {103 try {104 Method m = e.getMethod("canEdit", Relation.class);105 Boolean canEdit = (Boolean) m.invoke(null, r);106 if (canEdit) {107 return e.getConstructor(Relation.class, Collection.class).newInstance(layer, r, selectedMembers);108 }109 } catch (ReflectiveOperationException ex) {110 Logging.warn(ex);111 }112 }113 78 if (RelationDialogManager.getRelationDialogManager().isOpenInEditor(layer, r)) 114 79 return RelationDialogManager.getRelationDialogManager().getEditorForRelation(layer, r); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java
r13559 r14027 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.dialogs.relation.actions; 3 4 import java.beans.PropertyChangeEvent; 5 import java.beans.PropertyChangeListener; 6 import java.util.Objects; 3 7 4 8 import javax.swing.AbstractAction; … … 14 18 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable; 15 19 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel; 20 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable; 21 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel; 16 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 23 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 17 24 import org.openstreetmap.josm.io.OnlineResource; 18 25 19 26 /** 20 27 * Abstract superclass of relation editor actions. 28 * 21 29 * @since 9496 22 30 */ 23 public abstract class AbstractRelationEditorAction extends AbstractAction implements TableModelListener, ListSelectionListener { 24 protected final MemberTable memberTable; 25 protected final MemberTableModel memberTableModel; 26 protected final transient OsmDataLayer layer; 27 protected final transient IRelationEditor editor; 31 public abstract class AbstractRelationEditorAction extends AbstractAction 32 implements TableModelListener, ListSelectionListener, PropertyChangeListener { 33 private static final long serialVersionUID = 1L; 34 protected final transient IRelationEditorActionAccess editorAccess; 28 35 29 protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) { 30 this(memberTable, memberTableModel, actionMapKey, null, null); 31 } 36 /** 37 * Create a new relation editor action 38 * 39 * @param editorAccess 40 * The editor this action is for 41 * @param actionMapKey 42 * The key for the member table action map. 43 * @param updateOn 44 * The events that may cause the enabled state of this button to 45 * change. 46 */ 47 protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess, 48 IRelationEditorUpdateOn... updateOn) { 49 Objects.requireNonNull(editorAccess, "editorAccess"); 50 Objects.requireNonNull(updateOn, "updateOn"); 51 this.editorAccess = editorAccess; 52 for (IRelationEditorUpdateOn u : updateOn) { 53 u.register(editorAccess, this); 54 } 55 } 32 56 33 protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey, 34 OsmDataLayer layer, IRelationEditor editor) { 35 this.memberTable = memberTable; 36 this.memberTableModel = memberTableModel; 37 this.layer = layer; 38 this.editor = editor; 39 if (actionMapKey != null) { 40 this.memberTable.getActionMap().put(actionMapKey, this); 41 } 42 } 57 /** 58 * Create a new relation editor action 59 * 60 * @param editorAccess 61 * The editor this action is for 62 * @param actionMapKey 63 * The key for the member table action map. 64 * @param updateOn 65 * The events that may cause the enabled state of this button to 66 * change. 67 */ 68 protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess, String actionMapKey, 69 IRelationEditorUpdateOn... updateOn) { 70 this(editorAccess, updateOn); 71 Objects.requireNonNull(actionMapKey, "actionMapKey"); 72 73 this.editorAccess.addMemberTableAction(actionMapKey, this); 74 } 75 76 @Override 77 public void tableChanged(TableModelEvent e) { 78 updateEnabledState(); 79 } 80 81 @Override 82 public void valueChanged(ListSelectionEvent e) { 83 updateEnabledState(); 84 } 43 85 44 86 @Override 45 public void tableChanged(TableModelEvent e) {87 public void propertyChange(PropertyChangeEvent evt) { 46 88 updateEnabledState(); 47 89 } 48 90 49 @Override 50 public void valueChanged(ListSelectionEvent e) { 51 updateEnabledState(); 52 } 91 protected abstract void updateEnabledState(); 53 92 54 protected abstract void updateEnabledState(); 93 protected final boolean canDownload() { 94 if (editorAccess.getEditor().getRelation() == null) 95 return false; 96 DataSet ds = editorAccess.getEditor().getRelation().getDataSet(); 97 return !Main.isOffline(OnlineResource.OSM_API) && ds != null && !ds.isLocked() 98 && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy()); 99 } 55 100 56 protected final boolean canDownload() { 57 if (editor.getRelation() == null) 58 return false; 59 DataSet ds = editor.getRelation().getDataSet(); 60 return !Main.isOffline(OnlineResource.OSM_API) 61 && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy()); 62 } 101 protected MemberTable getMemberTable() { 102 return editorAccess.getMemberTable(); 103 } 104 105 protected MemberTableModel getMemberTableModel() { 106 return editorAccess.getMemberTableModel(); 107 } 108 109 protected SelectionTable getSelectionTable() { 110 return editorAccess.getSelectionTable(); 111 } 112 113 protected SelectionTableModel getSelectionTableModel() { 114 return editorAccess.getSelectionTableModel(); 115 } 116 117 protected IRelationEditor getEditor() { 118 return editorAccess.getEditor(); 119 } 120 121 protected TagEditorModel getTagModel() { 122 return editorAccess.getTagModel(); 123 } 124 125 protected OsmDataLayer getLayer() { 126 return editorAccess.getEditor().getLayer(); 127 } 128 129 public boolean isExpertOnly() { 130 return false; 131 } 63 132 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddFromSelectionAction.java
r13849 r14027 11 11 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 12 12 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; 13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;16 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable;17 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;19 13 20 14 /** … … 23 17 */ 24 18 abstract class AddFromSelectionAction extends AbstractRelationEditorAction { 19 private static final long serialVersionUID = 1L; 25 20 26 protected final SelectionTable selectionTable; 27 protected final SelectionTableModel selectionTableModel; 28 29 protected AddFromSelectionAction(MemberTable memberTable, MemberTableModel memberTableModel, SelectionTable selectionTable, 30 SelectionTableModel selectionTableModel, String actionMapKey, OsmDataLayer layer, IRelationEditor editor) { 31 super(memberTable, memberTableModel, actionMapKey, layer, editor); 32 this.selectionTable = selectionTable; 33 this.selectionTableModel = selectionTableModel; 21 protected AddFromSelectionAction(IRelationEditorActionAccess editorAccess, 22 IRelationEditorUpdateOn... updateOn) { 23 super(editorAccess, updateOn); 34 24 } 35 25 36 26 protected boolean isPotentialDuplicate(OsmPrimitive primitive) { 37 return memberTableModel.hasMembersReferringTo(Collections.singleton(primitive));27 return editorAccess.getMemberTableModel().hasMembersReferringTo(Collections.singleton(primitive)); 38 28 } 39 29 … … 44 34 ConditionalOptionPaneUtil.startBulkOperation("add_primitive_to_relation"); 45 35 for (OsmPrimitive primitive : primitives) { 46 if (primitive instanceof Relation && editor .getRelation() != null && editor.getRelation().equals(primitive)) {36 if (primitive instanceof Relation && editorAccess.getEditor().getRelation() != null && editorAccess.getEditor().getRelation().equals(primitive)) { 47 37 GenericRelationEditor.warnOfCircularReferences(primitive); 48 38 continue; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAfterSelection.java
r13130 r14027 7 7 8 8 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; 9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;12 9 import org.openstreetmap.josm.tools.ImageProvider; 13 10 import org.openstreetmap.josm.tools.Logging; … … 18 15 */ 19 16 public class AddSelectedAfterSelection extends AddFromSelectionAction { 17 private static final long serialVersionUID = 1L; 20 18 21 19 /** … … 25 23 * @param editor relation editor 26 24 */ 27 public AddSelectedAfterSelection( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {28 super( null, memberTableModel, null, selectionTableModel, null, null, editor);25 public AddSelectedAfterSelection(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); 29 27 putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last selected member")); 30 28 new ImageProvider("dialogs/conflict", "copyaftercurrentright").getResource().attachImageIcon(this, true); … … 34 32 @Override 35 33 protected void updateEnabledState() { 36 setEnabled(selectionTableModel.getRowCount() > 0 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 34 setEnabled(getSelectionTableModel().getRowCount() > 0 35 && getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0); 37 36 } 38 37 … … 40 39 public void actionPerformed(ActionEvent e) { 41 40 try { 42 memberTableModel.addMembersAfterIdx(filterConfirmedPrimitives(selectionTableModel.getSelection()),43 memberTableModel.getSelectionModel().getMaxSelectionIndex());41 getMemberTableModel().addMembersAfterIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()), 42 getMemberTableModel().getSelectionModel().getMaxSelectionIndex()); 44 43 } catch (AddAbortException ex) { 45 44 Logging.trace(ex); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtEndAction.java
r13130 r14027 7 7 8 8 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; 9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;12 9 import org.openstreetmap.josm.tools.ImageProvider; 13 10 import org.openstreetmap.josm.tools.Logging; … … 18 15 */ 19 16 public class AddSelectedAtEndAction extends AddFromSelectionAction { 17 private static final long serialVersionUID = 1L; 20 18 21 19 /** … … 25 23 * @param editor relation editor 26 24 */ 27 public AddSelectedAtEndAction( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {28 super( null, memberTableModel, null, selectionTableModel, null, null, editor);25 public AddSelectedAtEndAction(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); 29 27 putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset after the last member")); 30 28 new ImageProvider("dialogs/conflict", "copyendright").getResource().attachImageIcon(this, true); … … 34 32 @Override 35 33 protected void updateEnabledState() { 36 setEnabled( selectionTableModel.getRowCount() > 0);34 setEnabled(getSelectionTableModel().getRowCount() > 0); 37 35 } 38 36 … … 40 38 public void actionPerformed(ActionEvent e) { 41 39 try { 42 memberTableModel.addMembersAtEnd(filterConfirmedPrimitives(selectionTableModel.getSelection()));40 getMemberTableModel().addMembersAtEnd(filterConfirmedPrimitives(getSelectionTableModel().getSelection())); 43 41 } catch (AddAbortException ex) { 44 42 Logging.trace(ex); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedAtStartAction.java
r13130 r14027 7 7 8 8 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; 9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;12 9 import org.openstreetmap.josm.tools.ImageProvider; 13 10 import org.openstreetmap.josm.tools.Logging; … … 18 15 */ 19 16 public class AddSelectedAtStartAction extends AddFromSelectionAction { 17 private static final long serialVersionUID = 1L; 20 18 21 19 /** … … 25 23 * @param editor relation editor 26 24 */ 27 public AddSelectedAtStartAction( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {28 super( null, memberTableModel, null, selectionTableModel, null, null, editor);25 public AddSelectedAtStartAction(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); 29 27 putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first member")); 30 28 new ImageProvider("dialogs/conflict", "copystartright").getResource().attachImageIcon(this, true); … … 34 32 @Override 35 33 protected void updateEnabledState() { 36 setEnabled( selectionTableModel.getRowCount() > 0);34 setEnabled(getSelectionTableModel().getRowCount() > 0); 37 35 } 38 36 … … 40 38 public void actionPerformed(ActionEvent e) { 41 39 try { 42 memberTableModel.addMembersAtBeginning(filterConfirmedPrimitives(selectionTableModel.getSelection()));40 getMemberTableModel().addMembersAtBeginning(filterConfirmedPrimitives(getSelectionTableModel().getSelection())); 43 41 } catch (AddAbortException ex) { 44 42 Logging.trace(ex); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AddSelectedBeforeSelection.java
r13130 r14027 7 7 8 8 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; 9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;12 9 import org.openstreetmap.josm.tools.ImageProvider; 13 10 import org.openstreetmap.josm.tools.Logging; … … 18 15 */ 19 16 public class AddSelectedBeforeSelection extends AddFromSelectionAction { 17 private static final long serialVersionUID = 1L; 20 18 21 19 /** … … 25 23 * @param editor relation editor 26 24 */ 27 public AddSelectedBeforeSelection( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, IRelationEditor editor) {28 super( null, memberTableModel, null, selectionTableModel, null, null, editor);25 public AddSelectedBeforeSelection(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); 29 27 putValue(SHORT_DESCRIPTION, tr("Add all objects selected in the current dataset before the first selected member")); 30 28 new ImageProvider("dialogs/conflict", "copybeforecurrentright").getResource().attachImageIcon(this, true); … … 34 32 @Override 35 33 protected void updateEnabledState() { 36 setEnabled(selectionTableModel.getRowCount() > 0 && memberTableModel.getSelectionModel().getMinSelectionIndex() >= 0); 34 setEnabled(getSelectionTableModel().getRowCount() > 0 35 && editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex() >= 0); 37 36 } 38 37 … … 40 39 public void actionPerformed(ActionEvent e) { 41 40 try { 42 memberTableModel.addMembersBeforeIdx(filterConfirmedPrimitives(selectionTableModel.getSelection()),43 memberTableModel.getSelectionModel().getMinSelectionIndex());41 editorAccess.getMemberTableModel().addMembersBeforeIdx(filterConfirmedPrimitives(getSelectionTableModel().getSelection()), 42 editorAccess.getMemberTableModel().getSelectionModel().getMinSelectionIndex()); 44 43 } catch (AddAbortException ex) { 45 44 Logging.trace(ex); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ApplyAction.java
r13130 r14027 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.beans.PropertyChangeEvent;8 import java.beans.PropertyChangeListener;9 7 10 import javax.swing.event.TableModelEvent;11 12 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;15 import org.openstreetmap.josm.gui.layer.OsmDataLayer;16 import org.openstreetmap.josm.gui.tagging.TagEditorModel;17 8 import org.openstreetmap.josm.tools.ImageProvider; 18 9 … … 21 12 * @since 9496 22 13 */ 23 public class ApplyAction extends SavingAction implements PropertyChangeListener { 14 public class ApplyAction extends SavingAction { 15 private static final long serialVersionUID = 1L; 24 16 25 17 /** … … 31 23 * @param tagModel tag editor model 32 24 */ 33 public ApplyAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer, 34 IRelationEditor editor) { 35 super(memberTable, memberTableModel, tagModel, layer, editor, null); 25 public ApplyAction(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.TAG_CHANGE); 36 27 putValue(SHORT_DESCRIPTION, tr("Apply the current updates")); 37 28 new ImageProvider("save").getResource().attachImageIcon(this, true); 38 29 putValue(NAME, tr("Apply")); 39 updateEnabledState(); 40 memberTableModel.addTableModelListener(this); 41 tagModel.addPropertyChangeListener(this); 30 updateEnabledState(); 42 31 } 43 32 … … 45 34 public void actionPerformed(ActionEvent e) { 46 35 if (applyChanges()) { 47 editor.reloadDataFromRelation();36 editorAccess.getEditor().reloadDataFromRelation(); 48 37 } 49 38 } … … 53 42 setEnabled(isEditorDirty()); 54 43 } 55 56 @Override57 public void propertyChange(PropertyChangeEvent evt) {58 updateEnabledState();59 }60 61 @Override62 public void tableChanged(TableModelEvent e) {63 updateEnabledState();64 }65 44 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CancelAction.java
r13842 r14027 13 13 import org.openstreetmap.josm.gui.HelpAwareOptionPane; 14 14 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 15 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;16 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;17 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;18 import org.openstreetmap.josm.gui.layer.OsmDataLayer;19 import org.openstreetmap.josm.gui.tagging.TagEditorModel;20 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;21 15 import org.openstreetmap.josm.spi.preferences.Config; 22 16 import org.openstreetmap.josm.tools.ImageProvider; … … 28 22 */ 29 23 public class CancelAction extends SavingAction { 24 private static final long serialVersionUID = 1L; 30 25 31 26 /** … … 38 33 * @param tfRole role text field 39 34 */ 40 public CancelAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer, 41 IRelationEditor editor, AutoCompletingTextField tfRole) { 42 super(memberTable, memberTableModel, tagModel, layer, editor, tfRole); 35 public CancelAction(IRelationEditorActionAccess editorAccess) { 36 super(editorAccess); 43 37 putValue(SHORT_DESCRIPTION, tr("Cancel the updates and close the dialog")); 44 38 new ImageProvider("cancel").getResource().attachImageIcon(this); 45 39 putValue(NAME, tr("Cancel")); 46 40 47 if ( editorinstanceof RootPaneContainer) {48 InputMapUtils.addEscapeAction(((RootPaneContainer) editor).getRootPane(), this);41 if (getEditor() instanceof RootPaneContainer) { 42 InputMapUtils.addEscapeAction(((RootPaneContainer) getEditor()).getRootPane(), this); 49 43 } 50 44 setEnabled(true); … … 53 47 @Override 54 48 public void actionPerformed(ActionEvent e) { 55 memberTable.stopHighlighting();56 Relation snapshot = editor.getRelationSnapshot();57 if ((! memberTableModel.hasSameMembersAs(snapshot) || tagModel.isDirty())58 && !(snapshot == null && tagModel.getTags().isEmpty())) {49 getMemberTable().stopHighlighting(); 50 Relation snapshot = getEditor().getRelationSnapshot(); 51 if ((!getMemberTableModel().hasSameMembersAs(snapshot) || getTagModel().isDirty()) 52 && !(snapshot == null && getTagModel().getTags().isEmpty())) { 59 53 //give the user a chance to save the changes 60 54 int ret = confirmClosingByCancel(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/CopyMembersAction.java
r10604 r14027 8 8 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 9 9 import org.openstreetmap.josm.gui.datatransfer.RelationMemberTransferable; 10 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;12 import org.openstreetmap.josm.gui.layer.OsmDataLayer;13 10 14 11 /** … … 17 14 */ 18 15 public class CopyMembersAction extends AddFromSelectionAction { 16 private static final long serialVersionUID = 1L; 19 17 20 18 /** … … 24 22 * @param editor relation editor 25 23 */ 26 public CopyMembersAction( MemberTableModel memberTableModel, OsmDataLayer layer, IRelationEditor editor) {27 super( null, memberTableModel, null, null, null, layer, editor);24 public CopyMembersAction(IRelationEditorActionAccess editorAccess) { 25 super(editorAccess); 28 26 } 29 27 30 28 @Override 31 29 public void actionPerformed(ActionEvent e) { 32 final Collection<RelationMember> members = memberTableModel.getSelectedMembers();30 final Collection<RelationMember> members = getMemberTableModel().getSelectedMembers(); 33 31 34 32 if (!members.isEmpty()) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DeleteCurrentRelationAction.java
r13130 r14027 11 11 import org.openstreetmap.josm.data.osm.Relation; 12 12 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor; 13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;14 import org.openstreetmap.josm.gui.layer.OsmDataLayer;15 13 import org.openstreetmap.josm.tools.ImageProvider; 16 14 … … 20 18 */ 21 19 public class DeleteCurrentRelationAction extends AbstractRelationEditorAction implements PropertyChangeListener { 20 private static final long serialVersionUID = 1L; 22 21 23 22 /** … … 26 25 * @param editor relation editor 27 26 */ 28 public DeleteCurrentRelationAction( OsmDataLayer layer, IRelationEditor editor) {29 super( null, null, null, layer, editor);27 public DeleteCurrentRelationAction(IRelationEditorActionAccess editorAccess) { 28 super(editorAccess); 30 29 putValue(SHORT_DESCRIPTION, tr("Delete the currently edited relation")); 31 30 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true); … … 36 35 @Override 37 36 public void actionPerformed(ActionEvent e) { 38 Relation toDelete = editor.getRelation();37 Relation toDelete = getEditor().getRelation(); 39 38 if (toDelete == null) 40 39 return; 41 DeleteAction.deleteRelation( layer, toDelete);40 DeleteAction.deleteRelation(getLayer(), toDelete); 42 41 } 43 42 44 43 @Override 45 44 protected void updateEnabledState() { 46 setEnabled( editor.getRelationSnapshot() != null);45 setEnabled(getEditor().getRelationSnapshot() != null); 47 46 } 48 47 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadIncompleteMembersAction.java
r13761 r14027 11 11 import org.openstreetmap.josm.gui.MainApplication; 12 12 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask; 13 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;17 13 import org.openstreetmap.josm.tools.ImageProvider; 18 14 import org.openstreetmap.josm.tools.Shortcut; … … 23 19 */ 24 20 public class DownloadIncompleteMembersAction extends AbstractRelationEditorAction { 21 private static final long serialVersionUID = 1L; 25 22 26 23 /** … … 32 29 * @param editor relation editor 33 30 */ 34 public DownloadIncompleteMembersAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey, 35 OsmDataLayer layer, IRelationEditor editor) { 36 super(memberTable, memberTableModel, actionMapKey, layer, editor); 31 public DownloadIncompleteMembersAction(IRelationEditorActionAccess editorAccess, String actionMapKey) { 32 super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE); 37 33 Shortcut sc = Shortcut.registerShortcut("relationeditor:downloadincomplete", tr("Relation Editor: Download Members"), 38 34 KeyEvent.VK_HOME, Shortcut.ALT); … … 49 45 return; 50 46 MainApplication.worker.submit(new DownloadRelationMemberTask( 51 editor.getRelation(),52 memberTableModel.getIncompleteMemberPrimitives(),53 layer,54 (Dialog) editor)47 getEditor().getRelation(), 48 getMemberTableModel().getIncompleteMemberPrimitives(), 49 getLayer(), 50 (Dialog) getEditor()) 55 51 ); 56 52 } … … 58 54 @Override 59 55 protected void updateEnabledState() { 60 setEnabled( memberTableModel.hasIncompleteMembers() && canDownload());56 setEnabled(getMemberTableModel().hasIncompleteMembers() && canDownload()); 61 57 } 62 58 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DownloadSelectedIncompleteMembersAction.java
r13761 r14027 9 9 import org.openstreetmap.josm.gui.MainApplication; 10 10 import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask; 11 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;12 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;14 import org.openstreetmap.josm.gui.layer.OsmDataLayer;15 11 import org.openstreetmap.josm.tools.ImageProvider; 16 12 … … 20 16 */ 21 17 public class DownloadSelectedIncompleteMembersAction extends AbstractRelationEditorAction { 18 private static final long serialVersionUID = 1L; 22 19 23 20 /** … … 29 26 * @param editor relation editor 30 27 */ 31 public DownloadSelectedIncompleteMembersAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey, 32 OsmDataLayer layer, IRelationEditor editor) { 33 super(memberTable, memberTableModel, actionMapKey, layer, editor); 28 public DownloadSelectedIncompleteMembersAction(IRelationEditorActionAccess editorAccess) { 29 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 34 30 putValue(SHORT_DESCRIPTION, tr("Download selected incomplete members")); 35 31 new ImageProvider("dialogs/relation", "downloadincompleteselected").getResource().attachImageIcon(this, true); … … 43 39 return; 44 40 MainApplication.worker.submit(new DownloadRelationMemberTask( 45 editor.getRelation(),46 memberTableModel.getSelectedIncompleteMemberPrimitives(),47 layer,48 (Dialog) editor)41 getEditor().getRelation(), 42 getMemberTableModel().getSelectedIncompleteMemberPrimitives(), 43 getLayer(), 44 (Dialog) getEditor()) 49 45 ); 50 46 } … … 52 48 @Override 53 49 protected void updateEnabledState() { 54 setEnabled( memberTableModel.hasIncompleteSelectedMembers() && canDownload());50 setEnabled(getMemberTableModel().hasIncompleteSelectedMembers() && canDownload()); 55 51 } 56 52 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/DuplicateRelationAction.java
r13130 r14027 8 8 9 9 import org.openstreetmap.josm.data.osm.Relation; 10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 10 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer;13 import org.openstreetmap.josm.gui.tagging.TagEditorModel;14 11 import org.openstreetmap.josm.tools.ImageProvider; 15 12 … … 19 16 */ 20 17 public class DuplicateRelationAction extends AbstractRelationEditorAction { 21 22 private final transient TagEditorModel tagEditorModel; 18 private static final long serialVersionUID = 1L; 23 19 24 20 /** … … 28 24 * @param layer OSM data layer 29 25 */ 30 public DuplicateRelationAction(MemberTableModel memberTableModel, TagEditorModel tagEditorModel, OsmDataLayer layer) { 31 super(null, memberTableModel, null, layer, null); 32 this.tagEditorModel = tagEditorModel; 26 public DuplicateRelationAction(IRelationEditorActionAccess editorAccess) { 27 super(editorAccess); 33 28 putValue(SHORT_DESCRIPTION, tr("Create a copy of this relation and open it in another editor window")); 34 29 // FIXME provide an icon … … 41 36 public void actionPerformed(ActionEvent e) { 42 37 Relation copy = new Relation(); 43 tagEditorModel.applyToPrimitive(copy);44 memberTableModel.applyToRelation(copy);38 getTagModel().applyToPrimitive(copy); 39 editorAccess.getMemberTableModel().applyToRelation(copy); 45 40 if (!GraphicsEnvironment.isHeadless()) { 46 RelationEditor.getEditor( layer, copy, memberTableModel.getSelectedMembers()).setVisible(true);41 RelationEditor.getEditor(getLayer(), copy, editorAccess.getMemberTableModel().getSelectedMembers()).setVisible(true); 47 42 } 48 43 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/EditAction.java
r13130 r14027 11 11 import org.openstreetmap.josm.data.osm.Relation; 12 12 import org.openstreetmap.josm.data.osm.RelationMember; 13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;14 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;15 13 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer;17 14 import org.openstreetmap.josm.tools.ImageProvider; 18 15 … … 22 19 */ 23 20 public class EditAction extends AbstractRelationEditorAction { 21 private static final long serialVersionUID = 1L; 24 22 25 23 /** … … 29 27 * @param layer layer 30 28 */ 31 public EditAction( MemberTable memberTable, MemberTableModel memberTableModel, OsmDataLayer layer) {32 super( memberTable, memberTableModel, null, layer, null);29 public EditAction(IRelationEditorActionAccess editorAccess) { 30 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 33 31 putValue(SHORT_DESCRIPTION, tr("Edit the relation the currently selected relation member refers to")); 34 32 new ImageProvider("dialogs", "edit").getResource().attachImageIcon(this, true); … … 38 36 @Override 39 37 protected void updateEnabledState() { 40 setEnabled(memberTable.getSelectedRowCount() == 1 41 && memberTableModel.isEditableRelation(memberTable.getSelectedRow())); 38 setEnabled(editorAccess.getMemberTable().getSelectedRowCount() == 1 39 && editorAccess.getMemberTableModel() 40 .isEditableRelation(editorAccess.getMemberTable().getSelectedRow())); 42 41 } 43 42 44 43 protected Collection<RelationMember> getMembersForCurrentSelection(Relation r) { 45 44 Collection<RelationMember> members = new HashSet<>(); 46 Collection<OsmPrimitive> selection = layer.data.getSelected();45 Collection<OsmPrimitive> selection = getLayer().data.getSelected(); 47 46 for (RelationMember member: r.getMembers()) { 48 47 if (selection.contains(member.getMember())) { … … 57 56 if (!isEnabled()) 58 57 return; 59 int idx = memberTable.getSelectedRow();58 int idx = editorAccess.getMemberTable().getSelectedRow(); 60 59 if (idx < 0) 61 60 return; 62 OsmPrimitive primitive = memberTableModel.getReferredPrimitive(idx);61 OsmPrimitive primitive = editorAccess.getMemberTableModel().getReferredPrimitive(idx); 63 62 if (!(primitive instanceof Relation)) 64 63 return; … … 67 66 return; 68 67 69 RelationEditor.getEditor( layer, r, getMembersForCurrentSelection(r)).setVisible(true);68 RelationEditor.getEditor(getLayer(), r, getMembersForCurrentSelection(r)).setVisible(true); 70 69 } 71 70 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveDownAction.java
r13130 r14027 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;12 10 import org.openstreetmap.josm.tools.ImageProvider; 13 11 import org.openstreetmap.josm.tools.Shortcut; … … 18 16 */ 19 17 public class MoveDownAction extends AbstractRelationEditorAction { 18 private static final long serialVersionUID = 1L; 20 19 21 20 /** … … 25 24 * @param actionMapKey action map key 26 25 */ 27 public MoveDownAction( MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {28 super( memberTable, memberTableModel, actionMapKey);26 public MoveDownAction(IRelationEditorActionAccess editorAccess, String actionMapKey) { 27 super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 29 28 new ImageProvider("dialogs", "movedown").getResource().attachImageIcon(this, true); 30 29 Shortcut sc = Shortcut.registerShortcut("relationeditor:movedown", tr("Relation Editor: Move Down"), KeyEvent.VK_DOWN, Shortcut.ALT); … … 36 35 @Override 37 36 public void actionPerformed(ActionEvent e) { 38 memberTableModel.moveDown(memberTable.getSelectedRows());37 editorAccess.getMemberTableModel().moveDown(editorAccess.getMemberTable().getSelectedRows()); 39 38 } 40 39 41 40 @Override 42 41 protected void updateEnabledState() { 43 setEnabled( memberTableModel.canMoveDown(memberTable.getSelectedRows()));42 setEnabled(editorAccess.getMemberTableModel().canMoveDown(editorAccess.getMemberTable().getSelectedRows())); 44 43 } 45 44 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/MoveUpAction.java
r13130 r14027 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;12 10 import org.openstreetmap.josm.tools.ImageProvider; 13 11 import org.openstreetmap.josm.tools.Shortcut; … … 18 16 */ 19 17 public class MoveUpAction extends AbstractRelationEditorAction { 18 private static final long serialVersionUID = 1L; 20 19 21 20 /** … … 25 24 * @param actionMapKey key in table action map 26 25 */ 27 public MoveUpAction( MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {28 super( memberTable, memberTableModel, actionMapKey);26 public MoveUpAction(IRelationEditorActionAccess editorAccess, String actionMapKey) { 27 super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 29 28 new ImageProvider("dialogs", "moveup").getResource().attachImageIcon(this, true); 30 29 Shortcut sc = Shortcut.registerShortcut("relationeditor:moveup", tr("Relation Editor: Move Up"), KeyEvent.VK_UP, Shortcut.ALT); … … 36 35 @Override 37 36 public void actionPerformed(ActionEvent e) { 38 memberTableModel.moveUp(memberTable.getSelectedRows());37 editorAccess.getMemberTableModel().moveUp(editorAccess.getMemberTable().getSelectedRows()); 39 38 } 40 39 41 40 @Override 42 41 protected void updateEnabledState() { 43 setEnabled( memberTableModel.canMoveUp(memberTable.getSelectedRows()));42 setEnabled(editorAccess.getMemberTableModel().canMoveUp(editorAccess.getMemberTable().getSelectedRows())); 44 43 } 45 44 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/OKAction.java
r12846 r14027 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;12 import org.openstreetmap.josm.gui.tagging.TagEditorModel;13 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;14 8 import org.openstreetmap.josm.spi.preferences.Config; 15 9 import org.openstreetmap.josm.tools.ImageProvider; … … 19 13 */ 20 14 public class OKAction extends SavingAction { 15 private static final long serialVersionUID = 1L; 21 16 22 17 /** … … 29 24 * @param tfRole role text field 30 25 */ 31 public OKAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer, 32 IRelationEditor editor, AutoCompletingTextField tfRole) { 33 super(memberTable, memberTableModel, tagModel, layer, editor, tfRole); 26 public OKAction(IRelationEditorActionAccess editorAccess) { 27 super(editorAccess); 34 28 putValue(SHORT_DESCRIPTION, tr("Apply the updates and close the dialog")); 35 29 new ImageProvider("ok").getResource().attachImageIcon(this); … … 41 35 public void actionPerformed(ActionEvent e) { 42 36 Config.getPref().put("relation.editor.generic.lastrole", tfRole.getText()); 43 memberTable.stopHighlighting();37 editorAccess.getMemberTable().stopHighlighting(); 44 38 if (!applyChanges()) 45 39 return; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/PasteMembersAction.java
r12620 r14027 10 10 11 11 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 12 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;13 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;14 12 import org.openstreetmap.josm.gui.dialogs.relation.MemberTransferHandler; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer;16 13 import org.openstreetmap.josm.tools.Logging; 17 14 … … 21 18 */ 22 19 public class PasteMembersAction extends AddFromSelectionAction implements FlavorListener { 20 private static final long serialVersionUID = 1L; 23 21 24 22 /** … … 28 26 * @param editor relation editor 29 27 */ 30 public PasteMembersAction( MemberTable memberTable, OsmDataLayer layer, IRelationEditor editor) {31 super( memberTable, null, null, null, null, layer, editor);28 public PasteMembersAction(IRelationEditorActionAccess editorAccess) { 29 super(editorAccess); 32 30 updateEnabledState(); 33 31 } … … 43 41 44 42 private TransferSupport getSupport() { 45 return new TransferSupport( memberTable, Optional.ofNullable(ClipboardUtils.getClipboardContent())43 return new TransferSupport(editorAccess.getMemberTable(), Optional.ofNullable(ClipboardUtils.getClipboardContent()) 46 44 .orElseThrow(() -> new IllegalStateException("Failed to retrieve clipboard content"))); 47 45 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java
r13856 r14027 16 16 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 17 17 import org.openstreetmap.josm.gui.MainApplication; 18 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;19 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;20 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;21 import org.openstreetmap.josm.gui.layer.OsmDataLayer;22 import org.openstreetmap.josm.gui.tagging.TagEditorModel;23 18 import org.openstreetmap.josm.tools.ImageProvider; 24 19 import org.openstreetmap.josm.tools.Shortcut; … … 29 24 */ 30 25 public class RefreshAction extends SavingAction implements CommandQueueListener { 26 private static final long serialVersionUID = 1L; 31 27 32 28 /** … … 38 34 * @param tagModel tag editor model 39 35 */ 40 public RefreshAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer, 41 IRelationEditor editor) { 42 super(memberTable, memberTableModel, tagModel, layer, editor, null); 36 public RefreshAction(IRelationEditorActionAccess editorAccess) { 37 super(editorAccess); 43 38 // CHECKSTYLE.OFF: LineLength 44 39 Shortcut sc = Shortcut.registerShortcut("relationeditor:refresh", tr("Relation Editor: Refresh"), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE); … … 47 42 new ImageProvider("dialogs/refresh").getResource().attachImageIcon(this, true); 48 43 putValue(NAME, tr("Refresh")); 49 if (editor instanceof JComponent) {50 ((JComponent) editor ).getRootPane().getActionMap().put("refresh", this);51 ((JComponent) editor ).getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh");44 if (editorAccess.getEditor() instanceof JComponent) { 45 ((JComponent) editorAccess.getEditor()).getRootPane().getActionMap().put("refresh", this); 46 ((JComponent) editorAccess.getEditor()).getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh"); 52 47 } 53 48 MainApplication.undoRedo.addCommandQueueListener(this); … … 57 52 @Override 58 53 public void actionPerformed(ActionEvent e) { 59 Relation relation = editor .getRelation();54 Relation relation = editorAccess.getEditor().getRelation(); 60 55 if (relation == null) 61 56 return; … … 68 63 if (isEditorDirty() && confirmDiscardDirtyData() != 0) 69 64 return; 70 editor .reloadDataFromRelation();65 editorAccess.getEditor().reloadDataFromRelation(); 71 66 } 72 67 73 68 @Override 74 69 public void updateEnabledState() { 75 Relation relation = editor .getRelation();76 Relation snapshot = editor .getRelationSnapshot();70 Relation relation = editorAccess.getEditor().getRelation(); 71 Relation snapshot = editorAccess.getEditor().getRelationSnapshot(); 77 72 setEnabled(snapshot != null && ( 78 73 !relation.hasEqualTechnicalAttributes(snapshot) || -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveAction.java
r13130 r14027 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;12 10 import org.openstreetmap.josm.tools.ImageProvider; 13 11 import org.openstreetmap.josm.tools.Shortcut; … … 18 16 */ 19 17 public class RemoveAction extends AbstractRelationEditorAction { 18 private static final long serialVersionUID = 1L; 20 19 21 20 /** … … 25 24 * @param actionMapKey action map key 26 25 */ 27 public RemoveAction( MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {28 super( memberTable, memberTableModel, actionMapKey);26 public RemoveAction(IRelationEditorActionAccess editorAccess, String actionMapKey) { 27 super(editorAccess, actionMapKey, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 29 28 new ImageProvider("dialogs", "delete").getResource().attachImageIcon(this, true); 30 29 putValue(NAME, tr("Remove")); … … 37 36 @Override 38 37 public void actionPerformed(ActionEvent e) { 39 memberTableModel.remove(memberTable.getSelectedRows());38 editorAccess.getMemberTableModel().remove(editorAccess.getMemberTable().getSelectedRows()); 40 39 } 41 40 42 41 @Override 43 42 protected void updateEnabledState() { 44 setEnabled( memberTableModel.canRemove(memberTable.getSelectedRows()));43 setEnabled(editorAccess.getMemberTableModel().canRemove(editorAccess.getMemberTable().getSelectedRows())); 45 44 } 46 45 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RemoveSelectedAction.java
r13130 r14027 7 7 8 8 import org.openstreetmap.josm.data.osm.DataSet; 9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;10 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;11 import org.openstreetmap.josm.gui.layer.OsmDataLayer;12 9 import org.openstreetmap.josm.tools.ImageProvider; 13 10 … … 17 14 */ 18 15 public class RemoveSelectedAction extends AddFromSelectionAction { 16 private static final long serialVersionUID = 1L; 19 17 20 18 /** … … 24 22 * @param layer OSM data layer 25 23 */ 26 public RemoveSelectedAction( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, OsmDataLayer layer) {27 super( null, memberTableModel, null, selectionTableModel, null, layer, null);24 public RemoveSelectedAction(IRelationEditorActionAccess editorAccess) { 25 super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); 28 26 putValue(SHORT_DESCRIPTION, tr("Remove all members referring to one of the selected objects")); 29 27 new ImageProvider("dialogs/relation", "deletemembers").getResource().attachImageIcon(this, true); … … 33 31 @Override 34 32 protected void updateEnabledState() { 35 DataSet ds = layer.data;33 DataSet ds = getLayer().data; 36 34 if (ds == null || ds.selectionEmpty()) { 37 35 setEnabled(false); … … 39 37 } 40 38 // only enable the action if we have members referring to the selected primitives 41 setEnabled( memberTableModel.hasMembersReferringTo(ds.getSelected()));39 setEnabled(editorAccess.getMemberTableModel().hasMembersReferringTo(ds.getSelected())); 42 40 } 43 41 44 42 @Override 45 43 public void actionPerformed(ActionEvent e) { 46 memberTableModel.removeMembersReferringTo(selectionTableModel.getSelection());44 editorAccess.getMemberTableModel().removeMembersReferringTo(getSelectionTableModel().getSelection()); 47 45 } 48 46 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/ReverseAction.java
r13130 r14027 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;10 8 import org.openstreetmap.josm.tools.ImageProvider; 11 9 … … 15 13 */ 16 14 public class ReverseAction extends AbstractRelationEditorAction { 15 private static final long serialVersionUID = 1L; 17 16 18 17 /** 19 18 * Constructs a new {@code ReverseAction}. 20 * @param memberTable member table 21 * @param memberTableModel member table model 19 * @param editorAccess 22 20 */ 23 public ReverseAction(MemberTable memberTable, MemberTableModel memberTableModel) { 24 super(memberTable, memberTableModel, null); 21 public ReverseAction(IRelationEditorActionAccess editorAccess) { 22 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE); 23 25 24 putValue(SHORT_DESCRIPTION, tr("Reverse the order of the relation members")); 26 25 new ImageProvider("dialogs/relation", "reverse").getResource().attachImageIcon(this, true); … … 31 30 @Override 32 31 public void actionPerformed(ActionEvent e) { 33 memberTableModel.reverse();32 editorAccess.getMemberTableModel().reverse(); 34 33 } 35 34 36 35 @Override 37 36 protected void updateEnabledState() { 38 setEnabled( memberTableModel.getRowCount() > 0);37 setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0); 39 38 } 40 39 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SavingAction.java
r13842 r14027 22 22 import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec; 23 23 import org.openstreetmap.josm.gui.MainApplication; 24 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;25 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;26 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;27 24 import org.openstreetmap.josm.gui.dialogs.relation.RelationDialogManager; 28 25 import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor; 29 import org.openstreetmap.josm.gui.layer.OsmDataLayer;30 26 import org.openstreetmap.josm.gui.tagging.TagEditorModel; 31 27 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; … … 38 34 */ 39 35 abstract class SavingAction extends AbstractRelationEditorAction { 36 private static final long serialVersionUID = 1L; 40 37 41 protected final TagEditorModel tagModel;42 38 protected final AutoCompletingTextField tfRole; 43 39 44 protected SavingAction(MemberTable memberTable, MemberTableModel memberTableModel, TagEditorModel tagModel, OsmDataLayer layer, 45 IRelationEditor editor, AutoCompletingTextField tfRole) { 46 super(memberTable, memberTableModel, null, layer, editor); 47 this.tagModel = tagModel; 48 this.tfRole = tfRole; 40 protected SavingAction(IRelationEditorActionAccess editorAccess, IRelationEditorUpdateOn... updateOn) { 41 super(editorAccess, updateOn); 42 this.tfRole = editorAccess.getTextFieldRole(); 49 43 } 50 44 … … 56 50 final Relation newRelation = new Relation(); 57 51 tagEditorModel.applyToPrimitive(newRelation); 58 memberTableModel.applyToRelation(newRelation);52 getMemberTableModel().applyToRelation(newRelation); 59 53 List<RelationMember> newMembers = new ArrayList<>(); 60 54 for (RelationMember rm: newRelation.getMembers()) { … … 73 67 if (newRelation.getMembersCount() == 0 && !newRelation.hasKeys()) 74 68 return; 75 MainApplication.undoRedo.add(new AddCommand( layer.getDataSet(), newRelation));69 MainApplication.undoRedo.add(new AddCommand(getLayer().getDataSet(), newRelation)); 76 70 77 71 // make sure everybody is notified about the changes 78 72 // 79 editor.setRelation(newRelation);80 if ( editorinstanceof RelationEditor) {73 getEditor().setRelation(newRelation); 74 if (getEditor() instanceof RelationEditor) { 81 75 RelationDialogManager.getRelationDialogManager().updateContext( 82 layer, editor.getRelation(), (RelationEditor) editor);76 getLayer(), getEditor().getRelation(), (RelationEditor) getEditor()); 83 77 } 84 78 // Relation list gets update in EDT so selecting my be postponed to following EDT run … … 91 85 */ 92 86 protected void applyExistingConflictingRelation(TagEditorModel tagEditorModel) { 93 Relation editedRelation = new Relation(editor .getRelation());87 Relation editedRelation = new Relation(editorAccess.getEditor().getRelation()); 94 88 tagEditorModel.applyToPrimitive(editedRelation); 95 memberTableModel.applyToRelation(editedRelation);96 Conflict<Relation> conflict = new Conflict<>(editor .getRelation(), editedRelation);97 MainApplication.undoRedo.add(new ConflictAddCommand( layer.getDataSet(), conflict));89 editorAccess.getMemberTableModel().applyToRelation(editedRelation); 90 Conflict<Relation> conflict = new Conflict<>(editorAccess.getEditor().getRelation(), editedRelation); 91 MainApplication.undoRedo.add(new ConflictAddCommand(getLayer().getDataSet(), conflict)); 98 92 } 99 93 … … 103 97 */ 104 98 protected void applyExistingNonConflictingRelation(TagEditorModel tagEditorModel) { 105 Relation originRelation = editor .getRelation();99 Relation originRelation = editorAccess.getEditor().getRelation(); 106 100 Relation editedRelation = new Relation(originRelation); 107 101 tagEditorModel.applyToPrimitive(editedRelation); 108 memberTableModel.applyToRelation(editedRelation);102 getMemberTableModel().applyToRelation(editedRelation); 109 103 if (!editedRelation.hasEqualSemanticAttributes(originRelation, false)) { 110 104 MainApplication.undoRedo.add(new ChangeCommand(originRelation, editedRelation)); … … 153 147 + "''{1}''.<br>" 154 148 + "Please resolve this conflict first, then try again.</html>", 155 Utils.escapeReservedCharactersHTML( layer.getName()),156 Utils.escapeReservedCharactersHTML( editor.getRelation().getDisplayName(DefaultNameFormatter.getInstance()))149 Utils.escapeReservedCharactersHTML(getLayer().getName()), 150 Utils.escapeReservedCharactersHTML(getEditor().getRelation().getDisplayName(DefaultNameFormatter.getInstance())) 157 151 ), 158 152 tr("Double conflict"), … … 167 161 168 162 protected boolean applyChanges() { 169 if (editor .getRelation() == null) {170 applyNewRelation( tagModel);163 if (editorAccess.getEditor().getRelation() == null) { 164 applyNewRelation(getTagModel()); 171 165 } else if (isEditorDirty()) { 172 if (editor .isDirtyRelation()) {166 if (editorAccess.getEditor().isDirtyRelation()) { 173 167 if (confirmClosingBecauseOfDirtyState()) { 174 if ( layer.getConflicts().hasConflictForMy(editor.getRelation())) {168 if (getLayer().getConflicts().hasConflictForMy(editorAccess.getEditor().getRelation())) { 175 169 warnDoubleConflict(); 176 170 return false; 177 171 } 178 applyExistingConflictingRelation( tagModel);172 applyExistingConflictingRelation(getTagModel()); 179 173 hideEditor(); 180 174 } else 181 175 return false; 182 176 } else { 183 applyExistingNonConflictingRelation( tagModel);177 applyExistingNonConflictingRelation(getTagModel()); 184 178 } 185 179 } 186 editor .setRelation(editor.getRelation());180 editorAccess.getEditor().setRelation(editorAccess.getEditor().getRelation()); 187 181 return true; 188 182 } 189 183 190 184 protected void hideEditor() { 191 if (editor instanceof Component) {192 ((Component) editor ).setVisible(false);185 if (editorAccess.getEditor() instanceof Component) { 186 ((Component) editorAccess.getEditor()).setVisible(false); 193 187 } 194 188 } 195 189 196 190 protected boolean isEditorDirty() { 197 Relation snapshot = editor .getRelationSnapshot();198 return (snapshot != null && ! memberTableModel.hasSameMembersAs(snapshot)) || tagModel.isDirty();191 Relation snapshot = editorAccess.getEditor().getRelationSnapshot(); 192 return (snapshot != null && !getMemberTableModel().hasSameMembersAs(snapshot)) || getTagModel().isDirty(); 199 193 } 200 194 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectAction.java
r12933 r14027 7 7 8 8 import org.openstreetmap.josm.data.osm.Relation; 9 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;11 9 import org.openstreetmap.josm.tools.ImageProvider; 12 10 … … 16 14 */ 17 15 public class SelectAction extends AbstractRelationEditorAction { 16 private static final long serialVersionUID = 1L; 18 17 19 18 /** … … 22 21 * @param editor relation editor 23 22 */ 24 public SelectAction( OsmDataLayer layer, IRelationEditor editor) {25 super( null, null, null, layer, editor);23 public SelectAction(IRelationEditorActionAccess editorAccess) { 24 super(editorAccess); 26 25 putValue(NAME, tr("Select")); 27 26 putValue(SHORT_DESCRIPTION, tr("Select the currently edited relation")); … … 32 31 @Override 33 32 public void actionPerformed(ActionEvent e) { 34 Relation toSelect = editor .getRelation();33 Relation toSelect = editorAccess.getEditor().getRelation(); 35 34 if (toSelect == null) 36 35 return; 37 layer.data.setSelected(toSelect);36 getLayer().data.setSelected(toSelect); 38 37 } 39 38 40 39 @Override 41 40 protected void updateEnabledState() { 42 setEnabled(editor .getRelationSnapshot() != null);41 setEnabled(editorAccess.getEditor().getRelationSnapshot() != null); 43 42 } 44 43 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectPrimitivesForSelectedMembersAction.java
r13130 r14027 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;11 8 import org.openstreetmap.josm.tools.ImageProvider; 12 9 … … 17 14 */ 18 15 public class SelectPrimitivesForSelectedMembersAction extends AbstractRelationEditorAction { 16 private static final long serialVersionUID = 1L; 19 17 20 18 /** … … 24 22 * @param layer layer 25 23 */ 26 public SelectPrimitivesForSelectedMembersAction( MemberTable memberTable, MemberTableModel memberTableModel, OsmDataLayer layer) {27 super( memberTable, memberTableModel, null, layer, null);24 public SelectPrimitivesForSelectedMembersAction(IRelationEditorActionAccess editorAccess) { 25 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 28 26 putValue(SHORT_DESCRIPTION, tr("Select objects for selected relation members")); 29 27 new ImageProvider("dialogs/relation", "selectprimitives").getResource().attachImageIcon(this, true); … … 33 31 @Override 34 32 protected void updateEnabledState() { 35 setEnabled( memberTable.getSelectedRowCount() > 0);33 setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0); 36 34 } 37 35 38 36 @Override 39 37 public void actionPerformed(ActionEvent e) { 40 layer.data.setSelected(memberTableModel.getSelectedChildPrimitives());38 getLayer().data.setSelected(editorAccess.getMemberTableModel().getSelectedChildPrimitives()); 41 39 } 42 40 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SelectedMembersForSelectionAction.java
r13130 r14027 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;9 import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;10 import org.openstreetmap.josm.gui.layer.OsmDataLayer;11 8 import org.openstreetmap.josm.tools.ImageProvider; 12 9 … … 16 13 */ 17 14 public class SelectedMembersForSelectionAction extends AddFromSelectionAction { 15 private static final long serialVersionUID = 1L; 18 16 19 17 /** … … 23 21 * @param layer OSM data layer 24 22 */ 25 public SelectedMembersForSelectionAction( MemberTableModel memberTableModel, SelectionTableModel selectionTableModel, OsmDataLayer layer) {26 super( null, memberTableModel, null, selectionTableModel, null, layer, null);23 public SelectedMembersForSelectionAction(IRelationEditorActionAccess editorAccess) { 24 super(editorAccess, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE); 27 25 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection")); 28 26 new ImageProvider("dialogs/relation", "selectmembers").getResource().attachImageIcon(this, true); … … 32 30 @Override 33 31 protected void updateEnabledState() { 34 boolean enabled = selectionTableModel.getRowCount() > 035 && ! memberTableModel.getChildPrimitives(layer.data.getSelected()).isEmpty();32 boolean enabled = getSelectionTableModel().getRowCount() > 0 33 && !editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).isEmpty(); 36 34 37 35 if (enabled) { 38 36 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to {0} objects in the current selection", 39 memberTableModel.getChildPrimitives(layer.data.getSelected()).size()));37 editorAccess.getMemberTableModel().getChildPrimitives(getLayer().data.getSelected()).size())); 40 38 } else { 41 39 putValue(SHORT_DESCRIPTION, tr("Select relation members which refer to objects in the current selection")); … … 46 44 @Override 47 45 public void actionPerformed(ActionEvent e) { 48 memberTableModel.selectMembersReferringTo(layer.data.getSelected());46 editorAccess.getMemberTableModel().selectMembersReferringTo(getLayer().data.getSelected()); 49 47 } 50 48 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SetRoleAction.java
r10424 r14027 13 13 import org.openstreetmap.josm.Main; 14 14 import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil; 15 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;16 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;17 15 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 18 16 import org.openstreetmap.josm.tools.ImageProvider; … … 23 21 */ 24 22 public class SetRoleAction extends AbstractRelationEditorAction implements DocumentListener { 23 private static final long serialVersionUID = 1L; 25 24 26 25 private final transient AutoCompletingTextField tfRole; … … 32 31 * @param tfRole role text field 33 32 */ 34 public SetRoleAction( MemberTable memberTable, MemberTableModel memberTableModel, AutoCompletingTextField tfRole) {35 super( memberTable, memberTableModel, null);36 this.tfRole = tfRole;33 public SetRoleAction(IRelationEditorActionAccess editorAccess) { 34 super(editorAccess); 35 this.tfRole = editorAccess.getTextFieldRole(); 37 36 putValue(SHORT_DESCRIPTION, tr("Sets a role for the selected members")); 38 37 new ImageProvider("apply").getResource().attachImageIcon(this); … … 43 42 @Override 44 43 protected void updateEnabledState() { 45 setEnabled( memberTable.getSelectedRowCount() > 0);44 setEnabled(editorAccess.getMemberTable().getSelectedRowCount() > 0); 46 45 } 47 46 … … 83 82 @Override 84 83 public void actionPerformed(ActionEvent e) { 85 if (isEmptyRole() && !confirmSettingEmptyRole( memberTable.getSelectedRowCount())) {84 if (isEmptyRole() && !confirmSettingEmptyRole(editorAccess.getMemberTable().getSelectedRowCount())) { 86 85 return; 87 86 } 88 memberTableModel.updateRole(memberTable.getSelectedRows(), tfRole.getText());87 editorAccess.getMemberTableModel().updateRole(editorAccess.getMemberTable().getSelectedRows(), tfRole.getText()); 89 88 } 90 89 -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortAction.java
r13130 r14027 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;11 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;12 10 import org.openstreetmap.josm.tools.ImageProvider; 13 11 import org.openstreetmap.josm.tools.Shortcut; … … 18 16 */ 19 17 public class SortAction extends AbstractRelationEditorAction { 18 private static final long serialVersionUID = 1L; 20 19 21 20 /** … … 24 23 * @param memberTableModel member table model 25 24 */ 26 public SortAction( MemberTable memberTable, MemberTableModel memberTableModel) {27 super( memberTable, memberTableModel, null);25 public SortAction(IRelationEditorActionAccess editorAccess) { 26 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE); 28 27 new ImageProvider("dialogs", "sort").getResource().attachImageIcon(this, true); 29 28 putValue(NAME, tr("Sort")); … … 36 35 @Override 37 36 public void actionPerformed(ActionEvent e) { 38 memberTableModel.sort();37 editorAccess.getMemberTableModel().sort(); 39 38 } 40 39 41 40 @Override 42 41 protected void updateEnabledState() { 43 setEnabled( memberTableModel.getRowCount() > 0);42 setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0); 44 43 } 45 44 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/SortBelowAction.java
r13130 r14027 6 6 import java.awt.event.ActionEvent; 7 7 8 import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;9 import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;10 8 import org.openstreetmap.josm.tools.ImageProvider; 11 9 … … 15 13 */ 16 14 public class SortBelowAction extends AbstractRelationEditorAction { 15 private static final long serialVersionUID = 1L; 17 16 18 17 /** … … 21 20 * @param memberTableModel member table model 22 21 */ 23 public SortBelowAction( MemberTable memberTable, MemberTableModel memberTableModel) {24 super( memberTable, memberTableModel, null);22 public SortBelowAction(IRelationEditorActionAccess editorAccess) { 23 super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_CHANGE, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION); 25 24 new ImageProvider("dialogs", "sort_below").getResource().attachImageIcon(this, true); 26 25 putValue(NAME, tr("Sort below")); … … 31 30 @Override 32 31 public void actionPerformed(ActionEvent e) { 33 memberTableModel.sortBelow();32 editorAccess.getMemberTableModel().sortBelow(); 34 33 } 35 34 36 35 @Override 37 36 protected void updateEnabledState() { 38 setEnabled(memberTableModel.getRowCount() > 0 && !memberTableModel.getSelectionModel().isSelectionEmpty()); 37 setEnabled(editorAccess.getMemberTableModel().getRowCount() > 0 && !editorAccess.getMemberTableModel().getSelectionModel().isSelectionEmpty()); 38 } 39 40 @Override 41 public boolean isExpertOnly() { 42 return true; 39 43 } 40 44 } -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/GenericRelationEditorTest.java
r13489 r14027 118 118 SelectionTable selectionTable = new SelectionTable(selectionTableModel, memberTableModel); 119 119 120 LeftButtonToolbar leftButtonToolbar = new LeftButtonToolbar(memberTable, memberTableModel, re);121 assertNotNull(leftButtonToolbar.sortBelowButton);122 123 120 AutoCompletingTextField tfRole = GenericRelationEditor.buildRoleTextField(re); 124 121 assertNotNull(tfRole); … … 127 124 128 125 JPanel top = GenericRelationEditor.buildTagEditorPanel(tagEditorPanel); 129 JPanel bottom = GenericRelationEditor.buildMemberEditorPanel(130 memberTable, memberTableModel, selectionTable, selectionTableModel, re, leftButtonToolbar, tfRole);131 126 assertNotNull(top); 132 assertNotNull(bottom);133 assertNotNull(GenericRelationEditor.buildSplitPane(top, bottom, re));134 135 127 TagEditorModel tagModel = tagEditorPanel.getModel(); 136 128 137 assertNotNull(GenericRelationEditor.buildOkCancelButtonPanel(138 new OKAction(memberTable, memberTableModel, tagModel, layer, re, tfRole),139 new CancelAction(memberTable, memberTableModel, tagModel, layer, re, tfRole)));140 assertNotNull(GenericRelationEditor.buildSelectionControlButtonToolbar(memberTable, memberTableModel, selectionTableModel, re));141 assertNotNull(GenericRelationEditor.buildSelectionTablePanel(selectionTable));142 143 assertNotNull(GenericRelationEditor.buildToolBar(144 new RefreshAction(memberTable, memberTableModel, tagModel, layer, re),145 new ApplyAction(memberTable, memberTableModel, tagModel, layer, re),146 new SelectAction(layer, re),147 new DuplicateRelationAction(memberTableModel, tagModel, layer),148 new DeleteCurrentRelationAction(layer, re)));149 129 } 150 130 }
Note:
See TracChangeset
for help on using the changeset viewer.