source: josm/trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/AbstractRelationEditorAction.java @ 13509

Last change on this file since 13509 was 13509, checked in by Don-vip, 7 months ago

fix #16060 - NPE + minor fixes

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import javax.swing.AbstractAction;
5import javax.swing.event.ListSelectionEvent;
6import javax.swing.event.ListSelectionListener;
7import javax.swing.event.TableModelEvent;
8import javax.swing.event.TableModelListener;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.data.osm.DataSet;
12import org.openstreetmap.josm.data.osm.DataSet.DownloadPolicy;
13import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
14import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
15import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
16import org.openstreetmap.josm.gui.layer.OsmDataLayer;
17import org.openstreetmap.josm.io.OnlineResource;
18
19/**
20 * Abstract superclass of relation editor actions.
21 * @since 9496
22 */
23public abstract class AbstractRelationEditorAction extends AbstractAction implements TableModelListener, ListSelectionListener {
24    protected final MemberTable memberTable;
25    protected final MemberTableModel memberTableModel;
26    protected final transient OsmDataLayer layer;
27    protected final transient IRelationEditor editor;
28
29    protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey) {
30        this(memberTable, memberTableModel, actionMapKey, null, null);
31    }
32
33    protected AbstractRelationEditorAction(MemberTable memberTable, MemberTableModel memberTableModel, String actionMapKey,
34            OsmDataLayer layer, IRelationEditor editor) {
35        this.memberTable = memberTable;
36        this.memberTableModel = memberTableModel;
37        this.layer = layer;
38        this.editor = editor;
39        if (actionMapKey != null) {
40            this.memberTable.getActionMap().put(actionMapKey, this);
41        }
42    }
43
44    @Override
45    public void tableChanged(TableModelEvent e) {
46        updateEnabledState();
47    }
48
49    @Override
50    public void valueChanged(ListSelectionEvent e) {
51        updateEnabledState();
52    }
53
54    protected abstract void updateEnabledState();
55
56    protected final boolean canDownload() {
57        if (editor.getRelation() == null)
58            return false;
59        DataSet ds = editor.getRelation().getDataSet();
60        return !Main.isOffline(OnlineResource.OSM_API)
61            && ds != null && !ds.isLocked() && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
62    }
63}
Note: See TracBrowser for help on using the repository browser.