Changeset 5233 in josm for trunk


Ignore:
Timestamp:
2012-05-12T15:39:13+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #7684 - Various improvements in "upload=false" layers handling

Location:
trunk/src/org/openstreetmap/josm
Files:
8 edited

Legend:

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

    r4851 r5233  
    8383    protected void warnNoTargetLayersForSourceLayer(Layer sourceLayer) {
    8484        JOptionPane.showMessageDialog(Main.parent,
    85                 tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>"),
     85                tr("<html>There are no layers the source layer<br>''{0}''<br>could be merged to.</html>", sourceLayer.getName()),
    8686                tr("No target layers"), JOptionPane.WARNING_MESSAGE);
    8787    }
  • trunk/src/org/openstreetmap/josm/actions/MergeLayerAction.java

    r4982 r5233  
    77import java.awt.event.ActionEvent;
    88import java.awt.event.KeyEvent;
     9import java.util.Collection;
     10import java.util.Collections;
    911import java.util.List;
    1012
     
    1214import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    1315import org.openstreetmap.josm.gui.layer.Layer;
     16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     17import org.openstreetmap.josm.gui.util.GuiHelper;
     18import org.openstreetmap.josm.tools.ImageProvider;
    1419import org.openstreetmap.josm.tools.Shortcut;
    1520
     
    2530    }
    2631
    27     public void merge(List<Layer> sourceLayers) {
    28         Layer targetLayer = askTargetLayer(sourceLayers);
     32    protected void doMerge(List<Layer> targetLayers, final Collection<Layer> sourceLayers) {
     33        final Layer targetLayer = askTargetLayer(targetLayers);
    2934        if (targetLayer == null)
    3035            return;
    31         for (Layer l: sourceLayers) {
    32             if (l != targetLayer) {
    33                 targetLayer.mergeFrom(l);
    34                 Main.map.mapView.removeLayer(l);
     36        Main.worker.submit(new Runnable() {
     37            @Override
     38            public void run() {
     39                boolean layerMerged = false;
     40                for (Layer sourceLayer: sourceLayers) {
     41                    if (sourceLayer != null && sourceLayer != targetLayer) {
     42                        if (sourceLayer instanceof OsmDataLayer && targetLayer instanceof OsmDataLayer
     43                                && ((OsmDataLayer)sourceLayer).isUploadDiscouraged() != ((OsmDataLayer)targetLayer).isUploadDiscouraged()) {
     44                            if (warnMergingUploadDiscouragedLayers(sourceLayer, targetLayer)) {
     45                                break;
     46                            }
     47                        }
     48                        targetLayer.mergeFrom(sourceLayer);
     49                        Main.map.mapView.removeLayer(sourceLayer);
     50                        layerMerged = true;
     51                    }
     52                }
     53                if (layerMerged) {
     54                    Main.map.mapView.setActiveLayer(targetLayer);
     55                }
    3556            }
    36         }
    37         Main.map.mapView.setActiveLayer(targetLayer);
     57        });
     58    }
     59   
     60    public void merge(List<Layer> sourceLayers) {
     61        doMerge(sourceLayers, sourceLayers);
    3862    }
    3963
    40     public void merge(final Layer sourceLayer) {
     64    public void merge(Layer sourceLayer) {
    4165        if (sourceLayer == null)
    4266            return;
     
    4670            return;
    4771        }
    48         final Layer targetLayer = askTargetLayer(targetLayers);
    49         if (targetLayer == null)
    50             return;
    51         Main.worker.submit(new Runnable() {
    52             @Override
    53             public void run() {
    54                 targetLayer.mergeFrom(sourceLayer);
    55                 Main.map.mapView.removeLayer(sourceLayer);
    56                 Main.map.mapView.setActiveLayer(targetLayer);
    57             }
    58         });
     72        doMerge(targetLayers, Collections.singleton(sourceLayer));
    5973    }
    6074
     
    7488        setEnabled(!LayerListDialog.getInstance().getModel().getPossibleMergeTargets(getEditLayer()).isEmpty());
    7589    }
     90   
     91    /**
     92     * returns true if the user wants to cancel, false if they want to continue
     93     */
     94    public static final boolean warnMergingUploadDiscouragedLayers(Layer sourceLayer, Layer targetLayer) {
     95        return GuiHelper.warnUser(tr("Merging layers with different upload policies"),
     96                "<html>" +
     97                tr("You are about to merge data between layers ''{0}'' and ''{1}''.<br /><br />"+
     98                        "These layers have different upload policies and should not been merged as it.<br />"+
     99                        "Merging them will result to enforce the stricter policy (upload discouraged) to ''{1}''.<br /><br />"+
     100                        "<b>This is not the recommended way of merging such data</b>.<br />"+
     101                        "You should instead check and merge each object, one by one, by using ''<i>Merge selection</i>''.<br /><br />"+
     102                        "Are you sure you want to continue?", sourceLayer.getName(), targetLayer.getName(), targetLayer.getName())+
     103                "</html>",
     104                ImageProvider.get("dialogs", "mergedown"), tr("Ignore this hint and merge anyway"));
     105    }
    76106}
  • trunk/src/org/openstreetmap/josm/actions/MergeSelectionAction.java

    r4982 r5233  
    1616import org.openstreetmap.josm.gui.layer.Layer;
    1717import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     18import org.openstreetmap.josm.gui.util.GuiHelper;
     19import org.openstreetmap.josm.tools.ImageProvider;
    1820import org.openstreetmap.josm.tools.Shortcut;
    1921
     
    3739        if (targetLayer == null)
    3840            return;
     41        if (getEditLayer().isUploadDiscouraged() && targetLayer instanceof OsmDataLayer && !((OsmDataLayer)targetLayer).isUploadDiscouraged()
     42                && getEditLayer().data.getSelected().size() > 1) {
     43            if (warnMergingUploadDiscouragedObjects(targetLayer)) {
     44                return;
     45            }
     46        }
    3947        MergeSourceBuildingVisitor builder = new MergeSourceBuildingVisitor(getEditLayer().data);
    4048        ((OsmDataLayer)targetLayer).mergeFrom(builder.build());
     
    6068        setEnabled(selection != null && !selection.isEmpty());
    6169    }
     70   
     71    /**
     72     * returns true if the user wants to cancel, false if they want to continue
     73     */
     74    public static final boolean warnMergingUploadDiscouragedObjects(Layer targetLayer) {
     75        return GuiHelper.warnUser(tr("Merging too many objects with different upload policies"),
     76                "<html>" +
     77                tr("You are about to merge more than 1 object between layers ''{0}'' and ''{1}''.<br /><br />"+
     78                        "<b>This is not the recommended way of merging such data</b>.<br />"+
     79                        "You should instead check and merge each object, <b>one by one</b>.<br /><br />"+
     80                        "Are you sure you want to continue?", getEditLayer().getName(), targetLayer.getName(), targetLayer.getName())+
     81                "</html>",
     82                ImageProvider.get("dialogs", "mergedown"), tr("Ignore this hint and merge anyway"));
     83    }
    6284}
  • trunk/src/org/openstreetmap/josm/actions/UploadAction.java

    r5025 r5233  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
    7 import java.awt.Image;
    87import java.awt.event.ActionEvent;
    98import java.awt.event.KeyEvent;
    109import java.util.LinkedList;
    1110
    12 import javax.swing.Icon;
    13 import javax.swing.ImageIcon;
    1411import javax.swing.JOptionPane;
    1512import javax.swing.SwingUtilities;
     
    2219import org.openstreetmap.josm.data.APIDataSet;
    2320import org.openstreetmap.josm.data.conflict.ConflictCollection;
    24 import org.openstreetmap.josm.gui.ExtendedDialog;
    2521import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2622import org.openstreetmap.josm.gui.help.HelpUtil;
     
    2824import org.openstreetmap.josm.gui.io.UploadPrimitivesTask;
    2925import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     26import org.openstreetmap.josm.gui.util.GuiHelper;
    3027import org.openstreetmap.josm.tools.ImageProvider;
    3128import org.openstreetmap.josm.tools.Shortcut;
     
    126123     */
    127124    public static final boolean warnUploadDiscouraged(OsmDataLayer layer) {
    128         ExtendedDialog dlg = new ExtendedDialog(Main.parent,
    129                 tr("Upload discouraged"),
    130                 new String[] {tr("Cancel"), tr("Continue")});
    131         dlg.setContent("<html>" +
     125        return GuiHelper.warnUser(tr("Upload discouraged"),
     126                "<html>" +
    132127                tr("You are about to upload data from the layer ''{0}''.<br /><br />"+
    133                         "Sending data from this layer is <b>strongly discouraged</b>. If you continue,<br />"+
    134                         "it may require you subsequently have to revert your changes, or force other contributors to.<br /><br />"+
    135                         "Are you sure you want to continue?", layer.getName())+
    136                 "</html>");
    137         dlg.setButtonIcons(new Icon[] {
    138                 ImageProvider.get("cancel"),
    139                 ImageProvider.overlay(
    140                         ImageProvider.get("upload"),
    141                         new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),
    142                         ImageProvider.OverlayPosition.SOUTHEAST)});
    143         dlg.setToolTipTexts(new String[] {
    144                 tr("Cancel"),
    145                 tr("Ignore this hint and upload anyway")});
    146         dlg.setIcon(JOptionPane.WARNING_MESSAGE);
    147         dlg.setCancelButton(1);
    148         return dlg.showDialog().getValue() != 2;
     128                    "Sending data from this layer is <b>strongly discouraged</b>. If you continue,<br />"+
     129                    "it may require you subsequently have to revert your changes, or force other contributors to.<br /><br />"+
     130                    "Are you sure you want to continue?", layer.getName())+
     131                "</html>",
     132                ImageProvider.get("upload"), tr("Ignore this hint and upload anyway"));
    149133    }
    150134
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayerInfo.java

    r4310 r5233  
    3131        this.layer = layer;
    3232        this.doSaveToFile = layer.requiresSaveToFile();
    33         this.doUploadToServer = layer.requiresUploadToServer();
     33        this.doUploadToServer = layer.requiresUploadToServer() && !layer.isUploadDiscouraged();
    3434        this.file = layer.getAssociatedFile();
    3535    }
  • trunk/src/org/openstreetmap/josm/gui/io/SaveLayersTableColumnModel.java

    r5003 r5233  
    3737            StringBuilder sb = new StringBuilder();
    3838            sb.append("<html>");
    39             if (info.getLayer().requiresUploadToServer()) {
     39            if (info.getLayer().requiresUploadToServer() && !info.getLayer().isUploadDiscouraged()) {
    4040                add(needsUpload, defaultCellStyle);
    4141                sb.append(tr("Layer ''{0}'' has modifications which should be uploaded to the server.", info.getName()));
     
    4343            } else {
    4444                add(pnlEmpty, defaultCellStyle);
    45                 sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName()));
     45                if (info.getLayer().requiresUploadToServer()) {
     46                    sb.append(tr("Layer ''{0}'' has modifications which are discouraged to be uploaded.", info.getName()));
     47                } else {
     48                    sb.append(tr("Layer ''{0}'' has no modifications to be uploaded.", info.getName()));
     49                }
    4650            }
    4751            sb.append("<br/>");
  • trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    r5059 r5233  
    302302        final PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Merging layers"));
    303303        monitor.setCancelable(false);
     304        if (from instanceof OsmDataLayer && ((OsmDataLayer)from).isUploadDiscouraged()) {
     305            setUploadDiscouraged(true);
     306        }
    304307        mergeFrom(((OsmDataLayer)from).data, monitor);
    305308        monitor.close();
     
    411414
    412415    @Override public boolean isMergable(final Layer other) {
    413         return other instanceof OsmDataLayer && (isUploadDiscouraged() == ((OsmDataLayer)other).isUploadDiscouraged());
     416        // isUploadDiscouraged commented to allow merging between normal layers and discouraged layers with a warning (see #7684)
     417        return other instanceof OsmDataLayer;// && (isUploadDiscouraged() == ((OsmDataLayer)other).isUploadDiscouraged());
    414418    }
    415419
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r4695 r5233  
    22package org.openstreetmap.josm.gui.util;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5
    46import java.awt.Component;
    57import java.awt.Container;
     8import java.awt.Image;
    69
     10import javax.swing.Icon;
     11import javax.swing.ImageIcon;
     12import javax.swing.JOptionPane;
    713import javax.swing.SwingUtilities;
     14
     15import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.gui.ExtendedDialog;
     17import org.openstreetmap.josm.tools.ImageProvider;
    818
    919/**
     
    3343        }
    3444    }
     45   
     46    /**
     47     * returns true if the user wants to cancel, false if they
     48     * want to continue
     49     */
     50    public static final boolean warnUser(String title, String content, ImageIcon baseActionIcon, String continueToolTip) {
     51        ExtendedDialog dlg = new ExtendedDialog(Main.parent,
     52                title, new String[] {tr("Cancel"), tr("Continue")});
     53        dlg.setContent(content);
     54        dlg.setButtonIcons(new Icon[] {
     55                ImageProvider.get("cancel"),
     56                ImageProvider.overlay(
     57                        ImageProvider.get("upload"),
     58                        new ImageIcon(ImageProvider.get("warning-small").getImage().getScaledInstance(10 , 10, Image.SCALE_SMOOTH)),
     59                        ImageProvider.OverlayPosition.SOUTHEAST)});
     60        dlg.setToolTipTexts(new String[] {
     61                tr("Cancel"),
     62                continueToolTip});
     63        dlg.setIcon(JOptionPane.WARNING_MESSAGE);
     64        dlg.setCancelButton(1);
     65        return dlg.showDialog().getValue() != 2;
     66    }
    3567
    3668}
Note: See TracChangeset for help on using the changeset viewer.