Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 01df5dd1f1d8b9e5725c72e9b23338935a4e51f4 (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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
/**********************************************************************
 * Copyright (c) 2005, 2014 IBM Corporation, Ericsson
 * 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 - Initial API and implementation
 *     Bernd Hufmann - Updated for TMF
 **********************************************************************/

package org.eclipse.tracecompass.tmf.ui.views.uml2sd.preferences;

import java.util.Iterator;
import java.util.Set;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.ColorFieldEditor;
import org.eclipse.jface.preference.FontFieldEditor;
import org.eclipse.jface.preference.IntegerFieldEditor;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
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.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.tracecompass.tmf.ui.views.uml2sd.util.Messages;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;

/**
 * The Sequence Diagram preferences page implementation.
 *
 * @version 1.0
 * @author sveyrier
 */
public class SDViewerPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener {

    // ------------------------------------------------------------------------
    // Constants
    // ------------------------------------------------------------------------
    /**
     * Temporary preferences tag
     */
    private static final String TEMP_TAG = SDViewPref.TEMP_TAG;

    // ------------------------------------------------------------------------
    // Attributes
    // ------------------------------------------------------------------------
    /**
     * The preference handler used to access the PreferenceStore
     */
    private SDViewPref fPreferences = null;
    /**
     * BackGround color selector
     */
    private ColorFieldEditor fLineColor = null;
    /**
     * Foreground color selector
     */
    private ColorFieldEditor fBackGroundColor = null;
    /**
     * Font color selector
     */
    private ColorFieldEditor fTextColor = null;
    /**
     * List which display all modifiable sequence Diagram font
     */
    private List fClassItemList = null;
    /**
     * Font selector (The same is used for each modifiable font)
     */
    private FontFieldEditor fFont = null;
    /**
     * Link font when zooming selector
     */
    private BooleanFieldEditor fLink = null;
    /**
     * Enable tooltip selector
     */
    private BooleanFieldEditor fTooltip = null;
    /**
     * Do not take external time into account in the min max computation
     */
    private BooleanFieldEditor fNoExternalTime = null;
    /**
     * Use gradient color selector
     */
    private BooleanFieldEditor fUseGrad = null;
    /**
     * A button area.
     */
    private Composite fButtonArea;
    /**
     * SwimLane width selector
     */
    private IntegerFieldEditor fLifelineWidth = null;

    // ------------------------------------------------------------------------
    // Methods
    // ------------------------------------------------------------------------

    @Override
    protected Control createContents(Composite parent) {
        GridLayout gl = new GridLayout();
        gl.marginHeight = 0;
        gl.marginWidth = 0;
        parent.setLayout(gl);
        Composite page = new Composite(parent, SWT.NONE);
        GridLayout pageLayout = new GridLayout();
        pageLayout.numColumns = 2;
        GridData pageLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
        page.setLayoutData(pageLayoutdata);
        page.setLayout(pageLayout);

        fTooltip = new BooleanFieldEditor(ISDPreferences.PREF_TOOLTIP, Messages.SequenceDiagram_ShowTooltips, page);
        fTooltip.setPreferenceStore(fPreferences.getPreferenceStore());
        fTooltip.load();

        // link font with zoom pref
        fLink = new BooleanFieldEditor(ISDPreferences.PREF_LINK_FONT, Messages.SequenceDiagram_IncreaseFontSizeWhenZooming, page);
        fLink.setPreferenceStore(fPreferences.getPreferenceStore());
        fLink.load();

        fNoExternalTime = new BooleanFieldEditor(ISDPreferences.PREF_EXCLUDE_EXTERNAL_TIME, Messages.SequenceDiagram_ExcludeExternalTime, page);
        fNoExternalTime.setPreferenceStore(fPreferences.getPreferenceStore());
        fNoExternalTime.load();

        // use gradient color pref
        fUseGrad = new BooleanFieldEditor(ISDPreferences.PREF_USE_GRADIENT, Messages.SequenceDiagram_UseGradientColor, page);
        fUseGrad.setPreferenceStore(fPreferences.getPreferenceStore());
        fUseGrad.load();

        Label separator = new Label(page, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
        GridData sepData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
        separator.setLayoutData(sepData);

        Composite prefPage = new Composite(page, SWT.NONE);
        GridLayout prefPageLayout = new GridLayout();
        prefPage.setLayoutData(pageLayoutdata);
        prefPageLayout.numColumns = 1;
        prefPage.setLayout(prefPageLayout);

        // swimLane width pref
        fLifelineWidth = new IntegerFieldEditor(ISDPreferences.PREF_LIFELINE_WIDTH, Messages.SequenceDiagram_LifelineWidth, prefPage);
        fLifelineWidth.setPreferenceStore(fPreferences.getPreferenceStore());
        fLifelineWidth.setValidRange(119, 500);
        fLifelineWidth.load();

        // not very nice
        new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
        new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);

        // Font list pref
        fClassItemList = new List(prefPage, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
        GridData tabItemLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
        fClassItemList.setLayoutData(tabItemLayoutdata);

        String[] fontList2 = SDViewPref.getFontList2();
        for (int i = 0; i < fontList2.length; i++) {
            fClassItemList.add(fontList2[i]);
        }
        fClassItemList.setSelection(0);
        fClassItemList.addSelectionListener(this);
        fButtonArea = new Composite(prefPage, SWT.NONE);
        GridData tabItemLayoutdata2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL/* |GridData.GRAB_HORIZONTAL */| GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
        fButtonArea.setLayoutData(tabItemLayoutdata2);
        GridLayout buttonAreaLayout = new GridLayout();
        buttonAreaLayout.numColumns = 1;
        fButtonArea.setLayout(buttonAreaLayout);

        // font selector initialise for the lifeline font pref
        String[] fontList = SDViewPref.getFontList();
        fFont = new FontFieldEditor(fontList[0], "",//$NON-NLS-1$
                Messages.SequenceDiagram_AaBbYyZz, fButtonArea);
        fFont.getPreviewControl().setSize(500, 500);
        fFont.setPreferenceStore(fPreferences.getPreferenceStore());
        fFont.load();

        fBackGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, Messages.SequenceDiagram_Background, fButtonArea);
        fBackGroundColor.setPreferenceStore(fPreferences.getPreferenceStore());
        fBackGroundColor.load();

        fLineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, Messages.SequenceDiagram_Lines, fButtonArea);
        fLineColor.setPreferenceStore(fPreferences.getPreferenceStore());
        fLineColor.load();

        fTextColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, Messages.SequenceDiagram_Text, fButtonArea);
        fTextColor.setPreferenceStore(fPreferences.getPreferenceStore());
        fTextColor.load();
        swapPref(true);
        Dialog.applyDialogFont(page);

        return page;
    }

    @Override
    public void init(IWorkbench workbench) {
        fPreferences = SDViewPref.getInstance();
    }

    @Override
    protected void performApply() {
        // Store the prefrences in the PreferenceStore
        if (!fLifelineWidth.isValid()) {
            fLifelineWidth.showErrorMessage();
            return;
        }
        fFont.store();
        fBackGroundColor.store();
        fLineColor.store();
        fLink.store();
        fTooltip.store();
        fNoExternalTime.store();
        fTextColor.store();
        fUseGrad.store();
        fLifelineWidth.store();
        swapPref(false);
        // then save them in the preference file
        fPreferences.apply();
        swapPref(true);
    }

    @Override
    public boolean performOk() {
        performApply();
        return true;
    }

    @Override
    protected void performDefaults() {
        fLink.loadDefault();
        fTooltip.loadDefault();
        fNoExternalTime.loadDefault();
        fUseGrad.loadDefault();
        fLifelineWidth.loadDefault();

        // and all the fonts and colors
        // fonts and colors are stored for each time because
        // we are using only one FontFieldEditor
        Set<String> keySet = SDViewPref.getInstance().getFontPref().keySet();
        Iterator<String> it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fFont.setPreferenceName((String) prefName);
                fFont.loadDefault();
                fFont.setPreferenceName((String) prefName + TEMP_TAG);
                fFont.store();
            }
        }

        keySet = SDViewPref.getInstance().getBackColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fBackGroundColor.setPreferenceName((String) prefName);
                fBackGroundColor.loadDefault();
                fBackGroundColor.setPreferenceName((String) prefName + TEMP_TAG);
                fBackGroundColor.store();
            }

        }

        String[] fontList = SDViewPref.getFontList();
        fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
        fBackGroundColor.load();

        keySet = SDViewPref.getInstance().getForeColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fLineColor.setPreferenceName((String) prefName);
                fLineColor.loadDefault();
                fLineColor.setPreferenceName((String) prefName + TEMP_TAG);
                fLineColor.store();
            }
        }

        fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
        fLineColor.load();

        keySet = SDViewPref.getInstance().getTextColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fTextColor.setPreferenceName((String) prefName);
                fTextColor.loadDefault();
                fTextColor.setPreferenceName((String) prefName + TEMP_TAG);
                fTextColor.store();
            }
        }
        fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
        fTextColor.load();
    }

    @Override
    public void widgetSelected(SelectionEvent e) {
        // Store the past set font preference or else the
        // FontFieldEditor reassignment will make us loose the current modification
        fFont.store();
        fLineColor.store();
        fBackGroundColor.store();
        fTextColor.store();

        String[] fontList = SDViewPref.getFontList();

        // set the FontFieldEditor for the new selected graphNode font
        fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
        fFont.load();

        fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
        fBackGroundColor.load();

        fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
        fLineColor.load();

        fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
        fTextColor.load();

        // No Background for message graphNodes
        if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_SYNC_MESS)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_SYNC_MESS_RET))
                || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_ASYNC_MESS)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_ASYNC_MESS_RET))) {
            fBackGroundColor.setEnabled(false, fButtonArea);
        } else {
            fBackGroundColor.setEnabled(true, fButtonArea);
        }

        // No font used for execution occurrence and global frame
        if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_EXEC)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME))) {
            fTextColor.setEnabled(false, fButtonArea);
        } else {
            fTextColor.setEnabled(true, fButtonArea);
        }

        if (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME)) {
            fFont.setEnabled(false, fButtonArea);
        } else {
            fFont.setEnabled(true, fButtonArea);
        }
    }

    /**
     * Swap viewer preferences.
     *
     * @param toTemp Switch to the temporary preferences
     */
    protected void swapPref(boolean toTemp) {
        String tag1 = "";//$NON-NLS-1$
        String tag2 = TEMP_TAG;
        if (!toTemp) {
            tag1 = TEMP_TAG;
            tag2 = "";//$NON-NLS-1$
        }
        Set<String> keySet = SDViewPref.getInstance().getFontPref().keySet();
        Iterator<String> it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fFont.setPreferenceName((String) prefName + tag1);
                fFont.load();
                fFont.setPreferenceName((String) prefName + tag2);
                fFont.store();
            }
        }

        keySet = SDViewPref.getInstance().getBackColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fBackGroundColor.setPreferenceName((String) prefName + tag1);
                fBackGroundColor.load();
                fBackGroundColor.setPreferenceName((String) prefName + tag2);
                fBackGroundColor.store();
            }
        }

        keySet = SDViewPref.getInstance().getForeColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fLineColor.setPreferenceName((String) prefName + tag1);
                fLineColor.load();
                fLineColor.setPreferenceName((String) prefName + tag2);
                fLineColor.store();
            }
        }

        keySet = SDViewPref.getInstance().getTextColorPref().keySet();
        it = keySet.iterator();
        while (it.hasNext()) {
            Object prefName = it.next();
            if (prefName instanceof String) {
                fTextColor.setPreferenceName((String) prefName + tag1);
                fTextColor.load();
                fTextColor.setPreferenceName((String) prefName + tag2);
                fTextColor.store();
            }
        }
        String[] fontList = SDViewPref.getFontList();
        if (toTemp) {
            // set the FontFieldEditor for the new selected graphNode font
            fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
            fFont.load();

            fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
            fBackGroundColor.load();

            fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
            fLineColor.load();

            fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
            fTextColor.load();
        }
    }

    @Override
    public void widgetDefaultSelected(SelectionEvent e) {
        // Do nothing
    }
}

Back to the top