Changeset 2742 in josm for trunk


Ignore:
Timestamp:
2010-01-06T19:00:49+01:00 (10 years ago)
Author:
jttt
Message:

Fixed #4294 Tag selection after tag deletion behaviour

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r2741 r2742  
    5050import javax.swing.table.DefaultTableCellRenderer;
    5151import javax.swing.table.DefaultTableModel;
     52import javax.swing.table.TableModel;
    5253import javax.swing.text.JTextComponent;
    5354
     
    296297        }
    297298
    298         Main.main.getCurrentDataSet().fireSelectionChanged();
    299         selectionChanged(sel); // update whole table
    300         Main.parent.repaint(); // repaint all - drawing could have been changed
    301 
    302299        if(!key.equals(newkey)) {
    303300            for(int i=0; i < propertyTable.getRowCount(); i++)
     
    372369            return;
    373370        Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, value));
    374         Main.main.getCurrentDataSet().fireSelectionChanged();
    375         selectionChanged(sel); // update table
    376         Main.parent.repaint(); // repaint all - drawing could have been changed
    377 
    378371        btnAdd.requestFocusInWindow();
    379372    }
     
    696689    }
    697690
     691    private int findRow(TableModel model, Object value) {
     692        for (int i=0; i<model.getRowCount(); i++) {
     693            if (model.getValueAt(i, 0).equals(value))
     694                return i;
     695        }
     696        return -1;
     697    }
     698
    698699    public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
    699700        if (!isVisible())
     
    703704        if (propertyTable.getCellEditor() != null) {
    704705            propertyTable.getCellEditor().cancelCellEditing();
     706        }
     707
     708        String selectedTag = null;
     709        Relation selectedRelation = null;
     710        if (propertyTable.getSelectedRowCount() == 1) {
     711            selectedTag = (String)propertyData.getValueAt(propertyTable.getSelectedRow(), 0);
     712        }
     713        if (membershipTable.getSelectedRowCount() == 1) {
     714            selectedRelation = (Relation)membershipData.getValueAt(membershipTable.getSelectedRow(), 0);
    705715        }
    706716
     
    788798        propertyTable.getTableHeader().setVisible(hasSelection);
    789799        selectSth.setVisible(!hasSelection);
    790         if(hasTags) {
     800
     801        int selectedIndex;
     802        if (selectedTag != null && (selectedIndex = findRow(propertyData, selectedTag)) != -1) {
     803            propertyTable.changeSelection(selectedIndex, 0, false, false);
     804        } else if (selectedRelation != null && (selectedIndex = findRow(membershipData, selectedRelation)) != -1) {
     805            membershipTable.changeSelection(selectedIndex, 0, false, false);
     806        } else if(hasTags) {
    791807            propertyTable.changeSelection(0, 0, false, false);
    792808        } else if(hasMemberships) {
     
    825841        protected void deleteProperty(int row){
    826842            String key = propertyData.getValueAt(row, 0).toString();
     843
     844            String nextKey = null;
     845            int rowCount = propertyData.getRowCount();
     846            if (rowCount > 1) {
     847                nextKey = (String)propertyData.getValueAt((row + 1 < rowCount ? row + 1 : row - 1), 0);
     848            }
     849
    827850            Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected();
    828851            Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null));
    829             Main.main.getCurrentDataSet().fireSelectionChanged();
    830             selectionChanged(sel); // update table
    831 
    832             int rowCount = propertyTable.getRowCount();
    833             propertyTable.changeSelection((row < rowCount ? row : (rowCount-1)), 0, false, false);
     852
     853            membershipTable.clearSelection();
     854            if (nextKey != null) {
     855                propertyTable.changeSelection(findRow(propertyData, nextKey), 0, false, false);
     856            }
    834857        }
    835858
    836859        protected void deleteFromRelation(int row) {
    837860            Relation cur = (Relation)membershipData.getValueAt(row, 0);
     861
     862            Relation nextRelation = null;
     863            int rowCount = membershipTable.getRowCount();
     864            if (rowCount > 1) {
     865                nextRelation = (Relation)membershipData.getValueAt((row + 1 < rowCount ? row + 1 : row - 1), 0);
     866            }
    838867
    839868            ExtendedDialog ed = new ExtendedDialog(Main.parent,
     
    853882            }
    854883            Main.main.undoRedo.add(new ChangeCommand(cur, rel));
    855             Main.main.getCurrentDataSet().fireSelectionChanged();
    856             selectionChanged(sel); // update whole table
     884
     885            propertyTable.clearSelection();
     886            if (nextRelation != null) {
     887                membershipTable.changeSelection(findRow(membershipData, nextRelation), 0, false, false);
     888            }
    857889        }
    858890
Note: See TracChangeset for help on using the changeset viewer.