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