1 /**********************************************************************
2 * Copyright (c) 2012 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.control
.dialogs
;
14 import java
.util
.Arrays
;
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
.Shell
;
36 * <b><u>EnableEventsDialog</u></b>
38 * Dialog box for collecting information about the events to enable.
41 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
43 // ------------------------------------------------------------------------
45 // ------------------------------------------------------------------------
47 * The icon file for this dialog box.
49 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/edit.gif"; //$NON-NLS-1$
51 // ------------------------------------------------------------------------
53 // ------------------------------------------------------------------------
55 * The dialog composite.
57 private Composite fDialogComposite
= null;
59 * The Group for the session combo box.
61 private Group fSessionsGroup
= null;
63 * The Group for the channel combo box.
65 private Group fChannelsGroup
= null;
67 * The session combo box.
69 private CCombo fSessionsCombo
= null;
71 * The channel combo box.
73 private CCombo fChannelsCombo
= null;
75 * The list of available sessions.
77 private TraceSessionComponent
[] fSessions
;
79 * True for kernel, false for UST.
81 private boolean fIsKernel
;
83 * Index in session array (selected session).
85 private int fSessionIndex
= 0;
87 * The Channel where the events should be enabled.
89 private TraceChannelComponent fChannel
;
91 * List of available channels of the selected session.
93 private TraceChannelComponent
[] fChannels
;
95 // ------------------------------------------------------------------------
97 // ------------------------------------------------------------------------
99 * Constructor of dialog box.
100 * @param shell - the shell for the dialog box
102 public GetEventInfoDialog(Shell shell
) {
104 setShellStyle(SWT
.RESIZE
);
107 // ------------------------------------------------------------------------
109 // ------------------------------------------------------------------------
112 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog#getSession()
115 public TraceSessionComponent
getSession() {
116 return fSessions
[fSessionIndex
];
121 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
124 public TraceChannelComponent
getChannel() {
130 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
133 public void setIsKernel(boolean isKernel
) {
134 fIsKernel
= isKernel
;
139 * @see org.eclipse.linuxtools.lttng.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.lttng.ui.views.control.model.impl.TraceSessionComponent[])
142 public void setSessions(TraceSessionComponent
[] sessions
) {
143 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
146 // ------------------------------------------------------------------------
148 // ------------------------------------------------------------------------
151 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
154 protected void configureShell(Shell newShell
) {
155 super.configureShell(newShell
);
156 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
157 newShell
.setImage(LTTngUiPlugin
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
162 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
165 protected Control
createDialogArea(Composite parent
) {
168 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
169 GridLayout layout
= new GridLayout(1, true);
170 fDialogComposite
.setLayout(layout
);
171 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
173 fSessionsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
174 fSessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
175 layout
= new GridLayout(1, true);
176 fSessionsGroup
.setLayout(layout
);
177 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
178 fSessionsGroup
.setLayoutData(data
);
180 fSessionsCombo
= new CCombo(fSessionsGroup
, SWT
.READ_ONLY
);
181 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
182 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
184 String items
[] = new String
[fSessions
.length
];
185 for (int i
= 0; i
< items
.length
; i
++) {
186 items
[i
] = String
.valueOf(fSessions
[i
].getName());
189 fSessionsCombo
.setItems(items
);
190 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
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
);
197 fChannelsGroup
.setLayoutData(data
);
199 fChannelsCombo
= new CCombo(fChannelsGroup
, SWT
.READ_ONLY
);
200 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
201 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
202 fChannelsCombo
.setEnabled(false);
204 fSessionsCombo
.addSelectionListener(new SelectionListener() {
206 public void widgetSelected(SelectionEvent e
) {
207 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
209 if (fSessionIndex
>= 0) {
210 TraceDomainComponent domain
= null;
211 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
212 for (int i
= 0; i
< domains
.length
; i
++) {
214 if (domains
[i
].isKernel() == fIsKernel
) {
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());
226 fChannelsCombo
.setItems(items
);
227 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
229 fChannelsCombo
.setItems(new String
[0]);
230 fChannelsCombo
.setEnabled(false);
233 fChannelsCombo
.getParent().getParent().layout();
238 public void widgetDefaultSelected(SelectionEvent e
) {
241 return fDialogComposite
;
246 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
249 protected void createButtonsForButtonBar(Composite parent
) {
250 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
255 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
258 protected void okPressed() {
260 if (fSessionsCombo
.getSelectionIndex() < 0) {
261 MessageDialog
.openError(getShell(),
262 Messages
.TraceControl_EnableEventsDialogTitle
,
263 Messages
.TraceControl_EnableEventsNoSessionError
);
267 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
269 if ((fChannels
!= null) && (fChannels
.length
> 0) && (fChannelsCombo
.getSelectionIndex() < 0)) {
270 MessageDialog
.openError(getShell(),
271 Messages
.TraceControl_EnableEventsDialogTitle
,
272 Messages
.TraceControl_EnableEventsNoChannelError
);
276 if ((fChannels
!= null) && (fChannels
.length
> 0)) {
277 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];