tmf/lttng: Remove unneeded (non-Javadoc) comments
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / uml2sd / preferences / SDViewerPage.java
1 /**********************************************************************
2 * Copyright (c) 2005, 2013 IBM Corporation, Ericsson
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 *
8 * Contributors:
9 * IBM - Initial API and implementation
10 * Bernd Hufmann - Updated for TMF
11 **********************************************************************/
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 * @version 1.0
41 * @author sveyrier
42 */
43 public class SDViewerPage extends PreferencePage implements IWorkbenchPreferencePage, SelectionListener {
44
45 // ------------------------------------------------------------------------
46 // Constants
47 // ------------------------------------------------------------------------
48 /**
49 * Temporary preferences tag
50 */
51 protected static final String TEMP_TAG = SDViewPref.TEMP_TAG;
52
53 // ------------------------------------------------------------------------
54 // Attributes
55 // ------------------------------------------------------------------------
56 /**
57 * The preference handler used to access the PreferenceStore
58 */
59 protected SDViewPref fPreferences = null;
60 /**
61 * BackGround color selector
62 */
63 protected ColorFieldEditor fLineColor = null;
64 /**
65 * Foreground color selector
66 */
67 protected ColorFieldEditor fBackGroundColor = null;
68 /**
69 * Font color selector
70 */
71 protected ColorFieldEditor fTextColor = null;
72 /**
73 * List which display all modifiable sequence Diagram font
74 */
75 protected List fClassItemList = null;
76 /**
77 * Font selector (The same is used for each modifiable font)
78 */
79 protected FontFieldEditor fFont = null;
80 /**
81 * Link font when zooming selector
82 */
83 protected BooleanFieldEditor fLink = null;
84 /**
85 * Enable tooltip selector
86 */
87 protected BooleanFieldEditor fTooltip = null;
88 /**
89 * Do not take external time into account in the min max computation
90 */
91 protected BooleanFieldEditor fNoExternalTime = null;
92 /**
93 * Use gradient color selector
94 */
95 protected BooleanFieldEditor fUseGrad = null;
96 /**
97 * A button area.
98 */
99 protected Composite fButtonArea;
100 /**
101 * SwimLane width selector
102 */
103 protected IntegerFieldEditor fLifelineWidth = null;
104
105 // ------------------------------------------------------------------------
106 // Methods
107 // ------------------------------------------------------------------------
108
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
119 fTooltip = new BooleanFieldEditor(ISDPreferences.PREF_TOOLTIP, SDMessages._97, page);
120 fTooltip.setPreferenceStore(fPreferences.getPreferenceStore());
121 fTooltip.load();
122
123 // link font with zoom pref
124 fLink = new BooleanFieldEditor(ISDPreferences.PREF_LINK_FONT, SDMessages._82, page);
125 fLink.setPreferenceStore(fPreferences.getPreferenceStore());
126 fLink.load();
127
128 fNoExternalTime = new BooleanFieldEditor(ISDPreferences.PREF_EXCLUDE_EXTERNAL_TIME, SDMessages._83, page);
129 fNoExternalTime.setPreferenceStore(fPreferences.getPreferenceStore());
130 fNoExternalTime.load();
131
132 // use gradient color pref
133 fUseGrad = new BooleanFieldEditor(ISDPreferences.PREF_USE_GRADIENT, SDMessages._84, page);
134 fUseGrad.setPreferenceStore(fPreferences.getPreferenceStore());
135 fUseGrad.load();
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
148 fLifelineWidth = new IntegerFieldEditor(ISDPreferences.PREF_LIFELINE_WIDTH, SDMessages._80, prefPage);
149 fLifelineWidth.setPreferenceStore(fPreferences.getPreferenceStore());
150 fLifelineWidth.setValidRange(119, 500);
151 fLifelineWidth.load();
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
158 fClassItemList = new List(prefPage, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
159 GridData tabItemLayoutdata = new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
160 fClassItemList.setLayoutData(tabItemLayoutdata);
161
162 String[] fontList2 = SDViewPref.getFontList2();
163 for (int i = 0; i < fontList2.length; i++) {
164 fClassItemList.add(fontList2[i]);
165 }
166 fClassItemList.setSelection(0);
167 fClassItemList.addSelectionListener(this);
168 fButtonArea = new Composite(prefPage, SWT.NONE);
169 GridData tabItemLayoutdata2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL/* |GridData.GRAB_HORIZONTAL */| GridData.GRAB_VERTICAL | GridData.VERTICAL_ALIGN_FILL);
170 fButtonArea.setLayoutData(tabItemLayoutdata2);
171 GridLayout buttonAreaLayout = new GridLayout();
172 buttonAreaLayout.numColumns = 1;
173 fButtonArea.setLayout(buttonAreaLayout);
174
175 // font selector initialise for the lifeline font pref
176 String[] fontList = SDViewPref.getFontList();
177 fFont = new FontFieldEditor(fontList[0], "",//$NON-NLS-1$
178 SDMessages._81, fButtonArea);
179 fFont.getPreviewControl().setSize(500, 500);
180 fFont.setPreferenceStore(fPreferences.getPreferenceStore());
181 fFont.load();
182
183 fBackGroundColor = new ColorFieldEditor(fontList[0] + SDViewPref.BACK_COLOR_POSTFIX, SDMessages._85, fButtonArea);
184 fBackGroundColor.setPreferenceStore(fPreferences.getPreferenceStore());
185 fBackGroundColor.load();
186
187 fLineColor = new ColorFieldEditor(fontList[0] + SDViewPref.FORE_COLOR_POSTFIX, SDMessages._86, fButtonArea);
188 fLineColor.setPreferenceStore(fPreferences.getPreferenceStore());
189 fLineColor.load();
190
191 fTextColor = new ColorFieldEditor(fontList[0] + SDViewPref.TEXT_COLOR_POSTFIX, SDMessages._87, fButtonArea);
192 fTextColor.setPreferenceStore(fPreferences.getPreferenceStore());
193 fTextColor.load();
194 swapPref(true);
195 Dialog.applyDialogFont(page);
196
197 return page;
198 }
199
200 @Override
201 public void init(IWorkbench workbench) {
202 fPreferences = SDViewPref.getInstance();
203 }
204
205 @Override
206 protected void performApply() {
207 // Store the prefrences in the PreferenceStore
208 if (!fLifelineWidth.isValid()) {
209 fLifelineWidth.showErrorMessage();
210 return;
211 }
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();
221 swapPref(false);
222 // then save them in the preference file
223 fPreferences.apply();
224 swapPref(true);
225 }
226
227 @Override
228 public boolean performOk() {
229 performApply();
230 return true;
231 }
232
233 @Override
234 protected void performDefaults() {
235 fLink.loadDefault();
236 fTooltip.loadDefault();
237 fNoExternalTime.loadDefault();
238 fUseGrad.loadDefault();
239 fLifelineWidth.loadDefault();
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
244 Set<String> keySet = SDViewPref.getInstance().fFontPref.keySet();
245 Iterator<String> it = keySet.iterator();
246 while (it.hasNext()) {
247 Object prefName = it.next();
248 if (prefName instanceof String) {
249 fFont.setPreferenceName((String) prefName);
250 fFont.loadDefault();
251 fFont.setPreferenceName((String) prefName + TEMP_TAG);
252 fFont.store();
253 }
254 }
255
256 keySet = SDViewPref.getInstance().fBackColorPref.keySet();
257 it = keySet.iterator();
258 while (it.hasNext()) {
259 Object prefName = it.next();
260 if (prefName instanceof String) {
261 fBackGroundColor.setPreferenceName((String) prefName);
262 fBackGroundColor.loadDefault();
263 fBackGroundColor.setPreferenceName((String) prefName + TEMP_TAG);
264 fBackGroundColor.store();
265 }
266
267 }
268
269 String[] fontList = SDViewPref.getFontList();
270 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
271 fBackGroundColor.load();
272
273 keySet = SDViewPref.getInstance().fForeColorPref.keySet();
274 it = keySet.iterator();
275 while (it.hasNext()) {
276 Object prefName = it.next();
277 if (prefName instanceof String) {
278 fLineColor.setPreferenceName((String) prefName);
279 fLineColor.loadDefault();
280 fLineColor.setPreferenceName((String) prefName + TEMP_TAG);
281 fLineColor.store();
282 }
283 }
284
285 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
286 fLineColor.load();
287
288 keySet = SDViewPref.getInstance().fTextColorPref.keySet();
289 it = keySet.iterator();
290 while (it.hasNext()) {
291 Object prefName = it.next();
292 if (prefName instanceof String) {
293 fTextColor.setPreferenceName((String) prefName);
294 fTextColor.loadDefault();
295 fTextColor.setPreferenceName((String) prefName + TEMP_TAG);
296 fTextColor.store();
297 }
298 }
299 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
300 fTextColor.load();
301 }
302
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
307 fFont.store();
308 fLineColor.store();
309 fBackGroundColor.store();
310 fTextColor.store();
311
312 String[] fontList = SDViewPref.getFontList();
313
314 // set the FontFieldEditor for the new selected graphNode font
315 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
316 fFont.load();
317
318 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
319 fBackGroundColor.load();
320
321 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
322 fLineColor.load();
323
324 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
325 fTextColor.load();
326
327 // No Background for message graphNodes
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))) {
330 fBackGroundColor.setEnabled(false, fButtonArea);
331 } else {
332 fBackGroundColor.setEnabled(true, fButtonArea);
333 }
334
335 // No font used for execution occurrence and global frame
336 if ((fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_EXEC)) || (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME))) {
337 fTextColor.setEnabled(false, fButtonArea);
338 } else {
339 fTextColor.setEnabled(true, fButtonArea);
340 }
341
342 if (fontList[fClassItemList.getSelectionIndex()].equals(ISDPreferences.PREF_FRAME)) {
343 fFont.setEnabled(false, fButtonArea);
344 } else {
345 fFont.setEnabled(true, fButtonArea);
346 }
347 }
348
349 /**
350 * Swap viewer preferences.
351 *
352 * @param toTemp Switch to the temporary preferences
353 */
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 }
361 Set<String> keySet = SDViewPref.getInstance().fFontPref.keySet();
362 Iterator<String> it = keySet.iterator();
363 while (it.hasNext()) {
364 Object prefName = it.next();
365 if (prefName instanceof String) {
366 fFont.setPreferenceName((String) prefName + TAG1);
367 fFont.load();
368 fFont.setPreferenceName((String) prefName + TAG2);
369 fFont.store();
370 }
371 }
372
373 keySet = SDViewPref.getInstance().fBackColorPref.keySet();
374 it = keySet.iterator();
375 while (it.hasNext()) {
376 Object prefName = it.next();
377 if (prefName instanceof String) {
378 fBackGroundColor.setPreferenceName((String) prefName + TAG1);
379 fBackGroundColor.load();
380 fBackGroundColor.setPreferenceName((String) prefName + TAG2);
381 fBackGroundColor.store();
382 }
383 }
384
385 keySet = SDViewPref.getInstance().fForeColorPref.keySet();
386 it = keySet.iterator();
387 while (it.hasNext()) {
388 Object prefName = it.next();
389 if (prefName instanceof String) {
390 fLineColor.setPreferenceName((String) prefName + TAG1);
391 fLineColor.load();
392 fLineColor.setPreferenceName((String) prefName + TAG2);
393 fLineColor.store();
394 }
395 }
396
397 keySet = SDViewPref.getInstance().fTextColorPref.keySet();
398 it = keySet.iterator();
399 while (it.hasNext()) {
400 Object prefName = it.next();
401 if (prefName instanceof String) {
402 fTextColor.setPreferenceName((String) prefName + TAG1);
403 fTextColor.load();
404 fTextColor.setPreferenceName((String) prefName + TAG2);
405 fTextColor.store();
406 }
407 }
408 String[] fontList = SDViewPref.getFontList();
409 if (toTemp) {
410 // set the FontFieldEditor for the new selected graphNode font
411 fFont.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + TEMP_TAG);
412 fFont.load();
413
414 fBackGroundColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.BACK_COLOR_POSTFIX + TEMP_TAG);
415 fBackGroundColor.load();
416
417 fLineColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.FORE_COLOR_POSTFIX + TEMP_TAG);
418 fLineColor.load();
419
420 fTextColor.setPreferenceName(fontList[fClassItemList.getSelectionIndex()] + SDViewPref.TEXT_COLOR_POSTFIX + TEMP_TAG);
421 fTextColor.load();
422 }
423 }
424
425 @Override
426 public void widgetDefaultSelected(SelectionEvent e) {
427 }
428 }
This page took 0.054532 seconds and 6 git commands to generate.