0001: /*******************************************************************************
0002: * Copyright (c) 2004 IBM Corporation and others.
0003: * All rights reserved. This program and the accompanying materials
0004: * are made available under the terms of the Common Public License v1.0
0005: * which accompanies this distribution, and is available at
0006: * http://www.eclipse.org/legal/cpl-v10.html
0007: *
0008: * Contributors:
0009: * IBM Corporation - initial API and implementation
0010: *******************************************************************************/package org.eclipse.ui.internal.r21presentation.presentations;
0011:
0012: import java.util.ArrayList;
0013:
0014: import org.eclipse.jface.action.GroupMarker;
0015: import org.eclipse.jface.action.IMenuManager;
0016: import org.eclipse.jface.action.MenuManager;
0017: import org.eclipse.jface.action.Separator;
0018: import org.eclipse.jface.util.Geometry;
0019: import org.eclipse.jface.window.Window;
0020: import org.eclipse.swt.SWT;
0021: import org.eclipse.swt.custom.CLabel;
0022: import org.eclipse.swt.events.DisposeEvent;
0023: import org.eclipse.swt.events.DisposeListener;
0024: import org.eclipse.swt.events.MouseAdapter;
0025: import org.eclipse.swt.events.MouseEvent;
0026: import org.eclipse.swt.events.MouseListener;
0027: import org.eclipse.swt.events.SelectionAdapter;
0028: import org.eclipse.swt.events.SelectionEvent;
0029: import org.eclipse.swt.events.ShellAdapter;
0030: import org.eclipse.swt.events.ShellEvent;
0031: import org.eclipse.swt.graphics.Color;
0032: import org.eclipse.swt.graphics.Image;
0033: import org.eclipse.swt.graphics.Point;
0034: import org.eclipse.swt.graphics.Rectangle;
0035: import org.eclipse.swt.widgets.Control;
0036: import org.eclipse.swt.widgets.Event;
0037: import org.eclipse.swt.widgets.Listener;
0038: import org.eclipse.swt.widgets.Menu;
0039: import org.eclipse.swt.widgets.Shell;
0040: import org.eclipse.swt.widgets.ToolBar;
0041: import org.eclipse.swt.widgets.ToolItem;
0042: import org.eclipse.ui.IPropertyListener;
0043: import org.eclipse.ui.internal.IWorkbenchGraphicConstants;
0044: import org.eclipse.ui.internal.WorkbenchImages;
0045: import org.eclipse.ui.internal.WorkbenchWindow;
0046: import org.eclipse.ui.internal.dnd.DragUtil;
0047: import org.eclipse.ui.internal.presentations.SystemMenuClose;
0048: import org.eclipse.ui.internal.presentations.SystemMenuMaximize;
0049: import org.eclipse.ui.internal.presentations.SystemMenuMinimize;
0050: import org.eclipse.ui.internal.presentations.SystemMenuMove;
0051: import org.eclipse.ui.internal.presentations.SystemMenuRestore;
0052: import org.eclipse.ui.internal.presentations.UpdatingActionContributionItem;
0053: import org.eclipse.ui.internal.r21presentation.R21Colors;
0054: import org.eclipse.ui.internal.r21presentation.R21PresentationMessages;
0055: import org.eclipse.ui.internal.r21presentation.widgets.CTabItem;
0056: import org.eclipse.ui.internal.r21presentation.widgets.R21PaneFolder;
0057: import org.eclipse.ui.internal.util.Util;
0058: import org.eclipse.ui.presentations.IPartMenu;
0059: import org.eclipse.ui.presentations.IPresentablePart;
0060: import org.eclipse.ui.presentations.IStackPresentationSite;
0061: import org.eclipse.ui.presentations.PresentationUtil;
0062: import org.eclipse.ui.presentations.StackDropResult;
0063: import org.eclipse.ui.presentations.StackPresentation;
0064:
0065: /**
0066: * Base class for StackPresentations that display IPresentableParts in a CTabFolder.
0067: *
0068: * @since 3.0
0069: */
0070: public class R21BasicStackPresentation extends StackPresentation {
0071:
0072: private R21PaneFolder paneFolder;
0073: private IPresentablePart current;
0074: private boolean activeState = false;
0075: private MenuManager systemMenuManager = new MenuManager();
0076: private CLabel titleLabel;
0077:
0078: private final static String TAB_DATA = R21BasicStackPresentation.class
0079: .getName()
0080: + ".partId"; //$NON-NLS-1$
0081:
0082: // private PaneFolderButtonListener buttonListener = new PaneFolderButtonListener() {
0083: // public void stateButtonPressed(int buttonId) {
0084: // getSite().setState(buttonId);
0085: // }
0086: //
0087: // public void closeButtonPressed(CTabItem item) {
0088: // IPresentablePart part = getPartForTab(item);
0089: //
0090: // getSite().close(part);
0091: // }
0092: // };
0093: //
0094: private MouseListener mouseListener = new MouseAdapter() {
0095: public void mouseDown(MouseEvent e) {
0096: if (e.widget instanceof Control) {
0097: Control ctrl = (Control) e.widget;
0098: Point globalPos = ctrl.toDisplay(new Point(e.x, e.y));
0099:
0100: // PR#1GDEZ25 - If selection will change in mouse up ignore mouse down.
0101: // Else, set focus.
0102: CTabItem newItem = paneFolder.getItem(paneFolder
0103: .getControl().toControl(globalPos));
0104: if (newItem != null) {
0105: CTabItem oldItem = paneFolder.getSelection();
0106: if (newItem != oldItem)
0107: return;
0108: }
0109: if (current != null) {
0110: current.setFocus();
0111: }
0112: }
0113: }
0114:
0115: public void mouseDoubleClick(MouseEvent e) {
0116: if (getSite().getState() == IStackPresentationSite.STATE_MAXIMIZED) {
0117: getSite().setState(
0118: IStackPresentationSite.STATE_RESTORED);
0119: } else {
0120: getSite().setState(
0121: IStackPresentationSite.STATE_MAXIMIZED);
0122: }
0123: }
0124: };
0125:
0126: private MouseListener titleMouseListener = new MouseAdapter() {
0127: public void mouseDown(MouseEvent e) {
0128: if (e.widget instanceof Control) {
0129: Control ctrl = (Control) e.widget;
0130: Point globalPos = ctrl.toDisplay(new Point(0,
0131: titleLabel.getBounds().height));
0132:
0133: if ((e.button == 1) && overImage(e.x))
0134: showSystemMenu(globalPos);
0135: }
0136: }
0137: };
0138:
0139: private Listener menuListener = new Listener() {
0140: /* (non-Javadoc)
0141: * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
0142: */
0143: public void handleEvent(Event event) {
0144: Point pos = new Point(event.x, event.y);
0145:
0146: showSystemMenu(pos);
0147: }
0148: };
0149:
0150: private Listener dragListener = new Listener() {
0151: public void handleEvent(Event event) {
0152:
0153: Point localPos = new Point(event.x, event.y);
0154: // // Ignore drags unless they are on the title area
0155: // if ((tabFolder.getControl().getStyle() & SWT.TOP) != 0) {
0156: // if (localPos.y > tabFolder.getTabHeight()) {
0157: // return;
0158: // }
0159: // } else {
0160: // if (localPos.y < tabFolder.getControl().getBounds().height - tabFolder.getTabHeight()) {
0161: // return;
0162: // }
0163: // }
0164: //
0165: CTabItem tabUnderPointer = paneFolder.getItem(localPos);
0166:
0167: if (tabUnderPointer == null) {
0168: getSite().dragStart(
0169: paneFolder.getControl().toDisplay(localPos),
0170: false);
0171: return;
0172: }
0173:
0174: IPresentablePart part = getPartForTab(tabUnderPointer);
0175:
0176: if (getSite().isPartMoveable(part)) {
0177: getSite().dragStart(part,
0178: paneFolder.getControl().toDisplay(localPos),
0179: false);
0180: }
0181: }
0182: };
0183:
0184: private Listener selectionListener = new Listener() {
0185: public void handleEvent(Event e) {
0186: IPresentablePart item = getPartForTab((CTabItem) e.item);
0187:
0188: if (item != null) {
0189: getSite().selectPart(item);
0190: }
0191: }
0192: };
0193:
0194: private Listener resizeListener = new Listener() {
0195: public void handleEvent(Event e) {
0196: setControlSize();
0197: }
0198: };
0199:
0200: private IPropertyListener childPropertyChangeListener = new IPropertyListener() {
0201: public void propertyChanged(Object source, int property) {
0202: if (source instanceof IPresentablePart) {
0203: IPresentablePart part = (IPresentablePart) source;
0204: childPropertyChanged(part, property);
0205: }
0206: }
0207: };
0208:
0209: private DisposeListener tabDisposeListener = new DisposeListener() {
0210: public void widgetDisposed(DisposeEvent e) {
0211: if (e.widget instanceof CTabItem) {
0212: CTabItem item = (CTabItem) e.widget;
0213:
0214: IPresentablePart part = getPartForTab(item);
0215:
0216: part
0217: .removePropertyListener(childPropertyChangeListener);
0218: }
0219: }
0220: };
0221:
0222: /** the shell listener for upgrading the gradient */
0223: private ShellAdapter shellListener = new ShellAdapter() {
0224:
0225: public void shellActivated(ShellEvent event) {
0226: updateGradient();
0227: }
0228:
0229: public void shellDeactivated(ShellEvent event) {
0230: updateGradient();
0231: }
0232: };
0233:
0234: private ToolBar viewToolBar;
0235: private ToolItem pullDownButton;
0236: private ToolItem closeButton;
0237:
0238: public R21BasicStackPresentation(R21PaneFolder control,
0239: IStackPresentationSite stackSite) {
0240: super (stackSite);
0241: paneFolder = control;
0242:
0243: // tabFolder.setMinimizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MINIMIZED));
0244: // tabFolder.setMaximizeVisible(stackSite.supportsState(IStackPresentationSite.STATE_MAXIMIZED));
0245: //
0246: titleLabel = new CLabel(paneFolder.getControl(),
0247: SWT.SHADOW_NONE);
0248: titleLabel.setVisible(false);
0249: titleLabel.moveAbove(null);
0250: titleLabel.addMouseListener(titleMouseListener);
0251: titleLabel.addMouseListener(mouseListener);
0252: titleLabel.addListener(SWT.MenuDetect, menuListener);
0253: PresentationUtil.addDragListener(titleLabel, dragListener);
0254:
0255: //ColorSchemeService.setViewTitleFont(this, titleLabel);
0256:
0257: viewToolBar = new ToolBar(control.getControl(), SWT.HORIZONTAL
0258: | SWT.FLAT);
0259: viewToolBar.moveAbove(null);
0260:
0261: pullDownButton = new ToolItem(viewToolBar, SWT.PUSH);
0262: // Image img = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU);
0263: Image hoverImage = WorkbenchImages
0264: .getImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU_HOVER);
0265: pullDownButton.setDisabledImage(null); // TODO: comment this out?
0266: // PR#1GE56QT - Avoid creation of unnecessary image.
0267: pullDownButton.setImage(hoverImage);
0268: pullDownButton.setToolTipText(R21PresentationMessages
0269: .getString("BasicStackPresentation.menu")); //$NON-NLS-1$
0270: pullDownButton.addSelectionListener(new SelectionAdapter() {
0271: public void widgetSelected(SelectionEvent e) {
0272: showPaneMenu();
0273: }
0274: });
0275:
0276: closeButton = new ToolItem(viewToolBar, SWT.PUSH);
0277: // Image img = WorkbenchImages.getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW);
0278: hoverImage = WorkbenchImages
0279: .getImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW_HOVER);
0280: closeButton.setDisabledImage(null); // PR#1GE56QT - Avoid creation of unnecessary image.
0281: closeButton.setImage(hoverImage);
0282: closeButton.setToolTipText(R21PresentationMessages
0283: .getString("BasicStackPresentation.close")); //$NON-NLS-1$
0284: closeButton.addSelectionListener(new SelectionAdapter() {
0285: public void widgetSelected(SelectionEvent e) {
0286: close(getCurrent());
0287: }
0288: });
0289:
0290: // listener to switch between visible tabItems
0291: paneFolder.getControl().addListener(SWT.Selection,
0292: selectionListener);
0293:
0294: // listener to resize visible components
0295: paneFolder.getControl().addListener(SWT.Resize, resizeListener);
0296:
0297: // listen for mouse down on tab to set focus.
0298: paneFolder.getControl().addMouseListener(mouseListener);
0299:
0300: paneFolder.getControl().addListener(SWT.MenuDetect,
0301: menuListener);
0302:
0303: // tabFolder.addButtonListener(buttonListener);
0304:
0305: PresentationUtil.addDragListener(paneFolder.getControl(),
0306: dragListener);
0307:
0308: // add the shell listener to track shell activations
0309: // TODO: check if workaround can be removed (see bug 55458)
0310: paneFolder.getControl().getShell().addShellListener(
0311: shellListener);
0312:
0313: // Uncomment to allow dragging from the title label
0314: // PresentationUtil.addDragListener(titleLabel, new Listener() {
0315: // public void handleEvent(Event event) {
0316: // if (layout.isTrimOnTop()) {
0317: // Point localPos = new Point(event.x, event.y);
0318: // getSite().dragStart(titleLabel.toDisplay(localPos), false);
0319: // }
0320: // }
0321: // });
0322:
0323: // // Compute the tab height
0324: // int tabHeight = viewToolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
0325: //
0326: // // Enforce a minimum tab height
0327: // if (tabHeight < 20) {
0328: // tabHeight = 20;
0329: // }
0330: // paneFolder.setTabHeight(tabHeight);
0331: //
0332: populateSystemMenu(systemMenuManager);
0333: }
0334:
0335: /*
0336: * Return true if <code>x</code> is over the label image.
0337: */
0338: private boolean overImage(int x) {
0339: return x < titleLabel.getImage().getBounds().width;
0340: }
0341:
0342: /**
0343: * @param systemMenuManager
0344: */
0345: private void populateSystemMenu(IMenuManager systemMenuManager) {
0346:
0347: systemMenuManager.add(new GroupMarker("misc")); //$NON-NLS-1$
0348: systemMenuManager.add(new GroupMarker("restore")); //$NON-NLS-1$
0349: systemMenuManager.add(new UpdatingActionContributionItem(
0350: new SystemMenuRestore(getSite())));
0351:
0352: systemMenuManager.add(new SystemMenuMove(getSite(),
0353: getPaneName()));
0354: systemMenuManager.add(new GroupMarker("size")); //$NON-NLS-1$
0355: systemMenuManager.add(new GroupMarker("state")); //$NON-NLS-1$
0356: systemMenuManager.add(new UpdatingActionContributionItem(
0357: new SystemMenuMinimize(getSite())));
0358:
0359: systemMenuManager.add(new UpdatingActionContributionItem(
0360: new SystemMenuMaximize(getSite())));
0361: systemMenuManager.add(new Separator("close")); //$NON-NLS-1$
0362: systemMenuManager.add(new UpdatingActionContributionItem(
0363: new SystemMenuClose(getSite())));
0364:
0365: getSite().addSystemActions(systemMenuManager);
0366: }
0367:
0368: protected String getPaneName() {
0369: return R21PresentationMessages
0370: .getString("BasicStackPresentation.pane"); //$NON-NLS-1$
0371: }
0372:
0373: /**
0374: * Displays the view menu as a popup
0375: */
0376: public void showPaneMenu() {
0377: IPartMenu menu = getPartMenu();
0378:
0379: if (menu != null) {
0380: Rectangle bounds = DragUtil.getDisplayBounds(viewToolBar);
0381: menu
0382: .showMenu(new Point(bounds.x, bounds.y
0383: + bounds.height));
0384: }
0385: }
0386:
0387: /**
0388: * Returns the currently selected part, or <code>null</code>.
0389: *
0390: * @return the currently selected part, or <code>null</code>
0391: */
0392: protected IPresentablePart getCurrent() {
0393: return current;
0394: }
0395:
0396: /**
0397: * Returns the index of the tab for the given part, or returns tabFolder.getItemCount()
0398: * if there is no such tab.
0399: *
0400: * @param part part being searched for
0401: * @return the index of the tab for the given part, or the number of tabs
0402: * if there is no such tab
0403: */
0404: private final int indexOf(IPresentablePart part) {
0405: if (part == null) {
0406: return paneFolder.getItemCount();
0407: }
0408:
0409: CTabItem[] items = paneFolder.getItems();
0410:
0411: for (int idx = 0; idx < items.length; idx++) {
0412: IPresentablePart tabPart = getPartForTab(items[idx]);
0413:
0414: if (part == tabPart) {
0415: return idx;
0416: }
0417: }
0418:
0419: return items.length;
0420: }
0421:
0422: /**
0423: * Returns the tab for the given part, or null if there is no such tab
0424: *
0425: * @param part the part being searched for
0426: * @return the tab for the given part, or null if there is no such tab
0427: */
0428: protected final CTabItem getTab(IPresentablePart part) {
0429: CTabItem[] items = paneFolder.getItems();
0430:
0431: int idx = indexOf(part);
0432:
0433: if (idx < items.length) {
0434: return items[idx];
0435: }
0436:
0437: return null;
0438: }
0439:
0440: /**
0441: * @param part
0442: * @param property
0443: */
0444: protected void childPropertyChanged(IPresentablePart part,
0445: int property) {
0446:
0447: CTabItem tab = getTab(part);
0448: initTab(tab, part);
0449:
0450: switch (property) {
0451: case IPresentablePart.PROP_BUSY:
0452: break;
0453: case IPresentablePart.PROP_HIGHLIGHT_IF_BACK:
0454: // FontRegistry registry =
0455: // PlatformUI.getWorkbench().
0456: // getThemeManager().getCurrentTheme().
0457: // getFontRegistry();
0458: //
0459: // if(!getCurrent().equals(part))//Set bold if it does currently have focus
0460: // tab.setFont(registry.getBold(IWorkbenchThemeConstants.TAB_TEXT_FONT));
0461: // break;
0462: case IPresentablePart.PROP_TOOLBAR:
0463: case IPresentablePart.PROP_PANE_MENU:
0464: case IPresentablePart.PROP_TITLE:
0465: setControlSize();
0466: break;
0467: }
0468: }
0469:
0470: protected final IPresentablePart getPartForTab(CTabItem item) {
0471: IPresentablePart part = (IPresentablePart) item
0472: .getData(TAB_DATA);
0473:
0474: return part;
0475: }
0476:
0477: /**
0478: * Returns the underlying tab folder for this presentation.
0479: *
0480: * @return
0481: */
0482: protected R21PaneFolder getPaneFolder() {
0483: return paneFolder;
0484: }
0485:
0486: /**
0487: * Returns true iff the underlying tab folder has been disposed.
0488: *
0489: * @return
0490: */
0491: public boolean isDisposed() {
0492: return paneFolder == null || paneFolder.isDisposed();
0493: }
0494:
0495: /**
0496: * Update the tab folder's colours to match the current theme settings
0497: * and active state
0498: */
0499: protected void updateGradient() {
0500:
0501: if (isDisposed())
0502: return;
0503:
0504: Color fgColor;
0505: Color[] bgColors;
0506: int[] bgPercents;
0507: boolean vertical = false;
0508: if (isActive()) {
0509: if (getShellActivated()) {
0510: fgColor = R21Colors
0511: .getSystemColor(SWT.COLOR_TITLE_FOREGROUND);
0512: bgColors = R21Colors.getActiveViewGradient();
0513: bgPercents = R21Colors.getActiveViewGradientPercents();
0514: } else {
0515: fgColor = R21Colors
0516: .getSystemColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND);
0517: bgColors = R21Colors.getDeactivatedViewGradient();
0518: bgPercents = R21Colors
0519: .getDeactivatedViewGradientPercents();
0520: }
0521:
0522: } else {
0523: fgColor = R21Colors
0524: .getSystemColor(SWT.COLOR_LIST_FOREGROUND);
0525: bgColors = null;
0526: bgPercents = null;
0527: }
0528:
0529: drawGradient(fgColor, bgColors, bgPercents, vertical);
0530:
0531: // Color fgColor;
0532: // ITheme currentTheme = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme();
0533: // FontRegistry fontRegistry = currentTheme.getFontRegistry();
0534: // ColorRegistry colorRegistry = currentTheme.getColorRegistry();
0535: // Color [] bgColors = new Color[2];
0536: // int [] percent = new int[1];
0537: // boolean vertical;
0538:
0539: // if (isActive()){
0540: //
0541: // CTabItem item = getPaneFolder().getSelection();
0542: // if(item != null && !getPartForTab(item).isBusy()){
0543: // Font tabFont = fontRegistry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT);
0544: //// item.setFont(tabFont);
0545: // }
0546: //
0547: // fgColor = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_TEXT_COLOR);
0548: // bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_START);
0549: // bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.ACTIVE_TAB_BG_END);
0550: // percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.ACTIVE_TAB_PERCENT);
0551: // vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.ACTIVE_TAB_VERTICAL);
0552: // } else {
0553: // fgColor = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_TEXT_COLOR);
0554: // bgColors[0] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_START);
0555: // bgColors[1] = colorRegistry.get(IWorkbenchThemeConstants.INACTIVE_TAB_BG_END);
0556: // percent[0] = currentTheme.getInt(IWorkbenchThemeConstants.INACTIVE_TAB_PERCENT);
0557: // vertical = currentTheme.getBoolean(IWorkbenchThemeConstants.INACTIVE_TAB_VERTICAL);
0558: // }
0559: //
0560: //
0561: // drawGradient(fgColor, bgColors, bgPercents, false);
0562: }
0563:
0564: /**
0565: * Draws the applicable gradient on the title area
0566: *
0567: * @param fgColor
0568: * @param bgColors
0569: * @param percentages
0570: * @param vertical
0571: */
0572: public void drawGradient(Color fgColor, Color[] bgColors,
0573: int[] percentages, boolean vertical) {
0574: // paneFolder.setSelectionForeground(fgColor);
0575: // paneFolder.setSelectionBackground(bgColors, percentages, vertical);
0576:
0577: if (titleLabel == null || viewToolBar == null)
0578: return;
0579:
0580: titleLabel.setBackground(bgColors, percentages, vertical);
0581: titleLabel.setForeground(fgColor);
0582:
0583: titleLabel.update();
0584: }
0585:
0586: public boolean isActive() {
0587: return activeState;
0588: }
0589:
0590: /**
0591: * Set the size of a page in the folder.
0592: *
0593: * TODO: Kim here...I had to make this public so that the when the font
0594: * was updated via the color scheme service it could relayout the
0595: * presentation... calling control.getLayout() doesn't do the trick.
0596: */
0597: public void setControlSize() {
0598: // Set up the top-right controls
0599: //List topRight = new ArrayList(3);
0600:
0601: if (current != null) {
0602: paneFolder.setTopLeft(titleLabel);
0603: titleLabel.setText(current.getTitle());
0604: titleLabel.setImage(current.getTitleImage());
0605: titleLabel.setVisible(true);
0606: }
0607:
0608: Control currentToolbar = getCurrentToolbar();
0609: paneFolder.setTopCenter(currentToolbar);
0610:
0611: IPartMenu partMenu = getPartMenu();
0612:
0613: if (partMenu != null) {
0614: pullDownButton.setEnabled(true);
0615: } else {
0616: pullDownButton.setEnabled(false);
0617: }
0618: paneFolder.setTopRight(viewToolBar);
0619: viewToolBar.setVisible(true);
0620:
0621: paneFolder.layout(true);
0622:
0623: if (current != null) {
0624: Rectangle clientArea = paneFolder.getClientArea();
0625: Rectangle bounds = paneFolder.getControl().getBounds();
0626: clientArea.x += bounds.x;
0627: clientArea.y += bounds.y;
0628:
0629: current.setBounds(clientArea);
0630: }
0631:
0632: }
0633:
0634: /**
0635: * Returns the IPartMenu for the currently selected part, or null if the current
0636: * part does not have a menu.
0637: *
0638: * @return the IPartMenu for the currently selected part or null if none
0639: */
0640: protected IPartMenu getPartMenu() {
0641: IPresentablePart part = getCurrentPart();
0642: if (part == null) {
0643: return null;
0644: }
0645:
0646: return part.getMenu();
0647: }
0648:
0649: /* (non-Javadoc)
0650: * @see org.eclipse.ui.internal.skins.Presentation#dispose()
0651: */
0652: public void dispose() {
0653: if (isDisposed()) {
0654: return;
0655: }
0656:
0657: // remove shell listener
0658: paneFolder.getControl().getShell().removeShellListener(
0659: shellListener);
0660:
0661: PresentationUtil.removeDragListener(paneFolder.getControl(),
0662: dragListener);
0663: PresentationUtil.removeDragListener(titleLabel, dragListener);
0664:
0665: systemMenuManager.dispose();
0666: systemMenuManager.removeAll();
0667: paneFolder.getControl().dispose();
0668: paneFolder = null;
0669:
0670: titleLabel.dispose();
0671: titleLabel = null;
0672:
0673: viewToolBar.dispose();
0674: }
0675:
0676: /* (non-Javadoc)
0677: * @see org.eclipse.ui.internal.skins.Presentation#setActive(boolean)
0678: */
0679: public void setActive(boolean isActive) {
0680: activeState = isActive;
0681: updateGradient();
0682: }
0683:
0684: /**
0685: * Return whether the window's shell is activated
0686: */
0687: /* package */boolean getShellActivated() {
0688: Window window = getWindow();
0689: if (window instanceof WorkbenchWindow)
0690: return ((WorkbenchWindow) window).getShellActivated();
0691: else
0692: return false;
0693: }
0694:
0695: /**
0696: * Returns the top level window.
0697: */
0698: public Window getWindow() {
0699: Control ctrl = getControl();
0700: if (ctrl != null) {
0701: Object data = ctrl.getShell().getData();
0702: if (data instanceof Window)
0703: return (Window) data;
0704: }
0705: return null;
0706: }
0707:
0708: private CTabItem createPartTab(IPresentablePart part, int tabIndex) {
0709: CTabItem tabItem;
0710:
0711: int style = SWT.NONE;
0712:
0713: if (getSite().isCloseable(part)) {
0714: style |= SWT.CLOSE;
0715: }
0716:
0717: tabItem = paneFolder.createItem(style, tabIndex);
0718:
0719: tabItem.setData(TAB_DATA, part);
0720:
0721: part.addPropertyListener(childPropertyChangeListener);
0722: tabItem.addDisposeListener(tabDisposeListener);
0723:
0724: initTab(tabItem, part);
0725:
0726: return tabItem;
0727: }
0728:
0729: /**
0730: * Initializes a tab for the given part. Sets the text, icon, tool tip,
0731: * etc. This will also be called whenever a relevant property changes
0732: * in the part to reflect those changes in the tab. Subclasses may override
0733: * to change the appearance of tabs for a particular part.
0734: *
0735: * @param tabItem tab for the part
0736: * @param part the part being displayed
0737: */
0738: protected void initTab(CTabItem tabItem, IPresentablePart part) {
0739: tabItem.setText(part.getName());
0740:
0741: //tabItem.setImage(part.getTitleImage());
0742:
0743: String toolTipText = part.getTitleToolTip();
0744: if (!toolTipText.equals(Util.ZERO_LENGTH_STRING)) {
0745: tabItem.setToolTipText(toolTipText);
0746: }
0747:
0748: // FontRegistry registry =
0749: // PlatformUI.getWorkbench().
0750: // getThemeManager().getCurrentTheme().
0751: // getFontRegistry();
0752: //
0753: // if(part.isBusy())
0754: // tabItem.setFont(registry.getItalic(IWorkbenchThemeConstants.TAB_TEXT_FONT));
0755: // else{
0756: // tabItem.setFont(registry.get(IWorkbenchThemeConstants.TAB_TEXT_FONT));
0757: // }
0758:
0759: }
0760:
0761: /* (non-Javadoc)
0762: * @see org.eclipse.ui.internal.skins.StackPresentation#addPart(org.eclipse.ui.internal.skins.IPresentablePart, org.eclipse.ui.internal.skins.IPresentablePart)
0763: */
0764: public void addPart(IPresentablePart newPart, Object cookie) {
0765:
0766: int idx;
0767:
0768: if (cookie instanceof Integer) {
0769: idx = ((Integer) cookie).intValue();
0770: } else {
0771: // Select a location for newly inserted parts
0772: idx = paneFolder.getItemCount();
0773: }
0774:
0775: addPart(newPart, idx);
0776: }
0777:
0778: /**
0779: * Adds the given presentable part to this presentation at the given index.
0780: * Does nothing if a tab already exists for the given part.
0781: *
0782: * @param newPart
0783: * @param index
0784: */
0785: public void addPart(IPresentablePart newPart, int index) {
0786: // If we already have a tab for this part, do nothing
0787: if (getTab(newPart) != null) {
0788: return;
0789: }
0790: createPartTab(newPart, index);
0791:
0792: setControlSize();
0793: }
0794:
0795: /* (non-Javadoc)
0796: * @see org.eclipse.ui.internal.skins.StackPresentation#removePart(org.eclipse.ui.internal.skins.IPresentablePart)
0797: */
0798: public void removePart(IPresentablePart oldPart) {
0799: if (current == oldPart)
0800: current = null;
0801:
0802: CTabItem item = getTab(oldPart);
0803: if (item == null) {
0804: return;
0805: }
0806: oldPart.setVisible(false);
0807:
0808: item.dispose();
0809: }
0810:
0811: /* (non-Javadoc)
0812: * @see org.eclipse.ui.internal.skins.StackPresentation#selectPart(org.eclipse.ui.internal.skins.IPresentablePart)
0813: */
0814: public void selectPart(IPresentablePart toSelect) {
0815: if (toSelect == current) {
0816: return;
0817: }
0818:
0819: if (current != null) {
0820: current.setVisible(false);
0821: }
0822:
0823: current = toSelect;
0824:
0825: if (current != null) {
0826: paneFolder.setSelection(indexOf(current));
0827: current.setVisible(true);
0828: setControlSize();
0829: }
0830: }
0831:
0832: public IPresentablePart getCurrentPart() {
0833: return current;
0834: }
0835:
0836: /* (non-Javadoc)
0837: * @see org.eclipse.ui.internal.skins.Presentation#setBounds(org.eclipse.swt.graphics.Rectangle)
0838: */
0839: public void setBounds(Rectangle bounds) {
0840: paneFolder.getControl().setBounds(bounds);
0841: setControlSize();
0842: }
0843:
0844: /* (non-Javadoc)
0845: * @see org.eclipse.ui.internal.skins.Presentation#computeMinimumSize()
0846: */
0847: public Point computeMinimumSize() {
0848: return Geometry.getSize(paneFolder.computeTrim(0, 0, 0, 0));
0849: }
0850:
0851: /* (non-Javadoc)
0852: * @see org.eclipse.ui.internal.skins.Presentation#setVisible(boolean)
0853: */
0854: public void setVisible(boolean isVisible) {
0855: if (current != null) {
0856: current.setVisible(isVisible);
0857: }
0858: paneFolder.getControl().setVisible(isVisible);
0859: }
0860:
0861: /* (non-Javadoc)
0862: * @see org.eclipse.ui.internal.skins.Presentation#setState(int)
0863: */
0864: public void setState(int state) {
0865: // tabFolder.setState(state);
0866: }
0867:
0868: /* (non-Javadoc)
0869: * @see org.eclipse.ui.internal.skins.Presentation#getSystemMenuManager()
0870: */
0871: public IMenuManager getSystemMenuManager() {
0872: return systemMenuManager;
0873: }
0874:
0875: /**
0876: * @param point
0877: */
0878: protected void showSystemMenu(Point point) {
0879: Menu aMenu = systemMenuManager.createContextMenu(paneFolder
0880: .getControl().getParent());
0881: systemMenuManager.update(true);
0882: aMenu.setLocation(point.x, point.y);
0883: aMenu.setVisible(true);
0884: }
0885:
0886: /* (non-Javadoc)
0887: * @see org.eclipse.ui.internal.skins.Presentation#getControl()
0888: */
0889: public Control getControl() {
0890: return paneFolder.getControl();
0891: }
0892:
0893: /*
0894: * (non-Javadoc)
0895: *
0896: * @see org.eclipse.ui.internal.skins.StackPresentation#dragOver(org.eclipse.swt.widgets.Control,
0897: * org.eclipse.swt.graphics.Point)
0898: */
0899: public StackDropResult dragOver(Control currentControl,
0900: Point location) {
0901:
0902: // Determine which tab we're currently dragging over
0903: Point localPos = paneFolder.getControl().toControl(location);
0904: final CTabItem tabUnderPointer = paneFolder.getItem(localPos);
0905:
0906: // This drop target only deals with tabs... if we're not dragging over
0907: // a tab, exit.
0908: if (tabUnderPointer == null)
0909: return null;
0910:
0911: // workaround when left tab is dragged over next
0912: int dragOverIndex = paneFolder.indexOf(tabUnderPointer);
0913:
0914: return new StackDropResult(Geometry.toDisplay(paneFolder
0915: .getControl(), tabUnderPointer.getBounds()),
0916: new Integer(dragOverIndex));
0917: }
0918:
0919: /**
0920: * Returns the toolbar control for the currently selected part, or null if none (not
0921: * all parts have a toolbar).
0922: *
0923: * @return the current toolbar or null if none
0924: */
0925: protected Control getCurrentToolbar() {
0926: IPresentablePart part = getCurrentPart();
0927: if (part == null) {
0928: return null;
0929: }
0930:
0931: return part.getToolBar();
0932: }
0933:
0934: /* (non-Javadoc)
0935: * @see org.eclipse.ui.presentations.StackPresentation#showSystemMenu()
0936: */
0937: public void showSystemMenu() {
0938: IPresentablePart part = getCurrentPart();
0939: if (part != null) {
0940: Rectangle bounds = DragUtil.getDisplayBounds(paneFolder
0941: .getControl());
0942:
0943: int idx = paneFolder.getSelectionIndex();
0944: if (idx > -1) {
0945: CTabItem item = paneFolder.getItem(idx);
0946: Rectangle itemBounds = item.getBounds();
0947:
0948: bounds.x += itemBounds.x;
0949: bounds.y += itemBounds.y;
0950: }
0951:
0952: Point location = new Point(bounds.x, bounds.y
0953: + paneFolder.getTabHeight());
0954: showSystemMenu(location);
0955: }
0956: }
0957:
0958: /* (non-Javadoc)
0959: * @see org.eclipse.ui.presentations.StackPresentation#getTabList(IPresentablePart)
0960: */
0961: public Control[] getTabList(IPresentablePart part) {
0962: ArrayList list = new ArrayList();
0963: if (paneFolder.getTabPosition() == SWT.BOTTOM) {
0964: if (part.getToolBar() != null)
0965: list.add(part.getToolBar());
0966: if (part.getControl() != null)
0967: list.add(part.getControl());
0968: if (getPaneFolder() != null)
0969: list.add(getPaneFolder().getControl());
0970: } else {
0971: if (getPaneFolder() != null)
0972: list.add(getPaneFolder().getControl());
0973: if (part.getToolBar() != null)
0974: list.add(part.getToolBar());
0975: if (part.getControl() != null)
0976: list.add(part.getControl());
0977: }
0978: return (Control[]) list.toArray(new Control[list.size()]);
0979: }
0980:
0981: protected void showList(Shell parentShell, int x, int y) {
0982: // final R21PaneFolder tabFolder = getTabFolder();
0983: //
0984: // int shellStyle = SWT.RESIZE | SWT.ON_TOP | SWT.NO_TRIM;
0985: // int tableStyle = SWT.V_SCROLL | SWT.H_SCROLL;
0986: // final BasicStackList editorList = new BasicStackList(tabFolder.getControl().getShell(),
0987: // shellStyle, tableStyle);
0988: // editorList.setInput(this);
0989: // Point size = editorList.computeSizeHint();
0990: //
0991: // Rectangle bounds = Display.getCurrent().getBounds();
0992: // if (x + size.x > bounds.width) x = bounds.width - size.x;
0993: // if (y + size.y > bounds.height) y = bounds.height - size.y;
0994: // editorList.setLocation(new Point(x, y));
0995: // editorList.setVisible(true);
0996: // editorList.setFocus();
0997: // editorList.getTableViewer().getTable().getShell().addListener(
0998: // SWT.Deactivate, new Listener() {
0999: //
1000: // public void handleEvent(Event event) {
1001: // editorList.setVisible(false);
1002: // }
1003: // });
1004: }
1005:
1006: /*
1007: * Shows the list of tabs at the top left corner of the editor
1008: */
1009: protected void showListDefaultLocation() {
1010: R21PaneFolder tabFolder = getPaneFolder();
1011: Shell shell = tabFolder.getControl().getShell();
1012: Rectangle clientArea = tabFolder.getClientArea();
1013: Point location = tabFolder.getControl().getDisplay().map(
1014: tabFolder.getControl(), null, clientArea.x,
1015: clientArea.y);
1016: showList(shell, location.x, location.y);
1017: }
1018:
1019: void setSelection(CTabItem tabItem) {
1020: getSite().selectPart(getPartForTab(tabItem));
1021: }
1022:
1023: void close(IPresentablePart presentablePart) {
1024: getSite().close(new IPresentablePart[] { presentablePart });
1025: }
1026:
1027: Image getLabelImage(IPresentablePart presentablePart) {
1028: return presentablePart.getTitleImage();
1029: }
1030:
1031: String getLabelText(IPresentablePart presentablePart,
1032: boolean includePath) {
1033: String title = presentablePart.getTitle().trim();
1034: return title;
1035: }
1036:
1037: /* (non-Javadoc)
1038: * @see org.eclipse.ui.presentations.StackPresentation#setActive(int)
1039: */
1040: public void setActive(int newState) {
1041: setActive(newState == AS_ACTIVE_FOCUS);
1042: }
1043:
1044: }
|