1 11 package org.eclipse.debug.internal.ui.preferences; 12 13 import java.util.Iterator ; 14 15 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 16 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 17 import org.eclipse.debug.internal.ui.SWTFactory; 18 import org.eclipse.debug.internal.ui.views.ViewContextService; 19 import org.eclipse.debug.ui.DebugUITools; 20 import org.eclipse.debug.ui.IDebugUIConstants; 21 import org.eclipse.jface.dialogs.Dialog; 22 import org.eclipse.jface.preference.PreferencePage; 23 import org.eclipse.jface.viewers.CheckboxTableViewer; 24 import org.eclipse.jface.viewers.IStructuredContentProvider; 25 import org.eclipse.jface.viewers.Viewer; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.events.SelectionListener; 30 import org.eclipse.swt.layout.GridData; 31 import org.eclipse.swt.layout.GridLayout; 32 import org.eclipse.swt.widgets.Button; 33 import org.eclipse.swt.widgets.Composite; 34 import org.eclipse.swt.widgets.Control; 35 import org.eclipse.swt.widgets.Label; 36 import org.eclipse.swt.widgets.Table; 37 import org.eclipse.ui.IPerspectiveDescriptor; 38 import org.eclipse.ui.IPerspectiveRegistry; 39 import org.eclipse.ui.IWorkbench; 40 import org.eclipse.ui.IWorkbenchPreferencePage; 41 import org.eclipse.ui.PlatformUI; 42 import org.eclipse.ui.model.PerspectiveLabelProvider; 43 44 48 public class ViewManagementPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 49 50 private CheckboxTableViewer fPerspectiveViewer; 51 private Button fTrackViewsButton; 52 private Button fResetViewsButton; 53 private boolean fResetPressed= false; 55 private PerspectiveLabelProvider fLabelProvider= null; 56 private SelectionListener fSelectionListener= new SelectionAdapter() { 57 58 public void widgetSelected(SelectionEvent e) { 59 Object source = e.getSource(); 60 if (source == fResetViewsButton) { 61 handleResetPressed(); 62 } else if (source == fTrackViewsButton) { 63 handleTrackViewsToggled(); 64 } 65 } 66 67 }; 68 69 public ViewManagementPreferencePage() { 70 super(); 71 setTitle(DebugPreferencesMessages.ViewManagementPreferencePage_1); 72 setDescription(DebugPreferencesMessages.ViewManagementPreferencePage_0); 73 setPreferenceStore(DebugUITools.getPreferenceStore()); 74 } 75 76 79 public void createControl(Composite parent) { 80 super.createControl(parent); 81 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IDebugHelpContextIds.VIEW_MANAGEMENT_PREFERENCE_PAGE); 82 } 83 84 87 protected Control createContents(Composite parent) { 88 Composite composite= new Composite(parent, SWT.NONE); 89 composite.setLayout(new GridLayout()); 90 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 91 composite.setFont(parent.getFont()); 92 93 createPerspectiveViewer(composite); 94 95 createViewTrackingOptions(composite); 96 97 Dialog.applyDialogFont(composite); 98 99 return composite; 100 } 101 102 105 private void createViewTrackingOptions(Composite composite) { 106 fTrackViewsButton= new Button(composite, SWT.CHECK); 107 fTrackViewsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 108 fTrackViewsButton.setText(DebugPreferencesMessages.ViewManagementPreferencePage_3); 109 fTrackViewsButton.setSelection(DebugUITools.getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_TRACK_VIEWS)); 110 fTrackViewsButton.addSelectionListener(fSelectionListener); 111 112 Label label= new Label(composite, SWT.WRAP); 113 label.setText(DebugPreferencesMessages.ViewManagementPreferencePage_4); 114 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 115 116 fResetViewsButton= SWTFactory.createPushButton(composite, DebugPreferencesMessages.ViewManagementPreferencePage_5, null); 117 ((GridData) fResetViewsButton.getLayoutData()).horizontalAlignment= GridData.BEGINNING; 118 fResetViewsButton.addSelectionListener(fSelectionListener); 119 updateResetButton(); 120 } 121 122 private void handleResetPressed() { 123 fResetPressed= true; 124 fResetViewsButton.setEnabled(false); 125 } 126 127 protected void handleTrackViewsToggled() { 128 if (fTrackViewsButton.getSelection()) { 129 updateResetButton(); 131 } else { 132 fResetViewsButton.setEnabled(false); 134 } 135 } 136 137 140 private void createPerspectiveViewer(Composite parent) { 141 Label label= new Label(parent, SWT.WRAP); 142 label.setText(DebugPreferencesMessages.ViewManagementPreferencePage_2); 143 label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 144 145 Table table= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION); 146 table.setLayout(new GridLayout()); 147 table.setLayoutData(new GridData(GridData.FILL_BOTH)); 148 149 fPerspectiveViewer= new CheckboxTableViewer(table); 150 PerspectiveProvider provider= new PerspectiveProvider(); 151 fPerspectiveViewer.setContentProvider(provider); 152 fLabelProvider= new PerspectiveLabelProvider(); 153 fPerspectiveViewer.setLabelProvider(fLabelProvider); 154 fPerspectiveViewer.setInput(this); 155 156 checkPerspectives(getPreferenceStore().getString(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES)); 157 } 158 159 private void checkPerspectives(String perspectiveList) { 160 fPerspectiveViewer.setAllChecked(false); 161 IPerspectiveRegistry registry= PlatformUI.getWorkbench().getPerspectiveRegistry(); 162 Iterator perspectiveIds= ViewContextService.parseList(perspectiveList).iterator(); 163 while (perspectiveIds.hasNext()) { 164 IPerspectiveDescriptor descriptor = registry.findPerspectiveWithId((String ) perspectiveIds.next()); 165 if (descriptor != null) { 166 fPerspectiveViewer.setChecked(descriptor, true); 167 } 168 } 169 } 170 171 174 public boolean performOk() { 175 StringBuffer buffer= new StringBuffer (); 176 Object [] descriptors = fPerspectiveViewer.getCheckedElements(); 177 for (int i = 0; i < descriptors.length; i++) { 178 buffer.append(((IPerspectiveDescriptor) descriptors[i]).getId()).append(','); 179 } 180 181 getPreferenceStore().setValue(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES, buffer.toString()); 182 boolean trackViews = fTrackViewsButton.getSelection(); 183 getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_TRACK_VIEWS, trackViews); 184 if (fResetPressed || !trackViews) { 185 getPreferenceStore().setValue(IInternalDebugUIConstants.PREF_USER_VIEW_BINDINGS, ""); } 188 return super.performOk(); 189 } 190 191 194 protected void performDefaults() { 195 checkPerspectives(getPreferenceStore().getDefaultString(IDebugUIConstants.PREF_MANAGE_VIEW_PERSPECTIVES)); 196 fTrackViewsButton.setSelection(getPreferenceStore().getDefaultBoolean(IInternalDebugUIConstants.PREF_TRACK_VIEWS)); 197 fResetPressed= false; 198 updateResetButton(); 199 super.performDefaults(); 200 } 201 202 205 public void init(IWorkbench workbench) { 206 } 207 208 213 private void updateResetButton() { 214 boolean enableReset= !"".equals(getPreferenceStore().getString(IInternalDebugUIConstants.PREF_USER_VIEW_BINDINGS)); fResetViewsButton.setEnabled(enableReset && !fResetPressed && fTrackViewsButton.getSelection()); 218 } 219 220 private static class PerspectiveProvider implements IStructuredContentProvider { 221 222 225 public Object [] getElements(Object inputElement) { 226 return PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives(); 227 } 228 229 232 public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { 233 } 234 235 238 public void dispose() { 239 } 240 241 } 242 245 public void dispose() { 246 super.dispose(); 247 if (fLabelProvider != null) { 248 fLabelProvider.dispose(); 249 } 250 } 251 } 252 | Popular Tags |