Commit | Line | Data |
---|---|---|
6503ae0f BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2012 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
31a6a4e4 | 12 | package org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs; |
6503ae0f BH |
13 | |
14 | import java.util.Arrays; | |
15 | ||
16 | import org.eclipse.jface.dialogs.Dialog; | |
17 | import org.eclipse.jface.dialogs.IDialogConstants; | |
18 | import org.eclipse.jface.dialogs.MessageDialog; | |
31a6a4e4 BH |
19 | import org.eclipse.linuxtools.internal.lttng.ui.Activator; |
20 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.Messages; | |
21 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceChannelComponent; | |
22 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceDomainComponent; | |
23 | import org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceSessionComponent; | |
6503ae0f BH |
24 | import org.eclipse.swt.SWT; |
25 | import org.eclipse.swt.custom.CCombo; | |
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.Group; | |
6503ae0f BH |
33 | import org.eclipse.swt.widgets.Shell; |
34 | ||
35 | /** | |
36 | * <b><u>EnableEventsDialog</u></b> | |
37 | * <p> | |
38 | * Dialog box for collecting information about the events to enable. | |
39 | * </p> | |
40 | */ | |
41 | public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog { | |
42 | ||
43 | // ------------------------------------------------------------------------ | |
44 | // Constants | |
45 | // ------------------------------------------------------------------------ | |
46 | /** | |
47 | * The icon file for this dialog box. | |
48 | */ | |
49 | public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ | |
50 | ||
51 | // ------------------------------------------------------------------------ | |
52 | // Attributes | |
53 | // ------------------------------------------------------------------------ | |
54 | /** | |
55 | * The dialog composite. | |
56 | */ | |
57 | private Composite fDialogComposite = null; | |
58 | /** | |
59 | * The Group for the session combo box. | |
60 | */ | |
61 | private Group fSessionsGroup = null; | |
62 | /** | |
63 | * The Group for the channel combo box. | |
64 | */ | |
65 | private Group fChannelsGroup = null; | |
66 | /** | |
67 | * The session combo box. | |
68 | */ | |
69 | private CCombo fSessionsCombo = null; | |
70 | /** | |
71 | * The channel combo box. | |
72 | */ | |
73 | private CCombo fChannelsCombo = null; | |
74 | /** | |
75 | * The list of available sessions. | |
76 | */ | |
77 | private TraceSessionComponent[] fSessions; | |
78 | /** | |
79 | * True for kernel, false for UST. | |
80 | */ | |
81 | private boolean fIsKernel; | |
82 | /** | |
83 | * Index in session array (selected session). | |
84 | */ | |
85 | private int fSessionIndex = 0; | |
86 | /** | |
87 | * The Channel where the events should be enabled. | |
88 | */ | |
89 | private TraceChannelComponent fChannel; | |
90 | /** | |
91 | * List of available channels of the selected session. | |
92 | */ | |
93 | private TraceChannelComponent[] fChannels; | |
94 | ||
95 | // ------------------------------------------------------------------------ | |
96 | // Constructors | |
97 | // ------------------------------------------------------------------------ | |
98 | /** | |
99 | * Constructor of dialog box. | |
100 | * @param shell - the shell for the dialog box | |
6503ae0f | 101 | */ |
d132bcc7 | 102 | public GetEventInfoDialog(Shell shell) { |
6503ae0f | 103 | super(shell); |
498704b3 | 104 | setShellStyle(SWT.RESIZE); |
6503ae0f BH |
105 | } |
106 | ||
107 | // ------------------------------------------------------------------------ | |
108 | // Accessors | |
109 | // ------------------------------------------------------------------------ | |
110 | /* | |
111 | * (non-Javadoc) | |
31a6a4e4 | 112 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableEventsDialog#getSession() |
6503ae0f BH |
113 | */ |
114 | @Override | |
115 | public TraceSessionComponent getSession() { | |
116 | return fSessions[fSessionIndex]; | |
117 | } | |
118 | ||
119 | /* | |
120 | * (non-Javadoc) | |
31a6a4e4 | 121 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IEnableEventsDialog#getChannel() |
6503ae0f BH |
122 | */ |
123 | @Override | |
124 | public TraceChannelComponent getChannel() { | |
125 | return fChannel; | |
126 | } | |
127 | ||
d132bcc7 BH |
128 | /* |
129 | * (non-Javadoc) | |
31a6a4e4 | 130 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean) |
d132bcc7 BH |
131 | */ |
132 | @Override | |
133 | public void setIsKernel(boolean isKernel) { | |
134 | fIsKernel = isKernel; | |
135 | } | |
136 | ||
137 | /* | |
138 | * (non-Javadoc) | |
31a6a4e4 | 139 | * @see org.eclipse.linuxtools.internal.lttng.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng.ui.views.control.model.impl.TraceSessionComponent[]) |
d132bcc7 BH |
140 | */ |
141 | @Override | |
142 | public void setSessions(TraceSessionComponent[] sessions) { | |
143 | fSessions = Arrays.copyOf(sessions, sessions.length); | |
144 | } | |
145 | ||
6503ae0f BH |
146 | // ------------------------------------------------------------------------ |
147 | // Operations | |
148 | // ------------------------------------------------------------------------ | |
149 | /* | |
150 | * (non-Javadoc) | |
151 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
152 | */ | |
153 | @Override | |
154 | protected void configureShell(Shell newShell) { | |
155 | super.configureShell(newShell); | |
156 | newShell.setText(Messages.TraceControl_EnableEventsDialogTitle); | |
31a6a4e4 | 157 | newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE)); |
6503ae0f BH |
158 | } |
159 | ||
160 | /* | |
161 | * (non-Javadoc) | |
162 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
163 | */ | |
164 | @Override | |
165 | protected Control createDialogArea(Composite parent) { | |
166 | ||
167 | // Main dialog panel | |
168 | fDialogComposite = new Composite(parent, SWT.NONE); | |
169 | GridLayout layout = new GridLayout(1, true); | |
498704b3 BH |
170 | fDialogComposite.setLayout(layout); |
171 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
172 | ||
6503ae0f BH |
173 | fSessionsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
174 | fSessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName); | |
175 | layout = new GridLayout(1, true); | |
176 | fSessionsGroup.setLayout(layout); | |
6503ae0f BH |
177 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
178 | fSessionsGroup.setLayoutData(data); | |
179 | ||
180 | fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY); | |
181 | fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip); | |
182 | fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
6503ae0f BH |
183 | |
184 | String items[] = new String[fSessions.length]; | |
185 | for (int i = 0; i < items.length; i++) { | |
186 | items[i] = String.valueOf(fSessions[i].getName()); | |
187 | } | |
188 | ||
189 | fSessionsCombo.setItems(items); | |
190 | fSessionsCombo.setEnabled(fSessions.length > 0); | |
191 | ||
192 | fChannelsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
193 | fChannelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName); | |
194 | layout = new GridLayout(1, true); | |
195 | fChannelsGroup.setLayout(layout); | |
196 | data = new GridData(GridData.FILL_HORIZONTAL); | |
6503ae0f BH |
197 | fChannelsGroup.setLayoutData(data); |
198 | ||
199 | fChannelsCombo = new CCombo(fChannelsGroup, SWT.READ_ONLY); | |
200 | fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip); | |
6503ae0f BH |
201 | fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
202 | fChannelsCombo.setEnabled(false); | |
203 | ||
204 | fSessionsCombo.addSelectionListener(new SelectionListener() { | |
205 | @Override | |
206 | public void widgetSelected(SelectionEvent e) { | |
207 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
208 | ||
209 | if (fSessionIndex >= 0) { | |
210 | TraceDomainComponent domain = null; | |
211 | TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains(); | |
212 | for (int i = 0; i < domains.length; i++) { | |
213 | ||
214 | if (domains[i].isKernel() == fIsKernel) { | |
215 | domain = domains[i]; | |
216 | break; | |
217 | } | |
218 | } | |
219 | ||
220 | if (domain != null) { | |
221 | fChannels = domain.getChannels(); | |
222 | String items[] = new String[fChannels.length]; | |
223 | for (int i = 0; i < items.length; i++) { | |
224 | items[i] = String.valueOf(fChannels[i].getName()); | |
225 | } | |
226 | fChannelsCombo.setItems(items); | |
227 | fChannelsCombo.setEnabled(fChannels.length > 0); | |
228 | } else { | |
229 | fChannelsCombo.setItems(new String[0]); | |
230 | fChannelsCombo.setEnabled(false); | |
231 | fChannels = null; | |
232 | } | |
233 | fChannelsCombo.getParent().getParent().layout(); | |
234 | } | |
235 | } | |
236 | ||
237 | @Override | |
238 | public void widgetDefaultSelected(SelectionEvent e) { | |
239 | } | |
240 | }); | |
6503ae0f BH |
241 | return fDialogComposite; |
242 | } | |
243 | ||
244 | /* | |
245 | * (non-Javadoc) | |
246 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
247 | */ | |
248 | @Override | |
249 | protected void createButtonsForButtonBar(Composite parent) { | |
250 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ | |
251 | } | |
252 | ||
253 | /* | |
254 | * (non-Javadoc) | |
255 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
256 | */ | |
257 | @Override | |
258 | protected void okPressed() { | |
259 | ||
260 | if (fSessionsCombo.getSelectionIndex() < 0) { | |
261 | MessageDialog.openError(getShell(), | |
262 | Messages.TraceControl_EnableEventsDialogTitle, | |
263 | Messages.TraceControl_EnableEventsNoSessionError); | |
264 | return; | |
265 | } | |
266 | ||
267 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
268 | ||
269 | if ((fChannels != null) && (fChannels.length > 0) && (fChannelsCombo.getSelectionIndex() < 0)) { | |
270 | MessageDialog.openError(getShell(), | |
271 | Messages.TraceControl_EnableEventsDialogTitle, | |
272 | Messages.TraceControl_EnableEventsNoChannelError); | |
273 | return; | |
274 | } | |
275 | ||
276 | if ((fChannels != null) && (fChannels.length > 0)) { | |
277 | fChannel = fChannels[fChannelsCombo.getSelectionIndex()]; | |
278 | } | |
279 | ||
280 | super.okPressed(); | |
281 | } | |
282 | } |