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
.dialogs
.IAddContextDialog
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.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 abstract public class BaseAddContextHandler
extends BaseControlViewHandler
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 * The command execution parameter.
46 protected CommandParameter fParam
= null;
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
53 * Adds contexts to channel(s) and/or event(s)
56 * - a parameter instance with data for the command execution
58 * - list contexts to add
60 * - a progress monitor
61 * @throws ExecutionException
62 * If something goes wrong
64 abstract public void addContexts(CommandParameter param
, List
<String
> contextNames
, IProgressMonitor monitor
) throws ExecutionException
;
68 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
71 public Object
execute(ExecutionEvent event
) throws ExecutionException
{
73 final IWorkbenchWindow window
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow();
80 // Make a copy for thread safety
81 final CommandParameter param
= fParam
.clone();
83 UIJob getJob
= new UIJob(Messages
.TraceControl_GetContextJob
) {
85 public IStatus
runInUIThread(IProgressMonitor monitor
) {
88 final List
<String
> availableContexts
= param
.getSession().getContextList(monitor
);
89 final IAddContextDialog dialog
= TraceControlDialogFactory
.getInstance().getAddContextDialog();
90 dialog
.setAvalibleContexts(availableContexts
);
92 if ((dialog
.open() != Window
.OK
) || (dialog
.getContexts().isEmpty())) {
93 return Status
.OK_STATUS
;
96 Job addJob
= new Job(Messages
.TraceControl_AddContextJob
) {
98 protected IStatus
run(IProgressMonitor monitor2
) {
99 Exception error
= null;
102 List
<String
> contextNames
= dialog
.getContexts();
103 addContexts(param
, contextNames
, monitor2
);
105 } catch (ExecutionException e
) {
109 // get session configuration in all cases
113 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_AddContextFailure
, error
);
115 return Status
.OK_STATUS
;
118 addJob
.setUser(true);
120 } catch (ExecutionException e
) {
121 return new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, Messages
.TraceControl_GetContextFailure
, e
);
124 return Status
.OK_STATUS
;
127 getJob
.setUser(false);