Skip to main content
summaryrefslogtreecommitdiffstats
blob: d269dd275b1e6da9556d672c8c672ac9c58a7b4b (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
/*******************************************************************************
 * Copyright (c) 2005, 2006 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
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     Oracle - adapted for JSF tooling
 *     
 *******************************************************************************/
package org.eclipse.jst.jsf.ui.internal.preferences;

import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jst.jsf.ui.internal.Messages;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
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.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * The empty pref page used as the root of all other JSF feature preference pages
 * under the Web&XML top-level pref page
 * 
 * @author cbateman
 *
 */
public class EmptyRootPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {

    private Composite createComposite(Composite parent, int numColumns) {
        noDefaultAndApplyButton();
        
        Composite composite = new Composite(parent, SWT.NULL);

        // GridLayout
        GridLayout layout = new GridLayout();
        layout.numColumns = numColumns;
        composite.setLayout(layout);

        // GridData
        GridData data = new GridData(GridData.FILL);
        data.horizontalIndent = 0;
        data.verticalAlignment = GridData.FILL;
        data.horizontalAlignment = GridData.FILL;
        composite.setLayoutData(data);

        return composite;
    }

    protected Control createContents(Composite parent) {
        Composite composite = createScrolledComposite(parent);

        String description = Messages.JSFPreferences_RootPage_Description;
        Text text = new Text(composite, SWT.READ_ONLY);
        // some themes on GTK have different background colors for Text and Labels
        text.setBackground(composite.getBackground());
        text.setText(description);

        setSize(composite);
        return composite;
    }

    private Composite createScrolledComposite(Composite parent) {
        // create scrollbars for this parent when needed
        final ScrolledComposite sc1 = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
        sc1.setLayoutData(new GridData(GridData.FILL_BOTH));
        Composite composite = createComposite(sc1, 1);
        sc1.setContent(composite);

        // not calling setSize for composite will result in a blank composite,
        // so calling it here initially
        // setSize actually needs to be called after all controls are created,
        // so scrolledComposite
        // has correct minSize
        setSize(composite);
        return composite;
    }

    public void init(IWorkbench workbench) {
        // do  nothing
    }

    private void setSize(Composite composite) {
        if (composite != null) {
            // Note: The font is set here in anticipation that the class inheriting
            //       this base class may add widgets to the dialog.   setSize
            //       is assumed to be called just before we go live.
            applyDialogFont(composite);
            Point minSize = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            composite.setSize(minSize);
            // set scrollbar composite's min size so page is expandable but
            // has scrollbars when needed
            if (composite.getParent() instanceof ScrolledComposite) {
                ScrolledComposite sc1 = (ScrolledComposite) composite.getParent();
                sc1.setMinSize(minSize);
                sc1.setExpandHorizontal(true);
                sc1.setExpandVertical(true);
            }
        }
    }
}

Back to the top