Ignore:
Timestamp:
2010-03-10T10:00:20+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4651: Ability to download incomplete relation from selection
fixed #4098: Popup Menu entry "download relation members" in relation dialog should be "download incomplete relation members"
fixed two NPEs in RelationListDialog and SelectionListDialog
refactored SelectionListDialog to support better user feedback (enabled/disabled buttons and menu items)
Finally removed the sort() method on DataSet, marked as FIXME since a long time.

CAVEAT: DataSet.getSelected() now returns an unmodifiable list instead of a copy of the selection list. This may lead to UnsupportedOperationExceptions in the next few days. I tried to make sure the JOSM core uses getSelected() only for reading, but I didn't check the plugins.

File:
1 edited

Legend:

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

    r3020 r3102  
    1515import java.util.Comparator;
    1616import java.util.HashSet;
     17import java.util.Iterator;
    1718import java.util.List;
    1819import java.util.Set;
     
    5253import org.openstreetmap.josm.gui.SideButton;
    5354import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
     55import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationMemberTask;
    5456import org.openstreetmap.josm.gui.dialogs.relation.DownloadRelationTask;
    5557import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
     
    234236
    235237        @Override public void mouseClicked(MouseEvent e) {
     238            if (Main.main.getEditLayer() == null) return;
    236239            if (e.getClickCount() == 2 && SwingUtilities.isLeftMouseButton(e)) {
    237240                if (e.isControlDown()) {
     
    254257        }
    255258        @Override public void mousePressed(MouseEvent e) {
     259            if (Main.main.getEditLayer() == null) return;
    256260            if (e.isPopupTrigger()) {
    257261                openPopup(e);
     
    259263        }
    260264        @Override public void mouseReleased(MouseEvent e) {
     265            if (Main.main.getEditLayer() == null) return;
    261266            if (e.isPopupTrigger()) {
    262267                openPopup(e);
     
    507512                    Main.map.mapView.getEditLayer())
    508513            );
     514        }
     515    }
     516
     517    /**
     518     * Action for downloading incomplete members of selected relations
     519     *
     520     */
     521    class DownloadSelectedIncompleteMembersAction extends AbstractAction implements ListSelectionListener{
     522        public DownloadSelectedIncompleteMembersAction() {
     523            putValue(SHORT_DESCRIPTION, tr("Download incomplete members of selected relations"));
     524            putValue(SMALL_ICON, ImageProvider.get("dialogs/relation", "downloadincompleteselected"));
     525            putValue(NAME, tr("Download incomplete members"));
     526            updateEnabledState();
     527        }
     528
     529        public Set<OsmPrimitive> buildSetOfIncompleteMembers(List<Relation> rels) {
     530            Set<OsmPrimitive> ret = new HashSet<OsmPrimitive>();
     531            for(Relation r: rels) {
     532                ret.addAll(r.getIncompleteMembers());
     533            }
     534            return ret;
     535        }
     536
     537        public void actionPerformed(ActionEvent e) {
     538            if (!isEnabled())
     539                return;
     540            List<Relation> rels = model.getSelectedRelationsWithIncompleteMembers();
     541            if (rels.isEmpty()) return;
     542            Main.worker.submit(new DownloadRelationMemberTask(
     543                    rels,
     544                    buildSetOfIncompleteMembers(rels),
     545                    Main.map.mapView.getEditLayer()
     546            ));
     547        }
     548
     549        protected void updateEnabledState() {
     550            setEnabled(!model.getSelectedRelationsWithIncompleteMembers().isEmpty());
     551        }
     552
     553        public void valueChanged(ListSelectionEvent e) {
     554            updateEnabledState();
    509555        }
    510556    }
     
    623669        }
    624670
     671        /**
     672         * Replies the list of selected relations with incomplete members
     673         *
     674         * @return the list of selected relations with incomplete members
     675         */
     676        public List<Relation> getSelectedRelationsWithIncompleteMembers() {
     677            List<Relation> ret = getSelectedNonNewRelations();
     678            Iterator<Relation> it = ret.iterator();
     679            while(it.hasNext()) {
     680                Relation r = it.next();
     681                if (!r.hasIncompleteMembers()) {
     682                    it.remove();
     683                }
     684            }
     685            return ret;
     686        }
     687
    625688        public Object getElementAt(int index) {
    626689            return relations.get(index);
     
    715778            add(downloadMembersAction);
    716779
     780            // -- download incomplete members action
     781            //
     782            DownloadSelectedIncompleteMembersAction downloadSelectedIncompleteMembers = new DownloadSelectedIncompleteMembersAction();
     783            displaylist.addListSelectionListener(downloadSelectedIncompleteMembers);
     784            add(downloadSelectedIncompleteMembers);
     785
     786            addSeparator();
     787
    717788            // -- select members action
    718789            //
Note: See TracChangeset for help on using the changeset viewer.