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.Group;
020:
021: import org.eclipse.jface.dialogs.Dialog;
022: import org.eclipse.jface.dialogs.IMessageProvider;
023:
024: import org.eclipse.ui.PlatformUI;
025:
026: import org.eclipse.jdt.internal.corext.refactoring.code.InlineConstantRefactoring;
027:
028: import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
029:
030: import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
031: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
032:
033: public class InlineConstantWizard extends RefactoringWizard {
034:
035: private static final String MESSAGE = RefactoringMessages.InlineConstantWizard_message;
036:
037: public InlineConstantWizard(InlineConstantRefactoring ref) {
038: super (ref, DIALOG_BASED_USER_INTERFACE
039: | PREVIEW_EXPAND_FIRST_NODE);
040: setDefaultPageTitle(RefactoringMessages.InlineConstantWizard_Inline_Constant);
041: }
042:
043: /* non java-doc
044: * @see RefactoringWizard#addUserInputPages
045: */
046: protected void addUserInputPages() {
047:
048: String message = null;
049: int messageType = IMessageProvider.NONE;
050: if (!getInlineConstantRefactoring()
051: .isInitializerAllStaticFinal()) {
052: message = RefactoringMessages.InlineConstantWizard_initializer_refers_to_fields;
053: messageType = IMessageProvider.INFORMATION;
054: } else {
055: message = MESSAGE;
056: messageType = IMessageProvider.NONE;
057: }
058:
059: addPage(new InlineConstantInputPage(message, messageType));
060: }
061:
062: private InlineConstantRefactoring getInlineConstantRefactoring() {
063: return (InlineConstantRefactoring) getRefactoring();
064: }
065:
066: private static class InlineConstantInputPage extends
067: UserInputWizardPage {
068:
069: public static final String PAGE_NAME = "InlineConstantInputPage";//$NON-NLS-1$
070:
071: private InlineConstantRefactoring fRefactoring;
072: private Group fInlineMode;
073: private Button fRemove;
074:
075: private final int fOriginalMessageType;
076: private final String fOriginalMessage;
077:
078: public InlineConstantInputPage(String description,
079: int messageType) {
080: super (PAGE_NAME);
081: fOriginalMessage = description;
082: fOriginalMessageType = messageType;
083: setDescription(description);
084: }
085:
086: public void createControl(Composite parent) {
087: initializeDialogUnits(parent);
088: fRefactoring = (InlineConstantRefactoring) getRefactoring();
089: fRefactoring.setReplaceAllReferences(fRefactoring
090: .isDeclarationSelected());
091: fRefactoring.setRemoveDeclaration(true);
092:
093: Composite result = new Composite(parent, SWT.NONE);
094: setControl(result);
095: GridLayout layout = new GridLayout();
096: result.setLayout(layout);
097: GridData gd = null;
098:
099: fInlineMode = new Group(result, SWT.NONE);
100: fInlineMode.setLayoutData(new GridData(
101: GridData.FILL_HORIZONTAL));
102: fInlineMode.setLayout(new GridLayout());
103: fInlineMode
104: .setText(RefactoringMessages.InlineConstantInputPage_Inline);
105:
106: final Button all = new Button(fInlineMode, SWT.RADIO);
107: all.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
108: all
109: .setText(RefactoringMessages.InlineConstantInputPage_All_references);
110: all.setSelection(fRefactoring.getReplaceAllReferences());
111: all.addSelectionListener(new SelectionAdapter() {
112: public void widgetSelected(SelectionEvent event) {
113: fRefactoring.setReplaceAllReferences(true);
114: fRemove.setEnabled(true);
115: }
116: });
117:
118: fRemove = new Button(fInlineMode, SWT.CHECK);
119: gd = new GridData(GridData.FILL_HORIZONTAL);
120: gd.horizontalIndent = convertWidthInCharsToPixels(3);
121: fRemove.setLayoutData(gd);
122: fRemove
123: .setText(RefactoringMessages.InlineConstantInputPage_Delete_constant);
124: fRemove.setEnabled(all.getSelection());
125: fRemove.setSelection(fRefactoring.getRemoveDeclaration());
126: fRemove.addSelectionListener(new SelectionAdapter() {
127: public void widgetSelected(SelectionEvent e) {
128: fRefactoring.setRemoveDeclaration(fRemove
129: .getSelection());
130: }
131: });
132:
133: final Button onlySelected = new Button(fInlineMode,
134: SWT.RADIO);
135: onlySelected.setLayoutData(new GridData(
136: GridData.FILL_HORIZONTAL));
137: onlySelected
138: .setText(RefactoringMessages.InlineConstantInputPage_Only_selected);
139: onlySelected.setSelection(!fRefactoring
140: .getReplaceAllReferences());
141: onlySelected.setEnabled(!fRefactoring
142: .isDeclarationSelected());
143: onlySelected.addSelectionListener(new SelectionAdapter() {
144: public void widgetSelected(SelectionEvent event) {
145: fRefactoring.setReplaceAllReferences(false);
146: fRemove.setEnabled(false);
147: }
148: });
149: Dialog.applyDialogFont(result);
150:
151: PlatformUI.getWorkbench().getHelpSystem().setHelp(
152: getControl(),
153: IJavaHelpContextIds.INLINE_CONSTANT_WIZARD_PAGE);
154: }
155:
156: /*
157: * @see org.eclipse.jdt.internal.ui.refactoring.TextInputWizardPage#restoreMessage()
158: */
159: protected void restoreMessage() {
160: setMessage(fOriginalMessage, fOriginalMessageType);
161: }
162: }
163: }
|