1 11 12 package org.eclipse.ui.internal.dialogs; 13 14 import java.util.Arrays ; 15 import java.util.Comparator ; 16 import java.util.Locale ; 17 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IProgressMonitor; 20 import org.eclipse.core.runtime.IStatus; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.jface.dialogs.IDialogConstants; 24 import org.eclipse.jface.dialogs.MessageDialog; 25 import org.eclipse.jface.preference.IPreferenceStore; 26 import org.eclipse.jface.preference.PreferencePage; 27 import org.eclipse.jface.util.IPropertyChangeListener; 28 import org.eclipse.jface.util.PropertyChangeEvent; 29 import org.eclipse.jface.window.Window; 30 import org.eclipse.osgi.util.NLS; 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.accessibility.AccessibleAdapter; 33 import org.eclipse.swt.accessibility.AccessibleEvent; 34 import org.eclipse.swt.events.SelectionAdapter; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.events.SelectionListener; 37 import org.eclipse.swt.layout.FormAttachment; 38 import org.eclipse.swt.layout.FormData; 39 import org.eclipse.swt.layout.FormLayout; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.layout.GridLayout; 42 import org.eclipse.swt.widgets.Button; 43 import org.eclipse.swt.widgets.Combo; 44 import org.eclipse.swt.widgets.Composite; 45 import org.eclipse.swt.widgets.Control; 46 import org.eclipse.swt.widgets.Group; 47 import org.eclipse.swt.widgets.Label; 48 import org.eclipse.swt.widgets.Text; 49 import org.eclipse.ui.IWorkbench; 50 import org.eclipse.ui.IWorkbenchPreferenceConstants; 51 import org.eclipse.ui.IWorkbenchPreferencePage; 52 import org.eclipse.ui.PlatformUI; 53 import org.eclipse.ui.internal.IPreferenceConstants; 54 import org.eclipse.ui.internal.IWorkbenchConstants; 55 import org.eclipse.ui.internal.IWorkbenchHelpContextIds; 56 import org.eclipse.ui.internal.Workbench; 57 import org.eclipse.ui.internal.WorkbenchMessages; 58 import org.eclipse.ui.internal.WorkbenchPlugin; 59 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 60 import org.eclipse.ui.internal.themes.IThemeDescriptor; 61 import org.eclipse.ui.internal.util.PrefUtil; 62 import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer; 63 import org.eclipse.ui.progress.UIJob; 64 import org.eclipse.ui.themes.ITheme; 65 import org.eclipse.ui.themes.IThemeManager; 66 67 import com.ibm.icu.text.Collator; 68 69 74 public class ViewsPreferencePage extends PreferencePage implements 75 IWorkbenchPreferencePage { 76 77 private Button showTextOnPerspectiveBar; 78 79 82 private Button showTraditionalStyleTabs; 83 84 private Button enableAnimations; 85 86 private Button editorTopButton; 87 88 private Button editorBottomButton; 89 90 private Button viewTopButton; 91 92 private Button viewBottomButton; 93 94 private Button perspLeftButton; 95 96 private Button perspTopLeftButton; 97 98 private Button perspTopRightButton; 99 100 static final String EDITORS_TITLE = WorkbenchMessages.ViewsPreference_editors; 101 102 private static final String EDITORS_TOP_TITLE = WorkbenchMessages.ViewsPreference_editors_top; 103 104 private static final String EDITORS_BOTTOM_TITLE = WorkbenchMessages.ViewsPreference_editors_bottom; 105 106 private static final String VIEWS_TITLE = WorkbenchMessages.ViewsPreference_views; 107 108 private static final String VIEWS_TOP_TITLE = WorkbenchMessages.ViewsPreference_views_top; 109 110 private static final String VIEWS_BOTTOM_TITLE = WorkbenchMessages.ViewsPreference_views_bottom; 111 112 private static final String PERSP_TITLE = WorkbenchMessages.ViewsPreference_perspectiveBar; 113 114 private static final String PERSP_LEFT_TITLE = WorkbenchMessages.ViewsPreference_perspectiveBar_left; 115 116 private static final String PERSP_TOP_LEFT_TITLE = WorkbenchMessages.ViewsPreference_perspectiveBar_topLeft; 117 118 private static final String PERSP_TOP_RIGHT_TITLE = WorkbenchMessages.ViewsPreference_perspectiveBar_topRight; 119 120 private static final String R21PRESENTATION_ID = "org.eclipse.ui.internal.r21presentationFactory"; private static final String DEFAULT_PRESENTATION_ID = IWorkbenchConstants.DEFAULT_PRESENTATION_ID; 126 private static final String R30_PRESENTATION_ID = "org.eclipse.ui.presentations.r30"; 128 private static final String INITIAL_VAL = new String (); 129 130 private static final int INITIAL_LOC_INT = -1; 131 132 private String fastViewLoc = INITIAL_VAL; 135 136 private String showTextOnPerspBar = INITIAL_VAL; 137 138 private int editorAlignment; 139 140 private boolean editorAlignmentChanged = false; 141 142 private int viewAlignment; 143 144 private boolean viewAlignmentChanged = false; 145 146 private String perspBarLocation; 147 148 private Combo themeCombo; 149 150 private Combo presentationCombo; 151 152 private IConfigurationElement[] presentationFactories; 153 154 private String currentPresentationFactoryId; 155 156 private Button overridePresButton; 157 158 private IPropertyChangeListener overrideListener; 159 160 private boolean restartPosted = false; 161 162 private Group editorTabGroup; 163 164 private Group viewTabGroup; 165 166 private Group perspBarTabGroup; 167 168 private Text themeDescriptionText; 169 170 176 private Group createButtonGroup(Composite composite, String title) { 177 Group buttonComposite = new Group(composite, SWT.NONE); 178 buttonComposite.setText(title); 179 FormLayout layout = new FormLayout(); 180 layout.marginWidth = 5; layout.marginHeight = 5; buttonComposite.setLayout(layout); 183 buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 184 return buttonComposite; 185 } 186 187 197 protected Control createContents(Composite parent) { 198 initializeDialogUnits(parent); 199 200 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, 201 IWorkbenchHelpContextIds.VIEWS_PREFERENCE_PAGE); 202 203 IPreferenceStore internalStore = PrefUtil.getInternalPreferenceStore(); 204 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 205 206 editorAlignment = internalStore 207 .getInt(IPreferenceConstants.EDITOR_TAB_POSITION); 208 viewAlignment = internalStore 209 .getInt(IPreferenceConstants.VIEW_TAB_POSITION); 210 perspBarLocation = apiStore 211 .getString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR); 212 213 Composite composite = new Composite(parent, SWT.NONE); 214 composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); 215 216 GridLayout layout = new GridLayout(); 217 layout.marginWidth = 0; 218 layout.marginHeight = 0; 219 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 220 composite.setLayout(layout); 221 222 createPresentationCombo(composite); 223 createPresentationOverride(composite); 224 createEditorTabButtonGroup(composite); 225 createViewTabButtonGroup(composite); 226 createPerspBarTabButtonGroup(composite); 227 createShowTextOnPerspectiveBarPref(composite); 228 createThemeCombo(composite); 229 createThemeDescriptionText(composite); 230 createShowTraditionalStyleTabsPref(composite); 231 createEnableAnimationsPref(composite); 232 233 updateOverride(); 234 hookOverrideListener(); 235 236 applyDialogFont(composite); 237 238 return composite; 239 } 240 241 private void createThemeCombo(Composite composite) { 242 new Label(composite, SWT.NONE).setText(WorkbenchMessages.ViewsPreference_currentTheme); 243 themeCombo = new Combo(composite, SWT.READ_ONLY); 244 themeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 245 themeCombo.addSelectionListener(new SelectionAdapter() { 246 public void widgetSelected(SelectionEvent e) { 247 refreshThemeDescriptionText(); 248 } 249 }); 250 refreshThemeCombo(PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getId()); 251 } 252 253 254 261 private void createThemeDescriptionText(Composite parent) { 262 new Label(parent, SWT.NONE) 263 .setText(WorkbenchMessages.ViewsPreference_currentThemeDescription); 264 265 themeDescriptionText = new Text(parent, SWT.H_SCROLL | SWT.V_SCROLL 266 | SWT.READ_ONLY | SWT.BORDER | SWT.WRAP); 267 themeDescriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, 268 true, true)); 269 270 refreshThemeDescriptionText(); 271 } 272 273 private void refreshThemeDescriptionText() { 274 String description = null; 275 int idx = themeCombo.getSelectionIndex(); 276 if (idx > 0) { 278 IThemeDescriptor theme = WorkbenchPlugin.getDefault() 279 .getThemeRegistry().getThemes()[idx - 1]; 280 description = theme.getDescription(); 281 } 282 if (description == null) { 283 description = ""; } 285 themeDescriptionText.setText(description); 286 } 287 288 private Button createCheckButton(Composite composite, String text, boolean selection) { 289 Button button = new Button(composite, SWT.CHECK); 290 button.setText(text); 291 button.setSelection(selection); 292 return button; 293 } 294 295 private void createPresentationOverride(Composite parent) { 296 IPreferenceStore store = getPreferenceStore(); 297 boolean override = store.getBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION); 298 299 boolean showText = PrefUtil.getAPIPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR); 302 if (showText && isR21(currentPresentationFactoryId) || !showText && isR30(currentPresentationFactoryId)) { 303 if (!override) { 304 store.setValue(IPreferenceConstants.OVERRIDE_PRESENTATION, true); 305 override = true; 306 } 307 } 308 String barLocation = PrefUtil.getAPIPreferenceStore().getString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR); 311 if (!barLocation.equals(IWorkbenchPreferenceConstants.LEFT) && isR21(currentPresentationFactoryId) || !barLocation.equals(IWorkbenchPreferenceConstants.TOP_RIGHT) && isR30(currentPresentationFactoryId)) { 312 if (!override) { 313 store.setValue(IPreferenceConstants.OVERRIDE_PRESENTATION, true); 314 override = true; 315 } 316 } 317 318 overridePresButton = createCheckButton(parent, WorkbenchMessages.ViewsPreference_override, override); 319 overridePresButton.addSelectionListener(new SelectionListener() { 320 public void widgetSelected(SelectionEvent e) { 321 updateOverrideState(overridePresButton.getSelection()); 322 } 323 324 public void widgetDefaultSelected(SelectionEvent e) { 325 updateOverrideState(overridePresButton.getSelection()); 326 } 327 }); 328 } 329 330 private void updateOverrideState(boolean override) { 331 IPreferenceStore store = getPreferenceStore(); 332 if (store.getBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION) != override) { 333 store 334 .setValue(IPreferenceConstants.OVERRIDE_PRESENTATION, 335 override); 336 } 337 if (!override) 340 setPresentationPrefs(getSelectedPresentationID()); 341 } 342 343 private void createPresentationCombo(Composite parent) { 344 new Label(parent, SWT.NONE).setText(WorkbenchMessages.ViewsPreference_currentPresentation); 345 346 presentationCombo = new Combo(parent, SWT.READ_ONLY); 347 presentationCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); 348 presentationCombo.addSelectionListener(new SelectionListener() { 349 350 public void widgetSelected(SelectionEvent e) { 351 updateSettings(); 352 } 353 354 public void widgetDefaultSelected(SelectionEvent e) { 355 updateSettings(); 356 } 357 358 private void updateSettings() { 359 if (!overridePresButton.getSelection()) { 360 setPresentationPrefs(getSelectedPresentationID()); 361 } 362 } 363 }); 364 365 refreshPresentationCombo(); 366 setPresentationSelection(); 367 } 368 369 372 private void attachControls(Control leftControl, Control rightControl) { 373 FormData leftData = new FormData(); 374 leftData.left = new FormAttachment(0, 0); 375 376 FormData rightData = new FormData(); 377 rightData.left = new FormAttachment(leftControl, convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING)); 378 379 leftControl.setLayoutData(leftData); 380 rightControl.setLayoutData(rightData); 381 } 382 383 389 private void createEditorTabButtonGroup(Composite composite) { 390 editorTabGroup = createButtonGroup(composite, EDITORS_TITLE); 391 392 editorTopButton = new Button(editorTabGroup, SWT.RADIO); 393 editorTopButton.setText(EDITORS_TOP_TITLE); 394 editorTopButton.setSelection(editorAlignment == SWT.TOP); 395 editorTopButton.getAccessible().addAccessibleListener( 396 new AccessibleAdapter() { 397 public void getName(AccessibleEvent e) { 398 e.result = EDITORS_TITLE; 399 } 400 }); 401 402 editorBottomButton = new Button(editorTabGroup, SWT.RADIO); 403 editorBottomButton.setText(EDITORS_BOTTOM_TITLE); 404 editorBottomButton.setSelection(editorAlignment == SWT.BOTTOM); 405 406 SelectionListener sel = new SelectionAdapter() { 407 public void widgetSelected(SelectionEvent e) { 408 if (e.widget.equals(editorTopButton)) { 409 if (editorAlignment != SWT.TOP) { 410 editorAlignment = SWT.TOP; 411 editorAlignmentChanged = true; 412 } 413 } else if (e.widget.equals(editorBottomButton)) { 414 if (editorAlignment != SWT.BOTTOM) { 415 editorAlignment = SWT.BOTTOM; 416 editorAlignmentChanged = true; 417 } 418 } 419 } 420 }; 421 422 editorTopButton.addSelectionListener(sel); 423 editorBottomButton.addSelectionListener(sel); 424 425 attachControls(editorTopButton, editorBottomButton); 426 } 427 428 434 private void createViewTabButtonGroup(Composite composite) { 435 viewTabGroup = createButtonGroup(composite, VIEWS_TITLE); 436 437 viewTopButton = new Button(viewTabGroup, SWT.RADIO); 438 viewTopButton.setText(VIEWS_TOP_TITLE); 439 viewTopButton.setSelection(this.viewAlignment == SWT.TOP); 440 441 viewBottomButton = new Button(viewTabGroup, SWT.RADIO); 442 viewBottomButton.setText(VIEWS_BOTTOM_TITLE); 443 viewBottomButton.setSelection(viewAlignment == SWT.BOTTOM); 444 445 SelectionListener sel = new SelectionAdapter() { 446 public void widgetSelected(SelectionEvent e) { 447 if (e.widget.equals(viewTopButton)) { 448 if (viewAlignment != SWT.TOP) { 449 viewAlignment = SWT.TOP; 450 viewAlignmentChanged = true; 451 } 452 } else if (e.widget.equals(viewBottomButton)) { 453 if (viewAlignment != SWT.BOTTOM) { 454 viewAlignment = SWT.BOTTOM; 455 viewAlignmentChanged = true; 456 } 457 } 458 } 459 }; 460 461 viewTopButton.addSelectionListener(sel); 462 viewBottomButton.addSelectionListener(sel); 463 464 attachControls(viewTopButton, viewBottomButton); 465 } 466 467 473 private void createPerspBarTabButtonGroup(Composite composite) { 474 perspBarTabGroup = createButtonGroup(composite, PERSP_TITLE); 475 476 perspLeftButton = new Button(perspBarTabGroup, SWT.RADIO); 477 perspLeftButton.setText(PERSP_LEFT_TITLE); 478 perspLeftButton.setSelection(IWorkbenchPreferenceConstants.LEFT 479 .equals(perspBarLocation)); 480 perspLeftButton.addSelectionListener(new SelectionAdapter() { 481 public void widgetSelected(SelectionEvent e) { 482 perspBarLocation = IWorkbenchPreferenceConstants.LEFT; 483 } 484 }); 485 486 perspTopLeftButton = new Button(perspBarTabGroup, SWT.RADIO); 487 perspTopLeftButton.setText(PERSP_TOP_LEFT_TITLE); 488 perspTopLeftButton.setSelection(IWorkbenchPreferenceConstants.TOP_LEFT 489 .equals(perspBarLocation)); 490 perspTopLeftButton.addSelectionListener(new SelectionAdapter() { 491 public void widgetSelected(SelectionEvent e) { 492 perspBarLocation = IWorkbenchPreferenceConstants.TOP_LEFT; 493 } 494 }); 495 496 perspTopRightButton = new Button(perspBarTabGroup, SWT.RADIO); 497 perspTopRightButton.setText(PERSP_TOP_RIGHT_TITLE); 498 perspTopRightButton 499 .setSelection(IWorkbenchPreferenceConstants.TOP_RIGHT 500 .equals(perspBarLocation)); 501 perspTopRightButton.addSelectionListener(new SelectionAdapter() { 502 public void widgetSelected(SelectionEvent e) { 503 perspBarLocation = IWorkbenchPreferenceConstants.TOP_RIGHT; 504 } 505 }); 506 507 int spacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 508 509 FormData leftData = new FormData(); 510 leftData.left = new FormAttachment(0, 0); 511 512 FormData topLeftData = new FormData(); 513 topLeftData.left = new FormAttachment(perspLeftButton, spacing); 514 515 FormData topRightData = new FormData(); 516 topRightData.left = new FormAttachment(perspTopLeftButton, spacing); 517 518 perspLeftButton.setLayoutData(leftData); 519 perspTopLeftButton.setLayoutData(topLeftData); 520 perspTopRightButton.setLayoutData(topRightData); 521 } 522 523 528 private void hookOverrideListener() { 529 if (overrideListener != null) { 530 return; 531 } 532 IPreferenceStore store = getPreferenceStore(); 533 overrideListener = new IPropertyChangeListener() { 534 public void propertyChange(PropertyChangeEvent event) { 535 if (event.getProperty().equals( 536 IPreferenceConstants.OVERRIDE_PRESENTATION)) { 537 updateOverride(); 538 } 539 } 540 }; 541 store.addPropertyChangeListener(overrideListener); 542 } 543 544 547 public void dispose() { 548 super.dispose(); 549 if (overrideListener != null) { 550 getPreferenceStore().removePropertyChangeListener(overrideListener); 551 overrideListener = null; 552 } 553 } 554 555 private void updateOverride() { 556 boolean override = getPreferenceStore().getBoolean( 557 IPreferenceConstants.OVERRIDE_PRESENTATION); 558 editorTabGroup.setEnabled(override); 559 editorTopButton.setEnabled(override); 560 editorBottomButton.setEnabled(override); 561 viewTabGroup.setEnabled(override); 562 viewTopButton.setEnabled(override); 563 viewBottomButton.setEnabled(override); 564 perspBarTabGroup.setEnabled(override); 565 perspTopLeftButton.setEnabled(override); 566 perspLeftButton.setEnabled(override); 567 perspTopRightButton.setEnabled(override); 568 showTextOnPerspectiveBar.setEnabled(override); 569 } 570 571 private void refreshPresentationCombo() { 572 presentationCombo.removeAll(); 574 refreshPresentationFactories(); 575 576 for (int i = 0; i < presentationFactories.length; ++i) { 577 IConfigurationElement el = presentationFactories[i]; 578 String name = el.getAttribute(IWorkbenchConstants.TAG_NAME); 579 if (!currentPresentationFactoryId.equals(el 580 .getAttribute(IWorkbenchConstants.TAG_ID))) { 581 presentationCombo.add(name); 582 } else { 583 presentationCombo 584 .add(NLS.bind( 585 WorkbenchMessages.ViewsPreference_currentPresentationFormat, 586 name)); 587 } 588 } 589 } 590 591 private void setPresentationSelection() { 592 for (int i = 0; i < presentationFactories.length; ++i) { 593 if (currentPresentationFactoryId.equals(presentationFactories[i] 594 .getAttribute(IWorkbenchConstants.TAG_ID))) { 595 presentationCombo.select(i); 596 return; 597 } 598 } 599 } 601 602 607 private void refreshPresentationFactories() { 608 currentPresentationFactoryId = PrefUtil.getAPIPreferenceStore() 610 .getString( 611 IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID); 612 614 presentationFactories = Platform.getExtensionRegistry() 616 .getConfigurationElementsFor(PlatformUI.PLUGIN_ID, 617 IWorkbenchRegistryConstants.PL_PRESENTATION_FACTORIES); 618 619 Arrays.sort(presentationFactories, new Comparator () { 621 Collator collator = Collator.getInstance(Locale.getDefault()); 622 623 public int compare(Object a, Object b) { 624 IConfigurationElement el1 = (IConfigurationElement) a; 625 IConfigurationElement el2 = (IConfigurationElement) b; 626 return collator.compare(el1 627 .getAttribute(IWorkbenchConstants.TAG_NAME), el2 628 .getAttribute(IWorkbenchConstants.TAG_NAME)); 629 } 630 }); 631 } 632 633 639 private boolean updatePresentationPreferences() { 640 645 if (presentationCombo == null) { 646 return false; 647 } 648 649 String id = getSelectedPresentationID(); 650 651 if (id.equals(currentPresentationFactoryId)) { 653 return false; 654 } 655 656 currentPresentationFactoryId = id; 657 setPresentationPrefs(id); 659 PrefUtil.getAPIPreferenceStore().putValue( 661 IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID, id); 662 return true; 664 } 665 666 private void setPresentationPrefs(String id) { 667 if (isR21(id)) { 668 setR21Preferences(); 669 } else if (isR30(id)) { 670 setR30Preferences(); 671 } else if (isR33(id)) { 672 setR33Preferences(); 673 } 674 } 675 676 private boolean isR33(String id) { 677 return DEFAULT_PRESENTATION_ID.equals(id); 678 } 679 680 private boolean isR30(String id) { 681 return R30_PRESENTATION_ID.equals(id); 682 } 683 684 private boolean isR21(String id) { 685 return R21PRESENTATION_ID.equals(id); 686 } 687 688 private String getSelectedPresentationID() { 689 int selection = presentationCombo.getSelectionIndex(); 690 IConfigurationElement element = presentationFactories[selection]; 691 String id = element.getAttribute(IWorkbenchConstants.TAG_ID); 692 return id; 693 } 694 695 private void setR33Preferences() { 696 setR30Preferences(); 697 698 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 700 apiStore.setValue(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX, true); 701 } 702 703 private void setR30Preferences() { 704 IPreferenceStore internalStore = PrefUtil.getInternalPreferenceStore(); 705 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 706 707 apiStore.setValue(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX, false); 709 710 setEditorAlignDefault(internalStore); 711 setViewAlignDefault(internalStore); 712 713 perspBarLocation = apiStore 715 .getDefaultString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR); 716 perspLeftButton.setSelection(perspBarLocation 717 .equals(IWorkbenchPreferenceConstants.LEFT)); 718 perspTopLeftButton.setSelection(perspBarLocation 719 .equals(IWorkbenchPreferenceConstants.TOP_LEFT)); 720 perspTopRightButton.setSelection(perspBarLocation 721 .equals(IWorkbenchPreferenceConstants.TOP_RIGHT)); 722 723 perspBarLocation = INITIAL_VAL; 725 726 showTextOnPerspectiveBar 728 .setSelection(apiStore 729 .getDefaultBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)); 730 showTextOnPerspBar = INITIAL_VAL; 732 733 fastViewLoc = INITIAL_VAL; 735 } 736 737 private void setViewAlignDefault(IPreferenceStore internalStore) { 738 int oldVal; 739 oldVal = viewAlignment; 741 viewAlignment = internalStore 742 .getDefaultInt(IPreferenceConstants.VIEW_TAB_POSITION); 743 viewTopButton.setSelection(viewAlignment == SWT.TOP); 744 viewBottomButton.setSelection(viewAlignment == SWT.BOTTOM); 745 746 if (oldVal != viewAlignment) { 748 viewAlignmentChanged = true; 749 } 750 viewAlignment = INITIAL_LOC_INT; 751 } 752 753 private void setEditorAlignDefault(IPreferenceStore internalStore) { 754 int oldVal = editorAlignment; 757 editorAlignment = internalStore 758 .getDefaultInt(IPreferenceConstants.EDITOR_TAB_POSITION); 759 editorTopButton.setSelection(editorAlignment == SWT.TOP); 760 editorBottomButton.setSelection(editorAlignment == SWT.BOTTOM); 761 762 if (oldVal != editorAlignment) { 764 editorAlignmentChanged = true; 765 } 766 editorAlignment = INITIAL_LOC_INT; 767 } 768 769 private void setR21Preferences() { 770 int oldVal = editorAlignment; 773 editorAlignment = SWT.TOP; 774 editorTopButton.setSelection(editorAlignment == SWT.TOP); 775 editorBottomButton.setSelection(editorAlignment == SWT.BOTTOM); 776 if (oldVal != editorAlignment) { 777 editorAlignmentChanged = true; 778 } 779 780 oldVal = viewAlignment; 783 viewAlignment = SWT.BOTTOM; 784 viewTopButton.setSelection(viewAlignment == SWT.TOP); 785 viewBottomButton.setSelection(viewAlignment == SWT.BOTTOM); 786 if (oldVal != viewAlignment) { 787 viewAlignmentChanged = true; 788 } 789 790 perspBarLocation = IWorkbenchPreferenceConstants.LEFT; 793 perspLeftButton.setSelection(perspBarLocation 794 .equals(IWorkbenchPreferenceConstants.LEFT)); 795 perspTopLeftButton.setSelection(perspBarLocation 796 .equals(IWorkbenchPreferenceConstants.TOP_LEFT)); 797 perspTopRightButton.setSelection(perspBarLocation 798 .equals(IWorkbenchPreferenceConstants.TOP_RIGHT)); 799 800 showTextOnPerspectiveBar.setSelection(false); 803 showTextOnPerspBar = String.valueOf(false); 804 805 fastViewLoc = IWorkbenchPreferenceConstants.LEFT; 807 808 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 810 apiStore.setValue(IWorkbenchPreferenceConstants.ENABLE_NEW_MIN_MAX, false); 811 } 812 813 816 private void refreshThemeCombo(String themeToSelect) { 817 themeCombo.removeAll(); 818 ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager() 819 .getCurrentTheme(); 820 821 IThemeDescriptor[] descs = WorkbenchPlugin.getDefault() 822 .getThemeRegistry().getThemes(); 823 String defaultThemeString = PlatformUI.getWorkbench().getThemeManager() 824 .getTheme(IThemeManager.DEFAULT_THEME).getLabel(); 825 if (currentTheme.getId().equals(IThemeManager.DEFAULT_THEME)) { 826 defaultThemeString = NLS.bind( 827 WorkbenchMessages.ViewsPreference_currentThemeFormat, 828 new Object [] { defaultThemeString }); 829 } 830 themeCombo.add(defaultThemeString); 831 832 String themeString; 833 int selection = 0; 834 for (int i = 0; i < descs.length; i++) { 835 themeString = descs[i].getName(); 836 if (descs[i].getId().equals(currentTheme.getId())) { 837 themeString = NLS.bind( 838 WorkbenchMessages.ViewsPreference_currentThemeFormat, 839 new Object [] { themeString }); 840 } 841 if (themeToSelect.equals(descs[i].getId())) { 842 selection = i + 1; 843 } 844 themeCombo.add(themeString); 845 } 846 themeCombo.select(selection); 847 } 848 849 853 protected void createShowTextOnPerspectiveBarPref(Composite composite) { 854 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 855 856 showTextOnPerspectiveBar = createCheckButton( 857 composite, 858 WorkbenchMessages.WorkbenchPreference_showTextOnPerspectiveBar, 859 apiStore 860 .getBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)); 861 } 862 863 867 protected void createShowTraditionalStyleTabsPref(Composite composite) { 868 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 869 870 showTraditionalStyleTabs = createCheckButton( 871 composite, 872 WorkbenchMessages.ViewsPreference_traditionalTabs, 873 apiStore 874 .getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); 875 } 876 877 protected void createEnableAnimationsPref(Composite composite) { 878 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 879 880 enableAnimations = createCheckButton( 881 composite, 882 WorkbenchMessages.ViewsPreference_enableAnimations, 883 apiStore 884 .getBoolean(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS)); 885 } 886 887 892 protected IPreferenceStore doGetPreferenceStore() { 893 return WorkbenchPlugin.getDefault().getPreferenceStore(); 894 } 895 896 905 public void init(IWorkbench workbench) { 906 currentPresentationFactoryId = PrefUtil.getAPIPreferenceStore() 907 .getString( 908 IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID); 909 } 910 911 914 protected void performDefaults() { 915 IPreferenceStore store = getPreferenceStore(); 916 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 917 918 showTextOnPerspectiveBar 919 .setSelection(apiStore 920 .getDefaultBoolean(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)); 921 showTraditionalStyleTabs 922 .setSelection(apiStore 923 .getDefaultBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); 924 enableAnimations 925 .setSelection(apiStore 926 .getDefaultBoolean(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS)); 927 928 String presID = apiStore 929 .getDefaultString(IWorkbenchPreferenceConstants.PRESENTATION_FACTORY_ID); 930 currentPresentationFactoryId = presID; 931 setPresentationSelection(); 932 933 boolean overridePrefs = store 934 .getDefaultBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION); 935 overridePresButton.setSelection(overridePrefs); 936 937 updateOverrideState(overridePrefs); 938 939 setEditorAlignDefault(store); 940 setViewAlignDefault(store); 941 942 perspBarLocation = apiStore 943 .getDefaultString(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR); 944 perspLeftButton.setSelection(IWorkbenchPreferenceConstants.LEFT 945 .equals(perspBarLocation)); 946 perspTopLeftButton.setSelection(IWorkbenchPreferenceConstants.TOP_LEFT 947 .equals(perspBarLocation)); 948 perspTopRightButton 949 .setSelection(IWorkbenchPreferenceConstants.TOP_RIGHT 950 .equals(perspBarLocation)); 951 952 refreshThemeCombo(PlatformUI.getWorkbench().getThemeManager() 953 .getTheme(IThemeManager.DEFAULT_THEME).getId()); 954 refreshThemeDescriptionText(); 955 956 WorkbenchPlugin.getDefault().savePluginPreferences(); 957 958 super.performDefaults(); 959 } 960 961 964 public boolean performOk() { 965 IPreferenceStore store = getPreferenceStore(); 966 IPreferenceStore apiStore = PrefUtil.getAPIPreferenceStore(); 967 boolean override = store 968 .getBoolean(IPreferenceConstants.OVERRIDE_PRESENTATION); 969 970 boolean restart = updatePresentationPreferences(); 973 974 if (showTextOnPerspBar.equals(INITIAL_VAL) && !override) { 975 apiStore 976 .setToDefault(IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR); 977 } else { 978 apiStore.setValue( 979 IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR, 980 showTextOnPerspectiveBar.getSelection()); 981 } 982 983 if (editorAlignmentChanged) { 984 if (editorAlignment == INITIAL_LOC_INT) { 985 store.setToDefault(IPreferenceConstants.EDITOR_TAB_POSITION); 986 } else if (!override) { 987 store.setValue(IPreferenceConstants.EDITOR_TAB_POSITION, 989 editorAlignment); 990 } else { 991 store.setValue(IPreferenceConstants.EDITOR_TAB_POSITION, 993 editorAlignment); 994 } 995 restart = true; 996 } 997 998 if (viewAlignmentChanged) { 999 if (viewAlignment == INITIAL_LOC_INT) { 1000 store.setToDefault(IPreferenceConstants.VIEW_TAB_POSITION); 1001 } else if (!override) { 1002 store.setValue(IPreferenceConstants.VIEW_TAB_POSITION, 1004 viewAlignment); 1005 } else { 1006 store.setValue(IPreferenceConstants.VIEW_TAB_POSITION, 1008 viewAlignment); 1009 } 1010 restart = true; 1011 } 1012 1013 if (perspBarLocation.equals(INITIAL_VAL)) { 1014 apiStore 1015 .setToDefault(IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR); 1016 } else if (!override) { 1017 apiStore.setValue( 1019 IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, 1020 perspBarLocation); 1021 } else { 1022 apiStore.setValue( 1024 IWorkbenchPreferenceConstants.DOCK_PERSPECTIVE_BAR, 1025 perspBarLocation); 1026 } 1027 1028 if (fastViewLoc.equals(INITIAL_VAL)) { 1029 apiStore 1030 .setToDefault(IWorkbenchPreferenceConstants.INITIAL_FAST_VIEW_BAR_LOCATION); 1031 } else { 1032 apiStore 1033 .setValue( 1034 IWorkbenchPreferenceConstants.INITIAL_FAST_VIEW_BAR_LOCATION, 1035 fastViewLoc); 1036 } 1037 1038 int idx = themeCombo.getSelectionIndex(); 1039 if (idx <= 0) { 1040 Workbench.getInstance().getThemeManager().setCurrentTheme( 1041 IThemeManager.DEFAULT_THEME); 1042 refreshThemeCombo(IThemeManager.DEFAULT_THEME); 1043 } else { 1044 IThemeDescriptor applyTheme = WorkbenchPlugin.getDefault().getThemeRegistry().getThemes()[idx - 1]; 1045 Workbench.getInstance().getThemeManager() 1046 .setCurrentTheme(applyTheme.getId()); 1047 refreshThemeCombo(applyTheme.getId()); 1048 } 1049 refreshThemeDescriptionText(); 1050 1051 apiStore.setValue( 1052 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS, 1053 showTraditionalStyleTabs.getSelection()); 1054 apiStore.setValue(IWorkbenchPreferenceConstants.ENABLE_ANIMATIONS, 1055 enableAnimations.getSelection()); 1056 1057 PrefUtil.savePrefs(); 1058 1059 if (restart && !restartPosted) { 1062 if (getContainer() instanceof IWorkbenchPreferenceContainer) { 1063 IWorkbenchPreferenceContainer container = (IWorkbenchPreferenceContainer) getContainer(); 1064 UIJob job = new UIJob(WorkbenchMessages.ViewsPreference_restartRequestJobName) { 1065 public IStatus runInUIThread(IProgressMonitor monitor) { 1066 int really = new MessageDialog( 1068 null, 1069 WorkbenchMessages.ViewsPreference_presentationConfirm_title, 1070 null, 1071 WorkbenchMessages.ViewsPreference_presentationConfirm_message, 1072 MessageDialog.QUESTION, 1073 new String [] { 1074 WorkbenchMessages.ViewsPreference_presentationConfirm_yes, 1075 WorkbenchMessages.ViewsPreference_presentationConfirm_no }, 1076 1).open(); 1077 if (really == Window.OK) { 1078 PlatformUI.getWorkbench().restart(); 1079 } 1080 return Status.OK_STATUS; 1081 } 1082 }; 1083 job.setSystem(true); 1084 container.registerUpdateJob(job); 1085 restartPosted = true; 1086 } 1087 } 1088 return true; 1089 } 1090} 1091 | Popular Tags |