001: /*******************************************************************************
002: * Copyright (c) 2004, 2005 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.defaultpresentation;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.events.PaintEvent;
014: import org.eclipse.swt.events.PaintListener;
015: import org.eclipse.swt.graphics.Color;
016: import org.eclipse.swt.graphics.Point;
017: import org.eclipse.swt.graphics.Rectangle;
018: import org.eclipse.swt.widgets.Composite;
019: import org.eclipse.swt.widgets.Control;
020: import org.eclipse.ui.internal.presentations.util.AbstractTabFolder;
021: import org.eclipse.ui.internal.presentations.util.AbstractTabItem;
022: import org.eclipse.ui.internal.presentations.util.EnhancedFillLayout;
023: import org.eclipse.ui.internal.presentations.util.PartInfo;
024:
025: /**
026: * Implements the AbstractTabFolder interface, however this object only displays
027: * the content of the currently selected part. There are no tabs, no title, no toolbar,
028: * etc. There is no means to select a different part, unless it is done programmatically.
029: *
030: * @since 3.1
031: */
032: public class EmptyTabFolder extends AbstractTabFolder {
033:
034: private Composite control;
035: private Control childControl;
036: private Color borderColor;
037:
038: public EmptyTabFolder(Composite parent, boolean showborder) {
039: control = new Composite(parent, SWT.NONE);
040: EnhancedFillLayout layout = new EnhancedFillLayout();
041: control.setLayout(layout);
042: borderColor = parent.getDisplay().getSystemColor(
043: SWT.COLOR_WIDGET_NORMAL_SHADOW);
044: if (showborder) {
045: layout.xmargin = 1;
046: layout.ymargin = 1;
047: control.addPaintListener(new PaintListener() {
048: public void paintControl(PaintEvent e) {
049: e.gc.setForeground(borderColor);
050: Rectangle rect = control.getClientArea();
051: rect.width--;
052: rect.height--;
053: e.gc.drawRectangle(rect);
054: }
055: });
056: }
057: }
058:
059: /* (non-Javadoc)
060: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#computeSize(int, int)
061: */
062: public Point computeSize(int widthHint, int heightHint) {
063: if (childControl != null) {
064: // Fix for bug 85899 [Perspectives] [RCP]Standalone view does not divide space in
065: // proper ratio with reference when added to IPageLayout with showTitle parameter false
066: // If the childControl is a content proxy (a Composite with no children -- see PresentablePartFolder constructor),
067: // then computeSize returns 64x64, which is inappropriate.
068: // Note that this happens even if the Composite has a Layout that returns 0@0.
069: // Instead, use the sizes of the margins. This is equivalent to calling control.computeSize(...)
070: // if the childControl returned 0@0 for its preferred size.
071: if (childControl instanceof Composite) {
072: Composite composite = (Composite) childControl;
073: if (composite.getChildren().length == 0) {
074: EnhancedFillLayout layout = (EnhancedFillLayout) control
075: .getLayout();
076: int w = widthHint == SWT.DEFAULT ? layout.xmargin * 2
077: : widthHint;
078: int h = heightHint == SWT.DEFAULT ? layout.ymargin * 2
079: : heightHint;
080: return new Point(w, h);
081: }
082: }
083: return childControl.computeSize(widthHint, heightHint);
084: }
085: return new Point(0, 0);
086: }
087:
088: /* (non-Javadoc)
089: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#add(int, int)
090: */
091: public AbstractTabItem add(int index, int flags) {
092: return new EmptyTabItem();
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getContentParent()
097: */
098: public Composite getContentParent() {
099: return control;
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setContent(org.eclipse.swt.widgets.Control)
104: */
105: public void setContent(Control newContent) {
106: childControl = newContent;
107: }
108:
109: /* (non-Javadoc)
110: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getItems()
111: */
112: public AbstractTabItem[] getItems() {
113: return new AbstractTabItem[0];
114: }
115:
116: /* (non-Javadoc)
117: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getSelection()
118: */
119: public AbstractTabItem getSelection() {
120: return null;
121: }
122:
123: /* (non-Javadoc)
124: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelection(org.eclipse.ui.internal.presentations.util.AbstractTabItem)
125: */
126: public void setSelection(AbstractTabItem toSelect) {
127:
128: }
129:
130: public void setToolbar(Control toolbar) {
131: if (toolbar != null) {
132: toolbar.setVisible(false);
133: }
134: }
135:
136: public void layout(boolean flushCache) {
137: super .layout(flushCache);
138:
139: control.layout(flushCache);
140: }
141:
142: /* (non-Javadoc)
143: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelectedInfo(org.eclipse.ui.internal.presentations.util.PartInfo)
144: */
145: public void setSelectedInfo(PartInfo info) {
146:
147: }
148:
149: /* (non-Javadoc)
150: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#enablePaneMenu(boolean)
151: */
152: public void enablePaneMenu(boolean enabled) {
153:
154: }
155:
156: /* (non-Javadoc)
157: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getToolbarParent()
158: */
159: public Composite getToolbarParent() {
160: return control;
161: }
162:
163: /* (non-Javadoc)
164: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getControl()
165: */
166: public Control getControl() {
167: return control;
168: }
169:
170: /* (non-Javadoc)
171: * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getTabArea()
172: */
173: public Rectangle getTabArea() {
174: return new Rectangle(0, 0, 0, 0);
175: }
176: }
|