|
3 | 3 | import com.jme3.scene.Node; |
4 | 4 | import com.jme3.scene.control.Control; |
5 | 5 | import com.ss.editor.Messages; |
6 | | -import com.ss.editor.annotation.JmeThread; |
7 | | -import com.ss.editor.model.undo.editor.ModelChangeConsumer; |
8 | 6 | import com.ss.editor.util.ControlUtils; |
9 | 7 | import com.ss.rlib.util.array.Array; |
10 | | -import com.ss.rlib.util.array.ArrayCollectors; |
11 | 8 | import org.jetbrains.annotations.NotNull; |
12 | 9 |
|
13 | 10 | /** |
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}. |
15 | 12 | * |
16 | 13 | * @author JavaSaBr. |
17 | 14 | */ |
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 { |
31 | 16 |
|
32 | 17 | 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); |
37 | 19 | } |
38 | 20 |
|
39 | 21 | @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); |
53 | 25 | } |
54 | 26 |
|
55 | 27 | @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 | + } |
65 | 32 |
|
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; |
71 | 36 | } |
72 | 37 | } |
0 commit comments