Merge branch 'HistogramView'
[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, 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 $
8 *
9 * Contributors:
10 * IBM - Initial API and implementation
11 * Bernd Hufmann - Updated for TMF
12 **********************************************************************/
13 package org.eclipse.linuxtools.tmf.ui.views.uml2sd.preferences;
14
15 import java.util.Iterator;
16 import java.util.Set;
17
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;
36
37 /**
38 * The Sequence Diagram preferences page implementation
39 *
40 * @author sveyrier
41 */
42 public class SDViewerPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener {
43
44 /**
45 * The preference handler used to access the PreferenceStore
46 */
47 protected SDViewPref pref = null;
48 /**
49 * BackGround color selector
50 */
51 protected ColorFieldEditor lineColor = null;
52 /**
53 * Foreground color selector
54 */
55 protected ColorFieldEditor backGroundColor = null;
56
57 /**
58 * Font color selector
59 */
60 protected ColorFieldEditor textColor = null;
61
62 /**
63 * List which display all modifiable sequence Diagram font
64 */
65 protected List classItemList = null;
66
67 /**
68 * Font selector (The same is used for each modifiable font)
69 */
70 protected FontFieldEditor font = null;
71
72 /**
73 * Link font when zooming selector
74 */
75 protected BooleanFieldEditor link = null;
76
77 /**
78 * Enable tooltip selector
79 */
80 protected BooleanFieldEditor tooltip = null;
81
82 /**
83 * Do not take external time into account in the min max computation
84 */
85 protected BooleanFieldEditor noExternalTime = null;
86
87 /**
88 * Use gradient color selector
89 */
90 protected BooleanFieldEditor useGrad = null;
91
92 protected Composite buttonArea;
93
94 /**
95 * SwimLane width selector
96 */
97 protected IntegerFieldEditor lifelineWidth = null;
98
99 protected static final String TEMP_TAG = SDViewPref.TEMP_TAG;
100
101 public SDViewerPage() {
102 super();
103 }
104
105 /**
106 * Creates the Sequence Diagram preference page content
107 *
108 * @param parent the parent composite
109 */
110 @Override
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);
119
120 tooltip = new BooleanFieldEditor(SDViewPref.PREF_TOOLTIP, SDMessages._97, page);
121 tooltip.setPreferenceStore(pref.getPreferenceStore());
122 tooltip.load();
123
124 // link font with zoom pref
125 link = new BooleanFieldEditor(SDViewPref.PREF_LINK_FONT, SDMessages._82, page);
126 link.setPreferenceStore(pref.getPreferenceStore());
127 link.load();
128
129 noExternalTime = new BooleanFieldEditor(SDViewPref.PREF_EXCLUDE_EXTERNAL_TIME, SDMessages._83, page);
130 noExternalTime.setPreferenceStore(pref.getPreferenceStore());
131 noExternalTime.load();
132
133 // use gradient color pref
134 useGrad = new BooleanFieldEditor(SDViewPref.PREF_USE_GRADIENT, SDMessages._84, page);
135 useGrad.setPreferenceStore(pref.getPreferenceStore());
136 useGrad.load();
137
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);
141
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);
147
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();
153
154 // not very nice
155 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
156 new Label(prefPage, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.SHADOW_NONE);
157
158 // Font list pref
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);
162
163 String[] fontList2 = SDViewPref.getFontList2();
164 for (int i = 0; i < fontList2.length; i++) {
165 classItemList.add(fontList2[i]);
166 }
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);
175
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());
182 font.load();
183
184 backGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, SDMessages._85, buttonArea);
185 backGroundColor.setPreferenceStore(pref.getPreferenceStore());
186 backGroundColor.load();
187
188 lineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, SDMessages._86, buttonArea);
189 lineColor.setPreferenceStore(pref.getPreferenceStore());
190 lineColor.load();
191
192 textColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, SDMessages._87, buttonArea);
193 textColor.setPreferenceStore(pref.getPreferenceStore());
194 textColor.load();
195 swapPref(true);
196 Dialog.applyDialogFont(page);
197
198 return page;
199 }
200
201 @Override
202 public void init(IWorkbench workbench) {
203 pref = SDViewPref.getInstance();
204 }
205
206 /**
207 * Apply the modification performed in the Sequence diagram preference page
208 */
209 @Override
210 protected void performApply() {
211 // Store the prefrences in the PreferenceStore
212 if (!lifelineWidth.isValid()) {
213 lifelineWidth.showErrorMessage();
214 return;
215 }
216 font.store();
217 backGroundColor.store();
218 lineColor.store();
219 link.store();
220 tooltip.store();
221 noExternalTime.store();
222 textColor.store();
223 useGrad.store();
224 lifelineWidth.store();
225 swapPref(false);
226 // then save them in the preference file
227 pref.apply();
228 swapPref(true);
229 }
230
231 /**
232 * Apply the modification performed in the Sequence diagram preference page
233 *
234 * @return true
235 */
236 @Override
237 public boolean performOk() {
238 performApply();
239 return true;
240 }
241
242 /**
243 * Loads the Sequence diagram default preference settings
244 */
245 @Override
246 protected void performDefaults() {
247 link.loadDefault();
248 tooltip.loadDefault();
249 noExternalTime.loadDefault();
250 useGrad.loadDefault();
251 lifelineWidth.loadDefault();
252
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);
262 font.loadDefault();
263 font.setPreferenceName((String) prefName + TEMP_TAG);
264 font.store();
265 }
266 }
267
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();
277 }
278
279 }
280
281 String[] fontList = SDViewPref.getFontList();
282 backGroundColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
283 backGroundColor.load();
284
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);
293 lineColor.store();
294 }
295 }
296
297 lineColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
298 lineColor.load();
299
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);
308 textColor.store();
309 }
310 }
311 textColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
312 textColor.load();
313 }
314
315 /**
316 * Sent when a new selection occurs in the graphNode font list
317 *
318 * @param e the selection event
319 */
320 @Override
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
324 font.store();
325 lineColor.store();
326 backGroundColor.store();
327 textColor.store();
328
329 String[] fontList = SDViewPref.getFontList();
330
331 // set the FontFieldEditor for the new selected graphNode font
332 font.setPreferenceName(fontList[classItemList.getSelectionIndex()] + TEMP_TAG);
333 font.load();
334
335 backGroundColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
336 backGroundColor.load();
337
338 lineColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
339 lineColor.load();
340
341 textColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
342 textColor.load();
343
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);
348 else
349 backGroundColor.setEnabled(true, buttonArea);
350
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);
354 else
355 textColor.setEnabled(true, buttonArea);
356
357 if (fontList[classItemList.getSelectionIndex()].equals(SDViewPref.PREF_FRAME))
358 font.setEnabled(false, buttonArea);
359 else
360 font.setEnabled(true, buttonArea);
361 }
362
363 protected void swapPref(boolean toTemp) {
364 String TAG1 = "";//$NON-NLS-1$
365 String TAG2 = TEMP_TAG;
366 if (!toTemp) {
367 TAG1 = TEMP_TAG;
368 TAG2 = "";//$NON-NLS-1$
369 }
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);
376 font.load();
377 font.setPreferenceName((String) prefName + TAG2);
378 font.store();
379 }
380 }
381
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();
391 }
392
393 }
394
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);
401 lineColor.load();
402 lineColor.setPreferenceName((String) prefName + TAG2);
403 lineColor.store();
404 }
405 }
406
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);
413 textColor.load();
414 textColor.setPreferenceName((String) prefName + TAG2);
415 textColor.store();
416 }
417 }
418 String[] fontList = SDViewPref.getFontList();
419 if (toTemp) {
420 // set the FontFieldEditor for the new selected graphNode font
421 font.setPreferenceName(fontList[classItemList.getSelectionIndex()] + TEMP_TAG);
422 font.load();
423
424 backGroundColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
425 backGroundColor.load();
426
427 lineColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
428 lineColor.load();
429
430 textColor.setPreferenceName(fontList[classItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
431 textColor.load();
432 }
433 }
434
435 @Override
436 public void widgetDefaultSelected(SelectionEvent e) {
437 }
438 }
This page took 0.041701 seconds and 6 git commands to generate.