1 11 package org.eclipse.jdt.internal.ui.preferences.cleanup; 12 13 import java.util.Map ; 14 import java.util.Observable ; 15 import java.util.Observer ; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.swt.widgets.Label; 21 22 import org.eclipse.jdt.internal.ui.fix.ICleanUp; 23 import org.eclipse.jdt.internal.ui.preferences.formatter.JavaPreview; 24 import org.eclipse.jdt.internal.ui.preferences.formatter.ModifyDialogTabPage; 25 26 public abstract class CleanUpTabPage extends ModifyDialogTabPage { 27 28 private final Map fValues; 29 private JavaPreview fCleanUpPreview; 30 private final boolean fIsSaveAction; 31 private int fCount; 32 private int fSelectedCount; 33 34 public CleanUpTabPage(IModificationListener listener, Map values, boolean isSaveAction) { 35 super(listener, values); 36 fValues= values; 37 fIsSaveAction= isSaveAction; 38 fCount= 0; 39 fSelectedCount= 0; 40 } 41 42 45 public boolean isSaveAction() { 46 return fIsSaveAction; 47 } 48 49 public int getCleanUpCount() { 50 return fCount; 51 } 52 53 public int getSelectedCleanUpCount() { 54 return fSelectedCount; 55 } 56 57 protected abstract ICleanUp[] createPreviewCleanUps(Map values); 58 59 protected JavaPreview doCreateJavaPreview(Composite parent) { 60 fCleanUpPreview= new CleanUpPreview(parent, createPreviewCleanUps(fValues)); 61 return fCleanUpPreview; 62 } 63 64 protected void doUpdatePreview() { 65 fCleanUpPreview.setWorkingValues(fValues); 66 fCleanUpPreview.update(); 67 } 68 69 protected void initializePage() { 70 fCleanUpPreview.update(); 71 } 72 73 protected void registerPreference(final CheckboxPreference preference) { 74 fCount++; 75 preference.addObserver(new Observer () { 76 public void update(Observable o, Object arg) { 77 if (preference.getChecked()) { 78 fSelectedCount++; 79 } else { 80 fSelectedCount--; 81 } 82 } 83 }); 84 if (preference.getChecked()) { 85 fSelectedCount++; 86 } 87 } 88 89 protected void registerSlavePreference(final CheckboxPreference master, final RadioPreference[] slaves) { 90 internalRegisterSlavePreference(master, slaves); 91 registerPreference(master); 92 } 93 94 protected void registerSlavePreference(final CheckboxPreference master, final CheckboxPreference[] slaves) { 95 internalRegisterSlavePreference(master, slaves); 96 fCount+= slaves.length; 97 98 master.addObserver(new Observer () { 99 public void update(Observable o, Object arg) { 100 if (master.getChecked()) { 101 for (int i= 0; i < slaves.length; i++) { 102 if (slaves[i].getChecked()) { 103 fSelectedCount++; 104 } 105 } 106 } else { 107 for (int i= 0; i < slaves.length; i++) { 108 if (slaves[i].getChecked()) { 109 fSelectedCount--; 110 } 111 } 112 } 113 } 114 }); 115 116 for (int i= 0; i < slaves.length; i++) { 117 final CheckboxPreference slave= slaves[i]; 118 slave.addObserver(new Observer () { 119 public void update(Observable o, Object arg) { 120 if (slave.getChecked()) { 121 fSelectedCount++; 122 } else { 123 fSelectedCount--; 124 } 125 } 126 }); 127 } 128 129 if (master.getChecked()) { 130 for (int i= 0; i < slaves.length; i++) { 131 if (slaves[i].getChecked()) { 132 fSelectedCount++; 133 } 134 } 135 } 136 } 137 138 private void internalRegisterSlavePreference(final CheckboxPreference master, final ButtonPreference[] slaves) { 139 master.addObserver( new Observer () { 140 public void update(Observable o, Object arg) { 141 for (int i= 0; i < slaves.length; i++) { 142 slaves[i].setEnabled(master.getChecked()); 143 } 144 } 145 }); 146 147 for (int i= 0; i < slaves.length; i++) { 148 slaves[i].setEnabled(master.getChecked()); 149 } 150 } 151 152 protected void intent(Composite group) { 153 Label l= new Label(group, SWT.NONE); 154 GridData gd= new GridData(); 155 gd.widthHint= fPixelConverter.convertWidthInCharsToPixels(4); 156 l.setLayoutData(gd); 157 } 158 159 } | Popular Tags |