Revision: 6011
          http://sourceforge.net/p/jump-pilot/code/6011
Author:   ma15569
Date:     2018-12-02 11:53:17 +0000 (Sun, 02 Dec 2018)
Log Message:
-----------
Rewrite plugins to activate task monitor on saving/loading files

Modified Paths:
--------------
    core/trunk/src/org/openjump/core/ui/plugin/style/LoadStylePlugIn.java
    core/trunk/src/org/openjump/core/ui/plugin/style/SaveStylePlugIn.java

Modified: core/trunk/src/org/openjump/core/ui/plugin/style/LoadStylePlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/style/LoadStylePlugIn.java       
2018-12-01 09:57:27 UTC (rev 6010)
+++ core/trunk/src/org/openjump/core/ui/plugin/style/LoadStylePlugIn.java       
2018-12-02 11:53:17 UTC (rev 6011)
@@ -82,13 +82,20 @@
     }
 
     File file;
+    Layer layer;
+    private final JFCWithEnterAction fc = new JFCWithEnterAction();
+    private final FileNameExtensionFilter filter = new FileNameExtensionFilter(
+            "JUMP layer symbology", "style.xml");
+    private final FileNameExtensionFilter filter2 = new 
FileNameExtensionFilter(
+            "Spatial layer descriptor", "sld");
+
     private static final String FILE_CHOOSER_DIRECTORY_KEY = 
SaveFileDataSourceQueryChooser.class
             .getName() + " - FILE CHOOSER DIRECTORY";
 
     @Override
     public boolean execute(PlugInContext context) throws Exception {
-        final Layer layer = context.getSelectedLayer(0);
-        final JFCWithEnterAction fc = new JFCWithEnterAction();
+        layer = context.getSelectedLayer(0);
+
         fc.setCurrentDirectory(new File((String) PersistentBlackboardPlugIn
                 .get(context.getWorkbenchContext()).get(
                         FILE_CHOOSER_DIRECTORY_KEY)));
@@ -96,44 +103,45 @@
         fc.setDialogType(JFileChooser.OPEN_DIALOG);
         fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
         fc.setMultiSelectionEnabled(false);
-        final FileNameExtensionFilter filter = new FileNameExtensionFilter(
-                "JUMP layer symbology", "style.xml");
-        final FileNameExtensionFilter filter2 = new FileNameExtensionFilter(
-                "Spatial layer descriptor", "sld");
+
         fc.setFileFilter(filter2);
         fc.setFileFilter(filter);
         fc.addChoosableFileFilter(filter);
+
+        return true;
+
+    }
+
+    private void monitor(TaskMonitor monitor, File file) {
+        monitor.allowCancellationRequests();
+        monitor.report(I18N
+                
.get("com.vividsolutions.jump.workbench.plugin.PlugInManager.loading")
+                + ": " + file.getAbsolutePath());
+    }
+
+    @Override
+    public void run(TaskMonitor monitor, PlugInContext context)
+            throws Exception {
+
         if (JFileChooser.APPROVE_OPTION != fc.showOpenDialog(context
                 .getWorkbenchFrame())) {
-            return false;
+            return;
         }
         if (fc.getFileFilter().equals(filter)) {
 
             file = fc.getSelectedFile();
             // IOTools.loadMetadata_Jump(file, layer, true, false, true);
+            monitor(monitor, file);
 
             IOTools.loadSimbology_Jump(file, layer);
 
         } else if (fc.getFileFilter().equals(filter2)) {
-            final File file = fc.getSelectedFile();
-
+            file = fc.getSelectedFile();
+            monitor(monitor, file);
             IOTools.loadSimbology_SLD(file, context);
 
         }
 
-        return true;
-
     }
 
-    @Override
-    public void run(TaskMonitor monitor, PlugInContext context)
-            throws Exception {
-        monitor.allowCancellationRequests();
-        monitor.report(getName()
-                + ": "
-                + 
I18N.get("com.vividsolutions.jump.workbench.plugin.PlugInManager.loading")
-                + ": " + file.getAbsolutePath());
-
-    }
-
 }
\ No newline at end of file

Modified: core/trunk/src/org/openjump/core/ui/plugin/style/SaveStylePlugIn.java
===================================================================
--- core/trunk/src/org/openjump/core/ui/plugin/style/SaveStylePlugIn.java       
2018-12-01 09:57:27 UTC (rev 6010)
+++ core/trunk/src/org/openjump/core/ui/plugin/style/SaveStylePlugIn.java       
2018-12-02 11:53:17 UTC (rev 6011)
@@ -52,6 +52,14 @@
 import com.vividsolutions.jump.workbench.ui.images.IconLoader;
 import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn;
 
