1 11 package org.eclipse.ui.internal.dialogs; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.jface.dialogs.IDialogSettings; 15 import org.eclipse.jface.preference.IPreferenceNode; 16 import org.eclipse.jface.preference.PreferenceManager; 17 import org.eclipse.swt.widgets.Shell; 18 import org.eclipse.ui.IWorkbench; 19 import org.eclipse.ui.IWorkbenchWindow; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.activities.WorkbenchActivityHelper; 22 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 23 import org.eclipse.ui.internal.WorkbenchPlugin; 24 25 29 public class WorkbenchPreferenceDialog extends FilteredPreferenceDialog { 30 37 private static WorkbenchPreferenceDialog instance = null; 38 39 47 private static final String DIALOG_SETTINGS_SECTION = "WorkbenchPreferenceDialogSettings"; 49 50 68 public static final WorkbenchPreferenceDialog createDialogOn(Shell shell, final String preferencePageId) { 69 final WorkbenchPreferenceDialog dialog; 70 71 if (instance == null) { 72 76 77 Shell parentShell = shell; 78 if (parentShell == null) { 79 final IWorkbench workbench = PlatformUI.getWorkbench(); 81 final IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow(); 82 if (workbenchWindow != null) { 83 parentShell = workbenchWindow.getShell(); 84 } else { 85 parentShell = null; 86 } 87 } 88 89 final PreferenceManager preferenceManager = PlatformUI.getWorkbench() 91 .getPreferenceManager(); 92 dialog = new WorkbenchPreferenceDialog(parentShell, preferenceManager); 93 if (preferencePageId != null) { 94 dialog.setSelectedNode(preferencePageId); 95 } 96 dialog.create(); 97 PlatformUI.getWorkbench().getHelpSystem().setHelp( 98 dialog.getShell(), 99 IWorkbenchHelpContextIds.PREFERENCE_DIALOG); 100 101 } else { 102 106 dialog = instance; 107 if (preferencePageId != null) { 108 dialog.setCurrentPageId(preferencePageId); 109 } 110 111 } 112 113 return dialog; 115 } 116 117 126 public WorkbenchPreferenceDialog(Shell parentShell, PreferenceManager manager) { 127 super(parentShell, manager); 128 Assert.isTrue((instance == null), 129 "There cannot be two preference dialogs at once in the workbench."); instance = this; 131 132 } 133 134 135 138 public boolean close() { 139 instance = null; 140 return super.close(); 141 } 142 143 144 152 protected IPreferenceNode findNodeMatching(String nodeId) { 153 IPreferenceNode node = super.findNodeMatching(nodeId); 154 if (WorkbenchActivityHelper.filterItem(node)) { 155 return null; 156 } 157 return node; 158 } 159 160 163 protected void okPressed() { 164 super.okPressed(); 165 } 166 167 172 protected IDialogSettings getDialogBoundsSettings() { 173 IDialogSettings settings = WorkbenchPlugin.getDefault().getDialogSettings(); 174 IDialogSettings section = settings.getSection(DIALOG_SETTINGS_SECTION); 175 if (section == null) { 176 section = settings.addNewSection(DIALOG_SETTINGS_SECTION); 177 } 178 return section; 179 } 180 181 188 protected int getDialogBoundsStrategy() { 189 return DIALOG_PERSISTLOCATION; 190 } 191 } 192 | Popular Tags |