tmf: Add missing Javadoc to tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / preferences / SDViewerPage.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2008 IBM Corporation and others.
3 * Copyright (c) 2011, 2012 Ericsson.
4 *
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
9 *
10 * Contributors:
11 * IBM - Initial API and implementation
12 * Bernd Hufmann - Updated for TMF
13 **********************************************************************/
14 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences;
15
16 import java.util.Iterator;
17 import java.util.Set;
18
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;
37
38 /**
39 * The Sequence Diagram preferences page implementation.
40 *
41 * @version 1.0
42 * @author sveyrier
43 */
44 public class SDViewerPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener {
45
46 // ------------------------------------------------------------------------
47 // Constants
48 // ------------------------------------------------------------------------
49 /**
50 * Temporary preferences tag
51 */
52 protected static final String TEMP_TAG = SDViewPref.TEMP_TAG;
53
54 // ------------------------------------------------------------------------
55 // Attributes
56 // ------------------------------------------------------------------------
57 /**
58 * The preference handler used to access the PreferenceStore
59 */
60 protected SDViewPref fPreferences = null;
61 /**
62 * BackGround color selector
63 */
64 protected ColorFieldEditor fLineColor = null;
65 /**
66 * Foreground color selector
67 */
68 protected ColorFieldEditor fBackGroundColor = null;
69 /**
70 * Font color selector
71 */
72 protected ColorFieldEditor fTextColor = null;
73 /**
74 * List which display all modifiable sequence Diagram font
75 */
76 protected List fClassItemList = null;
77 /**
78 * Font selector (The same is used for each modifiable font)
79 */
80 protected FontFieldEditor fFont = null;
81 /**
82 * Link font when zooming selector
83 */
84 protected BooleanFieldEditor fLink = null;
85 /**
86 * Enable tooltip selector
87 */
88 protected BooleanFieldEditor fTooltip = null;
89 /**
90 * Do not take external time into account in the min max computation
91 */
92 protected BooleanFieldEditor fNoExternalTime = null;
93 /**
94 * Use gradient color selector
95 */
96 protected BooleanFieldEditor fUseGrad = null;
97 /**
98 * A button area.
99 */
100 protected Composite fButtonArea;
101 /**
102 * SwimLane width selector
103 */
104 protected IntegerFieldEditor fLifelineWidth = null;
105
106 // ------------------------------------------------------------------------
107 // Methods
108 // ------------------------------------------------------------------------
109
110 /*
111 * (non-Javadoc)
112 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
113 */
114 @Override
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);
123
124 fTooltip = new BooleanFieldEditor(ISDPreferences.PREF_TOOLTIP, SDMessages._97, page);
125 fTooltip.setPreferenceStore(fPreferences.getPreferenceStore());
126 fTooltip.load();
127
128 // link font with zoom pref
129 fLink = new BooleanFieldEditor(ISDPreferences.PREF_LINK_FONT, SDMessages._82, page);
130 fLink.setPreferenceStore(fPreferences.getPreferenceStore());
131 fLink.load();
132
133 fNoExternalTime = new BooleanFieldEditor(ISDPreferences.PREF_EXCLUDE_EXTERNAL_TIME, SDMessages._83, page);
134 fNoExternalTime.setPreferenceStore(fPreferences.getPreferenceStore());
135 fNoExternalTime.load();
136
137 // use gradient color pref
138 fUseGrad = new BooleanFieldEditor(ISDPreferences.PREF_USE_GRADIENT, SDMessages._84, page);
139 fUseGrad.setPreferenceStore(fPreferences.getPreferenceStore());
140 fUseGrad.load();
141
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);
145
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);
151
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();
157
158 // not very nice
159 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
160 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
161
162 // Font list pref
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);
166
167 String[] fontList2 = SDViewPref.getFontList2();
168 for (int i = 0; i < fontList2.length; i++) {
169 fClassItemList.add(fontList2[i]);
170 }
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);
179
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());
186 fFont.load();
187
188 fBackGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, SDMessages._85, fButtonArea);
189 fBackGroundColor.setPreferenceStore(fPreferences.getPreferenceStore());
190 fBackGroundColor.load();
191
192 fLineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, SDMessages._86, fButtonArea);
193 fLineColor.setPreferenceStore(fPreferences.getPreferenceStore());
194 fLineColor.load();
195
196 fTextColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, SDMessages._87, fButtonArea);
197 fTextColor.setPreferenceStore(fPreferences.getPreferenceStore());
198 fTextColor.load();
199 swapPref(true);
200 Dialog.applyDialogFont(page);
201
202 return page;
203 }
204
205 /*
206 * (non-Javadoc)
207 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
208 */
209 @Override
210 public void init(IWorkbench workbench) {
211 fPreferences = SDViewPref.getInstance();
212 }
213
214 /*
215 * (non-Javadoc)
216 * @see org.eclipse.jface.preference.PreferencePage#performApply()
217 */
218 @Override
219 protected void performApply() {
220 // Store the prefrences in the PreferenceStore
221 if (!fLifelineWidth.isValid()) {
222 fLifelineWidth.showErrorMessage();
223 return;
224 }
225 fFont.store();
226 fBackGroundColor.store();
227 fLineColor.store();
228 fLink.store();
229 fTooltip.store();
230 fNoExternalTime.store();
231 fTextColor.store();
232 fUseGrad.store();
233 fLifelineWidth.store();
234 swapPref(false);
235 // then save them in the preference file
236 fPreferences.apply();
237 swapPref(true);
238 }
239
240 /*
241 * (non-Javadoc)
242 * @see org.eclipse.jface.preference.PreferencePage#performOk()
243 */
244 @Override
245 public boolean performOk() {
246 performApply();
247 return true;
248 }
249
250 /*
251 * (non-Javadoc)
252 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
253 */
254 @Override
255 protected void performDefaults() {
256 fLink.loadDefault();
257 fTooltip.loadDefault();
258 fNoExternalTime.loadDefault();
259 fUseGrad.loadDefault();
260 fLifelineWidth.loadDefault();
261
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);
271 fFont.loadDefault();
272 fFont.setPreferenceName((String) prefName + TEMP_TAG);
273 fFont.store();
274 }
275 }
276
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();
286 }
287
288 }
289
290 String[] fontList = SDViewPref.getFontList();
291 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
292 fBackGroundColor.load();
293
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);
302 fLineColor.store();
303 }
304 }
305
306 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
307 fLineColor.load();
308
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);
317 fTextColor.store();
318 }
319 }
320 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
321 fTextColor.load();
322 }
323
324 /*
325 * (non-Javadoc)
326 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
327 */
328 @Override
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
332 fFont.store();
333 fLineColor.store();
334 fBackGroundColor.store();
335 fTextColor.store();
336
337 String[] fontList = SDViewPref.getFontList();
338
339 // set the FontFieldEditor for the new selected graphNode font
340 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
341 fFont.load();
342
343 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
344 fBackGroundColor.load();
345
346 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
347 fLineColor.load();
348
349 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
350 fTextColor.load();
351
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);
356 } else {
357 fBackGroundColor.setEnabled(true, fButtonArea);
358 }
359
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);
363 } else {
364 fTextColor.setEnabled(true, fButtonArea);
365 }
366
367 if (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME)) {
368 fFont.setEnabled(false, fButtonArea);
369 } else {
370 fFont.setEnabled(true, fButtonArea);
371 }
372 }
373
374 /**
375 * Swap viewer preferences.
376 *
377 * @param toTemp Switch to the temporary preferences
378 */
379 protected void swapPref(boolean toTemp) {
380 String TAG1 = "";//$NON-NLS-1$
381 String TAG2 = TEMP_TAG;
382 if (!toTemp) {
383 TAG1 = TEMP_TAG;
384 TAG2 = "";//$NON-NLS-1$
385 }
386 Set<String> keySet = SDViewPref.getInstance().fFontPref.keySet();
387 Iterator<String> it = keySet.iterator();
388 while (it.hasNext()) {
389 Object prefName = it.next();
390 if (prefName instanceof String) {
391 fFont.setPreferenceName((String) prefName + TAG1);
392 fFont.load();
393 fFont.setPreferenceName((String) prefName + TAG2);
394 fFont.store();
395 }
396 }
397
398 keySet = SDViewPref.getInstance().fBackColorPref.keySet();
399 it = keySet.iterator();
400 while (it.hasNext()) {
401 Object prefName = it.next();
402 if (prefName instanceof String) {
403 fBackGroundColor.setPreferenceName((String) prefName + TAG1);
404 fBackGroundColor.load();
405 fBackGroundColor.setPreferenceName((String) prefName + TAG2);
406 fBackGroundColor.store();
407 }
408 }
409
410 keySet = SDViewPref.getInstance().fForeColorPref.keySet();
411 it = keySet.iterator();
412 while (it.hasNext()) {
413 Object prefName = it.next();
414 if (prefName instanceof String) {
415 fLineColor.setPreferenceName((String) prefName + TAG1);
416 fLineColor.load();
417 fLineColor.setPreferenceName((String) prefName + TAG2);
418 fLineColor.store();
419 }
420 }
421
422 keySet = SDViewPref.getInstance().fTextColorPref.keySet();
423 it = keySet.iterator();
424 while (it.hasNext()) {
425 Object prefName = it.next();
426 if (prefName instanceof String) {
427 fTextColor.setPreferenceName((String) prefName + TAG1);
428 fTextColor.load();
429 fTextColor.setPreferenceName((String) prefName + TAG2);
430 fTextColor.store();
431 }
432 }
433 String[] fontList = SDViewPref.getFontList();
434 if (toTemp) {
435 // set the FontFieldEditor for the new selected graphNode font
436 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
437 fFont.load();
438
439 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
440 fBackGroundColor.load();
441
442 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
443 fLineColor.load();
444
445 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
446 fTextColor.load();
447 }
448 }
449
450 /*
451 * (non-Javadoc)
452 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
453 */
454 @Override
455 public void widgetDefaultSelected(SelectionEvent e) {
456 }
457 }
This page took 0.041422 seconds and 6 git commands to generate.