Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 24996aad49da2c2bdf9d18ec0e4114d4020eb80c (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
/*******************************************************************************
 * Copyright (c) 2008 Oracle Corporation.
 * 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:
 *    Cameron Bateman - initial API and implementation
 *******************************************************************************/
package org.eclipse.jst.jsf.facelet.ui.internal.facet;

import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.BeansObservables;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jst.jsf.facelet.core.internal.facet.ChangeActionType;
import org.eclipse.jst.jsf.facelet.core.internal.facet.FacetChangeModel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.wst.common.project.facet.ui.AbstractFacetWizardPage;

/**
 * A common facet change UI page, mainly used for facet install/uninstall.
 * 
 * @author cbateman
 *
 */
public abstract class FaceletChangePage extends AbstractFacetWizardPage
{
    private Button             _chgDefaultSuffix;
    private Button             _chgViewHandler;
    private Button             _chgConfigureListener;
    private Button             _chgWebappLifecycleListener;

    private DataBindingContext _bindingContext;
    private FacetChangeModel _dataModel;

    /**
     * @param name
     */
    public FaceletChangePage(String name)
    {
        super(name);
    }

    public void setConfig(final Object config)
    {
        _dataModel = (FacetChangeModel) config;
    }

    /**
     * @return the name of the change based on the actionType enumeration.
     */
    protected String getTextForChangeType()
    {
        final ChangeActionType actionType = _dataModel.getChangeActionType();

        switch (actionType)
        {
            case ADD:
                return "Add";

            case REMOVE:
                return "Remove";
        }

        return "*ERROR*";
    }

    private void initDefaultSuffixButton(final Composite parent)
    {
        _chgDefaultSuffix = new Button(parent, SWT.CHECK);
        _chgDefaultSuffix.setText(getTextForChangeType() + " '.xhtml' DEFAULT_SUFFIX parameter");
        _chgDefaultSuffix.setSelection(_dataModel.isChgDefaultSuffix());
        _chgDefaultSuffix.setLayoutData(new RowData());
        IObservableValue modelObservable = BeansObservables.observeValue(
                _dataModel, "chgDefaultSuffix");

        _bindingContext.bindValue(SWTObservables
                .observeSelection(_chgDefaultSuffix), modelObservable, null,
                null);
    }

    private void initViewHandlerButton(final Composite parent)
    {
        _chgViewHandler = new Button(parent, SWT.CHECK);
        _chgViewHandler.setText(getTextForChangeType() + " Facelet view handler");
        _chgViewHandler.setSelection(_dataModel.isChgViewHandler());
        _chgViewHandler.setLayoutData(new RowData());
        IObservableValue modelObservable = BeansObservables.observeValue(
                _dataModel, "chgViewHandler");

        _bindingContext
                .bindValue(SWTObservables.observeSelection(_chgViewHandler),
                        modelObservable, null, null);
    }

    private void initConfigureListener(final Composite parent)
    {
        _chgConfigureListener = new Button(parent, SWT.CHECK);
        _chgConfigureListener
                .setText(getTextForChangeType() + " configure listener (needed by some Tomcat containers)");
        _chgConfigureListener.setSelection(_dataModel.isChgConfigureListener());
        _chgConfigureListener.setLayoutData(new RowData());
        IObservableValue modelObservable = BeansObservables.observeValue(
                _dataModel, "chgConfigureListener");

        _bindingContext.bindValue(SWTObservables
                .observeSelection(_chgConfigureListener), modelObservable,
                null, null);
    }

    private void initWebappLifecycleListener(final Composite parent)
    {
        _chgWebappLifecycleListener = new Button(parent, SWT.CHECK);
        _chgWebappLifecycleListener
                .setText(getTextForChangeType() + " web application lifecycle listener (needed by some Tomcat containers)");
        _chgWebappLifecycleListener.setSelection(_dataModel
                .isChgConfigureListener());
        _chgWebappLifecycleListener.setLayoutData(new RowData());
        IObservableValue modelObservable = BeansObservables.observeValue(
                _dataModel, "chgWebAppLifecycleListener");

        _bindingContext.bindValue(SWTObservables
                .observeSelection(_chgWebappLifecycleListener),
                modelObservable, null, null);
    }

    public void createControl(final Composite parent)
    {
        setTitle("Facelet");
        setMessage("Configure Facelet settings");

        _bindingContext = new DataBindingContext();

        // WizardPageSupport.create(this, _bindingContext);

        final Composite control = new Composite(parent, SWT.NONE);
        final RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
        rowLayout.fill = true;
        control.setLayout(rowLayout);

        final Group webXMLGroup = new Group(control, SWT.NONE);
        webXMLGroup.setLayout(rowLayout);
        webXMLGroup.setText("Deployment Descriptor (web.xml) Configuration");
        initDefaultSuffixButton(webXMLGroup);
        initConfigureListener(webXMLGroup);
        initWebappLifecycleListener(webXMLGroup);

        final Group facesConfigGroup = new Group(control, SWT.NONE);
        facesConfigGroup.setLayout(rowLayout);
        facesConfigGroup
                .setText("Application (faces-config.xml) Configuration");
        initViewHandlerButton(facesConfigGroup);

        setControl(control);
    }
}

Back to the top