1 11 package org.eclipse.help.ui; 12 13 import java.util.Hashtable ; 14 15 import org.eclipse.help.ui.internal.Messages; 16 import org.eclipse.help.ui.internal.views.EngineDescriptor; 17 import org.eclipse.help.ui.internal.views.ScopeSet; 18 import org.eclipse.jface.preference.IPreferenceStore; 19 import org.eclipse.jface.preference.PreferencePage; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.SelectionAdapter; 22 import org.eclipse.swt.events.SelectionEvent; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Control; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Text; 30 31 41 public abstract class RootScopePage extends PreferencePage implements 42 ISearchScopePage { 43 private IEngineDescriptor ed; 44 45 private String scopeSetName; 46 47 private Button masterButton; 48 49 private Text labelText; 50 51 private Text descText; 52 53 private Hashtable disabledStates = new Hashtable (); 54 55 58 public RootScopePage() { 59 } 60 61 66 public void init(IEngineDescriptor ed, String scopeSetName) { 67 this.ed = ed; 68 this.scopeSetName = scopeSetName; 69 } 70 71 80 protected final Control createContents(Composite parent) { 81 initializeDefaults(getPreferenceStore()); 82 Composite container = new Composite(parent, SWT.NULL); 83 GridLayout layout = new GridLayout(); 84 layout.numColumns = 2; 86 container.setLayout(layout); 87 masterButton = new Button(container, SWT.CHECK); 88 masterButton.setText(Messages.RootScopePage_masterButton); 89 GridData gd = new GridData(); 90 gd.horizontalSpan = 2; masterButton.setLayoutData(gd); 92 Label spacer = new Label(container, SWT.NULL); 93 gd = new GridData(); 94 gd.horizontalSpan = 2; spacer.setLayoutData(gd); 96 boolean masterValue = getPreferenceStore().getBoolean( 97 ScopeSet.getMasterKey(ed.getId())); 98 masterButton.setSelection(masterValue); 99 masterButton.addSelectionListener(new SelectionAdapter() { 100 public void widgetSelected(SelectionEvent e) { 101 masterValueChanged(masterButton.getSelection()); 102 } 103 }); 104 Label label = new Label(container, SWT.NULL); 106 label.setText(Messages.RootScopePage_name); 107 labelText = new Text(container, SWT.BORDER); 108 gd = new GridData(GridData.FILL_HORIZONTAL); 109 gd.widthHint = 200; 110 labelText.setLayoutData(gd); 111 labelText.setEditable(ed.isUserDefined()); 112 label = new Label(container, SWT.NULL); 113 label.setText(Messages.RootScopePage_desc); 114 gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); 115 label.setLayoutData(gd); 116 descText = new Text(container, SWT.BORDER | SWT.MULTI | SWT.WRAP); 117 gd = new GridData(GridData.FILL_HORIZONTAL); 118 descText.setEditable(ed.isUserDefined()); 119 gd.widthHint = 200; 120 gd.heightHint = 48; 121 descText.setLayoutData(gd); 122 int ccol = createScopeContents(container); 124 if (ccol > layout.numColumns) { 126 layout.numColumns = ccol; 127 gd = (GridData) masterButton.getLayoutData(); 128 gd.horizontalSpan = layout.numColumns; 129 gd = (GridData) spacer.getLayoutData(); 130 gd.horizontalSpan = layout.numColumns; 131 gd = (GridData) labelText.getLayoutData(); 133 gd.horizontalSpan = layout.numColumns - 1; 134 gd = (GridData) descText.getLayoutData(); 135 gd.horizontalSpan = layout.numColumns - 1; 136 } 138 updateControls(true); 139 return container; 140 } 141 142 151 152 protected void masterValueChanged(boolean value) { 153 updateEnableState(value); 154 } 155 156 private void updateEnableState(boolean enabled) { 157 Composite container = masterButton.getParent(); 158 Control[] children = container.getChildren(); 159 160 boolean first = disabledStates.isEmpty(); 161 for (int i = 0; i < children.length; i++) { 162 Control child = children[i]; 163 if (child == masterButton) 164 continue; 165 if (!enabled) { 166 disabledStates.put(child, new Boolean (child.isEnabled())); 167 child.setEnabled(false); 168 } else { 169 Boolean savedState = (Boolean ) disabledStates.get(child); 170 if (!first) 171 child.setEnabled(savedState != null ? savedState 172 .booleanValue() : true); 173 } 174 } 175 } 176 177 182 183 protected String getScopeSetName() { 184 return scopeSetName; 185 } 186 187 192 193 protected IEngineDescriptor getEngineDescriptor() { 194 return ed; 195 } 196 197 204 205 protected boolean isEngineEnabled() { 206 return masterButton.getSelection(); 207 } 208 209 216 217 public boolean performOk() { 218 getPreferenceStore().setValue(ScopeSet.getMasterKey(ed.getId()), 219 masterButton.getSelection()); 220 if (labelText != null) { 221 ed.setLabel(labelText.getText()); 222 ed.setDescription(descText.getText()); 223 } 224 return true; 225 } 226 227 231 protected void performDefaults() { 232 getPreferenceStore().setToDefault(ScopeSet.getMasterKey(ed.getId())); 233 updateControls(false); 234 super.performDefaults(); 235 } 236 237 private void updateControls(boolean first) { 238 boolean value = getPreferenceStore().getBoolean( 239 ScopeSet.getMasterKey(ed.getId())); 240 boolean cvalue = masterButton.getSelection(); 241 if (value != cvalue) { 242 masterButton.setSelection(value); 243 masterValueChanged(value); 244 } else if (first) 245 masterValueChanged(value); 246 labelText.setText(ed.getLabel()); 247 descText.setText(ed.getDescription()); 248 } 249 250 257 258 protected void initializeDefaults(IPreferenceStore store) { 259 Boolean value = (Boolean ) ed.getParameters().get( 260 EngineDescriptor.P_MASTER); 261 store.setDefault(ScopeSet.getMasterKey(ed.getId()), value 262 .booleanValue()); 263 } 264 265 281 protected abstract int createScopeContents(Composite parent); 282 } 283 | Popular Tags |