Skip to main content
summaryrefslogtreecommitdiffstats
blob: b81fa6afdd9301122958cfd40c0bf1a79f162a16 (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
/*******************************************************************************
 * Copyright (c) 2006 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/Oracle - initial API and implementation
 *    
 ********************************************************************************/

package org.eclipse.jst.jsf.ui.internal.validation;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jst.jsf.core.internal.CompositeJSFPreferenceModel;
import org.eclipse.jst.jsf.core.internal.IJSFPreferenceModel;
import org.eclipse.jst.jsf.ui.internal.Messages;
import org.eclipse.jst.jsf.validation.internal.ValidationPreferences;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.preferences.IWorkbenchPreferenceContainer;

/**
 * Creates and manages a panel for configuring 
 * 
 * @author cbateman
 */
/*package*/ class ELPrefPanel 
{
    /* view */
    private final Group                                 _container;
    private final Button                                _chkBuildValidation;
    private final Button                                _chkIncrementalValidation;
    private final ProblemSeveritiesConfigurationBlock   _problemSeverities;
    
    /* model */
    private final ValidationPreferences  _prefs;
    
    /**
     * Allocates new container in parent.
     * @param parent
     * @param container 
     * @param prefs 
     */
    public ELPrefPanel(Composite parent, IWorkbenchPreferenceContainer container, ValidationPreferences prefs)
    {
        _prefs = prefs;

        _container = new Group(parent, SWT.NONE);
        _container.setText(Messages.JSFValidationPreferencePage_ELPrefPanel_Title);
        RowLayout rowLayout = new RowLayout(SWT.VERTICAL);
        rowLayout.marginTop = 5;
        rowLayout.marginLeft = 5; 
        _container.setLayout(rowLayout);

        _chkBuildValidation = new Button(_container, SWT.CHECK);
        _chkBuildValidation.setText(Messages.JSFValidationPreferencePage_ELPrefPanel_BuildValidationCheckBoxTitle);
        _chkBuildValidation.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e) 
            {
                _prefs.getElPrefs().setEnableBuildValidation(_chkBuildValidation.getSelection());
                refresh();
            }
        });
        
        _chkIncrementalValidation = new Button(_container, SWT.CHECK);
        _chkIncrementalValidation.setText(Messages.JSFValidationPreferencePage_ELPrefPanel_IncrementalValidationCheckBoxTitle);
        _chkIncrementalValidation.addSelectionListener(new SelectionAdapter()
        {
            public void widgetSelected(SelectionEvent e) 
            {
                _prefs.getElPrefs().setEnableIncrementalValidation(_chkIncrementalValidation.getSelection());
                refresh();
            }
        });

        new Label(_container, SWT.NONE);
        
        final List<IJSFPreferenceModel> models = new ArrayList<IJSFPreferenceModel>();
        models.add(_prefs.getElPrefs());
        models.add(_prefs.getTypeComparatorPrefs());
        final IJSFPreferenceModel compositeModel = new CompositeJSFPreferenceModel(
                models);

        _problemSeverities = new ProblemSeveritiesConfigurationBlock(compositeModel, null, container);
        _problemSeverities.createContents(_container);
    }
    
    /**
     * @return the top-level container managed by this panel
     */
    public Control getControl()
    {
        return _container;
    }
    
    
    /**
     * Refreshes the UI from the model
     */
    public void refresh()
    {
        _chkBuildValidation.setSelection(_prefs.getElPrefs().isEnableBuildValidation());
        _chkIncrementalValidation.
            setSelection(_prefs.getElPrefs().isEnableIncrementalValidation());
        _problemSeverities.updateControls();
    }

    /**
     * 
     */
    public void processChanges() {
        _problemSeverities.performOk();
    }
}

Back to the top