KickJava   Java API By Example, From Geeks To Geeks.

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


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.layout.GridData;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Control;
18 import org.eclipse.ui.forms.events.HyperlinkAdapter;
19 import org.eclipse.ui.forms.events.HyperlinkEvent;
20 import org.eclipse.ui.forms.widgets.Form;
21 import org.eclipse.ui.forms.widgets.FormToolkit;
22 import org.eclipse.ui.forms.widgets.ScrolledPageBook;
23 import org.eclipse.ui.internal.intro.impl.IIntroConstants;
24 import org.eclipse.ui.internal.intro.impl.Messages;
25 import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
26 import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
27 import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
28 import org.eclipse.ui.internal.intro.impl.util.DialogUtil;
29 import org.eclipse.ui.internal.intro.impl.util.Util;
30 import org.eclipse.ui.intro.config.IIntroContentProviderSite;
31
32 /**
33  * A Form that represents an Intro Page. It is swapped in the main page book in
34  * the FormIntroPartImplementation class. It has a page book for swapping in
35  * categories (content) of Intro Pages.
36  */

37 public class PageForm implements IIntroConstants {
38
39     protected FormToolkit toolkit;
40     private ScrolledPageBook categoryPageBook;
41     protected IntroModelRoot model;
42     private Form parentForm;
43     protected Form pageForm;
44     // private SharedStyleManager sharedStyleManager;
45

46     // Id to this page. There is only a single instance of this page in the
47
// main page book.
48
public static String JavaDoc PAGE_FORM_ID = "pageFormId"; //$NON-NLS-1$
49

50     // site is cached to hand down to the PageWidgetFactory for creating the UI
51
// for content providers..
52
private IIntroContentProviderSite site;
53
54     protected HyperlinkAdapter hyperlinkAdapter = new HyperlinkAdapter() {
55
56         public void linkActivated(HyperlinkEvent e) {
57             String JavaDoc url = (String JavaDoc) e.getHref();
58             IntroURLParser parser = new IntroURLParser(url);
59             if (parser.hasIntroUrl()) {
60                 // execute the action embedded in the IntroURL
61
parser.getIntroURL().execute();
62                 return;
63             } else if (parser.hasProtocol()) {
64                 Util.openBrowser(url);
65                 return;
66             }
67             DialogUtil.displayInfoMessage(((Control) e.getSource()).getShell(),
68                 Messages.HyperlinkAdapter_urlIs + " " + url); //$NON-NLS-1$
69
}
70
71         public void linkEntered(HyperlinkEvent e) {
72         }
73
74         public void linkExited(HyperlinkEvent e) {
75         }
76     };
77
78     /**
79      *
80      */

81     public PageForm(FormToolkit toolkit, IntroModelRoot modelRoot,
82             Form parentForm) {
83         this.toolkit = toolkit;
84         this.model = modelRoot;
85         this.parentForm = parentForm;
86     }
87
88     /**
89      * Create a Form for holding pages without navigation.
90      *
91      * @param pageBook
92      */

93     public void createPartControl(ScrolledPageBook mainPageBook,
94             SharedStyleManager sharedStyleManager) {
95
96         // Cash the shared style manager. We need to pass it around to category
97
// forms. So, do not null it!
98
// this.sharedStyleManager = sharedStyleManager;
99

100         // creating page in Main page book.
101
pageForm = toolkit.createForm(mainPageBook.getContainer());
102         mainPageBook.registerPage(getId(), pageForm);
103         GridLayout layout = new GridLayout();
104         layout.marginWidth = 0;
105         layout.marginHeight = 0;
106         pageForm.getBody().setLayout(layout);
107         // Util.highlight(pageForm.getBody(), SWT.COLOR_RED);
108

109         // Get form body. Form body is one column grid layout. Add page book
110
// and navigation UI to it.
111
categoryPageBook = toolkit.createPageBook(pageForm.getBody(),
112             SWT.H_SCROLL | SWT.V_SCROLL);
113         categoryPageBook.setLayoutData(new GridData(GridData.FILL_BOTH));
114
115         // pageForm.setText(rootPageStyleManager.getPageSubTitle());
116
}
117
118
119     protected String JavaDoc getId() {
120         return PAGE_FORM_ID;
121     }
122
123
124
125     /**
126      * This method is called when the current page changes. It creates the
127      * PageContentForm if necessary, and handles showing the page in the Page
128      * Book. It creates a model PageContentForm for the current page.
129      *
130      * @param pageID
131      */

132     public void showPage(AbstractIntroPage page,
133             SharedStyleManager sharedStyleManager) {
134
135         if (!categoryPageBook.hasPage(page.getId())) {
136             // if we do not have a category form for this page create one.
137
PageContentForm categoryForm = new PageContentForm(toolkit, model,
138                 page);
139             categoryForm.setContentProviderSite(site);
140             // load style manager only once, here.
141
PageStyleManager styleManager = new PageStyleManager(page,
142                 sharedStyleManager.getProperties());
143             categoryForm.createPartControl(categoryPageBook, styleManager);
144         }
145         categoryPageBook.showPage(page.getId());
146
147         // Get cached page subtitle from control data.
148
Composite pageComposite = (Composite) categoryPageBook.getCurrentPage();
149         // update main Form title.
150
parentForm.setText(model.getCurrentPage().getTitle());
151         // update this page form's title, ie: Page subtitle, if it exists.
152
pageForm.setText((String JavaDoc) pageComposite.getData(PAGE_SUBTITLE));
153
154         // TODO need to transfer focus to the first link in
155
// the page somehow; we may need IIntroPage interface with
156
// a few methods like 'setFocus()' etc.
157
// DG
158
}
159     
160     public void reflow() {
161         categoryPageBook.reflow(true);
162     }
163
164     public boolean hasPage(String JavaDoc pageId) {
165         return categoryPageBook.hasPage(pageId);
166     }
167
168     public void removePage(String JavaDoc pageId) {
169         categoryPageBook.removePage(pageId);
170     }
171
172     public void setContentProviderSite(IIntroContentProviderSite site) {
173         this.site = site;
174     }
175
176
177 }
178
Popular Tags