Ignore:
Timestamp:
2012-02-26T16:10:39+01:00 (12 years ago)
Author:
Don-vip
Message:

see #4043 - Have an 'upload prohibited' flag in .osm files

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
1 added
2 edited

Legend:

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

    r4982 r5025  
    55import static org.openstreetmap.josm.tools.I18n.tr;
    66
     7import java.awt.Image;
    78import java.awt.event.ActionEvent;
    89import java.awt.event.KeyEvent;
    910import java.util.LinkedList;
    1011
     12import javax.swing.Icon;
     13import javax.swing.ImageIcon;
    1114import javax.swing.JOptionPane;
    1215import javax.swing.SwingUtilities;
     
    1922import org.openstreetmap.josm.data.APIDataSet;
    2023import org.openstreetmap.josm.data.conflict.ConflictCollection;
     24import org.openstreetmap.josm.gui.ExtendedDialog;
    2125import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2226import org.openstreetmap.josm.gui.help.HelpUtil;
     
    2428import org.openstreetmap.josm.gui.io.UploadPrimitivesTask;
    2529import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     30import org.openstreetmap.josm.tools.ImageProvider;
    2631import org.openstreetmap.josm.tools.Shortcut;
    2732
     
    104109    }
    105110
    106     protected void alertUnresolvedConflicts(OsmDataLayer layer) {
     111    protected static void alertUnresolvedConflicts(OsmDataLayer layer) {
    107112        HelpAwareOptionPane.showOptionDialog(
    108113                Main.parent,
     
    115120        );
    116121    }
     122   
     123    /**
     124     * returns true if the user wants to cancel, false if they
     125     * want to continue
     126     */
     127    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>" +
     132                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;
     149    }
    117150
    118151    /**
    119152     * Check whether the preconditions are met to upload data in <code>apiData</code>.
    120      * Makes sure primitives in <code>apiData</code> don't participate in conflicts and
     153     * Makes sure upload is allowed, primitives in <code>apiData</code> don't participate in conflicts and
    121154     * runs the installed {@see UploadHook}s.
    122155     *
     
    126159     */
    127160    public boolean checkPreUploadConditions(OsmDataLayer layer, APIDataSet apiData) {
     161        if (layer.isUploadDiscouraged()) {
     162            if (warnUploadDiscouraged(layer)) {
     163                return false;
     164            }
     165        }
    128166        ConflictCollection conflicts = layer.getConflicts();
    129167        if (apiData.participatesInConflict(conflicts)) {
  • trunk/src/org/openstreetmap/josm/actions/UploadSelectionAction.java

    r4191 r5025  
    8888        if (!isEnabled())
    8989            return;
     90        if (getEditLayer().isUploadDiscouraged()) {
     91            if (UploadAction.warnUploadDiscouraged(getEditLayer())) {
     92                return;
     93            }
     94        }
    9095        UploadHullBuilder builder = new UploadHullBuilder();
    9196        UploadSelectionDialog dialog = new UploadSelectionDialog();
Note: See TracChangeset for help on using the changeset viewer.