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
.lttng
.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
.lttng
.ui
.Activator
;
28 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.ControlView
;
29 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.Messages
;
30 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.dialogs
.ICreateChannelDialog
;
31 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
32 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.TraceSessionState
;
33 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.TraceDomainComponent
;
34 import org
.eclipse
.linuxtools
.internal
.lttng
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
35 import org
.eclipse
.ui
.IWorkbenchPage
;
38 * <b><u>CreateChannelOnDomainHandler</u></b>
40 * Command handler implementation to create a trace channel for known domain.
43 public class CreateChannelOnDomainHandler
extends BaseControlViewHandler
{
45 // ------------------------------------------------------------------------
47 // ------------------------------------------------------------------------
49 * The the domain component the command is to be executed on.
51 private TraceDomainComponent fDomain
;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
58 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
61 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
63 // Get channel information from user
64 final ICreateChannelDialog dialog
= TraceControlDialogFactory
.getInstance().getCreateChannelDialog();
65 dialog
.setDomainComponent(fDomain
);
67 if (dialog
.open() != Window
.OK
) {
71 Job job
= new Job(Messages
.TraceControl_ChangeChannelStateJob
) {
73 protected IStatus
run(IProgressMonitor monitor
) {
74 String errorString
= null;
76 List
<String
> channelNames
= new ArrayList
<String
>();
77 channelNames
.add(dialog
.getChannelInfo().getName());
80 fDomain
.enableChannels(channelNames
, dialog
.getChannelInfo(), monitor
);
81 } catch (ExecutionException e
) {
82 if (errorString
== null) {
83 errorString
= new String();
85 errorString
+= e
.toString() + "\n"; //$NON-NLS-1$
88 // get session configuration in all cases
90 fDomain
.getConfigurationFromNode(monitor
);
91 } catch (ExecutionException e
) {
92 if (errorString
== null) {
93 errorString
= new String();
95 errorString
+= Messages
.TraceControl_ListSessionFailure
+ ": " + e
.toString(); //$NON-NLS-1$
98 if (errorString
!= null) {
99 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
);
101 return Status
.OK_STATUS
;
113 * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
116 public boolean isEnabled() {
118 // Get workbench page for the Control View
119 IWorkbenchPage page
= getWorkbenchPage();
125 // Check if one domain 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 TraceDomainComponent
) {
132 TraceDomainComponent domain
= (TraceDomainComponent
) element
;
133 TraceSessionComponent session
= (TraceSessionComponent
) domain
.getParent();
134 // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
135 if ((session
.getSessionState() == TraceSessionState
.INACTIVE
) && (!session
.isDestroyed())) {
141 return fDomain
!= null;