KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > presentations > defaultpresentation > EmptyTabFolder


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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 package org.eclipse.ui.internal.presentations.defaultpresentation;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.PaintEvent;
15 import org.eclipse.swt.events.PaintListener;
16 import org.eclipse.swt.graphics.Color;
17 import org.eclipse.swt.graphics.Point;
18 import org.eclipse.swt.graphics.Rectangle;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.internal.presentations.util.AbstractTabFolder;
22 import org.eclipse.ui.internal.presentations.util.AbstractTabItem;
23 import org.eclipse.ui.internal.presentations.util.EnhancedFillLayout;
24 import org.eclipse.ui.internal.presentations.util.PartInfo;
25
26 /**
27  * Implements the AbstractTabFolder interface, however this object only displays
28  * the content of the currently selected part. There are no tabs, no title, no toolbar,
29  * etc. There is no means to select a different part, unless it is done programmatically.
30  *
31  * @since 3.1
32  */

33 public class EmptyTabFolder extends AbstractTabFolder {
34
35     private Composite control;
36     private Control childControl;
37     private Color borderColor;
38     
39     public EmptyTabFolder(Composite parent, boolean showborder) {
40         control = new Composite(parent, SWT.NONE);
41         EnhancedFillLayout layout = new EnhancedFillLayout();
42         control.setLayout(layout);
43         borderColor = parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
44         if (showborder) {
45             layout.xmargin = 1;
46             layout.ymargin = 1;
47             control.addPaintListener(new PaintListener() {
48                 public void paintControl(PaintEvent e) {
49                     e.gc.setForeground(borderColor);
50                     Rectangle rect = control.getClientArea();
51                     rect.width--;
52                     rect.height--;
53                     e.gc.drawRectangle(rect);
54                 }
55             });
56         }
57     }
58     
59     /* (non-Javadoc)
60      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#computeSize(int, int)
61      */

62     public Point computeSize(int widthHint, int heightHint) {
63         if (childControl != null) {
64             // Fix for bug 85899 [Perspectives] [RCP]Standalone view does not divide space in
65
// proper ratio with reference when added to IPageLayout with showTitle parameter false
66
// If the childControl is a content proxy (a Composite with no children -- see PresentablePartFolder constructor),
67
// then computeSize returns 64x64, which is inappropriate.
68
// Note that this happens even if the Composite has a Layout that returns 0@0.
69
// Instead, use the sizes of the margins. This is equivalent to calling control.computeSize(...)
70
// if the childControl returned 0@0 for its preferred size.
71
if (childControl instanceof Composite) {
72                 Composite composite = (Composite) childControl;
73                 if (composite.getChildren().length == 0) {
74                     EnhancedFillLayout layout = (EnhancedFillLayout) control.getLayout();
75                     int w = widthHint == SWT.DEFAULT ? layout.xmargin * 2 : widthHint;
76                     int h = heightHint == SWT.DEFAULT ? layout.ymargin * 2 : heightHint;
77                     return new Point(w, h);
78                 }
79             }
80             return childControl.computeSize(widthHint, heightHint);
81         }
82         return new Point(0,0);
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#add(int, int)
87      */

88     public AbstractTabItem add(int index, int flags) {
89         return new EmptyTabItem();
90     }
91
92     /* (non-Javadoc)
93      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getContentParent()
94      */

95     public Composite getContentParent() {
96         return control;
97     }
98
99     /* (non-Javadoc)
100      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setContent(org.eclipse.swt.widgets.Control)
101      */

102     public void setContent(Control newContent) {
103         childControl = newContent;
104     }
105
106     /* (non-Javadoc)
107      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getItems()
108      */

109     public AbstractTabItem[] getItems() {
110         return new AbstractTabItem[0];
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getSelection()
115      */

116     public AbstractTabItem getSelection() {
117         return null;
118     }
119
120     /* (non-Javadoc)
121      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelection(org.eclipse.ui.internal.presentations.util.AbstractTabItem)
122      */

123     public void setSelection(AbstractTabItem toSelect) {
124
125     }
126
127     public void setToolbar(Control toolbar) {
128         if (toolbar != null) {
129             toolbar.setVisible(false);
130         }
131     }
132     
133     public void layout(boolean flushCache) {
134         super.layout(flushCache);
135         
136         control.layout(flushCache);
137     }
138     
139     /* (non-Javadoc)
140      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#setSelectedInfo(org.eclipse.ui.internal.presentations.util.PartInfo)
141      */

142     public void setSelectedInfo(PartInfo info) {
143
144     }
145
146     /* (non-Javadoc)
147      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#enablePaneMenu(boolean)
148      */

149     public void enablePaneMenu(boolean enabled) {
150
151     }
152
153     /* (non-Javadoc)
154      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getToolbarParent()
155      */

156     public Composite getToolbarParent() {
157         return control;
158     }
159
160     /* (non-Javadoc)
161      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getControl()
162      */

163     public Control getControl() {
164         return control;
165     }
166
167     /* (non-Javadoc)
168      * @see org.eclipse.ui.internal.presentations.util.AbstractTabFolder#getTabArea()
169      */

170     public Rectangle getTabArea() {
171         return new Rectangle(0,0,0,0);
172     }
173 }
174
Popular Tags