Ignore:
Timestamp:
2010-01-08T23:01:22+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4170: Downloaded open changesets are not listed

Location:
trunk/src/org/openstreetmap/josm/gui/io
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java

    r2767 r2781  
    7676        gc.weighty = 0.0;
    7777        gc.insets = new Insets(0, 0, 5, 0);
    78         add(new JMultilineLabel("Please decide what changeset data is uploaded to an whether to close the changeset after the next upload."), gc);
     78        add(new JMultilineLabel(tr("Please decide what changeset data is uploaded to an whether to close the changeset after the next upload.")), gc);
    7979
    8080        gc.gridwidth = 4;
     
    134134        btnClose.setMargin(new Insets(0,0,0,0));
    135135        cbOpenChangesets.addItemListener(closeChangesetAction);
     136        rbExisting.addItemListener(closeChangesetAction);
    136137        add(btnClose, gc);
    137138
     
    299300
    300301        public void actionPerformed(ActionEvent e) {
    301             DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(model);
     302            DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(ChangesetManagementPanel.this);
    302303            Main.worker.submit(task);
    303304        }
     
    324325
    325326        protected void refreshEnabledState() {
    326             setEnabled(cbOpenChangesets.getModel().getSize() > 0 && cbOpenChangesets.getSelectedItem() != null);
     327            setEnabled(
     328                    cbOpenChangesets.getModel().getSize() > 0
     329                    && cbOpenChangesets.getSelectedItem() != null
     330                    && rbExisting.isSelected()
     331            );
    327332        }
    328333
  • trunk/src/org/openstreetmap/josm/gui/io/DownloadOpenChangesetsTask.java

    r2689 r2781  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.awt.Component;
    67import java.io.IOException;
    78import java.util.List;
     
    1516import org.openstreetmap.josm.data.osm.UserInfo;
    1617import org.openstreetmap.josm.gui.ExceptionDialogUtil;
     18import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    1719import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1820import org.openstreetmap.josm.io.ChangesetQuery;
     
    2527 * This is a task for downloading the open changesets of the current user
    2628 * from the OSM server.
    27  *
    2829 */
    2930public class DownloadOpenChangesetsTask extends PleaseWaitRunnable {
     
    3233    private OsmServerChangesetReader reader;
    3334    private List<Changeset> changesets;
    34     private OpenChangesetComboBoxModel model;
    3535    private Exception lastException;
    36     private UserInfo userInfo;
     36    private Component parent;
    3737
    3838    /**
     
    4141     * after download
    4242     */
    43     public DownloadOpenChangesetsTask(OpenChangesetComboBoxModel model) {
    44         super(tr("Downloading open changesets ...", false /* don't ignore exceptions */));
    45         this.model = model;
     43    public DownloadOpenChangesetsTask(Component parent) {
     44        super(parent, tr("Downloading open changesets ..."), false /* don't ignore exceptions */);
     45        this.parent = parent;
    4646    }
    4747
     
    4949    protected void cancel() {
    5050        this.cancelled = true;
    51         reader.cancel();
     51        synchronized(this) {
     52            if (reader != null) {
     53                reader.cancel();
     54            }
     55        }
    5256    }
    5357
    5458    @Override
    5559    protected void finish() {
    56         if (cancelled)
     60        if (JosmUserIdentityManager.getInstance().isAnonymous()) {
     61            JOptionPane.showMessageDialog(
     62                    JOptionPane.getFrameForComponent(parent),
     63                    tr("<html>Could not retrieve the list of your open changesets because<br>"
     64                            + "JOSM doesn't know your identity.<br>"
     65                            + "You've either chosen to work anonymously or you are not entitled<br>"
     66                            + "to know the identity of the user on whose behalf you are working."
     67                            + "</html>"
     68                    ),
     69                    tr("Missing user identity"),
     70                    JOptionPane.ERROR_MESSAGE
     71            );
    5772            return;
     73        }
     74        if (cancelled)return;
    5875        if (lastException != null) {
    5976            ExceptionDialogUtil.explainException(lastException);
     
    6784                    JOptionPane.INFORMATION_MESSAGE
    6885            );
     86            return;
    6987        }
    7088        SwingUtilities.invokeLater(
     
    7896
    7997    /**
    80      * Fetch the user info from the server. This is necessary if we don't know
    81      * the users id yet
     98     * Refreshes the user info from the server. This is necessary if we don't know
     99     * the users id yet.
    82100     *
    83      * @return the user info
    84      * @throws OsmTransferException thrown in case of any communication exception
    85101     */
    86     protected UserInfo fetchUserInfo() throws OsmTransferException {
    87         OsmServerUserInfoReader reader = new OsmServerUserInfoReader();
    88         return reader.fetchUserInfo(getProgressMonitor().createSubTaskMonitor(1, false));
     102    protected void refreshUserIdentity(){
     103        JosmUserIdentityManager im = null;
     104        try {
     105            OsmServerUserInfoReader reader = new OsmServerUserInfoReader();
     106            UserInfo info = reader.fetchUserInfo(getProgressMonitor().createSubTaskMonitor(1, false));
     107            im = JosmUserIdentityManager.getInstance();
     108            im.setFullyIdentified(info.getDisplayName(), info);
     109        } catch(OsmTransferException e) {
     110            // retrieving the user info can fail if the current user is not authorised to
     111            // retrieve it, i.e. if he is working with an OAuth Access Token which doesn't
     112            // have the respective privileges or if he didn't or he can't authenticate with
     113            // a username/password-pair.
     114            //
     115            // Downgrade your knowlege about its identity if we've assumed that he was fully
     116            // identified. Otherwise, if he is anonymous or partially identified, keep our level
     117            // of knowlege.
     118            //
     119            if (im.isFullyIdentified()) {
     120                im.setPartiallyIdentified(im.getUserName());
     121            }
     122            System.err.println(tr("Warning: Failed to retrieve user infos for the current JOSM user. Exceptions was: {0}", e.toString()));
     123        }
    89124    }
    90125
     
    92127    protected void realRun() throws SAXException, IOException, OsmTransferException {
    93128        try {
    94             if (model.getUserId()== 0) {
    95                 userInfo = fetchUserInfo();
    96                 model.setUserId(userInfo.getId());
     129            JosmUserIdentityManager im = JosmUserIdentityManager.getInstance();
     130            if (im.isAnonymous()) {
     131                refreshUserIdentity();
     132            } else if (im.isFullyIdentified()){
     133                // do nothing
     134            } else if (im.isPartiallyIdentified()) {
     135                refreshUserIdentity();
    97136            }
    98             if (cancelled)
     137            if (cancelled)return;
     138            synchronized(this) {
     139                reader = new OsmServerChangesetReader();
     140            }
     141            ChangesetQuery query = new ChangesetQuery().beingOpen(true);
     142            if (im.isAnonymous())
     143                // we still don't know anything about the current user. Can't retrieve
     144                // its changesets
    99145                return;
    100             reader = new OsmServerChangesetReader();
    101             ChangesetQuery query = new ChangesetQuery().forUser((int)model.getUserId()).beingOpen(true);
     146            else if (im.isFullyIdentified()) {
     147                query = query.forUser(im.getUserId());
     148            } else {
     149                // we only know the users name, not its id. Nevermind, try to read
     150                // its open changesets anyway.
     151                //
     152                query = query.forUser(im.getUserName());
     153            }
    102154            changesets = reader.queryChangesets(
    103155                    query,
  • trunk/src/org/openstreetmap/josm/gui/io/OpenChangesetComboBoxModel.java

    r2711 r2781  
    1313
    1414/**
    15  * A combobox model for the list of open changesets
    16  *
     15 * A combobox model for the list of open changesets. The model is populated with the list
     16 * of open changesets kept in the {@see ChangesetCache}.
     17 *
    1718 */
    1819public class OpenChangesetComboBoxModel extends DefaultComboBoxModel implements ChangesetCacheListener {
    1920    private List<Changeset> changesets;
    20     private long uid;
    2121    private Changeset selectedChangeset = null;
    2222
     
    3232    }
    3333
     34    /**
     35     * Refreshes the content of the combobox model with the current list of open
     36     * changesets from the {@see ChangesetCache}.
     37     */
    3438    public void refresh() {
    3539        changesets.clear();
     
    3842        int idx = changesets.indexOf(selectedChangeset);
    3943        if (idx < 0) {
    40             setSelectedItem(null);
     44            selectFirstChangeset();
    4145        } else {
    4246            setSelectedItem(changesets.get(idx));
     
    4448    }
    4549
    46     public void setUserId(long uid) {
    47         this.uid = uid;
    48     }
    49 
    50     public long getUserId() {
    51         return uid;
    52     }
    53 
     50    /**
     51     * Selects the first changeset in the current list of open changesets
     52     */
    5453    public void selectFirstChangeset() {
    5554        if (changesets == null || changesets.isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.