-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'replace selected' action to relation editor
- Loading branch information
Showing
5 changed files
with
246 additions
and
13 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
resources/images/dialogs/relation/replaceselectedright.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/org/openstreetmap/josm/gui/dialogs/relation/actions/ReplaceSelectedAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// License: GPL. For details, see LICENSE file. | ||
package org.openstreetmap.josm.gui.dialogs.relation.actions; | ||
|
||
import static org.openstreetmap.josm.tools.I18n.tr; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.util.List; | ||
|
||
import org.openstreetmap.josm.data.osm.OsmPrimitive; | ||
import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor.AddAbortException; | ||
import org.openstreetmap.josm.tools.ImageProvider; | ||
import org.openstreetmap.josm.tools.Logging; | ||
|
||
/** | ||
* Replace selected relation members with the objects selected in the current dataset | ||
* @since xxx | ||
*/ | ||
public class ReplaceSelectedAction extends AddFromSelectionAction { | ||
|
||
/** | ||
* Constructs a new {@code ReplaceSelectedAction}. | ||
* @param editorAccess An interface to access the relation editor contents. | ||
*/ | ||
public ReplaceSelectedAction(IRelationEditorActionAccess editorAccess) { | ||
super(editorAccess, IRelationEditorUpdateOn.MEMBER_TABLE_SELECTION, IRelationEditorUpdateOn.SELECTION_TABLE_CHANGE); | ||
putValue(SHORT_DESCRIPTION, tr("Replace members with selected objects")); | ||
new ImageProvider("dialogs/relation", "replaceselectedright").getResource().attachImageIcon(this, true); | ||
updateEnabledState(); | ||
} | ||
|
||
@Override | ||
protected void updateEnabledState() { | ||
int numSelected = getSelectionTableModel().getRowCount(); | ||
setEnabled(numSelected > 0 && | ||
numSelected == getMemberTableModel().getSelectedIndices().length); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
try { | ||
int[] selectedMemberIndices = getMemberTableModel().getSelectedIndices(); | ||
List<OsmPrimitive> selection = getSelectionTableModel().getSelection(); | ||
int numSelectedPrimitives = selection.size(); | ||
if (numSelectedPrimitives != selectedMemberIndices.length) { | ||
return; | ||
} | ||
|
||
List<OsmPrimitive> filteredSelection = filterConfirmedPrimitives(selection, true); | ||
|
||
for (int i = 0; i < selectedMemberIndices.length; i++) { | ||
getMemberTableModel().updateMemberPrimitive(selectedMemberIndices[i], filteredSelection.get(i)); | ||
} | ||
} catch (AddAbortException ex) { | ||
Logging.trace(ex); | ||
} | ||
} | ||
} |