Changeset 2613 in josm for trunk


Ignore:
Timestamp:
2009-12-11T23:07:59+01:00 (14 years ago)
Author:
Gubaer
Message:

new: global in-memory cache for downloaded changesets
new: toggle dialog for changesets
new: downloading of changesets (currently without changeset content, will follow later)

Location:
trunk
Files:
14 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r2512 r2613  
    188188            map.mapView.removeLayer(layer);
    189189            if (map.mapView.getAllLayers().isEmpty()) {
     190                map.tearDownDialogsPane();
    190191                setMapFrame(null);
    191192            }
  • trunk/src/org/openstreetmap/josm/actions/CloseChangesetAction.java

    r2512 r2613  
    22package org.openstreetmap.josm.actions;
    33
     4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    45import static org.openstreetmap.josm.tools.I18n.tr;
    5 import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
    66
    77import java.awt.event.ActionEvent;
     
    1616import org.openstreetmap.josm.Main;
    1717import org.openstreetmap.josm.data.osm.Changeset;
     18import org.openstreetmap.josm.data.osm.ChangesetCache;
    1819import org.openstreetmap.josm.data.osm.UserInfo;
    1920import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     
    4950    }
    5051
    51     protected void onPostDownloadOpenChangesets(DownloadOpenChangesetsTask task) {
    52         if (task.isCancelled() || task.getLastException() != null) return;
    53 
    54         List<Changeset> openChangesets = task.getChangesets();
     52    protected void onPostDownloadOpenChangesets() {
     53        List<Changeset> openChangesets = ChangesetCache.getInstance().getOpenChangesets();
    5554        if (openChangesets.isEmpty()) {
    5655            JOptionPane.showMessageDialog(
     
    105104                                ExceptionDialogUtil.explainException(lastException);
    106105                            }
    107                             onPostDownloadOpenChangesets(DownloadOpenChangesetsTask.this);
     106                            ChangesetCache.getInstance().update(changesets);
     107                            if (!cancelled && lastException == null) {
     108                                onPostDownloadOpenChangesets();
     109                            }
    108110                        }
    109111                    }
     
    146148        }
    147149
    148         public List<Changeset> getChangesets() {
    149             return changesets;
    150         }
    151 
    152150        public Exception getLastException() {
    153151            return lastException;
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r2604 r2613  
    77import java.util.Map;
    88
     9import org.openstreetmap.josm.data.Bounds;
    910import org.openstreetmap.josm.data.coor.LatLon;
    1011import org.openstreetmap.josm.data.osm.visitor.Visitor;
     
    6869            setId(other.getId());
    6970            this.incomplete = true;
     71            this.tags = new HashMap<String, String>();
    7072        } else {
    71             cloneFrom(other);
     73            this.id = other.id;
     74            mergeFrom(other);
    7275            this.incomplete = false;
    7376        }
    74     }
    75 
    76     public void cloneFrom(Changeset other) {
    77         setId(other.getId());
    78         setUser(other.getUser());
    79         setCreatedAt(other.getCreatedAt());
    80         setClosedAt(other.getClosedAt());
    81         setMin(other.getMin());
    82         setMax(other.getMax());
    83         setKeys(other.getKeys());
    84         setOpen(other.isOpen());
    8577    }
    8678
     
    152144    public LatLon getMax() {
    153145        return max;
     146    }
     147
     148    public Bounds getBounds() {
     149        if (min != null && max != null)
     150            return new Bounds(min,max);
     151        return null;
    154152    }
    155153
     
    237235        if (id > 0)
    238236            return prime * result + getClass().hashCode();
    239         result = prime * result + ((closedAt == null) ? 0 : closedAt.hashCode());
    240         result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode());
    241         result = prime * result + ((max == null) ? 0 : max.hashCode());
    242         result = prime * result + ((min == null) ? 0 : min.hashCode());
    243         result = prime * result + (open ? 1231 : 1237);
    244         result = prime * result + ((tags == null) ? 0 : tags.hashCode());
    245         result = prime * result + ((user == null) ? 0 : user.hashCode());
    246         return result;
     237        else
     238            return super.hashCode();
    247239    }
    248240
     
    258250        if (this.id > 0 && other.id == this.id)
    259251            return true;
    260         if (closedAt == null) {
    261             if (other.closedAt != null)
    262                 return false;
    263         } else if (!closedAt.equals(other.closedAt))
    264             return false;
    265         if (createdAt == null) {
    266             if (other.createdAt != null)
    267                 return false;
    268         } else if (!createdAt.equals(other.createdAt))
    269             return false;
    270         if (id != other.id)
    271             return false;
    272         if (max == null) {
    273             if (other.max != null)
    274                 return false;
    275         } else if (!max.equals(other.max))
    276             return false;
    277         if (min == null) {
    278             if (other.min != null)
    279                 return false;
    280         } else if (!min.equals(other.min))
    281             return false;
    282         if (open != other.open)
    283             return false;
    284         if (tags == null) {
    285             if (other.tags != null)
    286                 return false;
    287         } else if (!tags.equals(other.tags))
    288             return false;
    289         if (user == null) {
    290             if (other.user != null)
    291                 return false;
    292         } else if (!user.equals(other.user))
    293             return false;
    294         return true;
     252        return this == obj;
    295253    }
    296254
     
    318276        this.min = other.min;
    319277        this.max = other.max;
    320         this.tags.clear();
    321         this.tags.putAll(other.tags);
     278        this.tags = new HashMap<String, String>(other.tags);
     279        this.incomplete = other.incomplete;
    322280    }
    323281}
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r2610 r2613  
    2020
    2121import org.openstreetmap.josm.data.SelectionChangedListener;
     22
    2223
    2324/**
  • trunk/src/org/openstreetmap/josm/gui/MapFrame.java

    r2566 r2613  
    44
    55import java.awt.BorderLayout;
    6 import java.awt.Component;
    76import java.awt.Container;
    87import java.awt.Dimension;
     8import java.awt.event.MouseWheelEvent;
    99import java.awt.event.MouseWheelListener;
    10 import java.awt.event.MouseWheelEvent;
    1110import java.util.ArrayList;
    1211import java.util.List;
     
    1615import javax.swing.BoxLayout;
    1716import javax.swing.ButtonGroup;
     17import javax.swing.JPanel;
    1818import javax.swing.JSplitPane;
    19 import javax.swing.JPanel;
    2019import javax.swing.JToolBar;
    2120import javax.swing.border.Border;
     21import javax.swing.plaf.basic.BasicSplitPaneDivider;
    2222import javax.swing.plaf.basic.BasicSplitPaneUI;
    23 import javax.swing.plaf.basic.BasicSplitPaneDivider;
    2423
    2524import org.openstreetmap.josm.Main;
     
    3029import org.openstreetmap.josm.actions.mapmode.SelectAction;
    3130import org.openstreetmap.josm.actions.mapmode.ZoomAction;
     31import org.openstreetmap.josm.gui.dialogs.ChangesetDialog;
    3232import org.openstreetmap.josm.gui.dialogs.CommandStackDialog;
    3333import org.openstreetmap.josm.gui.dialogs.ConflictDialog;
     
    126126        splitPane.setBorder(null);
    127127        splitPane.setUI(new BasicSplitPaneUI() {
     128            @Override
    128129            public BasicSplitPaneDivider createDefaultDivider() {
    129130                return new BasicSplitPaneDivider(this) {
     131                    @Override
    130132                    public void setBorder(Border b) {
    131133                    }
     
    148150        addToggleDialog(new HistoryDialog());
    149151        addToggleDialog(new SelectionListDialog());
    150         if(Main.pref.getBoolean("displayfilter", false))
     152        if(Main.pref.getBoolean("displayfilter", false)) {
    151153            addToggleDialog(new FilterDialog());
     154        }
    152155        addToggleDialog(new UserListDialog());
    153156        addToggleDialog(conflictDialog = new ConflictDialog());
    154157        addToggleDialog(new CommandStackDialog(this));
    155158        addToggleDialog(relationListDialog = new RelationListDialog());
     159        addToggleDialog(new ChangesetDialog(this));
    156160
    157161        // status line below the map
     
    209213    public void initializeDialogsPane() {
    210214        dialogsPanel.initialize(allDialogs);
     215    }
     216
     217    /**
     218     *
     219     */
     220    public void tearDownDialogsPane() {
     221        dialogsPanel.tearDown();
    211222    }
    212223
  • trunk/src/org/openstreetmap/josm/gui/PleaseWaitRunnable.java

    r2512 r2613  
    22package org.openstreetmap.josm.gui;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    64import java.awt.EventQueue;
    7 import java.io.FileNotFoundException;
    85import java.io.IOException;
     6import java.util.logging.Logger;
    97
    108import javax.swing.SwingUtilities;
     
    2321 */
    2422public abstract class PleaseWaitRunnable implements Runnable, CancelListener {
     23    private final static Logger logger = Logger.getLogger(PleaseWaitRunnable.class.getName());
    2524
    2625    private boolean cancelled = false;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/DialogsPanel.java

    r2566 r2613  
    3333
    3434    public boolean initialized = false; // read only from outside
    35    
     35
    3636    public void initialize(List<ToggleDialog> pAllDialogs) {
    3737        if (initialized)
     
    4343            add(pAllDialogs.get(i), false);
    4444        }
    45        
     45
    4646        this.add(mSpltPane);
    4747        reconstruct(Action.ELEMENT_SHRINKS, null);
    4848    }
    4949
     50    /**
     51     * Invoke before the panel is discarded. This will in turn call {@see ToggleDialog#tearDown()}
     52     * on every dialog.
     53     *
     54     */
     55    public void tearDown() {
     56        for(ToggleDialog dialog: allDialogs) {
     57            dialog.tearDown();
     58        }
     59    }
     60
    5061    public void add(ToggleDialog dlg) {
    5162        add(dlg, true);
    5263    }
    53    
     64
    5465    public void add(ToggleDialog dlg, boolean doReconstruct) {
    5566        allDialogs.add(dlg);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r2602 r2613  
    6868     */
    6969    protected boolean isCollapsed;
    70    
     70
    7171    /** the preferred height if the toggle dialog is expanded */
    7272    private int preferredHeight;
     
    120120        isDocked = Main.pref.getBoolean(preferencePrefix+".docked", true);
    121121        isCollapsed = Main.pref.getBoolean(preferencePrefix+".minimized", false);
    122         //System.err.println(name+": showing="+isShowing+" docked="+isDocked+" collapsed="+isCollapsed);
    123122    }
    124123
     
    214213     */
    215214    public void collapse() {
    216 //        if (isShowing && isDocked && !isCollapsed) {
     215        //        if (isShowing && isDocked && !isCollapsed) {
    217216        if (isDialogInDefaultView()) {
    218217            setContentVisible(false);
     
    231230     */
    232231    protected void expand() {
    233 //        if (isShowing && isDocked && isCollapsed) {
     232        //        if (isShowing && isDocked && isCollapsed) {
    234233        if (isDialogInCollapsedView()) {
    235234            setContentVisible(true);
     
    529528
    530529    /**
    531     * Change the Geometry of the detached dialog to better fit the content.
    532     */
     530     * Change the Geometry of the detached dialog to better fit the content.
     531     */
    533532    protected Rectangle getDetachedGeometry(Rectangle last) {
    534533        return last;
     
    552551        return true;
    553552    }
    554    
     553
    555554    /**
    556555     * primitive stateChangedListener for subclasses
     
    559558    }
    560559
    561     /***
    562      * End of override hooks
    563      **/
     560    /**
     561     * This method is called by hosting panel before the panel with the toggle dialogs
     562     * and the toggle dialogs themself are discared, for instance because no layer is
     563     * left in JOSM and  the main screen turns from the map editor to the MOTD panel.
     564     *
     565     * Override in subclasses to unregister as listener. After tearDown() is invoked
     566     * the dialog should be registered as listener.
     567     *
     568     * The default implementation is empty.
     569     */
     570    public void tearDown() {}
    564571}
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java

    r2599 r2613  
    2626import org.openstreetmap.josm.Main;
    2727import org.openstreetmap.josm.data.osm.Changeset;
     28import org.openstreetmap.josm.data.osm.ChangesetCache;
    2829import org.openstreetmap.josm.gui.JMultilineLabel;
    2930import org.openstreetmap.josm.tools.ImageProvider;
     
    104105        gc.weightx = 1.0;
    105106        model = new OpenChangesetComboBoxModel();
     107        ChangesetCache.getInstance().addChangesetCacheListener(model);
    106108        cbOpenChangesets = new JComboBox(model);
    107109        cbOpenChangesets.setToolTipText("Select an open changeset");
     
    171173    }
    172174
     175    public void setSelectedChangesetForNextUpload(Changeset cs) {
     176        int idx  = model.getIndexOf(cs);
     177        if (idx >=0) {
     178            rbExisting.setSelected(true);
     179            model.setSelectedItem(cs);
     180        }
     181    }
     182
    173183    /**
    174184     * Replies the currently selected changeset. null, if no changeset is
     
    203213    }
    204214
    205     public void updateListOfChangesetsAfterUploadOperation(Changeset cs) {
    206         if (cs == null || cs.isNew()) {
    207             model.setSelectedItem(null);
    208         } else if (cs.isOpen()){
    209             if (cs.get("created_by") == null) {
    210                 cs.put("created_by", getDefaultCreatedBy());
    211             }
    212             model.addOrUpdate(cs);
    213             cs = model.getChangesetById(cs.getId());
    214             model.setSelectedItem(cs);
    215             rbExisting.setSelected(true);
    216         } else if (!cs.isOpen()){
    217             removeChangeset(cs);
    218             rbUseNew.setSelected(true);
    219         }
    220     }
    221 
    222     /**
    223      * Remove a changeset from the list of open changeset
    224      *
    225      * @param cs the changeset to be removed. Ignored if null.
    226      */
    227     public void removeChangeset(Changeset cs) {
    228         if (cs ==  null) return;
    229         model.removeChangeset(cs);
    230         refreshGUI();
    231     }
    232 
    233215    /* ---------------------------------------------------------------------------- */
    234216    /* Interface ListDataListener                                                   */
     
    256238            if (rbExisting.isSelected()) {
    257239                firePropertyChange(SELECTED_CHANGESET_PROP, null, cs);
     240                if (cs == null) {
     241                    rbUseNew.setSelected(true);
     242                }
    258243            }
    259244        }
  • trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetDialog.java

    r2512 r2613  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.io;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.BorderLayout;
     
    68import java.awt.FlowLayout;
    79import java.awt.event.ActionEvent;
     10import java.awt.event.KeyEvent;
     11import java.awt.event.WindowAdapter;
     12import java.awt.event.WindowEvent;
    813import java.util.ArrayList;
    914import java.util.Collection;
     
    1217import javax.swing.BorderFactory;
    1318import javax.swing.DefaultListModel;
     19import javax.swing.JComponent;
    1420import javax.swing.JDialog;
    1521import javax.swing.JLabel;
     
    1824import javax.swing.JPanel;
    1925import javax.swing.JScrollPane;
     26import javax.swing.KeyStroke;
    2027import javax.swing.event.ListSelectionEvent;
    2128import javax.swing.event.ListSelectionListener;
     
    2633import org.openstreetmap.josm.tools.ImageProvider;
    2734import org.openstreetmap.josm.tools.WindowGeometry;
    28 
    29 import static org.openstreetmap.josm.tools.I18n.tr;
    3035
    3136/**
     
    4146    /** the list model */
    4247    private DefaultListModel model;
     48
     49    private SideButton btnCloseChangesets;
    4350
    4451    protected JPanel buildTopPanel() {
     
    6673        CloseAction closeAction = new CloseAction();
    6774        lstOpenChangesets.addListSelectionListener(closeAction);
    68         pnl.add(new SideButton(closeAction));
    69         pnl.add(new SideButton(new CancelAction()));
     75        pnl.add(btnCloseChangesets = new SideButton(closeAction));
     76        btnCloseChangesets.setFocusable(true);
     77        btnCloseChangesets.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter");
     78        btnCloseChangesets.getActionMap().put("enter",closeAction);
     79
     80        // -- cancel action
     81        SideButton btn;
     82        pnl.add(btn = new SideButton(new CancelAction()));
     83        btn.setFocusable(true);
    7084        return pnl;
    7185    }
     
    7791        getContentPane().add(buildCenterPanel(), BorderLayout.CENTER);
    7892        getContentPane().add(buildSouthPanel(), BorderLayout.SOUTH);
     93
     94        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0), "escape");
     95        getRootPane().getActionMap().put("escape", new CancelAction());
     96        addWindowListener(new WindowEventHandler());
    7997    }
    8098
     
    127145        }
    128146
    129         public void actionPerformed(ActionEvent e) {
     147        public void cancel() {
    130148            setCanceled(true);
    131149            setVisible(false);
    132150        }
     151
     152        public void actionPerformed(ActionEvent e) {
     153            cancel();
     154        }
     155    }
     156
     157    class WindowEventHandler extends WindowAdapter {
     158
     159        @Override
     160        public void windowActivated(WindowEvent arg0) {
     161            btnCloseChangesets.requestFocusInWindow();
     162        }
     163
     164        @Override
     165        public void windowClosing(WindowEvent arg0) {
     166            new CancelAction().cancel();
     167        }
     168
    133169    }
    134170
     
    162198        for (Changeset cs: changesets) {
    163199            model.addElement(cs);
     200        }
     201        if (!changesets.isEmpty()) {
     202            lstOpenChangesets.getSelectionModel().setSelectionInterval(0, changesets.size()-1);
    164203        }
    165204    }
  • trunk/src/org/openstreetmap/josm/gui/io/CloseChangesetTask.java

    r2599 r2613  
    1111
    1212import org.openstreetmap.josm.data.osm.Changeset;
     13import org.openstreetmap.josm.data.osm.ChangesetCache;
    1314import org.openstreetmap.josm.gui.ExceptionDialogUtil;
    1415import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    5960                new Runnable() {
    6061                    public void run() {
    61                         for (Changeset cs: closedChangesets) {
    62                             UploadDialog.getUploadDialog().updateListOfChangesetsAfterUploadOperation(cs);
    63                         }
     62                        ChangesetCache.getInstance().update(closedChangesets);
    6463                    }
    6564                }
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadOpenChangesetsTask.java

    r2599 r2613  
    1212import org.openstreetmap.josm.Main;
    1313import org.openstreetmap.josm.data.osm.Changeset;
     14import org.openstreetmap.josm.data.osm.ChangesetCache;
    1415import org.openstreetmap.josm.data.osm.UserInfo;
    1516import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     
    7071                new Runnable() {
    7172                    public void run() {
    72                         model.setChangesets(changesets);
     73                        ChangesetCache.getInstance().update(changesets);
    7374                    }
    7475                }
  • trunk/src/org/openstreetmap/josm/gui/io/OpenChangesetComboBoxModel.java

    r2599 r2613  
    22package org.openstreetmap.josm.gui.io;
    33
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    5 
    64import java.util.ArrayList;
    7 import java.util.Collection;
    85import java.util.List;
    96
     
    118
    129import org.openstreetmap.josm.data.osm.Changeset;
     10import org.openstreetmap.josm.data.osm.ChangesetCache;
     11import org.openstreetmap.josm.data.osm.ChangesetCacheEvent;
     12import org.openstreetmap.josm.data.osm.ChangesetCacheListener;
    1313
    1414/**
     
    1616 *
    1717 */
    18 public class OpenChangesetComboBoxModel extends DefaultComboBoxModel {
     18public class OpenChangesetComboBoxModel extends DefaultComboBoxModel implements ChangesetCacheListener {
    1919    private List<Changeset> changesets;
    2020    private long uid;
     
    3232    }
    3333
    34     protected void internalAddOrUpdate(Changeset cs) {
    35         Changeset other = getChangesetById(cs.getId());
    36         if (other != null) {
    37             cs.cloneFrom(other);
     34    public void refresh() {
     35        changesets.clear();
     36        changesets.addAll(ChangesetCache.getInstance().getOpenChangesets());
     37        fireContentsChanged(this, 0, getSize());
     38        int idx = changesets.indexOf(selectedChangeset);
     39        if (idx < 0) {
     40            setSelectedItem(null);
    3841        } else {
    39             changesets.add(cs);
    40         }
    41     }
    42 
    43     public void addOrUpdate(Changeset cs) {
    44         if (cs.getId() <= 0 )
    45             throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", cs.getId()));
    46         internalAddOrUpdate(cs);
    47         fireContentsChanged(this, 0, getSize());
    48     }
    49 
    50     public void remove(long id) {
    51         Changeset cs = getChangesetById(id);
    52         if (cs != null) {
    53             changesets.remove(cs);
    54         }
    55         fireContentsChanged(this, 0, getSize());
    56     }
    57 
    58     public void setChangesets(Collection<Changeset> changesets) {
    59         this.changesets.clear();
    60         if (changesets != null) {
    61             for (Changeset cs: changesets) {
    62                 internalAddOrUpdate(cs);
    63             }
    64         }
    65         fireContentsChanged(this, 0, getSize());
    66         if (getSelectedItem() == null && !this.changesets.isEmpty()) {
    67             setSelectedItem(this.changesets.get(0));
    68         } else if (getSelectedItem() != null) {
    69             if (changesets.contains(getSelectedItem())) {
    70                 setSelectedItem(getSelectedItem());
    71             } else if (!this.changesets.isEmpty()){
    72                 setSelectedItem(this.changesets.get(0));
    73             } else {
    74                 setSelectedItem(null);
    75             }
    76         } else {
    77             setSelectedItem(null);
     42            setSelectedItem(changesets.get(idx));
    7843        }
    7944    }
     
    9560    }
    9661
    97     public void removeChangeset(Changeset cs) {
    98         if (cs == null) return;
    99         changesets.remove(cs);
    100         if (selectedChangeset == cs) {
    101             selectFirstChangeset();
    102         }
    103         fireContentsChanged(this, 0, getSize());
     62    /* ------------------------------------------------------------------------------------ */
     63    /* ChangesetCacheListener                                                               */
     64    /* ------------------------------------------------------------------------------------ */
     65    public void changesetCacheUpdated(ChangesetCacheEvent event) {
     66        refresh();
    10467    }
     68
    10569    /* ------------------------------------------------------------------------------------ */
    10670    /* ComboBoxModel                                                                        */
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r2599 r2613  
    289289    }
    290290
     291    public void setSelectedChangesetForNextUpload(Changeset cs) {
     292        pnlChangesetManagement.setSelectedChangesetForNextUpload(cs);
     293    }
     294
    291295    /**
    292296     * Replies the {@see UploadStrategySpecification} the user entered in the dialog.
     
    298302        spec.setCloseChangesetAfterUpload(pnlChangesetManagement.isCloseChangesetAfterUpload());
    299303        return spec;
    300     }
    301 
    302     /**
    303      * Sets or updates the changeset cs.
    304      * If cs is null, does nothing.
    305      * If cs.getId() == 0 does nothing.
    306      * If cs.getId() > 0 and cs is open, adds it to the list of open
    307      * changesets. If it is closed, removes it from the list of open
    308      * changesets.
    309      *
    310      * @param cs the changeset
    311      */
    312     public void updateListOfChangesetsAfterUploadOperation(Changeset cs) {
    313         pnlChangesetManagement.updateListOfChangesetsAfterUploadOperation(cs);
    314     }
    315 
    316     /**
    317      * Removes <code>cs</code> from the list of open changesets in the upload
    318      * dialog
    319      *
    320      * @param cs the changeset. Ignored if null.
    321      */
    322     public void removeChangeset(Changeset cs) {
    323         if (cs == null) return;
    324         pnlChangesetManagement.removeChangeset(cs);
    325304    }
    326305
  • trunk/src/org/openstreetmap/josm/gui/io/UploadPrimitivesTask.java

    r2599 r2613  
    1818import org.openstreetmap.josm.data.APIDataSet;
    1919import org.openstreetmap.josm.data.osm.Changeset;
     20import org.openstreetmap.josm.data.osm.ChangesetCache;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2122import org.openstreetmap.josm.gui.DefaultNameFormatter;
     
    139140        // make sure the current changeset is removed from the upload dialog.
    140141        //
    141         UploadDialog.getUploadDialog().removeChangeset(changeset);
     142        ChangesetCache.getInstance().update(changeset);
    142143        Changeset newChangeSet = new Changeset();
    143144        newChangeSet.setKeys(this.changeset.getKeys());
     
    211212                layer.fireDataChange();
    212213                layer.onPostUploadToServer();
    213 
    214                 // make sure the upload dialog lists all known open changesets
    215                 //
    216                 if (lastException != null && lastException instanceof ChangesetClosedException) {
    217                     UploadDialog.getUploadDialog().removeChangeset(changeset);
    218                 } else {
    219                     UploadDialog.getUploadDialog().updateListOfChangesetsAfterUploadOperation(changeset);
    220                 }
     214                ChangesetCache.getInstance().update(changeset);
    221215            }
    222216        };
     
    298292        if (uploadCancelled)
    299293            return;
    300         if (lastException == null)
    301             return;
    302294
    303295        // depending on the success of the upload operation and on the policy for
     
    309301        Runnable r = new Runnable() {
    310302            public void run() {
     303                // if the changeset is still open after this upload we want it to
     304                // be selected on the next upload
     305                //
     306                ChangesetCache.getInstance().update(changeset);
     307                if (changeset != null && changeset.isOpen()) {
     308                    UploadDialog.getUploadDialog().setSelectedChangesetForNextUpload(changeset);
     309                }
     310                if (lastException == null)
     311                    return;
    311312                if (lastException instanceof ChangesetClosedException) {
    312313                    ChangesetClosedException e = (ChangesetClosedException)lastException;
     
    337338            }
    338339        };
    339         SwingUtilities.invokeLater(r);
     340        if (SwingUtilities.isEventDispatchThread()) {
     341            r.run();
     342        } else {
     343            SwingUtilities.invokeLater(r);
     344        }
    340345    }
    341346
  • trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java

    r2512 r2613  
    22package org.openstreetmap.josm.io;
    33
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
     6
    47import java.io.InputStream;
     8import java.util.ArrayList;
     9import java.util.Collection;
     10import java.util.Collections;
     11import java.util.Iterator;
    512import java.util.List;
    613
     
    916import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1017import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    11 import static org.openstreetmap.josm.tools.I18n.tr;
    1218
    1319/**
     
    6874
    6975    /**
    70      * Reads teh changeset with id <code>id</code> from the server
     76     * Reads the changeset with id <code>id</code> from the server
    7177     *
    7278     * @param id  the changeset id. id > 0 required.
     
    104110
    105111    /**
     112     * Reads the changeset with id <code>id</code> from the server
     113     *
     114     * @param ids  the list of ids. Ignored if null. Only load changesets for ids > 0.
     115     * @param monitor the progress monitor. Set to {@see NullProgressMonitor#INSTANCE} if null
     116     * @return the changeset read
     117     * @throws OsmTransferException thrown if something goes wrong
     118     * @throws IllegalArgumentException if id <= 0
     119     */
     120    public List<Changeset> readChangesets(Collection<Integer> ids, ProgressMonitor monitor) throws OsmTransferException {
     121        if (ids == null)
     122            return Collections.emptyList();
     123        if (monitor == null) {
     124            monitor = NullProgressMonitor.INSTANCE;
     125        }
     126        try {
     127            monitor.beginTask(trn("Downloading {0} changeset ...", "Downloading {0} changesets ...",ids.size(),ids.size()));
     128            monitor.setTicksCount(ids.size());
     129            List<Changeset> ret = new ArrayList<Changeset>();
     130            int i=0;
     131            for (Iterator<Integer> it = ids.iterator(); it.hasNext(); ) {
     132                int id = it.next();
     133                if (id <= 0) {
     134                    continue;
     135                }
     136                i++;
     137                StringBuffer sb = new StringBuffer();
     138                sb.append("changeset/").append(id);
     139                InputStream in = getInputStream(sb.toString(), monitor.createSubTaskMonitor(1, true));
     140                if (in == null)
     141                    return null;
     142                monitor.indeterminateSubTask(tr("({0}/{1}) Downloading changeset {0} ...", i,ids.size(), id));
     143                List<Changeset> changesets = OsmChangesetParser.parse(in, monitor.createSubTaskMonitor(1, true));
     144                if (changesets == null || changesets.isEmpty()) {
     145                    continue;
     146                }
     147                ret.addAll(changesets);
     148                monitor.worked(1);
     149            }
     150            return ret;
     151        } catch(OsmTransferException e) {
     152            throw e;
     153        } catch(IllegalDataException e) {
     154            throw new OsmTransferException(e);
     155        } finally {
     156            monitor.finishTask();
     157        }
     158    }
     159
     160    /**
    106161     * not implemented yet
    107162     *
Note: See TracChangeset for help on using the changeset viewer.