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.swt.SWT;
013: import org.eclipse.swt.events.SelectionAdapter;
014: import org.eclipse.swt.events.SelectionEvent;
015: import org.eclipse.swt.layout.GridData;
016: import org.eclipse.swt.layout.GridLayout;
017: import org.eclipse.swt.widgets.Button;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.swt.widgets.Label;
020:
021: import org.eclipse.jface.dialogs.Dialog;
022: import org.eclipse.jface.dialogs.IDialogSettings;
023:
024: import org.eclipse.ui.PlatformUI;
025:
026: import org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring;
027:
028: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
029:
030: import org.eclipse.ltk.core.refactoring.Refactoring;
031: import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
032: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
033:
034: public class InferTypeArgumentsWizard extends RefactoringWizard {
035:
036: public InferTypeArgumentsWizard(Refactoring refactoring) {
037: super (refactoring, DIALOG_BASED_USER_INTERFACE);
038: setDefaultPageTitle(RefactoringMessages.InferTypeArgumentsWizard_defaultPageTitle);
039: }
040:
041: /*
042: * @see org.eclipse.ltk.ui.refactoring.RefactoringWizard#addUserInputPages()
043: */
044: protected void addUserInputPages() {
045: addPage(new InferTypeArgumentsInputPage());
046: }
047:
048: private static class InferTypeArgumentsInputPage extends
049: UserInputWizardPage {
050:
051: public static final String PAGE_NAME = "InferTypeArgumentsInputPage"; //$NON-NLS-1$
052:
053: private static final String DESCRIPTION = RefactoringMessages.InferTypeArgumentsInputPage_description;
054:
055: private static final String DIALOG_SETTING_SECTION = "InferTypeArguments"; //$NON-NLS-1$
056: private static final String ASSUME_CLONE_RETURNS_SAME_TYPE = "assumeCloneReturnsSameType"; //$NON-NLS-1$
057: private static final String LEAVE_UNCONSTRAINED_RAW = "leaveUnconstrainedRaw"; //$NON-NLS-1$
058:
059: IDialogSettings fSettings;
060:
061: private InferTypeArgumentsRefactoring fRefactoring;
062:
063: public InferTypeArgumentsInputPage() {
064: super (PAGE_NAME);
065: setDescription(DESCRIPTION);
066: }
067:
068: public void createControl(Composite parent) {
069: fRefactoring = (InferTypeArgumentsRefactoring) getRefactoring();
070: loadSettings();
071:
072: Composite result = new Composite(parent, SWT.NONE);
073: setControl(result);
074: GridLayout layout = new GridLayout();
075: layout.numColumns = 1;
076: result.setLayout(layout);
077:
078: Label doit = new Label(result, SWT.WRAP);
079: doit
080: .setText(RefactoringMessages.InferTypeArgumentsWizard_lengthyDescription);
081: doit.setLayoutData(new GridData());
082:
083: Label separator = new Label(result, SWT.SEPARATOR
084: | SWT.HORIZONTAL);
085: separator.setLayoutData(new GridData(SWT.FILL,
086: SWT.BEGINNING, true, false));
087:
088: Button cloneCheckBox = new Button(result, SWT.CHECK);
089: cloneCheckBox
090: .setText(RefactoringMessages.InferTypeArgumentsWizard_assumeCloneSameType);
091: boolean assumeCloneValue = fSettings
092: .getBoolean(ASSUME_CLONE_RETURNS_SAME_TYPE);
093: fRefactoring
094: .setAssumeCloneReturnsSameType(assumeCloneValue);
095: cloneCheckBox.setSelection(assumeCloneValue);
096: cloneCheckBox.addSelectionListener(new SelectionAdapter() {
097: public void widgetSelected(SelectionEvent e) {
098: setAssumeCloseReturnsSameType(((Button) e.widget)
099: .getSelection());
100: }
101: });
102:
103: Button leaveRawCheckBox = new Button(result, SWT.CHECK);
104: leaveRawCheckBox
105: .setText(RefactoringMessages.InferTypeArgumentsWizard_leaveUnconstrainedRaw);
106: boolean leaveRawValue = fSettings
107: .getBoolean(LEAVE_UNCONSTRAINED_RAW);
108: fRefactoring.setLeaveUnconstrainedRaw(leaveRawValue);
109: leaveRawCheckBox.setSelection(leaveRawValue);
110: leaveRawCheckBox
111: .addSelectionListener(new SelectionAdapter() {
112: public void widgetSelected(SelectionEvent e) {
113: setLeaveUnconstrainedRaw(((Button) e.widget)
114: .getSelection());
115: }
116: });
117:
118: updateStatus();
119: Dialog.applyDialogFont(result);
120: PlatformUI
121: .getWorkbench()
122: .getHelpSystem()
123: .setHelp(
124: getControl(),
125: IJavaHelpContextIds.INFER_TYPE_ARGUMENTS_WIZARD_PAGE);
126: }
127:
128: private void setAssumeCloseReturnsSameType(boolean selection) {
129: fSettings.put(ASSUME_CLONE_RETURNS_SAME_TYPE, selection);
130: fRefactoring.setAssumeCloneReturnsSameType(selection);
131: }
132:
133: private void setLeaveUnconstrainedRaw(boolean selection) {
134: fSettings.put(LEAVE_UNCONSTRAINED_RAW, selection);
135: fRefactoring.setLeaveUnconstrainedRaw(selection);
136: }
137:
138: private void updateStatus() {
139: setPageComplete(true);
140: }
141:
142: private void loadSettings() {
143: fSettings = getDialogSettings().getSection(
144: DIALOG_SETTING_SECTION);
145: if (fSettings == null) {
146: fSettings = getDialogSettings().addNewSection(
147: DIALOG_SETTING_SECTION);
148: fSettings.put(ASSUME_CLONE_RETURNS_SAME_TYPE, true);
149: fSettings.put(LEAVE_UNCONSTRAINED_RAW, true);
150: }
151: fRefactoring.setAssumeCloneReturnsSameType(fSettings
152: .getBoolean(ASSUME_CLONE_RETURNS_SAME_TYPE));
153: fRefactoring.setLeaveUnconstrainedRaw(fSettings
154: .getBoolean(LEAVE_UNCONSTRAINED_RAW));
155: }
156:
157: }
158: }
|