1 package org.simantics.sysdyn.ui.properties.widgets.arrays;
\r
3 import java.util.ArrayList;
\r
4 import java.util.Collection;
\r
5 import java.util.Collections;
\r
7 import org.simantics.browsing.ui.common.node.AbstractNode;
\r
8 import org.simantics.browsing.ui.graph.impl.contributor.viewpoint.ViewpointContributorImpl;
\r
9 import org.simantics.db.ReadGraph;
\r
10 import org.simantics.db.Resource;
\r
11 import org.simantics.db.common.ResourceArray;
\r
12 import org.simantics.db.common.request.ObjectsWithType;
\r
13 import org.simantics.db.exception.DatabaseException;
\r
14 import org.simantics.layer0.Layer0;
\r
15 import org.simantics.sysdyn.SysdynResource;
\r
17 public class AvailableEnumerations extends ViewpointContributorImpl<ResourceArray> {
\r
20 public Collection<?> getContribution(ReadGraph graph, ResourceArray input)
\r
21 throws DatabaseException {
\r
22 Resource[] selection = input.resources;
\r
23 if(selection.length < 1)
\r
24 return Collections.emptyList();
\r
25 Layer0 l0 = Layer0.getInstance(graph);
\r
26 Resource configuration = null;
\r
28 // Variables need to be from the same configuration
\r
29 for(Resource r : selection) {
\r
30 Resource conf = graph.getPossibleObject(r, l0.PartOf);
\r
31 if(configuration == null || conf.equals(configuration))
\r
32 configuration = conf;
\r
34 return Collections.emptyList();
\r
37 ArrayList<AbstractNode<Resource>> result = new ArrayList<AbstractNode<Resource>>();
\r
38 SysdynResource sr = SysdynResource.getInstance(graph);
\r
39 if(configuration == null)
\r
41 for(Resource r : graph.syncRequest(new ObjectsWithType(configuration, l0.ConsistsOf, sr.Enumeration))) {
\r
42 result.add(new EnumerationNode(r));
\r
48 public String getViewpointId() {
\r
49 return "Used enumerations";
\r