Changeset 28416 in osm for applications/editors


Ignore:
Timestamp:
2012-05-31T13:45:56+02:00 (13 years ago)
Author:
simon04
Message:

JOSM/undelete: fix #josm7719

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/undelete/src/org/openstreetmap/josm/plugins/undelete/Undelete.java

    r28376 r28416  
    5757    public Undelete(PluginInformation info) {
    5858        super(info);
    59         Undelete = MainMenu.add(Main.main.menu.fileMenu, new UndeleteAction());
     59        Undelete = MainMenu.addAfter(Main.main.menu.fileMenu, new UndeleteAction(), false, Main.main.menu.updateModified);
    6060
    6161    }
     
    8383        gc.gridy = 0;
    8484        gc.weightx = 0;
    85         all.add(new JLabel(tr("Object type:")), gc);
    86         OsmPrimitiveTypesComboBox cbType = new OsmPrimitiveTypesComboBox();
    87         cbType.setToolTipText("Choose the OSM object type");
    88         cbType.setSelectedIndex(Main.pref.getInteger("undelete.lasttype", 0));
    89         gc.weightx = 1;
    90         all.add(cbType, gc);
    91         gc.gridy = 1;
    92         gc.weightx = 0;
    9385        all.add(new JLabel(tr("Object ID:")), gc);
    9486        OsmIdTextField tfId = new OsmIdTextField();
    9587        tfId.setText(Main.pref.get("undelete.osmid"));
    96         tfId.setToolTipText(tr("Enter the ID of the object that should be undeleted"));
     88        tfId.setToolTipText(tr("Enter the type and ID of the objects that should be undeleted, e.g., ''n1 w2''"));
    9789        // forward the enter key stroke to the undelete button
    9890        tfId.getKeymap().removeKeyStrokeBinding(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false));
    9991        gc.weightx = 1;
    10092        all.add(tfId, gc);
    101         gc.gridy = 2;
     93        gc.gridy++;
    10294        gc.fill = GridBagConstraints.BOTH;
    10395        gc.weighty = 1.0;
    10496        gc.weightx = 0;
    105         gc.gridy = 3;
     97        gc.gridy++;
    10698        all.add(layer, gc);
    10799        ExtendedDialog dialog = new ExtendedDialog(Main.parent,
     
    119111        dialog.showDialog();
    120112        if (dialog.getValue() != 1) return;
    121         Main.pref.putInteger("undelete.lasttype", cbType.getSelectedIndex());
    122113        Main.pref.put("undelete.newlayer", layer.isSelected());
    123114        Main.pref.put("undelete.osmid", tfId.getText());
    124         List<Long> ids=new ArrayList<Long>();
    125         for (PrimitiveId id: tfId.getIds()) {
    126                 ids.add(id.getUniqueId());
    127         }
    128         undelete(layer.isSelected(), cbType.getType(), ids, 0);
     115        undelete(layer.isSelected(), tfId.getIds(), 0);
    129116      }
    130117    }
     
    133120     * Download the given primitive.
    134121     */
    135     public void undelete(boolean newLayer, final OsmPrimitiveType type, final List<Long> ids, final long parent) {
     122    public void undelete(boolean newLayer, final List<PrimitiveId> ids, final long parent) {
    136123        OsmDataLayer tmpLayer = Main.main.getEditLayer();
    137124        if ((tmpLayer == null) || newLayer) {
     
    144131
    145132        HistoryLoadTask task  = new HistoryLoadTask();
    146         for (long id: ids)
    147         {
    148           task.add (id, type);
     133        for (PrimitiveId id: ids) {
     134            task.add(id);
    149135        }
    150136
     
    155141        Runnable r = new Runnable() {
    156142            @Override
    157                         public void run() {
     143            public void run() {
    158144              List<Node> nodes=new ArrayList<Node>();
    159               for (long id: ids)
     145              for (PrimitiveId pid: ids)
    160146              {
     147
     148                final Long id = pid.getUniqueId();
     149                final OsmPrimitiveType type = pid.getType();
    161150
    162151                History h = HistoryDataSet.getInstance().getHistory(id, type);
     
    171160                {
    172161                  // If the object is not deleted we get the real object
    173                   DownloadPrimitiveTask download=new DownloadPrimitiveTask(new SimplePrimitiveId(id, type), layer);
    174                   System.out.println(tr("Will get {0}", id));
     162                  DownloadPrimitiveTask download=new DownloadPrimitiveTask(pid, layer);
     163                  System.out.println(tr("Will get {0}", pid));
    175164                  download.run();
    176165
    177166
    178                   System.out.println(tr("Looking for {0}", id));
     167                  System.out.println(tr("Looking for {0}", pid));
    179168                  primitive=datas.getPrimitiveById(id, type);
    180                   System.out.println(tr("Found {0}", primitive.getId()));
     169                  System.out.println(tr("Found {0}", String.valueOf(primitive.getId())));
    181170                  if (parent>0 && type.equals(OsmPrimitiveType.NODE))
    182171                  {
     
    214203                    HistoryWay hWay = (HistoryWay) hPrimitive2;
    215204                    //System.out.println(tr("Primitive {0} version {1}: {2} nodes", hPrimitive2.getId(), hPrimitive2.getVersion(), hWay.getNumNodes()));
    216                     List<Long> nodeIds = hWay.getNodes();
    217                     undelete(false, OsmPrimitiveType.NODE, nodeIds, id);
     205                    List<PrimitiveId> nodeIds = new ArrayList<PrimitiveId>();
     206                    for (Long i: hWay.getNodes()) {
     207                        nodeIds.add(new SimplePrimitiveId(i, OsmPrimitiveType.NODE));
     208                    }
     209                    undelete(false, nodeIds, id);
    218210
    219211                    primitive=way;
     
    265257                //HistoryBrowserDialogManager.getInstance().show(h);
    266258              }
    267               if ((parent>0) && (type.equals(OsmPrimitiveType.NODE)))
     259              if (parent>0 && !ids.isEmpty() && ids.iterator().next().getType().equals(OsmPrimitiveType.NODE))
    268260              {
    269261                Way parentWay=(Way)datas.getPrimitiveById(parent, OsmPrimitiveType.WAY);
Note: See TracChangeset for help on using the changeset viewer.