1 package org.simantics.ui.selection;
\r
3 import org.simantics.db.ReadGraph;
\r
4 import org.simantics.db.Resource;
\r
5 import org.simantics.db.common.request.UnaryRead;
\r
6 import org.simantics.db.common.utils.Logger;
\r
7 import org.simantics.db.exception.DatabaseException;
\r
8 import org.simantics.db.layer0.variable.Variable;
\r
10 public class VariableWorkbenchSelectionElement implements WorkbenchSelectionElement {
\r
12 final private Variable variable;
\r
14 public VariableWorkbenchSelectionElement(Variable variable) {
\r
15 this.variable = variable;
\r
18 @SuppressWarnings("unchecked")
\r
20 public <T> T getContent(WorkbenchSelectionContentType<T> contentType) {
\r
21 if(contentType instanceof AnyResource) {
\r
22 AnyResource type = (AnyResource)contentType;
\r
24 return (T) type.processor.sync(new UnaryRead<Variable, Resource>(variable) {
\r
26 public Resource perform(ReadGraph graph) throws DatabaseException {
\r
27 return parameter.getRepresents(graph);
\r
30 } catch (DatabaseException e) {
\r
31 Logger.defaultLogError(e);
\r
34 else if(contentType instanceof AnyVariable) {
\r
41 public int hashCode() {
\r
42 return variable.hashCode();
\r
46 public boolean equals(Object object) {
\r
49 else if (object == null)
\r
51 else if (!(object instanceof VariableWorkbenchSelectionElement))
\r
53 VariableWorkbenchSelectionElement vwse = (VariableWorkbenchSelectionElement)object;
\r
54 return variable.equals(vwse.variable);
\r