KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > refactoring > actions > SafelyDeleteAction


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.refactoring.actions;
21
22 import org.netbeans.modules.xml.refactoring.RefactorRequest;
23 import org.netbeans.modules.xml.refactoring.impl.RefactoringUtil;
24 import org.netbeans.modules.xml.refactoring.ui.ReferenceableProvider;
25 import org.netbeans.modules.xml.refactoring.ui.j.spi.ui.DeleteRefactoringUI;
26 import org.netbeans.modules.xml.refactoring.ui.j.ui.RefactoringPanel;
27 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
28 import org.netbeans.modules.xml.refactoring.ui.views.WhereUsedView;
29 import org.netbeans.modules.xml.xam.Component;
30 import org.netbeans.modules.xml.xam.NamedReferenceable;
31 import org.netbeans.modules.xml.xam.Referenceable;
32 import org.openide.nodes.Node;
33 import org.openide.text.CloneableEditorSupport;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36 import org.openide.util.actions.CookieAction;
37 import org.openide.windows.TopComponent;
38
39 /**
40  * Remove the selected component(s) from the schema model. If the components
41  * are referenced elsewhere, the user will be asked for confirmation before
42  * removing them.
43  *
44  * @author Nathan Fiedler
45  * @author Jerri Lockhart
46  */

47 public class SafelyDeleteAction extends CookieAction {
48     /** silence compiler warnings */
49     private static final long serialVersionUID = 1L;
50     
51     private static final Class JavaDoc[] COOKIE_ARRAY =
52             new Class JavaDoc[] {ReferenceableProvider.class };
53     
54     /**
55      * Creates a new instance of RemoveAction.
56      */

57     public SafelyDeleteAction() {
58         putValue("noIconInMenu", Boolean.TRUE); // NOI18N
59
}
60     
61     protected boolean asynchronous() {
62         return false;
63     }
64     
65     protected boolean enable(Node[] nodes) {
66         if (super.enable(nodes)) {
67             Referenceable ref = AnalysisUtilities.getReferenceable(nodes);
68             return ref instanceof NamedReferenceable &&
69                     RefactoringUtil.isWritable(RefactorRequest.getModel(ref)) &&
70                     nodes[0].canDestroy();
71         }
72         return false;
73     }
74     
75     public HelpCtx getHelpCtx() {
76         // Leverage the help of the core action.
77
return HelpCtx.DEFAULT_HELP;
78     }
79     
80     public String JavaDoc getName() {
81         return NbBundle.getMessage(SafelyDeleteAction.class, "LBL_Remove");
82     }
83     
84     /**
85      * Perform the action based on the currently activated nodes.
86      * Note that if the source of the event triggering this action was itself
87      * a node, that node will be the sole argument to this method, rather
88      * than the activated nodes.
89      *
90      *
91      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
92      */

93     protected void performAction(Node[] nodes) {
94         
95         assert nodes.length==1:
96             "Length of nodes array should be 1";
97         Referenceable ref = AnalysisUtilities.getReferenceable(nodes);
98         if (ref instanceof Component && ((Component)ref).getParent() == null) {
99             return;
100         }
101         assert ref instanceof NamedReferenceable:"The NamedReferenceable for this node should not be null";
102         WhereUsedView wuv = new WhereUsedView(ref);
103         DeleteRefactoringUI ui = new DeleteRefactoringUI(wuv, NamedReferenceable.class.cast(ref));
104         TopComponent activetc = TopComponent.getRegistry().getActivated();
105         if (activetc instanceof CloneableEditorSupport.Pane) {
106          // new RefactoringPanel(ui, activetc);
107
} else {
108           // new RefactoringPanel(ui);
109
}
110     }
111     
112   
113     
114     protected int mode() {
115         return CookieAction.MODE_EXACTLY_ONE;
116     }
117     
118     
119     
120     protected Class JavaDoc[] cookieClasses() {
121         return COOKIE_ARRAY;
122     }
123 }
124
Popular Tags