KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > DefaultViewPresentation


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
31  * Controls the appearance of views stacked into the workbench.
32  *
33  * @since 3.0
34  */

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         // do not support close box on unselected tabs.
70
tabFolder.setUnselectedCloseVisible(false);
71         
72         // do not support icons in unselected tabs.
73
tabFolder.setUnselectedImageVisible(false);
74         
75         init();
76     }
77     
78     /**
79      * Set the tab folder tab style to a tradional style tab
80      * @param traditionalTab <code>true</code> if traditional style tabs should be used
81      * <code>false</code> otherwise.
82      */

83     protected void setTabStyle(boolean traditionalTab) {
84         // set the tab style to non-simple
85
getTabFolder().setSimpleTab(traditionalTab);
86     }
87
88
89     /* (non-Javadoc)
90      * @see org.eclipse.ui.internal.presentations.DefaultPartPresentation#updateGradient()
91      */

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         //call super to ensure that the toolbar is updated properly.
119
super.updateGradient();
120         
121         if (resizeNeeded) {
122             getTabFolder().setTabHeight(computeTabHeight());
123
124             //ensure proper control sizes for new fonts
125
setControlSize();
126         }
127     }
128
129     /* (non-Javadoc)
130      * @see org.eclipse.ui.internal.skins.Presentation#setActive(int)
131      */

132     public void setActive(int newState) {
133         super.setActive(newState);
134         
135         updateGradient();
136     }
137     
138     /* (non-Javadoc)
139      * @see org.eclipse.ui.internal.presentations.DefaultPartPresentation#widgetDisposed()
140      */

141     protected void widgetDisposed() {
142         preferenceStore.removePropertyChangeListener(propertyChangeListener);
143         apiPreferenceStore.removePropertyChangeListener(propertyChangeListener);
144         super.widgetDisposed();
145     }
146     
147     /* (non-Javadoc)
148      * @see org.eclipse.ui.internal.presentations.DefaultPartPresentation#getPartMenu()
149      */

150     protected String JavaDoc getPaneName() {
151         return WorkbenchMessages.getString("ViewPane.moveView"); //$NON-NLS-1$
152
}
153 }
154
Popular Tags