-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChildProgramNodeContribution.java
More file actions
83 lines (69 loc) · 2.29 KB
/
ChildProgramNodeContribution.java
File metadata and controls
83 lines (69 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.jbm.urcap.customAPI.impl;
import com.ur.urcap.api.contribution.ProgramNodeContribution;
import com.ur.urcap.api.contribution.program.ProgramAPIProvider;
import com.ur.urcap.api.domain.data.DataModel;
import com.ur.urcap.api.domain.script.ScriptWriter;
import com.ur.urcap.api.domain.undoredo.UndoRedoManager;
import com.ur.urcap.api.domain.undoredo.UndoableChanges;
// The ChildProgramNodeCOntribution implements the MyCustomAPI interface,
// and must hence override the methods inherited from this interface
public class ChildProgramNodeContribution implements ProgramNodeContribution, MyCustomAPI {
private final ProgramAPIProvider apiProvider;
private final ChildProgramNodeView view;
private final DataModel model;
private final UndoRedoManager undoRedoManager;
private static final String COLOR_KEY = "colorKey";
private static final String DEFAULT_COLOR = MyColor.RED.toString();
public ChildProgramNodeContribution(ProgramAPIProvider apiProvider, ChildProgramNodeView view,
DataModel model) {
this.apiProvider = apiProvider;
this.view = view;
this.model = model;
this.undoRedoManager = this.apiProvider.getProgramAPI().getUndoRedoManager();
}
@Override
public void openView() {
view.updateColor(getColor());
}
@Override
public void closeView() {
}
@Override
public String getTitle() {
return getColor().toString()+" Child node";
}
@Override
public boolean isDefined() {
return true;
}
@Override
public void generateScript(ScriptWriter writer) {
writer.appendLine("popup(\"This is a "+getColor()+" Child node\", \"Child node popup\", blocking=True)");
}
/*****
* Overriding the getColor() method to comply with the MyCustomAPI interface
*/
@Override
public MyColor getColor() {
String colorInModel = model.get(COLOR_KEY, DEFAULT_COLOR);
if(colorInModel.equals(MyColor.RED.toString())) {
return MyColor.RED;
} else if(colorInModel.equals(MyColor.GREEN.toString())) {
return MyColor.GREEN;
} else {
return MyColor.BLUE;
}
}
/*****
* Overriding the setColor() method to comply with the MyCustomAPI interface
*/
@Override
public void setColor(final MyColor color) {
undoRedoManager.recordChanges(new UndoableChanges() {
@Override
public void executeChanges() {
model.set(COLOR_KEY, color.toString());
}
});
}
}