1 11 package org.eclipse.jdt.internal.ui.refactoring.reorg; 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 import org.eclipse.swt.widgets.Text; 22 23 import org.eclipse.jface.dialogs.Dialog; 24 25 import org.eclipse.ui.PlatformUI; 26 27 import org.eclipse.ltk.core.refactoring.Refactoring; 28 29 import org.eclipse.jdt.internal.corext.refactoring.tagging.IDelegateUpdating; 30 import org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating; 31 import org.eclipse.jdt.internal.corext.refactoring.tagging.IQualifiedNameUpdating; 32 import org.eclipse.jdt.internal.corext.refactoring.tagging.IReferenceUpdating; 33 import org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating; 34 35 import org.eclipse.jdt.internal.ui.refactoring.DelegateUIHelper; 36 import org.eclipse.jdt.internal.ui.refactoring.QualifiedNameComponent; 37 import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; 38 import org.eclipse.jdt.internal.ui.refactoring.TextInputWizardPage; 39 import org.eclipse.jdt.internal.ui.util.RowLayouter; 40 41 abstract class RenameInputWizardPage extends TextInputWizardPage { 42 43 private String fHelpContextID; 44 private Button fUpdateReferences; 45 private Button fUpdateTextualMatches; 46 private Button fUpdateQualifiedNames; 47 private Button fLeaveDelegateCheckBox; 48 private Button fDeprecateDelegateCheckBox; 49 private QualifiedNameComponent fQualifiedNameComponent; 50 51 57 public RenameInputWizardPage(String description, String contextHelpId, boolean isLastUserPage, String initialValue) { 58 super(description, isLastUserPage, initialValue); 59 fHelpContextID= contextHelpId; 60 } 61 62 public void createControl(Composite parent) { 63 Composite superComposite= new Composite(parent, SWT.NONE); 64 setControl(superComposite); 65 initializeDialogUnits(superComposite); 66 superComposite.setLayout(new GridLayout()); 67 Composite composite= new Composite(superComposite, SWT.NONE); 68 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 69 70 GridLayout layout= new GridLayout(); 71 layout.numColumns= 2; 72 layout.marginHeight= 0; 73 layout.marginWidth= 0; 74 75 composite.setLayout(layout); 76 RowLayouter layouter= new RowLayouter(2); 77 78 Label label= new Label(composite, SWT.NONE); 79 label.setText(getLabelText()); 80 81 Text text= createTextInputField(composite); 82 text.selectAll(); 83 GridData gd= new GridData(GridData.FILL_HORIZONTAL); 84 gd.widthHint= convertWidthInCharsToPixels(25); 85 text.setLayoutData(gd); 86 87 layouter.perform(label, text, 1); 88 89 Label separator= new Label(composite, SWT.NONE); 90 GridData gridData= new GridData(SWT.FILL, SWT.FILL, false, false); 91 gridData.heightHint= 2; 92 separator.setLayoutData(gridData); 93 94 95 int indent= convertWidthInCharsToPixels(2); 96 97 addOptionalUpdateReferencesCheckbox(composite, layouter); 98 addAdditionalOptions(composite, layouter); 99 addOptionalUpdateTextualMatches(composite, layouter); 100 addOptionalUpdateQualifiedNameComponent(composite, layouter, indent); 101 addOptionalLeaveDelegateCheckbox(composite, layouter); 102 addOptionalDeprecateDelegateCheckbox(composite, layouter, indent); 103 updateForcePreview(); 104 105 Dialog.applyDialogFont(superComposite); 106 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), fHelpContextID); 107 } 108 109 115 protected void addAdditionalOptions(Composite composite, RowLayouter layouter) { 116 } 118 119 public void setVisible(boolean visible) { 120 if (visible) { 121 INameUpdating nameUpdating= (INameUpdating)getRefactoring().getAdapter(INameUpdating.class); 122 if (nameUpdating != null) { 123 String newName= getNewName(nameUpdating); 124 if (newName != null && newName.length() > 0 && !newName.equals(getInitialValue())) { 125 Text textField= getTextField(); 126 textField.setText(newName); 127 textField.setSelection(0, newName.length()); 128 } 129 } 130 } 131 super.setVisible(visible); 132 } 133 134 140 protected String getNewName(INameUpdating nameUpdating) { 141 return nameUpdating.getNewElementName(); 142 } 143 144 protected boolean saveSettings() { 145 return true; 149 } 150 151 public void dispose() { 152 if (saveSettings()) { 153 saveBooleanSetting(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES, fUpdateTextualMatches); 154 saveBooleanSetting(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES, fUpdateQualifiedNames); 155 if (fQualifiedNameComponent != null) 156 fQualifiedNameComponent.savePatterns(getRefactoringSettings()); 157 DelegateUIHelper.saveLeaveDelegateSetting(fLeaveDelegateCheckBox); 158 DelegateUIHelper.saveDeprecateDelegateSetting(fDeprecateDelegateCheckBox); 159 } 160 super.dispose(); 161 } 162 163 private void addOptionalUpdateReferencesCheckbox(Composite result, RowLayouter layouter) { 164 final IReferenceUpdating ref= (IReferenceUpdating)getRefactoring().getAdapter(IReferenceUpdating.class); 165 if (ref == null || !ref.canEnableUpdateReferences()) 166 return; 167 String title= RefactoringMessages.RenameInputWizardPage_update_references; 168 boolean defaultValue= true; fUpdateReferences= createCheckbox(result, title, defaultValue, layouter); 170 ref.setUpdateReferences(fUpdateReferences.getSelection()); 171 fUpdateReferences.addSelectionListener(new SelectionAdapter(){ 172 public void widgetSelected(SelectionEvent e) { 173 ref.setUpdateReferences(fUpdateReferences.getSelection()); 174 } 175 }); 176 } 177 178 private void addOptionalUpdateTextualMatches(Composite result, RowLayouter layouter) { 179 final ITextUpdating refactoring= (ITextUpdating) getRefactoring().getAdapter(ITextUpdating.class); 180 if (refactoring == null || !refactoring.canEnableTextUpdating()) 181 return; 182 String title= RefactoringMessages.RenameInputWizardPage_update_textual_matches; 183 boolean defaultValue= getBooleanSetting(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES, refactoring.getUpdateTextualMatches()); 184 fUpdateTextualMatches= createCheckbox(result, title, defaultValue, layouter); 185 refactoring.setUpdateTextualMatches(fUpdateTextualMatches.getSelection()); 186 fUpdateTextualMatches.addSelectionListener(new SelectionAdapter(){ 187 public void widgetSelected(SelectionEvent e) { 188 refactoring.setUpdateTextualMatches(fUpdateTextualMatches.getSelection()); 189 updateForcePreview(); 190 } 191 }); 192 } 193 194 private void addOptionalUpdateQualifiedNameComponent(Composite parent, RowLayouter layouter, int marginWidth) { 195 final IQualifiedNameUpdating ref= (IQualifiedNameUpdating)getRefactoring().getAdapter(IQualifiedNameUpdating.class); 196 if (ref == null || !ref.canEnableQualifiedNameUpdating()) 197 return; 198 fUpdateQualifiedNames= new Button(parent, SWT.CHECK); 199 int indent= marginWidth + fUpdateQualifiedNames.computeSize(SWT.DEFAULT, SWT.DEFAULT).x; 200 fUpdateQualifiedNames.setText(RefactoringMessages.RenameInputWizardPage_update_qualified_names); 201 layouter.perform(fUpdateQualifiedNames); 202 203 fQualifiedNameComponent= new QualifiedNameComponent(parent, SWT.NONE, ref, getRefactoringSettings()); 204 layouter.perform(fQualifiedNameComponent); 205 GridData gd= (GridData)fQualifiedNameComponent.getLayoutData(); 206 gd.horizontalAlignment= GridData.FILL; 207 gd.horizontalIndent= indent; 208 209 boolean defaultSelection= getBooleanSetting(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES, ref.getUpdateQualifiedNames()); 210 fUpdateQualifiedNames.setSelection(defaultSelection); 211 updateQulifiedNameUpdating(ref, defaultSelection); 212 213 fUpdateQualifiedNames.addSelectionListener(new SelectionAdapter() { 214 public void widgetSelected(SelectionEvent e) { 215 boolean enabled= ((Button)e.widget).getSelection(); 216 updateQulifiedNameUpdating(ref, enabled); 217 } 218 }); 219 } 220 221 private void updateQulifiedNameUpdating(final IQualifiedNameUpdating ref, boolean enabled) { 222 fQualifiedNameComponent.setEnabled(enabled); 223 ref.setUpdateQualifiedNames(enabled); 224 updateForcePreview(); 225 } 226 227 private void addOptionalLeaveDelegateCheckbox(Composite result, RowLayouter layouter) { 228 final IDelegateUpdating refactoring= (IDelegateUpdating) getRefactoring().getAdapter(IDelegateUpdating.class); 229 if (refactoring == null || !refactoring.canEnableDelegateUpdating()) 230 return; 231 fLeaveDelegateCheckBox= createCheckbox(result, refactoring.getDelegateUpdatingTitle(false), DelegateUIHelper.loadLeaveDelegateSetting(refactoring), layouter); 232 refactoring.setDelegateUpdating(fLeaveDelegateCheckBox.getSelection()); 233 fLeaveDelegateCheckBox.addSelectionListener(new SelectionAdapter() { 234 public void widgetSelected(SelectionEvent e) { 235 refactoring.setDelegateUpdating(fLeaveDelegateCheckBox.getSelection()); 236 } 237 }); 238 } 239 240 private void addOptionalDeprecateDelegateCheckbox(Composite result, RowLayouter layouter, int marginWidth) { 241 final IDelegateUpdating refactoring= (IDelegateUpdating) getRefactoring().getAdapter(IDelegateUpdating.class); 242 if (refactoring == null || !refactoring.canEnableDelegateUpdating()) 243 return; 244 fDeprecateDelegateCheckBox= new Button(result, SWT.CHECK); 245 GridData data= new GridData(); 246 data.horizontalAlignment= GridData.FILL; 247 data.horizontalIndent= (marginWidth + fDeprecateDelegateCheckBox.computeSize(SWT.DEFAULT, SWT.DEFAULT).x); 248 fDeprecateDelegateCheckBox.setLayoutData(data); 249 fDeprecateDelegateCheckBox.setText(DelegateUIHelper.getDeprecateDelegateCheckBoxTitle()); 250 fDeprecateDelegateCheckBox.setSelection(DelegateUIHelper.loadDeprecateDelegateSetting(refactoring)); 251 layouter.perform(fDeprecateDelegateCheckBox); 252 refactoring.setDeprecateDelegates(fDeprecateDelegateCheckBox.getSelection()); 253 fDeprecateDelegateCheckBox.addSelectionListener(new SelectionAdapter() { 254 public void widgetSelected(SelectionEvent e) { 255 refactoring.setDeprecateDelegates(fDeprecateDelegateCheckBox.getSelection()); 256 } 257 }); 258 if (fLeaveDelegateCheckBox != null) { 259 fDeprecateDelegateCheckBox.setEnabled(fLeaveDelegateCheckBox.getSelection()); 260 fLeaveDelegateCheckBox.addSelectionListener(new SelectionAdapter() { 261 public void widgetSelected(SelectionEvent e) { 262 fDeprecateDelegateCheckBox.setEnabled(fLeaveDelegateCheckBox.getSelection()); 263 } 264 }); 265 } 266 } 267 268 protected void updateLeaveDelegateCheckbox(int delegateCount) { 269 if (fLeaveDelegateCheckBox == null) 270 return; 271 final IDelegateUpdating refactoring= (IDelegateUpdating) getRefactoring().getAdapter(IDelegateUpdating.class); 272 fLeaveDelegateCheckBox.setEnabled(delegateCount > 0); 273 fLeaveDelegateCheckBox.setText(refactoring.getDelegateUpdatingTitle(delegateCount > 1)); 274 if (delegateCount == 0) { 275 fLeaveDelegateCheckBox.setSelection(false); 276 refactoring.setDelegateUpdating(false); 277 } 278 } 279 280 protected String getLabelText() { 281 return RefactoringMessages.RenameInputWizardPage_new_name; 282 } 283 284 protected boolean getBooleanSetting(String key, boolean defaultValue) { 285 String update= getRefactoringSettings().get(key); 286 if (update != null) 287 return Boolean.valueOf(update).booleanValue(); 288 else 289 return defaultValue; 290 } 291 292 protected void saveBooleanSetting(String key, Button checkBox) { 293 if (checkBox != null) 294 getRefactoringSettings().put(key, checkBox.getSelection()); 295 } 296 297 private static Button createCheckbox(Composite parent, String title, boolean value, RowLayouter layouter) { 298 Button checkBox= new Button(parent, SWT.CHECK); 299 checkBox.setText(title); 300 checkBox.setSelection(value); 301 layouter.perform(checkBox); 302 return checkBox; 303 } 304 305 private void updateForcePreview() { 306 boolean forcePreview= false; 307 Refactoring refactoring= getRefactoring(); 308 ITextUpdating tu= (ITextUpdating) refactoring.getAdapter(ITextUpdating.class); 309 IQualifiedNameUpdating qu= (IQualifiedNameUpdating)refactoring.getAdapter(IQualifiedNameUpdating.class); 310 if (tu != null) { 311 forcePreview= tu.getUpdateTextualMatches(); 312 } 313 if (qu != null) { 314 forcePreview |= qu.getUpdateQualifiedNames(); 315 } 316 getRefactoringWizard().setForcePreviewReview(forcePreview); 317 } 318 } 319 | Popular Tags |