1 package com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.actions
;
3 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
4 import com
.intellij
.openapi
.actionSystem
.CommonShortcuts
;
5 import com
.intellij
.openapi
.project
.DumbAwareAction
;
6 import com
.intellij
.openapi
.project
.ProjectBundle
;
7 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.ArtifactEditorEx
;
8 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.LayoutTreeSelection
;
9 import com
.intellij
.openapi
.roots
.ui
.configuration
.artifacts
.nodes
.PackagingElementNode
;
10 import com
.intellij
.packaging
.elements
.PackagingElement
;
11 import com
.intellij
.packaging
.elements
.RenameablePackagingElement
;
13 import javax
.swing
.tree
.TreePath
;
18 public class RenamePackagingElementAction
extends DumbAwareAction
{
19 private final ArtifactEditorEx myArtifactEditor
;
21 public RenamePackagingElementAction(ArtifactEditorEx artifactEditor
) {
22 super(ProjectBundle
.message("action.name.rename.packaging.element"));
23 registerCustomShortcutSet(CommonShortcuts
.getRename(), artifactEditor
.getLayoutTreeComponent().getTreePanel());
24 myArtifactEditor
= artifactEditor
;
28 public void update(AnActionEvent e
) {
29 final LayoutTreeSelection selection
= myArtifactEditor
.getLayoutTreeComponent().getSelection();
30 final PackagingElement
<?
> element
= selection
.getElementIfSingle();
31 final boolean visible
= element
instanceof RenameablePackagingElement
&& ((RenameablePackagingElement
)element
).canBeRenamed();
32 e
.getPresentation().setEnabled(visible
);
33 e
.getPresentation().setVisible(visible
);
36 public void actionPerformed(AnActionEvent e
) {
37 final LayoutTreeSelection selection
= myArtifactEditor
.getLayoutTreeComponent().getSelection();
38 final PackagingElementNode
<?
> node
= selection
.getNodeIfSingle();
39 if (node
== null) return;
40 final TreePath path
= selection
.getPath(node
);
41 myArtifactEditor
.getLayoutTreeComponent().ensureRootIsWritable();
42 myArtifactEditor
.getLayoutTreeComponent().rename(path
);