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
.SDMessages
;
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 protected static final String TEMP_TAG
= SDViewPref
.TEMP_TAG
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * The preference handler used to access the PreferenceStore
59 protected SDViewPref fPreferences
= null;
61 * BackGround color selector
63 protected ColorFieldEditor fLineColor
= null;
65 * Foreground color selector
67 protected ColorFieldEditor fBackGroundColor
= null;
71 protected ColorFieldEditor fTextColor
= null;
73 * List which display all modifiable sequence Diagram font
75 protected List fClassItemList
= null;
77 * Font selector (The same is used for each modifiable font)
79 protected FontFieldEditor fFont
= null;
81 * Link font when zooming selector
83 protected BooleanFieldEditor fLink
= null;
85 * Enable tooltip selector
87 protected BooleanFieldEditor fTooltip
= null;
89 * Do not take external time into account in the min max computation
91 protected BooleanFieldEditor fNoExternalTime
= null;
93 * Use gradient color selector
95 protected BooleanFieldEditor fUseGrad
= null;
99 protected Composite fButtonArea
;
101 * SwimLane width selector
103 protected IntegerFieldEditor fLifelineWidth
= null;
105 // ------------------------------------------------------------------------
107 // ------------------------------------------------------------------------
111 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
114 protected Control
createContents(Composite parent
) {
115 parent
.setLayout(new GridLayout());
116 Composite page
= new Composite(parent
, SWT
.NONE
);
117 GridLayout pageLayout
= new GridLayout();
118 pageLayout
.numColumns
= 2;
119 GridData pageLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
120 page
.setLayoutData(pageLayoutdata
);
121 page
.setLayout(pageLayout
);
123 fTooltip
= new BooleanFieldEditor(ISDPreferences
.PREF_TOOLTIP
, SDMessages
._97
, page
);
124 fTooltip
.setPreferenceStore(fPreferences
.getPreferenceStore());
127 // link font with zoom pref
128 fLink
= new BooleanFieldEditor(ISDPreferences
.PREF_LINK_FONT
, SDMessages
._82
, page
);
129 fLink
.setPreferenceStore(fPreferences
.getPreferenceStore());
132 fNoExternalTime
= new BooleanFieldEditor(ISDPreferences
.PREF_EXCLUDE_EXTERNAL_TIME
, SDMessages
._83
, page
);
133 fNoExternalTime
.setPreferenceStore(fPreferences
.getPreferenceStore());
134 fNoExternalTime
.load();
136 // use gradient color pref
137 fUseGrad
= new BooleanFieldEditor(ISDPreferences
.PREF_USE_GRADIENT
, SDMessages
._84
, page
);
138 fUseGrad
.setPreferenceStore(fPreferences
.getPreferenceStore());
141 Label separator
= new Label(page
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
142 GridData sepData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
143 separator
.setLayoutData(sepData
);
145 Composite prefPage
= new Composite(page
, SWT
.NONE
);
146 GridLayout prefPageLayout
= new GridLayout();
147 prefPage
.setLayoutData(pageLayoutdata
);
148 prefPageLayout
.numColumns
= 1;
149 prefPage
.setLayout(prefPageLayout
);
151 // swimLane width pref
152 fLifelineWidth
= new IntegerFieldEditor(ISDPreferences
.PREF_LIFELINE_WIDTH
, SDMessages
._80
, prefPage
);
153 fLifelineWidth
.setPreferenceStore(fPreferences
.getPreferenceStore());
154 fLifelineWidth
.setValidRange(119, 500);
155 fLifelineWidth
.load();
158 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
159 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
162 fClassItemList
= new List(prefPage
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
);
163 GridData tabItemLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
164 fClassItemList
.setLayoutData(tabItemLayoutdata
);
166 String
[] fontList2
= SDViewPref
.getFontList2();
167 for (int i
= 0; i
< fontList2
.length
; i
++) {
168 fClassItemList
.add(fontList2
[i
]);
170 fClassItemList
.setSelection(0);
171 fClassItemList
.addSelectionListener(this);
172 fButtonArea
= new Composite(prefPage
, SWT
.NONE
);
173 GridData tabItemLayoutdata2
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
/* |GridData.GRAB_HORIZONTAL */| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
174 fButtonArea
.setLayoutData(tabItemLayoutdata2
);
175 GridLayout buttonAreaLayout
= new GridLayout();
176 buttonAreaLayout
.numColumns
= 1;
177 fButtonArea
.setLayout(buttonAreaLayout
);
179 // font selector initialise for the lifeline font pref
180 String
[] fontList
= SDViewPref
.getFontList();
181 fFont
= new FontFieldEditor(fontList
[0], "",//$NON-NLS-1$
182 SDMessages
._81
, fButtonArea
);
183 fFont
.getPreviewControl().setSize(500, 500);
184 fFont
.setPreferenceStore(fPreferences
.getPreferenceStore());
187 fBackGroundColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.BACK_COLOR_POSTFIX
, SDMessages
._85
, fButtonArea
);
188 fBackGroundColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
189 fBackGroundColor
.load();
191 fLineColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.FORE_COLOR_POSTFIX
, SDMessages
._86
, fButtonArea
);
192 fLineColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
195 fTextColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.TEXT_COLOR_POSTFIX
, SDMessages
._87
, fButtonArea
);
196 fTextColor
.setPreferenceStore(fPreferences
.getPreferenceStore());
199 Dialog
.applyDialogFont(page
);
206 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
209 public void init(IWorkbench workbench
) {
210 fPreferences
= SDViewPref
.getInstance();
215 * @see org.eclipse.jface.preference.PreferencePage#performApply()
218 protected void performApply() {
219 // Store the prefrences in the PreferenceStore
220 if (!fLifelineWidth
.isValid()) {
221 fLifelineWidth
.showErrorMessage();
225 fBackGroundColor
.store();
229 fNoExternalTime
.store();
232 fLifelineWidth
.store();
234 // then save them in the preference file
235 fPreferences
.apply();
241 * @see org.eclipse.jface.preference.PreferencePage#performOk()
244 public boolean performOk() {
251 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
254 protected void performDefaults() {
256 fTooltip
.loadDefault();
257 fNoExternalTime
.loadDefault();
258 fUseGrad
.loadDefault();
259 fLifelineWidth
.loadDefault();
261 // and all the fonts and colors
262 // fonts and colors are stored for each time because
263 // we are using only one FontFieldEditor
264 Set
<String
> keySet
= SDViewPref
.getInstance().fFontPref
.keySet();
265 Iterator
<String
> it
= keySet
.iterator();
266 while (it
.hasNext()) {
267 Object prefName
= it
.next();
268 if (prefName
instanceof String
) {
269 fFont
.setPreferenceName((String
) prefName
);
271 fFont
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
276 keySet
= SDViewPref
.getInstance().fBackColorPref
.keySet();
277 it
= keySet
.iterator();
278 while (it
.hasNext()) {
279 Object prefName
= it
.next();
280 if (prefName
instanceof String
) {
281 fBackGroundColor
.setPreferenceName((String
) prefName
);
282 fBackGroundColor
.loadDefault();
283 fBackGroundColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
284 fBackGroundColor
.store();
289 String
[] fontList
= SDViewPref
.getFontList();
290 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
291 fBackGroundColor
.load();
293 keySet
= SDViewPref
.getInstance().fForeColorPref
.keySet();
294 it
= keySet
.iterator();
295 while (it
.hasNext()) {
296 Object prefName
= it
.next();
297 if (prefName
instanceof String
) {
298 fLineColor
.setPreferenceName((String
) prefName
);
299 fLineColor
.loadDefault();
300 fLineColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
305 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
308 keySet
= SDViewPref
.getInstance().fTextColorPref
.keySet();
309 it
= keySet
.iterator();
310 while (it
.hasNext()) {
311 Object prefName
= it
.next();
312 if (prefName
instanceof String
) {
313 fTextColor
.setPreferenceName((String
) prefName
);
314 fTextColor
.loadDefault();
315 fTextColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
319 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
325 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
328 public void widgetSelected(SelectionEvent e
) {
329 // Store the past set font preference or else the
330 // FontFieldEditor reassignment will make us loose the current modification
333 fBackGroundColor
.store();
336 String
[] fontList
= SDViewPref
.getFontList();
338 // set the FontFieldEditor for the new selected graphNode font
339 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
342 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
343 fBackGroundColor
.load();
345 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
348 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
351 // No Background for message graphNodes
352 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_SYNC_MESS_RET
))
353 || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_ASYNC_MESS_RET
))) {
354 fBackGroundColor
.setEnabled(false, fButtonArea
);
356 fBackGroundColor
.setEnabled(true, fButtonArea
);
359 // No font used for execution occurrence and global frame
360 if ((fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_EXEC
)) || (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
))) {
361 fTextColor
.setEnabled(false, fButtonArea
);
363 fTextColor
.setEnabled(true, fButtonArea
);
366 if (fontList
[fClassItemList
.getSelectionIndex()].equals(ISDPreferences
.PREF_FRAME
)) {
367 fFont
.setEnabled(false, fButtonArea
);
369 fFont
.setEnabled(true, fButtonArea
);
374 * Swap viewer preferences.
376 * @param toTemp Switch to the temporary preferences
378 protected void swapPref(boolean toTemp
) {
379 String TAG1
= "";//$NON-NLS-1$
380 String TAG2
= TEMP_TAG
;
383 TAG2
= "";//$NON-NLS-1$
385 Set
<String
> keySet
= SDViewPref
.getInstance().fFontPref
.keySet();
386 Iterator
<String
> it
= keySet
.iterator();
387 while (it
.hasNext()) {
388 Object prefName
= it
.next();
389 if (prefName
instanceof String
) {
390 fFont
.setPreferenceName((String
) prefName
+ TAG1
);
392 fFont
.setPreferenceName((String
) prefName
+ TAG2
);
397 keySet
= SDViewPref
.getInstance().fBackColorPref
.keySet();
398 it
= keySet
.iterator();
399 while (it
.hasNext()) {
400 Object prefName
= it
.next();
401 if (prefName
instanceof String
) {
402 fBackGroundColor
.setPreferenceName((String
) prefName
+ TAG1
);
403 fBackGroundColor
.load();
404 fBackGroundColor
.setPreferenceName((String
) prefName
+ TAG2
);
405 fBackGroundColor
.store();
409 keySet
= SDViewPref
.getInstance().fForeColorPref
.keySet();
410 it
= keySet
.iterator();
411 while (it
.hasNext()) {
412 Object prefName
= it
.next();
413 if (prefName
instanceof String
) {
414 fLineColor
.setPreferenceName((String
) prefName
+ TAG1
);
416 fLineColor
.setPreferenceName((String
) prefName
+ TAG2
);
421 keySet
= SDViewPref
.getInstance().fTextColorPref
.keySet();
422 it
= keySet
.iterator();
423 while (it
.hasNext()) {
424 Object prefName
= it
.next();
425 if (prefName
instanceof String
) {
426 fTextColor
.setPreferenceName((String
) prefName
+ TAG1
);
428 fTextColor
.setPreferenceName((String
) prefName
+ TAG2
);
432 String
[] fontList
= SDViewPref
.getFontList();
434 // set the FontFieldEditor for the new selected graphNode font
435 fFont
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + TEMP_TAG
);
438 fBackGroundColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
439 fBackGroundColor
.load();
441 fLineColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
444 fTextColor
.setPreferenceName(fontList
[fClassItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
451 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
454 public void widgetDefaultSelected(SelectionEvent e
) {