2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.openapi
.roots
.ui
.configuration
.actions
;
19 import com
.intellij
.openapi
.actionSystem
.*;
20 import com
.intellij
.openapi
.actionSystem
.ex
.CustomComponentAction
;
21 import com
.intellij
.openapi
.actionSystem
.impl
.ActionButtonWithText
;
22 import com
.intellij
.openapi
.fileChooser
.ex
.FileNodeDescriptor
;
23 import com
.intellij
.openapi
.project
.DumbAware
;
24 import com
.intellij
.openapi
.vfs
.VirtualFile
;
25 import org
.jetbrains
.annotations
.Nullable
;
28 import javax
.swing
.tree
.DefaultMutableTreeNode
;
29 import javax
.swing
.tree
.TreePath
;
32 * @author Eugene Zhuravlev
37 public abstract class ContentEntryEditingAction
extends ToggleAction
implements CustomComponentAction
, DumbAware
{
38 protected final JTree myTree
;
40 protected ContentEntryEditingAction(JTree tree
) {
42 getTemplatePresentation().setEnabled(true);
45 public void update(AnActionEvent e
) {
47 final Presentation presentation
= e
.getPresentation();
48 presentation
.setEnabled(true);
49 final VirtualFile
[] files
= getSelectedFiles();
50 if (files
== null || files
.length
== 0) {
51 presentation
.setEnabled(false);
54 for (VirtualFile file
: files
) {
55 if (file
== null || !file
.isDirectory()) {
56 presentation
.setEnabled(false);
63 protected final VirtualFile
[] getSelectedFiles() {
64 final TreePath
[] selectionPaths
= myTree
.getSelectionPaths();
65 if (selectionPaths
== null) {
68 final VirtualFile
[] selected
= new VirtualFile
[selectionPaths
.length
];
69 for (int i
= 0; i
< selectionPaths
.length
; i
++) {
70 TreePath treePath
= selectionPaths
[i
];
71 final DefaultMutableTreeNode node
= (DefaultMutableTreeNode
)treePath
.getLastPathComponent();
72 final Object nodeDescriptor
= node
.getUserObject();
73 if (!(nodeDescriptor
instanceof FileNodeDescriptor
)) {
76 selected
[i
] = ((FileNodeDescriptor
)nodeDescriptor
).getElement().getFile();
81 public JComponent
createCustomComponent(Presentation presentation
) {
82 return new ActionButtonWithText(this, presentation
, ActionPlaces
.UNKNOWN
, ActionToolbar
.DEFAULT_MINIMUM_BUTTON_SIZE
);