]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java
Logger fixes after merge commit:fdbe8762
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / ui / WorkbenchSelectionProvider.java
index 096fd7aae54fc21adf301415d37728a7a3031a24..5bd73f97a463b74f0ecb4f84842ac454a903212d 100644 (file)
@@ -13,6 +13,7 @@ package org.simantics.diagram.ui;
 \r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.Optional;\r
 import java.util.concurrent.CopyOnWriteArrayList;\r
 import java.util.concurrent.TimeUnit;\r
 \r
@@ -22,18 +23,23 @@ import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.SelectionChangedEvent;\r
 import org.eclipse.jface.viewers.StructuredSelection;\r
 import org.eclipse.ui.IWorkbenchPartSite;\r
+import org.simantics.db.exception.DatabaseException;\r
 import org.simantics.diagram.elements.AdaptableImmutableProxyElement;\r
 import org.simantics.g2d.canvas.ICanvasContext;\r
 import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant;\r
 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
 import org.simantics.g2d.canvas.impl.HintReflection.HintListener;\r
+import org.simantics.g2d.diagram.participant.ElementJSON;\r
 import org.simantics.g2d.diagram.participant.Selection;\r
 import org.simantics.g2d.element.ElementHints;\r
 import org.simantics.g2d.element.IElement;\r
-import org.simantics.utils.datastructures.hints.IHintObservable;\r
+import org.simantics.ui.selection.WorkbenchSelectionUtils;\r
 import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintObservable;\r
 import org.simantics.utils.threads.IThreadWorkQueue;\r
 import org.simantics.utils.threads.ThreadUtils;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
 \r
 /**\r
  * A canvas participant that listens to the #0 mouse selection and provides it\r
@@ -41,7 +47,9 @@ import org.simantics.utils.threads.ThreadUtils;
  * \r
  * @author Tuukka Lehtonen\r
  */\r
-public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implements IPostSelectionProvider {\r
+public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implements IPostSelectionProvider, ElementJSON {\r
+\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(WorkbenchSelectionProvider.class);\r
 \r
     private static final long                                 POST_SELECTION_DELAY = 300;\r
 \r
@@ -205,4 +213,15 @@ public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implem
         System.out.println("WorkbenchSelectionProvider: TODO: set selection: " + selection);\r
     }\r
 \r
+    @Override\r
+    public Optional<String> getJSON(IElement element) {\r
+        ISelection sel = constructAdaptableSelection(Collections.singleton(element));\r
+        try {\r
+            return Optional.ofNullable( WorkbenchSelectionUtils.getPossibleJSON(sel) );\r
+        } catch (DatabaseException e) {\r
+            LOGGER.error("Unexpected failure while constructing JSON from element " + element, e);\r
+            return Optional.empty();\r
+        }\r
+    }\r
+\r
 }\r