Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding RenameLightOperation to change the name of a light #9

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
@@ -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));
});
}
}