KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > intro > impl > swt > PageContentForm


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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.intro.impl.swt;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Label;
16 import org.eclipse.ui.forms.widgets.FormToolkit;
17 import org.eclipse.ui.forms.widgets.ScrolledPageBook;
18 import org.eclipse.ui.forms.widgets.TableWrapData;
19 import org.eclipse.ui.forms.widgets.TableWrapLayout;
20 import org.eclipse.ui.internal.intro.impl.IIntroConstants;
21 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
22 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
23 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
24 import org.eclipse.ui.intro.config.IIntroContentProviderSite;
25
26 /**
27  * A Composite that represents the content of an Intro Page. It is swapped in
28  * the categories page book in the PageForm class.
29  */

30 public class PageContentForm implements IIntroConstants {
31
32     private FormToolkit toolkit;
33     private IntroModelRoot model;
34     private PageStyleManager styleManager;
35     // composite to control reflow.
36
private Composite contentComposite;
37
38     // the page we are modeling here.
39
private AbstractIntroPage page;
40
41     // site is cached to hand down to the PageWidgetFactory for creating the UI
42
// for content providers..
43
private IIntroContentProviderSite site;
44
45
46     public PageContentForm(FormToolkit toolkit, IntroModelRoot modelRoot) {
47         this.toolkit = toolkit;
48         this.model = modelRoot;
49         page = model.getCurrentPage();
50     }
51
52     public PageContentForm(FormToolkit toolkit, IntroModelRoot modelRoot,
53             AbstractIntroPage page) {
54         this(toolkit, modelRoot);
55         this.page = page;
56     }
57
58
59     /**
60      * Create the form for the root page. Number of columns there is equal to
61      * the number of links. Every image link does not cache a model object for
62      * data retrieval..
63      *
64      * @param pageBook
65      */

66     public void createPartControl(ScrolledPageBook contentPageBook,
67             PageStyleManager pageStyleManager) {
68         styleManager = pageStyleManager;
69
70         // categoriesComposite has Table Layout with one col. Holds page
71
// description and composite with all other children.
72
contentComposite = contentPageBook.createPage(page.getId());
73         // Util.highlight(contentComposite, SWT.COLOR_GREEN);
74
TableWrapLayout layout = new TableWrapLayout();
75         layout.topMargin = 15;
76         layout.leftMargin = 15;
77         layout.rightMargin = 15;
78         layout.bottomMargin = 15;
79         layout.verticalSpacing = 15;
80         contentComposite.setLayout(layout);
81
82         if (styleManager.getPageDescription() != null) {
83             Label label = toolkit.createLabel(contentComposite, styleManager
84                 .getPageDescription(), SWT.WRAP);
85             label.setFont(PageStyleManager.getBannerFont());
86             TableWrapData td = new TableWrapData();
87             td.align = TableWrapData.FILL;
88             label.setLayoutData(td);
89         }
90
91         // Store the sub-title data for this composite from this page's
92
// subtitle. Make sure you do this before creating the page content to
93
// filter out page sub-title from content area.
94
contentComposite.setData(PAGE_SUBTITLE, styleManager.getPageSubTitle());
95
96         createPageChildren(page, contentComposite);
97
98         styleManager = null;
99     }
100
101     private void createPageChildren(AbstractIntroPage page, Composite parent) {
102         // setup page composite/layout
103
PageWidgetFactory factory = new PageWidgetFactory(toolkit, styleManager);
104         factory.setContentProviderSite(site);
105         Composite pageComposite = createPageTableComposite(factory, toolkit, styleManager, parent);
106         // now add all children
107
AbstractIntroElement[] children = page.getChildren();
108         for (int i = 0; i < children.length; i++)
109             factory.createIntroElement(pageComposite, children[i]);
110
111     }
112
113     /**
114      * Creates a composite with TableWrapLayout to hold all page children. The
115      * default number of columns is 1.
116      *
117      * @param parent
118      * @return
119      */

120     static Composite createPageTableComposite(PageWidgetFactory factory, FormToolkit toolkit,
121             PageStyleManager styleManager, Composite parent) {
122         Composite client = toolkit.createComposite(parent);
123         TableWrapLayout layout = new TableWrapLayout();
124         layout.topMargin = 0;
125         layout.bottomMargin = 0;
126         layout.leftMargin = 0;
127         layout.rightMargin = 0;
128         int numColumns = styleManager.getPageNumberOfColumns();
129         layout.numColumns = numColumns == 0 ? 1 : numColumns;
130         layout.horizontalSpacing = styleManager.getPageHorizantalSpacing();
131         layout.verticalSpacing = styleManager.getPageVerticalSpacing();
132         client.setLayout(layout);
133
134         // parent has TableWrapLayout, and so update layout of this child.
135
TableWrapData td = new TableWrapData(TableWrapData.FILL,
136             TableWrapData.FILL);
137         // td.align = TableWrapData.FILL;
138
td.grabHorizontal = true;
139         client.setLayoutData(td);
140         return client;
141     }
142
143
144     public void setContentProviderSite(IIntroContentProviderSite site) {
145         this.site = site;
146     }
147
148
149
150 }
151
Popular Tags