KickJava   Java API By Example, From Geeks To Geeks.

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


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  * RefactoringUndoAction.java
21  *
22  * Created on May 25, 2006, 12:17 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 RefactoringUndoAction 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     public void performAction() {
55     UndoRedoProgress progress = new UndoRedoProgress();
56     progress.start();
57     try {
58         RefactoringManager.getInstance().undo();
59     } finally {
60         progress.stop();
61     }
62     }
63     
64     /**
65      * Test whether the action should be enabled based
66      * on the currently activated nodes.
67      *
68      *
69      * @param activatedNodes current activated nodes, may be empty but not <code>null</code>
70      * @return <code>true</code> to be enabled, <code>false</code> to be disabled
71      */

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

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

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

127     protected boolean asynchronous() {
128         return true;
129     }
130 }
131
Popular Tags