KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > views > properties > tabbed > view > TabbedPropertyComposite


1 /*******************************************************************************
2  * Copyright (c) 2001, 2007 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.views.properties.tabbed.view;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.custom.ScrolledComposite;
15 import org.eclipse.swt.layout.FormAttachment;
16 import org.eclipse.swt.layout.FormData;
17 import org.eclipse.swt.layout.FormLayout;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetWidgetFactory;
20
21
22 /**
23  * Composite responsible for drawing the tabbed property sheet page.
24  *
25  * @author Anthony Hunter
26  */

27 public class TabbedPropertyComposite
28     extends Composite {
29
30     private TabbedPropertySheetWidgetFactory factory;
31
32     private Composite mainComposite;
33
34     private Composite leftComposite;
35
36     private ScrolledComposite scrolledComposite;
37
38     private Composite tabComposite;
39
40     private TabbedPropertyTitle title;
41
42     private TabbedPropertyList listComposite;
43
44     private boolean displayTitle;
45
46     /**
47      * Constructor for a TabbedPropertyComposite
48      *
49      * @param parent
50      * the parent widget.
51      * @param factory
52      * the widget factory.
53      * @param displayTitle
54      * if <code>true</code>, then the title bar will be displayed.
55      */

56     public TabbedPropertyComposite(Composite parent,
57             TabbedPropertySheetWidgetFactory factory, boolean displayTitle) {
58         super(parent, SWT.NO_FOCUS);
59         this.factory = factory;
60         this.displayTitle = displayTitle;
61
62         createMainComposite();
63     }
64
65     /**
66      * Create the main composite.
67      */

68     protected void createMainComposite() {
69         mainComposite = factory.createComposite(this, SWT.NO_FOCUS);
70         mainComposite.setLayout(new FormLayout());
71         FormData formData = new FormData();
72         formData.left = new FormAttachment(0, 0);
73         formData.right = new FormAttachment(100, 0);
74         formData.top = new FormAttachment(0, 0);
75         formData.bottom = new FormAttachment(100, 0);
76         mainComposite.setLayoutData(formData);
77
78         createMainContents();
79     }
80
81     /**
82      * Create the contents in the main composite.
83      */

84     protected void createMainContents() {
85         if (displayTitle) {
86             title = new TabbedPropertyTitle(mainComposite, factory);
87
88             FormData data = new FormData();
89             data.left = new FormAttachment(0, 0);
90             data.right = new FormAttachment(100, 0);
91             data.top = new FormAttachment(0, 0);
92             title.setLayoutData(data);
93         }
94
95         leftComposite = factory.createComposite(mainComposite, SWT.NO_FOCUS);
96         leftComposite.setLayout(new FormLayout());
97
98         scrolledComposite = factory.createScrolledComposite(mainComposite, SWT.H_SCROLL
99             | SWT.V_SCROLL | SWT.NO_FOCUS);
100         scrolledComposite.setLayout(new FormLayout());
101
102         FormData formData = new FormData();
103         formData.left = new FormAttachment(leftComposite, 0);
104         formData.right = new FormAttachment(100, 0);
105         if (displayTitle) {
106             formData.top = new FormAttachment(title, 0);
107         } else {
108             formData.top = new FormAttachment(0, 0);
109         }
110         formData.bottom = new FormAttachment(100, 0);
111         scrolledComposite.setLayoutData(formData);
112
113         formData = new FormData();
114         formData.left = new FormAttachment(0, 0);
115         formData.right = new FormAttachment(scrolledComposite, 0);
116         if (displayTitle) {
117             formData.top = new FormAttachment(title, 0);
118         } else {
119             formData.top = new FormAttachment(0, 0);
120         }
121         formData.bottom = new FormAttachment(100, 0);
122         leftComposite.setLayoutData(formData);
123
124         tabComposite = factory.createComposite(scrolledComposite, SWT.NO_FOCUS);
125         tabComposite.setLayout(new FormLayout());
126
127         scrolledComposite.setContent(tabComposite);
128         scrolledComposite.setAlwaysShowScrollBars(false);
129         scrolledComposite.setExpandVertical(true);
130         scrolledComposite.setExpandHorizontal(true);
131
132         listComposite = new TabbedPropertyList(leftComposite, factory);
133         formData = new FormData();
134         formData.left = new FormAttachment(0, 0);
135         formData.right = new FormAttachment(100, 0);
136         formData.top = new FormAttachment(0, 0);
137         formData.bottom = new FormAttachment(100, 0);
138         listComposite.setLayoutData(formData);
139
140         FormData data = new FormData();
141         data.left = new FormAttachment(0, 0);
142         data.right = new FormAttachment(100, 0);
143         data.top = new FormAttachment(0, 0);
144         data.bottom = new FormAttachment(100, 0);
145         tabComposite.setLayoutData(data);
146     }
147
148     /**
149      * Get the tabbed property list, which is the list of tabs on the left hand
150      * side of this composite.
151      *
152      * @return the tabbed property list.
153      */

154     public TabbedPropertyList getList() {
155         return listComposite;
156     }
157
158     /**
159      * Get the tabbed property title bar.
160      *
161      * @return the tabbed property title bar or <code>null</code> if not used.
162      */

163     public TabbedPropertyTitle getTitle() {
164         return title;
165     }
166
167     /**
168      * Get the tab composite where sections display their property contents.
169      *
170      * @return the tab composite.
171      */

172     public Composite getTabComposite() {
173         return tabComposite;
174     }
175
176     /**
177      * Get the scrolled composite which surrounds the title bar and tab
178      * composite.
179      *
180      * @return the scrolled composite.
181      */

182     public ScrolledComposite getScrolledComposite() {
183         return scrolledComposite;
184     }
185
186     /**
187      * Get the widget factory.
188      *
189      * @return the widget factory.
190      */

191     protected TabbedPropertySheetWidgetFactory getFactory() {
192         return factory;
193     }
194
195     /**
196      * @see org.eclipse.swt.widgets.Widget#dispose()
197      */

198     public void dispose() {
199         listComposite.dispose();
200         if (displayTitle) {
201             title.dispose();
202         }
203         super.dispose();
204     }
205 }
206
Popular Tags