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
.internal
.lttng2
.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
.internal
.lttng2
.ui
.Activator
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.messages
.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
;
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
.graphics
.Point
;
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
;
34 import org
.eclipse
.swt
.widgets
.Shell
;
38 * Dialog box for collecting information about the events to enable.
41 * @author Bernd Hufmann
43 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * The icon file for this dialog box.
51 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
57 * The dialog composite.
59 private Composite fDialogComposite
= null;
61 * The Group for the session combo box.
63 private Group fSessionsGroup
= null;
65 * The Group for the channel combo box.
67 private Group fChannelsGroup
= null;
69 * The session combo box.
71 private CCombo fSessionsCombo
= null;
73 * The channel combo box.
75 private CCombo fChannelsCombo
= null;
77 * The list of available sessions.
79 private TraceSessionComponent
[] fSessions
;
81 * True for kernel, false for UST.
83 private boolean fIsKernel
;
85 * Index in session array (selected session).
87 private int fSessionIndex
= 0;
89 * The Channel where the events should be enabled.
91 private TraceChannelComponent fChannel
;
93 * List of available channels of the selected session.
95 private TraceChannelComponent
[] fChannels
;
97 // ------------------------------------------------------------------------
99 // ------------------------------------------------------------------------
101 * Constructor of dialog box.
102 * @param shell - the shell for the dialog box
104 public GetEventInfoDialog(Shell shell
) {
106 setShellStyle(SWT
.RESIZE
);
109 // ------------------------------------------------------------------------
111 // ------------------------------------------------------------------------
114 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
117 public TraceSessionComponent
getSession() {
118 return fSessions
[fSessionIndex
];
123 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
126 public TraceChannelComponent
getChannel() {
132 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
135 public void setIsKernel(boolean isKernel
) {
136 fIsKernel
= isKernel
;
141 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
144 public void setSessions(TraceSessionComponent
[] sessions
) {
145 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
148 // ------------------------------------------------------------------------
150 // ------------------------------------------------------------------------
153 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
156 protected void configureShell(Shell newShell
) {
157 super.configureShell(newShell
);
158 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
159 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
164 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
167 protected Control
createDialogArea(Composite parent
) {
170 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
171 GridLayout layout
= new GridLayout(1, true);
172 fDialogComposite
.setLayout(layout
);
173 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
175 fSessionsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
176 fSessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
177 layout
= new GridLayout(1, true);
178 fSessionsGroup
.setLayout(layout
);
179 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
180 fSessionsGroup
.setLayoutData(data
);
182 fSessionsCombo
= new CCombo(fSessionsGroup
, SWT
.READ_ONLY
);
183 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
184 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
186 String items
[] = new String
[fSessions
.length
];
187 for (int i
= 0; i
< items
.length
; i
++) {
188 items
[i
] = String
.valueOf(fSessions
[i
].getName());
191 fSessionsCombo
.setItems(items
);
192 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
194 fChannelsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
195 fChannelsGroup
.setText(Messages
.TraceControl_EnableEventsChannelGroupName
);
196 layout
= new GridLayout(1, true);
197 fChannelsGroup
.setLayout(layout
);
198 data
= new GridData(GridData
.FILL_HORIZONTAL
);
199 fChannelsGroup
.setLayoutData(data
);
201 fChannelsCombo
= new CCombo(fChannelsGroup
, SWT
.READ_ONLY
);
202 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
203 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
204 fChannelsCombo
.setEnabled(false);
206 fSessionsCombo
.addSelectionListener(new SelectionListener() {
208 public void widgetSelected(SelectionEvent e
) {
209 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
211 if (fSessionIndex
>= 0) {
212 TraceDomainComponent domain
= null;
213 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
214 for (int i
= 0; i
< domains
.length
; i
++) {
216 if (domains
[i
].isKernel() == fIsKernel
) {
222 if (domain
!= null) {
223 fChannels
= domain
.getChannels();
224 String selectionItems
[] = new String
[fChannels
.length
];
225 for (int i
= 0; i
< selectionItems
.length
; i
++) {
226 selectionItems
[i
] = String
.valueOf(fChannels
[i
].getName());
228 fChannelsCombo
.setItems(selectionItems
);
229 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
231 fChannelsCombo
.setItems(new String
[0]);
232 fChannelsCombo
.setEnabled(false);
235 fChannelsCombo
.getParent().getParent().layout();
240 public void widgetDefaultSelected(SelectionEvent e
) {
244 getShell().setMinimumSize(new Point(300, 200));
246 return fDialogComposite
;
251 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
254 protected void createButtonsForButtonBar(Composite parent
) {
255 createButton(parent
, IDialogConstants
.CANCEL_ID
, "&Cancel", true); //$NON-NLS-1$
256 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
261 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
264 protected void okPressed() {
266 if (fSessionsCombo
.getSelectionIndex() < 0) {
267 MessageDialog
.openError(getShell(),
268 Messages
.TraceControl_EnableEventsDialogTitle
,
269 Messages
.TraceControl_EnableEventsNoSessionError
);
273 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
275 if ((fChannels
!= null) && (fChannels
.length
> 0) && (fChannelsCombo
.getSelectionIndex() < 0)) {
276 MessageDialog
.openError(getShell(),
277 Messages
.TraceControl_EnableEventsDialogTitle
,
278 Messages
.TraceControl_EnableEventsNoChannelError
);
282 if ((fChannels
!= null) && (fChannels
.length
> 0)) {
283 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];