1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.KeyEvent;
|
---|
9 | import java.util.LinkedHashSet;
|
---|
10 | import java.util.Set;
|
---|
11 | import java.util.stream.Collectors;
|
---|
12 |
|
---|
13 | import javax.swing.JList;
|
---|
14 | import javax.swing.JTable;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.data.osm.OsmData;
|
---|
17 | import org.openstreetmap.josm.data.osm.PrimitiveId;
|
---|
18 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
19 | import org.openstreetmap.josm.gui.dialogs.OsmIdSelectionDialog;
|
---|
20 | import org.openstreetmap.josm.gui.history.HistoryBrowserDialogManager;
|
---|
21 | import org.openstreetmap.josm.io.NetworkManager;
|
---|
22 | import org.openstreetmap.josm.io.OnlineResource;
|
---|
23 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Display history information about OSM ways, nodes, or relations.
|
---|
27 | * @since 968
|
---|
28 | */
|
---|
29 | public class HistoryInfoAction extends JosmAction {
|
---|
30 |
|
---|
31 | /** Action shortcut, made public in order to be used from {@code GettingStarted} page. */
|
---|
32 | public static final Shortcut SHORTCUT = Shortcut.registerShortcut("core:historyinfo", tr("History"), KeyEvent.VK_H, Shortcut.CTRL);
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Constructs a new {@code HistoryInfoAction}.
|
---|
36 | */
|
---|
37 | public HistoryInfoAction() {
|
---|
38 | super(tr("History"), "dialogs/history",
|
---|
39 | tr("Display history information about OSM ways, nodes, or relations."),
|
---|
40 | SHORTCUT, true, "action/historyinfo", false);
|
---|
41 | setHelpId(ht("/Action/ObjectHistory"));
|
---|
42 | setEnabled(true);
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public void actionPerformed(ActionEvent ae) {
|
---|
47 | // Generic handling of tables displaying OSM primitives
|
---|
48 | Set<PrimitiveId> sel = new LinkedHashSet<>();
|
---|
49 | if (ae.getSource() instanceof JTable) {
|
---|
50 | JTable table = (JTable) ae.getSource();
|
---|
51 | for (int row : table.getSelectedRows()) {
|
---|
52 | for (int col = 0; col < table.getModel().getColumnCount(); col++) {
|
---|
53 | Object value = table.getModel().getValueAt(row, col);
|
---|
54 | if (value instanceof PrimitiveId) {
|
---|
55 | sel.add((PrimitiveId) value);
|
---|
56 | break;
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 | } else if (ae.getSource() instanceof JList) {
|
---|
61 | JList<?> list = (JList<?>) ae.getSource();
|
---|
62 | sel = list.getSelectedValuesList()
|
---|
63 | .stream().filter(v -> v instanceof PrimitiveId)
|
---|
64 | .map(v -> (PrimitiveId) v)
|
---|
65 | .collect(Collectors.toCollection(LinkedHashSet::new));
|
---|
66 | }
|
---|
67 | if (!sel.isEmpty()) {
|
---|
68 | HistoryBrowserDialogManager.getInstance().showHistory(sel);
|
---|
69 | return;
|
---|
70 | }
|
---|
71 | // Otherwise show history for currently selected objects
|
---|
72 | OsmData<?, ?, ?, ?> set = getLayerManager().getActiveData();
|
---|
73 | if (set != null && !set.selectionEmpty()) {
|
---|
74 | HistoryBrowserDialogManager.getInstance().showHistory(set.getAllSelected());
|
---|
75 | } else {
|
---|
76 | HistoryObjectIDDialog dialog = new HistoryObjectIDDialog();
|
---|
77 | if (dialog.showDialog().getValue() == dialog.getContinueButtonIndex()) {
|
---|
78 | HistoryBrowserDialogManager.getInstance().showHistory(dialog.getOsmIds());
|
---|
79 | }
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Dialog allowing to choose object id if no one is selected.
|
---|
85 | * @since 6448
|
---|
86 | */
|
---|
87 | public static class HistoryObjectIDDialog extends OsmIdSelectionDialog {
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Constructs a new {@code HistoryObjectIDDialog}.
|
---|
91 | */
|
---|
92 | public HistoryObjectIDDialog() {
|
---|
93 | super(MainApplication.getMainFrame(), tr("Show history"), tr("Show history"), tr("Cancel"));
|
---|
94 | setButtonIcons("dialogs/history", "cancel");
|
---|
95 | init();
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Override
|
---|
99 | public void setupDialog() {
|
---|
100 | super.setupDialog();
|
---|
101 | buttons.get(0).setEnabled(!NetworkManager.isOffline(OnlineResource.OSM_API));
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|