1 /**********************************************************************
2 * Copyright (c) 2005, 2008, 2011 IBM Corporation and others.
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
7 * $Id: SDViewerPage.java,v 1.5 2008/01/24 02:28:51 apnan Exp $
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
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
42 public class SDViewerPage
extends PreferencePage
implements IWorkbenchPreferencePage
, SelectionListener
{
45 * The preference handler used to access the PreferenceStore
47 protected SDViewPref pref
= null;
49 * BackGround color selector
51 protected ColorFieldEditor lineColor
= null;
53 * Foreground color selector
55 protected ColorFieldEditor backGroundColor
= null;
60 protected ColorFieldEditor textColor
= null;
63 * List which display all modifiable sequence Diagram font
65 protected List classItemList
= null;
68 * Font selector (The same is used for each modifiable font)
70 protected FontFieldEditor font
= null;
73 * Link font when zooming selector
75 protected BooleanFieldEditor link
= null;
78 * Enable tooltip selector
80 protected BooleanFieldEditor tooltip
= null;
83 * Do not take external time into account in the min max computation
85 protected BooleanFieldEditor noExternalTime
= null;
88 * Use gradient color selector
90 protected BooleanFieldEditor useGrad
= null;
92 protected Composite buttonArea
;
95 * SwimLane width selector
97 protected IntegerFieldEditor lifelineWidth
= null;
99 protected static final String TEMP_TAG
= SDViewPref
.TEMP_TAG
;
101 public SDViewerPage() {
106 * Creates the Sequence Diagram preference page content
108 * @param parent the parent composite
111 protected Control
createContents(Composite parent
) {
112 parent
.setLayout(new GridLayout());
113 Composite page
= new Composite(parent
, SWT
.NONE
);
114 GridLayout pageLayout
= new GridLayout();
115 pageLayout
.numColumns
= 2;
116 GridData pageLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
117 page
.setLayoutData(pageLayoutdata
);
118 page
.setLayout(pageLayout
);
120 tooltip
= new BooleanFieldEditor(SDViewPref
.PREF_TOOLTIP
, SDMessages
._97
, page
);
121 tooltip
.setPreferenceStore(pref
.getPreferenceStore());
124 // link font with zoom pref
125 link
= new BooleanFieldEditor(SDViewPref
.PREF_LINK_FONT
, SDMessages
._82
, page
);
126 link
.setPreferenceStore(pref
.getPreferenceStore());
129 noExternalTime
= new BooleanFieldEditor(SDViewPref
.PREF_EXCLUDE_EXTERNAL_TIME
, SDMessages
._83
, page
);
130 noExternalTime
.setPreferenceStore(pref
.getPreferenceStore());
131 noExternalTime
.load();
133 // use gradient color pref
134 useGrad
= new BooleanFieldEditor(SDViewPref
.PREF_USE_GRADIENT
, SDMessages
._84
, page
);
135 useGrad
.setPreferenceStore(pref
.getPreferenceStore());
138 Label separator
= new Label(page
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
139 GridData sepData
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_HORIZONTAL
| GridData
.VERTICAL_ALIGN_FILL
);
140 separator
.setLayoutData(sepData
);
142 Composite prefPage
= new Composite(page
, SWT
.NONE
);
143 GridLayout prefPageLayout
= new GridLayout();
144 prefPage
.setLayoutData(pageLayoutdata
);
145 prefPageLayout
.numColumns
= 1;
146 prefPage
.setLayout(prefPageLayout
);
148 // swimLane width pref
149 lifelineWidth
= new IntegerFieldEditor(SDViewPref
.PREF_LIFELINE_WIDTH
, SDMessages
._80
, prefPage
);
150 lifelineWidth
.setPreferenceStore(pref
.getPreferenceStore());
151 lifelineWidth
.setValidRange(119, 500);
152 lifelineWidth
.load();
155 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
156 new Label(prefPage
, SWT
.SEPARATOR
| SWT
.HORIZONTAL
| SWT
.SHADOW_NONE
);
159 classItemList
= new List(prefPage
, SWT
.SINGLE
| SWT
.H_SCROLL
| SWT
.V_SCROLL
| SWT
.BORDER
);
160 GridData tabItemLayoutdata
= new GridData(GridData
.GRAB_HORIZONTAL
| GridData
.HORIZONTAL_ALIGN_FILL
| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
161 classItemList
.setLayoutData(tabItemLayoutdata
);
163 String
[] fontList2
= SDViewPref
.getFontList2();
164 for (int i
= 0; i
< fontList2
.length
; i
++) {
165 classItemList
.add(fontList2
[i
]);
167 classItemList
.setSelection(0);
168 classItemList
.addSelectionListener(this);
169 buttonArea
= new Composite(prefPage
, SWT
.NONE
);
170 GridData tabItemLayoutdata2
= new GridData(GridData
.HORIZONTAL_ALIGN_FILL
/* |GridData.GRAB_HORIZONTAL */| GridData
.GRAB_VERTICAL
| GridData
.VERTICAL_ALIGN_FILL
);
171 buttonArea
.setLayoutData(tabItemLayoutdata2
);
172 GridLayout buttonAreaLayout
= new GridLayout();
173 buttonAreaLayout
.numColumns
= 1;
174 buttonArea
.setLayout(buttonAreaLayout
);
176 // font selector initialise for the lifeline font pref
177 String
[] fontList
= SDViewPref
.getFontList();
178 font
= new FontFieldEditor(fontList
[0], "",//$NON-NLS-1$
179 SDMessages
._81
, buttonArea
);
180 font
.getPreviewControl().setSize(500, 500);
181 font
.setPreferenceStore(pref
.getPreferenceStore());
184 backGroundColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.BACK_COLOR_POSTFIX
, SDMessages
._85
, buttonArea
);
185 backGroundColor
.setPreferenceStore(pref
.getPreferenceStore());
186 backGroundColor
.load();
188 lineColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.FORE_COLOR_POSTFIX
, SDMessages
._86
, buttonArea
);
189 lineColor
.setPreferenceStore(pref
.getPreferenceStore());
192 textColor
= new ColorFieldEditor(fontList
[0] + SDViewPref
.TEXT_COLOR_POSTFIX
, SDMessages
._87
, buttonArea
);
193 textColor
.setPreferenceStore(pref
.getPreferenceStore());
196 Dialog
.applyDialogFont(page
);
202 public void init(IWorkbench workbench
) {
203 pref
= SDViewPref
.getInstance();
207 * Apply the modification performed in the Sequence diagram preference page
210 protected void performApply() {
211 // Store the prefrences in the PreferenceStore
212 if (!lifelineWidth
.isValid()) {
213 lifelineWidth
.showErrorMessage();
217 backGroundColor
.store();
221 noExternalTime
.store();
224 lifelineWidth
.store();
226 // then save them in the preference file
232 * Apply the modification performed in the Sequence diagram preference page
237 public boolean performOk() {
243 * Loads the Sequence diagram default preference settings
246 protected void performDefaults() {
248 tooltip
.loadDefault();
249 noExternalTime
.loadDefault();
250 useGrad
.loadDefault();
251 lifelineWidth
.loadDefault();
253 // and all the fonts and colors
254 // fonts and colors are stored for each time because
255 // we are using only one FontFieldEditor
256 Set
<String
> keySet
= SDViewPref
.getInstance().fontPref
.keySet();
257 Iterator
<String
> it
= keySet
.iterator();
258 while (it
.hasNext()) {
259 Object prefName
= it
.next();
260 if (prefName
instanceof String
) {
261 font
.setPreferenceName((String
) prefName
);
263 font
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
268 keySet
= SDViewPref
.getInstance().backColorPref
.keySet();
269 it
= keySet
.iterator();
270 while (it
.hasNext()) {
271 Object prefName
= it
.next();
272 if (prefName
instanceof String
) {
273 backGroundColor
.setPreferenceName((String
) prefName
);
274 backGroundColor
.loadDefault();
275 backGroundColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
276 backGroundColor
.store();
281 String
[] fontList
= SDViewPref
.getFontList();
282 backGroundColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
283 backGroundColor
.load();
285 keySet
= SDViewPref
.getInstance().foreColorPref
.keySet();
286 it
= keySet
.iterator();
287 while (it
.hasNext()) {
288 Object prefName
= it
.next();
289 if (prefName
instanceof String
) {
290 lineColor
.setPreferenceName((String
) prefName
);
291 lineColor
.loadDefault();
292 lineColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
297 lineColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
300 keySet
= SDViewPref
.getInstance().textColorPref
.keySet();
301 it
= keySet
.iterator();
302 while (it
.hasNext()) {
303 Object prefName
= it
.next();
304 if (prefName
instanceof String
) {
305 textColor
.setPreferenceName((String
) prefName
);
306 textColor
.loadDefault();
307 textColor
.setPreferenceName((String
) prefName
+ TEMP_TAG
);
311 textColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
316 * Sent when a new selection occurs in the graphNode font list
318 * @param e the selection event
321 public void widgetSelected(SelectionEvent e
) {
322 // Store the past set font preference or else the
323 // FontFieldEditor reassignment will make us loose the current modification
326 backGroundColor
.store();
329 String
[] fontList
= SDViewPref
.getFontList();
331 // set the FontFieldEditor for the new selected graphNode font
332 font
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + TEMP_TAG
);
335 backGroundColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
336 backGroundColor
.load();
338 lineColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
341 textColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
344 // No Background for message graphNodes
345 if ((fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_SYNC_MESS
)) || (fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_SYNC_MESS_RET
))
346 || (fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_ASYNC_MESS
)) || (fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_ASYNC_MESS_RET
)))
347 backGroundColor
.setEnabled(false, buttonArea
);
349 backGroundColor
.setEnabled(true, buttonArea
);
351 // No font used for execution occurrence and global frame
352 if ((fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_EXEC
)) || (fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_FRAME
)))
353 textColor
.setEnabled(false, buttonArea
);
355 textColor
.setEnabled(true, buttonArea
);
357 if (fontList
[classItemList
.getSelectionIndex()].equals(SDViewPref
.PREF_FRAME
))
358 font
.setEnabled(false, buttonArea
);
360 font
.setEnabled(true, buttonArea
);
363 protected void swapPref(boolean toTemp
) {
364 String TAG1
= "";//$NON-NLS-1$
365 String TAG2
= TEMP_TAG
;
368 TAG2
= "";//$NON-NLS-1$
370 Set
<String
> keySet
= SDViewPref
.getInstance().fontPref
.keySet();
371 Iterator
<String
> it
= keySet
.iterator();
372 while (it
.hasNext()) {
373 Object prefName
= it
.next();
374 if (prefName
instanceof String
) {
375 font
.setPreferenceName((String
) prefName
+ TAG1
);
377 font
.setPreferenceName((String
) prefName
+ TAG2
);
382 keySet
= SDViewPref
.getInstance().backColorPref
.keySet();
383 it
= keySet
.iterator();
384 while (it
.hasNext()) {
385 Object prefName
= it
.next();
386 if (prefName
instanceof String
) {
387 backGroundColor
.setPreferenceName((String
) prefName
+ TAG1
);
388 backGroundColor
.load();
389 backGroundColor
.setPreferenceName((String
) prefName
+ TAG2
);
390 backGroundColor
.store();
395 keySet
= SDViewPref
.getInstance().foreColorPref
.keySet();
396 it
= keySet
.iterator();
397 while (it
.hasNext()) {
398 Object prefName
= it
.next();
399 if (prefName
instanceof String
) {
400 lineColor
.setPreferenceName((String
) prefName
+ TAG1
);
402 lineColor
.setPreferenceName((String
) prefName
+ TAG2
);
407 keySet
= SDViewPref
.getInstance().textColorPref
.keySet();
408 it
= keySet
.iterator();
409 while (it
.hasNext()) {
410 Object prefName
= it
.next();
411 if (prefName
instanceof String
) {
412 textColor
.setPreferenceName((String
) prefName
+ TAG1
);
414 textColor
.setPreferenceName((String
) prefName
+ TAG2
);
418 String
[] fontList
= SDViewPref
.getFontList();
420 // set the FontFieldEditor for the new selected graphNode font
421 font
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + TEMP_TAG
);
424 backGroundColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.BACK_COLOR_POSTFIX
+ TEMP_TAG
);
425 backGroundColor
.load();
427 lineColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.FORE_COLOR_POSTFIX
+ TEMP_TAG
);
430 textColor
.setPreferenceName(fontList
[classItemList
.getSelectionIndex()] + SDViewPref
.TEXT_COLOR_POSTFIX
+ TEMP_TAG
);
436 public void widgetDefaultSelected(SelectionEvent e
) {