001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 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.intro.impl.swt;
011:
012: import org.eclipse.swt.SWT;
013: import org.eclipse.swt.widgets.Composite;
014: import org.eclipse.swt.widgets.Label;
015: import org.eclipse.ui.forms.widgets.FormToolkit;
016: import org.eclipse.ui.forms.widgets.ScrolledPageBook;
017: import org.eclipse.ui.forms.widgets.TableWrapData;
018: import org.eclipse.ui.forms.widgets.TableWrapLayout;
019: import org.eclipse.ui.internal.intro.impl.IIntroConstants;
020: import org.eclipse.ui.internal.intro.impl.model.AbstractIntroElement;
021: import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
022: import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
023: import org.eclipse.ui.intro.config.IIntroContentProviderSite;
024:
025: /**
026: * A Composite that represents the content of an Intro Page. It is swapped in
027: * the categories page book in the PageForm class.
028: */
029: public class PageContentForm implements IIntroConstants {
030:
031: private FormToolkit toolkit;
032: private IntroModelRoot model;
033: private PageStyleManager styleManager;
034: // composite to control reflow.
035: private Composite contentComposite;
036:
037: // the page we are modeling here.
038: private AbstractIntroPage page;
039:
040: // site is cached to hand down to the PageWidgetFactory for creating the UI
041: // for content providers..
042: private IIntroContentProviderSite site;
043:
044: public PageContentForm(FormToolkit toolkit, IntroModelRoot modelRoot) {
045: this .toolkit = toolkit;
046: this .model = modelRoot;
047: page = model.getCurrentPage();
048: }
049:
050: public PageContentForm(FormToolkit toolkit,
051: IntroModelRoot modelRoot, AbstractIntroPage page) {
052: this (toolkit, modelRoot);
053: this .page = page;
054: }
055:
056: /**
057: * Create the form for the root page. Number of columns there is equal to
058: * the number of links. Every image link does not cache a model object for
059: * data retrieval..
060: *
061: * @param pageBook
062: */
063: public void createPartControl(ScrolledPageBook contentPageBook,
064: PageStyleManager pageStyleManager) {
065: styleManager = pageStyleManager;
066:
067: // categoriesComposite has Table Layout with one col. Holds page
068: // description and composite with all other children.
069: contentComposite = contentPageBook.createPage(page.getId());
070: // Util.highlight(contentComposite, SWT.COLOR_GREEN);
071: TableWrapLayout layout = new TableWrapLayout();
072: layout.topMargin = 15;
073: layout.leftMargin = 15;
074: layout.rightMargin = 15;
075: layout.bottomMargin = 15;
076: layout.verticalSpacing = 15;
077: contentComposite.setLayout(layout);
078:
079: if (styleManager.getPageDescription() != null) {
080: Label label = toolkit.createLabel(contentComposite,
081: styleManager.getPageDescription(), SWT.WRAP);
082: label.setFont(PageStyleManager.getBannerFont());
083: TableWrapData td = new TableWrapData();
084: td.align = TableWrapData.FILL;
085: label.setLayoutData(td);
086: }
087:
088: // Store the sub-title data for this composite from this page's
089: // subtitle. Make sure you do this before creating the page content to
090: // filter out page sub-title from content area.
091: contentComposite.setData(PAGE_SUBTITLE, styleManager
092: .getPageSubTitle());
093:
094: createPageChildren(page, contentComposite);
095:
096: styleManager = null;
097: }
098:
099: private void createPageChildren(AbstractIntroPage page,
100: Composite parent) {
101: // setup page composite/layout
102: PageWidgetFactory factory = new PageWidgetFactory(toolkit,
103: styleManager);
104: factory.setContentProviderSite(site);
105: Composite pageComposite = createPageTableComposite(factory,
106: toolkit, styleManager, parent);
107: // now add all children
108: AbstractIntroElement[] children = page.getChildren();
109: for (int i = 0; i < children.length; i++)
110: factory.createIntroElement(pageComposite, children[i]);
111:
112: }
113:
114: /**
115: * Creates a composite with TableWrapLayout to hold all page children. The
116: * default number of columns is 1.
117: *
118: * @param parent
119: * @return
120: */
121: static Composite createPageTableComposite(
122: PageWidgetFactory factory, FormToolkit toolkit,
123: PageStyleManager styleManager, Composite parent) {
124: Composite client = toolkit.createComposite(parent);
125: TableWrapLayout layout = new TableWrapLayout();
126: layout.topMargin = 0;
127: layout.bottomMargin = 0;
128: layout.leftMargin = 0;
129: layout.rightMargin = 0;
130: int numColumns = styleManager.getPageNumberOfColumns();
131: layout.numColumns = numColumns == 0 ? 1 : numColumns;
132: layout.horizontalSpacing = styleManager
133: .getPageHorizantalSpacing();
134: layout.verticalSpacing = styleManager.getPageVerticalSpacing();
135: client.setLayout(layout);
136:
137: // parent has TableWrapLayout, and so update layout of this child.
138: TableWrapData td = new TableWrapData(TableWrapData.FILL,
139: TableWrapData.FILL);
140: // td.align = TableWrapData.FILL;
141: td.grabHorizontal = true;
142: client.setLayoutData(td);
143: return client;
144: }
145:
146: public void setContentProviderSite(IIntroContentProviderSite site) {
147: this.site = site;
148: }
149:
150: }
|