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