X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fui%2FWorkbenchSelectionProvider.java;h=5bd73f97a463b74f0ecb4f84842ac454a903212d;hp=096fd7aae54fc21adf301415d37728a7a3031a24;hb=79c8788e8707e66d1f3a28621de2aae1fa824136;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java index 096fd7aae..5bd73f97a 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/ui/WorkbenchSelectionProvider.java @@ -13,6 +13,7 @@ package org.simantics.diagram.ui; import java.util.ArrayList; import java.util.Collections; +import java.util.Optional; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; @@ -22,18 +23,23 @@ import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.ui.IWorkbenchPartSite; +import org.simantics.db.exception.DatabaseException; import org.simantics.diagram.elements.AdaptableImmutableProxyElement; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.impl.AbstractCanvasParticipant; import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency; import org.simantics.g2d.canvas.impl.HintReflection.HintListener; +import org.simantics.g2d.diagram.participant.ElementJSON; import org.simantics.g2d.diagram.participant.Selection; import org.simantics.g2d.element.ElementHints; import org.simantics.g2d.element.IElement; -import org.simantics.utils.datastructures.hints.IHintObservable; +import org.simantics.ui.selection.WorkbenchSelectionUtils; import org.simantics.utils.datastructures.hints.IHintContext.Key; +import org.simantics.utils.datastructures.hints.IHintObservable; import org.simantics.utils.threads.IThreadWorkQueue; import org.simantics.utils.threads.ThreadUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * A canvas participant that listens to the #0 mouse selection and provides it @@ -41,7 +47,9 @@ import org.simantics.utils.threads.ThreadUtils; * * @author Tuukka Lehtonen */ -public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implements IPostSelectionProvider { +public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implements IPostSelectionProvider, ElementJSON { + + private static final Logger LOGGER = LoggerFactory.getLogger(WorkbenchSelectionProvider.class); private static final long POST_SELECTION_DELAY = 300; @@ -205,4 +213,15 @@ public class WorkbenchSelectionProvider extends AbstractCanvasParticipant implem System.out.println("WorkbenchSelectionProvider: TODO: set selection: " + selection); } + @Override + public Optional getJSON(IElement element) { + ISelection sel = constructAdaptableSelection(Collections.singleton(element)); + try { + return Optional.ofNullable( WorkbenchSelectionUtils.getPossibleJSON(sel) ); + } catch (DatabaseException e) { + LOGGER.error("Unexpected failure while constructing JSON from element " + element, e); + return Optional.empty(); + } + } + }