Ignore:
Timestamp:
2010-03-17T11:17:57+01:00 (14 years ago)
Author:
guggis
Message:

added editing of raw tags and raw members

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
5 added
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/dnd/PrimitiveIdListTransferHandler.java

    r20489 r20527  
    2424       
    2525        /**
     26         * Replies true if {@code transferFlavors} includes the data flavor {@see PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}.
     27
     28         * @param transferFlavors an array of transferFlavors
     29         * @return true if {@code transferFlavors} includes the data flavor {@see PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}.
     30         */
     31        public static boolean isSupportedFlavor(DataFlavor[] transferFlavors) {
     32                for (DataFlavor df: transferFlavors) {
     33                        if (df.equals(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR)) return true;
     34                }
     35                return false;
     36        }
     37       
     38        /**
    2639         * Creates the transfer handler
    2740         *
     
    3447        }
    3548
    36         /**
    37          * Replies true if {@code transferFlavors} includes the data flavor {@see PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}.
    38 
    39          * @param transferFlavors an array of transferFlavors
    40          * @return
    41          */
    42         protected boolean isSupportedFlavor(DataFlavor[] transferFlavors) {
    43                 for (DataFlavor df: transferFlavors) {
    44                         if (df.equals(PrimitiveIdTransferable.PRIMITIVE_ID_LIST_FLAVOR)) return true;
    45                 }
    46                 return false;
    47         }
     49       
    4850       
    4951        protected Transferable createTransferable(JComponent c) {
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/JosmSelectionListModel.java

    r20489 r20527  
    227227        public List<PrimitiveId> getSelectedPrimitiveIds() {
    228228                List<PrimitiveId> ret = new ArrayList<PrimitiveId>(getSelected().size());
    229                 for(OsmPrimitive p: getSelected()) {
    230                         ret.add(p.getPrimitiveId());
     229                for(int i=0; i< selection.size(); i++) {
     230                        if (selectionModel.isSelectedIndex(i)) {
     231                                ret.add(selection.get(i).getPrimitiveId());
     232                        }
    231233                }
    232234                return ret;
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r20489 r20527  
    7777    private JosmSelectionPanel pnlJosmSelection;
    7878    private BasicEditorPanel pnlBasicEditor;
     79    private AdvancedEditorPanel pnlAdvancedEditor;
    7980    private TurnRestrictionEditorModel editorModel;
    8081   
     
    117118        tpEditors.setTitleAt(0, tr("Basic"));
    118119        tpEditors.setToolTipTextAt(0, tr("Edit basic attributes of a turn restriction"));
     120       
     121        tpEditors.add(pnlAdvancedEditor = new AdvancedEditorPanel(editorModel));
     122        tpEditors.setTitleAt(1, tr("Advanced"));
     123        tpEditors.setToolTipTextAt(1, tr("Edit the raw tags and members of this turn restriction"));
     124       
    119125        pnl.add(tpEditors, BorderLayout.CENTER);
    120126        return pnl;
     
    161167     */
    162168    protected void build() {           
    163         editorModel = new TurnRestrictionEditorModel();
     169        editorModel = new TurnRestrictionEditorModel(getLayer());
    164170        Container c = getContentPane();
    165171        c.setLayout(new BorderLayout());
     
    222228     
    223229        if (turnRestriction == null) {
    224                 editorModel.populate(new Relation(), getLayer().data);
    225         } else if (turnRestriction.getDataSet() == null) {
    226                 editorModel.populate(turnRestriction, getLayer().data);
    227         } else if (turnRestriction.getDataSet() == getLayer().data) {
     230                editorModel.populate(new Relation());
     231        } else if (turnRestriction.getDataSet() == null || turnRestriction.getDataSet() == getLayer().data) {
    228232                editorModel.populate(turnRestriction);
    229233        } else {
    230                 throw new IllegalArgumentException(MessageFormat.format("turnRestriction must not belong to the layer {0}", getLayer().getName()));
     234                throw new IllegalArgumentException(MessageFormat.format("turnRestriction must belong to layer ''{0}''", getLayer().getName()));
    231235        }
    232236        setTurnRestrictionSnapshot(turnRestriction == null ? null : new Relation(turnRestriction));
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditorModel.java

    r20489 r20527  
    22
    33import java.text.MessageFormat;
    4 import java.util.ArrayList;
    5 import java.util.Collections;
    64import java.util.List;
    75import java.util.Observable;
     6import java.util.Set;
    87import java.util.logging.Logger;
     8
     9import javax.swing.event.TableModelEvent;
     10import javax.swing.event.TableModelListener;
    911
    1012import org.openstreetmap.josm.data.osm.DataSet;
     
    1315import org.openstreetmap.josm.data.osm.PrimitiveId;
    1416import org.openstreetmap.josm.data.osm.Relation;
    15 import org.openstreetmap.josm.data.osm.RelationMember;
    1617import org.openstreetmap.josm.data.osm.TagCollection;
    1718import org.openstreetmap.josm.data.osm.Way;
     
    2728import org.openstreetmap.josm.data.osm.event.WayNodesChangedEvent;
    2829import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
     30import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     31import org.openstreetmap.josm.gui.tagging.TagEditorModel;
     32import org.openstreetmap.josm.gui.tagging.TagModel;
    2933import org.openstreetmap.josm.tools.CheckParameterUtil;
    3034
     
    5963        }
    6064       
    61        
    62         /**
    63          * holds the relation member of turn restriction relation from which the turn
    64          * restriction leg with role 'from' was initialized. This is needed if OSM
    65          * data contains turn restrictions with multiple 'from' members. The
    66          * field is null if a turn restriction didn't have a member with role
    67          * 'from'.
    68          */
    69         private RelationMember fromRelationMember;
    70        
    71         /**
    72          * holds the relation member of turn restriction relation from which the turn
    73          * restriction leg with role 'to' was initialized. This is needed if OSM
    74          * data contains turn restrictions with multiple 'to' members. The
    75          * field is null if a turn restriction didn't have a member with role
    76          * 'to'.
    77          */
    78         private RelationMember toRelationMember;
    79         private Way from;
    80         private Way to;
    81         private TagCollection tags = new TagCollection();
    82         private DataSet dataSet;
    83         private final List<OsmPrimitive> vias = new ArrayList<OsmPrimitive>();
    84        
    85         public TurnRestrictionEditorModel(){
     65        private OsmDataLayer layer;
     66        private final TagEditorModel tagEditorModel = new TagEditorModel();
     67        private  RelationMemberEditorModel memberModel;
     68       
     69        /**
     70         * Creates a model in the context of a {@see OsmDataLayer}
     71         *
     72         * @param layer the layer. Must not be null.
     73         * @throws IllegalArgumentException thrown if {@code layer} is null
     74         */
     75        public TurnRestrictionEditorModel(OsmDataLayer layer) throws IllegalArgumentException{
     76                CheckParameterUtil.ensureParameterNotNull(layer, "layer");
     77                this.layer = layer;
     78                memberModel = new RelationMemberEditorModel(layer);
     79                memberModel.addTableModelListener(new RelationMemberModelListener());
    8680        }
    8781       
     
    9690        public void setTurnRestrictionLeg(TurnRestrictionLegRole role, Way way) {
    9791                CheckParameterUtil.ensureParameterNotNull(role, "role");
    98                 Way oldValue = null;
    9992                switch(role){
    100                 case FROM:
    101                         oldValue = this.from;
    102                         this.from = way;
     93                case FROM:
     94                        memberModel.setFromPrimitive(way);
    10395                        break;
    10496                case TO:
    105                         oldValue = this.to;
    106                         this.to = way;
     97                        memberModel.setToPrimitive(way);
    10798                        break;
    10899                }
     100        }       
    109101               
    110                 if (oldValue != way) {
    111                         setChanged();
    112                         notifyObservers();             
    113                 }
    114         }       
    115        
    116102        /**
    117103         * Sets the way participating in the turn restriction in a given role.
     
    132118                        throw new IllegalArgumentException(MessageFormat.format("parameter ''wayId'' of type {0} expected, got {1}", OsmPrimitiveType.WAY, wayId.getType()));
    133119                }
    134                
    135                 if (dataSet == null) {                 
    136                         throw new IllegalStateException("data set not initialized");                   
    137                 }
    138                 OsmPrimitive p = dataSet.getPrimitiveById(wayId);
     120
     121                OsmPrimitive p = layer.data.getPrimitiveById(wayId);
    139122                if (p == null) {
    140                         throw new IllegalStateException(MessageFormat.format("didn't find way with id {0} in dataset {1}", wayId, dataSet));                   
     123                        throw new IllegalStateException(MessageFormat.format("didn''t find way with id {0} in layer ''{1}''", wayId, layer.getName()));                 
    141124                }
    142125                setTurnRestrictionLeg(role, (Way)p);
     
    144127       
    145128        /**
    146          * Replies the turn restrictioin leg with role {@code role}
     129         * "Officially" a turn restriction should have exactly one member with
     130         * role {@see TurnRestrictionLegRole#FROM} and one member with role {@see TurnRestrictionLegRole#TO},
     131         * both referring to an OSM {@see Way}. In order to deals with turn restrictions where these
     132         * integrity constraints are violated, this model also supports relation with multiple or no
     133         * 'from' or 'to' members.
     134         *
     135         * Replies the turn restriction legs with role {@code role}. If no leg with this
     136         * role exists, an empty set is returned. If multiple legs exists, the set of referred
     137         * primitives is returned. 
    147138         *
    148139         * @param role the role. Must not be null.
    149          * @return the turn restrictioin leg with role {@code role}. null, if
     140         * @return the set of turn restriction legs with role {@code role}. The empty set, if
    150141         * no such turn restriction leg exists
    151142         * @throws IllegalArgumentException thrown if role is null
    152143         */
    153         public Way getTurnRestrictionLeg(TurnRestrictionLegRole role){
     144        public Set<OsmPrimitive>getTurnRestrictionLeg(TurnRestrictionLegRole role){
    154145                CheckParameterUtil.ensureParameterNotNull(role, "role");
    155146                switch(role){
    156                 case FROM: return from;
    157                 case TO: return to;
    158                 }
     147                case FROM: return memberModel.getFromPrimitives();
     148                case TO: return memberModel.getToPrimitives();
     149                }
     150                // should not happen
    159151                return null;
    160152        }
     
    167159         */
    168160        protected void initFromTurnRestriction(Relation turnRestriction) {
    169                 this.from = null;
    170                 this.to = null;
    171                 this.fromRelationMember = null;
    172                 this.toRelationMember = null;
    173                 this.tags = new TagCollection();
    174                 this.vias.clear();
    175                 if (turnRestriction == null) return;
    176                 for (RelationMember rm: turnRestriction.getMembers()) {
    177                         if (rm.getRole().equals("from") && rm.isWay()) {
    178                                 this.fromRelationMember = rm;
    179                                 this.from = rm.getWay();
    180                                 break;
    181                         }
    182                 }
    183                 for (RelationMember rm: turnRestriction.getMembers()) {
    184                         if (rm.getRole().equals("to") && rm.isWay()) {
    185                                 this.toRelationMember = rm;
    186                                 this.to = rm.getWay();
    187                                 break;
    188                         }
    189                 }
    190161               
    191                 for (RelationMember rm: turnRestriction.getMembers()) {
    192                         if (rm.getRole().equals("via")) {
    193                                 this.vias.add(rm.getMember());
    194                         }
    195                 }
     162                // populate the member model
     163                memberModel.populate(turnRestriction);
    196164               
    197165                // make sure we have a restriction tag
    198                 tags = TagCollection.from(turnRestriction);
     166                TagCollection tags = TagCollection.from(turnRestriction);
    199167                tags.setUniqueForKey("type", "restriction");
     168                tagEditorModel.initFromTags(tags);
    200169                               
    201170                setChanged();
     
    215184        public void populate(Relation turnRestriction) {
    216185                CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
    217                 if (turnRestriction.getDataSet() == null) {                     
     186                if (turnRestriction.getDataSet() != null && turnRestriction.getDataSet() != layer.data) {                       
    218187                        throw new IllegalArgumentException(
    219188                                // don't translate - it's a technical message
    220                                 MessageFormat.format("turnRestriction {0} must belong to a dataset", turnRestriction.getId())
     189                                MessageFormat.format("turnRestriction {0} must not belong to a different dataset than the dataset of layer ''{1}''", turnRestriction.getId(), layer.getName())
    221190                        );
    222191                }
    223                 this.dataSet = turnRestriction.getDataSet();
    224192                initFromTurnRestriction(turnRestriction);
    225193        }
    226194       
    227         /**
    228          * Populates the turn restriction editor model with a new turn restriction,
    229          * which isn't added to a data set yet. {@code ds} is the data set the turn
    230          * restriction is eventually being added to. Relation members of this
    231          * turn restriction must refer to objects in {@code ds}.
    232          * 
    233          * {@code turnRestriction} is an arbitrary relation. A tag type=restriction
    234          * isn't required. If it is missing, it is added here.  {@code turnRestriction}
    235          * is required to be a new turn restriction with a negative id. It must not be
    236          * part of a dataset yet
    237          *
    238          * @param turnRestriction the turn restriction. Must not be null. New turn restriction
    239          * required
    240          * @param ds the dataset. Must not be null.
    241          * @throws IllegalArgumentException thrown if turnRestriction is null
    242          * @throws IllegalArgumentException thrown if turnRestriction is part of a dataset
    243          * @throws IllegalArgumentException thrown if turnRestriction isn't a new turn restriction 
    244          */
    245         public void populate(Relation turnRestriction, DataSet ds) {
    246                 CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
    247                 CheckParameterUtil.ensureParameterNotNull(ds, "ds");
    248                 if (!turnRestriction.isNew()){                 
    249                         throw new IllegalArgumentException(
    250                                         // don't translate - it's a technical message
    251                                         MessageFormat.format("new turn restriction expected, got turn restriction with id {0}", turnRestriction.getId())
    252                         );
    253                 }
    254                 if (turnRestriction.getDataSet() != null) {
    255                         throw new IllegalArgumentException(
    256                     // don't translate - it's a technical message
    257                                         MessageFormat.format("expected turn restriction not assigned to a  dataset, got turn restriction with id {0} assigned to {1}", turnRestriction.getId(), turnRestriction.getDataSet())
    258                         );
    259                 }
    260                 for(RelationMember rm: turnRestriction.getMembers()) {
    261                         if (rm.getMember().getDataSet() != ds) {
    262                                 throw new IllegalArgumentException(
    263                             // don't translate - it's a technical message
    264                                                 MessageFormat.format("expected all members assigned to dataset {0}, got member {1} assigned to {2}", ds, rm, rm.getMember().getDataSet())
    265                                 );
    266                         }
    267                 }
    268                 this.dataSet = ds;
    269                 initFromTurnRestriction(turnRestriction);
    270         }
    271195       
    272196        /**
     
    277201        public void apply(Relation turnRestriction) {
    278202                CheckParameterUtil.ensureParameterNotNull(turnRestriction, "turnRestriction");
    279                 // apply the tags
     203               
     204                TagCollection tags = tagEditorModel.getTagCollection();
    280205                tags.applyTo(turnRestriction);
    281                
    282                 List<RelationMember> members = new ArrayList<RelationMember>();
    283                 if (from != null){
    284                         members.add(new RelationMember("from", from));
    285                 }
    286                 if (to != null) {
    287                         members.add(new RelationMember("to", to));                     
    288                 }
    289                 for(OsmPrimitive via: vias) {
    290                         members.add(new RelationMember("via", via));
    291                 }
    292                 turnRestriction.setMembers(members);
     206                memberModel.applyTo(turnRestriction);           
    293207        }
    294208       
     
    300214         */
    301215        public String getRestrictionTagValue() {
     216                TagCollection tags = tagEditorModel.getTagCollection();
    302217                if (!tags.hasTagsFor("restriction")) return null;
    303218                return tags.getJoinedValues("restriction");
     
    312227        public void setRestrictionTagValue(String value){
    313228                if (value == null || value.trim().equals("")) {
    314                         tags.removeByKey("restriction");
     229                        tagEditorModel.delete("restriction");                   
    315230                } else {
    316                         tags.setUniqueForKey("restriction", value.trim());
     231                        TagModel  tm = tagEditorModel.get("restriction");
     232                        if (tm != null){
     233                                tm.setValue(value);
     234                        } else {
     235                                tagEditorModel.add(new TagModel("restriction", value));
     236                        }
    317237                }
    318238                setChanged();
     
    327247         */
    328248        public List<OsmPrimitive> getVias() {
    329                 return Collections.unmodifiableList(vias);
     249                return memberModel.getVias();
    330250        }
    331251       
     
    342262         */
    343263        public void setVias(List<OsmPrimitive> vias) {
    344                 if (vias == null) {
    345                         this.vias.clear();
    346                         setChanged();
    347                         notifyObservers();
    348                         return;
    349                 }
    350                 for (OsmPrimitive p: vias) {
    351                         if (p == null)
    352                                 throw new IllegalArgumentException("a via object must not be null");
    353                         if (p.getDataSet() != dataSet)
    354                                 throw new IllegalArgumentException(MessageFormat.format("a via object must belong to dataset {1}, object {2} belongs to {3}", dataSet, p.getPrimitiveId(), p.getDataSet()));
    355                 }
    356                 this.vias.clear();
    357                 this.vias.addAll(vias);
    358                 setChanged();
    359                 notifyObservers();
    360         }
    361        
    362         /**
    363          * Replies the dataset this turn restriction editor model is
    364          * working with
    365          *
    366          * @return the dataset
    367          */
    368         public DataSet getDataSet() {
    369                 return this.dataSet;
    370         }
    371 
     264                memberModel.setVias(vias);
     265        }
     266       
     267        /**
     268         * Replies the layer in whose context this editor is working
     269         *
     270         * @return the layer in whose context this editor is working
     271         */
     272        public OsmDataLayer getLayer() {
     273                return layer;
     274        }
     275       
    372276        /**
    373277         * Registers this model with global event sources like {@see DatasetEventManager}
     
    383287                DatasetEventManager.getInstance().removeDatasetListener(this);
    384288        }
     289       
     290        /**
     291         * Replies the tag  editor model
     292         *
     293         * @return the tag  editor model
     294         */
     295        public TagEditorModel getTagEditorModel() {
     296                return tagEditorModel;
     297        }
     298       
     299        /**
     300         * Replies the editor model for the relation members
     301         *
     302         * @return the editor model for the relation members
     303         */
     304        public RelationMemberEditorModel getRelationMemberEditorModel() {
     305                return memberModel;
     306        }
    385307
    386308        /* ----------------------------------------------------------------------------------------- */
    387309        /* interface DataSetListener                                                                 */
    388         /* ----------------------------------------------------------------------------------------- */
    389        
     310        /* ----------------------------------------------------------------------------------------- */
    390311        protected boolean isAffectedByDataSetUpdate(DataSet ds, List<? extends OsmPrimitive> updatedPrimitives) {
    391                 if (ds != dataSet) return false;
     312                if (ds != layer.data) return false;
    392313                if (updatedPrimitives == null || updatedPrimitives.isEmpty()) return false;
    393                 if (from != null && updatedPrimitives.contains(from)) return true;
    394                 if (to != null && updatedPrimitives.contains(to)) return true;
    395                 for (OsmPrimitive via: vias){
    396                         if (updatedPrimitives.contains(via)) return true;
    397                 }
    398                 return false;
     314                Set<OsmPrimitive> myPrimitives = memberModel.getMemberPrimitives();
     315                int size1 = myPrimitives.size();
     316                myPrimitives.retainAll(updatedPrimitives);
     317                return size1 != myPrimitives.size();
    399318        }
    400319       
     
    402321                // refresh the views
    403322                setChanged();
    404                 notifyObservers();
    405                
     323                notifyObservers();             
    406324        }
    407325
     
    439357                }               
    440358        }       
     359       
     360        class RelationMemberModelListener implements TableModelListener {
     361                public void tableChanged(TableModelEvent e) {
     362                        setChanged();
     363                        notifyObservers();
     364                }               
     365        }       
    441366}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegEditor.java

    r20489 r20527  
    55import java.awt.BorderLayout;
    66import java.awt.Font;
    7 import java.awt.Image;
    87import java.awt.Toolkit;
    98import java.awt.datatransfer.Clipboard;
     
    2019import java.io.IOException;
    2120import java.util.Collections;
     21import java.util.HashSet;
    2222import java.util.List;
    2323import java.util.Observable;
    2424import java.util.Observer;
     25import java.util.Set;
    2526import java.util.logging.Logger;
    2627
     
    2829import javax.swing.Action;
    2930import javax.swing.BorderFactory;
    30 import javax.swing.ImageIcon;
    3131import javax.swing.JButton;
    3232import javax.swing.JComponent;
     
    3939import javax.swing.UIManager;
    4040
     41import org.openstreetmap.josm.data.osm.OsmPrimitive;
    4142import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    4243import org.openstreetmap.josm.data.osm.PrimitiveId;
    43 import org.openstreetmap.josm.data.osm.Way;
    4444import org.openstreetmap.josm.gui.DefaultNameFormatter;
    4545import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    5858 
    5959        private JLabel lblOsmObject;
    60         private Way way;
     60        private final Set<OsmPrimitive> legs = new HashSet<OsmPrimitive>();
    6161        private TurnRestrictionEditorModel model;
    6262        private TurnRestrictionLegRole role;
     
    140140
    141141        protected void refresh(){
    142                 Way newWay = model.getTurnRestrictionLeg(role);
    143                 way = newWay;
    144                 if (way == null) {
     142                legs.clear();
     143                legs.addAll(model.getTurnRestrictionLeg(role));
     144                if (legs.isEmpty()) {
    145145                        lblOsmObject.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC));
    146146                        lblOsmObject.setIcon(null);
    147147                        lblOsmObject.setText(tr("please select a way"));
    148148                        lblOsmObject.setToolTipText(null);
    149                 } else {
     149                } else if (legs.size() == 1){
     150                        OsmPrimitive leg = legs.iterator().next();
    150151                        lblOsmObject.setFont(UIManager.getFont("Label.font"));
    151152                        lblOsmObject.setIcon(ImageProvider.get("data", "way"));
    152                         lblOsmObject.setText(DefaultNameFormatter.getInstance().format(way));
    153                         lblOsmObject.setToolTipText(DefaultNameFormatter.getInstance().buildDefaultToolTip(way));
     153                        lblOsmObject.setText(leg.getDisplayName(DefaultNameFormatter.getInstance()));
     154                        lblOsmObject.setToolTipText(DefaultNameFormatter.getInstance().buildDefaultToolTip(leg));
     155                } else {
     156                        lblOsmObject.setFont(UIManager.getFont("Label.font").deriveFont(Font.ITALIC));
     157                        lblOsmObject.setIcon(null);
     158                        lblOsmObject.setText(tr("multiple objects with role ''{0}''",this.role.toString()));
     159                        lblOsmObject.setToolTipText(null);                     
    154160                }
    155161                renderColors();
     
    201207        /* ----------------------------------------------------------------------------- */
    202208        public List<PrimitiveId> getSelectedPrimitiveIds() {
    203                 if (way == null) return Collections.emptyList();
    204                 return Collections.singletonList(way.getPrimitiveId());
     209                if (legs.size() == 1) {
     210                        return Collections.singletonList(legs.iterator().next().getPrimitiveId());
     211                }
     212                return Collections.emptyList();
    205213        }
    206214       
     
    247255               
    248256                public void updateEnabledState() {
    249                         setEnabled(way != null);
     257                        setEnabled(legs.size()>0);
    250258                }
    251259        }
     
    284292                @Override
    285293                protected Transferable createTransferable(JComponent c) {
    286                         if (way == null) return null;
     294                        if (legs.size() != 1) return null;
    287295                        return super.createTransferable(c);
    288296                }
     
    326334               
    327335                public void updateEnabledState() {
    328                         setEnabled(way != null);
     336                        setEnabled(legs.size() == 1);
    329337                }
    330338        }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/ViaListModel.java

    r20489 r20527  
    171171                if (idsToInsert == null) return;
    172172                List<OsmPrimitive> primitives = new ArrayList<OsmPrimitive>(idsToInsert.size());
    173                 DataSet ds = model.getDataSet();
     173                DataSet ds = model.getLayer().data;
    174174                for(PrimitiveId id: idsToInsert){
    175175                        OsmPrimitive p = ds.getPrimitiveById(id);
Note: See TracChangeset for help on using the changeset viewer.