Move alltests plugin to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / preferences / SDViewerPage.java
CommitLineData
73005152 1/**********************************************************************
030f8f1f 2 * Copyright (c) 2005, 2014 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;
92330441 24import org.eclipse.linuxtools.tmf.ui.views.uml2sd.util.Messages;
73005152
BH
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 */
cab6c8ff 51 private 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 */
cab6c8ff 59 private SDViewPref fPreferences = null;
73005152
BH
60 /**
61 * BackGround color selector
62 */
cab6c8ff 63 private ColorFieldEditor fLineColor = null;
73005152
BH
64 /**
65 * Foreground color selector
66 */
cab6c8ff 67 private ColorFieldEditor fBackGroundColor = null;
73005152
BH
68 /**
69 * Font color selector
70 */
cab6c8ff 71 private ColorFieldEditor fTextColor = null;
73005152
BH
72 /**
73 * List which display all modifiable sequence Diagram font
74 */
cab6c8ff 75 private List fClassItemList = null;
73005152
BH
76 /**
77 * Font selector (The same is used for each modifiable font)
78 */
cab6c8ff 79 private FontFieldEditor fFont = null;
73005152
BH
80 /**
81 * Link font when zooming selector
82 */
cab6c8ff 83 private BooleanFieldEditor fLink = null;
73005152
BH
84 /**
85 * Enable tooltip selector
86 */
cab6c8ff 87 private BooleanFieldEditor fTooltip = null;
73005152
BH
88 /**
89 * Do not take external time into account in the min max computation
90 */
cab6c8ff 91 private BooleanFieldEditor fNoExternalTime = null;
73005152
BH
92 /**
93 * Use gradient color selector
94 */
cab6c8ff 95 private BooleanFieldEditor fUseGrad = null;
df0b8ff4
BH
96 /**
97 * A button area.
98 */
cab6c8ff 99 private Composite fButtonArea;
73005152
BH
100 /**
101 * SwimLane width selector
102 */
cab6c8ff 103 private IntegerFieldEditor fLifelineWidth = null;
73005152 104
df0b8ff4 105 // ------------------------------------------------------------------------
df0b8ff4
BH
106 // Methods
107 // ------------------------------------------------------------------------
108
73005152
BH
109 @Override
110 protected Control createContents(Composite parent) {
030f8f1f
PT
111 GridLayout gl = new GridLayout();
112 gl.marginHeight = 0;
113 gl.marginWidth = 0;
114 parent.setLayout(gl);
73005152
BH
115 Composite page = new Composite(parent, SWT.NONE);
116 GridLayout pageLayout = new GridLayout();
117 pageLayout.numColumns = 2;
118 GridData pageLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
119 page.setLayoutData(pageLayoutdata);
120 page.setLayout(pageLayout);
121
92330441 122 fTooltip = new BooleanFieldEditor(ISDPreferences.PREF_TOOLTIP, Messages.SequenceDiagram_ShowTooltips, page);
eb63f5ff
BH
123 fTooltip.setPreferenceStore(fPreferences.getPreferenceStore());
124 fTooltip.load();
73005152
BH
125
126 // link font with zoom pref
92330441 127 fLink = new BooleanFieldEditor(ISDPreferences.PREF_LINK_FONT, Messages.SequenceDiagram_IncreaseFontSizeWhenZooming, page);
eb63f5ff
BH
128 fLink.setPreferenceStore(fPreferences.getPreferenceStore());
129 fLink.load();
73005152 130
92330441 131 fNoExternalTime = new BooleanFieldEditor(ISDPreferences.PREF_EXCLUDE_EXTERNAL_TIME, Messages.SequenceDiagram_ExcludeExternalTime, page);
eb63f5ff
BH
132 fNoExternalTime.setPreferenceStore(fPreferences.getPreferenceStore());
133 fNoExternalTime.load();
73005152
BH
134
135 // use gradient color pref
92330441 136 fUseGrad = new BooleanFieldEditor(ISDPreferences.PREF_USE_GRADIENT, Messages.SequenceDiagram_UseGradientColor, page);
eb63f5ff
BH
137 fUseGrad.setPreferenceStore(fPreferences.getPreferenceStore());
138 fUseGrad.load();
73005152
BH
139
140 Label separator = new Label(page, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
141 GridData sepData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
142 separator.setLayoutData(sepData);
143
144 Composite prefPage = new Composite(page, SWT.NONE);
145 GridLayout prefPageLayout = new GridLayout();
146 prefPage.setLayoutData(pageLayoutdata);
147 prefPageLayout.numColumns = 1;
148 prefPage.setLayout(prefPageLayout);
149
150 // swimLane width pref
92330441 151 fLifelineWidth = new IntegerFieldEditor(ISDPreferences.PREF_LIFELINE_WIDTH, Messages.SequenceDiagram_LifelineWidth, prefPage);
eb63f5ff
BH
152 fLifelineWidth.setPreferenceStore(fPreferences.getPreferenceStore());
153 fLifelineWidth.setValidRange(119, 500);
154 fLifelineWidth.load();
73005152
BH
155
156 // not very nice
157 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
158 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
159
160 // Font list pref
eb63f5ff 161 fClassItemList = new List(prefPage, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
73005152 162 GridData tabItemLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
eb63f5ff 163 fClassItemList.setLayoutData(tabItemLayoutdata);
73005152 164
e6ace8bb
BH
165 String[] fontList2 = SDViewPref.getFontList2();
166 for (int i = 0; i < fontList2.length; i++) {
eb63f5ff 167 fClassItemList.add(fontList2[i]);
73005152 168 }
eb63f5ff
BH
169 fClassItemList.setSelection(0);
170 fClassItemList.addSelectionListener(this);
171 fButtonArea = new Composite(prefPage, SWT.NONE);
73005152 172 GridData tabItemLayoutdata2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL/* |GridData.GRAB_HORIZONTAL */| GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
eb63f5ff 173 fButtonArea.setLayoutData(tabItemLayoutdata2);
73005152
BH
174 GridLayout buttonAreaLayout = new GridLayout();
175 buttonAreaLayout.numColumns = 1;
eb63f5ff 176 fButtonArea.setLayout(buttonAreaLayout);
73005152
BH
177
178 // font selector initialise for the lifeline font pref
e6ace8bb 179 String[] fontList = SDViewPref.getFontList();
eb63f5ff 180 fFont = new FontFieldEditor(fontList[0], "",//$NON-NLS-1$
92330441 181 Messages.SequenceDiagram_AaBbYyZz, fButtonArea);
eb63f5ff
BH
182 fFont.getPreviewControl().setSize(500, 500);
183 fFont.setPreferenceStore(fPreferences.getPreferenceStore());
184 fFont.load();
185
92330441 186 fBackGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, Messages.SequenceDiagram_Background, fButtonArea);
eb63f5ff
BH
187 fBackGroundColor.setPreferenceStore(fPreferences.getPreferenceStore());
188 fBackGroundColor.load();
189
92330441 190 fLineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, Messages.SequenceDiagram_Lines, fButtonArea);
eb63f5ff
BH
191 fLineColor.setPreferenceStore(fPreferences.getPreferenceStore());
192 fLineColor.load();
193
92330441 194 fTextColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, Messages.SequenceDiagram_Text, fButtonArea);
eb63f5ff
BH
195 fTextColor.setPreferenceStore(fPreferences.getPreferenceStore());
196 fTextColor.load();
73005152
BH
197 swapPref(true);
198 Dialog.applyDialogFont(page);
199
200 return page;
201 }
202
203 @Override
204 public void init(IWorkbench workbench) {
eb63f5ff 205 fPreferences = SDViewPref.getInstance();
73005152
BH
206 }
207
73005152
BH
208 @Override
209 protected void performApply() {
210 // Store the prefrences in the PreferenceStore
eb63f5ff
BH
211 if (!fLifelineWidth.isValid()) {
212 fLifelineWidth.showErrorMessage();
73005152
BH
213 return;
214 }
eb63f5ff
BH
215 fFont.store();
216 fBackGroundColor.store();
217 fLineColor.store();
218 fLink.store();
219 fTooltip.store();
220 fNoExternalTime.store();
221 fTextColor.store();
222 fUseGrad.store();
223 fLifelineWidth.store();
73005152
BH
224 swapPref(false);
225 // then save them in the preference file
eb63f5ff 226 fPreferences.apply();
73005152
BH
227 swapPref(true);
228 }
229
73005152
BH
230 @Override
231 public boolean performOk() {
232 performApply();
233 return true;
234 }
abbdd66a 235
73005152
BH
236 @Override
237 protected void performDefaults() {
eb63f5ff
BH
238 fLink.loadDefault();
239 fTooltip.loadDefault();
240 fNoExternalTime.loadDefault();
241 fUseGrad.loadDefault();
242 fLifelineWidth.loadDefault();
73005152
BH
243
244 // and all the fonts and colors
245 // fonts and colors are stored for each time because
246 // we are using only one FontFieldEditor
cab6c8ff 247 Set<String> keySet = SDViewPref.getInstance().getFontPref().keySet();
73005152
BH
248 Iterator<String> it = keySet.iterator();
249 while (it.hasNext()) {
250 Object prefName = it.next();
251 if (prefName instanceof String) {
eb63f5ff
BH
252 fFont.setPreferenceName((String) prefName);
253 fFont.loadDefault();
254 fFont.setPreferenceName((String) prefName + TEMP_TAG);
255 fFont.store();
73005152
BH
256 }
257 }
258
cab6c8ff 259 keySet = SDViewPref.getInstance().getBackColorPref().keySet();
73005152
BH
260 it = keySet.iterator();
261 while (it.hasNext()) {
262 Object prefName = it.next();
263 if (prefName instanceof String) {
eb63f5ff
BH
264 fBackGroundColor.setPreferenceName((String) prefName);
265 fBackGroundColor.loadDefault();
266 fBackGroundColor.setPreferenceName((String) prefName + TEMP_TAG);
267 fBackGroundColor.store();
73005152
BH
268 }
269
270 }
271
e6ace8bb 272 String[] fontList = SDViewPref.getFontList();
eb63f5ff
BH
273 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
274 fBackGroundColor.load();
73005152 275
cab6c8ff 276 keySet = SDViewPref.getInstance().getForeColorPref().keySet();
73005152
BH
277 it = keySet.iterator();
278 while (it.hasNext()) {
279 Object prefName = it.next();
280 if (prefName instanceof String) {
eb63f5ff
BH
281 fLineColor.setPreferenceName((String) prefName);
282 fLineColor.loadDefault();
283 fLineColor.setPreferenceName((String) prefName + TEMP_TAG);
284 fLineColor.store();
73005152
BH
285 }
286 }
287
eb63f5ff
BH
288 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
289 fLineColor.load();
73005152 290
cab6c8ff 291 keySet = SDViewPref.getInstance().getTextColorPref().keySet();
73005152
BH
292 it = keySet.iterator();
293 while (it.hasNext()) {
294 Object prefName = it.next();
295 if (prefName instanceof String) {
eb63f5ff
BH
296 fTextColor.setPreferenceName((String) prefName);
297 fTextColor.loadDefault();
298 fTextColor.setPreferenceName((String) prefName + TEMP_TAG);
299 fTextColor.store();
73005152
BH
300 }
301 }
eb63f5ff
BH
302 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
303 fTextColor.load();
73005152
BH
304 }
305
73005152
BH
306 @Override
307 public void widgetSelected(SelectionEvent e) {
308 // Store the past set font preference or else the
309 // FontFieldEditor reassignment will make us loose the current modification
eb63f5ff
BH
310 fFont.store();
311 fLineColor.store();
312 fBackGroundColor.store();
313 fTextColor.store();
73005152 314
e6ace8bb 315 String[] fontList = SDViewPref.getFontList();
abbdd66a 316
73005152 317 // set the FontFieldEditor for the new selected graphNode font
eb63f5ff
BH
318 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
319 fFont.load();
73005152 320
eb63f5ff
BH
321 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
322 fBackGroundColor.load();
73005152 323
eb63f5ff
BH
324 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
325 fLineColor.load();
73005152 326
eb63f5ff
BH
327 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
328 fTextColor.load();
73005152
BH
329
330 // No Background for message graphNodes
abbdd66a
AM
331 if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_SYNC_MESS)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_SYNC_MESS_RET))
332 || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_ASYNC_MESS)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_ASYNC_MESS_RET))) {
eb63f5ff 333 fBackGroundColor.setEnabled(false, fButtonArea);
df0b8ff4 334 } else {
eb63f5ff 335 fBackGroundColor.setEnabled(true, fButtonArea);
df0b8ff4 336 }
73005152
BH
337
338 // No font used for execution occurrence and global frame
abbdd66a 339 if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_EXEC)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME))) {
eb63f5ff 340 fTextColor.setEnabled(false, fButtonArea);
df0b8ff4 341 } else {
eb63f5ff 342 fTextColor.setEnabled(true, fButtonArea);
df0b8ff4 343 }
73005152 344
abbdd66a 345 if (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME)) {
eb63f5ff 346 fFont.setEnabled(false, fButtonArea);
df0b8ff4 347 } else {
eb63f5ff 348 fFont.setEnabled(true, fButtonArea);
df0b8ff4 349 }
73005152
BH
350 }
351
a0a88f65
AM
352 /**
353 * Swap viewer preferences.
354 *
355 * @param toTemp Switch to the temporary preferences
356 */
73005152 357 protected void swapPref(boolean toTemp) {
f26e290b
BH
358 String tag1 = "";//$NON-NLS-1$
359 String tag2 = TEMP_TAG;
73005152 360 if (!toTemp) {
f26e290b
BH
361 tag1 = TEMP_TAG;
362 tag2 = "";//$NON-NLS-1$
73005152 363 }
cab6c8ff 364 Set<String> keySet = SDViewPref.getInstance().getFontPref().keySet();
73005152
BH
365 Iterator<String> it = keySet.iterator();
366 while (it.hasNext()) {
367 Object prefName = it.next();
368 if (prefName instanceof String) {
f26e290b 369 fFont.setPreferenceName((String) prefName + tag1);
eb63f5ff 370 fFont.load();
f26e290b 371 fFont.setPreferenceName((String) prefName + tag2);
eb63f5ff 372 fFont.store();
73005152
BH
373 }
374 }
375
cab6c8ff 376 keySet = SDViewPref.getInstance().getBackColorPref().keySet();
73005152
BH
377 it = keySet.iterator();
378 while (it.hasNext()) {
379 Object prefName = it.next();
380 if (prefName instanceof String) {
f26e290b 381 fBackGroundColor.setPreferenceName((String) prefName + tag1);
eb63f5ff 382 fBackGroundColor.load();
f26e290b 383 fBackGroundColor.setPreferenceName((String) prefName + tag2);
eb63f5ff 384 fBackGroundColor.store();
73005152 385 }
73005152
BH
386 }
387
cab6c8ff 388 keySet = SDViewPref.getInstance().getForeColorPref().keySet();
73005152
BH
389 it = keySet.iterator();
390 while (it.hasNext()) {
391 Object prefName = it.next();
392 if (prefName instanceof String) {
f26e290b 393 fLineColor.setPreferenceName((String) prefName + tag1);
eb63f5ff 394 fLineColor.load();
f26e290b 395 fLineColor.setPreferenceName((String) prefName + tag2);
eb63f5ff 396 fLineColor.store();
73005152
BH
397 }
398 }
399
cab6c8ff 400 keySet = SDViewPref.getInstance().getTextColorPref().keySet();
73005152
BH
401 it = keySet.iterator();
402 while (it.hasNext()) {
403 Object prefName = it.next();
404 if (prefName instanceof String) {
f26e290b 405 fTextColor.setPreferenceName((String) prefName + tag1);
eb63f5ff 406 fTextColor.load();
f26e290b 407 fTextColor.setPreferenceName((String) prefName + tag2);
eb63f5ff 408 fTextColor.store();
73005152
BH
409 }
410 }
e6ace8bb 411 String[] fontList = SDViewPref.getFontList();
73005152
BH
412 if (toTemp) {
413 // set the FontFieldEditor for the new selected graphNode font
eb63f5ff
BH
414 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
415 fFont.load();
73005152 416
eb63f5ff
BH
417 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
418 fBackGroundColor.load();
73005152 419
eb63f5ff
BH
420 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
421 fLineColor.load();
73005152 422
eb63f5ff
BH
423 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
424 fTextColor.load();
73005152
BH
425 }
426 }
427
428 @Override
429 public void widgetDefaultSelected(SelectionEvent e) {
430 }
431}
This page took 0.099879 seconds and 5 git commands to generate.