]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.template2d.ui/src/org/simantics/modeling/template2d/ui/wizard/DrawingTemplateExporter.java
Add progress monitoring for copying resources on desktop
[simantics/platform.git] / bundles / org.simantics.modeling.template2d.ui / src / org / simantics / modeling / template2d / ui / wizard / DrawingTemplateExporter.java
index bee851607a3a748848fd1f171c96ef14a2877fa1..ead7e836d2d18d2d8f61907245422aadb6f79ff1 100644 (file)
@@ -29,7 +29,6 @@ import org.simantics.databoard.serialization.SerializationException;
 import org.simantics.db.ReadGraph;
 import org.simantics.db.Resource;
 import org.simantics.db.Session;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.CopyHandler;
 import org.simantics.db.layer0.util.ClipboardUtils;
@@ -41,13 +40,17 @@ import org.simantics.db.request.Read;
 import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.modeling.template2d.DiagramTemplateConstants;
 import org.simantics.utils.ui.dialogs.ShowMessage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @author Tuukka Lehtonen
- * @author Teemu Mätäsniemi
+ * @author Teemu M�t�sniemi
  */
 public class DrawingTemplateExporter implements IRunnableWithProgress {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(DrawingTemplateExporter.class);
+    
     ExportPlan exportModel;
 
     public DrawingTemplateExporter(ExportPlan exportModel) {
@@ -92,25 +95,22 @@ public class DrawingTemplateExporter implements IRunnableWithProgress {
                 public SimanticsClipboard perform(ReadGraph graph) throws DatabaseException {
                     CopyHandler ch = graph.adapt(template, CopyHandler.class);
                     SimanticsClipboardImpl clipboard = new SimanticsClipboardImpl();
-                    ch.copyToClipboard(graph, clipboard);
+                    ch.copyToClipboard(graph, clipboard, SubMonitor.convert(mon, 50));
                     return clipboard;
                 }
             });
             for (Set<Representation> object : clipboard.getContents()) {
                 TransferableGraph1 tg = ClipboardUtils.accept(object, SimanticsKeys.KEY_TRANSFERABLE_GRAPH);
-                mon.worked(95);
+                mon.worked(50);
 
                 mon.setTaskName("Writing transferable graph...");
                 DataContainers.writeFile(location, new DataContainer(
                         DiagramTemplateConstants.DRAWING_TEMPLATE_FORMAT, DiagramTemplateConstants.DRAWING_TEMPLATE_CURRENT_VERSION,
                         new Variant(TransferableGraph1.BINDING, tg)));
-
                 mon.worked(5);
             }
-
         } catch (DatabaseException e) {
-            e.printStackTrace();
-            Logger.defaultLogError(e);
+            LOGGER.error("Drawing template export failed", e);
             mon.setCanceled(true);
             ShowMessage.showError("Export failed.", "Internal application error in export. See log for details.");
         }