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
;
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
;
37 * <b><u>EnableEventsDialog</u></b>
39 * Dialog box for collecting information about the events to enable.
42 public class GetEventInfoDialog
extends Dialog
implements IGetEventInfoDialog
{
44 // ------------------------------------------------------------------------
46 // ------------------------------------------------------------------------
48 * The icon file for this dialog box.
50 public static final String TARGET_NEW_CONNECTION_ICON_FILE
= "icons/elcl16/edit.gif"; //$NON-NLS-1$
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
56 * The dialog composite.
58 private Composite fDialogComposite
= null;
60 * The Group for the session combo box.
62 private Group fSessionsGroup
= null;
64 * The Group for the channel combo box.
66 private Group fChannelsGroup
= null;
68 * The session combo box.
70 private CCombo fSessionsCombo
= null;
72 * The channel combo box.
74 private CCombo fChannelsCombo
= null;
76 * The list of available sessions.
78 private TraceSessionComponent
[] fSessions
;
80 * True for kernel, false for UST.
82 private boolean fIsKernel
;
84 * Index in session array (selected session).
86 private int fSessionIndex
= 0;
88 * The Channel where the events should be enabled.
90 private TraceChannelComponent fChannel
;
92 * List of available channels of the selected session.
94 private TraceChannelComponent
[] fChannels
;
96 // ------------------------------------------------------------------------
98 // ------------------------------------------------------------------------
100 * Constructor of dialog box.
101 * @param shell - the shell for the dialog box
103 public GetEventInfoDialog(Shell shell
) {
105 setShellStyle(SWT
.RESIZE
);
108 // ------------------------------------------------------------------------
110 // ------------------------------------------------------------------------
113 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
116 public TraceSessionComponent
getSession() {
117 return fSessions
[fSessionIndex
];
122 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
125 public TraceChannelComponent
getChannel() {
131 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
134 public void setIsKernel(boolean isKernel
) {
135 fIsKernel
= isKernel
;
140 * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
143 public void setSessions(TraceSessionComponent
[] sessions
) {
144 fSessions
= Arrays
.copyOf(sessions
, sessions
.length
);
147 // ------------------------------------------------------------------------
149 // ------------------------------------------------------------------------
152 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
155 protected void configureShell(Shell newShell
) {
156 super.configureShell(newShell
);
157 newShell
.setText(Messages
.TraceControl_EnableEventsDialogTitle
);
158 newShell
.setImage(Activator
.getDefault().loadIcon(TARGET_NEW_CONNECTION_ICON_FILE
));
163 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
166 protected Control
createDialogArea(Composite parent
) {
169 fDialogComposite
= new Composite(parent
, SWT
.NONE
);
170 GridLayout layout
= new GridLayout(1, true);
171 fDialogComposite
.setLayout(layout
);
172 fDialogComposite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
174 fSessionsGroup
= new Group(fDialogComposite
, SWT
.SHADOW_NONE
);
175 fSessionsGroup
.setText(Messages
.TraceControl_EnableEventsSessionGroupName
);
176 layout
= new GridLayout(1, true);
177 fSessionsGroup
.setLayout(layout
);
178 GridData data
= new GridData(GridData
.FILL_HORIZONTAL
);
179 fSessionsGroup
.setLayoutData(data
);
181 fSessionsCombo
= new CCombo(fSessionsGroup
, SWT
.READ_ONLY
);
182 fSessionsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsSessionsTooltip
);
183 fSessionsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
185 String items
[] = new String
[fSessions
.length
];
186 for (int i
= 0; i
< items
.length
; i
++) {
187 items
[i
] = String
.valueOf(fSessions
[i
].getName());
190 fSessionsCombo
.setItems(items
);
191 fSessionsCombo
.setEnabled(fSessions
.length
> 0);
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
);
198 fChannelsGroup
.setLayoutData(data
);
200 fChannelsCombo
= new CCombo(fChannelsGroup
, SWT
.READ_ONLY
);
201 fChannelsCombo
.setToolTipText(Messages
.TraceControl_EnableEventsChannelsTooltip
);
202 fChannelsCombo
.setLayoutData(new GridData(GridData
.FILL_HORIZONTAL
));
203 fChannelsCombo
.setEnabled(false);
205 fSessionsCombo
.addSelectionListener(new SelectionListener() {
207 public void widgetSelected(SelectionEvent e
) {
208 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
210 if (fSessionIndex
>= 0) {
211 TraceDomainComponent domain
= null;
212 TraceDomainComponent
[] domains
= fSessions
[fSessionIndex
].getDomains();
213 for (int i
= 0; i
< domains
.length
; i
++) {
215 if (domains
[i
].isKernel() == fIsKernel
) {
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());
227 fChannelsCombo
.setItems(items
);
228 fChannelsCombo
.setEnabled(fChannels
.length
> 0);
230 fChannelsCombo
.setItems(new String
[0]);
231 fChannelsCombo
.setEnabled(false);
234 fChannelsCombo
.getParent().getParent().layout();
239 public void widgetDefaultSelected(SelectionEvent e
) {
243 getShell().setMinimumSize(new Point(300, 200));
245 return fDialogComposite
;
250 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
253 protected void createButtonsForButtonBar(Composite parent
) {
254 createButton(parent
, IDialogConstants
.OK_ID
, "&Ok", true); //$NON-NLS-1$
259 * @see org.eclipse.jface.dialogs.Dialog#okPressed()
262 protected void okPressed() {
264 if (fSessionsCombo
.getSelectionIndex() < 0) {
265 MessageDialog
.openError(getShell(),
266 Messages
.TraceControl_EnableEventsDialogTitle
,
267 Messages
.TraceControl_EnableEventsNoSessionError
);
271 fSessionIndex
= fSessionsCombo
.getSelectionIndex();
273 if ((fChannels
!= null) && (fChannels
.length
> 0) && (fChannelsCombo
.getSelectionIndex() < 0)) {
274 MessageDialog
.openError(getShell(),
275 Messages
.TraceControl_EnableEventsDialogTitle
,
276 Messages
.TraceControl_EnableEventsNoChannelError
);
280 if ((fChannels
!= null) && (fChannels
.length
> 0)) {
281 fChannel
= fChannels
[fChannelsCombo
.getSelectionIndex()];