KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > spi > impl > RSMDataObjectAction


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.refactoring.spi.impl;
20
21 import java.awt.event.ActionEvent JavaDoc;
22 import javax.swing.Action JavaDoc;
23 import javax.swing.JMenuItem JavaDoc;
24 import org.netbeans.api.fileinfo.NonRecursiveFolder;
25 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
26 import org.openide.actions.RenameAction;
27 import org.openide.loaders.DataObject;
28 import org.openide.loaders.DataShadow;
29 import org.openide.util.ContextAwareAction;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.Lookup;
32
33 import org.openide.util.actions.SystemAction;
34 import org.openide.util.actions.Presenter.Menu;
35 import org.openide.util.actions.Presenter.Popup;
36
37 /** Action that displays refactoring submenu action on JavaDataObject
38  * and delegates to it.
39  *
40  * @author Martin Matula, Jan Becicka
41  */

42 public class RSMDataObjectAction extends SystemAction implements Menu, Popup, ContextAwareAction {
43     // create delegate (RefactoringSubMenuAction)
44
private final RefactoringSubMenuAction action = new RefactoringSubMenuAction(false);
45     
46     private static final RenameAction renameAction = (RenameAction) SystemAction.get(RenameAction.class);
47     
48     public void actionPerformed(ActionEvent JavaDoc ev) {
49         // do nothing -- should never be called
50
}
51     
52     public String JavaDoc getName() {
53         return (String JavaDoc) action.getValue(Action.NAME);
54     }
55     
56     public HelpCtx getHelpCtx() {
57         return HelpCtx.DEFAULT_HELP;
58         // If you will provide context help then use:
59
// return new HelpCtx(RSMEditorActionAction.class);
60
}
61     
62     public JMenuItem JavaDoc getMenuPresenter() {
63         return action.getMenuPresenter();
64     }
65     
66     public JMenuItem JavaDoc getPopupPresenter() {
67         return action.getPopupPresenter();
68     }
69     
70     public Action JavaDoc createContextAwareInstance(Lookup actionContext) {
71         DataObject dobj = (DataObject) actionContext.lookup(DataObject.class);
72         while (dobj instanceof DataShadow) {
73             dobj = ((DataShadow) dobj).getOriginal();
74         }
75         
76         boolean isRecursive = !(actionContext.lookup(NonRecursiveFolder.class) != null);
77         Action JavaDoc a = RefactoringActionsFactory.renameAction().createContextAwareInstance(actionContext);
78         if (a.isEnabled()) {
79             return this;
80         } else {
81             return renameAction.createContextAwareInstance(actionContext);
82         }
83     }
84 }
85     
86
Popular Tags