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
.List
;
16 import org
.eclipse
.core
.commands
.ExecutionEvent
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.core
.runtime
.jobs
.Job
;
22 import org
.eclipse
.jface
.window
.Window
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.Messages
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.IAddContextDialog
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
27 import org
.eclipse
.ui
.IWorkbenchWindow
;
28 import org
.eclipse
.ui
.PlatformUI
;
29 import org
.eclipse
.ui
.progress
.UIJob
;
32 * <b><u>BaseAddContextHandler</u></b>
34 * Base command handler implementation to add contexts.
37 abstract public class BaseAddContextHandler
extends BaseControlViewHandler
{
39 // ------------------------------------------------------------------------
41 // ------------------------------------------------------------------------
43 * The command execution parameter.
45 protected CommandParameter fParam
= null;
47 // ------------------------------------------------------------------------
49 // ------------------------------------------------------------------------
52 * Adds contexts to channel(s) and/or event(s)
53 * @param param - a parameter instance with data for the command execution
54 * @param contextNames - list contexts to add
55 * @param monitor - a progress monitor
56 * @throws ExecutionException
58 abstract public void addContexts(CommandParameter param
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
;
62 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
65 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
67 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
74 // Make a copy for thread safety
75 final CommandParameter param
= fParam
.clone();
77 UIJob getJob
= new UIJob(Messages
.TraceControl_GetContextJob
) {
79 public IStatus
runInUIThread(IProgressMonitor monitor
) {
82 final List
<String
> availableContexts
= param
.getSession().getContextList(monitor
);
83 final IAddContextDialog dialog
= TraceControlDialogFactory
.getInstance().getAddContextDialog();
84 dialog
.setAvalibleContexts(availableContexts
);
86 if ((dialog
.open() != Window
.OK
) || (dialog
.getContexts().isEmpty())) {
87 return Status
.OK_STATUS
;
90 Job addJob
= new Job(Messages
.TraceControl_AddContextJob
) {
92 protected IStatus
run(IProgressMonitor monitor
) {
93 StringBuffer errorString
= new StringBuffer();
96 List
<String
> contextNames
= dialog
.getContexts();
97 addContexts(param
, contextNames
, monitor
);
99 } catch (ExecutionException e
) {
100 errorString
.append(e
.toString());
101 errorString
.append('\n');
104 // get session configuration in all cases
106 param
.getSession().getConfigurationFromNode(monitor
);
107 } catch (ExecutionException e
) {
108 errorString
.append(Messages
.TraceControl_ListSessionFailure
);
109 errorString
.append(": "); //$NON-NLS-1$
110 errorString
.append(e
.toString());
113 if (errorString
.length() > 0) {
114 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, errorString
.toString());
116 return Status
.OK_STATUS
;
119 addJob
.setUser(true);
121 } catch (ExecutionException e
) {
122 return new Status(Status
.ERROR
, Activator
.PLUGIN_ID
, e
.toString());
125 return Status
.OK_STATUS
;
128 getJob
.setUser(false);