1 /*******************************************************************************
2 * Copyright (c) 2000, 2011 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.refactoring;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.SelectionAdapter;
15 import org.eclipse.swt.events.SelectionEvent;
16 import org.eclipse.swt.layout.GridData;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.ui.PlatformUI;
26 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
27 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
29 import org.eclipse.jdt.internal.corext.refactoring.code.InlineConstantRefactoring;
30 import org.eclipse.jdt.internal.corext.util.Messages;
32 import org.eclipse.jdt.ui.JavaElementLabels;
34 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
36 public class InlineConstantWizard extends RefactoringWizard {
38 private static final String MESSAGE = RefactoringMessages.InlineConstantWizard_message;
40 public InlineConstantWizard(InlineConstantRefactoring ref) {
41 super(ref, DIALOG_BASED_USER_INTERFACE | PREVIEW_EXPAND_FIRST_NODE);
42 setDefaultPageTitle(RefactoringMessages.InlineConstantWizard_Inline_Constant);
46 * @see RefactoringWizard#addUserInputPages
49 protected void addUserInputPages() {
51 if(!getInlineConstantRefactoring().isInitializerAllStaticFinal()) {
52 message= RefactoringMessages.InlineConstantWizard_initializer_refers_to_fields;
57 addPage(new InlineConstantInputPage(message));
60 private InlineConstantRefactoring getInlineConstantRefactoring(){
61 return (InlineConstantRefactoring)getRefactoring();
64 private static class InlineConstantInputPage extends UserInputWizardPage {
66 public static final String PAGE_NAME= "InlineConstantInputPage";//$NON-NLS-1$
68 private InlineConstantRefactoring fRefactoring;
69 private Button fRemove;
71 public InlineConstantInputPage(String description) {
73 setDescription(description);
76 public void createControl(Composite parent) {
77 initializeDialogUnits(parent);
78 fRefactoring= (InlineConstantRefactoring)getRefactoring();
79 fRefactoring.setReplaceAllReferences(fRefactoring.isDeclarationSelected());
80 fRefactoring.setRemoveDeclaration(true);
82 Composite result= new Composite(parent, SWT.NONE);
84 GridLayout layout= new GridLayout();
85 result.setLayout(layout);
88 Label label= new Label(result, SWT.NONE);
89 String constantLabel= JavaElementLabels.getElementLabel(fRefactoring.getField(), JavaElementLabels.ALL_DEFAULT | JavaElementLabels.ALL_FULLY_QUALIFIED);
90 label.setText(Messages.format(RefactoringMessages.InlineConstantInputPage_Inline_constant, constantLabel));
91 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
93 Composite separator= new Composite(result, SWT.NONE);
94 separator.setLayoutData(new GridData(0, 0));
96 final Button all= new Button(result, SWT.RADIO);
97 all.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
98 all.setText(RefactoringMessages.InlineConstantInputPage_All_references);
99 all.setSelection(fRefactoring.getReplaceAllReferences());
100 all.addSelectionListener(new SelectionAdapter() {
102 public void widgetSelected(SelectionEvent event) {
103 fRefactoring.setReplaceAllReferences(true);
104 fRemove.setEnabled(true);
108 fRemove= new Button(result, SWT.CHECK);
109 gd= new GridData(GridData.FILL_HORIZONTAL);
110 gd.horizontalIndent= convertWidthInCharsToPixels(3);
111 fRemove.setLayoutData(gd);
112 fRemove.setText(RefactoringMessages.InlineConstantInputPage_Delete_constant);
113 fRemove.setEnabled(all.getSelection());
114 fRemove.setSelection(fRefactoring.getRemoveDeclaration());
115 fRemove.addSelectionListener(new SelectionAdapter() {
117 public void widgetSelected(SelectionEvent e) {
118 fRefactoring.setRemoveDeclaration(fRemove.getSelection());
123 final Button onlySelected= new Button(result, SWT.RADIO);
124 onlySelected.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
125 onlySelected.setText(RefactoringMessages.InlineConstantInputPage_Only_selected);
126 onlySelected.setSelection(!fRefactoring.getReplaceAllReferences());
127 if (fRefactoring.isDeclarationSelected()) {
128 onlySelected.setEnabled(false);
131 onlySelected.setFocus();
133 onlySelected.addSelectionListener(new SelectionAdapter() {
135 public void widgetSelected(SelectionEvent event) {
136 fRefactoring.setReplaceAllReferences(false);
137 fRemove.setEnabled(false);
141 Dialog.applyDialogFont(result);
143 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.INLINE_CONSTANT_WIZARD_PAGE);