Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 5d1d2b39eaa75008a390e5a105a140764c3949ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*******************************************************************************
 * Copyright (c) 2004, 2016 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.ui.internal.intro.impl.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledPageBook;
import org.eclipse.ui.internal.intro.impl.IIntroConstants;
import org.eclipse.ui.internal.intro.impl.Messages;
import org.eclipse.ui.internal.intro.impl.model.AbstractIntroPage;
import org.eclipse.ui.internal.intro.impl.model.IntroModelRoot;
import org.eclipse.ui.internal.intro.impl.model.url.IntroURLParser;
import org.eclipse.ui.internal.intro.impl.util.DialogUtil;
import org.eclipse.ui.internal.intro.impl.util.Util;
import org.eclipse.ui.intro.config.IIntroContentProviderSite;

/**
 * A Form that represents an Intro Page. It is swapped in the main page book in
 * the FormIntroPartImplementation class. It has a page book for swapping in
 * categories (content) of Intro Pages.
 */
public class PageForm implements IIntroConstants {

    protected FormToolkit toolkit;
    private ScrolledPageBook categoryPageBook;
    protected IntroModelRoot model;
    private Form parentForm;
    protected Form pageForm;
    // private SharedStyleManager sharedStyleManager;

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

    // site is cached to hand down to the PageWidgetFactory for creating the UI
    // for content providers..
    private IIntroContentProviderSite site;

    protected HyperlinkAdapter hyperlinkAdapter = new HyperlinkAdapter() {

        @Override
		public void linkActivated(HyperlinkEvent e) {
            String url = (String) e.getHref();
            IntroURLParser parser = new IntroURLParser(url);
            if (parser.hasIntroUrl()) {
                // execute the action embedded in the IntroURL
                parser.getIntroURL().execute();
                return;
            } else if (parser.hasProtocol()) {
                Util.openBrowser(url);
                return;
            }
            DialogUtil.displayInfoMessage(((Control) e.getSource()).getShell(),
                Messages.HyperlinkAdapter_urlIs + " " + url); //$NON-NLS-1$
        }

        @Override
		public void linkEntered(HyperlinkEvent e) {
        }

        @Override
		public void linkExited(HyperlinkEvent e) {
        }
    };

    /**
     *
     */
    public PageForm(FormToolkit toolkit, IntroModelRoot modelRoot,
            Form parentForm) {
        this.toolkit = toolkit;
        this.model = modelRoot;
        this.parentForm = parentForm;
    }

    /**
     * Create a Form for holding pages without navigation.
     *
     * @param pageBook
     */
    public void createPartControl(ScrolledPageBook mainPageBook,
            SharedStyleManager sharedStyleManager) {

        // Cash the shared style manager. We need to pass it around to category
        // forms. So, do not null it!
        // this.sharedStyleManager = sharedStyleManager;

        // creating page in Main page book.
        pageForm = toolkit.createForm(mainPageBook.getContainer());
        mainPageBook.registerPage(getId(), pageForm);
        GridLayout layout = new GridLayout();
        layout.marginWidth = 0;
        layout.marginHeight = 0;
        pageForm.getBody().setLayout(layout);
        // Util.highlight(pageForm.getBody(), SWT.COLOR_RED);

        // Get form body. Form body is one column grid layout. Add page book
        // and navigation UI to it.
        categoryPageBook = toolkit.createPageBook(pageForm.getBody(),
            SWT.H_SCROLL | SWT.V_SCROLL);
        categoryPageBook.setLayoutData(new GridData(GridData.FILL_BOTH));

        // pageForm.setText(rootPageStyleManager.getPageSubTitle());
    }


    protected String getId() {
        return PAGE_FORM_ID;
    }



    /**
     * This method is called when the current page changes. It creates the
     * PageContentForm if necessary, and handles showing the page in the Page
     * Book. It creates a model PageContentForm for the current page.
     *
     * @param pageID
     */
    public void showPage(AbstractIntroPage page,
            SharedStyleManager sharedStyleManager) {

        if (!categoryPageBook.hasPage(page.getId())) {
            // if we do not have a category form for this page create one.
            PageContentForm categoryForm = new PageContentForm(toolkit, model,
                page);
            categoryForm.setContentProviderSite(site);
            // load style manager only once, here.
            PageStyleManager styleManager = new PageStyleManager(page,
                sharedStyleManager.getProperties());
            categoryForm.createPartControl(categoryPageBook, styleManager);
        }
        categoryPageBook.showPage(page.getId());

        // Get cached page subtitle from control data.
        Composite pageComposite = (Composite) categoryPageBook.getCurrentPage();
        // update main Form title.
        parentForm.setText(model.getCurrentPage().getTitle());
        // update this page form's title, ie: Page subtitle, if it exists.
        pageForm.setText((String) pageComposite.getData(PAGE_SUBTITLE));

        // TODO need to transfer focus to the first link in
        // the page somehow; we may need IIntroPage interface with
        // a few methods like 'setFocus()' etc.
        // DG
    }

    public void reflow() {
    	categoryPageBook.reflow(true);
    }

    public boolean hasPage(String pageId) {
        return categoryPageBook.hasPage(pageId);
    }

    public void removePage(String pageId) {
        categoryPageBook.removePage(pageId);
    }

    public void setContentProviderSite(IIntroContentProviderSite site) {
        this.site = site;
    }


}

Back to the top