Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4da3a1f4b53d7acae8592fe283cbea6ab20ed145 (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
/*******************************************************************************
 * Copyright (c) 2008, 2011 THALES GLOBAL SERVICES.
 * 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:
 *    Obeo - initial API and implementation
 *******************************************************************************/
package org.eclipse.sirius.ui.tools.internal.preference;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
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.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

import org.eclipse.sirius.common.tools.api.constant.CommonPreferencesConstants;
import org.eclipse.sirius.common.ui.SiriusTransPlugin;
import org.eclipse.sirius.business.api.preferences.DesignerPreferencesKeys;
import org.eclipse.sirius.provider.SiriusEditPlugin;
import org.eclipse.sirius.ui.business.api.preferences.DesignerUIPreferencesKeys;

/**
 * Page for viewpoint preferences.
 * 
 * @author ymortier
 */
public class DesignerPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

    /**
     * Label of the check box emptyAirdFragmentOnControl.
     */
    public static final String EMPTY_AIRD_ON_CONTROL_CHECKBOX_LABEL = "Always create an aird fragment on control";

    private BooleanFieldEditor refreshOnRepresentationOpening;

    private BooleanFieldEditor autoRefresh;

    private BooleanFieldEditor emptyAirdFragmentOnControl;

    private BooleanFieldEditor defensiveFileEdit;

    private BooleanFieldEditor traceMode;
    
    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors()
     */
    @Override
    protected void createFieldEditors() {
        setPreferenceStore(SiriusEditPlugin.getPlugin().getPreferenceStore());

        Composite parent = getFieldEditorParent();
        if (parent.getLayout() == null) {
            GridLayout gridLayout = new GridLayout(1, false);
            parent.setLayout(gridLayout);
        }

        addRefreshFields(parent);
        addFilesFields(parent);
        addProfilingField(parent);

    }

    private void addFilesFields(Composite parent) {
        Composite fileComposite = createGroup(parent, "Files");

        emptyAirdFragmentOnControl = new BooleanFieldEditorWithHelp(DesignerPreferencesKeys.PREF_EMPTY_AIRD_FRAGMENT_ON_CONTROL.name(), EMPTY_AIRD_ON_CONTROL_CHECKBOX_LABEL,
                "Allow the creation of an empty aird fragment if there is no selected representation", new Composite(fileComposite, SWT.NONE));
        addField(emptyAirdFragmentOnControl);

        defensiveFileEdit = new BooleanFieldEditor(CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, "Validate file edits on command application.", new Composite(fileComposite, SWT.NONE));
        addField(defensiveFileEdit);

    }

    private void addRefreshFields(Composite parent) {
        Composite refreshComposite = createGroup(parent, "Refresh");

        refreshOnRepresentationOpening = new BooleanFieldEditor(DesignerUIPreferencesKeys.PREF_REFRESH_ON_REPRESENTATION_OPENING.name(), "Do refresh on representation opening", new Composite(
                refreshComposite, SWT.NONE));
        addField(refreshOnRepresentationOpening);

        autoRefresh = new BooleanFieldEditor(DesignerPreferencesKeys.PREF_AUTO_REFRESH.name(), "Automatic Refresh", new Composite(refreshComposite, SWT.NONE));
        addField(autoRefresh);
    }

    private void addProfilingField(Composite parent) {
        Composite profilerComposite = createGroup(parent, "Profiler");

        traceMode = new BooleanFieldEditorWithHelp(CommonPreferencesConstants.PREF_TRACE_ON, "Profiling", "Open the profiler view: Sirius Profiler > Time Profiler View.", new Composite(profilerComposite,
                SWT.NONE));
        addField(traceMode);
    }

    private Group createGroup(Composite parent, String text) {
        Group group = new Group(parent, SWT.NONE);
        GridLayout gridLayout = new GridLayout(1, false);
        group.setLayout(gridLayout);
        GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.grabExcessHorizontalSpace = true;
        gridData.horizontalSpan = 1;
        group.setLayoutData(gridData);
        group.setText(text);

        return group;
    }

    /**
     * {@inheritDoc}
     * 
     * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
     */
    public void init(final IWorkbench workbench) {
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected void initialize() {
        super.initialize();

        // Set preference store to common ui plugin, FileStatusPrecommitListener
        // and profiler
        // will take the value there.
        defensiveFileEdit.setPreferenceStore(SiriusTransPlugin.getPlugin().getPreferenceStore());
        defensiveFileEdit.load();
        traceMode.setPreferenceStore(SiriusTransPlugin.getPlugin().getPreferenceStore());
        traceMode.load();
    }

}

Back to the top