tmf: Update copyright headers in tmf.ui
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / preferences / SDViewerPage.java
CommitLineData
73005152 1/**********************************************************************
c8422608 2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
73005152
BH
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
abbdd66a
AM
7 *
8 * Contributors:
c8422608
AM
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
73005152 11 **********************************************************************/
c8422608 12
73005152
BH
13package org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences;
14
15import java.util.Iterator;
16import java.util.Set;
17
18import org.eclipse.jface.dialogs.Dialog;
19import org.eclipse.jface.preference.BooleanFieldEditor;
20import org.eclipse.jface.preference.ColorFieldEditor;
21import org.eclipse.jface.preference.FontFieldEditor;
22import org.eclipse.jface.preference.IntegerFieldEditor;
23import org.eclipse.jface.preference.PreferencePage;
24import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.SDMessages;
25import org.eclipse.swt.SWT;
26import org.eclipse.swt.events.SelectionEvent;
27import org.eclipse.swt.events.SelectionListener;
28import org.eclipse.swt.layout.GridData;
29import org.eclipse.swt.layout.GridLayout;
30import org.eclipse.swt.widgets.Composite;
31import org.eclipse.swt.widgets.Control;
32import org.eclipse.swt.widgets.Label;
33import org.eclipse.swt.widgets.List;
34import org.eclipse.ui.IWorkbench;
35import org.eclipse.ui.IWorkbenchPreferencePage;
36
37/**
df0b8ff4 38 * The Sequence Diagram preferences page implementation.
abbdd66a 39 *
df0b8ff4 40 * @version 1.0
73005152
BH
41 * @author sveyrier
42 */
43public class SDViewerPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener {
44
df0b8ff4
BH
45 // ------------------------------------------------------------------------
46 // Constants
47 // ------------------------------------------------------------------------
48 /**
49 * Temporary preferences tag
50 */
51 protected static final String TEMP_TAG = SDViewPref.TEMP_TAG;
abbdd66a 52
df0b8ff4
BH
53 // ------------------------------------------------------------------------
54 // Attributes
55 // ------------------------------------------------------------------------
73005152
BH
56 /**
57 * The preference handler used to access the PreferenceStore
58 */
eb63f5ff 59 protected SDViewPref fPreferences = null;
73005152
BH
60 /**
61 * BackGround color selector
62 */
eb63f5ff 63 protected ColorFieldEditor fLineColor = null;
73005152
BH
64 /**
65 * Foreground color selector
66 */
eb63f5ff 67 protected ColorFieldEditor fBackGroundColor = null;
73005152
BH
68 /**
69 * Font color selector
70 */
eb63f5ff 71 protected ColorFieldEditor fTextColor = null;
73005152
BH
72 /**
73 * List which display all modifiable sequence Diagram font
74 */
eb63f5ff 75 protected List fClassItemList = null;
73005152
BH
76 /**
77 * Font selector (The same is used for each modifiable font)
78 */
eb63f5ff 79 protected FontFieldEditor fFont = null;
73005152
BH
80 /**
81 * Link font when zooming selector
82 */
eb63f5ff 83 protected BooleanFieldEditor fLink = null;
73005152
BH
84 /**
85 * Enable tooltip selector
86 */
eb63f5ff 87 protected BooleanFieldEditor fTooltip = null;
73005152
BH
88 /**
89 * Do not take external time into account in the min max computation
90 */
eb63f5ff 91 protected BooleanFieldEditor fNoExternalTime = null;
73005152
BH
92 /**
93 * Use gradient color selector
94 */
eb63f5ff 95 protected BooleanFieldEditor fUseGrad = null;
df0b8ff4
BH
96 /**
97 * A button area.
98 */
eb63f5ff 99 protected Composite fButtonArea;
73005152
BH
100 /**
101 * SwimLane width selector
102 */
eb63f5ff 103 protected IntegerFieldEditor fLifelineWidth = null;
73005152 104
df0b8ff4 105 // ------------------------------------------------------------------------
df0b8ff4
BH
106 // Methods
107 // ------------------------------------------------------------------------
108
109 /*
110 * (non-Javadoc)
111 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
73005152
BH
112 */
113 @Override
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);
122
abbdd66a 123 fTooltip = new BooleanFieldEditor(ISDPreferences.PREF_TOOLTIP, SDMessages._97, page);
eb63f5ff
BH
124 fTooltip.setPreferenceStore(fPreferences.getPreferenceStore());
125 fTooltip.load();
73005152
BH
126
127 // link font with zoom pref
abbdd66a 128 fLink = new BooleanFieldEditor(ISDPreferences.PREF_LINK_FONT, SDMessages._82, page);
eb63f5ff
BH
129 fLink.setPreferenceStore(fPreferences.getPreferenceStore());
130 fLink.load();
73005152 131
abbdd66a 132 fNoExternalTime = new BooleanFieldEditor(ISDPreferences.PREF_EXCLUDE_EXTERNAL_TIME, SDMessages._83, page);
eb63f5ff
BH
133 fNoExternalTime.setPreferenceStore(fPreferences.getPreferenceStore());
134 fNoExternalTime.load();
73005152
BH
135
136 // use gradient color pref
abbdd66a 137 fUseGrad = new BooleanFieldEditor(ISDPreferences.PREF_USE_GRADIENT, SDMessages._84, page);
eb63f5ff
BH
138 fUseGrad.setPreferenceStore(fPreferences.getPreferenceStore());
139 fUseGrad.load();
73005152
BH
140
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);
144
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);
150
151 // swimLane width pref
abbdd66a 152 fLifelineWidth = new IntegerFieldEditor(ISDPreferences.PREF_LIFELINE_WIDTH, SDMessages._80, prefPage);
eb63f5ff
BH
153 fLifelineWidth.setPreferenceStore(fPreferences.getPreferenceStore());
154 fLifelineWidth.setValidRange(119, 500);
155 fLifelineWidth.load();
73005152
BH
156
157 // not very nice
158 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
159 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
160
161 // Font list pref
eb63f5ff 162 fClassItemList = new List(prefPage, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
73005152 163 GridData tabItemLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
eb63f5ff 164 fClassItemList.setLayoutData(tabItemLayoutdata);
73005152 165
e6ace8bb
BH
166 String[] fontList2 = SDViewPref.getFontList2();
167 for (int i = 0; i < fontList2.length; i++) {
eb63f5ff 168 fClassItemList.add(fontList2[i]);
73005152 169 }
eb63f5ff
BH
170 fClassItemList.setSelection(0);
171 fClassItemList.addSelectionListener(this);
172 fButtonArea = new Composite(prefPage, SWT.NONE);
73005152 173 GridData tabItemLayoutdata2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL/* |GridData.GRAB_HORIZONTAL */| GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
eb63f5ff 174 fButtonArea.setLayoutData(tabItemLayoutdata2);
73005152
BH
175 GridLayout buttonAreaLayout = new GridLayout();
176 buttonAreaLayout.numColumns = 1;
eb63f5ff 177 fButtonArea.setLayout(buttonAreaLayout);
73005152
BH
178
179 // font selector initialise for the lifeline font pref
e6ace8bb 180 String[] fontList = SDViewPref.getFontList();
eb63f5ff
BH
181 fFont = new FontFieldEditor(fontList[0], "",//$NON-NLS-1$
182 SDMessages._81, fButtonArea);
183 fFont.getPreviewControl().setSize(500, 500);
184 fFont.setPreferenceStore(fPreferences.getPreferenceStore());
185 fFont.load();
186
187 fBackGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, SDMessages._85, fButtonArea);
188 fBackGroundColor.setPreferenceStore(fPreferences.getPreferenceStore());
189 fBackGroundColor.load();
190
191 fLineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, SDMessages._86, fButtonArea);
192 fLineColor.setPreferenceStore(fPreferences.getPreferenceStore());
193 fLineColor.load();
194
195 fTextColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, SDMessages._87, fButtonArea);
196 fTextColor.setPreferenceStore(fPreferences.getPreferenceStore());
197 fTextColor.load();
73005152
BH
198 swapPref(true);
199 Dialog.applyDialogFont(page);
200
201 return page;
202 }
203
df0b8ff4
BH
204 /*
205 * (non-Javadoc)
206 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
207 */
73005152
BH
208 @Override
209 public void init(IWorkbench workbench) {
eb63f5ff 210 fPreferences = SDViewPref.getInstance();
73005152
BH
211 }
212
df0b8ff4
BH
213 /*
214 * (non-Javadoc)
215 * @see org.eclipse.jface.preference.PreferencePage#performApply()
73005152
BH
216 */
217 @Override
218 protected void performApply() {
219 // Store the prefrences in the PreferenceStore
eb63f5ff
BH
220 if (!fLifelineWidth.isValid()) {
221 fLifelineWidth.showErrorMessage();
73005152
BH
222 return;
223 }
eb63f5ff
BH
224 fFont.store();
225 fBackGroundColor.store();
226 fLineColor.store();
227 fLink.store();
228 fTooltip.store();
229 fNoExternalTime.store();
230 fTextColor.store();
231 fUseGrad.store();
232 fLifelineWidth.store();
73005152
BH
233 swapPref(false);
234 // then save them in the preference file
eb63f5ff 235 fPreferences.apply();
73005152
BH
236 swapPref(true);
237 }
238
df0b8ff4
BH
239 /*
240 * (non-Javadoc)
241 * @see org.eclipse.jface.preference.PreferencePage#performOk()
73005152
BH
242 */
243 @Override
244 public boolean performOk() {
245 performApply();
246 return true;
247 }
abbdd66a 248
df0b8ff4
BH
249 /*
250 * (non-Javadoc)
251 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
73005152
BH
252 */
253 @Override
254 protected void performDefaults() {
eb63f5ff
BH
255 fLink.loadDefault();
256 fTooltip.loadDefault();
257 fNoExternalTime.loadDefault();
258 fUseGrad.loadDefault();
259 fLifelineWidth.loadDefault();
73005152
BH
260
261 // and all the fonts and colors
262 // fonts and colors are stored for each time because
263 // we are using only one FontFieldEditor
eb63f5ff 264 Set<String> keySet = SDViewPref.getInstance().fFontPref.keySet();
73005152
BH
265 Iterator<String> it = keySet.iterator();
266 while (it.hasNext()) {
267 Object prefName = it.next();
268 if (prefName instanceof String) {
eb63f5ff
BH
269 fFont.setPreferenceName((String) prefName);
270 fFont.loadDefault();
271 fFont.setPreferenceName((String) prefName + TEMP_TAG);
272 fFont.store();
73005152
BH
273 }
274 }
275
eb63f5ff 276 keySet = SDViewPref.getInstance().fBackColorPref.keySet();
73005152
BH
277 it = keySet.iterator();
278 while (it.hasNext()) {
279 Object prefName = it.next();
280 if (prefName instanceof String) {
eb63f5ff
BH
281 fBackGroundColor.setPreferenceName((String) prefName);
282 fBackGroundColor.loadDefault();
283 fBackGroundColor.setPreferenceName((String) prefName + TEMP_TAG);
284 fBackGroundColor.store();
73005152
BH
285 }
286
287 }
288
e6ace8bb 289 String[] fontList = SDViewPref.getFontList();
eb63f5ff
BH
290 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
291 fBackGroundColor.load();
73005152 292
eb63f5ff 293 keySet = SDViewPref.getInstance().fForeColorPref.keySet();
73005152
BH
294 it = keySet.iterator();
295 while (it.hasNext()) {
296 Object prefName = it.next();
297 if (prefName instanceof String) {
eb63f5ff
BH
298 fLineColor.setPreferenceName((String) prefName);
299 fLineColor.loadDefault();
300 fLineColor.setPreferenceName((String) prefName + TEMP_TAG);
301 fLineColor.store();
73005152
BH
302 }
303 }
304
eb63f5ff
BH
305 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
306 fLineColor.load();
73005152 307
eb63f5ff 308 keySet = SDViewPref.getInstance().fTextColorPref.keySet();
73005152
BH
309 it = keySet.iterator();
310 while (it.hasNext()) {
311 Object prefName = it.next();
312 if (prefName instanceof String) {
eb63f5ff
BH
313 fTextColor.setPreferenceName((String) prefName);
314 fTextColor.loadDefault();
315 fTextColor.setPreferenceName((String) prefName + TEMP_TAG);
316 fTextColor.store();
73005152
BH
317 }
318 }
eb63f5ff
BH
319 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
320 fTextColor.load();
73005152
BH
321 }
322
df0b8ff4
BH
323 /*
324 * (non-Javadoc)
325 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
73005152
BH
326 */
327 @Override
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
eb63f5ff
BH
331 fFont.store();
332 fLineColor.store();
333 fBackGroundColor.store();
334 fTextColor.store();
73005152 335
e6ace8bb 336 String[] fontList = SDViewPref.getFontList();
abbdd66a 337
73005152 338 // set the FontFieldEditor for the new selected graphNode font
eb63f5ff
BH
339 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
340 fFont.load();
73005152 341
eb63f5ff
BH
342 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
343 fBackGroundColor.load();
73005152 344
eb63f5ff
BH
345 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
346 fLineColor.load();
73005152 347
eb63f5ff
BH
348 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
349 fTextColor.load();
73005152
BH
350
351 // No Background for message graphNodes
abbdd66a
AM
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))) {
eb63f5ff 354 fBackGroundColor.setEnabled(false, fButtonArea);
df0b8ff4 355 } else {
eb63f5ff 356 fBackGroundColor.setEnabled(true, fButtonArea);
df0b8ff4 357 }
73005152
BH
358
359 // No font used for execution occurrence and global frame
abbdd66a 360 if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_EXEC)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME))) {
eb63f5ff 361 fTextColor.setEnabled(false, fButtonArea);
df0b8ff4 362 } else {
eb63f5ff 363 fTextColor.setEnabled(true, fButtonArea);
df0b8ff4 364 }
73005152 365
abbdd66a 366 if (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME)) {
eb63f5ff 367 fFont.setEnabled(false, fButtonArea);
df0b8ff4 368 } else {
eb63f5ff 369 fFont.setEnabled(true, fButtonArea);
df0b8ff4 370 }
73005152
BH
371 }
372
a0a88f65
AM
373 /**
374 * Swap viewer preferences.
375 *
376 * @param toTemp Switch to the temporary preferences
377 */
73005152
BH
378 protected void swapPref(boolean toTemp) {
379 String TAG1 = "";//$NON-NLS-1$
380 String TAG2 = TEMP_TAG;
381 if (!toTemp) {
382 TAG1 = TEMP_TAG;
383 TAG2 = "";//$NON-NLS-1$
384 }
eb63f5ff 385 Set<String> keySet = SDViewPref.getInstance().fFontPref.keySet();
73005152
BH
386 Iterator<String> it = keySet.iterator();
387 while (it.hasNext()) {
388 Object prefName = it.next();
389 if (prefName instanceof String) {
eb63f5ff
BH
390 fFont.setPreferenceName((String) prefName + TAG1);
391 fFont.load();
392 fFont.setPreferenceName((String) prefName + TAG2);
393 fFont.store();
73005152
BH
394 }
395 }
396
eb63f5ff 397 keySet = SDViewPref.getInstance().fBackColorPref.keySet();
73005152
BH
398 it = keySet.iterator();
399 while (it.hasNext()) {
400 Object prefName = it.next();
401 if (prefName instanceof String) {
eb63f5ff
BH
402 fBackGroundColor.setPreferenceName((String) prefName + TAG1);
403 fBackGroundColor.load();
404 fBackGroundColor.setPreferenceName((String) prefName + TAG2);
405 fBackGroundColor.store();
73005152 406 }
73005152
BH
407 }
408
eb63f5ff 409 keySet = SDViewPref.getInstance().fForeColorPref.keySet();
73005152
BH
410 it = keySet.iterator();
411 while (it.hasNext()) {
412 Object prefName = it.next();
413 if (prefName instanceof String) {
eb63f5ff
BH
414 fLineColor.setPreferenceName((String) prefName + TAG1);
415 fLineColor.load();
416 fLineColor.setPreferenceName((String) prefName + TAG2);
417 fLineColor.store();
73005152
BH
418 }
419 }
420
eb63f5ff 421 keySet = SDViewPref.getInstance().fTextColorPref.keySet();
73005152
BH
422 it = keySet.iterator();
423 while (it.hasNext()) {
424 Object prefName = it.next();
425 if (prefName instanceof String) {
eb63f5ff
BH
426 fTextColor.setPreferenceName((String) prefName + TAG1);
427 fTextColor.load();
428 fTextColor.setPreferenceName((String) prefName + TAG2);
429 fTextColor.store();
73005152
BH
430 }
431 }
e6ace8bb 432 String[] fontList = SDViewPref.getFontList();
73005152
BH
433 if (toTemp) {
434 // set the FontFieldEditor for the new selected graphNode font
eb63f5ff
BH
435 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
436 fFont.load();
73005152 437
eb63f5ff
BH
438 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
439 fBackGroundColor.load();
73005152 440
eb63f5ff
BH
441 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
442 fLineColor.load();
73005152 443
eb63f5ff
BH
444 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
445 fTextColor.load();
73005152
BH
446 }
447 }
448
df0b8ff4
BH
449 /*
450 * (non-Javadoc)
451 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
452 */
73005152
BH
453 @Override
454 public void widgetDefaultSelected(SelectionEvent e) {
455 }
456}
This page took 0.053703 seconds and 5 git commands to generate.