1 /**********************************************************************
2 * Copyright (c) 2012, 2013 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
.control
.ui
.views
.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
.control
.ui
.Activator
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.IAddContextDialog
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.messages
.Messages
;
27 import org
.eclipse
.ui
.IWorkbenchWindow
;
28 import org
.eclipse
.ui
.PlatformUI
;
29 import org
.eclipse
.ui
.progress
.UIJob
;
33 * Base command handler implementation to add contexts.
36 * @author Bernd Hufmann
38 public abstract class BaseAddContextHandler
extends BaseControlViewHandler
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
45 * The command execution parameter.
47 protected CommandParameter fParam
= null;
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
54 * Adds contexts to channel(s) and/or event(s)
57 * - a parameter instance with data for the command execution
59 * - list contexts to add
61 * - a progress monitor
62 * @throws ExecutionException
63 * If something goes wrong
65 public abstract void addContexts(CommandParameter param
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
;
68 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
70 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
77 // Make a copy for thread safety
78 final CommandParameter param
= fParam
.clone();
80 UIJob getJob
= new UIJob(Messages
.TraceControl_GetContextJob
) {
82 public IStatus
runInUIThread(IProgressMonitor monitor
) {
85 final List
<String
> availableContexts
= param
.getSession().getContextList(monitor
);
86 final IAddContextDialog dialog
= TraceControlDialogFactory
.getInstance().getAddContextDialog();
87 dialog
.setAvalibleContexts(availableContexts
);
89 if ((dialog
.open() != Window
.OK
) || (dialog
.getContexts().isEmpty())) {
90 return Status
.OK_STATUS
;
93 Job addJob
= new Job(Messages
.TraceControl_AddContextJob
) {
95 protected IStatus
run(IProgressMonitor monitor2
) {
96 Exception error
= null;
99 List
<String
> contextNames
= dialog
.getContexts();
100 addContexts(param
, contextNames
, monitor2
);
102 } catch (ExecutionException e
) {
106 // get session configuration in all cases
110 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_AddContextFailure
, error
);
112 return Status
.OK_STATUS
;
115 addJob
.setUser(true);
117 } catch (ExecutionException e
) {
118 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_GetContextFailure
, e
);
121 return Status
.OK_STATUS
;
124 getJob
.setUser(false);