+/**
+ * plugin to save a layer style as file.
+ * Currently supported JUMP XML format [file_name.style.xml] and (partially) 
+ * Spatial layer descriptor [file_name.sld]
+ * @author Giuseppe Aruta
+ * @date 2018_21_2
+ *
+ */
 public class SaveStylePlugIn extends ThreadedBasePlugIn {
 
     public final static ImageIcon ICON = IconLoader.icon("style_out.png");
@@ -75,6 +83,12 @@
     }
 
     File file;
+    Layer layer;
+    private final FileNameExtensionFilter filter = new FileNameExtensionFilter(
+            "JUMP layer symbology", "style.xml");
+    private final FileNameExtensionFilter filter2 = new 
FileNameExtensionFilter(
+            "Spatial layer descriptor", "sld");
+    private final JFCWithEnterAction fc = new 
GUIUtil.FileChooserWithOverwritePrompting();
     private static final String FILE_CHOOSER_DIRECTORY_KEY = 
SaveFileDataSourceQueryChooser.class
             .getName() + " - FILE CHOOSER DIRECTORY";
 
@@ -82,8 +96,8 @@
     public boolean execute(PlugInContext context) throws Exception {
         reportNothingToUndoYet(context);
 
-        final Layer layer = context.getSelectedLayer(0);
-        final JFCWithEnterAction fc = new 
GUIUtil.FileChooserWithOverwritePrompting();
+        layer = context.getSelectedLayer(0);
+
         fc.setCurrentDirectory(
 
         new File((String) PersistentBlackboardPlugIn.get(
@@ -95,30 +109,49 @@
         fc.setDialogTitle(name);
         fc.setDialogType(JFileChooser.SAVE_DIALOG);
 
-        final FileNameExtensionFilter filter = new FileNameExtensionFilter(
-                "JUMP layer symbology", "style.xml");
-        final FileNameExtensionFilter filter2 = new FileNameExtensionFilter(
-                "Spatial layer descriptor", "sld");
-
         fc.setFileFilter(filter2);
         fc.setFileFilter(filter);
         fc.addChoosableFileFilter(filter);
 
+        return true;
+    }
+
+    public EnableCheck createEnableCheck(final WorkbenchContext 
workbenchContext) {
+        final EnableCheckFactory ecf = new 
EnableCheckFactory(workbenchContext);
+        final MultiEnableCheck mec = new MultiEnableCheck().add(
+                ecf.createWindowWithLayerNamePanelMustBeActiveCheck())
+                .add(ecf.createExactlyNLayerablesMustBeSelectedCheck(1,
+                        Layer.class));
+        return mec;
+
+    }
+
+    private void monitor(TaskMonitor monitor, File file) {
+        monitor.allowCancellationRequests();
+        monitor.report(I18N.get("ui.plugin.SaveDatasetAsPlugIn.saving") + ": "
+                + file.getAbsolutePath());
+    }
+
+    @Override
+    public void run(TaskMonitor monitor, PlugInContext context)
+            throws Exception {
+
         if (JFileChooser.APPROVE_OPTION != fc.showSaveDialog(context
                 .getWorkbenchFrame())) {
-            return false;
+            return;
         }
         String filePath = "";
         if (fc.getFileFilter().equals(filter)) {
             file = fc.getSelectedFile();
             file = FileUtil.addExtensionIfNone(file, "style.xml");
-
+            monitor(monitor, file);
             IOTools.saveSimbology_Jump(file, layer);
             filePath = file.getAbsolutePath();
 
         } else if (fc.getFileFilter().equals(filter2)) {
-            File file = fc.getSelectedFile();
+            file = fc.getSelectedFile();
             file = FileUtil.addExtensionIfNone(file, "sld");
+            monitor(monitor, file);
             IOTools.saveSimbology_SLD2(file, layer);
             filePath = file.getAbsolutePath();
         }
@@ -130,28 +163,8 @@
                                 + ": " + filePath, getName(),
                         JOptionPane.PLAIN_MESSAGE);
 
-        return true;
-    }
+        return;
 
-    public EnableCheck createEnableCheck(final WorkbenchContext 
workbenchContext) {
-        final EnableCheckFactory ecf = new 
EnableCheckFactory(workbenchContext);
-        final MultiEnableCheck mec = new MultiEnableCheck().add(
-                ecf.createWindowWithLayerNamePanelMustBeActiveCheck())
-                .add(ecf.createExactlyNLayerablesMustBeSelectedCheck(1,
-                        Layer.class));
-        return mec;
-
     }
 
-    @Override
-    public void run(TaskMonitor monitor, PlugInContext context)
-            throws Exception {
-
-        monitor.allowCancellationRequests();
-        monitor.report(getName() + ": "
-                + I18N.get("ui.plugin.SaveDatasetAsPlugIn.saving") + ": "
-                + file.getAbsolutePath());
-
-    }
-
 }
\ No newline at end of file



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to