KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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
12 package org.eclipse.jdt.internal.ui.refactoring;
13
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
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.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring;
29
30 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
31
32 import org.eclipse.ltk.core.refactoring.Refactoring;
33 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
34 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
35
36 public class InferTypeArgumentsWizard extends RefactoringWizard {
37
38     public InferTypeArgumentsWizard(Refactoring refactoring) {
39         super(refactoring, DIALOG_BASED_USER_INTERFACE);
40         setDefaultPageTitle(RefactoringMessages.InferTypeArgumentsWizard_defaultPageTitle);
41     }
42
43     /*
44      * @see org.eclipse.ltk.ui.refactoring.RefactoringWizard#addUserInputPages()
45      */

46     protected void addUserInputPages() {
47         addPage(new InferTypeArgumentsInputPage());
48     }
49
50     private static class InferTypeArgumentsInputPage extends UserInputWizardPage {
51
52         public static final String JavaDoc PAGE_NAME= "InferTypeArgumentsInputPage"; //$NON-NLS-1$
53

54         private static final String JavaDoc DESCRIPTION= RefactoringMessages.InferTypeArgumentsInputPage_description;
55         
56         private static final String JavaDoc DIALOG_SETTING_SECTION= "InferTypeArguments"; //$NON-NLS-1$
57
private static final String JavaDoc ASSUME_CLONE_RETURNS_SAME_TYPE= "assumeCloneReturnsSameType"; //$NON-NLS-1$
58
private static final String JavaDoc LEAVE_UNCONSTRAINED_RAW= "leaveUnconstrainedRaw"; //$NON-NLS-1$
59

60         IDialogSettings fSettings;
61
62         private InferTypeArgumentsRefactoring fRefactoring;
63
64         
65         public InferTypeArgumentsInputPage() {
66             super(PAGE_NAME);
67             setDescription(DESCRIPTION);
68         }
69
70         public void createControl(Composite parent) {
71             fRefactoring= (InferTypeArgumentsRefactoring) getRefactoring();
72             loadSettings();
73             
74             Composite result= new Composite(parent, SWT.NONE);
75             setControl(result);
76             GridLayout layout= new GridLayout();
77             layout.numColumns= 1;
78             result.setLayout(layout);
79             
80             Label doit= new Label(result, SWT.WRAP);
81             doit.setText(RefactoringMessages.InferTypeArgumentsWizard_lengthyDescription);
82             doit.setLayoutData(new GridData());
83             
84             Label separator= new Label(result, SWT.SEPARATOR | SWT.HORIZONTAL);
85             separator.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));
86             
87             Button cloneCheckBox= new Button(result, SWT.CHECK);
88             cloneCheckBox.setText(RefactoringMessages.InferTypeArgumentsWizard_assumeCloneSameType);
89             boolean assumeCloneValue= fSettings.getBoolean(ASSUME_CLONE_RETURNS_SAME_TYPE);
90             fRefactoring.setAssumeCloneReturnsSameType(assumeCloneValue);
91             cloneCheckBox.setSelection(assumeCloneValue);
92             cloneCheckBox.addSelectionListener(new SelectionAdapter() {
93                 public void widgetSelected(SelectionEvent e) {
94                     setAssumeCloseReturnsSameType(((Button)e.widget).getSelection());
95                 }
96             });
97             
98             Button leaveRawCheckBox= new Button(result, SWT.CHECK);
99             leaveRawCheckBox.setText(RefactoringMessages.InferTypeArgumentsWizard_leaveUnconstrainedRaw);
100             boolean leaveRawValue= fSettings.getBoolean(LEAVE_UNCONSTRAINED_RAW);
101             fRefactoring.setLeaveUnconstrainedRaw(leaveRawValue);
102             leaveRawCheckBox.setSelection(leaveRawValue);
103             leaveRawCheckBox.addSelectionListener(new SelectionAdapter() {
104                 public void widgetSelected(SelectionEvent e) {
105                     setLeaveUnconstrainedRaw(((Button)e.widget).getSelection());
106                 }
107             });
108             
109             updateStatus();
110             Dialog.applyDialogFont(result);
111             PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.INFER_TYPE_ARGUMENTS_WIZARD_PAGE);
112         }
113
114         private void setAssumeCloseReturnsSameType(boolean selection) {
115             fSettings.put(ASSUME_CLONE_RETURNS_SAME_TYPE, selection);
116             fRefactoring.setAssumeCloneReturnsSameType(selection);
117         }
118         
119         private void setLeaveUnconstrainedRaw(boolean selection) {
120             fSettings.put(LEAVE_UNCONSTRAINED_RAW, selection);
121             fRefactoring.setLeaveUnconstrainedRaw(selection);
122         }
123         
124         private void updateStatus() {
125             setPageComplete(true);
126         }
127         
128         private void loadSettings() {
129             fSettings= getDialogSettings().getSection(DIALOG_SETTING_SECTION);
130             if (fSettings == null) {
131                 fSettings= getDialogSettings().addNewSection(DIALOG_SETTING_SECTION);
132                 fSettings.put(ASSUME_CLONE_RETURNS_SAME_TYPE, true);
133                 fSettings.put(LEAVE_UNCONSTRAINED_RAW, true);
134             }
135             fRefactoring.setAssumeCloneReturnsSameType(fSettings.getBoolean(ASSUME_CLONE_RETURNS_SAME_TYPE));
136             fRefactoring.setLeaveUnconstrainedRaw(fSettings.getBoolean(LEAVE_UNCONSTRAINED_RAW));
137         }
138         
139         
140     }
141 }
142
Popular Tags