001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.presentations;
011:
012: import org.eclipse.jface.preference.IPreferenceStore;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.widgets.Composite;
015: import org.eclipse.ui.IWorkbenchPreferenceConstants;
016: import org.eclipse.ui.PlatformUI;
017: import org.eclipse.ui.internal.IPreferenceConstants;
018: import org.eclipse.ui.internal.WorkbenchPlugin;
019: import org.eclipse.ui.internal.preferences.IDynamicPropertyMap;
020: import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultMultiTabListener;
021: import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultSimpleTabListener;
022: import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultTabFolder;
023: import org.eclipse.ui.internal.presentations.defaultpresentation.DefaultThemeListener;
024: import org.eclipse.ui.internal.presentations.defaultpresentation.EmptyTabFolder;
025: import org.eclipse.ui.internal.presentations.util.PresentablePartFolder;
026: import org.eclipse.ui.internal.presentations.util.StandardEditorSystemMenu;
027: import org.eclipse.ui.internal.presentations.util.StandardViewSystemMenu;
028: import org.eclipse.ui.internal.presentations.util.TabbedStackPresentation;
029:
030: /**
031: * The default presentation factory for the Workbench.
032: *
033: * @since 3.0
034: */
035: public class WorkbenchPresentationFactory extends
036: AbstractPresentationFactory {
037:
038: // don't reset these dynamically, so just keep the information static.
039: // see bug:
040: // 75422 [Presentations] Switching presentation to R21 switches immediately,
041: // but only partially
042: private static int editorTabPosition = WorkbenchPlugin.getDefault()
043: .getPreferenceStore().getInt(
044: IPreferenceConstants.EDITOR_TAB_POSITION);
045: private static int viewTabPosition = WorkbenchPlugin.getDefault()
046: .getPreferenceStore().getInt(
047: IPreferenceConstants.VIEW_TAB_POSITION);
048:
049: /* (non-Javadoc)
050: * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createEditorPresentation(org.eclipse.swt.widgets.Composite, org.eclipse.ui.presentations.IStackPresentationSite)
051: */
052: public StackPresentation createEditorPresentation(Composite parent,
053: IStackPresentationSite site) {
054: DefaultTabFolder folder = new DefaultTabFolder(
055: parent,
056: editorTabPosition | SWT.BORDER,
057: site
058: .supportsState(IStackPresentationSite.STATE_MINIMIZED),
059: site
060: .supportsState(IStackPresentationSite.STATE_MAXIMIZED));
061:
062: /*
063: * Set the minimum characters to display, if the preference is something
064: * other than the default. This is mainly intended for RCP applications
065: * or for expert users (i.e., via the plug-in customization file).
066: *
067: * Bug 32789.
068: */
069: final IPreferenceStore store = PlatformUI.getPreferenceStore();
070: if (store
071: .contains(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS)) {
072: final int minimumCharacters = store
073: .getInt(IWorkbenchPreferenceConstants.EDITOR_MINIMUM_CHARACTERS);
074: if (minimumCharacters >= 0) {
075: folder.setMinimumCharacters(minimumCharacters);
076: }
077: }
078:
079: PresentablePartFolder partFolder = new PresentablePartFolder(
080: folder);
081:
082: TabbedStackPresentation result = new TabbedStackPresentation(
083: site, partFolder, new StandardEditorSystemMenu(site));
084:
085: DefaultThemeListener themeListener = new DefaultThemeListener(
086: folder, result.getTheme());
087: result.getTheme().addListener(themeListener);
088:
089: IDynamicPropertyMap workbenchPreferences = result
090: .getPluginPreferences(WorkbenchPlugin.getDefault());
091:
092: new DefaultMultiTabListener(workbenchPreferences,
093: IPreferenceConstants.SHOW_MULTIPLE_EDITOR_TABS, folder);
094:
095: new DefaultSimpleTabListener(
096: result.getApiPreferences(),
097: IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
098: folder);
099:
100: return result;
101: }
102:
103: /*
104: * (non-Javadoc)
105: *
106: * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createViewPresentation(org.eclipse.swt.widgets.Composite,
107: * org.eclipse.ui.presentations.IStackPresentationSite)
108: */
109: public StackPresentation createViewPresentation(Composite parent,
110: IStackPresentationSite site) {
111:
112: DefaultTabFolder folder = new DefaultTabFolder(
113: parent,
114: viewTabPosition | SWT.BORDER,
115: site
116: .supportsState(IStackPresentationSite.STATE_MINIMIZED),
117: site
118: .supportsState(IStackPresentationSite.STATE_MAXIMIZED));
119:
120: final IPreferenceStore store = PlatformUI.getPreferenceStore();
121: final int minimumCharacters = store
122: .getInt(IWorkbenchPreferenceConstants.VIEW_MINIMUM_CHARACTERS);
123: if (minimumCharacters >= 0) {
124: folder.setMinimumCharacters(minimumCharacters);
125: }
126:
127: PresentablePartFolder partFolder = new PresentablePartFolder(
128: folder);
129:
130: folder.setUnselectedCloseVisible(false);
131: folder.setUnselectedImageVisible(false);
132:
133: TabbedStackPresentation result = new TabbedStackPresentation(
134: site, partFolder, new StandardViewSystemMenu(site));
135:
136: DefaultThemeListener themeListener = new DefaultThemeListener(
137: folder, result.getTheme());
138: result.getTheme().addListener(themeListener);
139:
140: new DefaultSimpleTabListener(
141: result.getApiPreferences(),
142: IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS,
143: folder);
144:
145: return result;
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see org.eclipse.ui.presentations.AbstractPresentationFactory#createStandaloneViewPresentation(org.eclipse.swt.widgets.Composite,
152: * org.eclipse.ui.presentations.IStackPresentationSite, boolean)
153: */
154: public StackPresentation createStandaloneViewPresentation(
155: Composite parent, IStackPresentationSite site,
156: boolean showTitle) {
157:
158: if (showTitle) {
159: return createViewPresentation(parent, site);
160: }
161: EmptyTabFolder folder = new EmptyTabFolder(parent, true);
162: TabbedStackPresentation presentation = new TabbedStackPresentation(
163: site, folder, new StandardViewSystemMenu(site));
164:
165: return presentation;
166: }
167:
168: }
|