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