001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.ui.refactoring;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.ModifyEvent;
014: import org.eclipse.swt.events.ModifyListener;
015: import org.eclipse.swt.events.SelectionAdapter;
016: import org.eclipse.swt.events.SelectionEvent;
017: import org.eclipse.swt.layout.GridData;
018: import org.eclipse.swt.layout.GridLayout;
019: import org.eclipse.swt.widgets.Button;
020: import org.eclipse.swt.widgets.Composite;
021: import org.eclipse.swt.widgets.Label;
022: import org.eclipse.swt.widgets.Text;
023:
024: import org.eclipse.jface.dialogs.Dialog;
025:
026: import org.eclipse.ui.PlatformUI;
027:
028: import org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring;
029:
030: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
031: import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
032:
033: import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
034: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
035:
036: public class ConvertAnonymousToNestedWizard extends RefactoringWizard {
037:
038: public ConvertAnonymousToNestedWizard(
039: ConvertAnonymousToNestedRefactoring ref) {
040: super (ref, PREVIEW_EXPAND_FIRST_NODE
041: | DIALOG_BASED_USER_INTERFACE);
042: setDefaultPageTitle(RefactoringMessages.ConvertAnonymousToNestedAction_wizard_title);
043: }
044:
045: /* non java-doc
046: * @see RefactoringWizard#addUserInputPages
047: */
048: protected void addUserInputPages() {
049: addPage(new ConvertAnonymousToNestedInputPage());
050: }
051:
052: private static class ConvertAnonymousToNestedInputPage extends
053: UserInputWizardPage {
054:
055: private static final String DESCRIPTION = RefactoringMessages.ConvertAnonymousToNestedInputPage_description;
056: public static final String PAGE_NAME = "ConvertAnonymousToNestedInputPage";//$NON-NLS-1$
057:
058: public ConvertAnonymousToNestedInputPage() {
059: super (PAGE_NAME);
060: setDescription(DESCRIPTION);
061: }
062:
063: public void createControl(Composite parent) {
064: Composite result = new Composite(parent, SWT.NONE);
065: setControl(result);
066: GridLayout layout = new GridLayout();
067: layout.numColumns = 2;
068: layout.verticalSpacing = 8;
069: result.setLayout(layout);
070:
071: addVisibilityControl(result);
072: Text textField = addFieldNameField(result);
073: addDeclareFinalCheckbox(result);
074: addDeclareAsStaticCheckbox(result);
075:
076: textField.setFocus();
077: setPageComplete(false);
078: Dialog.applyDialogFont(result);
079: PlatformUI
080: .getWorkbench()
081: .getHelpSystem()
082: .setHelp(
083: getControl(),
084: IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_WIZARD_PAGE);
085: }
086:
087: private Text addFieldNameField(Composite result) {
088: Label nameLabel = new Label(result, SWT.NONE);
089: nameLabel
090: .setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_class_name);
091: nameLabel.setLayoutData(new GridData());
092:
093: final Text classNameField = new Text(result, SWT.BORDER
094: | SWT.SINGLE);
095: classNameField.setLayoutData(new GridData(
096: GridData.FILL_HORIZONTAL));
097: classNameField.addModifyListener(new ModifyListener() {
098: public void modifyText(ModifyEvent e) {
099: ConvertAnonymousToNestedInputPage.this
100: .getConvertRefactoring().setClassName(
101: classNameField.getText());
102: ConvertAnonymousToNestedInputPage.this
103: .updateStatus();
104: }
105: });
106: TextFieldNavigationHandler.install(classNameField);
107: return classNameField;
108: }
109:
110: private void updateStatus() {
111: setPageComplete(getConvertRefactoring().validateInput());
112: }
113:
114: private void addVisibilityControl(Composite result) {
115: int[] availableVisibilities = getConvertRefactoring()
116: .getAvailableVisibilities();
117: int currectVisibility = getConvertRefactoring()
118: .getVisibility();
119: IVisibilityChangeListener visibilityChangeListener = new IVisibilityChangeListener() {
120: public void visibilityChanged(int newVisibility) {
121: getConvertRefactoring()
122: .setVisibility(newVisibility);
123: }
124:
125: public void modifierChanged(int modifier,
126: boolean isChecked) {
127: }
128: };
129: Composite visibilityComposite = VisibilityControlUtil
130: .createVisibilityControl(result,
131: visibilityChangeListener,
132: availableVisibilities, currectVisibility);
133: if (visibilityComposite != null) {
134: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
135: gd.horizontalSpan = 2;
136: visibilityComposite.setLayoutData(gd);
137: }
138: }
139:
140: public void addDeclareFinalCheckbox(Composite result) {
141: GridData gd;
142: final Button declareFinalCheckbox = new Button(result,
143: SWT.CHECK);
144: declareFinalCheckbox.setEnabled(getConvertRefactoring()
145: .canEnableSettingFinal());
146: declareFinalCheckbox.setSelection(getConvertRefactoring()
147: .getDeclareFinal());
148: declareFinalCheckbox
149: .setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_declare_final);
150: gd = new GridData(GridData.FILL_HORIZONTAL);
151: gd.horizontalSpan = 2;
152: declareFinalCheckbox.setLayoutData(gd);
153: declareFinalCheckbox
154: .addSelectionListener(new SelectionAdapter() {
155: public void widgetSelected(SelectionEvent e) {
156: getConvertRefactoring()
157: .setDeclareFinal(
158: declareFinalCheckbox
159: .getSelection());
160: }
161: });
162: }
163:
164: public void addDeclareAsStaticCheckbox(Composite result) {
165: GridData gd;
166: final Button declareAsStaticCheckbox = new Button(result,
167: SWT.CHECK);
168: ConvertAnonymousToNestedRefactoring r = getConvertRefactoring();
169: declareAsStaticCheckbox
170: .setEnabled((!r.mustInnerClassBeStatic() && !r
171: .isLocalInnerType()));
172: declareAsStaticCheckbox
173: .setSelection(getConvertRefactoring()
174: .getDeclareStatic());
175: declareAsStaticCheckbox
176: .setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_declare_static);
177: gd = new GridData(GridData.FILL_HORIZONTAL);
178: gd.horizontalSpan = 2;
179: declareAsStaticCheckbox.setLayoutData(gd);
180: declareAsStaticCheckbox
181: .addSelectionListener(new SelectionAdapter() {
182: public void widgetSelected(SelectionEvent e) {
183: getConvertRefactoring().setDeclareStatic(
184: declareAsStaticCheckbox
185: .getSelection());
186: }
187: });
188: }
189:
190: private ConvertAnonymousToNestedRefactoring getConvertRefactoring() {
191: return (ConvertAnonymousToNestedRefactoring) getRefactoring();
192: }
193: }
194: }
|