- Timestamp:
- 2010-01-08T23:01:22+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/ChangesetManagementPanel.java
r2767 r2781 76 76 gc.weighty = 0.0; 77 77 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); 79 79 80 80 gc.gridwidth = 4; … … 134 134 btnClose.setMargin(new Insets(0,0,0,0)); 135 135 cbOpenChangesets.addItemListener(closeChangesetAction); 136 rbExisting.addItemListener(closeChangesetAction); 136 137 add(btnClose, gc); 137 138 … … 299 300 300 301 public void actionPerformed(ActionEvent e) { 301 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask( model);302 DownloadOpenChangesetsTask task = new DownloadOpenChangesetsTask(ChangesetManagementPanel.this); 302 303 Main.worker.submit(task); 303 304 } … … 324 325 325 326 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 ); 327 332 } 328 333 -
trunk/src/org/openstreetmap/josm/gui/io/DownloadOpenChangesetsTask.java
r2689 r2781 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Component; 6 7 import java.io.IOException; 7 8 import java.util.List; … … 15 16 import org.openstreetmap.josm.data.osm.UserInfo; 16 17 import org.openstreetmap.josm.gui.ExceptionDialogUtil; 18 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 17 19 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 18 20 import org.openstreetmap.josm.io.ChangesetQuery; … … 25 27 * This is a task for downloading the open changesets of the current user 26 28 * from the OSM server. 27 *28 29 */ 29 30 public class DownloadOpenChangesetsTask extends PleaseWaitRunnable { … … 32 33 private OsmServerChangesetReader reader; 33 34 private List<Changeset> changesets; 34 private OpenChangesetComboBoxModel model;35 35 private Exception lastException; 36 private UserInfo userInfo;36 private Component parent; 37 37 38 38 /** … … 41 41 * after download 42 42 */ 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; 46 46 } 47 47 … … 49 49 protected void cancel() { 50 50 this.cancelled = true; 51 reader.cancel(); 51 synchronized(this) { 52 if (reader != null) { 53 reader.cancel(); 54 } 55 } 52 56 } 53 57 54 58 @Override 55 59 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 ); 57 72 return; 73 } 74 if (cancelled)return; 58 75 if (lastException != null) { 59 76 ExceptionDialogUtil.explainException(lastException); … … 67 84 JOptionPane.INFORMATION_MESSAGE 68 85 ); 86 return; 69 87 } 70 88 SwingUtilities.invokeLater( … … 78 96 79 97 /** 80 * Fetchthe user info from the server. This is necessary if we don't know81 * 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. 82 100 * 83 * @return the user info84 * @throws OsmTransferException thrown in case of any communication exception85 101 */ 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 } 89 124 } 90 125 … … 92 127 protected void realRun() throws SAXException, IOException, OsmTransferException { 93 128 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(); 97 136 } 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 99 145 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 } 102 154 changesets = reader.queryChangesets( 103 155 query, -
trunk/src/org/openstreetmap/josm/gui/io/OpenChangesetComboBoxModel.java
r2711 r2781 13 13 14 14 /** 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 * 17 18 */ 18 19 public class OpenChangesetComboBoxModel extends DefaultComboBoxModel implements ChangesetCacheListener { 19 20 private List<Changeset> changesets; 20 private long uid;21 21 private Changeset selectedChangeset = null; 22 22 … … 32 32 } 33 33 34 /** 35 * Refreshes the content of the combobox model with the current list of open 36 * changesets from the {@see ChangesetCache}. 37 */ 34 38 public void refresh() { 35 39 changesets.clear(); … … 38 42 int idx = changesets.indexOf(selectedChangeset); 39 43 if (idx < 0) { 40 se tSelectedItem(null);44 selectFirstChangeset(); 41 45 } else { 42 46 setSelectedItem(changesets.get(idx)); … … 44 48 } 45 49 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 */ 54 53 public void selectFirstChangeset() { 55 54 if (changesets == null || changesets.isEmpty()) { -
trunk/src/org/openstreetmap/josm/io/OsmServerChangesetReader.java
r2688 r2781 48 48 * @return the list of changesets read from the server 49 49 * @throws IllegalArgumentException thrown if query is null 50 * @throws OsmTransferException 50 * @throws OsmTransferException thrown if something goes wrong w 51 51 */ 52 52 public List<Changeset> queryChangesets(ChangesetQuery query, ProgressMonitor monitor) throws OsmTransferException { -
trunk/src/org/openstreetmap/josm/io/OsmServerUserInfoReader.java
r2748 r2781 121 121 } 122 122 123 124 125 123 public UserInfo fetchUserInfo(ProgressMonitor monitor) throws OsmTransferException { 126 124 try { 127 monitor.beginTask(tr("Reading user info ...")); 125 monitor.beginTask(tr("")); 126 monitor.indeterminateSubTask(tr("Reading user info ...")); 128 127 InputStream in = getInputStream("user/details", monitor.createSubTaskMonitor(1, true)); 129 128 return buildFromXML(
Note:
See TracChangeset
for help on using the changeset viewer.