Ticket #2114: ImproveProperties.patch
File ImproveProperties.patch, 7.4 KB (added by , 15 years ago) |
---|
-
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
127 127 * @param row The row of the table from which the value is edited. 128 128 */ 129 129 void propertyEdit(int row) { 130 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 131 if (sel.isEmpty()) return; 132 130 133 String key = propertyData.getValueAt(row, 0).toString(); 131 134 objKey=key; 132 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 133 if (sel.isEmpty()) { 134 JOptionPane.showMessageDialog(Main.parent, tr("Please select the objects you want to change properties for.")); 135 return; 136 } 135 137 136 String msg = "<html>"+trn("This will change up to {0} object.", "This will change up to {0} objects.", sel.size(), sel.size())+"<br><br>("+tr("An empty value deletes the key.", key)+")</html>"; 138 137 139 138 JPanel panel = new JPanel(new BorderLayout()); … … 303 302 */ 304 303 void add() { 305 304 Collection<OsmPrimitive> sel = Main.ds.getSelected(); 306 if (sel.isEmpty()) { 307 JOptionPane.showMessageDialog(Main.parent, tr("Please select objects for which you want to change properties.")); 308 return; 309 } 305 if (sel.isEmpty()) return; 310 306 311 307 JPanel p = new JPanel(new BorderLayout()); 312 308 p.add(new JLabel("<html>"+trn("This will change up to {0} object.","This will change up to {0} objects.", sel.size(),sel.size())+"<br><br>"+tr("Please select a key")), … … 401 397 Main.main.undoRedo.add(new ChangePropertyCommand(sel, key, null)); 402 398 Main.ds.fireSelectionChanged(sel); 403 399 selectionChanged(sel); // update table 404 400 405 401 int rowCount = propertyTable.getRowCount(); 406 402 propertyTable.changeSelection((row < rowCount ? row : (rowCount-1)), 0, false, false); 407 403 } … … 438 434 439 435 public JComboBox taggingPresets = new JComboBox(); 440 436 437 /** 438 * The Add/Edit/Delete buttons (needed to be able to disable them) 439 */ 440 private final SideButton btnAdd; 441 private final SideButton btnEdit; 442 private final SideButton btnDel; 441 443 444 private final JLabel selectSth = new JLabel(tr("Please select the objects you want to change properties for.")); 445 442 446 /** 443 447 * Create a new PropertiesDialog 444 448 */ … … 547 551 // combine both tables and wrap them in a scrollPane 548 552 JPanel bothTables = new JPanel(); 549 553 bothTables.setLayout(new GridBagLayout()); 554 bothTables.add(selectSth, GBC.eol().fill().insets(10, 10, 10, 10)); 550 555 bothTables.add(propertyTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); 551 556 bothTables.add(propertyTable, GBC.eol().fill(GBC.BOTH)); 552 557 bothTables.add(membershipTable.getTableHeader(), GBC.eol().fill(GBC.HORIZONTAL)); … … 600 605 else 601 606 { 602 607 int sel = propertyTable.getSelectedRow(); 603 if (e.getActionCommand().equals("Edit")) { 604 if(propertyTable.getRowCount() == 1) 605 sel = 0; 606 if (sel == -1) 607 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to edit.")); 608 else 609 propertyEdit(sel); 610 } else if (e.getActionCommand().equals("Delete")) { 611 if (sel == -1) 612 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete.")); 613 else 614 delete(sel); 615 } 608 // Although we might edit/delete the wrong tag here, chances are still better 609 // than just displaying an error message (which always "fails"). 610 if (e.getActionCommand().equals("Edit")) 611 propertyEdit(sel >= 0 ? sel : 0); 612 else if (e.getActionCommand().equals("Delete")) 613 delete(sel >= 0 ? sel : 0); 616 614 } 617 615 } 618 616 }; 619 617 620 618 Shortcut s = Shortcut.registerShortcut("properties:add", tr("Add Properties"), KeyEvent.VK_B, 621 619 Shortcut.GROUP_MNEMONIC); 622 buttonPanel.add(new SideButton(marktr("Add"),"add","Properties", 623 tr("Add a new key/value pair to all objects"), s, buttonAction)); 620 this.btnAdd = new SideButton(marktr("Add"),"add","Properties", 621 tr("Add a new key/value pair to all objects"), s, buttonAction); 622 buttonPanel.add(this.btnAdd); 624 623 625 624 s = Shortcut.registerShortcut("properties:edit", tr("Edit Properties"), KeyEvent.VK_I, 626 625 Shortcut.GROUP_MNEMONIC); 627 buttonPanel.add(new SideButton(marktr("Edit"),"edit","Properties", 628 tr("Edit the value of the selected key for all objects"), s, buttonAction)); 626 this.btnEdit = new SideButton(marktr("Edit"),"edit","Properties", 627 tr("Edit the value of the selected key for all objects"), s, buttonAction); 628 buttonPanel.add(this.btnEdit); 629 629 630 630 s = Shortcut.registerShortcut("properties:delete", tr("Delete Properties"), KeyEvent.VK_Q, 631 631 Shortcut.GROUP_MNEMONIC); 632 buttonPanel.add(new SideButton(marktr("Delete"),"delete","Properties", 633 tr("Delete the selected key in all objects"), s, buttonAction)); 632 this.btnDel = new SideButton(marktr("Delete"),"delete","Properties", 633 tr("Delete the selected key in all objects"), s, buttonAction); 634 buttonPanel.add(this.btnDel); 634 635 add(buttonPanel, BorderLayout.SOUTH); 635 636 636 637 DataSet.selListeners.add(this); … … 651 652 propertyTable.getCellEditor().cancelCellEditing(); 652 653 653 654 // re-load property data 654 655 655 propertyData.setRowCount(0); 656 656 657 657 Map<String, Integer> keyCount = new HashMap<String, Integer>(); … … 680 680 propertyData.addRow(new Object[]{e.getKey(), e.getValue()}); 681 681 } 682 682 683 boolean hasTags = !newSelection.isEmpty() && propertyData.getRowCount() > 0; 684 boolean hasSelection = !newSelection.isEmpty(); 685 btnAdd.setEnabled(hasSelection); 686 btnEdit.setEnabled(hasTags); 687 btnDel.setEnabled(hasTags); 688 propertyTable.setVisible(hasSelection); 689 propertyTable.getTableHeader().setVisible(hasSelection); 690 selectSth.setVisible(!hasSelection); 691 if(hasTags) propertyTable.changeSelection(0, 0, false, false); 692 683 693 // re-load membership data 684 694 // this is rather expensive since we have to walk through all members of all existing relationships. 685 695 // could use back references here for speed if necessary. … … 707 717 } 708 718 709 719 membershipTable.getTableHeader().setVisible(membershipData.getRowCount() > 0); 720 membershipTable.setVisible(membershipData.getRowCount() > 0); 710 721 711 722 if(propertyData.getRowCount() != 0 || membershipData.getRowCount() != 0) { 712 setTitle(tr("Properties: {0} / Memberships: {1}", 723 setTitle(tr("Properties: {0} / Memberships: {1}", 713 724 propertyData.getRowCount(), membershipData.getRowCount()), true); 714 725 } else { 715 726 setTitle(tr("Properties / Memberships"), false);