1 11 package org.eclipse.jdt.ui.actions; 12 13 import org.eclipse.core.runtime.CoreException; 14 15 import org.eclipse.jface.text.ITextSelection; 16 17 import org.eclipse.ui.PlatformUI; 18 19 import org.eclipse.jdt.core.ICompilationUnit; 20 21 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester; 22 import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter; 23 24 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 25 import org.eclipse.jdt.internal.ui.actions.ActionUtil; 26 import org.eclipse.jdt.internal.ui.actions.SelectionConverter; 27 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; 28 import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection; 29 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; 30 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 31 32 41 public class IntroduceParameterAction extends SelectionDispatchAction { 42 43 private final JavaEditor fEditor; 44 45 49 public IntroduceParameterAction(JavaEditor editor) { 50 super(editor.getEditorSite()); 51 setText(RefactoringMessages.IntroduceParameterAction_label); 52 fEditor= editor; 53 setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null); 54 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.INTRODUCE_PARAMETER_ACTION); 55 } 56 57 60 public void selectionChanged(ITextSelection selection) { 61 setEnabled((fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null)); 62 } 63 64 67 public void selectionChanged(JavaTextSelection selection) { 68 setEnabled(RefactoringAvailabilityTester.isIntroduceParameterAvailable(selection)); 69 } 70 71 74 public void run(ITextSelection selection) { 75 if (!ActionUtil.isEditable(fEditor)) 76 return; 77 try{ 78 ICompilationUnit unit= SelectionConverter.getInputAsCompilationUnit(fEditor); 79 RefactoringExecutionStarter.startIntroduceParameter(unit, selection.getOffset(), selection.getLength(), getShell()); 80 } catch (CoreException e){ 81 ExceptionHandler.handle(e, RefactoringMessages.IntroduceParameterAction_dialog_title, RefactoringMessages.NewTextRefactoringAction_exception); 82 } 83 } 84 } 85 | Popular Tags |