Changeset 9519 in josm for trunk/src/org


Ignore:
Timestamp:
2016-01-17T23:24:09+01:00 (9 years ago)
Author:
simon04
Message:

fix #7090 - Upload dialog allow select another user open changeset

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

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

    r8510 r9519  
    5555
    5656    protected void onPostDownloadOpenChangesets() {
    57         List<Changeset> openChangesets = ChangesetCache.getInstance().getOpenChangesets();
     57        List<Changeset> openChangesets = ChangesetCache.getInstance().getOpenChangesetsForCurrentUser();
    5858        if (openChangesets.isEmpty()) {
    5959            JOptionPane.showMessageDialog(
  • trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java

    r9059 r9519  
    1414import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
    1515import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
     16import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    1617import org.openstreetmap.josm.gui.util.GuiHelper;
     18import org.openstreetmap.josm.tools.Predicate;
     19import org.openstreetmap.josm.tools.Utils;
    1720
    1821/**
     
    192195    }
    193196
     197    /**
     198     * If the current user {@link JosmUserIdentityManager#isAnonymous() is known}, the {@link #getOpenChangesets() open changesets}
     199     * for the {@link JosmUserIdentityManager#isCurrentUser(User) current user} are returned. Otherwise,
     200     * the unfiltered {@link #getOpenChangesets() open changesets} are returned.
     201     *
     202     * @return a list of changesets
     203     */
     204    public List<Changeset> getOpenChangesetsForCurrentUser() {
     205        if (JosmUserIdentityManager.getInstance().isAnonymous()) {
     206            return getOpenChangesets();
     207        } else {
     208            return new ArrayList<>(Utils.filter(getOpenChangesets(), new Predicate<Changeset>() {
     209                @Override
     210                public boolean evaluate(Changeset object) {
     211                    return JosmUserIdentityManager.getInstance().isCurrentUser(object.getUser());
     212                }
     213            }));
     214        }
     215    }
     216
    194217    /* ------------------------------------------------------------------------- */
    195218    /* interface PreferenceChangedListener                                       */
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r9059 r9519  
    1010import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
    1111import org.openstreetmap.josm.data.Preferences.StringSetting;
     12import org.openstreetmap.josm.data.osm.User;
    1213import org.openstreetmap.josm.data.osm.UserInfo;
    1314import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
     
    223224
    224225    /**
    225      * Replies true if the user with name <code>username</code> is the current
    226      * user
     226     * Replies true if the user with name <code>username</code> is the current user
    227227     *
    228228     * @param username the user name
    229      * @return true if the user with name <code>username</code> is the current
    230      * user
     229     * @return true if the user with name <code>username</code> is the current user
    231230     */
    232231    public boolean isCurrentUser(String username) {
    233         if (username == null || this.userName == null) return false;
    234         return this.userName.equals(username);
     232        return username != null && this.userName != null && this.userName.equals(username);
     233    }
     234
     235    /**
     236     * Replies true if the current user is {@link #isFullyIdentified() fully identified} and the {@link #getUserId() user ids} match,
     237     * or if the current user is not {@link #isFullyIdentified() fully identified} and the {@link #userName user names} match.
     238     *
     239     * @param user the user to test
     240     * @return true if given user is the current user
     241     */
     242    public boolean isCurrentUser(User user) {
     243        if (user == null) {
     244            return false;
     245        } else if (isFullyIdentified()) {
     246            return getUserId() == user.getId();
     247        } else {
     248            return isCurrentUser(user.getName());
     249        }
    235250    }
    236251
  • trunk/src/org/openstreetmap/josm/gui/io/OpenChangesetComboBoxModel.java

    r9078 r9519  
    4141    public void refresh() {
    4242        changesets.clear();
    43         changesets.addAll(ChangesetCache.getInstance().getOpenChangesets());
     43        changesets.addAll(ChangesetCache.getInstance().getOpenChangesetsForCurrentUser());
    4444        fireContentsChanged(this, 0, getSize());
    4545        int idx = changesets.indexOf(selectedChangeset);
Note: See TracChangeset for help on using the changeset viewer.