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 | **********************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.control.dialogs; | |
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; | |
19 | import org.eclipse.linuxtools.lttng.ui.LTTngUiPlugin; | |
20 | import org.eclipse.linuxtools.lttng.ui.views.control.Messages; | |
21 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceChannelComponent; | |
22 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceDomainComponent; | |
23 | import org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent; | |
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 | |
101 | * @param isKernel - a flag to indicate Kernel or UST events. | |
102 | * @param sessions - a list of available sessions | |
103 | */ | |
104 | public GetEventInfoDialog(Shell shell, boolean isKernel, TraceSessionComponent[] sessions) { | |
105 | super(shell); | |
106 | fIsKernel = isKernel; | |
107 | fSessions = Arrays.copyOf(sessions, sessions.length); | |
498704b3 | 108 | setShellStyle(SWT.RESIZE); |
6503ae0f BH |
109 | } |
110 | ||
111 | // ------------------------------------------------------------------------ | |
112 | // Accessors | |
113 | // ------------------------------------------------------------------------ | |
114 | /* | |
115 | * (non-Javadoc) | |
116 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog#getSession() | |
117 | */ | |
118 | @Override | |
119 | public TraceSessionComponent getSession() { | |
120 | return fSessions[fSessionIndex]; | |
121 | } | |
122 | ||
123 | /* | |
124 | * (non-Javadoc) | |
125 | * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog#getChannel() | |
126 | */ | |
127 | @Override | |
128 | public TraceChannelComponent getChannel() { | |
129 | return fChannel; | |
130 | } | |
131 | ||
132 | // ------------------------------------------------------------------------ | |
133 | // Operations | |
134 | // ------------------------------------------------------------------------ | |
135 | /* | |
136 | * (non-Javadoc) | |
137 | * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) | |
138 | */ | |
139 | @Override | |
140 | protected void configureShell(Shell newShell) { | |
141 | super.configureShell(newShell); | |
142 | newShell.setText(Messages.TraceControl_EnableEventsDialogTitle); | |
143 | newShell.setImage(LTTngUiPlugin.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE)); | |
144 | } | |
145 | ||
146 | /* | |
147 | * (non-Javadoc) | |
148 | * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) | |
149 | */ | |
150 | @Override | |
151 | protected Control createDialogArea(Composite parent) { | |
152 | ||
153 | // Main dialog panel | |
154 | fDialogComposite = new Composite(parent, SWT.NONE); | |
155 | GridLayout layout = new GridLayout(1, true); | |
498704b3 BH |
156 | fDialogComposite.setLayout(layout); |
157 | fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH)); | |
158 | ||
6503ae0f BH |
159 | fSessionsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); |
160 | fSessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName); | |
161 | layout = new GridLayout(1, true); | |
162 | fSessionsGroup.setLayout(layout); | |
6503ae0f BH |
163 | GridData data = new GridData(GridData.FILL_HORIZONTAL); |
164 | fSessionsGroup.setLayoutData(data); | |
165 | ||
166 | fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY); | |
167 | fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip); | |
168 | fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
6503ae0f BH |
169 | |
170 | String items[] = new String[fSessions.length]; | |
171 | for (int i = 0; i < items.length; i++) { | |
172 | items[i] = String.valueOf(fSessions[i].getName()); | |
173 | } | |
174 | ||
175 | fSessionsCombo.setItems(items); | |
176 | fSessionsCombo.setEnabled(fSessions.length > 0); | |
177 | ||
178 | fChannelsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
179 | fChannelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName); | |
180 | layout = new GridLayout(1, true); | |
181 | fChannelsGroup.setLayout(layout); | |
182 | data = new GridData(GridData.FILL_HORIZONTAL); | |
6503ae0f BH |
183 | fChannelsGroup.setLayoutData(data); |
184 | ||
185 | fChannelsCombo = new CCombo(fChannelsGroup, SWT.READ_ONLY); | |
186 | fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip); | |
6503ae0f BH |
187 | fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
188 | fChannelsCombo.setEnabled(false); | |
189 | ||
190 | fSessionsCombo.addSelectionListener(new SelectionListener() { | |
191 | @Override | |
192 | public void widgetSelected(SelectionEvent e) { | |
193 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
194 | ||
195 | if (fSessionIndex >= 0) { | |
196 | TraceDomainComponent domain = null; | |
197 | TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains(); | |
198 | for (int i = 0; i < domains.length; i++) { | |
199 | ||
200 | if (domains[i].isKernel() == fIsKernel) { | |
201 | domain = domains[i]; | |
202 | break; | |
203 | } | |
204 | } | |
205 | ||
206 | if (domain != null) { | |
207 | fChannels = domain.getChannels(); | |
208 | String items[] = new String[fChannels.length]; | |
209 | for (int i = 0; i < items.length; i++) { | |
210 | items[i] = String.valueOf(fChannels[i].getName()); | |
211 | } | |
212 | fChannelsCombo.setItems(items); | |
213 | fChannelsCombo.setEnabled(fChannels.length > 0); | |
214 | } else { | |
215 | fChannelsCombo.setItems(new String[0]); | |
216 | fChannelsCombo.setEnabled(false); | |
217 | fChannels = null; | |
218 | } | |
219 | fChannelsCombo.getParent().getParent().layout(); | |
220 | } | |
221 | } | |
222 | ||
223 | @Override | |
224 | public void widgetDefaultSelected(SelectionEvent e) { | |
225 | } | |
226 | }); | |
6503ae0f BH |
227 | return fDialogComposite; |
228 | } | |
229 | ||
230 | /* | |
231 | * (non-Javadoc) | |
232 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
233 | */ | |
234 | @Override | |
235 | protected void createButtonsForButtonBar(Composite parent) { | |
236 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ | |
237 | } | |
238 | ||
239 | /* | |
240 | * (non-Javadoc) | |
241 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
242 | */ | |
243 | @Override | |
244 | protected void okPressed() { | |
245 | ||
246 | if (fSessionsCombo.getSelectionIndex() < 0) { | |
247 | MessageDialog.openError(getShell(), | |
248 | Messages.TraceControl_EnableEventsDialogTitle, | |
249 | Messages.TraceControl_EnableEventsNoSessionError); | |
250 | return; | |
251 | } | |
252 | ||
253 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
254 | ||
255 | if ((fChannels != null) && (fChannels.length > 0) && (fChannelsCombo.getSelectionIndex() < 0)) { | |
256 | MessageDialog.openError(getShell(), | |
257 | Messages.TraceControl_EnableEventsDialogTitle, | |
258 | Messages.TraceControl_EnableEventsNoChannelError); | |
259 | return; | |
260 | } | |
261 | ||
262 | if ((fChannels != null) && (fChannels.length > 0)) { | |
263 | fChannel = fChannels[fChannelsCombo.getSelectionIndex()]; | |
264 | } | |
265 | ||
266 | super.okPressed(); | |
267 | } | |
268 | } |