1 package org.simantics.sysdyn.ui.browser.nodes;
\r
3 import org.simantics.browsing.ui.common.node.DeleteException;
\r
4 import org.simantics.browsing.ui.common.node.IDeletableNode;
\r
5 import org.simantics.db.Resource;
\r
6 import org.simantics.db.WriteGraph;
\r
7 import org.simantics.db.common.request.ObjectsWithType;
\r
8 import org.simantics.db.common.request.WriteRequest;
\r
9 import org.simantics.db.common.utils.ListUtils;
\r
10 import org.simantics.db.exception.CancelTransactionException;
\r
11 import org.simantics.db.exception.DatabaseException;
\r
12 import org.simantics.db.layer0.util.RemoverUtil;
\r
13 import org.simantics.db.layer0.variable.Variable;
\r
14 import org.simantics.layer0.Layer0;
\r
15 import org.simantics.sysdyn.SysdynResource;
\r
16 import org.simantics.ui.SimanticsUI;
\r
17 import org.simantics.utils.ui.ExceptionUtils;
\r
19 public class EnumerationNode extends VariableNode<Resource> implements /*IModifiableNode,*/ IDeletableNode {
\r
21 public EnumerationNode(Resource resource) {
\r
25 public EnumerationNode(Variable variable, Resource represents) {
\r
26 super(variable, represents);
\r
30 public Modifier getModifier(String columnId) {
\r
32 Session session = SimanticsUI.getSession();
\r
33 LabelModifier modifier = new LabelModifier(session, data, session.getService(Layer0.class).HasName) {
\r
35 public String isValid(String label) {
\r
36 if (!new VariableNameValidator().isValid(data, label))
\r
46 public void delete() throws DeleteException {
\r
48 SimanticsUI.getSession().syncRequest(new WriteRequest() {
\r
50 public void perform(WriteGraph graph) throws DatabaseException, CancelTransactionException {
\r
51 SysdynResource sr = SysdynResource.getInstance(graph);
\r
52 for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacedEnumeration_Inverse)) {
\r
53 graph.deny(redeclaration, sr.Module_redeclaration_Inverse);
\r
56 for(Resource redeclaration : graph.getObjects(data, sr.Redeclaration_replacingEnumeration_Inverse)) {
\r
57 graph.deny(redeclaration, sr.Module_redeclaration_Inverse);
\r
60 Layer0 L0 = Layer0.getInstance(graph);
\r
61 Resource conf = graph.getPossibleObject(data, L0.PartOf);
\r
62 for(Resource var : graph.syncRequest(new ObjectsWithType(conf, L0.ConsistsOf, sr.Variable))) {
\r
63 Resource arrayIndexes = graph.getPossibleObject(var, sr.Variable_arrayIndexesList);
\r
64 if(arrayIndexes != null) {
\r
65 if(ListUtils.getNode(graph, arrayIndexes, data) != null) {
\r
66 ListUtils.removeElement(graph, arrayIndexes, data);
\r
71 RemoverUtil.remove(graph, data);
\r
75 } catch (DatabaseException e) {
\r
76 ExceptionUtils.logAndShowError(e);
\r