1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.preferences
;
16 import java
.util
.Iterator
;
19 import org
.eclipse
.jface
.dialogs
.Dialog
;
20 import org
.eclipse
.jface
.preference
.BooleanFieldEditor
;
21 import org
.eclipse
.jface
.preference
.ColorFieldEditor
;
22 import org
.eclipse
.jface
.preference
.FontFieldEditor
;
23 import org
.eclipse
.jface
.preference
.IntegerFieldEditor
;
24 import org
.eclipse
.jface
.preference
.PreferencePage
;
25 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.util
.SDMessages
;
26 import org
.eclipse
.swt
.SWT
;
27 import org
.eclipse
.swt
.events
.SelectionEvent
;
28 import org
.eclipse
.swt
.events
.SelectionListener
;
29 import org
.eclipse
.swt
.layout
.GridData
;
30 import org
.eclipse
.swt
.layout
.GridLayout
;
31 import org
.eclipse
.swt
.widgets
.Composite
;
32 import org
.eclipse
.swt
.widgets
.Control
;
33 import org
.eclipse
.swt
.widgets
.Label
;
34 import org
.eclipse
.swt
.widgets
.List
;
35 import org
.eclipse
.ui
.IWorkbench
;
36 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
39 * The Sequence Diagram preferences page implementation.
44 public class SDViewerPage
extends PreferencePage
implements IWorkbenchPreferencePage
, SelectionListener
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * Temporary preferences tag
52 protected static final String TEMP_TAG
= SDViewPref
.TEMP_TAG
;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
58 * The preference handler used to access the PreferenceStore
60 protected SDViewPref fPreferences
= null;
62 * BackGround color selector
64 protected ColorFieldEditor fLineColor
= null;
66 * Foreground color selector
68 protected ColorFieldEditor fBackGroundColor
= null;
72 protected ColorFieldEditor fTextColor
= null;
74 * List which display all modifiable sequence Diagram font
76 protected List fClassItemList
= null;
78 * Font selector (The same is used for each modifiable font)
80 protected FontFieldEditor fFont
= null;
82 * Link font when zooming selector
84 protected BooleanFieldEditor fLink
= null;
86 * Enable tooltip selector
88 protected BooleanFieldEditor fTooltip
= null;
90 * Do not take external time into account in the min max computation
92 protected BooleanFieldEditor fNoExternalTime
= null;
94 * Use gradient color selector
96 protected BooleanFieldEditor fUseGrad
= null;
100 protected Composite fButtonArea
;
102 * SwimLane width selector
104 protected IntegerFieldEditor fLifelineWidth
= null;
106 // ------------------------------------------------------------------------
108 // ------------------------------------------------------------------------
112 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
115 protected Control
createContents(Composite parent
) {
116 parent
.setLayout(new GridLayout());
117 Composite page
= new Composite(parent
, SWT
.NONE
);
118 GridLayout pageLayout
= new GridLayout();
119 pageLayout
.numColumns
= 2;
120 GridData pageLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
121 page
.setLayoutData(pageLayoutdata
);
122 page
.setLayout(pageLayout
);
124 fTooltip
= new BooleanFieldEditor(ISDPreferences
.PREF_TOOLTIP
, SDMessages
._97
, page
);
125 fTooltip
.setPreferenceStore(fPreferences
.getPreferenceStore());
128 // link font with zoom pref
129 fLink
= new BooleanFieldEditor(ISDPreferences
.PREF_LINK_FONT
, SDMessages
._82
, page
);
130 fLink
.setPreferenceStore(fPreferences
.getPreferenceStore());
133 fNoExternalTime
= new BooleanFieldEditor(ISDPreferences
.PREF_EXCLUDE_EXTERNAL_TIME
, SDMessages
._83
, page
);
134 fNoExternalTime
.setPreferenceStore(fPreferences
.getPreferenceStore());
135 fNoExternalTime
.load();
137 // use gradient color pref
138 fUseGrad
= new BooleanFieldEditor(ISDPreferences
.PREF_USE_GRADIENT
, SDMessages
._84
, page
);
139 fUseGrad
.setPreferenceStore(fPreferences
.getPreferenceStore());
142 Label separator
= new Label(page
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
143 GridData sepData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
144 separator
.setLayoutData(sepData
);
146 Composite prefPage
= new Composite(page
, SWT
.NONE
);
147 GridLayout prefPageLayout
= new GridLayout();
148 prefPage
.setLayoutData(pageLayoutdata
);
149 prefPageLayout
.numColumns
= 1;
150 prefPage
.setLayout(prefPageLayout
);
152 // swimLane width pref
153 fLifelineWidth
= new IntegerFieldEditor(ISDPreferences
.PREF_LIFELINE_WIDTH
, SDMessages
._80
, prefPage
);
154 fLifelineWidth
.setPreferenceStore(fPreferences
.getPreferenceStore());
155 fLifelineWidth
.setValidRange(119, 500);
156 fLifelineWidth
.load();
159 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
160 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
163 fClassItemList
= new List(prefPage
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
);
164 GridData tabItemLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
165 fClassItemList
.setLayoutData(tabItemLayoutdata
);
167 String
[] fontList2
= SDViewPref
.getFontList2();
168 for (int i
= 0; i
< fontList2
.length
; i
++) {
169 fClassItemList
.add(fontList2
[i
]);
171 fClassItemList
.setSelection(0);
172 fClassItemList
.addSelectionListener(this);
173 fButtonArea
= new Composite(prefPage
, SWT
.NONE
);
174 GridData tabItemLayoutdata2
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
/* |GridData.GRAB_HORIZONTAL */| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
175 fButtonArea
.setLayoutData(tabItemLayoutdata2
);
176 GridLayout buttonAreaLayout
= new GridLayout();
177 buttonAreaLayout
.numColumns
= 1;
178 fButtonArea
.setLayout(buttonAreaLayout
);
180 // font selector initialise for the lifeline font pref
181 String
[] fontList
= SDViewPref
.getFontList();
182 fFont
= new FontFieldEditor(fontList
[0], "",//$NON-NLS-1$
183 SDMessages
._81
, fButtonArea
);
184 fFont
.getPreviewControl().setSize(500, 500);
185 fFont
.setPreferenceStore(fPreferences
.getPreferenceStore());
188 fBackGroundColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.BACK_COLOR_POSTFIX
, SDMessages
._85
, fButtonArea
);
189 fBackGroundColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
190 fBackGroundColor
.load();
192 fLineColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.FORE_COLOR_POSTFIX
, SDMessages
._86
, fButtonArea
);
193 fLineColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
196 fTextColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.TEXT_COLOR_POSTFIX
, SDMessages
._87
, fButtonArea
);
197 fTextColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
200 Dialog
.applyDialogFont(page
);
207 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
210 public void init(IWorkbench workbench
) {
211 fPreferences
= SDViewPref
.getInstance();
216 * @see org.eclipse.jface.preference.PreferencePage#performApply()
219 protected void performApply() {
220 // Store the prefrences in the PreferenceStore
221 if (!fLifelineWidth
.isValid()) {
222 fLifelineWidth
.showErrorMessage();
226 fBackGroundColor
.store();
230 fNoExternalTime
.store();
233 fLifelineWidth
.store();
235 // then save them in the preference file
236 fPreferences
.apply();
242 * @see org.eclipse.jface.preference.PreferencePage#performOk()
245 public boolean performOk() {
252 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
255 protected void performDefaults() {
257 fTooltip
.loadDefault();
258 fNoExternalTime
.loadDefault();
259 fUseGrad
.loadDefault();
260 fLifelineWidth
.loadDefault();
262 // and all the fonts and colors
263 // fonts and colors are stored for each time because
264 // we are using only one FontFieldEditor
265 Set
<String
> keySet
= SDViewPref
.getInstance().fFontPref
.keySet();
266 Iterator
<String
> it
= keySet
.iterator();
267 while (it
.hasNext()) {
268 Object prefName
= it
.next();
269 if (prefName
instanceof String
) {
270 fFont
.setPreferenceName((String
) prefName
);
272 fFont
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
277 keySet
= SDViewPref
.getInstance().fBackColorPref
.keySet();
278 it
= keySet
.iterator();
279 while (it
.hasNext()) {
280 Object prefName
= it
.next();
281 if (prefName
instanceof String
) {
282 fBackGroundColor
.setPreferenceName((String
) prefName
);
283 fBackGroundColor
.loadDefault();
284 fBackGroundColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
285 fBackGroundColor
.store();
290 String
[] fontList
= SDViewPref
.getFontList();
291 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
292 fBackGroundColor
.load();
294 keySet
= SDViewPref
.getInstance().fForeColorPref
.keySet();
295 it
= keySet
.iterator();
296 while (it
.hasNext()) {
297 Object prefName
= it
.next();
298 if (prefName
instanceof String
) {
299 fLineColor
.setPreferenceName((String
) prefName
);
300 fLineColor
.loadDefault();
301 fLineColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
306 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
309 keySet
= SDViewPref
.getInstance().fTextColorPref
.keySet();
310 it
= keySet
.iterator();
311 while (it
.hasNext()) {
312 Object prefName
= it
.next();
313 if (prefName
instanceof String
) {
314 fTextColor
.setPreferenceName((String
) prefName
);
315 fTextColor
.loadDefault();
316 fTextColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
320 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
326 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
329 public void widgetSelected(SelectionEvent e
) {
330 // Store the past set font preference or else the
331 // FontFieldEditor reassignment will make us loose the current modification
334 fBackGroundColor
.store();
337 String
[] fontList
= SDViewPref
.getFontList();
339 // set the FontFieldEditor for the new selected graphNode font
340 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
343 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
344 fBackGroundColor
.load();
346 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
349 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
352 // No Background for message graphNodes
353 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS_RET
))
354 || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS_RET
))) {
355 fBackGroundColor
.setEnabled(false, fButtonArea
);
357 fBackGroundColor
.setEnabled(true, fButtonArea
);
360 // No font used for execution occurrence and global frame
361 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_EXEC
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
))) {
362 fTextColor
.setEnabled(false, fButtonArea
);
364 fTextColor
.setEnabled(true, fButtonArea
);
367 if (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
)) {
368 fFont
.setEnabled(false, fButtonArea
);
370 fFont
.setEnabled(true, fButtonArea
);
374 protected void swapPref(boolean toTemp
) {
375 String TAG1
= "";//$NON-NLS-1$
376 String TAG2
= TEMP_TAG
;
379 TAG2
= "";//$NON-NLS-1$
381 Set
<String
> keySet
= SDViewPref
.getInstance().fFontPref
.keySet();
382 Iterator
<String
> it
= keySet
.iterator();
383 while (it
.hasNext()) {
384 Object prefName
= it
.next();
385 if (prefName
instanceof String
) {
386 fFont
.setPreferenceName((String
) prefName
+ TAG1
);
388 fFont
.setPreferenceName((String
) prefName
+ TAG2
);
393 keySet
= SDViewPref
.getInstance().fBackColorPref
.keySet();
394 it
= keySet
.iterator();
395 while (it
.hasNext()) {
396 Object prefName
= it
.next();
397 if (prefName
instanceof String
) {
398 fBackGroundColor
.setPreferenceName((String
) prefName
+ TAG1
);
399 fBackGroundColor
.load();
400 fBackGroundColor
.setPreferenceName((String
) prefName
+ TAG2
);
401 fBackGroundColor
.store();
405 keySet
= SDViewPref
.getInstance().fForeColorPref
.keySet();
406 it
= keySet
.iterator();
407 while (it
.hasNext()) {
408 Object prefName
= it
.next();
409 if (prefName
instanceof String
) {
410 fLineColor
.setPreferenceName((String
) prefName
+ TAG1
);
412 fLineColor
.setPreferenceName((String
) prefName
+ TAG2
);
417 keySet
= SDViewPref
.getInstance().fTextColorPref
.keySet();
418 it
= keySet
.iterator();
419 while (it
.hasNext()) {
420 Object prefName
= it
.next();
421 if (prefName
instanceof String
) {
422 fTextColor
.setPreferenceName((String
) prefName
+ TAG1
);
424 fTextColor
.setPreferenceName((String
) prefName
+ TAG2
);
428 String
[] fontList
= SDViewPref
.getFontList();
430 // set the FontFieldEditor for the new selected graphNode font
431 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
434 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
435 fBackGroundColor
.load();
437 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
440 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
447 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
450 public void widgetDefaultSelected(SelectionEvent e
) {