]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-after/ui/org/eclipse/jdt/ui/actions/ExtractTempAction.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-after / ui / org / eclipse / jdt / ui / actions / ExtractTempAction.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.ui.actions;
12
13 import org.eclipse.jface.text.ITextSelection;
14
15 import org.eclipse.ui.PlatformUI;
16
17 import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
18
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;
24
25 /**
26  * Extracts an expression into a new local variable and replaces all occurrences of
27  * the expression with the local variable.
28  *
29  * <p>
30  * This class may be instantiated; it is not intended to be subclassed.
31  * </p>
32  *
33  * @since 2.0
34  *
35  * @noextend This class is not intended to be subclassed by clients.
36  */
37 public class ExtractTempAction extends SelectionDispatchAction {
38
39         public final JavaEditor fEditor;
40
41         /**
42          * Note: This constructor is for internal use only. Clients should not call this constructor.
43          * @param editor the java editor
44          *
45          * @noreference This method is not intended to be referenced by clients.
46          */
47         public ExtractTempAction(JavaEditor editor) {
48                 super(editor.getEditorSite());
49                 setText(RefactoringMessages.ExtractTempAction_label);
50                 fEditor= editor;
51                 setEnabled(SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
52                 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.EXTRACT_TEMP_ACTION);
53         }
54
55         /* (non-Javadoc)
56          * Method declared on SelectionDispatchAction
57          */
58         @Override
59         public void selectionChanged(ITextSelection selection) {
60                 setEnabled(fEditor != null && SelectionConverter.getInputAsCompilationUnit(fEditor) != null);
61         }
62
63         /**
64          * Note: This method is for internal use only. Clients should not call this method.
65          * @param selection the Java text selection (internal type)
66          *
67          * @noreference This method is not intended to be referenced by clients.
68          */
69         @Override
70         public void selectionChanged(JavaTextSelection selection) {
71                 setEnabled(RefactoringAvailabilityTester.isExtractTempAvailable(selection));
72         }
73
74         /* (non-Javadoc)
75          * Method declared on SelectionDispatchAction
76          */
77         @Override
78         public void run(ITextSelection selection) {
79                 fEditor.generated_3768409073535194677(this, selection);
80         }
81 }