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
.handlers
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Iterator
;
16 import java
.util
.List
;
18 import org
.eclipse
.core
.commands
.ExecutionEvent
;
19 import org
.eclipse
.core
.commands
.ExecutionException
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.core
.runtime
.IStatus
;
22 import org
.eclipse
.core
.runtime
.Status
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.jface
.viewers
.ISelection
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.jface
.window
.Window
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.ICreateChannelOnSessionDialog
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
32 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.TraceSessionState
;
33 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
35 import org
.eclipse
.ui
.IWorkbenchPage
;
38 * <b><u>CreateChannelOnSessionHandler</u></b>
40 * Command handler implementation to create a trace channel for unknown domain
44 public class CreateChannelOnSessionHandler
extends BaseControlViewHandler
{
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
50 * The session component the command is to be executed on.
52 private TraceSessionComponent fSession
= null;
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
59 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
62 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
64 final ICreateChannelOnSessionDialog dialog
= TraceControlDialogFactory
.getInstance().getCreateChannelOnSessionDialog();
66 if (dialog
.open() != Window
.OK
) {
70 Job job
= new Job(Messages
.TraceControl_ChangeChannelStateJob
) {
72 protected IStatus
run(IProgressMonitor monitor
) {
73 String errorString
= null;
75 List
<String
> channelNames
= new ArrayList
<String
>();
76 TraceDomainComponent newDomain
= new TraceDomainComponent("dummy", fSession
); //$NON-NLS-1$
77 channelNames
.add(dialog
.getChannelInfo().getName());
78 newDomain
.setIsKernel(dialog
.isKernel());
81 newDomain
.enableChannels(channelNames
, dialog
.getChannelInfo(), monitor
);
82 } catch (ExecutionException e
) {
83 if (errorString
== null) {
84 errorString
= new String();
86 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
89 // get session configuration in all cases
91 fSession
.getConfigurationFromNode(monitor
);
92 } catch (ExecutionException e
) {
93 if (errorString
== null) {
94 errorString
= new String();
96 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
99 if (errorString
!= null) {
100 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
);
102 return Status
.OK_STATUS
;
113 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
116 public boolean isEnabled() {
117 // Get workbench page for the Control View
118 IWorkbenchPage page
= getWorkbenchPage();
125 // Check if one session is selected
126 ISelection selection
= page
.getSelection(ControlView
.ID
);
127 if (selection
instanceof StructuredSelection
) {
128 StructuredSelection structered
= ((StructuredSelection
) selection
);
129 for (Iterator
<?
> iterator
= structered
.iterator(); iterator
.hasNext();) {
130 Object element
= (Object
) iterator
.next();
131 if (element
instanceof TraceSessionComponent
) {
132 // Add only TraceSessionComponents that are inactive and not destroyed
133 TraceSessionComponent session
= (TraceSessionComponent
) element
;
134 if ((session
.getSessionState() == TraceSessionState
.INACTIVE
) && (!session
.isDestroyed())) {
140 return fSession
!= null;