KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > ui > refactoring > RedoRefactoringAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ltk.ui.refactoring;
12
13 import java.lang.reflect.InvocationTargetException JavaDoc;
14
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IProgressMonitor;
17
18 import org.eclipse.swt.widgets.Shell;
19
20 import org.eclipse.jface.action.IAction;
21 import org.eclipse.jface.operation.IRunnableWithProgress;
22 import org.eclipse.jface.viewers.ISelection;
23
24 import org.eclipse.ui.IWorkbenchWindowActionDelegate;
25
26 import org.eclipse.ltk.core.refactoring.IUndoManager;
27 import org.eclipse.ltk.core.refactoring.IValidationCheckResultQuery;
28 import org.eclipse.ltk.core.refactoring.RefactoringCore;
29 import org.eclipse.ltk.core.refactoring.UndoManagerAdapter;
30 import org.eclipse.ltk.internal.ui.refactoring.Messages;
31 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages;
32 import org.eclipse.ltk.internal.ui.refactoring.UndoManagerAction;
33
34 /**
35  * The refactoring redo action. When executed the action performs
36  * the top most change from the refactoring undo manager's redo
37  * stack.
38  * <p>
39  * The action is typically added to a global refactoring menu via
40  * the <code>org.eclipse.ui.actionSets</code> extension point.
41  * </p>
42  * <p>
43  * Note: this class isn't intended to be subclassed. Clients are only
44  * allowed to instantiate the class or to reference it from an action
45  * set.
46  * </p>
47  *
48  * @deprecated This action is now longer needed. Undo is now performed via the
49  * global undo/redo stack provided by <code>org.eclipse.core.commands</code>.
50  *
51  * @since 3.0
52  */

53 public class RedoRefactoringAction extends UndoManagerAction implements IWorkbenchWindowActionDelegate {
54
55     private int fPatternLength;
56
57     /**
58      * Creates a new redo refactoring action.
59      */

60     public RedoRefactoringAction() {
61     }
62
63     /* (non-Javadoc)
64      * Method declared in UndoManagerAction
65      */

66     protected String JavaDoc getName() {
67         return RefactoringUIMessages.RedoRefactoringAction_name;
68     }
69     
70     /* (non-Javadoc)
71      * Method declared in UndoManagerAction
72      */

73     protected IRunnableWithProgress createOperation(Shell parent) {
74         final IValidationCheckResultQuery query= new Query(parent, RefactoringUIMessages.RedoRefactoringAction_error_title) {
75             protected String JavaDoc getFullMessage(String JavaDoc errorMessage) {
76                 return Messages.format(
77                     RefactoringUIMessages.RedoRefactoringAction_error_message,
78                     errorMessage);
79             }
80         };
81         return new IRunnableWithProgress(){
82             public void run(IProgressMonitor pm) throws InvocationTargetException JavaDoc {
83                 try {
84                     RefactoringCore.getUndoManager().performRedo(query, pm);
85                 } catch (CoreException e) {
86                     throw new InvocationTargetException JavaDoc(e);
87                 }
88             }
89         };
90     }
91     
92     /* (non-Javadoc)
93      * Method declared in UndoManagerAction
94      */

95     protected UndoManagerAdapter createUndoManagerListener() {
96         return new UndoManagerAdapter() {
97             public void redoStackChanged(IUndoManager manager) {
98                 IAction action= getAction();
99                 if (action == null)
100                     return;
101                 boolean enabled= false;
102                 String JavaDoc text= null;
103                 if (manager.anythingToRedo()) {
104                     enabled= true;
105                     text= getActionText();
106                 } else {
107                     text= RefactoringUIMessages.RedoRefactoringAction_label;
108                 }
109                 action.setEnabled(enabled);
110                 action.setText(text);
111             }
112         };
113     }
114         
115     /* (non-Javadoc)
116      * Method declared in IActionDelegate
117      */

118     public void selectionChanged(IAction action, ISelection s) {
119         if (!isHooked()) {
120             hookListener(action);
121             fPatternLength= RefactoringUIMessages.RedoRefactoringAction_extendedLabel.length();
122             IUndoManager undoManager = RefactoringCore.getUndoManager();
123             if (undoManager.anythingToRedo()) {
124                 if (undoManager.peekRedoName() != null)
125                     action.setText(getActionText());
126                 action.setEnabled(true);
127             } else {
128                 action.setEnabled(false);
129             }
130         }
131     }
132     
133     private String JavaDoc getActionText() {
134         return shortenText(Messages.format(
135             RefactoringUIMessages.RedoRefactoringAction_extendedLabel,
136             RefactoringCore.getUndoManager().peekRedoName()), fPatternLength);
137     }
138 }
139
Popular Tags