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
.util
.xml
.tree
.actions
;
19 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
20 import com
.intellij
.openapi
.application
.ApplicationBundle
;
21 import com
.intellij
.openapi
.application
.Result
;
22 import com
.intellij
.openapi
.command
.WriteCommandAction
;
23 import com
.intellij
.openapi
.ui
.Messages
;
24 import com
.intellij
.openapi
.util
.IconLoader
;
25 import com
.intellij
.ui
.treeStructure
.SimpleNode
;
26 import com
.intellij
.util
.xml
.DomElement
;
27 import com
.intellij
.util
.xml
.DomFileElement
;
28 import com
.intellij
.util
.xml
.DomUtil
;
29 import com
.intellij
.util
.xml
.ElementPresentation
;
30 import com
.intellij
.util
.xml
.tree
.BaseDomElementNode
;
31 import com
.intellij
.util
.xml
.tree
.DomFileElementNode
;
32 import com
.intellij
.util
.xml
.tree
.DomModelTreeView
;
35 * User: Sergey.Vasiliev
37 public class DeleteDomElement
extends BaseDomTreeAction
{
39 public DeleteDomElement() {
42 public DeleteDomElement(final DomModelTreeView treeView
) {
46 public void actionPerformed(AnActionEvent e
, DomModelTreeView treeView
) {
47 final SimpleNode selectedNode
= treeView
.getTree().getSelectedNode();
49 if (selectedNode
instanceof BaseDomElementNode
) {
51 if (selectedNode
instanceof DomFileElementNode
) {
52 e
.getPresentation().setVisible(false);
56 final DomElement domElement
= ((BaseDomElementNode
)selectedNode
).getDomElement();
58 final int ret
= Messages
.showOkCancelDialog(getPresentationText(selectedNode
) + "?", ApplicationBundle
.message("action.remove"),
59 Messages
.getQuestionIcon());
61 new WriteCommandAction(domElement
.getManager().getProject(), DomUtil
.getFile(domElement
)) {
62 protected void run(final Result result
) throws Throwable
{
63 domElement
.undefine();
70 public void update(AnActionEvent e
, DomModelTreeView treeView
) {
71 final SimpleNode selectedNode
= treeView
.getTree().getSelectedNode();
73 if (selectedNode
instanceof DomFileElementNode
) {
74 e
.getPresentation().setVisible(false);
78 boolean enabled
= false;
79 if (selectedNode
instanceof BaseDomElementNode
) {
80 final DomElement domElement
= ((BaseDomElementNode
)selectedNode
).getDomElement();
81 if (domElement
.isValid() && DomUtil
.hasXml(domElement
) && !(domElement
.getParent() instanceof DomFileElement
)) {
86 e
.getPresentation().setEnabled(enabled
);
90 e
.getPresentation().setText(getPresentationText(selectedNode
));
93 e
.getPresentation().setText(ApplicationBundle
.message("action.remove"));
96 e
.getPresentation().setIcon(IconLoader
.getIcon("/general/remove.png"));
99 private static String
getPresentationText(final SimpleNode selectedNode
) {
100 String removeString
= ApplicationBundle
.message("action.remove");
101 final ElementPresentation presentation
= ((BaseDomElementNode
)selectedNode
).getDomElement().getPresentation();
102 removeString
+= " " + presentation
.getTypeName() +
103 (presentation
.getElementName() == null || presentation
.getElementName().trim().length() == 0?
"" : ": " + presentation
.getElementName());