KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > ConvertAnonymousToNestedWizard


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Text;
24
25 import org.eclipse.jface.dialogs.Dialog;
26
27 import org.eclipse.ui.PlatformUI;
28
29 import org.eclipse.jdt.internal.corext.refactoring.code.ConvertAnonymousToNestedRefactoring;
30
31 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
32 import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
33
34 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
35 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
36
37 public class ConvertAnonymousToNestedWizard extends RefactoringWizard {
38
39     public ConvertAnonymousToNestedWizard(ConvertAnonymousToNestedRefactoring ref) {
40         super(ref, PREVIEW_EXPAND_FIRST_NODE | DIALOG_BASED_USER_INTERFACE);
41         setDefaultPageTitle(RefactoringMessages.ConvertAnonymousToNestedAction_wizard_title);
42     }
43
44     /* non java-doc
45      * @see RefactoringWizard#addUserInputPages
46      */

47     protected void addUserInputPages(){
48         addPage(new ConvertAnonymousToNestedInputPage());
49     }
50     
51     private static class ConvertAnonymousToNestedInputPage extends UserInputWizardPage {
52
53         private static final String JavaDoc DESCRIPTION = RefactoringMessages.ConvertAnonymousToNestedInputPage_description;
54         public static final String JavaDoc PAGE_NAME= "ConvertAnonymousToNestedInputPage";//$NON-NLS-1$
55

56         public ConvertAnonymousToNestedInputPage() {
57             super(PAGE_NAME);
58             setDescription(DESCRIPTION);
59         }
60
61         public void createControl(Composite parent) {
62             Composite result= new Composite(parent, SWT.NONE);
63             setControl(result);
64             GridLayout layout= new GridLayout();
65             layout.numColumns= 2;
66             layout.verticalSpacing= 8;
67             result.setLayout(layout);
68         
69             addVisibilityControl(result);
70             Text textField= addFieldNameField(result);
71             addDeclareFinalCheckbox(result);
72             addDeclareAsStaticCheckbox(result);
73         
74             textField.setFocus();
75             setPageComplete(false);
76             Dialog.applyDialogFont(result);
77             PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.CONVERT_ANONYMOUS_TO_NESTED_WIZARD_PAGE);
78         }
79
80         private Text addFieldNameField(Composite result) {
81             Label nameLabel= new Label(result, SWT.NONE);
82             nameLabel.setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_class_name);
83             nameLabel.setLayoutData(new GridData());
84         
85             final Text classNameField= new Text(result, SWT.BORDER | SWT.SINGLE);
86             classNameField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
87             classNameField.addModifyListener(new ModifyListener(){
88                 public void modifyText(ModifyEvent e) {
89                     ConvertAnonymousToNestedInputPage.this.getConvertRefactoring().setClassName(classNameField.getText());
90                     ConvertAnonymousToNestedInputPage.this.updateStatus();
91                 }
92             });
93             TextFieldNavigationHandler.install(classNameField);
94             return classNameField;
95         }
96     
97         private void updateStatus() {
98             setPageComplete(getConvertRefactoring().validateInput());
99         }
100     
101         private void addVisibilityControl(Composite result) {
102             int[] availableVisibilities= getConvertRefactoring().getAvailableVisibilities();
103             int currectVisibility= getConvertRefactoring().getVisibility();
104             IVisibilityChangeListener visibilityChangeListener= new IVisibilityChangeListener(){
105                 public void visibilityChanged(int newVisibility) {
106                     getConvertRefactoring().setVisibility(newVisibility);
107                 }
108
109                 public void modifierChanged(int modifier, boolean isChecked) {
110                 }
111             };
112             Composite visibilityComposite= VisibilityControlUtil.createVisibilityControl(result, visibilityChangeListener, availableVisibilities, currectVisibility);
113             if(visibilityComposite != null) {
114                 GridData gd= new GridData(GridData.FILL_HORIZONTAL);
115                 gd.horizontalSpan= 2;
116                 visibilityComposite.setLayoutData(gd);
117             }
118         }
119     
120         public void addDeclareFinalCheckbox(Composite result) {
121             GridData gd;
122             final Button declareFinalCheckbox= new Button(result, SWT.CHECK);
123             declareFinalCheckbox.setEnabled(getConvertRefactoring().canEnableSettingFinal());
124             declareFinalCheckbox.setSelection(getConvertRefactoring().getDeclareFinal());
125             declareFinalCheckbox.setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_declare_final);
126             gd= new GridData(GridData.FILL_HORIZONTAL);
127             gd.horizontalSpan= 2;
128             declareFinalCheckbox.setLayoutData(gd);
129             declareFinalCheckbox.addSelectionListener(new SelectionAdapter(){
130                 public void widgetSelected(SelectionEvent e) {
131                     getConvertRefactoring().setDeclareFinal(declareFinalCheckbox.getSelection());
132                 }
133             });
134         }
135     
136         public void addDeclareAsStaticCheckbox(Composite result) {
137             GridData gd;
138             final Button declareAsStaticCheckbox= new Button(result, SWT.CHECK);
139             ConvertAnonymousToNestedRefactoring r= getConvertRefactoring();
140             declareAsStaticCheckbox.setEnabled((!r.mustInnerClassBeStatic() && !r.isLocalInnerType()));
141             declareAsStaticCheckbox.setSelection(getConvertRefactoring().getDeclareStatic());
142             declareAsStaticCheckbox.setText(RefactoringMessages.ConvertAnonymousToNestedInputPage_declare_static);
143             gd= new GridData(GridData.FILL_HORIZONTAL);
144             gd.horizontalSpan= 2;
145             declareAsStaticCheckbox.setLayoutData(gd);
146             declareAsStaticCheckbox.addSelectionListener(new SelectionAdapter() {
147                 public void widgetSelected(SelectionEvent e) {
148                     getConvertRefactoring().setDeclareStatic(declareAsStaticCheckbox.getSelection());
149                 }
150             });
151         }
152          
153         private ConvertAnonymousToNestedRefactoring getConvertRefactoring(){
154             return (ConvertAnonymousToNestedRefactoring)getRefactoring();
155         }
156     }
157 }
158
Popular Tags