1 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.Group; 21 22 import org.eclipse.jface.dialogs.Dialog; 23 import org.eclipse.jface.dialogs.IMessageProvider; 24 25 import org.eclipse.ui.PlatformUI; 26 27 import org.eclipse.jdt.internal.corext.refactoring.code.InlineConstantRefactoring; 28 29 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 30 31 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 32 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; 33 34 public class InlineConstantWizard extends RefactoringWizard { 35 36 private static final String MESSAGE = RefactoringMessages.InlineConstantWizard_message; 37 38 public InlineConstantWizard(InlineConstantRefactoring ref) { 39 super(ref, DIALOG_BASED_USER_INTERFACE | PREVIEW_EXPAND_FIRST_NODE); 40 setDefaultPageTitle(RefactoringMessages.InlineConstantWizard_Inline_Constant); 41 } 42 43 46 protected void addUserInputPages() { 47 48 String message= null; 49 int messageType= IMessageProvider.NONE; 50 if(!getInlineConstantRefactoring().isInitializerAllStaticFinal()) { 51 message= RefactoringMessages.InlineConstantWizard_initializer_refers_to_fields; 52 messageType= IMessageProvider.INFORMATION; 53 } else { 54 message= MESSAGE; 55 messageType= IMessageProvider.NONE; 56 } 57 58 addPage(new InlineConstantInputPage(message, messageType)); 59 } 60 61 private InlineConstantRefactoring getInlineConstantRefactoring(){ 62 return (InlineConstantRefactoring)getRefactoring(); 63 } 64 65 private static class InlineConstantInputPage extends UserInputWizardPage { 66 67 public static final String PAGE_NAME= "InlineConstantInputPage"; 69 private InlineConstantRefactoring fRefactoring; 70 private Group fInlineMode; 71 private Button fRemove; 72 73 private final int fOriginalMessageType; 74 private final String fOriginalMessage; 75 76 public InlineConstantInputPage(String description, int messageType) { 77 super(PAGE_NAME); 78 fOriginalMessage= description; 79 fOriginalMessageType= messageType; 80 setDescription(description); 81 } 82 83 public void createControl(Composite parent) { 84 initializeDialogUnits(parent); 85 fRefactoring= (InlineConstantRefactoring)getRefactoring(); 86 fRefactoring.setReplaceAllReferences(fRefactoring.isDeclarationSelected()); 87 fRefactoring.setRemoveDeclaration(true); 88 89 Composite result= new Composite(parent, SWT.NONE); 90 setControl(result); 91 GridLayout layout= new GridLayout(); 92 result.setLayout(layout); 93 GridData gd= null; 94 95 fInlineMode= new Group(result, SWT.NONE); 96 fInlineMode.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 97 fInlineMode.setLayout(new GridLayout()); 98 fInlineMode.setText(RefactoringMessages.InlineConstantInputPage_Inline); 99 100 final Button all= new Button(fInlineMode, SWT.RADIO); 101 all.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 102 all.setText(RefactoringMessages.InlineConstantInputPage_All_references); 103 all.setSelection(fRefactoring.getReplaceAllReferences()); 104 all.addSelectionListener(new SelectionAdapter() { 105 public void widgetSelected(SelectionEvent event) { 106 fRefactoring.setReplaceAllReferences(true); 107 fRemove.setEnabled(true); 108 } 109 }); 110 111 fRemove= new Button(fInlineMode, SWT.CHECK); 112 gd= new GridData(GridData.FILL_HORIZONTAL); 113 gd.horizontalIndent= convertWidthInCharsToPixels(3); 114 fRemove.setLayoutData(gd); 115 fRemove.setText(RefactoringMessages.InlineConstantInputPage_Delete_constant); 116 fRemove.setEnabled(all.getSelection()); 117 fRemove.setSelection(fRefactoring.getRemoveDeclaration()); 118 fRemove.addSelectionListener(new SelectionAdapter() { 119 public void widgetSelected(SelectionEvent e) { 120 fRefactoring.setRemoveDeclaration(fRemove.getSelection()); 121 } 122 }); 123 124 125 final Button onlySelected= new Button(fInlineMode, SWT.RADIO); 126 onlySelected.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 127 onlySelected.setText(RefactoringMessages.InlineConstantInputPage_Only_selected); 128 onlySelected.setSelection(!fRefactoring.getReplaceAllReferences()); 129 onlySelected.setEnabled(!fRefactoring.isDeclarationSelected()); 130 onlySelected.addSelectionListener(new SelectionAdapter() { 131 public void widgetSelected(SelectionEvent event) { 132 fRefactoring.setReplaceAllReferences(false); 133 fRemove.setEnabled(false); 134 } 135 }); 136 Dialog.applyDialogFont(result); 137 138 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaHelpContextIds.INLINE_CONSTANT_WIZARD_PAGE); 139 } 140 141 144 protected void restoreMessage() { 145 setMessage(fOriginalMessage, fOriginalMessageType); 146 } 147 } 148 } 149 | Popular Tags |