Ignore:
Timestamp:
2014-12-10T21:21:58+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #10830 - enable "show history" action in selection dialog when a single object is selected

File:
1 edited

Legend:

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

    r7750 r7781  
    8282public class SelectionListDialog extends ToggleDialog  {
    8383    private JList<OsmPrimitive> lstPrimitives;
    84     private DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
    85     private SelectionListModel model = new SelectionListModel(selectionModel);
    86 
    87     private SelectAction actSelect = new SelectAction();
    88     private SearchAction actSearch = new SearchAction();
    89     private ShowHistoryAction actShowHistory = new ShowHistoryAction();
    90     private ZoomToJOSMSelectionAction actZoomToJOSMSelection = new ZoomToJOSMSelectionAction();
    91     private ZoomToListSelection actZoomToListSelection = new ZoomToListSelection();
    92     private SelectInRelationListAction actSetRelationSelection = new SelectInRelationListAction();
    93     private EditRelationAction actEditRelationSelection = new EditRelationAction();
    94     private DownloadSelectedIncompleteMembersAction actDownloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
     84    private final DefaultListSelectionModel selectionModel = new DefaultListSelectionModel();
     85    private final SelectionListModel model = new SelectionListModel(selectionModel);
     86
     87    private final SelectAction actSelect = new SelectAction();
     88    private final SearchAction actSearch = new SearchAction();
     89    private final ShowHistoryAction actShowHistory = new ShowHistoryAction();
     90    private final ZoomToJOSMSelectionAction actZoomToJOSMSelection = new ZoomToJOSMSelectionAction();
     91    private final ZoomToListSelection actZoomToListSelection = new ZoomToListSelection();
     92    private final SelectInRelationListAction actSetRelationSelection = new SelectInRelationListAction();
     93    private final EditRelationAction actEditRelationSelection = new EditRelationAction();
     94    private final DownloadSelectedIncompleteMembersAction actDownloadSelIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
    9595
    9696    /** the popup menu and its handler */
     
    169169    public void showNotify() {
    170170        MapView.addEditLayerChangeListener(model);
     171        SelectionEventManager.getInstance().addSelectionListener(actShowHistory, FireMode.IN_EDT_CONSOLIDATED);
    171172        SelectionEventManager.getInstance().addSelectionListener(model, FireMode.IN_EDT_CONSOLIDATED);
    172173        DatasetEventManager.getInstance().addDatasetListener(model, FireMode.IN_EDT);
     
    185186        MapView.removeEditLayerChangeListener(actSearch);
    186187        MapView.removeEditLayerChangeListener(model);
     188        SelectionEventManager.getInstance().removeSelectionListener(actShowHistory);
    187189        SelectionEventManager.getInstance().removeSelectionListener(model);
    188190        DatasetEventManager.getInstance().removeDatasetListener(model);
     
    237239        handler.addAction(actEditRelationSelection);
    238240        handler.addSeparator();
    239         handler.addAction(actDownloadSelectedIncompleteMembers);
     241        handler.addAction(actDownloadSelIncompleteMembers);
    240242        return handler;
    241243    }
     
    348350     * The action for showing history information of the current history item.
    349351     */
    350     class ShowHistoryAction extends AbstractAction implements ListSelectionListener {
     352    class ShowHistoryAction extends AbstractAction implements ListSelectionListener, SelectionChangedListener {
    351353        /**
    352354         * Constructs a new {@code ShowHistoryAction}.
     
    356358            putValue(SHORT_DESCRIPTION, tr("Display the history of the selected objects."));
    357359            putValue(SMALL_ICON, ImageProvider.get("dialogs", "history"));
    358             updateEnabledState();
     360            updateEnabledState(model.getSize());
    359361        }
    360362
     
    362364        public void actionPerformed(ActionEvent e) {
    363365            Collection<OsmPrimitive> sel = model.getSelected();
    364             if (sel.isEmpty())return;
     366            if (sel.isEmpty() && model.getSize() != 1) {
     367                return;
     368            } else if (sel.isEmpty()) {
     369                sel = Collections.singleton(model.getElementAt(0));
     370            }
    365371            HistoryBrowserDialogManager.getInstance().showHistory(sel);
    366372        }
    367373
    368         protected void updateEnabledState() {
    369             setEnabled(!model.getSelected().isEmpty());
     374        protected void updateEnabledState(int osmSelectionSize) {
     375            // See #10830 - allow to click on history button is a single object is selected, even if not selected again in the list
     376            setEnabled(!model.getSelected().isEmpty() || osmSelectionSize == 1);
    370377        }
    371378
    372379        @Override
    373380        public void valueChanged(ListSelectionEvent e) {
    374             updateEnabledState();
     381            updateEnabledState(model.getSize());
     382        }
     383
     384        @Override
     385        public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) {
     386            updateEnabledState(newSelection.size());
    375387        }
    376388    }
Note: See TracChangeset for help on using the changeset viewer.