1 package com
.intellij
.openapi
.roots
.ui
.configuration
.actions
;
3 import com
.intellij
.openapi
.actionSystem
.*;
4 import com
.intellij
.openapi
.actionSystem
.ex
.CustomComponentAction
;
5 import com
.intellij
.openapi
.actionSystem
.impl
.ActionButtonWithText
;
6 import com
.intellij
.openapi
.fileChooser
.ex
.FileNodeDescriptor
;
7 import com
.intellij
.openapi
.project
.DumbAware
;
8 import com
.intellij
.openapi
.vfs
.VirtualFile
;
9 import org
.jetbrains
.annotations
.Nullable
;
12 import javax
.swing
.tree
.DefaultMutableTreeNode
;
13 import javax
.swing
.tree
.TreePath
;
16 * @author Eugene Zhuravlev
21 public abstract class ContentEntryEditingAction
extends ToggleAction
implements CustomComponentAction
, DumbAware
{
22 protected final JTree myTree
;
24 protected ContentEntryEditingAction(JTree tree
) {
26 getTemplatePresentation().setEnabled(true);
29 public void update(AnActionEvent e
) {
31 final Presentation presentation
= e
.getPresentation();
32 presentation
.setEnabled(true);
33 final VirtualFile
[] files
= getSelectedFiles();
34 if (files
== null || files
.length
== 0) {
35 presentation
.setEnabled(false);
38 for (VirtualFile file
: files
) {
39 if (file
== null || !file
.isDirectory()) {
40 presentation
.setEnabled(false);
47 protected final VirtualFile
[] getSelectedFiles() {
48 final TreePath
[] selectionPaths
= myTree
.getSelectionPaths();
49 if (selectionPaths
== null) {
52 final VirtualFile
[] selected
= new VirtualFile
[selectionPaths
.length
];
53 for (int i
= 0; i
< selectionPaths
.length
; i
++) {
54 TreePath treePath
= selectionPaths
[i
];
55 final DefaultMutableTreeNode node
= (DefaultMutableTreeNode
)treePath
.getLastPathComponent();
56 final Object nodeDescriptor
= node
.getUserObject();
57 if (!(nodeDescriptor
instanceof FileNodeDescriptor
)) {
60 selected
[i
] = ((FileNodeDescriptor
)nodeDescriptor
).getElement().getFile();
65 public JComponent
createCustomComponent(Presentation presentation
) {
66 return new ActionButtonWithText(this, presentation
, ActionPlaces
.UNKNOWN
, ActionToolbar
.DEFAULT_MINIMUM_BUTTON_SIZE
);