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.common.utils.CommonDBUtils;
15 import org.simantics.db.exception.DatabaseException;
16 import org.simantics.db.layer0.util.Layer0Utils;
17 import org.simantics.db.service.UndoRedoSupport;
18 import org.simantics.district.network.ontology.DistrictNetworkResource;
21 * Change the enabled/disabled state of a single tech type table record
23 public class EnableTechTypeItem extends WriteRequest {
29 public EnableTechTypeItem(Resource table, int itemIndex, boolean enable) {
32 this.itemIndex = itemIndex;
37 public void perform(WriteGraph graph) throws DatabaseException {
38 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
40 Binding binding = new ArrayListBinding(Datatypes.INTEGER_ARRAY, Bindings.INTEGER);
41 List<Integer> enabled = graph.getPossibleRelatedValue2(table, DN.TechType_TechTypeTable_HasEnabledItems, binding);
43 enabled = Collections.emptyList();
46 if (!enabled.contains(itemIndex)) {
47 enabled = new ArrayList<>(enabled);
48 enabled.add((Integer) itemIndex);
49 graph.getSession().markUndoPoint();
50 graph.claimLiteral(table, DN.TechType_TechTypeTable_HasEnabledItems, enabled, binding);
51 Layer0Utils.addCommentMetadata(graph, "Enable tech type table item " + (itemIndex + 1));
54 if (enabled.contains(itemIndex)) {
55 enabled = new ArrayList<>(enabled);
56 enabled.remove((Integer) itemIndex); // note - without the cast, itemIndex is list index, not element value
57 graph.getSession().markUndoPoint();
58 graph.claimLiteral(table, DN.TechType_TechTypeTable_HasEnabledItems, enabled, binding);
59 Layer0Utils.addCommentMetadata(graph, "Disable tech type table item " + (itemIndex + 1));