|
1 /* |
|
2 * Copyright (c) 2007-2010 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 * Connection preferences page |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine.preferences; |
|
20 |
|
21 import org.eclipse.jface.preference.IPreferenceStore; |
|
22 import org.eclipse.jface.preference.PreferencePage; |
|
23 import org.eclipse.swt.SWT; |
|
24 import org.eclipse.swt.layout.GridData; |
|
25 import org.eclipse.swt.layout.GridLayout; |
|
26 import org.eclipse.swt.widgets.Button; |
|
27 import org.eclipse.swt.widgets.Composite; |
|
28 import org.eclipse.swt.widgets.Control; |
|
29 import org.eclipse.swt.widgets.Label; |
|
30 import org.eclipse.ui.IWorkbench; |
|
31 import org.eclipse.ui.IWorkbenchPreferencePage; |
|
32 import org.eclipse.ui.PlatformUI; |
|
33 |
|
34 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
|
35 import com.nokia.traceviewer.TraceViewerHelpContextIDs; |
|
36 import com.nokia.traceviewer.TraceViewerPlugin; |
|
37 import com.nokia.traceviewer.engine.ConnectionHelper; |
|
38 import com.nokia.traceviewer.internal.api.TraceViewerAPI2Impl; |
|
39 |
|
40 /** |
|
41 * Connection preferences page |
|
42 * |
|
43 */ |
|
44 public final class TraceViewerConnectionPreferencesPage extends PreferencePage |
|
45 implements IWorkbenchPreferencePage { |
|
46 |
|
47 /** |
|
48 * Id for Connection preferences page |
|
49 */ |
|
50 public static final String PAGE_ID = "com.nokia.traceviewer.preferences.ConnectionPreferences"; //$NON-NLS-1$ |
|
51 |
|
52 /** |
|
53 * PreferenceStore holding all preferences |
|
54 */ |
|
55 private final IPreferenceStore store; |
|
56 |
|
57 /** |
|
58 * Auto-connect to dynamic connections checkbox |
|
59 */ |
|
60 private Button autoConnectDynamicConnectionsCheckBox; |
|
61 |
|
62 /** |
|
63 * Connection that is used after latest call to <code>saveSettings()</code> |
|
64 * method. |
|
65 */ |
|
66 private IConnection conn; |
|
67 |
|
68 /** |
|
69 * Constructor |
|
70 */ |
|
71 public TraceViewerConnectionPreferencesPage() { |
|
72 super(); |
|
73 |
|
74 // Set the preference store for the preference page. |
|
75 store = TraceViewerPlugin.getDefault().getPreferenceStore(); |
|
76 setPreferenceStore(store); |
|
77 } |
|
78 |
|
79 /* |
|
80 * (non-Javadoc) |
|
81 * |
|
82 * @see |
|
83 * org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse |
|
84 * .swt.widgets.Composite) |
|
85 */ |
|
86 @Override |
|
87 protected Control createContents(Composite parent) { |
|
88 |
|
89 // Create Top composite in top of the parent composite |
|
90 Composite top = new Composite(parent, SWT.LEFT); |
|
91 GridData topCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, |
|
92 false); |
|
93 top.setLayoutData(topCompositeGridData); |
|
94 GridLayout topCompositeGridLayout = new GridLayout(); |
|
95 topCompositeGridLayout.horizontalSpacing = 5; |
|
96 topCompositeGridLayout.verticalSpacing = 5; |
|
97 topCompositeGridLayout.marginWidth = 0; |
|
98 topCompositeGridLayout.marginHeight = 0; |
|
99 top.setLayout(topCompositeGridLayout); |
|
100 |
|
101 // Create client side UI |
|
102 Composite returnedComposite = ConnectionHelper |
|
103 .createClientServiceUI(top); |
|
104 |
|
105 // If client service UI couldn't be constructed, give an error message |
|
106 // to the user |
|
107 if (returnedComposite == null) { |
|
108 Label errorLabel = new Label(top, SWT.NONE); |
|
109 String msg = Messages |
|
110 .getString("TraceViewerConnectionPreferencesPage.ServiceUiFailed"); //$NON-NLS-1$ |
|
111 errorLabel.setText(msg); |
|
112 } else { |
|
113 |
|
114 // Select connection from the UI with ID |
|
115 String selectedConnId = store |
|
116 .getString(PreferenceConstants.SELECTED_CONNECTION_ID); |
|
117 ConnectionHelper.selectConnectionFromUIWithID(selectedConnId); |
|
118 } |
|
119 |
|
120 // Auto-connect to dynamic connections checkbox |
|
121 autoConnectDynamicConnectionsCheckBox = new Button(top, SWT.CHECK); |
|
122 String autoConnectText = Messages |
|
123 .getString("TraceViewerConnectionPreferencesPage.AutoConnectDynamicText"); //$NON-NLS-1$ |
|
124 String autoConnectToolTip = Messages |
|
125 .getString("TraceViewerConnectionPreferencesPage.AutoConnectDynamicToolTip"); //$NON-NLS-1$ |
|
126 autoConnectDynamicConnectionsCheckBox.setText(autoConnectText); |
|
127 autoConnectDynamicConnectionsCheckBox |
|
128 .setToolTipText(autoConnectToolTip); |
|
129 autoConnectDynamicConnectionsCheckBox |
|
130 .setSelection(store |
|
131 .getBoolean(PreferenceConstants.AUTO_CONNECT_DYNAMIC_CONNECTIONS_CHECKBOX)); |
|
132 |
|
133 // Set help |
|
134 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, |
|
135 TraceViewerHelpContextIDs.CONNECTION_PREFERENCES); |
|
136 |
|
137 return top; |
|
138 } |
|
139 |
|
140 /* |
|
141 * (non-Javadoc) |
|
142 * |
|
143 * @see |
|
144 * org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench) |
|
145 */ |
|
146 public void init(IWorkbench workbench) { |
|
147 } |
|
148 |
|
149 /* |
|
150 * (non-Javadoc) |
|
151 * |
|
152 * @see org.eclipse.jface.preference.PreferencePage#performOk() |
|
153 */ |
|
154 @Override |
|
155 public boolean performOk() { |
|
156 saveSettings(); |
|
157 // Preferences has been saved successfully, notifying listeners about |
|
158 // the change. Default implementation of super.performApply() calls back |
|
159 // performOK() method so notification to listeners should be only sent |
|
160 // in here. In case of Apply and OK sequence, however, the notification |
|
161 // is sent twice. Only sent the notification if the connection ID is not |
|
162 // the virtual "Current connection" |
|
163 if (conn != null |
|
164 && !conn.getIdentifier().equals( |
|
165 ConnectionHelper.CURRENT_CONNECTION_ID)) { |
|
166 TraceViewerAPI2Impl.notifyConnPrefsChanged(conn); |
|
167 } |
|
168 return super.performOk(); |
|
169 } |
|
170 |
|
171 /* |
|
172 * (non-Javadoc) |
|
173 * |
|
174 * @see org.eclipse.jface.preference.PreferencePage#performApply() |
|
175 */ |
|
176 @Override |
|
177 public void performApply() { |
|
178 saveSettings(); |
|
179 super.performApply(); |
|
180 } |
|
181 |
|
182 /* |
|
183 * (non-Javadoc) |
|
184 * |
|
185 * @see org.eclipse.jface.preference.PreferencePage#performDefaults() |
|
186 */ |
|
187 @Override |
|
188 protected void performDefaults() { |
|
189 if (getControl() != null && !getControl().isDisposed()) { |
|
190 autoConnectDynamicConnectionsCheckBox.setSelection(false); |
|
191 } |
|
192 super.performDefaults(); |
|
193 } |
|
194 |
|
195 /** |
|
196 * Saves settings |
|
197 */ |
|
198 private void saveSettings() { |
|
199 if (getControl() != null && !getControl().isDisposed()) { |
|
200 conn = ConnectionHelper |
|
201 .saveConnectionSettingsToPreferenceStore(false); |
|
202 |
|
203 store |
|
204 .setValue( |
|
205 PreferenceConstants.AUTO_CONNECT_DYNAMIC_CONNECTIONS_CHECKBOX, |
|
206 autoConnectDynamicConnectionsCheckBox |
|
207 .getSelection()); |
|
208 } |
|
209 } |
|
210 } |