\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
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
* \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
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