KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RefactoringRedoAction.java
21  *
22  * Created on May 25, 2006, 12:19 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.xml.refactoring.actions;
29
30 import java.text.MessageFormat JavaDoc;
31 import org.netbeans.modules.xml.refactoring.RefactoringManager;
32 import org.netbeans.modules.xml.refactoring.impl.UndoRedoProgress;
33 import org.openide.nodes.Node;
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36 import org.openide.util.RequestProcessor;
37 import org.openide.util.actions.CallableSystemAction;
38
39 /**
40  *
41  * @author Jeri Lockhart
42  */

43 public class RefactoringRedoAction extends CallableSystemAction {
44     
45     private static final long serialVersionUID = 1L;
46     
47     /**
48      * Perform the action based on the currently activated nodes.
49      * Note that if the source of the event triggering this action was itself
50      * a node, that node will be the sole argument to this method, rather
51      * than the activated nodes.
52      *
53      *
54      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
55      */

56     public void performAction() {
57     UndoRedoProgress progress = new UndoRedoProgress();
58     progress.start();
59     try {
60         RefactoringManager.getInstance().redo();
61     } finally {
62         progress.stop();
63     }
64     }
65     
66     /**
67      * Test whether the action should be enabled based
68      * on the currently activated nodes.
69      *
70      *
71      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
72      * @return <code>true</code> to be enabled, <code>false</code> to be disabled
73      */

74     public boolean isEnabled() {
75         return RefactoringManager.getInstance().canRedo();
76     }
77     
78     /**
79      * Get a human presentable name of the action.
80      * This may be
81      * presented as an item in a menu.
82      * <p>Using the normal menu presenters, an included ampersand
83      * before a letter will be treated as the name of a mnemonic.
84      *
85      * @return the name of the action
86      */

87     public String JavaDoc getName() {
88         String JavaDoc redoType = ""; //NOI18N
89
if (RefactoringManager.getInstance().canRedo()) {
90             redoType =
91                     RefactoringManager.getInstance().getLastRefactorRequest().getDescription();
92             
93             return MessageFormat.format(NbBundle.getMessage(RefactoringRedoAction.class,
94                     "LBL_Redo"),
95                     new Object JavaDoc[]{redoType});
96         }
97         return NbBundle.getMessage(RefactoringUndoAction.class,
98                 "LBL_Redo_Disabled");
99     }
100     
101     /**
102      * Get a help context for the action.
103      *
104      * @return the help context for this action
105      */

106     public HelpCtx getHelpCtx() {
107         return HelpCtx.DEFAULT_HELP;
108     }
109     
110     /**
111      * If true, this action should be performed asynchronously in a private thread.
112      * If false, it will be performed synchronously as called in the event thread.
113      * <p>The default value is true for compatibility reasons; subclasses are strongly
114      * encouraged to override it to be false, and to either do their work promptly
115      * in the event thread and return, or to somehow do work asynchronously (for example
116      * using {@link RequestProcessor#getDefault}).
117      * <p class="nonnormative">You may currently set the global default to false
118      * by setting the system property
119      * <code>org.openide.util.actions.CallableSystemAction.synchronousByDefault</code>
120      * to <code>true</code>.</p>
121      * <p class="nonnormative">When true, the current implementation also provides for a wait cursor during
122      * the execution of the action. Subclasses which override to return false should
123      * consider directly providing a wait or busy cursor if the nature of the action
124      * merits it.</p>
125      *
126      * @return true if this action should automatically be performed asynchronously
127      * @since 4.11
128      */

129     protected boolean asynchronous() {
130     return true;
131     }
132     
133 }
134
Popular Tags