1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
13 import org.eclipse.jface.text.ITextSelection;
15 import org.eclipse.ui.PlatformUI;
17 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
19 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
20 import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
21 import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
22 import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
23 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
26 * Extracts an expression into a new local variable and replaces all occurrences of
27 * the expression with the local variable.
30 * This class may be instantiated; it is not intended to be subclassed.
35 * @noextend This class is not intended to be subclassed by clients.
37 public class ExtractTempAction extends SelectionDispatchAction {
39 public final JavaEditor fEditor;
42 * Note: This constructor is for internal use only. Clients should not call this constructor.
43 * @param editor the java editor
45 * @noreference This method is not intended to be referenced by clients.
47 public ExtractTempAction(JavaEditor editor) {
48 super(editor.getEditorSite());
49 setText(RefactoringMessages.ExtractTempAction_label);
51 setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
52 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_TEMP_ACTION);
56 * Method declared on SelectionDispatchAction
59 public void selectionChanged(ITextSelection selection) {
60 setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
64 * Note: This method is for internal use only. Clients should not call this method.
65 * @param selection the Java text selection (internal type)
67 * @noreference This method is not intended to be referenced by clients.
70 public void selectionChanged(JavaTextSelection selection) {
71 setEnabled(RefactoringAvailabilityTester.isExtractTempAvailable(selection));
75 * Method declared on SelectionDispatchAction
78 public void run(ITextSelection selection) {
79 fEditor.generated_3768409073535194677(this, selection);