+
+ componentType = elementSelector.getSelector().componentType;
+ }
+
+ readRegions(diagram);
+ readRoutes();
+ readComponentTypes();
+ updatePropertyList();
+ }
+
+ private void readComponentTypes() {
+ try {
+ Simantics.getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ List<Resource> types = findComponentTypes(graph);
+
+ componentTypes = new ArrayList<>(types.size() + 1);
+ componentTypeNames = new ArrayList<>(types.size() + 1);
+
+ componentTypes.add(null);
+ componentTypeNames.add("Any type");
+ componentTypes.addAll(types);
+ for (Resource t : types) {
+ componentTypeNames.add(graph.getValue2(t, L0.HasName));
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to read district component types", e);
+ }
+ }
+
+ private void readRoutes() {
+ final Map<Resource, String> routes = new HashMap<>();
+
+ try {
+ Simantics.getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ RouteResource ROUTE = RouteResource.getInstance(graph);
+
+ Resource model = ActiveModels.getPossibleActiveModel(graph, Simantics.getProjectResource());
+ List<Resource> routeCollection = QueryIndexUtils.searchByType(graph, model, ROUTE.Route);
+ for (Resource r : routeCollection) {
+ String name = graph.getRelatedValue(r, L0.HasLabel);
+ routes.put(r, name);
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to read routes in the model", e);
+ }
+
+ routeNames = routes.values().toArray(new String[routes.size()]);
+ routeResources = routes.keySet().toArray(new Resource[routes.size()]);
+ }
+
+ private void readRegions(Resource diagram) {
+ final Map<Resource, String> regions = new HashMap<>();
+
+ try {
+ Simantics.getSession().syncRequest(new ReadRequest() {
+ @Override
+ public void run(ReadGraph graph) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ ModelingResources MOD = ModelingResources.getInstance(graph);
+ DiagramRegionsResource DR = DiagramRegionsResource.getInstance(graph);
+
+ // If a specific diagram is given, use that
+ Collection<Resource> ds = diagram != null ? Collections.singleton(diagram) : diagrams;
+
+ for (Resource composite : ds) {
+ Resource diagram = graph.getSingleObject(composite, MOD.CompositeToDiagram);
+ for (Resource r : graph.getObjects(diagram, DR.hasRegion)) {
+ if (!graph.isInstanceOf(r, DR.Region))
+ continue;
+ String name = graph.getRelatedValue(r, L0.HasLabel);
+ regions.put(r, name);
+ }
+ }
+ }
+ });
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to read regions in the model", e);