1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
;
15 import java
.util
.Iterator
;
18 import org
.eclipse
.jface
.dialogs
.Dialog
;
19 import org
.eclipse
.jface
.preference
.BooleanFieldEditor
;
20 import org
.eclipse
.jface
.preference
.ColorFieldEditor
;
21 import org
.eclipse
.jface
.preference
.FontFieldEditor
;
22 import org
.eclipse
.jface
.preference
.IntegerFieldEditor
;
23 import org
.eclipse
.jface
.preference
.PreferencePage
;
24 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.Messages
;
25 import org
.eclipse
.swt
.SWT
;
26 import org
.eclipse
.swt
.events
.SelectionEvent
;
27 import org
.eclipse
.swt
.events
.SelectionListener
;
28 import org
.eclipse
.swt
.layout
.GridData
;
29 import org
.eclipse
.swt
.layout
.GridLayout
;
30 import org
.eclipse
.swt
.widgets
.Composite
;
31 import org
.eclipse
.swt
.widgets
.Control
;
32 import org
.eclipse
.swt
.widgets
.Label
;
33 import org
.eclipse
.swt
.widgets
.List
;
34 import org
.eclipse
.ui
.IWorkbench
;
35 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
38 * The Sequence Diagram preferences page implementation.
43 public class SDViewerPage
extends PreferencePage
implements IWorkbenchPreferencePage
, SelectionListener
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * Temporary preferences tag
51 private static final String TEMP_TAG
= SDViewPref
.TEMP_TAG
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * The preference handler used to access the PreferenceStore
59 private SDViewPref fPreferences
= null;
61 * BackGround color selector
63 private ColorFieldEditor fLineColor
= null;
65 * Foreground color selector
67 private ColorFieldEditor fBackGroundColor
= null;
71 private ColorFieldEditor fTextColor
= null;
73 * List which display all modifiable sequence Diagram font
75 private List fClassItemList
= null;
77 * Font selector (The same is used for each modifiable font)
79 private FontFieldEditor fFont
= null;
81 * Link font when zooming selector
83 private BooleanFieldEditor fLink
= null;
85 * Enable tooltip selector
87 private BooleanFieldEditor fTooltip
= null;
89 * Do not take external time into account in the min max computation
91 private BooleanFieldEditor fNoExternalTime
= null;
93 * Use gradient color selector
95 private BooleanFieldEditor fUseGrad
= null;
99 private Composite fButtonArea
;
101 * SwimLane width selector
103 private IntegerFieldEditor fLifelineWidth
= null;
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
110 protected Control
createContents(Composite parent
) {
111 parent
.setLayout(new GridLayout());
112 Composite page
= new Composite(parent
, SWT
.NONE
);
113 GridLayout pageLayout
= new GridLayout();
114 pageLayout
.numColumns
= 2;
115 GridData pageLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
116 page
.setLayoutData(pageLayoutdata
);
117 page
.setLayout(pageLayout
);
119 fTooltip
= new BooleanFieldEditor(ISDPreferences
.PREF_TOOLTIP
, Messages
.SequenceDiagram_ShowTooltips
, page
);
120 fTooltip
.setPreferenceStore(fPreferences
.getPreferenceStore());
123 // link font with zoom pref
124 fLink
= new BooleanFieldEditor(ISDPreferences
.PREF_LINK_FONT
, Messages
.SequenceDiagram_IncreaseFontSizeWhenZooming
, page
);
125 fLink
.setPreferenceStore(fPreferences
.getPreferenceStore());
128 fNoExternalTime
= new BooleanFieldEditor(ISDPreferences
.PREF_EXCLUDE_EXTERNAL_TIME
, Messages
.SequenceDiagram_ExcludeExternalTime
, page
);
129 fNoExternalTime
.setPreferenceStore(fPreferences
.getPreferenceStore());
130 fNoExternalTime
.load();
132 // use gradient color pref
133 fUseGrad
= new BooleanFieldEditor(ISDPreferences
.PREF_USE_GRADIENT
, Messages
.SequenceDiagram_UseGradientColor
, page
);
134 fUseGrad
.setPreferenceStore(fPreferences
.getPreferenceStore());
137 Label separator
= new Label(page
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
138 GridData sepData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
139 separator
.setLayoutData(sepData
);
141 Composite prefPage
= new Composite(page
, SWT
.NONE
);
142 GridLayout prefPageLayout
= new GridLayout();
143 prefPage
.setLayoutData(pageLayoutdata
);
144 prefPageLayout
.numColumns
= 1;
145 prefPage
.setLayout(prefPageLayout
);
147 // swimLane width pref
148 fLifelineWidth
= new IntegerFieldEditor(ISDPreferences
.PREF_LIFELINE_WIDTH
, Messages
.SequenceDiagram_LifelineWidth
, prefPage
);
149 fLifelineWidth
.setPreferenceStore(fPreferences
.getPreferenceStore());
150 fLifelineWidth
.setValidRange(119, 500);
151 fLifelineWidth
.load();
154 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
155 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
158 fClassItemList
= new List(prefPage
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
);
159 GridData tabItemLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
160 fClassItemList
.setLayoutData(tabItemLayoutdata
);
162 String
[] fontList2
= SDViewPref
.getFontList2();
163 for (int i
= 0; i
< fontList2
.length
; i
++) {
164 fClassItemList
.add(fontList2
[i
]);
166 fClassItemList
.setSelection(0);
167 fClassItemList
.addSelectionListener(this);
168 fButtonArea
= new Composite(prefPage
, SWT
.NONE
);
169 GridData tabItemLayoutdata2
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
/* |GridData.GRAB_HORIZONTAL */| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
170 fButtonArea
.setLayoutData(tabItemLayoutdata2
);
171 GridLayout buttonAreaLayout
= new GridLayout();
172 buttonAreaLayout
.numColumns
= 1;
173 fButtonArea
.setLayout(buttonAreaLayout
);
175 // font selector initialise for the lifeline font pref
176 String
[] fontList
= SDViewPref
.getFontList();
177 fFont
= new FontFieldEditor(fontList
[0], "",//$NON-NLS-1$
178 Messages
.SequenceDiagram_AaBbYyZz
, fButtonArea
);
179 fFont
.getPreviewControl().setSize(500, 500);
180 fFont
.setPreferenceStore(fPreferences
.getPreferenceStore());
183 fBackGroundColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.BACK_COLOR_POSTFIX
, Messages
.SequenceDiagram_Background
, fButtonArea
);
184 fBackGroundColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
185 fBackGroundColor
.load();
187 fLineColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.FORE_COLOR_POSTFIX
, Messages
.SequenceDiagram_Lines
, fButtonArea
);
188 fLineColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
191 fTextColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.TEXT_COLOR_POSTFIX
, Messages
.SequenceDiagram_Text
, fButtonArea
);
192 fTextColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
195 Dialog
.applyDialogFont(page
);
201 public void init(IWorkbench workbench
) {
202 fPreferences
= SDViewPref
.getInstance();
206 protected void performApply() {
207 // Store the prefrences in the PreferenceStore
208 if (!fLifelineWidth
.isValid()) {
209 fLifelineWidth
.showErrorMessage();
213 fBackGroundColor
.store();
217 fNoExternalTime
.store();
220 fLifelineWidth
.store();
222 // then save them in the preference file
223 fPreferences
.apply();
228 public boolean performOk() {
234 protected void performDefaults() {
236 fTooltip
.loadDefault();
237 fNoExternalTime
.loadDefault();
238 fUseGrad
.loadDefault();
239 fLifelineWidth
.loadDefault();
241 // and all the fonts and colors
242 // fonts and colors are stored for each time because
243 // we are using only one FontFieldEditor
244 Set
<String
> keySet
= SDViewPref
.getInstance().getFontPref().keySet();
245 Iterator
<String
> it
= keySet
.iterator();
246 while (it
.hasNext()) {
247 Object prefName
= it
.next();
248 if (prefName
instanceof String
) {
249 fFont
.setPreferenceName((String
) prefName
);
251 fFont
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
256 keySet
= SDViewPref
.getInstance().getBackColorPref().keySet();
257 it
= keySet
.iterator();
258 while (it
.hasNext()) {
259 Object prefName
= it
.next();
260 if (prefName
instanceof String
) {
261 fBackGroundColor
.setPreferenceName((String
) prefName
);
262 fBackGroundColor
.loadDefault();
263 fBackGroundColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
264 fBackGroundColor
.store();
269 String
[] fontList
= SDViewPref
.getFontList();
270 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
271 fBackGroundColor
.load();
273 keySet
= SDViewPref
.getInstance().getForeColorPref().keySet();
274 it
= keySet
.iterator();
275 while (it
.hasNext()) {
276 Object prefName
= it
.next();
277 if (prefName
instanceof String
) {
278 fLineColor
.setPreferenceName((String
) prefName
);
279 fLineColor
.loadDefault();
280 fLineColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
285 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
288 keySet
= SDViewPref
.getInstance().getTextColorPref().keySet();
289 it
= keySet
.iterator();
290 while (it
.hasNext()) {
291 Object prefName
= it
.next();
292 if (prefName
instanceof String
) {
293 fTextColor
.setPreferenceName((String
) prefName
);
294 fTextColor
.loadDefault();
295 fTextColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
299 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
304 public void widgetSelected(SelectionEvent e
) {
305 // Store the past set font preference or else the
306 // FontFieldEditor reassignment will make us loose the current modification
309 fBackGroundColor
.store();
312 String
[] fontList
= SDViewPref
.getFontList();
314 // set the FontFieldEditor for the new selected graphNode font
315 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
318 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
319 fBackGroundColor
.load();
321 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
324 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
327 // No Background for message graphNodes
328 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS_RET
))
329 || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS_RET
))) {
330 fBackGroundColor
.setEnabled(false, fButtonArea
);
332 fBackGroundColor
.setEnabled(true, fButtonArea
);
335 // No font used for execution occurrence and global frame
336 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_EXEC
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
))) {
337 fTextColor
.setEnabled(false, fButtonArea
);
339 fTextColor
.setEnabled(true, fButtonArea
);
342 if (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
)) {
343 fFont
.setEnabled(false, fButtonArea
);
345 fFont
.setEnabled(true, fButtonArea
);
350 * Swap viewer preferences.
352 * @param toTemp Switch to the temporary preferences
354 protected void swapPref(boolean toTemp
) {
355 String tag1
= "";//$NON-NLS-1$
356 String tag2
= TEMP_TAG
;
359 tag2
= "";//$NON-NLS-1$
361 Set
<String
> keySet
= SDViewPref
.getInstance().getFontPref().keySet();
362 Iterator
<String
> it
= keySet
.iterator();
363 while (it
.hasNext()) {
364 Object prefName
= it
.next();
365 if (prefName
instanceof String
) {
366 fFont
.setPreferenceName((String
) prefName
+ tag1
);
368 fFont
.setPreferenceName((String
) prefName
+ tag2
);
373 keySet
= SDViewPref
.getInstance().getBackColorPref().keySet();
374 it
= keySet
.iterator();
375 while (it
.hasNext()) {
376 Object prefName
= it
.next();
377 if (prefName
instanceof String
) {
378 fBackGroundColor
.setPreferenceName((String
) prefName
+ tag1
);
379 fBackGroundColor
.load();
380 fBackGroundColor
.setPreferenceName((String
) prefName
+ tag2
);
381 fBackGroundColor
.store();
385 keySet
= SDViewPref
.getInstance().getForeColorPref().keySet();
386 it
= keySet
.iterator();
387 while (it
.hasNext()) {
388 Object prefName
= it
.next();
389 if (prefName
instanceof String
) {
390 fLineColor
.setPreferenceName((String
) prefName
+ tag1
);
392 fLineColor
.setPreferenceName((String
) prefName
+ tag2
);
397 keySet
= SDViewPref
.getInstance().getTextColorPref().keySet();
398 it
= keySet
.iterator();
399 while (it
.hasNext()) {
400 Object prefName
= it
.next();
401 if (prefName
instanceof String
) {
402 fTextColor
.setPreferenceName((String
) prefName
+ tag1
);
404 fTextColor
.setPreferenceName((String
) prefName
+ tag2
);
408 String
[] fontList
= SDViewPref
.getFontList();
410 // set the FontFieldEditor for the new selected graphNode font
411 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
414 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
415 fBackGroundColor
.load();
417 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
420 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
426 public void widgetDefaultSelected(SelectionEvent e
) {