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; | |
33 | import org.eclipse.swt.widgets.Label; | |
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 | */ | |
50 | public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ | |
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 | |
102 | * @param isKernel - a flag to indicate Kernel or UST events. | |
103 | * @param sessions - a list of available sessions | |
104 | */ | |
105 | public GetEventInfoDialog(Shell shell, boolean isKernel, TraceSessionComponent[] sessions) { | |
106 | super(shell); | |
107 | fIsKernel = isKernel; | |
108 | fSessions = Arrays.copyOf(sessions, sessions.length); | |
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); | |
156 | fDialogComposite.setLayout(layout); | |
157 | Label label = new Label(fDialogComposite, SWT.NONE); | |
158 | // a simple way to make dialog wider :-) | |
159 | label.setText(" "); //$NON-NLS-1$ | |
160 | fSessionsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
161 | fSessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName); | |
162 | layout = new GridLayout(1, true); | |
163 | fSessionsGroup.setLayout(layout); | |
164 | // GridData data = new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1); | |
165 | GridData data = new GridData(GridData.FILL_HORIZONTAL); | |
166 | fSessionsGroup.setLayoutData(data); | |
167 | ||
168 | fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY); | |
169 | fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip); | |
170 | fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
171 | // fSessionsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1)); | |
172 | ||
173 | String items[] = new String[fSessions.length]; | |
174 | for (int i = 0; i < items.length; i++) { | |
175 | items[i] = String.valueOf(fSessions[i].getName()); | |
176 | } | |
177 | ||
178 | fSessionsCombo.setItems(items); | |
179 | fSessionsCombo.setEnabled(fSessions.length > 0); | |
180 | ||
181 | fChannelsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE); | |
182 | fChannelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName); | |
183 | layout = new GridLayout(1, true); | |
184 | fChannelsGroup.setLayout(layout); | |
185 | data = new GridData(GridData.FILL_HORIZONTAL); | |
186 | // data = new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1); | |
187 | fChannelsGroup.setLayoutData(data); | |
188 | ||
189 | fChannelsCombo = new CCombo(fChannelsGroup, SWT.READ_ONLY); | |
190 | fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip); | |
191 | // fChannelsCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1)); | |
192 | fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); | |
193 | fChannelsCombo.setEnabled(false); | |
194 | ||
195 | fSessionsCombo.addSelectionListener(new SelectionListener() { | |
196 | @Override | |
197 | public void widgetSelected(SelectionEvent e) { | |
198 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
199 | ||
200 | if (fSessionIndex >= 0) { | |
201 | TraceDomainComponent domain = null; | |
202 | TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains(); | |
203 | for (int i = 0; i < domains.length; i++) { | |
204 | ||
205 | if (domains[i].isKernel() == fIsKernel) { | |
206 | domain = domains[i]; | |
207 | break; | |
208 | } | |
209 | } | |
210 | ||
211 | if (domain != null) { | |
212 | fChannels = domain.getChannels(); | |
213 | String items[] = new String[fChannels.length]; | |
214 | for (int i = 0; i < items.length; i++) { | |
215 | items[i] = String.valueOf(fChannels[i].getName()); | |
216 | } | |
217 | fChannelsCombo.setItems(items); | |
218 | fChannelsCombo.setEnabled(fChannels.length > 0); | |
219 | } else { | |
220 | fChannelsCombo.setItems(new String[0]); | |
221 | fChannelsCombo.setEnabled(false); | |
222 | fChannels = null; | |
223 | } | |
224 | fChannelsCombo.getParent().getParent().layout(); | |
225 | } | |
226 | } | |
227 | ||
228 | @Override | |
229 | public void widgetDefaultSelected(SelectionEvent e) { | |
230 | } | |
231 | }); | |
232 | // label.setText(""); | |
233 | return fDialogComposite; | |
234 | } | |
235 | ||
236 | /* | |
237 | * (non-Javadoc) | |
238 | * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) | |
239 | */ | |
240 | @Override | |
241 | protected void createButtonsForButtonBar(Composite parent) { | |
242 | createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$ | |
243 | } | |
244 | ||
245 | /* | |
246 | * (non-Javadoc) | |
247 | * @see org.eclipse.jface.dialogs.Dialog#okPressed() | |
248 | */ | |
249 | @Override | |
250 | protected void okPressed() { | |
251 | ||
252 | if (fSessionsCombo.getSelectionIndex() < 0) { | |
253 | MessageDialog.openError(getShell(), | |
254 | Messages.TraceControl_EnableEventsDialogTitle, | |
255 | Messages.TraceControl_EnableEventsNoSessionError); | |
256 | return; | |
257 | } | |
258 | ||
259 | fSessionIndex = fSessionsCombo.getSelectionIndex(); | |
260 | ||
261 | if ((fChannels != null) && (fChannels.length > 0) && (fChannelsCombo.getSelectionIndex() < 0)) { | |
262 | MessageDialog.openError(getShell(), | |
263 | Messages.TraceControl_EnableEventsDialogTitle, | |
264 | Messages.TraceControl_EnableEventsNoChannelError); | |
265 | return; | |
266 | } | |
267 | ||
268 | if ((fChannels != null) && (fChannels.length > 0)) { | |
269 | fChannel = fChannels[fChannelsCombo.getSelectionIndex()]; | |
270 | } | |
271 | ||
272 | super.okPressed(); | |
273 | } | |
274 | } |