Ignore:
Timestamp:
2016-11-12T14:52:32+01:00 (3 years ago)
Author:
Don-vip
Message:

see #10387 - refactor various actions and commands so they can be used without data layer

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JoinAreasAction.java

    r10755 r11240  
    4343import org.openstreetmap.josm.gui.Notification;
    4444import org.openstreetmap.josm.gui.conflict.tags.CombinePrimitiveResolverDialog;
     45import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4546import org.openstreetmap.josm.tools.Geometry;
    4647import org.openstreetmap.josm.tools.Pair;
     
    541542     * @throws UserCancelException if user cancels the operation
    542543     */
    543     private JoinAreasResult joinAreas(List<Multipolygon> areas) throws UserCancelException {
     544    public JoinAreasResult joinAreas(List<Multipolygon> areas) throws UserCancelException {
    544545
    545546        JoinAreasResult result = new JoinAreasResult();
     
    12961297     * @return list of polygons, or null if too complex relation encountered.
    12971298     */
    1298     private static List<Multipolygon> collectMultipolygons(Collection<Way> selectedWays) {
     1299    public static List<Multipolygon> collectMultipolygons(Collection<Way> selectedWays) {
    12991300
    13001301        List<Multipolygon> result = new ArrayList<>();
     
    14041405    private RelationRole addOwnMultipolygonRelation(Collection<Way> inner) {
    14051406        if (inner.isEmpty()) return null;
     1407        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    14061408        // Create new multipolygon relation and add all inner ways to it
    14071409        Relation newRel = new Relation();
     
    14101412            newRel.addMember(new RelationMember("inner", w));
    14111413        }
    1412         cmds.add(new AddCommand(newRel));
     1414        cmds.add(layer != null ? new AddCommand(layer, newRel) :
     1415            new AddCommand(inner.iterator().next().getDataSet(), newRel));
    14131416        addedRelations.add(newRel);
    14141417
     
    14261429        List<RelationRole> result = new ArrayList<>();
    14271430
    1428         for (Relation r : Main.getLayerManager().getEditDataSet().getRelations()) {
     1431        for (Relation r : osm.getDataSet().getRelations()) {
    14291432            if (r.isDeleted()) {
    14301433                continue;
     
    14801483        }
    14811484
     1485        OsmDataLayer layer = Main.getLayerManager().getEditLayer();
    14821486        Relation newRel;
    14831487        switch (multiouters.size()) {
     
    15081512            }
    15091513            newRel.addMember(new RelationMember("outer", outer));
    1510             cmds.add(new AddCommand(newRel));
     1514            cmds.add(layer != null ? new AddCommand(layer, newRel) : new AddCommand(outer.getDataSet(), newRel));
    15111515        }
    15121516    }
  • trunk/src/org/openstreetmap/josm/actions/PurgeAction.java

    r10619 r11240  
    9393            return;
    9494
    95         Collection<OsmPrimitive> sel = getLayerManager().getEditDataSet().getAllSelected();
     95        doPurge(getLayerManager().getEditDataSet().getAllSelected(), true);
     96    }
     97
     98    /**
     99     * Performs purge on selected OSM primitives.
     100     * @param sel selected OSM primitives
     101     * @param confirm asks user confirmation through a popup dialog
     102     * @since 11240
     103     */
     104    public void doPurge(Collection<OsmPrimitive> sel, boolean confirm) {
    96105        layer = Main.getLayerManager().getEditLayer();
    97106
     
    205214        boolean clearUndoRedo = false;
    206215
    207         if (!GraphicsEnvironment.isHeadless()) {
     216        if (!GraphicsEnvironment.isHeadless() && confirm) {
    208217            final boolean answer = ConditionalOptionPaneUtil.showConfirmationDialog(
    209218                    "purge", Main.parent, buildPanel(modified), tr("Confirm Purging"),
     
    216225        }
    217226
    218         Main.main.undoRedo.add(new PurgeCommand(Main.getLayerManager().getEditLayer(), toPurgeChecked, makeIncomplete));
     227        Main.main.undoRedo.add(layer != null ? new PurgeCommand(layer, toPurgeChecked, makeIncomplete) :
     228            new PurgeCommand(toPurgeChecked.iterator().next().getDataSet(), toPurgeChecked, makeIncomplete));
    219229
    220230        if (clearUndoRedo) {
  • trunk/src/org/openstreetmap/josm/actions/SelectByInternalPointAction.java

    r10448 r11240  
    3030
    3131    /**
    32      * Returns the surrounding polygons/multipolygons
    33      * ordered by their area size (from small to large)
     32     * Returns the surrounding polygons/multipolygons ordered by their area size (from small to large)
    3433     * which contain the internal point.
    3534     *
     
    3837     */
    3938    public static Collection<OsmPrimitive> getSurroundingObjects(EastNorth internalPoint) {
    40         final DataSet ds = Main.getLayerManager().getEditDataSet();
     39        return getSurroundingObjects(Main.getLayerManager().getEditDataSet(), internalPoint);
     40    }
     41
     42    /**
     43     * Returns the surrounding polygons/multipolygons ordered by their area size (from small to large)
     44     * which contain the internal point.
     45     *
     46     * @param ds the data set
     47     * @param internalPoint the internal point.
     48     * @return the surrounding polygons/multipolygons
     49     * @since 11240
     50     */
     51    public static Collection<OsmPrimitive> getSurroundingObjects(DataSet ds, EastNorth internalPoint) {
    4152        if (ds == null) {
    4253            return Collections.emptySet();
  • trunk/src/org/openstreetmap/josm/actions/SplitWayAction.java

    r10775 r11240  
    539539        final Way changedWay = new Way(way);
    540540        changedWay.setNodes(wayToKeep.getNodes());
    541         commandList.add(new ChangeCommand(way, changedWay));
     541        commandList.add(layer != null ? new ChangeCommand(layer, way, changedWay) : new ChangeCommand(way.getDataSet(), way, changedWay));
    542542        if (!newSelection.contains(way)) {
    543543            newSelection.add(way);
     
    548548        newSelection.addAll(newWays);
    549549        for (Way wayToAdd : newWays) {
    550             commandList.add(new AddCommand(layer, wayToAdd));
     550            commandList.add(layer != null ? new AddCommand(layer, wayToAdd) : new AddCommand(way.getDataSet(), wayToAdd));
    551551        }
    552552
     
    678678
    679679            if (c != null) {
    680                 commandList.add(new ChangeCommand(layer, r, c));
     680                commandList.add(layer != null ? new ChangeCommand(layer, r, c) : new ChangeCommand(r.getDataSet(), r, c));
    681681            }
    682682        }
Note: See TracChangeset for help on using the changeset viewer.