Ignore:
Timestamp:
2018-07-12T23:02:02+02:00 (5 weeks ago)
Author:
michael2402
Message:

See #16388: New mechanism for plugins to register relation editor actions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/RelationEditor.java

    r12620 r14027  
    66import java.beans.PropertyChangeListener;
    77import java.beans.PropertyChangeSupport;
    8 import java.lang.reflect.Method;
    9 import java.util.ArrayList;
    108import java.util.Collection;
    11 import java.util.List;
    129
    1310import org.openstreetmap.josm.Main;
     
    1714import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    1815import org.openstreetmap.josm.tools.CheckParameterUtil;
    19 import org.openstreetmap.josm.tools.Logging;
    2016
    2117/**
     
    2420 */
    2521public abstract class RelationEditor extends ExtendedDialog implements IRelationEditor {
     22        private static final long serialVersionUID = 1L;
    2623
    27     /** the property name for the current relation.
     24        /** the property name for the current relation.
    2825     * @see #setRelation(Relation)
    2926     * @see #getRelation()
     
    3532     */
    3633    public static final String RELATION_SNAPSHOT_PROP = RelationEditor.class.getName() + ".relationSnapshot";
    37 
    38     /** the list of registered relation editor classes */
    39     private static List<Class<RelationEditor>> editors = new ArrayList<>();
    4034
    4135    /** The relation that this editor is working on. */
     
    7165
    7266    /**
    73      * Registers a relation editor class. Depending on the type of relation to be edited
    74      * {@link #getEditor(OsmDataLayer, Relation, Collection)} will create an instance of
    75      * this class.
    76      *
    77      * @param clazz the class
    78      */
    79     public void registerRelationEditor(Class<RelationEditor> clazz) {
    80         if (clazz != null && !editors.contains(clazz)) {
    81             editors.add(clazz);
    82         }
    83     }
    84 
    85     /**
    8667     * This is a factory method that creates an appropriate RelationEditor instance suitable for editing the relation
    8768     * that was passed in as an argument.
    8869     *
    89      * This method is guaranteed to return a working RelationEditor. If no specific editor has been registered for the
    90      * type of relation, then a generic editor will be returned.
    91      *
    92      * Editors can be registered by adding their class to the static list "editors" in the RelationEditor class.
    93      * When it comes to editing a relation, all registered editors are queried via their static "canEdit" method whether
    94      * they feel responsible for that kind of relation, and if they return true then an instance of that class will be used.
     70     * This method is guaranteed to return a working RelationEditor.
    9571     *
    9672     * @param layer the data layer the relation is a member of
     
    10076     */
    10177    public static RelationEditor getEditor(OsmDataLayer layer, Relation r, Collection<RelationMember> selectedMembers) {
    102         for (Class<RelationEditor> e : editors) {
    103             try {
    104                 Method m = e.getMethod("canEdit", Relation.class);
    105                 Boolean canEdit = (Boolean) m.invoke(null, r);
    106                 if (canEdit) {
    107                     return e.getConstructor(Relation.class, Collection.class).newInstance(layer, r, selectedMembers);
    108                 }
    109             } catch (ReflectiveOperationException ex) {
    110                 Logging.warn(ex);
    111             }
    112         }
    11378        if (RelationDialogManager.getRelationDialogManager().isOpenInEditor(layer, r))
    11479            return RelationDialogManager.getRelationDialogManager().getEditorForRelation(layer, r);
Note: See TracChangeset for help on using the changeset viewer.