From: Antti Villberg Date: Wed, 7 Dec 2016 13:43:02 +0000 (+0200) Subject: Added ResourceWorkbenchSelectionElement X-Git-Tag: v1.25.0~18 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F89%2F189%2F2;p=simantics%2Fplatform.git Added ResourceWorkbenchSelectionElement refs #6853 Change-Id: I878cc7d463ae30090ba55a886e59d7ed2c4fd647 --- diff --git a/bundles/org.simantics.ui/src/org/simantics/ui/selection/ResourceWorkbenchSelectionElement.java b/bundles/org.simantics.ui/src/org/simantics/ui/selection/ResourceWorkbenchSelectionElement.java new file mode 100644 index 000000000..3fa247ac1 --- /dev/null +++ b/bundles/org.simantics.ui/src/org/simantics/ui/selection/ResourceWorkbenchSelectionElement.java @@ -0,0 +1,49 @@ +package org.simantics.ui.selection; + +import org.simantics.db.Resource; +import org.simantics.db.common.utils.Logger; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.layer0.request.ResourceVariable; + +public class ResourceWorkbenchSelectionElement implements WorkbenchSelectionElement { + + final private Resource resource; + + public ResourceWorkbenchSelectionElement(Resource resource) { + this.resource = resource; + } + + @SuppressWarnings("unchecked") + @Override + public T getContent(WorkbenchSelectionContentType contentType) { + if(contentType instanceof AnyResource) { + return (T)resource; + } else if(contentType instanceof AnyVariable) { + AnyVariable type = (AnyVariable)contentType; + try { + return (T) type.processor.sync(new ResourceVariable(resource)); + } catch (DatabaseException e) { + Logger.defaultLogError(e); + } + } + return null; + } + + @Override + public int hashCode() { + return resource.hashCode(); + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else if (object == null) + return false; + else if (!(object instanceof ResourceWorkbenchSelectionElement)) + return false; + ResourceWorkbenchSelectionElement vwse = (ResourceWorkbenchSelectionElement)object; + return resource.equals(vwse.resource); + } + +}