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.widgets.Button; 17 import org.eclipse.swt.widgets.Composite; 18 19 import org.eclipse.ltk.core.refactoring.Refactoring; 20 21 import org.eclipse.jdt.internal.corext.refactoring.tagging.IDelegateUpdating; 22 23 import org.eclipse.jdt.internal.ui.JavaPlugin; 24 25 32 public class DelegateUIHelper { 33 34 public static Button generateDeprecateDelegateCheckbox(Composite parent, Refactoring refactoring) { 35 final IDelegateUpdating updating= (IDelegateUpdating) refactoring.getAdapter(IDelegateUpdating.class); 36 if (updating == null || !updating.canEnableDelegateUpdating()) 37 return null; 38 final Button button= createCheckbox(parent, getDeprecateDelegateCheckBoxTitle(), loadDeprecateDelegateSetting(updating)); 39 updating.setDeprecateDelegates(button.getSelection()); 40 button.addSelectionListener(new SelectionAdapter() { 41 42 public void widgetSelected(SelectionEvent e) { 43 updating.setDeprecateDelegates(button.getSelection()); 44 } 45 }); 46 return button; 47 } 48 49 public static Button generateLeaveDelegateCheckbox(Composite parent, Refactoring refactoring, boolean plural) { 50 final IDelegateUpdating updating= (IDelegateUpdating) refactoring.getAdapter(IDelegateUpdating.class); 51 if (updating == null || !updating.canEnableDelegateUpdating()) 52 return null; 53 final Button button= createCheckbox(parent, updating.getDelegateUpdatingTitle(plural), loadLeaveDelegateSetting(updating)); 54 updating.setDelegateUpdating(button.getSelection()); 55 button.addSelectionListener(new SelectionAdapter() { 56 57 public void widgetSelected(SelectionEvent e) { 58 updating.setDelegateUpdating(button.getSelection()); 59 } 60 }); 61 return button; 62 } 63 64 public static void saveLeaveDelegateSetting(Button button) { 65 saveBooleanSetting(DELEGATE_UPDATING, button); 66 } 67 68 public static void saveDeprecateDelegateSetting(Button button) { 69 saveBooleanSetting(DELEGATE_DEPRECATION, button); 70 } 71 72 public static boolean loadLeaveDelegateSetting(IDelegateUpdating refactoring) { 73 return getBooleanSetting(DELEGATE_UPDATING, refactoring.getDelegateUpdating()); 74 } 75 76 public static boolean loadDeprecateDelegateSetting(IDelegateUpdating refactoring) { 77 return getBooleanSetting(DELEGATE_DEPRECATION, refactoring.getDeprecateDelegates()); 78 } 79 80 public static String getDeprecateDelegateCheckBoxTitle() { 81 return RefactoringMessages.DelegateCreator_deprecate_delegates; 82 } 83 84 86 89 public static final String DELEGATE_UPDATING= "delegateUpdating"; 91 94 public static final String DELEGATE_DEPRECATION= "delegateDeprecation"; 96 private DelegateUIHelper() { 97 } 99 100 private static Button createCheckbox(Composite parent, String title, boolean value) { 101 Button checkBox= new Button(parent, SWT.CHECK); 102 checkBox.setText(title); 103 checkBox.setSelection(value); 104 return checkBox; 105 } 106 107 private static boolean getBooleanSetting(String key, boolean defaultValue) { 108 String update= JavaPlugin.getDefault().getDialogSettings().get(key); 109 if (update != null) 110 return Boolean.valueOf(update).booleanValue(); 111 else 112 return defaultValue; 113 } 114 115 private static void saveBooleanSetting(String key, Button button) { 116 if (button != null && !button.isDisposed() && button.getEnabled()) 117 JavaPlugin.getDefault().getDialogSettings().put(key, button.getSelection()); 118 } 119 } 120 | Popular Tags |