Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.jme3.light.Light;
import com.ss.editor.annotation.FXThread;
import com.ss.editor.annotation.FromAnyThread;
import com.ss.editor.model.undo.editor.ChangeConsumer;
import com.ss.editor.ui.Icons;
import com.ss.editor.ui.control.model.tree.action.RemoveLightAction;
import com.ss.editor.ui.control.model.tree.action.RenameNodeAction;
import com.ss.editor.ui.control.model.tree.action.operation.RenameLightOperation;
import com.ss.editor.ui.control.tree.NodeTree;
import com.ss.editor.ui.control.tree.node.TreeNode;
import com.ss.rlib.util.StringUtils;
Expand All @@ -15,6 +17,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.ss.rlib.util.ObjectUtils.notNull;

/**
* The base implementation of {@link TreeNode} to present lights.
*
Expand All @@ -40,6 +44,9 @@ public LightTreeNode(@NotNull final T element, final long objectId) {
public void changeName(@NotNull final NodeTree<?> nodeTree, @NotNull final String newName) {
final T element = getElement();
element.setName(newName);

final ChangeConsumer consumer = notNull(nodeTree.getChangeConsumer());
consumer.execute(new RenameLightOperation(element.getName(), newName, element));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.ss.editor.ui.control.model.tree.action.operation;


import com.jme3.light.Light;
import com.ss.editor.model.undo.editor.ModelChangeConsumer;
import com.ss.editor.model.undo.impl.AbstractEditorOperation;
import org.jetbrains.annotations.NotNull;

public class RenameLightOperation extends AbstractEditorOperation<ModelChangeConsumer> {
/**
* The constant PROPERTY_NAME.
*/
public static final String PROPERTY_NAME = "name";

/**
* The old name.
*/
@NotNull
private final String oldName;

/**
* The new name.
*/
@NotNull
private final String newName;

/**
* The node.
*/
@NotNull
private final Light light;

/**
* Instantiates a new Rename node operation.
*
* @param oldName the old name
* @param newName the new name
* @param light the light
*/
public RenameLightOperation(@NotNull final String oldName, @NotNull final String newName, @NotNull final Light light) {
this.oldName = oldName;
this.newName = newName;
this.light = light;
}

@Override
protected void redoImpl(@NotNull final ModelChangeConsumer editor) {
EXECUTOR_MANAGER.addJMETask(() -> {
light.setName(newName);
EXECUTOR_MANAGER.addFXTask(() -> editor.notifyFXChangeProperty(light, PROPERTY_NAME));
});
}

@Override
protected void undoImpl(@NotNull final ModelChangeConsumer editor) {
EXECUTOR_MANAGER.addJMETask(() -> {
light.setName(oldName);
EXECUTOR_MANAGER.addFXTask(() -> editor.notifyFXChangeProperty(light, PROPERTY_NAME));
});
}
}