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

Last change on this file since 14029 was 14029, checked in by michael2402, 8 months ago

See #16388: Checkstyle: Convert tabs to spaces.

File size: 4.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.dialogs.relation.actions;
3
4import java.beans.PropertyChangeEvent;
5import java.beans.PropertyChangeListener;
6import java.util.Objects;
7
8import javax.swing.AbstractAction;
9import javax.swing.event.ListSelectionEvent;
10import javax.swing.event.ListSelectionListener;
11import javax.swing.event.TableModelEvent;
12import javax.swing.event.TableModelListener;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.data.osm.DataSet;
16import org.openstreetmap.josm.data.osm.DownloadPolicy;
17import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
18import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
19import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
20import org.openstreetmap.josm.gui.dialogs.relation.SelectionTable;
21import org.openstreetmap.josm.gui.dialogs.relation.SelectionTableModel;
22import org.openstreetmap.josm.gui.layer.OsmDataLayer;
23import org.openstreetmap.josm.gui.tagging.TagEditorModel;
24import org.openstreetmap.josm.io.OnlineResource;
25
26/**
27 * Abstract superclass of relation editor actions.
28 *
29 * @since 9496
30 */
31public abstract class AbstractRelationEditorAction extends AbstractAction
32        implements TableModelListener, ListSelectionListener, PropertyChangeListener {
33    private static final long serialVersionUID = 1L;
34    protected final transient IRelationEditorActionAccess editorAccess;
35
36    /**
37     * Create a new relation editor action
38     *
39     * @param editorAccess
40     *            The editor this action is for
41     * @param actionMapKey
42     *            The key for the member table action map.
43     * @param updateOn
44     *            The events that may cause the enabled state of this button to
45     *            change.
46     */
47    protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess,
48            IRelationEditorUpdateOn... updateOn) {
49        Objects.requireNonNull(editorAccess, "editorAccess");
50        Objects.requireNonNull(updateOn, "updateOn");
51        this.editorAccess = editorAccess;
52        for (IRelationEditorUpdateOn u : updateOn) {
53            u.register(editorAccess, this);
54        }
55    }
56
57    /**
58     * Create a new relation editor action
59     *
60     * @param editorAccess
61     *            The editor this action is for
62     * @param actionMapKey
63     *            The key for the member table action map.
64     * @param updateOn
65     *            The events that may cause the enabled state of this button to
66     *            change.
67     */
68    protected AbstractRelationEditorAction(IRelationEditorActionAccess editorAccess, String actionMapKey,
69            IRelationEditorUpdateOn... updateOn) {
70        this(editorAccess, updateOn);
71        Objects.requireNonNull(actionMapKey, "actionMapKey");
72
73        this.editorAccess.addMemberTableAction(actionMapKey, this);
74    }
75
76    @Override
77    public void tableChanged(TableModelEvent e) {
78        updateEnabledState();
79    }
80
81    @Override
82    public void valueChanged(ListSelectionEvent e) {
83        updateEnabledState();
84    }
85
86    @Override
87    public void propertyChange(PropertyChangeEvent evt) {
88        updateEnabledState();
89    }
90
91    protected abstract void updateEnabledState();
92
93    protected final boolean canDownload() {
94        if (editorAccess.getEditor().getRelation() == null)
95            return false;
96        DataSet ds = editorAccess.getEditor().getRelation().getDataSet();
97        return !Main.isOffline(OnlineResource.OSM_API) && ds != null && !ds.isLocked()
98                && !DownloadPolicy.BLOCKED.equals(ds.getDownloadPolicy());
99    }
100
101    protected MemberTable getMemberTable() {
102        return editorAccess.getMemberTable();
103    }
104
105    protected MemberTableModel getMemberTableModel() {
106        return editorAccess.getMemberTableModel();
107    }
108
109    protected SelectionTable getSelectionTable() {
110        return editorAccess.getSelectionTable();
111    }
112
113    protected SelectionTableModel getSelectionTableModel() {
114        return editorAccess.getSelectionTableModel();
115    }
116
117    protected IRelationEditor getEditor() {
118        return editorAccess.getEditor();
119    }
120
121    protected TagEditorModel getTagModel() {
122        return editorAccess.getTagModel();
123    }
124
125    protected OsmDataLayer getLayer() {
126        return editorAccess.getEditor().getLayer();
127    }
128
129    public boolean isExpertOnly() {
130        return false;
131    }
132}
Note: See TracBrowser for help on using the repository browser.