KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > presentations > WorkbenchPresentationFactory


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

11
12 package org.eclipse.ui.presentations;
13
14 import org.eclipse.jface.preference.IPreferenceStore;
15 import org.eclipse.swt.SWT;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.ui.IWorkbenchPreferenceConstants;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.internal.IPreferenceConstants;
20 import org.eclipse.ui.internal.WorkbenchPlugin;
21 import org.eclipse.ui.internal.preferences.IDynamicPropertyMap;
22 import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultMultiTabListener;
23 import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultSimpleTabListener;
24 import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder;
25 import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultThemeListener;
26 import org.eclipse.ui.internal.presentations.defaultpresentation.EmptyTabFolder;
27 import org.eclipse.ui.internal.presentations.util.PresentablePartFolder;
28 import org.eclipse.ui.internal.presentations.util.StandardEditorSystemMenu;
29 import org.eclipse.ui.internal.presentations.util.StandardViewSystemMenu;
30 import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
31
32 /**
33  * The default presentation factory for the Workbench.
34  *
35  * @since 3.0
36  */

37 public class WorkbenchPresentationFactory extends AbstractPresentationFactory {
38
39     // don't reset these dynamically, so just keep the information static.
40
// see bug:
41
// 75422 [Presentations] Switching presentation to R21 switches immediately,
42
// but only partially
43
private static int editorTabPosition = WorkbenchPlugin
44         .getDefault().getPreferenceStore().getInt(IPreferenceConstants.EDITOR_TAB_POSITION);
45     private static int viewTabPosition = WorkbenchPlugin
46         .getDefault().getPreferenceStore().getInt(IPreferenceConstants.VIEW_TAB_POSITION);
47     
48     /* (non-Javadoc)
49      * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createEditorPresentation(org.eclipse.swt.widgets.Composite, org.eclipse.ui.presentations.IStackPresentationSite)
50      */

51     public StackPresentation createEditorPresentation(Composite parent,
52             IStackPresentationSite site) {
53         DefaultTabFolder folder = new DefaultTabFolder(parent, editorTabPosition | SWT.BORDER,
54                 site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
55                 site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
56         
57         /*
58          * Set the minimum characters to display, if the preference is something
59          * other than the default. This is mainly intended for RCP applications
60          * or for expert users (i.e., via the plug-in customization file).
61          *
62          * Bug 32789.
63          */

64         final IPreferenceStore store = PlatformUI.getPreferenceStore();
65         if (store
66                 .contains(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS)) {
67             final int minimumCharacters = store
68                     .getInt(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS);
69             if (minimumCharacters >= 0) {
70                 folder.setMinimumCharacters(minimumCharacters);
71             }
72         }
73         
74         PresentablePartFolder partFolder = new PresentablePartFolder(folder);
75         
76         TabbedStackPresentation result = new TabbedStackPresentation(site, partFolder,
77                 new StandardEditorSystemMenu(site));
78         
79         DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
80         result.getTheme().addListener(themeListener);
81         
82         IDynamicPropertyMap workbenchPreferences = result.getPluginPreferences(WorkbenchPlugin.getDefault());
83         
84         new DefaultMultiTabListener(workbenchPreferences,
85                 IPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, folder);
86
87         new DefaultSimpleTabListener(result.getApiPreferences(),
88                 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
89                 folder);
90         
91         return result;
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createViewPresentation(org.eclipse.swt.widgets.Composite,
98      * org.eclipse.ui.presentations.IStackPresentationSite)
99      */

100     public StackPresentation createViewPresentation(Composite parent,
101             IStackPresentationSite site) {
102         
103         DefaultTabFolder folder = new DefaultTabFolder(parent, viewTabPosition | SWT.BORDER,
104                 site.supportsState(IStackPresentationSite.STATE_MINIMIZED),
105                 site.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
106
107         final IPreferenceStore store = PlatformUI.getPreferenceStore();
108         final int minimumCharacters = store
109                 .getInt(IWorkbenchPreferenceConstants.VIEW_MINIMUM_CHARACTERS);
110         if (minimumCharacters >= 0) {
111             folder.setMinimumCharacters(minimumCharacters);
112         }
113         
114         PresentablePartFolder partFolder = new PresentablePartFolder(folder);
115         
116         folder.setUnselectedCloseVisible(false);
117         folder.setUnselectedImageVisible(false);
118         
119         TabbedStackPresentation result = new TabbedStackPresentation(site, partFolder,
120                 new StandardViewSystemMenu(site));
121         
122         DefaultThemeListener themeListener = new DefaultThemeListener(folder, result.getTheme());
123         result.getTheme().addListener(themeListener);
124         
125         new DefaultSimpleTabListener(result.getApiPreferences(),
126                 IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
127                 folder);
128
129         return result;
130     }
131
132     /*
133      * (non-Javadoc)
134      *
135      * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createStandaloneViewPresentation(org.eclipse.swt.widgets.Composite,
136      * org.eclipse.ui.presentations.IStackPresentationSite, boolean)
137      */

138     public StackPresentation createStandaloneViewPresentation(Composite parent,
139             IStackPresentationSite site, boolean showTitle) {
140         
141         if (showTitle) {
142             return createViewPresentation(parent, site);
143         }
144         EmptyTabFolder folder = new EmptyTabFolder(parent, true);
145         TabbedStackPresentation presentation = new TabbedStackPresentation(site, folder, new StandardViewSystemMenu(site));
146             
147         return presentation;
148     }
149
150 }
151
Popular Tags