001: /*******************************************************************************
002: * Copyright (c) 2004, 2007 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.internal.presentations;
011:
012: import org.eclipse.jface.action.ContributionItem;
013: import org.eclipse.swt.SWT;
014: import org.eclipse.swt.widgets.Menu;
015: import org.eclipse.swt.widgets.MenuItem;
016: import org.eclipse.ui.IViewReference;
017: import org.eclipse.ui.IWorkbenchPartReference;
018: import org.eclipse.ui.internal.FastViewBar;
019: import org.eclipse.ui.internal.IChangeListener;
020: import org.eclipse.ui.internal.IntModel;
021: import org.eclipse.ui.internal.PartPane;
022: import org.eclipse.ui.internal.RadioMenu;
023: import org.eclipse.ui.internal.ViewStackTrimToolBar;
024: import org.eclipse.ui.internal.WorkbenchMessages;
025: import org.eclipse.ui.internal.WorkbenchWindow;
026:
027: /**
028: * @since 3.0
029: */
030: public class SystemMenuFastViewOrientation extends ContributionItem {
031:
032: private PartPane viewPane;
033:
034: private IntModel currentOrientation = new IntModel(SWT.VERTICAL);
035:
036: private ViewStackTrimToolBar minimizedStack = null;
037:
038: public SystemMenuFastViewOrientation(PartPane newViewPane) {
039: this (newViewPane, null);
040: }
041:
042: /**
043: * @param pane
044: * @param vstt
045: */
046: public SystemMenuFastViewOrientation(PartPane newViewPane,
047: final ViewStackTrimToolBar vstt) {
048: this .viewPane = newViewPane;
049: this .minimizedStack = vstt;
050:
051: currentOrientation.addChangeListener(new IChangeListener() {
052: public void update(boolean changed) {
053: if (changed) {
054: WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane
055: .getPage().getWorkbenchWindow();
056:
057: if (vstt == null) {
058: FastViewBar bar = workbenchWindow
059: .getFastViewBar();
060: if (bar != null && viewPane != null) {
061: IWorkbenchPartReference ref = viewPane
062: .getPartReference();
063:
064: if (ref instanceof IViewReference) {
065: bar.setOrientation(
066: (IViewReference) ref,
067: currentOrientation.get());
068: }
069: }
070: } else {
071: vstt.setOrientation(currentOrientation.get(),
072: workbenchWindow);
073: }
074: }
075: }
076: });
077: }
078:
079: public void dispose() {
080: viewPane = null;
081: }
082:
083: public void fill(Menu menu, int index) {
084: WorkbenchWindow workbenchWindow = (WorkbenchWindow) viewPane
085: .getPage().getWorkbenchWindow();
086:
087: IWorkbenchPartReference ref = viewPane.getPartReference();
088: if (!(ref instanceof IViewReference))
089: return;
090:
091: if (minimizedStack == null) {
092: FastViewBar bar = workbenchWindow.getFastViewBar();
093: if (bar != null && viewPane != null) {
094: currentOrientation.set(bar
095: .getOrientation((IViewReference) ref));
096: }
097: } else {
098: currentOrientation.set(minimizedStack.getPaneOrientation());
099: }
100:
101: MenuItem orientationItem = new MenuItem(menu, SWT.CASCADE,
102: index);
103: {
104: orientationItem
105: .setText(WorkbenchMessages.FastViewBar_view_orientation);
106:
107: Menu orientationSwtMenu = new Menu(orientationItem);
108: RadioMenu orientationMenu = new RadioMenu(
109: orientationSwtMenu, currentOrientation);
110: orientationMenu.addMenuItem(
111: WorkbenchMessages.FastViewBar_horizontal,
112: new Integer(SWT.HORIZONTAL));
113: orientationMenu.addMenuItem(
114: WorkbenchMessages.FastViewBar_vertical,
115: new Integer(SWT.VERTICAL));
116:
117: orientationItem.setMenu(orientationSwtMenu);
118: }
119: }
120:
121: public boolean isDynamic() {
122: return true;
123: }
124: }
|