Changeset 17500 in josm for trunk/src/org
- Timestamp:
- 2021-02-21T01:02:50+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDiscussionPanel.java
r17371 r17500 15 15 import javax.swing.AbstractAction; 16 16 import javax.swing.BorderFactory; 17 import javax.swing.JOptionPane; 17 18 import javax.swing.JPanel; 18 19 import javax.swing.JScrollPane; 19 20 import javax.swing.JTable; 20 21 import javax.swing.JToolBar; 22 import javax.swing.SwingConstants; 21 23 22 24 import org.openstreetmap.josm.actions.downloadtasks.ChangesetHeaderDownloadTask; … … 24 26 import org.openstreetmap.josm.data.osm.Changeset; 25 27 import org.openstreetmap.josm.gui.MainApplication; 28 import org.openstreetmap.josm.gui.NoteInputDialog; 26 29 import org.openstreetmap.josm.io.NetworkManager; 27 30 import org.openstreetmap.josm.io.OnlineResource; 31 import org.openstreetmap.josm.io.OsmApi; 32 import org.openstreetmap.josm.io.OsmTransferException; 33 import org.openstreetmap.josm.tools.ExceptionUtil; 28 34 import org.openstreetmap.josm.tools.ImageProvider; 35 import org.openstreetmap.josm.tools.Logging; 29 36 30 37 /** … … 39 46 40 47 private final UpdateChangesetDiscussionAction actUpdateChangesets = new UpdateChangesetDiscussionAction(); 48 private final AddChangesetCommentAction actAddChangesetComment = new AddChangesetCommentAction(); 41 49 42 50 private final ChangesetDiscussionTableModel model = new ChangesetDiscussionTableModel(); … … 49 57 JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT)); 50 58 51 JToolBar tb = new JToolBar( JToolBar.VERTICAL);59 JToolBar tb = new JToolBar(SwingConstants.VERTICAL); 52 60 tb.setFloatable(false); 53 61 54 62 // -- changeset discussion update 55 63 tb.add(actUpdateChangesets); 56 actUpdateChangesets.initProperties(current); 64 // -- add a comment to changeset discussion 65 tb.add(actAddChangesetComment); 66 67 initProperties(); 57 68 58 69 pnl.add(tb); 59 70 return pnl; 71 } 72 73 void initProperties() { 74 actUpdateChangesets.initProperties(current); 75 actAddChangesetComment.initProperties(current); 60 76 } 61 77 … … 82 98 } 83 99 84 publicvoid initProperties(Changeset cs) {100 void initProperties(Changeset cs) { 85 101 setEnabled(cs != null && !NetworkManager.isOffline(OnlineResource.OSM_API)); 102 } 103 } 104 105 /** 106 * Adds a discussion comment to the current changeset 107 */ 108 class AddChangesetCommentAction extends AbstractAction { 109 AddChangesetCommentAction() { 110 putValue(NAME, tr("Comment")); 111 new ImageProvider("dialogs/notes", "note_comment").getResource().attachImageIcon(this); 112 putValue(SHORT_DESCRIPTION, tr("Add comment")); 113 } 114 115 @Override 116 public void actionPerformed(ActionEvent evt) { 117 if (current == null) 118 return; 119 NoteInputDialog dialog = new NoteInputDialog(MainApplication.getMainFrame(), tr("Comment on changeset"), tr("Add comment")); 120 dialog.showNoteDialog(tr("Add comment to changeset:"), ImageProvider.get("dialogs/notes", "note_comment")); 121 if (dialog.getValue() != 1) { 122 return; 123 } 124 try { 125 OsmApi.getOsmApi().addCommentToChangeset(current, dialog.getInputText(), null); 126 } catch (OsmTransferException e) { 127 Logging.error(e); 128 JOptionPane.showMessageDialog( 129 MainApplication.getMainFrame(), 130 ExceptionUtil.explainOsmTransferException(e), 131 tr("Error"), 132 JOptionPane.ERROR_MESSAGE); 133 } 134 } 135 136 void initProperties(Changeset cs) { 137 setEnabled(cs != null && !cs.isOpen() && !NetworkManager.isOffline(OnlineResource.OSM_API)); 86 138 } 87 139 } … … 101 153 updateView(cs); 102 154 } 103 actUpdateChangesets.initProperties(current);155 initProperties(); 104 156 if (cs != null && cs.getDiscussion().size() < cs.getCommentsCount()) { 105 157 actUpdateChangesets.actionPerformed(null); -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r17498 r17500 536 536 537 537 /** 538 * Adds a comment to the discussion of a closed changeset. 539 * 540 * @param changeset the changeset where to add a comment. Must be closed. changeset.getId() > 0 required. 541 * @param comment Text of the comment 542 * @param monitor the progress monitor. If null, uses {@link NullProgressMonitor#INSTANCE} 543 * 544 * @throws OsmTransferException if something goes wrong. 545 * @since 17500 546 */ 547 public void addCommentToChangeset(Changeset changeset, String comment, ProgressMonitor monitor) throws OsmTransferException { 548 if (changeset.isOpen()) 549 throw new IllegalArgumentException(tr("Changeset must be closed in order to add a comment")); 550 else if (changeset.getId() <= 0) 551 throw new IllegalArgumentException(tr("Changeset ID > 0 expected. Got {0}.", changeset.getId())); 552 sendRequest("POST", "changeset/" + changeset.getId() + "/comment", 553 "text=" + Utils.encodeUrl(comment), monitor, "application/x-www-form-urlencoded", true, false); 554 } 555 556 /** 538 557 * Uploads a list of changes in "diff" form to the server. 539 558 * … … 644 663 } 645 664 665 protected final String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, 666 boolean doAuthenticate, boolean fastFail) throws OsmTransferException { 667 return sendRequest(requestMethod, urlSuffix, requestBody, monitor, null, doAuthenticate, fastFail); 668 } 669 646 670 /** 647 671 * Generic method for sending requests to the OSM API. … … 655 679 * @param requestBody the body of the HTTP request, if any. 656 680 * @param monitor the progress monitor 657 * @param doAuthenticate set to true, if the request sent to the server shall include authentication 658 * credentials; 681 * @param contentType Content-Type to set for PUT/POST/DELETE requests. 682 * Can be set to {@code null}, in that case it means {@code text/xml} 683 * @param doAuthenticate set to true, if the request sent to the server shall include authentication credentials; 659 684 * @param fastFail true to request a short timeout 660 685 * … … 664 689 */ 665 690 protected final String sendRequest(String requestMethod, String urlSuffix, String requestBody, ProgressMonitor monitor, 666 boolean doAuthenticate, boolean fastFail) throws OsmTransferException {691 String contentType, boolean doAuthenticate, boolean fastFail) throws OsmTransferException { 667 692 int retries = fastFail ? 0 : getMaxRetries(); 668 693 … … 686 711 687 712 if ("PUT".equals(requestMethod) || "POST".equals(requestMethod) || "DELETE".equals(requestMethod)) { 688 client.setHeader("Content-Type", "text/xml");713 client.setHeader("Content-Type", contentType == null ? "text/xml" : contentType); 689 714 // It seems that certain bits of the Ruby API are very unhappy upon 690 715 // receipt of a PUT/POST message without a Content-length header,
Note:
See TracChangeset
for help on using the changeset viewer.