Opened 18 years ago
Closed 18 years ago
#136 closed enhancement (fixed)
Patch for uploading hooks
Reported by: | Owned by: | imi | |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Core | Version: | latest |
Keywords: | Cc: |
Description
This patch allows plugins to hook to the upload action, vetoing it if needed.
Index: /home/frsantos/Proyectos/JOSM/josm/src/org/openstreetmap/josm/actions/UploadAction.java
===================================================================
--- /home/frsantos/Proyectos/JOSM/josm/src/org/openstreetmap/josm/actions/UploadAction.java (revision 219)
+++ /home/frsantos/Proyectos/JOSM/josm/src/org/openstreetmap/josm/actions/UploadAction.java (working copy)
@@ -32,6 +32,27 @@
- @author imi
*/
public class UploadAction extends JosmAction {
+
+ / Upload Hook */
+ public interface UploadHook {
+ /
+ * Checks the upload.
+ * @param add The added primitives
+ * @param update The updated primitives
+ * @param delete The deleted primitives
+ * @return true, if the upload can continue
+ */
+ boolean checkUpload(Collection<OsmPrimitive> add, Collection<OsmPrimitive> update, Collection<OsmPrimitive> delete);
+ }
+
+ /
+ * The list of upload hooks. These hooks will be called after showing the
+ * upload window, so that any plugin can perform actions with the data and
+ * veto the upload
+ */
+ public final Collection<UploadHook> uploadHooks = new LinkedList<UploadHook>();
+
+
public UploadAction() {
super(tr("Upload to OSM"), "upload", tr("Upload all changes to the OSM server."), KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK, true);
}
@@ -66,6 +87,10 @@
if (!displayUploadScreen(add, update, delete))
return;
+ for(UploadHook hook : uploadHooks)
+ if( !hook.checkUpload(add, update, delete) )
+ return;
+
final OsmServerWriter server = new OsmServerWriter();
final Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>();
all.addAll(add);
Patch applied in revision 230. Existing upload confirmation dialog refactored to be just one element in the queue of UploadHook objects, allowing plugins to decide whether to insert their stuff before or after the dialog ("before" is suggested).