-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathPluginComponentBlock.java
More file actions
101 lines (81 loc) · 3.67 KB
/
PluginComponentBlock.java
File metadata and controls
101 lines (81 loc) · 3.67 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.gmail.visualbukkit.blocks;
import com.gmail.visualbukkit.VisualBukkitApp;
import com.gmail.visualbukkit.project.*;
import com.gmail.visualbukkit.ui.ActionMenuItem;
import org.json.JSONArray;
import org.json.JSONObject;
public non-sealed abstract class PluginComponentBlock extends Block {
private final StatementHolder childStatementHolder = new StatementHolder(this);
public PluginComponentBlock() {
getStyleClass().add("plugin-component-block");
ActionMenuItem pasteItem = new ActionMenuItem(VisualBukkitApp.localizedText("context_menu.paste_after"), e -> UndoManager.current().execute(() -> childStatementHolder.addFirst(CopyPasteManager.pasteStatement())));
ActionMenuItem collapseItem = new ActionMenuItem(VisualBukkitApp.localizedText("context_menu.collapse_all"), e -> childStatementHolder.setCollapsedRecursive(true));
ActionMenuItem expandItem = new ActionMenuItem(VisualBukkitApp.localizedText("context_menu.expand_all"), e -> childStatementHolder.setCollapsedRecursive(false));
ActionMenuItem javadocItem = new ActionMenuItem(VisualBukkitApp.localizedText("context_menu.javadocs"), e -> JavadocsManager.getCompJavaDocs(getPluginComponent()));
pasteItem.disableProperty().bind(CopyPasteManager.statementCopiedProperty().not());
getContextMenu().getItems().addAll(collapseItem, expandItem, pasteItem, javadocItem);
getContextMenu().setOnShowing(e -> {
collapseItem.setDisable(childStatementHolder.isEmpty());
expandItem.setDisable(collapseItem.isDisable());
});
}
@Override
public void delete() {
ProjectManager.current().promptDeletePluginComponent(ProjectManager.current().getPluginComponent(this));
}
@Override
public void updateState() {
super.updateState();
childStatementHolder.forEach(StatementBlock::updateState);
}
public abstract void prepareBuild(BuildInfo buildInfo);
public String generateChildrenJava(BuildInfo buildInfo) {
String childrenJava = childStatementHolder.generateJava(buildInfo);
return buildInfo.getLocalVariableDeclarations() + childrenJava;
}
@Override
public JSONObject serialize() {
JSONObject json = super.serialize();
for (StatementBlock block : childStatementHolder) {
json.append("statements", block.serialize());
}
return json;
}
@Override
public void deserialize(JSONObject json) {
super.deserialize(json);
JSONArray statements = json.optJSONArray("statements");
if (statements != null) {
for (Object obj : statements) {
if (obj instanceof JSONObject statementJson) {
childStatementHolder.addLast(BlockRegistry.newStatement(statementJson));
}
}
}
}
public StatementHolder getChildStatementHolder() {
return childStatementHolder;
}
public PluginComponent getPluginComponent() {
return ProjectManager.current().getPluginComponent(this);
}
@BlockDefinition(id = "unknown-plugin-component", name = "Unknown Plugin Component")
public static class Unknown extends PluginComponentBlock {
private JSONObject json = new JSONObject();
@Override
public void updateState() {
super.updateState();
pseudoClassStateChanged(INVALID_STYLE_CLASS, true);
}
@Override
public void prepareBuild(BuildInfo buildInfo) {}
@Override
public JSONObject serialize() {
return json;
}
@Override
public void deserialize(JSONObject json) {
this.json = json;
}
}
}