]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/ui refactoring/org/eclipse/jdt/internal/ui/refactoring/InlineConstantWizard.java
Case Study: adding data and statistics
[ifi-stolz-refaktor.git] / case-study / jdt-before / ui refactoring / org / eclipse / jdt / internal / ui / refactoring / InlineConstantWizard.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.refactoring;
12
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;
21
22 import org.eclipse.jface.dialogs.Dialog;
23
24 import org.eclipse.ui.PlatformUI;
25
26 import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
27 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
28
29 import org.eclipse.jdt.internal.corext.refactoring.code.InlineConstantRefactoring;
30 import org.eclipse.jdt.internal.corext.util.Messages;
31
32 import org.eclipse.jdt.ui.JavaElementLabels;
33
34 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
35
36 public class InlineConstantWizard extends RefactoringWizard {
37
38         private static final String MESSAGE = RefactoringMessages.InlineConstantWizard_message;
39
40         public InlineConstantWizard(InlineConstantRefactoring ref) {
41                 super(ref, DIALOG_BASED_USER_INTERFACE | PREVIEW_EXPAND_FIRST_NODE);
42                 setDefaultPageTitle(RefactoringMessages.InlineConstantWizard_Inline_Constant);
43         }
44
45         /* non java-doc
46          * @see RefactoringWizard#addUserInputPages
47          */
48         @Override
49         protected void addUserInputPages() {
50                 String message= null;
51                 if(!getInlineConstantRefactoring().isInitializerAllStaticFinal()) {
52                         message= RefactoringMessages.InlineConstantWizard_initializer_refers_to_fields;
53                 } else {
54                         message= MESSAGE;
55                 }
56
57                 addPage(new InlineConstantInputPage(message));
58         }
59
60         private InlineConstantRefactoring getInlineConstantRefactoring(){
61                 return (InlineConstantRefactoring)getRefactoring();
62         }
63
64         private static class InlineConstantInputPage extends UserInputWizardPage {
65
66                 public static final String PAGE_NAME= "InlineConstantInputPage";//$NON-NLS-1$
67
68                 private InlineConstantRefactoring fRefactoring;
69                 private Button fRemove;
70
71                 public InlineConstantInputPage(String description) {
72                         super(PAGE_NAME);
73                         setDescription(description);
74                 }
75
76                 public void createControl(Composite parent) {
77                         initializeDialogUnits(parent);
78                         fRefactoring= (InlineConstantRefactoring)getRefactoring();
79                         fRefactoring.setReplaceAllReferences(fRefactoring.isDeclarationSelected());
80                         fRefactoring.setRemoveDeclaration(true);
81
82                         Composite result= new Composite(parent, SWT.NONE);
83                         setControl(result);
84                         GridLayout layout= new GridLayout();
85                         result.setLayout(layout);
86                         GridData gd= null;
87
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));
92
93                         Composite separator= new Composite(result, SWT.NONE);
94                         separator.setLayoutData(new GridData(0, 0));
95
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() {
101                                 @Override
102                                 public void widgetSelected(SelectionEvent event) {
103                                         fRefactoring.setReplaceAllReferences(true);
104                                         fRemove.setEnabled(true);
105                                 }
106                         });
107
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() {
116                                 @Override
117                                 public void widgetSelected(SelectionEvent e) {
118                                         fRefactoring.setRemoveDeclaration(fRemove.getSelection());
119                                 }
120                         });
121
122
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);
129                                 all.setFocus();
130                         } else {
131                                 onlySelected.setFocus();
132                         }
133                         onlySelected.addSelectionListener(new SelectionAdapter() {
134                                 @Override
135                                 public void widgetSelected(SelectionEvent event) {
136                                         fRefactoring.setReplaceAllReferences(false);
137                                         fRemove.setEnabled(false);
138                                 }
139                         });
140
141                         Dialog.applyDialogFont(result);
142
143                         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.INLINE_CONSTANT_WIZARD_PAGE);
144                 }
145
146         }
147 }