]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added ResourceWorkbenchSelectionElement 89/189/2
authorAntti Villberg <antti.villberg@semantum.fi>
Wed, 7 Dec 2016 13:43:02 +0000 (15:43 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Wed, 7 Dec 2016 13:54:25 +0000 (16:54 +0300)
refs #6853

Change-Id: I878cc7d463ae30090ba55a886e59d7ed2c4fd647

bundles/org.simantics.ui/src/org/simantics/ui/selection/ResourceWorkbenchSelectionElement.java [new file with mode: 0644]

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 (file)
index 0000000..3fa247a
--- /dev/null
@@ -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> T getContent(WorkbenchSelectionContentType<T> 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);
+    }
+
+}