Skip to content

Commit d13d650

Browse files
committed
implemented "disable all actions"
1 parent 2f9407b commit d13d650

12 files changed

Lines changed: 215 additions & 55 deletions

src/main/java/com/ss/editor/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public class Messages {
299299
public static final String MODEL_NODE_TREE_ACTION_ADD_WHEEL;
300300
public static final String MODEL_NODE_TREE_ACTION_ADD_TERRAIN;
301301
public static final String MODEL_NODE_TREE_ACTION_ENABLE_ALL_CONTROLS;
302+
public static final String MODEL_NODE_TREE_ACTION_DISABLE_ALL_CONTROLS;
302303

303304
public static final String MODEL_PROPERTY_CULL_HINT;
304305
public static final String MODEL_PROPERTY_SHADOW_MODE;
@@ -1000,6 +1001,7 @@ public class Messages {
10001001
MODEL_NODE_TREE_ACTION_ADD_WHEEL = bundle.getString("ModelNodeTreeActionAddWheel");
10011002
MODEL_NODE_TREE_ACTION_ADD_TERRAIN = bundle.getString("ModelNodeTreeActionAddTerrain");
10021003
MODEL_NODE_TREE_ACTION_ENABLE_ALL_CONTROLS = bundle.getString("ModelNodeTreeActionEnableAllControls");
1004+
MODEL_NODE_TREE_ACTION_DISABLE_ALL_CONTROLS = bundle.getString("ModelNodeTreeActionDisableAllControls");
10031005

10041006
MODEL_PROPERTY_CULL_HINT = bundle.getString("ModelPropertyCullHint");
10051007
MODEL_PROPERTY_SHADOW_MODE = bundle.getString("ModelPropertyShadowMode");
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.ss.editor.model.undo.impl;
2+
3+
import com.jme3.scene.Node;
4+
import com.jme3.scene.control.Control;
5+
import com.ss.editor.annotation.FxThread;
6+
import com.ss.editor.annotation.JmeThread;
7+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
8+
import com.ss.rlib.util.array.Array;
9+
import org.jetbrains.annotations.NotNull;
10+
11+
/**
12+
* The implementation of {@link AbstractEditorOperation} to chane {@link com.jme3.scene.control.AbstractControl} in {@link Node}.
13+
*
14+
* @author JavaSaBr.
15+
*/
16+
public class ChangeControlsOperation extends AbstractEditorOperation<ModelChangeConsumer> {
17+
18+
/**
19+
* The controls to change.
20+
*/
21+
@NotNull
22+
private final Array<Control> controls;
23+
24+
public ChangeControlsOperation(@NotNull final Array<Control> controls) {
25+
this.controls = controls;
26+
}
27+
28+
@Override
29+
@JmeThread
30+
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
31+
EXECUTOR_MANAGER.addJmeTask(() -> {
32+
33+
for (final Control control : controls) {
34+
redoChange(control);
35+
}
36+
37+
EXECUTOR_MANAGER.addFxTask(() -> {
38+
controls.forEach(editor, (control, consumer) ->
39+
consumer.notifyFxChangeProperty(control, getPropertyName()));
40+
});
41+
});
42+
}
43+
44+
/**
45+
* Apply new changes to the control.
46+
*
47+
* @param control the control.
48+
*/
49+
@JmeThread
50+
protected void redoChange(@NotNull final Control control) {
51+
}
52+
53+
@Override
54+
@JmeThread
55+
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
56+
EXECUTOR_MANAGER.addJmeTask(() -> {
57+
58+
for (final Control control : controls) {
59+
undoChange(control);
60+
}
61+
62+
EXECUTOR_MANAGER.addFxTask(() -> {
63+
controls.forEach(editor, (control, consumer) ->
64+
consumer.notifyFxChangeProperty(control, getPropertyName()));
65+
});
66+
});
67+
}
68+
69+
/**
70+
* Revert changes for the control.
71+
*
72+
* @param control the control.
73+
*/
74+
@JmeThread
75+
protected void undoChange(@NotNull final Control control) {
76+
}
77+
78+
/**
79+
* Get the property name.
80+
*
81+
* @return the property name.
82+
*/
83+
@FxThread
84+
protected @NotNull String getPropertyName() {
85+
throw new UnsupportedOperationException();
86+
}
87+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.ss.editor.model.undo.impl;
2+
3+
import com.jme3.scene.Node;
4+
import com.jme3.scene.control.Control;
5+
import com.ss.editor.Messages;
6+
import com.ss.editor.util.ControlUtils;
7+
import com.ss.rlib.util.array.Array;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
/**
11+
* The implementation of {@link AbstractEditorOperation} to disable {@link com.jme3.scene.control.AbstractControl} in {@link Node}.
12+
*
13+
* @author JavaSaBr.
14+
*/
15+
public class DisableControlsOperation extends ChangeControlsOperation {
16+
17+
public DisableControlsOperation(@NotNull final Array<Control> controls) {
18+
super(controls);
19+
}
20+
21+
@Override
22+
protected void redoChange(final @NotNull Control control) {
23+
super.redoChange(control);
24+
ControlUtils.setEnabled(control, false);
25+
}
26+
27+
@Override
28+
protected void undoChange(final @NotNull Control control) {
29+
super.undoChange(control);
30+
ControlUtils.setEnabled(control, true);
31+
}
32+
33+
@Override
34+
protected @NotNull String getPropertyName() {
35+
return Messages.MODEL_PROPERTY_IS_ENABLED;
36+
}
37+
}

src/main/java/com/ss/editor/model/undo/impl/EnableControlsOperation.java

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,35 @@
33
import com.jme3.scene.Node;
44
import com.jme3.scene.control.Control;
55
import com.ss.editor.Messages;
6-
import com.ss.editor.annotation.JmeThread;
7-
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
86
import com.ss.editor.util.ControlUtils;
97
import com.ss.rlib.util.array.Array;
10-
import com.ss.rlib.util.array.ArrayCollectors;
118
import org.jetbrains.annotations.NotNull;
129

1310
/**
14-
* The implementation of {@link AbstractEditorOperation} to enable {@link com.jme3.scene.control.AbstractControl} in a {@link Node}.
11+
* The implementation of {@link AbstractEditorOperation} to enable {@link com.jme3.scene.control.AbstractControl} in {@link Node}.
1512
*
1613
* @author JavaSaBr.
1714
*/
18-
public class EnableControlsOperation extends AbstractEditorOperation<ModelChangeConsumer> {
19-
20-
/**
21-
* The controls to enable.
22-
*/
23-
@NotNull
24-
private final Array<Control> controls;
25-
26-
/**
27-
* The list of disabled controls.
28-
*/
29-
@NotNull
30-
private final Array<Control> wasDisabled;
15+
public class EnableControlsOperation extends ChangeControlsOperation {
3116

3217
public EnableControlsOperation(@NotNull final Array<Control> controls) {
33-
this.controls = controls;
34-
this.wasDisabled = controls.stream()
35-
.filter(control -> !ControlUtils.isEnabled(control))
36-
.collect(ArrayCollectors.toArray(Control.class));
18+
super(controls);
3719
}
3820

3921
@Override
40-
@JmeThread
41-
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
42-
EXECUTOR_MANAGER.addJmeTask(() -> {
43-
44-
for (final Control control : wasDisabled) {
45-
ControlUtils.setEnabled(control, true);
46-
}
47-
48-
EXECUTOR_MANAGER.addFxTask(() -> {
49-
wasDisabled.forEach(editor, (control, consumer) ->
50-
consumer.notifyFxChangeProperty(control, Messages.MODEL_PROPERTY_IS_ENABLED));
51-
});
52-
});
22+
protected void redoChange(final @NotNull Control control) {
23+
super.redoChange(control);
24+
ControlUtils.setEnabled(control, true);
5325
}
5426

5527
@Override
56-
@JmeThread
57-
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
58-
EXECUTOR_MANAGER.addJmeTask(() -> {
59-
60-
for (final Control control : wasDisabled) {
61-
ControlUtils.setEnabled(control, false);
62-
}
63-
64-
wasDisabled.clear();
28+
protected void undoChange(final @NotNull Control control) {
29+
super.undoChange(control);
30+
ControlUtils.setEnabled(control, false);
31+
}
6532

66-
EXECUTOR_MANAGER.addFxTask(() -> {
67-
wasDisabled.forEach(editor, (control, consumer) ->
68-
consumer.notifyFxChangeProperty(control, Messages.MODEL_PROPERTY_IS_ENABLED));
69-
});
70-
});
33+
@Override
34+
protected @NotNull String getPropertyName() {
35+
return Messages.MODEL_PROPERTY_IS_ENABLED;
7136
}
7237
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.ss.editor.ui.control.tree.action.impl;
2+
3+
import static com.ss.rlib.util.ObjectUtils.notNull;
4+
import static com.ss.rlib.util.array.ArrayCollectors.toArray;
5+
import com.jme3.scene.Spatial;
6+
import com.jme3.scene.control.Control;
7+
import com.ss.editor.Messages;
8+
import com.ss.editor.annotation.FxThread;
9+
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
10+
import com.ss.editor.model.undo.impl.DisableControlsOperation;
11+
import com.ss.editor.ui.Icons;
12+
import com.ss.editor.ui.control.tree.NodeTree;
13+
import com.ss.editor.ui.control.tree.action.AbstractNodeAction;
14+
import com.ss.editor.ui.control.tree.node.TreeNode;
15+
import com.ss.editor.util.ControlUtils;
16+
import com.ss.editor.util.NodeUtils;
17+
import com.ss.rlib.util.array.Array;
18+
import javafx.scene.image.Image;
19+
import org.jetbrains.annotations.NotNull;
20+
import org.jetbrains.annotations.Nullable;
21+
22+
/**
23+
* The action to disable all controls in a selected node.
24+
*
25+
* @author JavaSaBr
26+
*/
27+
public class DisableAllControlsAction extends AbstractNodeAction<ModelChangeConsumer> {
28+
29+
public DisableAllControlsAction(@NotNull final NodeTree<?> nodeTree, @NotNull final TreeNode<?> node) {
30+
super(nodeTree, node);
31+
}
32+
33+
@Override
34+
@FxThread
35+
protected @Nullable Image getIcon() {
36+
return Icons.STOP_16;
37+
}
38+
39+
@Override
40+
@FxThread
41+
protected @NotNull String getName() {
42+
return Messages.MODEL_NODE_TREE_ACTION_DISABLE_ALL_CONTROLS;
43+
}
44+
45+
@Override
46+
@FxThread
47+
protected void process() {
48+
49+
final Array<Control> controls = NodeUtils.children((Spatial) getNode().getElement())
50+
.flatMap(ControlUtils::controls)
51+
.filter(ControlUtils::isEnabled)
52+
.collect(toArray(Control.class));
53+
54+
final ModelChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer());
55+
changeConsumer.execute(new DisableControlsOperation(controls));
56+
}
57+
}

src/main/java/com/ss/editor/ui/control/tree/action/impl/EnableAllControlsAction.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.ss.editor.ui.control.tree.action.impl;
22

3+
import static com.ss.rlib.util.ObjectUtils.notNull;
4+
import static com.ss.rlib.util.array.ArrayCollectors.toArray;
35
import com.jme3.scene.Spatial;
46
import com.jme3.scene.control.Control;
57
import com.ss.editor.Messages;
@@ -13,15 +15,12 @@
1315
import com.ss.editor.util.ControlUtils;
1416
import com.ss.editor.util.NodeUtils;
1517
import com.ss.rlib.util.array.Array;
16-
import com.ss.rlib.util.array.ArrayCollectors;
1718
import javafx.scene.image.Image;
1819
import org.jetbrains.annotations.NotNull;
1920
import org.jetbrains.annotations.Nullable;
2021

21-
import static com.ss.rlib.util.ObjectUtils.notNull;
22-
2322
/**
24-
* The action to re-activate a physics control.
23+
* The action to enable all controls in a selected node.
2524
*
2625
* @author JavaSaBr
2726
*/
@@ -34,7 +33,7 @@ public EnableAllControlsAction(@NotNull final NodeTree<?> nodeTree, @NotNull fin
3433
@Override
3534
@FxThread
3635
protected @Nullable Image getIcon() {
37-
return Icons.REPLAY_16;
36+
return Icons.PLAY_16;
3837
}
3938

4039
@Override
@@ -48,8 +47,9 @@ public EnableAllControlsAction(@NotNull final NodeTree<?> nodeTree, @NotNull fin
4847
protected void process() {
4948

5049
final Array<Control> controls = NodeUtils.children((Spatial) getNode().getElement())
51-
.flatMap(ControlUtils::controls)
52-
.collect(ArrayCollectors.toArray(Control.class));
50+
.flatMap(ControlUtils::controls)
51+
.filter(control -> !ControlUtils.isEnabled(control))
52+
.collect(toArray(Control.class));
5353

5454
final ModelChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer());
5555
changeConsumer.execute(new EnableControlsOperation(controls));

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.ss.editor.ui.control.model.ModelNodeTree;
2525
import com.ss.editor.ui.control.tree.NodeTree;
2626
import com.ss.editor.ui.control.tree.action.impl.AddUserDataAction;
27+
import com.ss.editor.ui.control.tree.action.impl.DisableAllControlsAction;
2728
import com.ss.editor.ui.control.tree.action.impl.EnableAllControlsAction;
2829
import com.ss.editor.ui.control.tree.action.impl.RemoveNodeAction;
2930
import com.ss.editor.ui.control.tree.action.impl.control.CreateCustomControlAction;
@@ -139,6 +140,12 @@ public void fillContextMenu(@NotNull final NodeTree<?> nodeTree,
139140
.findAny()
140141
.ifPresent(c -> items.add(new EnableAllControlsAction(nodeTree, this)));
141142

143+
NodeUtils.children(element)
144+
.flatMap(ControlUtils::controls)
145+
.filter(ControlUtils::isEnabled)
146+
.findAny()
147+
.ifPresent(c -> items.add(new DisableAllControlsAction(nodeTree, this)));
148+
142149
super.fillContextMenu(nodeTree, items);
143150
}
144151

src/main/resources/messages/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ ModelNodeTreeActionSphereCollisionShape=Sphere
276276
ModelNodeTreeActionAddWheel=Add wheel
277277
ModelNodeTreeActionAddTerrain=Terrain
278278
ModelNodeTreeActionEnableAllControls=Enable all controls
279+
ModelNodeTreeActionDisableAllControls=Disable all controls
279280
280281
ModelPropertyCullHint=Cull Hint
281282
ModelPropertyShadowMode=Shadow mode

src/main/resources/messages/messages_de.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ ModelNodeTreeActionSphereCollisionShape=Kugel
276276
ModelNodeTreeActionAddWheel=Rad
277277
ModelNodeTreeActionAddTerrain=Gelände
278278
ModelNodeTreeActionEnableAllControls=Enable all controls
279+
ModelNodeTreeActionDisableAllControls=Disable all controls
279280
280281
ModelPropertyCullHint=Cull Hint
281282
ModelPropertyShadowMode=Schattenmodus

src/main/resources/messages/messages_fr.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ ModelNodeTreeActionSphereCollisionShape=Sphère
276276
ModelNodeTreeActionAddWheel=Ajouter une roue
277277
ModelNodeTreeActionAddTerrain=Terrain
278278
ModelNodeTreeActionEnableAllControls=Enable all controls
279+
ModelNodeTreeActionDisableAllControls=Disable all controls
279280

280281
ModelPropertyCullHint=Cull hint
281282
ModelPropertyShadowMode=Mode Shadow

0 commit comments

Comments
 (0)