Hi,
i want to create a global variable and Change the value by the user. The creating works fine, but when i want to update the value it removes the global Var in Datamodel.
programAPI.getUndoRedoManager().recordChanges(new UndoableChanges() {
@Override
public void executeChanges() {
if (isDefined()) {
ArrayList<Variable> gVars = new ArrayList<Variable>();
gVars.addAll(programAPI.getVariableModel().get(new Filter<Variable>() {
@Override
public boolean accept(Variable element) {
return element.getType().equals(Variable.Type.GLOBAL) && element.getDisplayName().equals(getSelectedPottingPoint().getDisplayName() + "_PT1");
}
}));
if (gVars.isEmpty()) {
GlobalVariable variablePT1 = null;
try {
System.out.println("Variable: " + getSelectedPottingPoint().getDisplayName()
+ "_PT1" + " was created");
variablePT1 = variableFactory.createGlobalVariable(
getSelectedPottingPoint().getDisplayName() + "_PT1",
programAPI.getValueFactoryProvider().createExpressionBuilder()
.append(String.valueOf(model.get(POTTING_TIME, 0d))).build());
model.set(getSelectedPottingPoint().getDisplayName() + "_PT1", variablePT1);
if(model.isSet(getSelectedPottingPoint().getDisplayName() + "_PT1")) {
System.out.println(getSelectedPottingPoint().getDisplayName() + "_PT1 is set");
}else {
System.out.println(getSelectedPottingPoint().getDisplayName() + "_PT1 is not set");
}
} catch (VariableException e) {
e.printStackTrace();
} catch (InvalidExpressionException e) {
e.printStackTrace();
}
} else {
try {
System.out.println("Variable: " + getSelectedPottingPoint().getDisplayName()
+ "_PT1" + " was updated");
model.set(getSelectedPottingPoint().getDisplayName() + "_PT1", model.get(POTTING_TIME, 0d));
if(model.isSet(getSelectedPottingPoint().getDisplayName() + "_PT1")) {
System.out.println(getSelectedPottingPoint().getDisplayName() + "_PT1 is set");
}else {
System.out.println(getSelectedPottingPoint().getDisplayName() + "_PT1 is not set");
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
Am i doing something wrong or forgetting to define something?
Ronny