1 11 package org.eclipse.ui.internal.presentations; 12 13 import org.eclipse.jface.preference.IPreferenceStore; 14 import org.eclipse.jface.util.IPropertyChangeListener; 15 import org.eclipse.jface.util.PropertyChangeEvent; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.custom.CTabItem; 18 import org.eclipse.swt.graphics.Font; 19 import org.eclipse.swt.widgets.Composite; 20 import org.eclipse.ui.IWorkbenchPreferenceConstants; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.IPreferenceConstants; 23 import org.eclipse.ui.internal.IWorkbenchThemeConstants; 24 import org.eclipse.ui.internal.WorkbenchMessages; 25 import org.eclipse.ui.internal.WorkbenchPlugin; 26 import org.eclipse.ui.internal.util.PrefUtil; 27 import org.eclipse.ui.presentations.IStackPresentationSite; 28 import org.eclipse.ui.themes.ITheme; 29 30 35 public class DefaultViewPresentation extends DefaultPartPresentation { 36 37 private IPreferenceStore preferenceStore = WorkbenchPlugin.getDefault().getPreferenceStore(); 38 private IPreferenceStore apiPreferenceStore = PrefUtil.getAPIPreferenceStore(); 39 40 private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { 41 public void propertyChange(PropertyChangeEvent propertyChangeEvent) { 42 43 if(isDisposed()) 44 return; 45 46 if (IPreferenceConstants.VIEW_TAB_POSITION.equals(propertyChangeEvent.getProperty()) && !isDisposed()) { 47 int tabLocation = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); 48 getTabFolder().setTabPosition(tabLocation); 49 layout(false); 50 } else if (IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS.equals(propertyChangeEvent.getProperty()) && !isDisposed()) { 51 boolean traditionalTab = apiPreferenceStore.getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS); 52 setTabStyle(traditionalTab); 53 } 54 } 55 }; 56 57 public DefaultViewPresentation(Composite parent, IStackPresentationSite newSite) { 58 59 super(new PaneFolder(parent, SWT.BORDER), newSite); 60 PaneFolder tabFolder = getTabFolder(); 61 62 preferenceStore.addPropertyChangeListener(propertyChangeListener); 63 apiPreferenceStore.addPropertyChangeListener(propertyChangeListener); 64 int tabLocation = preferenceStore.getInt(IPreferenceConstants.VIEW_TAB_POSITION); 65 66 tabFolder.setTabPosition(tabLocation); 67 setTabStyle(apiPreferenceStore.getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS)); 68 69 tabFolder.setUnselectedCloseVisible(false); 71 72 tabFolder.setUnselectedImageVisible(false); 74 75 init(); 76 } 77 78 83 protected void setTabStyle(boolean traditionalTab) { 84 getTabFolder().setSimpleTab(traditionalTab); 86 } 87 88 89 92 protected void updateGradient() { 93 if (isDisposed()) 94 return; 95 96 ITheme theme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme(); 97 98 if (isActive()) { 99 setActiveTabColors(); 100 } 101 else { 102 setInactiveTabColors(); 103 } 104 boolean resizeNeeded = false; 105 106 CTabItem item = getTabFolder().getSelection(); 107 Font tabFont = theme.getFontRegistry().get(IWorkbenchThemeConstants.TAB_TEXT_FONT); 108 if(item != null && !getPartForTab(item).isBusy()){ 109 item.setFont(null); 110 } 111 112 Font oldTabFont = getTabFolder().getControl().getFont(); 113 if (!oldTabFont.equals(tabFont)) { 114 getTabFolder().getControl().setFont(tabFont); 115 resizeNeeded = true; 116 } 117 118 super.updateGradient(); 120 121 if (resizeNeeded) { 122 getTabFolder().setTabHeight(computeTabHeight()); 123 124 setControlSize(); 126 } 127 } 128 129 132 public void setActive(int newState) { 133 super.setActive(newState); 134 135 updateGradient(); 136 } 137 138 141 protected void widgetDisposed() { 142 preferenceStore.removePropertyChangeListener(propertyChangeListener); 143 apiPreferenceStore.removePropertyChangeListener(propertyChangeListener); 144 super.widgetDisposed(); 145 } 146 147 150 protected String getPaneName() { 151 return WorkbenchMessages.getString("ViewPane.moveView"); } 153 } 154 | Popular Tags |