1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.modeling;
14 import java.util.ArrayList;
15 import java.util.List;
17 import org.eclipse.core.runtime.IAdaptable;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.db.layer0.SelectionHints;
21 import org.simantics.db.layer0.variable.Variable;
22 import org.simantics.utils.datastructures.hints.HintContext;
25 * @author Tuukka Lehtonen
27 public class PropertyVariablesImpl extends HintContext implements PropertyVariables, IAdaptable {
29 private final Variable container;
30 private final Variable configuration;
31 private final Variable visualized;
32 private final Variable modified;
33 private final String suffix;
35 public PropertyVariablesImpl(Variable container, Variable visualized, Variable modified) {
36 this(container, null, visualized, modified, null);
39 public PropertyVariablesImpl(Variable container, Variable visualized, Variable modified, String suffix) {
40 this(container, null, visualized, modified, suffix);
43 public PropertyVariablesImpl(Variable container, Variable configuration, Variable visualized, Variable modified) {
44 this(container, configuration, visualized, modified, null);
47 public PropertyVariablesImpl(Variable container, Variable configuration, Variable visualized, Variable modified, String suffix) {
48 if (visualized == null)
49 throw new NullPointerException("null visualized variable");
50 this.container = container;
51 this.configuration = configuration;
52 this.visualized = visualized;
53 this.modified = modified;
55 setHintWithoutNotification(SelectionHints.KEY_MAIN, visualized);
56 setHintWithoutNotification(SelectionHints.KEY_SELECTION_PROPERTY, visualized);
60 public Variable getContainer() {
64 public Variable getConfiguration() {
69 public Variable getVisualVariable() {
74 public Variable getModificationVariable() {
79 public String getSuffix() {
84 public PropertyVariables withSuffix(String suffix) {
85 return new PropertyVariablesImpl(container, visualized, modified, suffix);
89 public PropertyVariables resolved(ReadGraph graph) throws DatabaseException {
93 Variable c = configuration;
94 Variable v = visualized;
95 Variable m = modified;
97 c = c.browsePossible(graph, suffix);
99 v = v.browsePossible(graph, suffix);
103 m = m.browsePossible(graph, suffix);
104 return new PropertyVariablesImpl(container, c, v, m, null);
108 public int hashCode() {
109 final int prime = 31;
111 result = prime * result + ((container == null) ? 0 : container.hashCode());
112 result = prime * result + ((configuration == null) ? 0 : configuration.hashCode());
113 result = prime * result + ((modified == null) ? 0 : modified.hashCode());
114 result = prime * result + ((visualized == null) ? 0 : visualized.hashCode());
119 public boolean equals(Object obj) {
124 if (getClass() != obj.getClass())
126 PropertyVariablesImpl other = (PropertyVariablesImpl) obj;
127 if (container == null) {
128 if (other.container != null)
130 } else if (!container.equals(other.container))
132 if (configuration == null) {
133 if (other.configuration != null)
135 } else if (!configuration.equals(other.configuration))
137 if (modified == null) {
138 if (other.modified != null)
140 } else if (!modified.equals(other.modified))
142 if (visualized == null) {
143 if (other.visualized != null)
145 } else if (!visualized.equals(other.visualized))
150 @SuppressWarnings("rawtypes")
152 public Object getAdapter(Class adapter) {
153 if (adapter == Variable.class)
158 public static List<PropertyVariables> resolve(ReadGraph graph, List<PropertyVariables> vars) throws DatabaseException {
159 List<PropertyVariables> result = new ArrayList<PropertyVariables>(vars.size());
160 for (PropertyVariables var : vars) {
161 PropertyVariables v = var.resolved(graph);