|
| 1 | +package com.ss.editor.ui.control.model.tree.action; |
| 2 | + |
| 3 | +import static com.ss.rlib.util.ObjectUtils.notNull; |
| 4 | +import com.jme3.asset.AssetKey; |
| 5 | +import com.jme3.material.Material; |
| 6 | +import com.ss.editor.Messages; |
| 7 | +import com.ss.editor.annotation.FXThread; |
| 8 | +import com.ss.editor.model.undo.editor.ChangeConsumer; |
| 9 | +import com.ss.editor.ui.Icons; |
| 10 | +import com.ss.editor.ui.control.property.operation.PropertyOperation; |
| 11 | +import com.ss.editor.ui.control.tree.NodeTree; |
| 12 | +import com.ss.editor.ui.control.tree.action.AbstractNodeAction; |
| 13 | +import com.ss.editor.ui.control.tree.node.TreeNode; |
| 14 | +import javafx.scene.image.Image; |
| 15 | +import org.jetbrains.annotations.NotNull; |
| 16 | +import org.jetbrains.annotations.Nullable; |
| 17 | + |
| 18 | +/** |
| 19 | + * The implementation of the {@link AbstractNodeAction} to make a material as embedded. |
| 20 | + * |
| 21 | + * @author JavaSaBr |
| 22 | + */ |
| 23 | +public class MakeAsEmbeddedMaterialAction extends AbstractNodeAction<ChangeConsumer> { |
| 24 | + |
| 25 | + public MakeAsEmbeddedMaterialAction(@NotNull final NodeTree<?> nodeTree, @NotNull final TreeNode<?> node) { |
| 26 | + super(nodeTree, node); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + protected @Nullable Image getIcon() { |
| 31 | + return Icons.INFLUENCER_16; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + protected @NotNull String getName() { |
| 36 | + return Messages.MODEL_NODE_TREE_ACTION_MAKE_EMBEDDED; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + @FXThread |
| 41 | + protected void process() { |
| 42 | + super.process(); |
| 43 | + |
| 44 | + final TreeNode<?> node = getNode(); |
| 45 | + final Material material = (Material) node.getElement(); |
| 46 | + |
| 47 | + final PropertyOperation<ChangeConsumer, Material, AssetKey> operation = |
| 48 | + new PropertyOperation<>(material, "AssetKey", null, material.getKey()); |
| 49 | + operation.setApplyHandler(Material::setKey); |
| 50 | + |
| 51 | + final ChangeConsumer changeConsumer = notNull(getNodeTree().getChangeConsumer()); |
| 52 | + changeConsumer.execute(operation); |
| 53 | + } |
| 54 | +} |
0 commit comments