1 11 package org.eclipse.help.ui.internal.browser; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.core.runtime.Preferences; 16 import org.eclipse.help.internal.base.HelpBasePlugin; 17 import org.eclipse.help.internal.base.IHelpBaseConstants; 18 import org.eclipse.help.internal.browser.BrowserManager; 19 import org.eclipse.help.ui.internal.IHelpUIConstants; 20 import org.eclipse.help.ui.internal.Messages; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.jface.preference.IPreferenceNode; 23 import org.eclipse.jface.preference.IPreferencePage; 24 import org.eclipse.jface.preference.PreferenceManager; 25 import org.eclipse.jface.preference.PreferencePage; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.layout.GridData; 28 import org.eclipse.swt.layout.GridLayout; 29 import org.eclipse.swt.widgets.Button; 30 import org.eclipse.swt.widgets.Composite; 31 import org.eclipse.swt.widgets.Control; 32 import org.eclipse.swt.widgets.Group; 33 import org.eclipse.swt.widgets.Label; 34 import org.eclipse.ui.IWorkbench; 35 import org.eclipse.ui.IWorkbenchPreferencePage; 36 import org.eclipse.ui.PlatformUI; 37 import org.eclipse.ui.dialogs.PreferenceLinkArea; 38 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 39 40 43 public class BrowsersPreferencePage extends PreferencePage implements 44 IWorkbenchPreferencePage { 45 private Button alwaysExternal; 46 47 private static final String WBROWSER_PAGE_ID = "org.eclipse.ui.browser.preferencePage"; 49 private Button whelpAsViewButton; 50 51 private Button whelpAsInfopopButton; 52 53 private Button dhelpAsTrayButton; 54 55 private Button dhelpAsInfopopButton; 56 57 private Button openInPlaceButton; 58 59 private Button openInEditorButton; 60 61 private Button showPotentialHitsButton; 62 63 private Button showActualHitsButton; 64 65 71 protected Control createContents(Composite parent) { 72 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, 73 IHelpUIConstants.PREF_PAGE_BROWSERS); 74 Composite mainComposite = new Composite(parent, SWT.NULL); 75 GridData data = new GridData(); 76 data.verticalAlignment = GridData.FILL; 77 data.horizontalAlignment = GridData.FILL; 78 mainComposite.setLayoutData(data); 79 GridLayout layout = new GridLayout(); 80 layout.marginHeight = 0; 81 layout.marginWidth = 0; 82 mainComposite.setLayout(layout); 83 Label description = new Label(mainComposite, SWT.NULL); 84 description.setText(Messages.select_browser); 85 if (BrowserManager.getInstance().isEmbeddedBrowserPresent()) { 86 alwaysExternal = new Button(mainComposite, SWT.CHECK); 87 alwaysExternal 88 .setLayoutData(new GridData(GridData.GRAB_HORIZONTAL)); 89 alwaysExternal.setText(Messages.use_only_external_browser); 90 alwaysExternal.setSelection(HelpBasePlugin.getDefault() 91 .getPluginPreferences().getBoolean( 92 IHelpBaseConstants.P_KEY_ALWAYS_EXTERNAL_BROWSER)); 93 } 94 createLinkArea(mainComposite); 95 createSpacer(mainComposite); 96 createDynamicHelpArea(mainComposite); 97 createSpacer(mainComposite); 98 createSearchArea(mainComposite); 99 Dialog.applyDialogFont(mainComposite); 100 return mainComposite; 101 } 102 103 private void createLinkArea(Composite parent) { 104 IPreferenceNode node = getPreferenceNode(WBROWSER_PAGE_ID); 105 if (node != null) { 106 PreferenceLinkArea linkArea = new PreferenceLinkArea(parent, 107 SWT.WRAP, WBROWSER_PAGE_ID, 108 Messages.BrowsersPreferencePage_message, 109 (IWorkbenchPreferenceContainer) getContainer(), null); 110 GridData data = new GridData(GridData.FILL_HORIZONTAL 111 | GridData.GRAB_HORIZONTAL); 112 linkArea.getControl().setLayoutData(data); 113 } 114 } 115 116 private void createDynamicHelpArea(Composite parent) { 117 Group group = new Group(parent, SWT.NONE); 118 GridLayout layout = new GridLayout(); 119 layout.numColumns = 2; 120 group.setLayout(layout); 121 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 122 group.setText(Messages.BrowsersPreferencePage_wgroup); 123 whelpAsViewButton = new Button(group, SWT.RADIO); 124 whelpAsViewButton.setText(Messages.BrowsersPreferencePage_view); 125 whelpAsInfopopButton = new Button(group, SWT.RADIO); 126 whelpAsInfopopButton.setText(Messages.BrowsersPreferencePage_winfopop); 127 boolean winfopop = HelpBasePlugin.getDefault().getPluginPreferences() 128 .getBoolean(IHelpBaseConstants.P_KEY_WINDOW_INFOPOP); 129 whelpAsViewButton.setSelection(!winfopop); 130 whelpAsInfopopButton.setSelection(winfopop); 131 132 createSpacer(parent); 133 layout = new GridLayout(); 134 layout.numColumns = 2; 135 group = new Group(parent, SWT.NONE); 136 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 137 group.setLayout(layout); 138 group.setText(Messages.BrowsersPreferencePage_dgroup); 139 dhelpAsTrayButton = new Button(group, SWT.RADIO); 140 dhelpAsTrayButton.setText(Messages.BrowsersPreferencePage_tray); 141 dhelpAsInfopopButton = new Button(group, SWT.RADIO); 142 dhelpAsInfopopButton.setText(Messages.BrowsersPreferencePage_dinfopop); 143 boolean dinfopop = HelpBasePlugin.getDefault().getPluginPreferences() 144 .getBoolean(IHelpBaseConstants.P_KEY_DIALOG_INFOPOP); 145 dhelpAsTrayButton.setSelection(!dinfopop); 146 dhelpAsInfopopButton.setSelection(dinfopop); 147 148 if (PlatformUI.getWorkbench().getBrowserSupport() 149 .isInternalWebBrowserAvailable()) { 150 createSpacer(parent); 151 layout = new GridLayout(); 152 layout.numColumns = 2; 153 group = new Group(parent, SWT.NONE); 154 group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 155 group.setLayout(layout); 156 group.setText(Messages.BrowsersPreferencePage_openModeGroup); 157 openInPlaceButton = new Button(group, SWT.RADIO); 158 openInPlaceButton 159 .setText(Messages.BrowsersPreferencePage_openInPlace); 160 openInEditorButton = new Button(group, SWT.RADIO); 161 openInEditorButton 162 .setText(Messages.BrowsersPreferencePage_openInEditor); 163 boolean openInBrowser = HelpBasePlugin.getDefault() 164 .getPluginPreferences().getBoolean( 165 IHelpBaseConstants.P_KEY_OPEN_IN_EDITOR); 166 openInPlaceButton.setSelection(!openInBrowser); 167 openInEditorButton.setSelection(openInBrowser); 168 } 169 } 170 171 private void createSearchArea(Composite parent) { 172 Group searchGroup = new Group(parent, SWT.NONE); 173 searchGroup.setText(Messages.BrowsersPreferencePage_search); 174 searchGroup.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 175 searchGroup.setLayout(new GridLayout()); 176 177 showPotentialHitsButton = new Button(searchGroup, SWT.RADIO); 178 showPotentialHitsButton.setText(Messages.BrowsersPreferencePage_searchPotentialHits); 179 180 showActualHitsButton = new Button(searchGroup, SWT.RADIO); 181 showActualHitsButton.setText(Messages.BrowsersPreferencePage_searchActualHits); 182 183 boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() 184 .getBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); 185 186 showPotentialHitsButton.setSelection(showPotentialHits); 187 showActualHitsButton.setSelection(!showPotentialHits); 188 } 189 190 private IPreferenceNode getPreferenceNode(String pageId) { 191 Iterator iterator = PlatformUI.getWorkbench().getPreferenceManager() 192 .getElements(PreferenceManager.PRE_ORDER).iterator(); 193 while (iterator.hasNext()) { 194 IPreferenceNode next = (IPreferenceNode) iterator.next(); 195 if (next.getId().equals(pageId)) 196 return next; 197 } 198 return null; 199 } 200 201 204 public void init(IWorkbench workbench) { 205 } 206 207 216 protected void performDefaults() { 217 if (alwaysExternal != null) { 218 alwaysExternal.setSelection(HelpBasePlugin.getDefault() 219 .getPluginPreferences().getDefaultBoolean( 220 IHelpBaseConstants.P_KEY_ALWAYS_EXTERNAL_BROWSER)); 221 } 222 223 boolean winfopop = HelpBasePlugin.getDefault().getPluginPreferences() 224 .getDefaultBoolean(IHelpBaseConstants.P_KEY_WINDOW_INFOPOP); 225 whelpAsViewButton.setSelection(!winfopop); 226 whelpAsInfopopButton.setSelection(winfopop); 227 228 boolean dinfopop = HelpBasePlugin.getDefault().getPluginPreferences() 229 .getDefaultBoolean(IHelpBaseConstants.P_KEY_DIALOG_INFOPOP); 230 dhelpAsTrayButton.setSelection(!dinfopop); 231 dhelpAsInfopopButton.setSelection(dinfopop); 232 233 if (openInPlaceButton!=null) { 234 boolean openInEditor = HelpBasePlugin.getDefault() 235 .getPluginPreferences().getDefaultBoolean( 236 IHelpBaseConstants.P_KEY_OPEN_IN_EDITOR); 237 openInPlaceButton.setSelection(!openInEditor); 238 openInEditorButton.setSelection(openInEditor); 239 } 240 241 boolean showPotentialHits = HelpBasePlugin.getDefault().getPluginPreferences() 242 .getDefaultBoolean(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS); 243 showPotentialHitsButton.setSelection(showPotentialHits); 244 showActualHitsButton.setSelection(!showPotentialHits); 245 246 super.performDefaults(); 247 } 248 249 252 public boolean performOk() { 253 Preferences pref = HelpBasePlugin.getDefault().getPluginPreferences(); 254 if (alwaysExternal != null) { 255 pref.setValue(IHelpBaseConstants.P_KEY_ALWAYS_EXTERNAL_BROWSER, 256 alwaysExternal.getSelection()); 257 BrowserManager.getInstance().setAlwaysUseExternal( 258 alwaysExternal.getSelection()); 259 } 260 pref.setValue(IHelpBaseConstants.P_KEY_WINDOW_INFOPOP, 261 whelpAsInfopopButton.getSelection()); 262 pref.setValue(IHelpBaseConstants.P_KEY_DIALOG_INFOPOP, 263 dhelpAsInfopopButton.getSelection()); 264 if (openInEditorButton!=null) 265 pref.setValue(IHelpBaseConstants.P_KEY_OPEN_IN_EDITOR, 266 openInEditorButton.getSelection()); 267 pref.setValue(IHelpBaseConstants.P_KEY_SHOW_POTENTIAL_HITS, 268 showPotentialHitsButton.getSelection()); 269 HelpBasePlugin.getDefault().savePluginPreferences(); 270 return true; 271 } 272 273 279 private void createSpacer(Composite parent) { 280 Label spacer = new Label(parent, SWT.NONE); 281 GridData data = new GridData(); 282 data.horizontalAlignment = GridData.FILL; 283 data.verticalAlignment = GridData.BEGINNING; 284 spacer.setLayoutData(data); 285 } 286 } 287
| Popular Tags
|