]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
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.internal.ui.refactoring; | |
12 | ||
13 | import org.eclipse.swt.SWT; | |
14 | import org.eclipse.swt.events.ModifyEvent; | |
15 | import org.eclipse.swt.events.ModifyListener; | |
16 | import org.eclipse.swt.layout.GridData; | |
17 | import org.eclipse.swt.layout.GridLayout; | |
18 | import org.eclipse.swt.widgets.Button; | |
19 | import org.eclipse.swt.widgets.Composite; | |
20 | import org.eclipse.swt.widgets.Label; | |
21 | import org.eclipse.swt.widgets.Text; | |
22 | ||
23 | import org.eclipse.jface.dialogs.Dialog; | |
24 | import org.eclipse.jface.dialogs.IDialogSettings; | |
25 | ||
26 | import org.eclipse.ui.PlatformUI; | |
27 | ||
28 | import org.eclipse.ltk.ui.refactoring.RefactoringWizard; | |
29 | import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; | |
30 | ||
31 | import org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring; | |
32 | ||
33 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
34 | import org.eclipse.jdt.internal.ui.JavaPlugin; | |
35 | import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler; | |
36 | ||
37 | public class ConvertAnonymousToNestedWizard extends RefactoringWizard { | |
38 | ||
39 | /** | |
40 | * The dialog setting section for <code>ConvertAnonymousToNestedWizard</code>. | |
41 | * | |
42 | * @since 3.7 | |
43 | */ | |
44 | static final String DIALOG_SETTING_SECTION= "ConvertAnonymousToNestedWizard"; //$NON-NLS-1$ | |
45 | ||
46 | public ConvertAnonymousToNestedWizard(ConvertAnonymousToNestedRefactoring ref) { | |
47 | super(ref, PREVIEW_EXPAND_FIRST_NODE | DIALOG_BASED_USER_INTERFACE); | |
48 | setDefaultPageTitle(RefactoringMessages.ConvertAnonymousToNestedAction_wizard_title); | |
49 | setDialogSettings(JavaPlugin.getDefault().getDialogSettings()); | |
50 | } | |
51 | ||
52 | /* non java-doc | |
53 | * @see RefactoringWizard#addUserInputPages | |
54 | */ | |
55 | @Override | |
56 | protected void addUserInputPages(){ | |
57 | addPage(new ConvertAnonymousToNestedInputPage()); | |
58 | } | |
59 | ||
60 | public static class ConvertAnonymousToNestedInputPage extends UserInputWizardPage { | |
61 | ||
62 | private static final String DESCRIPTION = RefactoringMessages.ConvertAnonymousToNestedInputPage_description; | |
63 | public static final String PAGE_NAME= "ConvertAnonymousToNestedInputPage";//$NON-NLS-1$ | |
64 | ||
65 | /** | |
66 | * Stores the value of the declare as static option. | |
67 | * | |
68 | * @since 3.7 | |
69 | */ | |
70 | public static final String DECLARE_AS_STATIC= "DeclareAsStatic"; //$NON-NLS-1$ | |
71 | ||
72 | /** | |
73 | * Stores the value of the declare as final option. | |
74 | * | |
75 | * @since 3.7 | |
76 | */ | |
77 | public static final String DECLARE_AS_FINAL= "DeclareAsFinal"; //$NON-NLS-1$ | |
78 | ||
79 | /** | |
80 | * Stores the value of visibility control option. | |
81 | * | |
82 | * @since 3.7 | |
83 | */ | |
84 | public static final String VISIBILITY_CONTROL= "VisibilityControl"; //$NON-NLS-1$ | |
85 | ||
86 | /** | |
87 | * Stores the dialog settings. | |
88 | * | |
89 | * @since 3.7 | |
90 | */ | |
91 | public IDialogSettings fSettings; | |
92 | ||
93 | public ConvertAnonymousToNestedInputPage() { | |
94 | super(PAGE_NAME); | |
95 | setDescription(DESCRIPTION); | |
96 | } | |
97 | ||
98 | /** | |
99 | * Initializes the default settings for the dialog options. | |
100 | * | |
101 | * @since 3.7 | |
102 | */ | |
103 | private void initializeDefaultSettings() { | |
104 | fSettings= getDialogSettings().getSection(DIALOG_SETTING_SECTION); | |
105 | if (fSettings == null) { | |
106 | fSettings= getDialogSettings().addNewSection(DIALOG_SETTING_SECTION); | |
107 | fSettings.put(DECLARE_AS_STATIC, getConvertRefactoring().getDeclareStatic()); | |
108 | fSettings.put(DECLARE_AS_FINAL, getConvertRefactoring().getDeclareFinal()); | |
109 | fSettings.put(VISIBILITY_CONTROL, getConvertRefactoring().getVisibility()); | |
110 | } | |
111 | } | |
112 | ||
113 | public void createControl(Composite parent) { | |
114 | Composite result= new Composite(parent, SWT.NONE); | |
115 | setControl(result); | |
116 | GridLayout layout= new GridLayout(); | |
117 | layout.numColumns= 2; | |
118 | layout.verticalSpacing= 8; | |
119 | result.setLayout(layout); | |
120 | ||
121 | initializeDefaultSettings(); | |
122 | addVisibilityControl(result); | |
123 | Text textField= addFieldNameField(result); | |
124 | addDeclareFinalCheckbox(result); | |
125 | addDeclareAsStaticCheckbox(result); | |
126 | ||
127 | textField.setFocus(); | |
128 | setPageComplete(false); | |
129 | Dialog.applyDialogFont(result); | |
130 | PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_WIZARD_PAGE); | |
131 | } | |
132 | ||
133 | private Text addFieldNameField(Composite result) { | |
134 | Label nameLabel= new Label(result, SWT.NONE); | |
135 | nameLabel.setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_class_name); | |
136 | nameLabel.setLayoutData(new GridData()); | |
137 | ||
138 | final Text classNameField= new Text(result, SWT.BORDER | SWT.SINGLE); | |
139 | classNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
140 | classNameField.addModifyListener(new ModifyListener(){ | |
141 | public void modifyText(ModifyEvent e) { | |
142 | ConvertAnonymousToNestedInputPage.this.getConvertRefactoring().setClassName(classNameField.getText()); | |
143 | ConvertAnonymousToNestedInputPage.this.updateStatus(); | |
144 | } | |
145 | }); | |
146 | TextFieldNavigationHandler.install(classNameField); | |
147 | return classNameField; | |
148 | } | |
149 | ||
150 | private void updateStatus() { | |
151 | setPageComplete(getConvertRefactoring().validateInput()); | |
152 | } | |
153 | ||
154 | private void addVisibilityControl(Composite result) { | |
155 | final ConvertAnonymousToNestedRefactoring r= getConvertRefactoring(); | |
156 | r.generated_2819614190789374683(result, ConvertAnonymousToNestedInputPage.this); | |
157 | } | |
158 | ||
159 | public void addDeclareFinalCheckbox(Composite result) { | |
160 | GridData gd; | |
161 | final Button declareFinalCheckbox= new Button(result, SWT.CHECK); | |
162 | final ConvertAnonymousToNestedRefactoring r= getConvertRefactoring(); | |
163 | r.generated_3840251535444546581(declareFinalCheckbox, ConvertAnonymousToNestedInputPage.this); | |
164 | } | |
165 | ||
166 | public void addDeclareAsStaticCheckbox(Composite result) { | |
167 | GridData gd; | |
168 | final Button declareAsStaticCheckbox= new Button(result, SWT.CHECK); | |
169 | final ConvertAnonymousToNestedRefactoring r= getConvertRefactoring(); | |
170 | r.generated_8267986069549191202(declareAsStaticCheckbox, ConvertAnonymousToNestedInputPage.this); | |
171 | } | |
172 | ||
173 | public ConvertAnonymousToNestedRefactoring getConvertRefactoring(){ | |
174 | return (ConvertAnonymousToNestedRefactoring)getRefactoring(); | |
175 | } | |
176 | } | |
177 | } |