|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * General preferences page |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracebuilder.preferences; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.Iterator; |
|
23 |
|
24 import org.eclipse.jface.preference.BooleanFieldEditor; |
|
25 import org.eclipse.jface.preference.FieldEditorPreferencePage; |
|
26 import org.eclipse.jface.preference.RadioGroupFieldEditor; |
|
27 import org.eclipse.jface.preference.StringFieldEditor; |
|
28 import org.eclipse.ui.IWorkbench; |
|
29 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
30 import org.eclipse.ui.PlatformUI; |
|
31 |
|
32 import com.nokia.tracebuilder.engine.TraceBuilderConfiguration; |
|
33 import com.nokia.tracebuilder.engine.TraceBuilderGlobals; |
|
34 import com.nokia.tracebuilder.engine.TraceBuilderHelp; |
|
35 import com.nokia.tracebuilder.project.TraceProjectAPI; |
|
36 import com.nokia.tracebuilder.project.TraceProjectAPIList; |
|
37 import com.nokia.tracebuilder.view.TraceViewPlugin; |
|
38 |
|
39 /** |
|
40 * This class represents a preference page that is contributed to the |
|
41 * Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we |
|
42 * can use the field support built into JFace that allows us to create a page |
|
43 * that is small and knows how to save, restore and apply itself. |
|
44 * <p> |
|
45 * This page is used to modify preferences only. They are stored in the |
|
46 * preference store that belongs to the main plug-in class. That way, |
|
47 * preferences can be accessed directly via the preference store. |
|
48 * |
|
49 */ |
|
50 public class GeneralPreferencePage extends FieldEditorPreferencePage implements |
|
51 IWorkbenchPreferencePage { |
|
52 |
|
53 /** |
|
54 * Number of columns in format radio group |
|
55 */ |
|
56 private static final int FORMAT_COLUMNS = 1; // CodForChk_Dis_Magic |
|
57 |
|
58 /** |
|
59 * Constructor |
|
60 */ |
|
61 public GeneralPreferencePage() { |
|
62 super(GRID); |
|
63 setPreferenceStore(TraceViewPlugin.getDefault().getPreferenceStore()); |
|
64 setDescription(Messages.getString("GeneralPreferencePage.Description")); //$NON-NLS-1$ |
|
65 } |
|
66 |
|
67 /* |
|
68 * (non-Javadoc) |
|
69 * |
|
70 * @see |
|
71 * org.eclipse.jface.preference.FieldEditorPreferencePage#createFieldEditors |
|
72 * () |
|
73 */ |
|
74 @Override |
|
75 protected void createFieldEditors() { |
|
76 String formatGroupTitle = Messages |
|
77 .getString("GeneralPreferencePage.TraceFormatTitle"); //$NON-NLS-1$ |
|
78 TraceProjectAPIList apilist = TraceBuilderGlobals.getTraceModel() |
|
79 .getExtension(TraceProjectAPIList.class); |
|
80 if (apilist != null) { |
|
81 Iterator<TraceProjectAPI> apis = apilist.getAPIs(); |
|
82 ArrayList<String[]> list = new ArrayList<String[]>(); |
|
83 while (apis.hasNext()) { |
|
84 TraceProjectAPI api = apis.next(); |
|
85 if (api.isVisibleInConfiguration()) { |
|
86 String name = api.getName(); |
|
87 String title = api.getTitle(); |
|
88 list.add(new String[] { title, name }); |
|
89 } |
|
90 } |
|
91 if (list.size() > 1) { |
|
92 String[][] formatters = new String[list.size()][]; |
|
93 list.toArray(formatters); |
|
94 addField(new RadioGroupFieldEditor( |
|
95 TraceBuilderConfiguration.FORMATTER_NAME, |
|
96 formatGroupTitle, FORMAT_COLUMNS, formatters, |
|
97 getFieldEditorParent(), true)); |
|
98 } |
|
99 } |
|
100 addField(new BooleanFieldEditor( |
|
101 TraceBuilderConfiguration.PRINTF_SUPPORT, |
|
102 Messages |
|
103 .getString("GeneralPreferencePage.PrintfParserSupportTitle"), //$NON-NLS-1$ |
|
104 getFieldEditorParent())); |
|
105 addField(new StringFieldEditor( |
|
106 TraceBuilderConfiguration.PRINTF_EXTENSION, Messages |
|
107 .getString("GeneralPreferencePage.PrintfMacroTitle"), //$NON-NLS-1$ |
|
108 StringFieldEditor.UNLIMITED, getFieldEditorParent())); |
|
109 } |
|
110 |
|
111 /* |
|
112 * (non-Javadoc) |
|
113 * |
|
114 * @see org.eclipse.jface.preference.FieldEditorPreferencePage#initialize() |
|
115 */ |
|
116 @Override |
|
117 protected void initialize() { |
|
118 super.initialize(); |
|
119 |
|
120 PlatformUI.getWorkbench().getHelpSystem().setHelp( |
|
121 getControl(), |
|
122 TraceBuilderHelp.HELP_CONTEXT_BASE |
|
123 + TraceBuilderHelp.GENERAL_PREFERENCES_CONTEXT); |
|
124 } |
|
125 |
|
126 /* |
|
127 * (non-Javadoc) |
|
128 * |
|
129 * @see |
|
130 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) |
|
131 */ |
|
132 public void init(IWorkbench workbench) { |
|
133 } |
|
134 |
|
135 } |