1 package org.simantics.district.network.techtype.requests;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import org.simantics.databoard.Bindings;
8 import org.simantics.databoard.Datatypes;
9 import org.simantics.databoard.binding.Binding;
10 import org.simantics.databoard.binding.impl.ArrayListBinding;
11 import org.simantics.db.Resource;
12 import org.simantics.db.WriteGraph;
13 import org.simantics.db.common.request.WriteRequest;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.db.layer0.util.Layer0Utils;
16 import org.simantics.district.network.ontology.DistrictNetworkResource;
19 * Change the enabled/disabled state of a single tech type table record
21 public class EnableTechTypeItem extends WriteRequest {
27 public EnableTechTypeItem(Resource table, int itemIndex, boolean enable) {
30 this.itemIndex = itemIndex;
35 public void perform(WriteGraph graph) throws DatabaseException {
36 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
38 Binding binding = new ArrayListBinding(Datatypes.INTEGER_ARRAY, Bindings.INTEGER);
39 List<Integer> enabled = graph.getPossibleRelatedValue2(table, DN.TechType_TechTypeTable_HasEnabledItems, binding);
41 enabled = Collections.emptyList();
44 if (!enabled.contains(itemIndex)) {
45 enabled = new ArrayList<>(enabled);
46 enabled.add((Integer) itemIndex);
47 graph.getSession().markUndoPoint();
48 graph.claimLiteral(table, DN.TechType_TechTypeTable_HasEnabledItems, enabled, binding);
49 Layer0Utils.addCommentMetadata(graph, "Enable tech type table item " + (itemIndex + 1));
52 if (enabled.contains(itemIndex)) {
53 enabled = new ArrayList<>(enabled);
54 enabled.remove((Integer) itemIndex); // note - without the cast, itemIndex is list index, not element value
55 graph.getSession().markUndoPoint();
56 graph.claimLiteral(table, DN.TechType_TechTypeTable_HasEnabledItems, enabled, binding);
57 Layer0Utils.addCommentMetadata(graph, "Disable tech type table item " + (itemIndex + 1));