1 11 package org.eclipse.ltk.ui.refactoring; 12 13 import java.lang.reflect.InvocationTargetException ; 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 53 public class RedoRefactoringAction extends UndoManagerAction implements IWorkbenchWindowActionDelegate { 54 55 private int fPatternLength; 56 57 60 public RedoRefactoringAction() { 61 } 62 63 66 protected String getName() { 67 return RefactoringUIMessages.RedoRefactoringAction_name; 68 } 69 70 73 protected IRunnableWithProgress createOperation(Shell parent) { 74 final IValidationCheckResultQuery query= new Query(parent, RefactoringUIMessages.RedoRefactoringAction_error_title) { 75 protected String getFullMessage(String 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 { 83 try { 84 RefactoringCore.getUndoManager().performRedo(query, pm); 85 } catch (CoreException e) { 86 throw new InvocationTargetException (e); 87 } 88 } 89 }; 90 } 91 92 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 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 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 getActionText() { 134 return shortenText(Messages.format( 135 RefactoringUIMessages.RedoRefactoringAction_extendedLabel, 136 RefactoringCore.getUndoManager().peekRedoName()), fPatternLength); 137 } 138 } 139 | Popular Tags |