]> gerrit.simantics Code Review - simantics/platform.git/blob
5702fe9e496d893862802df9461b6ee6d45e97db
[simantics/platform.git] /
1 package org.simantics.modeling.ui.diagram.monitor;
2
3 import org.simantics.databoard.Bindings;
4 import org.simantics.databoard.util.ObjectUtils;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.CommentMetadata;
7 import org.simantics.db.common.request.WriteRequest;
8 import org.simantics.db.exception.DatabaseException;
9 import org.simantics.db.layer0.variable.Variable;
10 import org.simantics.db.layer0.variable.VariableWriteImplied;
11 import org.simantics.db.layer0.variable.Variables;
12
13 public class MonitorVariableWrite extends WriteRequest {
14
15     final private Variable variable;
16     final private String label;
17
18     public MonitorVariableWrite(Variable variable, String label) {
19         super(null);
20         this.variable = variable;
21         this.label = label;
22     }
23
24     @Override
25     public void perform(WriteGraph graph) throws DatabaseException {
26
27         Variable converted = variable.getPossibleProperty(graph, Variables.CONVERTED_VALUE);
28         if(converted != null) {
29             converted.setValue(graph, label, Bindings.STRING);
30
31             // Add a comment to metadata.
32             CommentMetadata cm = graph.getMetadata(CommentMetadata.class);
33             graph.addMetadata(cm.add("Set value " + ObjectUtils.toString(label)));
34         } else {
35             new VariableWriteImplied(variable, label).perform(graph);
36         }
37
38     }
39
40 }