Source Code Cross Referenced for PromoteTempWizard.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » refactoring » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » jdt » org.eclipse.jdt.internal.ui.refactoring 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 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.core.runtime.Assert;
013:
014:        import org.eclipse.swt.SWT;
015:        import org.eclipse.swt.events.ModifyEvent;
016:        import org.eclipse.swt.events.ModifyListener;
017:        import org.eclipse.swt.events.SelectionAdapter;
018:        import org.eclipse.swt.events.SelectionEvent;
019:        import org.eclipse.swt.layout.GridData;
020:        import org.eclipse.swt.layout.GridLayout;
021:        import org.eclipse.swt.widgets.Button;
022:        import org.eclipse.swt.widgets.Composite;
023:        import org.eclipse.swt.widgets.Group;
024:        import org.eclipse.swt.widgets.Label;
025:        import org.eclipse.swt.widgets.Text;
026:
027:        import org.eclipse.jface.dialogs.Dialog;
028:        import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
029:
030:        import org.eclipse.ui.PlatformUI;
031:
032:        import org.eclipse.jdt.internal.corext.refactoring.code.PromoteTempToFieldRefactoring;
033:
034:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
035:        import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
036:        import org.eclipse.jdt.internal.ui.refactoring.contentassist.ControlContentAssistHelper;
037:        import org.eclipse.jdt.internal.ui.refactoring.contentassist.FieldNameProcessor;
038:
039:        import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
040:        import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
041:
042:        public class PromoteTempWizard extends RefactoringWizard {
043:
044:            public PromoteTempWizard(PromoteTempToFieldRefactoring ref) {
045:                super (ref, DIALOG_BASED_USER_INTERFACE
046:                        | PREVIEW_EXPAND_FIRST_NODE);
047:                setDefaultPageTitle(RefactoringMessages.ConvertLocalToField_title);
048:            }
049:
050:            /* non java-doc
051:             * @see RefactoringWizard#addUserInputPages
052:             */
053:            protected void addUserInputPages() {
054:                addPage(new PromoteTempInputPage());
055:            }
056:
057:            private static class PromoteTempInputPage extends
058:                    UserInputWizardPage {
059:
060:                private static final String DESCRIPTION = RefactoringMessages.PromoteTempInputPage_description;
061:                public static final String PAGE_NAME = "PromoteTempInputPage";//$NON-NLS-1$
062:                private static final String[] RADIO_BUTTON_LABELS = {
063:                        RefactoringMessages.PromoteTempInputPage_Field_declaration,
064:                        RefactoringMessages.PromoteTempInputPage_Current_method,
065:                        RefactoringMessages.PromoteTempInputPage_constructors };
066:                private static final Integer[] RADIO_BUTTON_DATA = {
067:                        new Integer(
068:                                PromoteTempToFieldRefactoring.INITIALIZE_IN_FIELD),
069:                        new Integer(
070:                                PromoteTempToFieldRefactoring.INITIALIZE_IN_METHOD),
071:                        new Integer(
072:                                PromoteTempToFieldRefactoring.INITIALIZE_IN_CONSTRUCTOR) };
073:                private Button fDeclareStaticCheckbox;
074:                private Button fDeclareFinalCheckbox;
075:                private Button[] fInitializeInRadioButtons;
076:                private Text fNameField;
077:
078:                public PromoteTempInputPage() {
079:                    super (PAGE_NAME);
080:                    setDescription(DESCRIPTION);
081:                }
082:
083:                public void createControl(Composite parent) {
084:                    Composite result = new Composite(parent, SWT.NONE);
085:                    setControl(result);
086:                    GridLayout layout = new GridLayout();
087:                    layout.numColumns = 2;
088:                    layout.verticalSpacing = 8;
089:                    result.setLayout(layout);
090:
091:                    addFieldNameField(result);
092:                    addVisibilityControl(result);
093:                    addInitizeInRadioButtonGroup(result);
094:                    addDeclareStaticCheckbox(result);
095:                    addDeclareFinalCheckbox(result);
096:
097:                    Dialog.applyDialogFont(result);
098:                    PlatformUI
099:                            .getWorkbench()
100:                            .getHelpSystem()
101:                            .setHelp(
102:                                    getControl(),
103:                                    IJavaHelpContextIds.PROMOTE_TEMP_TO_FIELD_WIZARD_PAGE);
104:                }
105:
106:                private void addFieldNameField(Composite result) {
107:                    Label nameLabel = new Label(result, SWT.NONE);
108:                    nameLabel
109:                            .setText(RefactoringMessages.PromoteTempInputPage_Field_name);
110:                    nameLabel.setLayoutData(new GridData());
111:
112:                    String[] guessedFieldNames = getPromoteTempRefactoring()
113:                            .guessFieldNames();
114:
115:                    fNameField = new Text(result, SWT.BORDER | SWT.SINGLE);
116:                    fNameField.setText(guessedFieldNames[0]);
117:                    fNameField.selectAll();
118:                    fNameField.setLayoutData(new GridData(
119:                            GridData.FILL_HORIZONTAL));
120:                    fNameField.addModifyListener(new ModifyListener() {
121:                        public void modifyText(ModifyEvent e) {
122:                            PromoteTempInputPage.this 
123:                                    .getPromoteTempRefactoring().setFieldName(
124:                                            fNameField.getText());
125:                            PromoteTempInputPage.this .updateStatus();
126:                        }
127:                    });
128:                    IContentAssistProcessor processor = new FieldNameProcessor(
129:                            guessedFieldNames, getPromoteTempRefactoring());
130:                    ControlContentAssistHelper.createTextContentAssistant(
131:                            fNameField, processor);
132:                    TextFieldNavigationHandler.install(fNameField);
133:                }
134:
135:                private void updateStatus() {
136:                    setPageComplete(getPromoteTempRefactoring().validateInput());
137:                }
138:
139:                private void addInitizeInRadioButtonGroup(Composite result) {
140:                    GridData gd;
141:                    Group initializeIn = new Group(result, SWT.NONE);
142:                    initializeIn
143:                            .setText(RefactoringMessages.PromoteTempInputPage_Initialize);
144:                    initializeIn.setLayout(new GridLayout());
145:                    gd = new GridData(GridData.FILL_HORIZONTAL);
146:                    gd.horizontalSpan = 2;
147:                    initializeIn.setLayoutData(gd);
148:
149:                    Assert
150:                            .isTrue(RADIO_BUTTON_LABELS.length == RADIO_BUTTON_DATA.length);
151:                    fInitializeInRadioButtons = new Button[RADIO_BUTTON_LABELS.length];
152:                    for (int i = 0; i < RADIO_BUTTON_LABELS.length; i++) {
153:                        Integer dataItem = RADIO_BUTTON_DATA[i];
154:                        fInitializeInRadioButtons[i] = new Button(initializeIn,
155:                                SWT.RADIO);
156:                        fInitializeInRadioButtons[i]
157:                                .setEnabled(canEnable(dataItem.intValue()));
158:                        fInitializeInRadioButtons[i]
159:                                .setText(RADIO_BUTTON_LABELS[i]);
160:                        fInitializeInRadioButtons[i].setSelection(dataItem
161:                                .intValue() == getPromoteTempRefactoring()
162:                                .getInitializeIn());
163:                        fInitializeInRadioButtons[i]
164:                                .setLayoutData(new GridData());
165:                        fInitializeInRadioButtons[i].setData(dataItem);
166:                        final int j = i;
167:                        fInitializeInRadioButtons[i]
168:                                .addSelectionListener(new SelectionAdapter() {
169:                                    public void widgetSelected(SelectionEvent e) {
170:                                        getPromoteTempRefactoring()
171:                                                .setInitializeIn(
172:                                                        getDataAsInt(fInitializeInRadioButtons[j]));
173:                                        updateButtonsEnablement();
174:                                    }
175:                                });
176:                    }
177:                }
178:
179:                private void updateButtonsEnablement() {
180:                    fDeclareFinalCheckbox
181:                            .setEnabled(getPromoteTempRefactoring()
182:                                    .canEnableSettingFinal());
183:                    fDeclareStaticCheckbox
184:                            .setEnabled(getPromoteTempRefactoring()
185:                                    .canEnableSettingStatic());
186:                    for (int i = 0; i < fInitializeInRadioButtons.length; i++) {
187:                        fInitializeInRadioButtons[i]
188:                                .setEnabled(canEnable(getDataAsInt(fInitializeInRadioButtons[i])));
189:                    }
190:                }
191:
192:                private static int getDataAsInt(Button button) {
193:                    return ((Integer) button.getData()).intValue();
194:                }
195:
196:                private boolean canEnable(int initializeIn) {
197:                    switch (initializeIn) {
198:                    case PromoteTempToFieldRefactoring.INITIALIZE_IN_CONSTRUCTOR:
199:                        return getPromoteTempRefactoring()
200:                                .canEnableSettingDeclareInConstructors();
201:                    case PromoteTempToFieldRefactoring.INITIALIZE_IN_FIELD:
202:                        return getPromoteTempRefactoring()
203:                                .canEnableSettingDeclareInFieldDeclaration();
204:                    case PromoteTempToFieldRefactoring.INITIALIZE_IN_METHOD:
205:                        return getPromoteTempRefactoring()
206:                                .canEnableSettingDeclareInMethod();
207:                    default:
208:                        Assert.isTrue(false);
209:                        return false;
210:                    }
211:                }
212:
213:                public void addDeclareStaticCheckbox(Composite result) {
214:                    GridData gd;
215:                    fDeclareStaticCheckbox = new Button(result, SWT.CHECK);
216:                    fDeclareStaticCheckbox
217:                            .setEnabled(getPromoteTempRefactoring()
218:                                    .canEnableSettingStatic());
219:                    fDeclareStaticCheckbox
220:                            .setSelection(getPromoteTempRefactoring()
221:                                    .getDeclareStatic());
222:                    fDeclareStaticCheckbox
223:                            .setText(RefactoringMessages.PromoteTempInputPage_declare_static);
224:                    gd = new GridData(GridData.FILL_HORIZONTAL);
225:                    gd.horizontalSpan = 2;
226:                    fDeclareStaticCheckbox.setLayoutData(gd);
227:                    fDeclareStaticCheckbox
228:                            .addSelectionListener(new SelectionAdapter() {
229:                                public void widgetSelected(SelectionEvent e) {
230:                                    getPromoteTempRefactoring()
231:                                            .setDeclareStatic(
232:                                                    fDeclareStaticCheckbox
233:                                                            .getSelection());
234:                                    updateButtonsEnablement();
235:                                }
236:                            });
237:                }
238:
239:                private void addDeclareFinalCheckbox(Composite result) {
240:                    GridData gd;
241:                    fDeclareFinalCheckbox = new Button(result, SWT.CHECK);
242:                    fDeclareFinalCheckbox
243:                            .setEnabled(getPromoteTempRefactoring()
244:                                    .canEnableSettingFinal());
245:                    fDeclareFinalCheckbox
246:                            .setSelection(getPromoteTempRefactoring()
247:                                    .getDeclareFinal());
248:                    fDeclareFinalCheckbox
249:                            .setText(RefactoringMessages.PromoteTempInputPage_declare_final);
250:                    gd = new GridData(GridData.FILL_HORIZONTAL);
251:                    gd.horizontalSpan = 2;
252:                    fDeclareFinalCheckbox.setLayoutData(gd);
253:                    fDeclareFinalCheckbox
254:                            .addSelectionListener(new SelectionAdapter() {
255:                                public void widgetSelected(SelectionEvent e) {
256:                                    getPromoteTempRefactoring()
257:                                            .setDeclareFinal(
258:                                                    fDeclareFinalCheckbox
259:                                                            .getSelection());
260:                                    updateButtonsEnablement();
261:                                }
262:                            });
263:                }
264:
265:                private void addVisibilityControl(Composite result) {
266:                    int[] availableVisibilities = getPromoteTempRefactoring()
267:                            .getAvailableVisibilities();
268:                    int currectVisibility = getPromoteTempRefactoring()
269:                            .getVisibility();
270:                    IVisibilityChangeListener visibilityChangeListener = new IVisibilityChangeListener() {
271:                        public void visibilityChanged(int newVisibility) {
272:                            getPromoteTempRefactoring().setVisibility(
273:                                    newVisibility);
274:                        }
275:
276:                        public void modifierChanged(int modifier,
277:                                boolean isChecked) {
278:                        }
279:                    };
280:                    Composite visibilityComposite = VisibilityControlUtil
281:                            .createVisibilityControl(result,
282:                                    visibilityChangeListener,
283:                                    availableVisibilities, currectVisibility);
284:                    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
285:                    gd.horizontalSpan = 2;
286:                    visibilityComposite.setLayoutData(gd);
287:                }
288:
289:                private PromoteTempToFieldRefactoring getPromoteTempRefactoring() {
290:                    return (PromoteTempToFieldRefactoring) getRefactoring();
291:                }
292:
293:                /* (non-Javadoc)
294:                 * @see org.eclipse.jface.dialogs.IDialogPage#setVisible(boolean)
295:                 */
296:                public void setVisible(boolean visible) {
297:                    super.setVisible(visible);
298:                    if (visible && fNameField != null)
299:                        fNameField.setFocus();
300:                }
301:
302:            }
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.