Changeset 1794 in josm for trunk/src


Ignore:
Timestamp:
2009-07-15T18:28:23+02:00 (15 years ago)
Author:
Gubaer
Message:

implemented #2664: Set the role for multiple members at the same time

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs/relation
Files:
2 edited

Legend:

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

    r1790 r1794  
    1313import java.awt.event.ComponentAdapter;
    1414import java.awt.event.ComponentEvent;
     15import java.awt.event.FocusAdapter;
     16import java.awt.event.FocusEvent;
    1517import java.awt.event.KeyEvent;
    1618import java.io.IOException;
     
    3032import javax.swing.JSplitPane;
    3133import javax.swing.JTable;
     34import javax.swing.JTextField;
    3235import javax.swing.KeyStroke;
    3336import javax.swing.ListSelectionModel;
     37import javax.swing.event.DocumentEvent;
     38import javax.swing.event.DocumentListener;
    3439import javax.swing.event.ListSelectionEvent;
    3540import javax.swing.event.ListSelectionListener;
     
    8893    private SelectionTableModel selectionTableModel;
    8994
     95    private JTextField tfRole;
     96
    9097    /**
    9198     * Creates a new relation editor for the given relation. The relation
     
    506513        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    507514        buttonPanel.add(new SideButton(new DownlaodAction()));
     515        buttonPanel.add(new JLabel(tr("Role:")));
     516        tfRole = new JTextField(10);
     517        tfRole.addFocusListener(
     518                new FocusAdapter() {
     519                    @Override
     520                    public void focusGained(FocusEvent e) {
     521                        tfRole.selectAll();
     522                    }
     523                }
     524        );
     525        buttonPanel.add(tfRole);
     526        SetRoleAction setRoleAction = new SetRoleAction();
     527        memberTableModel.getSelectionModel().addListSelectionListener(setRoleAction);
     528        buttonPanel.add(new SideButton(setRoleAction));
     529        tfRole.getDocument().addDocumentListener(setRoleAction);
    508530        return buttonPanel;
    509531    }
     
    862884        public void actionPerformed(ActionEvent e) {
    863885            downloadRelationMembers();
     886        }
     887    }
     888
     889    class SetRoleAction extends AbstractAction implements ListSelectionListener, DocumentListener{
     890        public SetRoleAction() {
     891            putValue(SHORT_DESCRIPTION,   tr("Sets a role for the selected members"));
     892            // FIXME: find better icon
     893            putValue(SMALL_ICON, ImageProvider.get("ok"));
     894            putValue(NAME, tr("Apply Role"));
     895            refreshEnabled();
     896        }
     897
     898        protected void refreshEnabled() {
     899            setEnabled(memberTable.getSelectedRowCount() > 0 && !tfRole.getText().equals(""));
     900        }
     901
     902        public void actionPerformed(ActionEvent e) {
     903            memberTableModel.updateRole(memberTable.getSelectedRows(), tfRole.getText());
     904        }
     905
     906        public void valueChanged(ListSelectionEvent e) {
     907            refreshEnabled();
     908        }
     909
     910        public void changedUpdate(DocumentEvent e) {
     911            refreshEnabled();
     912        }
     913
     914        public void insertUpdate(DocumentEvent e) {
     915            refreshEnabled();
     916        }
     917
     918        public void removeUpdate(DocumentEvent e) {
     919            refreshEnabled();
    864920        }
    865921    }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableModel.java

    r1793 r1794  
    326326        return count;
    327327    }
     328
     329    /**
     330     * updates the role of the members given by the indices in <code>idx</code>
     331     *
     332     * @param idx the array of indices
     333     * @param role the new role
     334     */
     335    public void updateRole(int [] idx, String role) {
     336        if (idx == null || idx.length == 0) return;
     337        for (int row: idx) {
     338            members.get(row).role = role;
     339        }
     340        fireTableDataChanged();
     341        for (int row: idx) {
     342            getSelectionModel().addSelectionInterval(row, row);
     343        }
     344    }
    328345}
Note: See TracChangeset for help on using the changeset viewer.