Ticket #23808: 23808.patch

File 23808.patch, 5.6 KB (added by taylor.smock, 21 months ago)

Add buttons to notification to download referrers

  • src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    Subject: [PATCH] 23808
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/actions/AlignInCircleAction.java b/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
    a b  
    55import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66import static org.openstreetmap.josm.tools.I18n.tr;
    77
     8import java.awt.Color;
     9import java.awt.GridBagConstraints;
     10import java.awt.GridBagLayout;
    811import java.awt.event.ActionEvent;
    912import java.awt.event.KeyEvent;
    1013import java.util.ArrayList;
     
    1821import java.util.TreeMap;
    1922import java.util.stream.Collectors;
    2023
     24import javax.swing.AbstractAction;
     25import javax.swing.Action;
     26import javax.swing.JButton;
     27import javax.swing.JEditorPane;
    2128import javax.swing.JOptionPane;
     29import javax.swing.JPanel;
    2230
    2331import org.openstreetmap.josm.command.Command;
    2432import org.openstreetmap.josm.command.MoveCommand;
     
    2937import org.openstreetmap.josm.data.osm.DataSet;
    3038import org.openstreetmap.josm.data.osm.Node;
    3139import org.openstreetmap.josm.data.osm.OsmPrimitive;
     40import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3241import org.openstreetmap.josm.data.osm.Way;
    3342import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon;
    3443import org.openstreetmap.josm.data.osm.visitor.paint.relations.Multipolygon.JoinedWay;
    3544import org.openstreetmap.josm.data.validation.tests.CrossingWays;
    3645import org.openstreetmap.josm.data.validation.tests.SelfIntersectingWay;
     46import org.openstreetmap.josm.gui.MainApplication;
    3747import org.openstreetmap.josm.gui.Notification;
     48import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
     49import org.openstreetmap.josm.tools.GBC;
    3850import org.openstreetmap.josm.tools.Geometry;
    3951import org.openstreetmap.josm.tools.Logging;
    4052import org.openstreetmap.josm.tools.Shortcut;
     
    8294            super(msg);
    8395        }
    8496    }
     97
     98    /**
     99     * IncompleteReferrers exception has to be raised when action can't be performed due to objects without
     100     * referrer information
     101     */
     102    public static class IncompleteReferrers extends InvalidSelection {
     103        private final long[] nodeIds;
     104
     105        /**
     106         * Create an IncompleteReferrers exception with specific message
     107         * @param msg Message that will be displayed to the user
     108         * @param nodeIds The nodes that are missing referrers
     109         */
     110        IncompleteReferrers(String msg, long... nodeIds) {
     111            super(msg);
     112            this.nodeIds = nodeIds;
     113        }
     114
     115        public long[] getNodeIds() {
     116            return this.nodeIds;
     117        }
     118    }
    85119
    86120    /**
    87121     * Add a {@link MoveCommand} to move a node to a PolarCoor if there is a significant move.
     
    120154                .show();
    121155
    122156            }
     157        } catch (IncompleteReferrers except) {
     158            Logging.debug(except);
     159            final JPanel panel = new JPanel(new GridBagLayout());
     160            final JMultilineLabel lbl = new JMultilineLabel(except.getMessage());
     161            final DataSet editDataSet = getLayerManager().getEditDataSet();
     162            final Action downloadReferrers = new AbstractAction(tr("Download Referrers ({0} nodes)", except.getNodeIds().length)) {
     163                @Override
     164                public void actionPerformed(ActionEvent e) {
     165                    Collection<OsmPrimitive> toDownload = new ArrayList<>(except.getNodeIds().length);
     166                    for (long nodeId : except.getNodeIds()) {
     167                        toDownload.add(editDataSet.getPrimitiveById(nodeId, OsmPrimitiveType.NODE));
     168                    }
     169                    DownloadReferrersAction.downloadReferrers(getLayerManager().getEditLayer(), toDownload);
     170                }
     171            };
     172            final Action downloadAlong = new AbstractAction("Download Along") {
     173                @Override
     174                public void actionPerformed(ActionEvent e) {
     175                    MainApplication.getMenu().downloadAlongWay.actionPerformed(e);
     176                }
     177            };
     178            lbl.setMaxWidth(Notification.DEFAULT_CONTENT_WIDTH);
     179            lbl.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
     180            lbl.setForeground(Color.BLACK);
     181            panel.setOpaque(false);
     182            panel.add(lbl, GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     183            panel.add(new JButton(downloadReferrers));
     184            panel.add(new JButton(downloadAlong), GBC.eol().fill(GridBagConstraints.HORIZONTAL));
     185            new Notification().setContent(panel)
     186                    .setIcon(JOptionPane.INFORMATION_MESSAGE)
     187                    .setDuration(Notification.TIME_SHORT)
     188                    .show();
    123189        } catch (InvalidSelection except) {
    124190            Logging.debug(except);
    125191            new Notification(except.getMessage())
     
    274340
    275341        // Check if one or more nodes does not have all parents available
    276342        if (nodes.stream().anyMatch(not(Node::isReferrersDownloaded)))
    277             throw new InvalidSelection(tr("One or more nodes involved in this action may have additional referrers."));
     343            throw new IncompleteReferrers(tr("One or more nodes involved in this action may have additional referrers."),
     344                    nodes.stream().filter(not(Node::isReferrersDownloaded)).mapToLong(Node::getUniqueId).toArray());
    278345
    279346
    280347        if (center == null) {