--- /dev/null
+package org.simantics.ui.selection;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.UnaryRead;\r
+import org.simantics.db.common.utils.Logger;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.db.layer0.variable.Variable;\r
+\r
+public class VariableWorkbenchSelectionElement implements WorkbenchSelectionElement {\r
+ \r
+ final private Variable variable;\r
+ \r
+ public VariableWorkbenchSelectionElement(Variable variable) {\r
+ this.variable = variable;\r
+ }\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ @Override\r
+ public <T> T getContent(WorkbenchSelectionContentType<T> contentType) {\r
+ if(contentType instanceof AnyResource) {\r
+ AnyResource type = (AnyResource)contentType;\r
+ try {\r
+ return (T) type.processor.sync(new UnaryRead<Variable, Resource>(variable) {\r
+ @Override\r
+ public Resource perform(ReadGraph graph) throws DatabaseException {\r
+ return parameter.getRepresents(graph);\r
+ }\r
+ });\r
+ } catch (DatabaseException e) {\r
+ Logger.defaultLogError(e);\r
+ }\r
+ }\r
+ else if(contentType instanceof AnyVariable) {\r
+ return (T)variable;\r
+ } \r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public int hashCode() {\r
+ return variable.hashCode();\r
+ }\r
+ \r
+ @Override\r
+ public boolean equals(Object object) {\r
+ if (this == object)\r
+ return true;\r
+ else if (object == null)\r
+ return false;\r
+ else if (!(object instanceof VariableWorkbenchSelectionElement))\r
+ return false;\r
+ VariableWorkbenchSelectionElement vwse = (VariableWorkbenchSelectionElement)object;\r
+ return variable.equals(vwse.variable);\r
+ }\r
+ \r
+\r
+}\r