2 * Copyright (c) 2000-2006 JetBrains s.r.o. All Rights Reserved.
5 package com
.intellij
.util
.xml
.tree
.actions
;
7 import com
.intellij
.openapi
.actionSystem
.AnAction
;
8 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
9 import com
.intellij
.openapi
.command
.WriteCommandAction
;
10 import com
.intellij
.openapi
.application
.Result
;
11 import com
.intellij
.util
.xml
.tree
.DomModelTreeView
;
12 import com
.intellij
.util
.xml
.tree
.DomElementsGroupNode
;
13 import com
.intellij
.util
.xml
.DomUtil
;
14 import com
.intellij
.util
.Icons
;
15 import com
.intellij
.javaee
.model
.ElementPresentationManager
;
16 import com
.sun
.corba
.se
.impl
.presentation
.rmi
.PresentationManagerImpl
;
17 import jetbrains
.fabrique
.ui
.treeStructure
.SimpleNode
;
19 import java
.lang
.reflect
.Type
;
22 * User: Sergey.Vasiliev
24 public class AddElementInCollectionAction
extends AnAction
{
25 private DomModelTreeView myTreeView
;
28 public AddElementInCollectionAction(final DomModelTreeView treeView
) {
29 myTreeView
= treeView
;
32 public void actionPerformed(AnActionEvent e
) {
33 if (myTreeView
.getTree().getSelectedNode() instanceof DomElementsGroupNode
) {
34 final DomElementsGroupNode selectedNode
= (DomElementsGroupNode
)myTreeView
.getTree().getSelectedNode();
35 new WriteCommandAction(selectedNode
.getDomElement().getParent().getManager().getProject()) {
36 protected void run(final Result result
) throws Throwable
{
37 selectedNode
.getChildDescription().addValue(selectedNode
.getDomElement());
43 public void update(AnActionEvent e
) {
44 final SimpleNode selectedNode
= myTreeView
.getTree().getSelectedNode();
45 final boolean enabled
= selectedNode
instanceof DomElementsGroupNode
;
47 e
.getPresentation().setEnabled(enabled
);
50 final Type type
= ((DomElementsGroupNode
)selectedNode
).getChildDescription().getType();
51 e
.getPresentation().setText("Add " + ElementPresentationManager
.getPresentationForClass(DomUtil
.getRawType(type
)).getElementName());
53 e
.getPresentation().setText("");
56 e
.getPresentation().setIcon(Icons
.ADD_ICON
);