Skip to content

Commit 12b5b67

Browse files
committed
fixed adding user data to a linked node.
1 parent 021fd5c commit 12b5b67

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

src/main/java/com/ss/editor/ui/component/bar/action/OpenAssetAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private void openAssetByNative() {
8282
}
8383

8484
/**
85-
* Open asset folder use custom file chooser.
85+
* Open an asset folder using custom file chooser.
8686
*/
8787
private void openAsset() {
8888

src/main/java/com/ss/editor/ui/control/model/node/spatial/SpatialTreeNode.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
6565
@NotNull final ObservableList<MenuItem> items) {
6666
if (!(nodeTree instanceof ModelNodeTree)) return;
6767

68-
final AssetLinkNode linkNode = findParent(getElement(), AssetLinkNode.class::isInstance);
68+
final T element = getElement();
69+
final AssetLinkNode linkNode = findParent(element, AssetLinkNode.class::isInstance);
6970

7071
if (linkNode == null) {
7172
final Menu createMenu = createCreationMenu(nodeTree);
@@ -74,12 +75,14 @@ public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
7475
if (toolMenu != null) items.add(toolMenu);
7576
}
7677

77-
if (canRemove()) items.add(new RemoveNodeAction(nodeTree, this));
78-
79-
if (linkNode == null) {
78+
if (linkNode == null || element == linkNode) {
8079
items.add(new AddUserDataAction(nodeTree, this));
8180
}
8281

82+
if (canRemove()) {
83+
items.add(new RemoveNodeAction(nodeTree, this));
84+
}
85+
8386
super.fillContextMenu(nodeTree, items);
8487
}
8588

src/main/java/com/ss/editor/ui/control/model/tree/action/AddUserDataAction.java

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,22 @@
2727
import org.jetbrains.annotations.Nullable;
2828

2929
/**
30-
* The action to add a new user data.
30+
* The action to add new user data.
3131
*
3232
* @author JavaSaBr
3333
*/
3434
public class AddUserDataAction extends AbstractNodeAction<ModelChangeConsumer> {
3535

3636
private enum DataType {
37-
/**
38-
* Float data type.
39-
*/
4037
FLOAT,
41-
/**
42-
* Integer data type.
43-
*/
4438
INTEGER,
45-
/**
46-
* Vector 3 f data type.
47-
*/
4839
VECTOR3F,
49-
/**
50-
* Vector 2 f data type.
51-
*/
5240
VECTOR2F,
53-
/**
54-
* Color data type.
55-
*/
5641
COLOR,
57-
/**
58-
* Boolean data type.
59-
*/
6042
BOOLEAN,
61-
/**
62-
* String data type.
63-
*/
64-
STRING,
43+
STRING
6544
}
6645

67-
6846
@NotNull
6947
private static final String PROPERTY_NAME = "name";
7048

@@ -96,14 +74,37 @@ protected void process() {
9674
definitions.add(new PropertyDefinition(STRING, Messages.MODEL_PROPERTY_NAME, PROPERTY_NAME, ""));
9775
definitions.add(new PropertyDefinition(ENUM, Messages.MODEL_PROPERTY_DATA_TYPE, PROPERTY_DATA_TYPE, DataType.STRING));
9876

99-
final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, this::addUserData,
100-
vars -> !StringUtils.isEmpty(vars.getString(PROPERTY_NAME)));
77+
final GenericFactoryDialog dialog = new GenericFactoryDialog(definitions, this::addUserData, this::validate);
10178

10279
dialog.setTitle(Messages.ADD_USER_DATA_DIALOG_TITLE);
10380
dialog.setButtonOkText(Messages.SIMPLE_DIALOG_BUTTON_ADD);
10481
dialog.show();
10582
}
10683

84+
/**
85+
* Validate the input paramaters.
86+
*
87+
* @param vars the input paramaters.
88+
* @return true if all is ok.
89+
*/
90+
@FXThread
91+
private boolean validate(@NotNull final VarTable vars) {
92+
if(!vars.has(PROPERTY_NAME)) return false;
93+
94+
final String name = vars.getString(PROPERTY_NAME);
95+
96+
final TreeNode<?> node = getNode();
97+
final Spatial element = (Spatial) node.getElement();
98+
99+
return !StringUtils.isEmpty(name) && element.getUserData(name) == null;
100+
}
101+
102+
/**
103+
* Add new user date.
104+
*
105+
* @param vars the input paramaters.
106+
*/
107+
@FXThread
107108
private void addUserData(@NotNull final VarTable vars) {
108109

109110
final String name = vars.get(PROPERTY_NAME);

0 commit comments

Comments
 (0)