Add support for LTTng 2.0 command add-context
authorBernd Hufmann <bhufmann@gmail.com>
Wed, 4 Apr 2012 18:12:59 +0000 (14:12 -0400)
committerBernd Hufmann <bhufmann@gmail.com>
Tue, 10 Apr 2012 12:20:39 +0000 (08:20 -0400)
18 files changed:
org.eclipse.linuxtools.lttng2.ui/plugin.properties
org.eclipse.linuxtools.lttng2.ui/plugin.xml
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/Messages.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/AddContextDialog.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/TraceControlDialogFactory.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java [new file with mode: 0644]
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/messages.properties
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceChannelComponent.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceDomainComponent.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceEventComponent.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/model/impl/TraceSessionComponent.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/ILttngControlService.java
org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/service/LTTngControlService.java

index 21f0793a20aaf339b12ed12fc57541952a4469f9..231557ac676471eb711beb34da956c2a5a4129be 100644 (file)
@@ -62,37 +62,6 @@ commands.experiment.rename.description = Rename an LTTng Experiment
 commands.experiment.delete = Delete Experiment
 commands.experiment.delete.description = Delete an LTTng Experiment
 
-
-# trace control (RSE) properties
-lttng.rse.subsystem.type.name=LTTng
-lttng.rse.subsystem.type.description=LTTng TCF Subsystem
-lttng.rse.subsystem.config.name = LTTng Tracing
-lttng.rse.subsystem.config.description = LTTng Tracing Subsystem Configuration
-
-action.set.label = LTTng RSE action set
-action.set.description = LTTng RSE action set
-
-menu.lttng.label = LTTng
-action.stop.label = Stop
-action.stop.tooltip = Stop the selected trace
-action.pause.label = Pause
-action.pause.tooltip = Pause tracing
-action.start.label = Start
-action.start.tooltip = Start tracing
-action.newtrace.label = New Trace
-action.newtrace.tooltip = Create a new trace
-action.configuretrace.label = Configure Trace
-action.configuretrace.tooltip = Configure the selected trace
-action.browse.label = Browse Trace
-action.browse.tooltip = Browse the trace folder of selected trace
-action.configuremarkers.label = Configure Markers
-action.configuremarkers.tooltip = Configure the markers of selected target
-action.delete.label = Delete Trace
-action.delete.tooltip = Delete the selected trace
-
-action.import.label = Import To Project
-action.import.tooltip = Import selected trace to a project
-
 # LTTng 2.0 trace control commands
 trace.control.rse.system.type.name=LTTng (v2.0 or later)
 trace.control.rse.system.type.description=LTTng Trace Control (v2.0 or later) 
@@ -112,7 +81,6 @@ commands.control.disconnect.description=Disconnect to Target Node
 commands.control.refresh=Refresh
 commands.control.refresh.description=Refresh Node Configuration
 
-
 commands.control.delete=Delete
 commands.control.delete.description=Delete Target Node
 
@@ -137,7 +105,6 @@ commands.control.start.description=Start Trace Session
 commands.control.stop=Stop
 commands.control.stop.description=Stop Trace Session
 
-#commands.control.enable.event=Enable
 commands.control.enable.assign.description=Assign Event to Session and Channel and Enable Event 
 
 commands.control.enable.event=Enable Event
@@ -149,6 +116,8 @@ commands.control.enable.eventOnDomain.description=Enable Event on Default Channe
 commands.control.enable.eventOnSession=Enable Event (default channel)
 commands.control.enable.eventOnSession.description=Enable Event on Default Channel
 
-
 commands.control.disable.event=Disable Event
 commands.control.disable.event.description=Disable Event
+
+commands.control.add.context=Add Context
+commands.control.add.context.description=Add Context to Channel(s) and/or Event(s)
index 135a71264f46b1d16e25ee08c64e69862bd937cd..e332ce4a8ae7b2876639005a0fad12a6feaade32 100644 (file)
             id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.enableEventOnSession"
             name="%commands.control.enable.eventOnSession">
       </command>
-      
+
+      <command
+            categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+            description="%commands.control.add.context.description"
+            id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnDomain"
+            name="%commands.control.add.context">
+      </command>
+
+      <command
+            categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+            description="%commands.control.add.context.description"
+            id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnChannel"
+            name="%commands.control.add.context">
+      </command>
+
+      <command
+            categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+            description="%commands.control.add.context.description"
+            id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnEvent"
+            name="%commands.control.add.context">
+      </command>
+
    </extension>
    <extension
          point="org.eclipse.ui.menus">
                </with>
             </visibleWhen>
          </command>
-
          <command
                commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.enableEventOnChannel"
                icon="icons/elcl16/edit.gif"
                </with>
             </visibleWhen>
          </command>
-
-
-
+         <command
+               commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnDomain"
+               icon="icons/elcl16/edit.gif"
+               label="%commands.control.add.context"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="activeMenuSelection">
+                  <and>
+                     <iterate
+                           operator="or">
+                        <instanceof
+                              value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent">
+                        </instanceof>
+                     </iterate>
+                     <count
+                           value="1">
+                     </count>
+                  </and>
+               </with>
+            </visibleWhen>
+         </command>
+         <command
+               commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnChannel"
+               icon="icons/elcl16/edit.gif"
+               label="%commands.control.add.context"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="activeMenuSelection">
+                  <and>
+                     <iterate
+                           operator="or">
+                        <instanceof
+                              value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent">
+                        </instanceof>
+                     </iterate>
+                     <count
+                           value="1">
+                     </count>
+                  </and>
+               </with>
+            </visibleWhen>
+         </command>
+         <command
+               commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnEvent"
+               icon="icons/elcl16/edit.gif"
+               label="%commands.control.add.context"
+               style="push">
+            <visibleWhen
+                  checkEnabled="false">
+               <with
+                     variable="activeMenuSelection">
+                  <and>
+                     <iterate
+                           operator="or">
+                        <instanceof
+                              value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent">
+                        </instanceof>
+                     </iterate>
+                     <count
+                           value="1">
+                     </count>
+                  </and>
+               </with>
+            </visibleWhen>
+         </command>
       </menuContribution>
       
    </extension>
             </with>
          </activeWhen>
       </handler>
+      
+      <handler
+            class="org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.AddContextOnDomainHandler"
+            commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnDomain">
+         <activeWhen>
+            <with
+                  variable="selection">
+               <iterate
+                     operator="or">
+                  <instanceof
+                        value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent">
+                  </instanceof>
+               </iterate>
+            </with>
+         </activeWhen>
+      </handler>
+
+      <handler
+            class="org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.AddContextOnChannelHandler"
+            commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnChannel">
+         <activeWhen>
+            <with
+                  variable="selection">
+               <iterate
+                     operator="or">
+                  <instanceof
+                        value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent">
+                  </instanceof>
+               </iterate>
+            </with>
+         </activeWhen>
+      </handler>
+
+      <handler
+            class="org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.AddContextOnEventHandler"
+            commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.addContextOnEvent">
+         <activeWhen>
+            <with
+                  variable="selection">
+               <iterate
+                     operator="or">
+                  <instanceof
+                        value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent">
+                  </instanceof>
+               </iterate>
+            </with>
+         </activeWhen>
+      </handler>
+      
    </extension>
    
     <extension
index 6c9981a95d5b09f3402b2287815e213370bd3d07..ea48be8efb2a11c2bedf59155df63d129ada61a3 100644 (file)
@@ -58,6 +58,9 @@ final public class Messages extends NLS {
     public static String TraceControl_EnableEventsFailure;
     public static String TraceControl_DisableEventsJob;
     
+    public static String TraceControl_GetContextJob;
+    public static String TraceControl_AddContextJob;
+    
     // Dialogs
     public static String TraceControl_NewDialogTitle;
     public static String TraceControl_NewNodeExistingConnectionGroupName;
@@ -132,6 +135,10 @@ final public class Messages extends NLS {
     public static String TraceControl_InvalidLogLevelEventNameError;
     public static String TraceControl_InvalidLogLevel;
     
+    public static String TraceControl_AddContextDialogTitle;
+    public static String TraceControl_AddContextAvailableContextsLabel;
+    public static String TraceControl_AddContextAvailableContextsTooltip;
+    public static String TraceControl_AddContextAllLabel;
 
     // Tree structure strings
     public static String TraceControl_KernelDomainDisplayName;
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/AddContextDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/AddContextDialog.java
new file mode 100644 (file)
index 0000000..9533329
--- /dev/null
@@ -0,0 +1,394 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * <b><u>AddContextDialog</u></b>
+ * <p>
+ * Dialog box for collecting information about contexts to be added to channels/events.
+ * </p>
+ */
+public class AddContextDialog extends Dialog implements IAddContextDialog  {
+
+    // ------------------------------------------------------------------------
+    // Constants
+    // ------------------------------------------------------------------------
+    
+    /**
+     * The icon file for this dialog box.
+     */
+    public static final String ADD_CONTEXT_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ 
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    /**
+     * The dialog composite.
+     */
+    private Composite fDialogComposite;
+    /**
+     * A tree viewer for displaying and selection of available contexts.
+     */
+    private CheckboxTreeViewer fContextsViewer;
+    /**
+     * A Tree model for the checkbox tree viewer.
+     */
+    private ContextModel fContextModel = new ContextModel();
+    /**
+     * The contexts to add.
+     */
+    private List<String> fSelectedContexts = new ArrayList<String>();
+    
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+    /**
+     * Constructor
+     * @param shell - a shell for the display of the dialog
+     */
+    public AddContextDialog(Shell shell) {
+        super(shell);
+        setShellStyle(SWT.RESIZE);
+    }
+    
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#setAvalibleContexts(java.util.List)
+     */
+    @Override
+    public void setAvalibleContexts(List<String> contexts) {
+        fContextModel.setAvalibleContexts(contexts);
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog#getContexts()
+     */
+    @Override
+    public List<String> getContexts() {
+        List<String> ret = new ArrayList<String>();
+        ret.addAll(fSelectedContexts);
+        return ret;
+    }
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+     */
+    @Override
+    protected void configureShell(Shell newShell) {
+        super.configureShell(newShell);
+        newShell.setText(Messages.TraceControl_AddContextDialogTitle);
+        newShell.setImage(Activator.getDefault().loadIcon(ADD_CONTEXT_ICON_FILE));
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+     */
+    @Override
+    protected Control createDialogArea(Composite parent) {
+
+        // Main dialog panel
+        fDialogComposite = new Composite(parent, SWT.NONE);
+        GridLayout layout = new GridLayout(1, true);
+        fDialogComposite.setLayout(layout);
+        fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        // Contexts list
+        Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        contextGroup.setText(Messages.TraceControl_AddContextAvailableContextsLabel);
+        layout = new GridLayout(1, true);
+        contextGroup.setLayout(layout);
+        contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+        
+        fContextsViewer = new CheckboxTreeViewer(contextGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+        fContextsViewer.getTree().setToolTipText(Messages.TraceControl_AddContextAvailableContextsTooltip); 
+
+        fContextsViewer.setContentProvider(new ContextsContentProvider());
+        fContextsViewer.setLabelProvider(new ContextsLabelProvider());
+        fContextsViewer.addCheckStateListener(new ContextCheckListener());
+        fContextsViewer.setInput(fContextModel);
+        fContextsViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
+        
+        getShell().setMinimumSize(new Point(500, 650));
+        
+        return fDialogComposite;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+     */
+    @Override
+    protected void createButtonsForButtonBar(Composite parent) {
+        createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+     */
+    @Override
+    protected void okPressed() {
+        fSelectedContexts.clear();
+
+        Object[] checkedElements = fContextsViewer.getCheckedElements();
+        for (int i = 0; i < checkedElements.length; i++) {
+            IContextModelComponent component = (IContextModelComponent)checkedElements[i];
+            fSelectedContexts.add(component.getName());
+        }
+        
+        // validation successful -> call super.okPressed()
+        super.okPressed();
+    }
+    
+    // ------------------------------------------------------------------------
+    // Helper classes and methods
+    // ------------------------------------------------------------------------
+    /**
+     * Content provider for the contexts tree
+     */
+    final public static class ContextsContentProvider implements ITreeContentProvider {
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+        }
+
+        @Override
+        public Object[] getElements(Object inputElement) {
+            return getChildren(inputElement);
+        }
+
+        @Override
+        public Object[] getChildren(Object parentElement) {
+            if (parentElement instanceof IContextModelComponent) {
+                return ((IContextModelComponent)parentElement).getChildren();
+            }
+            return null;
+        }
+
+        @Override
+        public Object getParent(Object element) {
+            if (element instanceof IContextModelComponent) {
+                return ((IContextModelComponent)element).getParent();
+            }
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren(Object element) {
+            if (element instanceof IContextModelComponent) {
+                return ((IContextModelComponent)element).hasChildren();
+            }
+            return false;
+        }
+    }
+
+    /**
+     * Label provider for the contexts tree
+     */
+    final public static class ContextsLabelProvider extends ColumnLabelProvider {
+        @Override
+        public String getText(Object element) {
+            
+            if ((element != null) && (element instanceof IContextModelComponent)) {
+                return ((IContextModelComponent)element).getName();
+            }
+
+            return "";//$NON-NLS-1$
+        }
+    }
+    
+    /**
+     * Check state listener for the contexts tree. 
+     */
+    final public class ContextCheckListener implements ICheckStateListener {
+        @Override
+        public void checkStateChanged(CheckStateChangedEvent event) {
+          if (event.getChecked()) {
+              if (event.getElement() instanceof AllContexts) {
+                  fContextsViewer.setSubtreeChecked(event.getElement(), true);
+              } 
+          } else { 
+              if (event.getElement() instanceof AllContexts) {
+                  fContextsViewer.setSubtreeChecked(event.getElement(), false);
+              } else {
+                  IContextModelComponent component = (IContextModelComponent) event.getElement();
+                  fContextsViewer.setChecked(component.getParent(), false);
+              }
+          }
+        }
+    }
+
+    /**
+     * Model for the context tree viewer (root component)
+     */
+    public static class ContextModel implements IContextModelComponent {
+
+        private AllContexts fAllContexts;
+        
+        public ContextModel() {
+            fAllContexts = new AllContexts(this);
+        }
+
+        public void setAvalibleContexts(List<String> contexts) {
+            fAllContexts.setAvalibleContexts(contexts);
+        }
+        
+        @Override
+        public String getName() {
+            return "root"; //$NON-NLS-1$
+        }
+        
+        @Override
+        public Object getParent() {
+            return null;
+        }
+
+        @Override
+        public Object[] getChildren() {
+            Object[] ret = new Object[1];
+            ret[0] = fAllContexts;
+            return ret;
+        }
+
+        @Override
+        public boolean hasChildren() {
+            return true;
+        }
+    }
+
+    /**
+     * Model element (to select/deselect) all contexts) for the context tree viewer 
+     */
+    public static class AllContexts implements IContextModelComponent {
+        /**
+         * The available list of contexts.
+         */
+        private List<Context> fAvailableContexts;
+        
+        private IContextModelComponent fParent;
+
+        public AllContexts(IContextModelComponent parent) {
+            fParent = parent;
+        }
+        
+        public void setAvalibleContexts(List<String> contexts) {
+            fAvailableContexts = new ArrayList<Context>();
+            if (contexts != null) {
+                for (Iterator<String> iterator = contexts.iterator(); iterator.hasNext();) {
+                    String name = (String) iterator.next();
+                    fAvailableContexts.add(new Context(this, name));
+                }
+            }
+        }
+
+        @Override
+        public String getName() {
+            return Messages.TraceControl_AddContextAllLabel;
+        }
+        
+        @Override
+        public Object[] getChildren() {
+            return fAvailableContexts.toArray();
+        }
+        
+        @Override
+        public Object getParent() {
+            return fParent;
+        }
+        
+        @Override
+        public boolean hasChildren() {
+            return true;
+        }
+    }
+
+    /**
+     * Model element (the context) for the context tree viewer 
+     */
+    public static class Context implements IContextModelComponent {
+
+        private String fContextName;
+        private IContextModelComponent fParent; 
+        
+        public Context(IContextModelComponent parent, String name) {
+            fParent = parent;
+            fContextName = name;
+        }
+        
+        @Override
+        public String getName() {
+            return fContextName;
+        }
+
+        @Override
+        public Object getParent() {
+            return fParent;
+        }
+
+        @Override
+        public Object[] getChildren() {
+            return null;
+        }
+
+        @Override
+        public boolean hasChildren() {
+            return false;
+        }
+    }
+
+    /**
+     * Interface for the tree model used for the context tree viewer. 
+     */
+    public interface IContextModelComponent {
+        public String getName();
+        public Object getParent();
+        public Object[] getChildren();
+        public boolean hasChildren();
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/dialogs/IAddContextDialog.java
new file mode 100644 (file)
index 0000000..c8c0dd3
--- /dev/null
@@ -0,0 +1,46 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import java.util.List;
+
+/**
+ * <b><u>IAddContextDialog</u></b>
+ * <p>
+ * Interface for providing information about contexts to be added to channels/events.
+ * </p>
+ */
+public interface IAddContextDialog {
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Sets the available contexts to choose from.
+     * @param contexts - a list of available contexts.
+     */
+    public void setAvalibleContexts(List<String> contexts);
+    
+    /**
+     * @return array of contexts to be added
+     */
+    public List<String> getContexts();
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /**
+     * @return returns the open return value
+     */
+    int open();
+}
index f8d5d8a7205fc9f6e2a8942231cf259b65075723..3af2ce8d6a5bc592e9449444e6e22dbc45867dc2 100644 (file)
@@ -43,6 +43,11 @@ final public class TraceControlDialogFactory {
      * The confirmation dialog implementation
      */
     private IConfirmDialog fConfirmDialog;
+    
+    /**
+     * The add context dialog implementation
+     */
+    private IAddContextDialog fAddContextDialog;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -175,6 +180,24 @@ final public class TraceControlDialogFactory {
     public void setConfirmDialog(IConfirmDialog confirmDialog) {
         fConfirmDialog = confirmDialog;
     }
+    
+    /**
+     * @return the add context dialog implementation
+     */
+    public IAddContextDialog getAddContextDialog() {
+        if (fAddContextDialog == null) {
+            fAddContextDialog = new AddContextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+        }
+        return fAddContextDialog;
+    }
+    
+    /**
+     * Sets the add context dialog information
+     * @param addContextDialog
+     */
+    public void setAddContextDialog(IAddContextDialog addContextDialog) {
+        fAddContextDialog = addContextDialog;
+    }
 }
 
 
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnChannelHandler.java
new file mode 100644 (file)
index 0000000..0deea89
--- /dev/null
@@ -0,0 +1,96 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * <b><u>AddContextOnChannelHandler</u></b>
+ * <p>
+ * Command handler implementation to add contexts to a given channel and all of its events.
+ * </p>
+ */
+public class AddContextOnChannelHandler extends BaseAddContextHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof ChannelCommandParameter) {
+            TraceChannelComponent channel = ((ChannelCommandParameter)param).getChannel();
+            channel.addContexts(contextNames, monitor);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+     */
+    @Override
+    public boolean isEnabled() {
+        // Get workbench page for the Control View
+        IWorkbenchPage page = getWorkbenchPage();
+        if (page == null) {
+            return false;
+        }
+
+        TraceChannelComponent channel = null;
+        TraceSessionComponent session = null;
+        ISelection selection = page.getSelection(ControlView.ID);
+        if (selection instanceof StructuredSelection) {
+            StructuredSelection structered = ((StructuredSelection) selection);
+            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
+                Object element = (Object) iterator.next();
+                if (element instanceof TraceChannelComponent) {
+                    // Add only if corresponding TraceSessionComponents is inactive and not destroyed
+                    TraceChannelComponent tmpChannel = (TraceChannelComponent) element; 
+                    session = tmpChannel.getSession();
+                    if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
+                        channel = tmpChannel;
+                    }
+                }
+            }
+        }
+        
+        boolean isEnabled = (channel != null);
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new ChannelCommandParameter(session, channel);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnDomainHandler.java
new file mode 100644 (file)
index 0000000..d5e6626
--- /dev/null
@@ -0,0 +1,104 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * <b><u>AddContextOnDomainHandler</u></b>
+ * <p>
+ * Command handler implementation to add contexts to all channels and all events.
+ * </p>
+ */
+public class AddContextOnDomainHandler extends BaseAddContextHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof DomainCommandParameter) {
+            TraceDomainComponent domain = ((DomainCommandParameter)param).getDomain();
+            domain.addContexts(contextNames, monitor);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+     */
+    @Override
+    public boolean isEnabled() {
+        
+        // Get workbench page for the Control View
+        IWorkbenchPage page = getWorkbenchPage();
+        if (page == null) {
+            return false;
+        }
+        
+        TraceDomainComponent domain = null;
+        TraceSessionComponent session = null;
+        
+        // Check if one domain is selected
+        ISelection selection = page.getSelection(ControlView.ID);
+        if (selection instanceof StructuredSelection) {
+            StructuredSelection structered = ((StructuredSelection) selection);
+            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
+                Object element = (Object) iterator.next();
+                if (element instanceof TraceDomainComponent) {
+                    TraceDomainComponent tmpDomain = (TraceDomainComponent) element;
+                    session = (TraceSessionComponent) tmpDomain.getParent();
+                    
+                    // Add only TraceDomainComponent whose TraceSessionComponent parent is inactive and not destroyed
+                    if ((session.getSessionState() == TraceSessionState.INACTIVE) && (!session.isDestroyed())) {
+                        domain = tmpDomain;
+                    }
+                }
+            }
+        }
+        
+        boolean isEnabled = domain != null;
+        
+        fLock.lock();
+        try {
+            fParam = null;
+            if (isEnabled) {
+                fParam = new DomainCommandParameter(session, domain);
+            }
+        } finally {
+            fLock.unlock();
+        }
+
+        return isEnabled;
+    }
+
+
+}
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/AddContextOnEventHandler.java
new file mode 100644 (file)
index 0000000..7611c8e
--- /dev/null
@@ -0,0 +1,96 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.ui.IWorkbenchPage;
+
+/**
+ * <b><u>AddContextOnEventHandler</u></b>
+ * <p>
+ * Command handler implementation to add contexts to a given event.
+ * </p>
+ */
+public class AddContextOnEventHandler extends BaseAddContextHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.BaseAddContextHandler#addContexts(org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CommandParameter, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
+        if (param instanceof EventCommandParameter) {
+            TraceEventComponent event = ((EventCommandParameter)param).getEvent();
+            event.addContexts(contextNames, monitor);
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+     */
+    @Override
+    public boolean isEnabled() {
+        // Get workbench page for the Control View
+        IWorkbenchPage page = getWorkbenchPage();
+        if (page == null) {
+            return false;
+        }
+
+        TraceEventComponent event = null;
+        TraceSessionComponent session = null;
+        ISelection selection = page.getSelection(ControlView.ID);
+        if (selection instanceof StructuredSelection) {
+            StructuredSelection structered = ((StructuredSelection) selection);
+            for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
+                Object element = (Object) iterator.next();
+                if (element instanceof TraceEventComponent) {
+                    // Add only if corresponding TraceSessionComponents is inactive and not destroyed
+                    TraceEventComponent tmpEvent = (TraceEventComponent) element; 
+                    session = tmpEvent.getSession();
+                    if(session.getSessionState() == TraceSessionState.INACTIVE && !session.isDestroyed()) {
+                        event = tmpEvent;
+                    }
+                }
+            }
+        }
+        
+        boolean isEnabled = (event != null);
+        fLock.lock();
+        try {
+            fParam = null;
+            if(isEnabled) {
+                fParam = new EventCommandParameter(session, event);
+            }
+        } finally {
+            fLock.unlock();
+        }
+        return isEnabled;
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/BaseAddContextHandler.java
new file mode 100644 (file)
index 0000000..339e0b5
--- /dev/null
@@ -0,0 +1,136 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IAddContextDialog;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.UIJob;
+
+/**
+ * <b><u>BaseAddContextHandler</u></b>
+ * <p>
+ * Base command handler implementation to add contexts.
+ * </p>
+ */
+abstract public class BaseAddContextHandler extends BaseControlViewHandler {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    /**
+     * The command execution parameter.
+     */
+    protected CommandParameter fParam = null;
+
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+    
+    /**
+     * Adds contexts to channel(s) and/or event(s) 
+     * @param param - a parameter instance with data for the command execution
+     * @param contextNames - list contexts to add
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    abstract public void addContexts(CommandParameter param, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException;
+    
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+     */
+    @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+        final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+        if (window == null) {
+            return false;
+        }
+        fLock.lock();
+        try {
+            // Make a copy for thread safety
+            final CommandParameter param = fParam.clone();
+
+            UIJob getJob = new UIJob(Messages.TraceControl_GetContextJob) {
+                @Override
+                public IStatus runInUIThread(IProgressMonitor monitor) {
+
+                    try {
+                        final List<String> availableContexts = param.getSession().getContextList(monitor);
+                        final IAddContextDialog dialog = TraceControlDialogFactory.getInstance().getAddContextDialog();
+                        dialog.setAvalibleContexts(availableContexts); 
+
+                        if ((dialog.open() != Window.OK) || (dialog.getContexts().isEmpty())) {
+                            return Status.OK_STATUS;
+                        }
+
+                        Job addJob = new Job(Messages.TraceControl_AddContextJob) {
+                            @Override
+                            protected IStatus run(IProgressMonitor monitor) {
+                                StringBuffer errorString = new StringBuffer();
+
+                                try {
+                                    List<String> contextNames = dialog.getContexts();
+                                    addContexts(param, contextNames, monitor);
+
+                                } catch (ExecutionException e) {
+                                    errorString.append(e.toString());
+                                    errorString.append('\n');
+                                }
+
+                                // get session configuration in all cases
+                                try {
+                                    param.getSession().getConfigurationFromNode(monitor);
+                                } catch (ExecutionException e) {
+                                    errorString.append(Messages.TraceControl_ListSessionFailure);
+                                    errorString.append(": "); //$NON-NLS-1$
+                                    errorString.append(e.toString());
+                                } 
+
+                                if (errorString.length() > 0) {
+                                    return new Status(Status.ERROR, Activator.PLUGIN_ID, errorString.toString());
+                                }
+                                return Status.OK_STATUS;
+                            }
+                        };
+                        addJob.setUser(true);
+                        addJob.schedule();
+                    } catch (ExecutionException e) {
+                        return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
+                    }
+
+                    return Status.OK_STATUS;
+                }
+            };
+            getJob.setUser(false);
+            getJob.schedule();
+
+        } finally {
+            fLock.unlock();
+        }
+        return null;
+    }
+}
diff --git a/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java b/org.eclipse.linuxtools.lttng2.ui/src/org/eclipse/linuxtools/internal/lttng2/ui/views/control/handlers/EventCommandParameter.java
new file mode 100644 (file)
index 0000000..82f4b9b
--- /dev/null
@@ -0,0 +1,66 @@
+/**********************************************************************
+ * Copyright (c) 2012 Ericsson
+ * 
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors: 
+ *   Bernd Hufmann - Initial API and implementation
+ **********************************************************************/
+package org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+
+/**
+ *  Class containing parameter for a command execution. 
+ */
+public class EventCommandParameter extends CommandParameter {
+
+    // ------------------------------------------------------------------------
+    // Attributes
+    // ------------------------------------------------------------------------
+    private TraceEventComponent fEvent;
+
+    // ------------------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------------------
+
+    /**
+     * Constructor
+     * @param session - a trace session component.
+     * @param event - a trace event component
+     */
+    public EventCommandParameter(TraceSessionComponent session, TraceEventComponent event) {
+        super(session);
+        fEvent = event;
+    }
+
+    // ------------------------------------------------------------------------
+    // Accessors
+    // ------------------------------------------------------------------------
+
+    /**
+     * @return the trace event component
+     */
+    public TraceEventComponent getEvent() {
+        return fEvent;
+    }
+    
+    // ------------------------------------------------------------------------
+    // Operations
+    // ------------------------------------------------------------------------
+
+    /*
+     * (non-Javadoc)
+     * @see java.lang.Object#clone()
+     */
+    @Override
+    public EventCommandParameter clone() {
+        EventCommandParameter clone = (EventCommandParameter) super.clone();
+        clone.fEvent = fEvent;
+        return clone;
+    }
+}
\ No newline at end of file
index 8dc114118faec2f17ebe5fbac1352a4da101fb49..3065622daa5ae88f77d84e660743bfc3f2c37f0e 100644 (file)
@@ -31,6 +31,9 @@ TraceControl_EnableEventsJob=Enabling Events...
 TraceControl_EnableEventsFailure=Enable Events failed
 TraceControl_DisableEventsJob=Disabling Events...
 
+TraceControl_GetContextJob=Getting Available Contexts... 
+TraceControl_AddContextJob=Adding Contexts...
+
 # Dialogs
 TraceControl_NewDialogTitle=New Connection
 TraceControl_NewNodeExistingConnectionGroupName=Existing Connections
@@ -105,6 +108,11 @@ TraceControl_InvalidWildcardError=The wild card name is invalid
 TraceControl_InvalidLogLevelEventNameError=The event name for log level is invalid
 TraceControl_InvalidLogLevel=No log level selected
 
+TraceControl_AddContextDialogTitle=Add Contexts
+TraceControl_AddContextAvailableContextsLabel=Contexts
+TraceControl_AddContextAvailableContextsTooltip=Available Contexts
+TraceControl_AddContextAllLabel=All Contexts
+
 # Tree structure strings
 TraceControl_KernelDomainDisplayName=Kernel
 TraceControl_UstGlobalDomainDisplayName=UST global
index 29d3ca7dc5d670c4f98c896f95acd4658f7e9fe4..20f990938778b618b24e661f06c2b582cd75a87f 100644 (file)
@@ -359,4 +359,23 @@ public class TraceChannelComponent extends TraceControlComponent {
     public void disableEvent(List<String> eventNames, IProgressMonitor monitor) throws ExecutionException {
         getControlService().disableEvent(getParent().getParent().getName(), getName(), eventNames, isKernel(), monitor);
     }
+    
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts) throws ExecutionException {
+        addContexts(contexts, new NullProgressMonitor());
+    }
+
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
+        getControlService().addContexts(getSessionName(), getName(), null, isKernel(), contexts, monitor);
+    }
 }
index c88f90a83c102633d37938d0574309f508ed478f..c8373395d2e1122c35c7b34ab5c9234619cbae87 100644 (file)
@@ -271,4 +271,22 @@ public class TraceDomainComponent extends TraceControlComponent {
         getControlService().enableLogLevel(getSessionName(), null, eventName, logLevelType, level, monitor);
     }
 
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts) throws ExecutionException {
+        addContexts(contexts, new NullProgressMonitor());
+    }
+
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
+        getControlService().addContexts(getSessionName(), null, null, isKernel(), contexts, monitor);
+    }
 }
index f67b3cff0c999cba0627f28d0e8d351e94995de1..7c2f85a224eb5f0405bdd342d9a78e0a4ad22d38 100644 (file)
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl;
 
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.IEventInfo;
@@ -182,6 +187,13 @@ public class TraceEventComponent extends TraceControlComponent {
        return ((TraceChannelComponent)getParent()).getSessionName(); 
     }
 
+    /**
+     * @return session from parent
+     */
+    public TraceSessionComponent getSession() {
+       return ((TraceChannelComponent)getParent()).getSession(); 
+    }
+
     /**
      * @return channel name from parent
      */
@@ -199,4 +211,23 @@ public class TraceEventComponent extends TraceControlComponent {
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
+    
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts) throws ExecutionException {
+        addContexts(contexts, new NullProgressMonitor());
+    }
+
+    /**
+     * Add contexts to given channels and or events
+     * @param contexts - a list of contexts to add
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    public void addContexts(List<String> contexts, IProgressMonitor monitor) throws ExecutionException {
+        getControlService().addContexts(getSessionName(),getChannelName(), getName(), isKernel(), contexts, monitor);
+    }
 }
index e8cffe2da5218c0ebee7783a628d3f0dc4827558..f1d1476dd1ca72a730435f7d5c61a00547c434a7 100644 (file)
@@ -362,4 +362,21 @@ public class TraceSessionComponent extends TraceControlComponent {
     public void enableLogLevel(String eventName, LogLevelType logLevelType, TraceLogLevel level, IProgressMonitor monitor) throws ExecutionException {
         getControlService().enableLogLevel(getName(), null, eventName, logLevelType, level, monitor);
     }
+    
+    /**
+     * Gets all available contexts to be added to channels/events.
+     * @return the list of available contexts
+     */
+    public List<String> getContextList() throws ExecutionException {
+        return getContextList(new NullProgressMonitor());
+    }
+
+    /**
+     * Gets all available contexts to be added to channels/events.
+     * @param monitor
+     * @return the list of available contexts
+     */
+    public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
+        return getControlService().getContextList(monitor);
+    }
 }
index 2824c2f4b92e611e4c3d854c28843fcc45611896..14a6410a3289b4c5a489378832ae3c013f0570e3 100644 (file)
@@ -178,5 +178,24 @@ public interface ILttngControlService {
      * @throws ExecutionException
      */
     public void disableEvent(String sessionName, String channelName, List<String> eventNames, boolean isKernel, IProgressMonitor monitor) throws ExecutionException;
+    
+    /**
+     * Gets all available context names to be added to channels/events.
+     * @param monitor
+     * @return the list of available contexts
+     */
+    public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException;
+    
+    /**
+     * Add contexts to given channels and or events
+     * @param sessionName - a session name
+     * @param channelName - a channel name (null for all channels)
+     * @param eventName - a event name (null for all events)
+     * @param isKernel -  a flag for indicating kernel or UST.
+     * @param contexts - a list of name of contexts to add
+     * @param monitor - a progress monitor
+     * @throws ExecutionException
+     */
+    public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contexts, IProgressMonitor monitor) throws ExecutionException;
 
 }
index ef08cae9d85be0207c87d179fd96042757209276..c471d2f03bef3d0b0056f18d3796c90c80cf4fbf 100644 (file)
@@ -98,7 +98,11 @@ public class LTTngControlService implements ILttngControlService {
      * Command to disable a event. 
      */
     private final static String COMMAND_DISABLE_EVENT = CONTROL_COMMAND + " disable-event "; //$NON-NLS-1$
-
+    /**
+     * Command to add a context to channels and/or events
+     */
+    private final static String COMMAND_ADD_CONTEXT = CONTROL_COMMAND + " add-context "; //$NON-NLS-1$
+    
     // Command options constants 
     /**
      * Command line option for output path.
@@ -120,10 +124,18 @@ public class LTTngControlService implements ILttngControlService {
      * Command line option for specifying a channel.
      */
     private final static String OPTION_CHANNEL = " -c ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a event.
+     */
+    private final static String OPTION_EVENT = " -e ";  //$NON-NLS-1$
     /**
      * Command line option for specifying all events.
      */
     private final static String OPTION_ALL = " -a ";  //$NON-NLS-1$
+    /**
+     * Command line option for specifying a context.
+     */
+    private final static String OPTION_CONTEXT_TYPE = " -t ";  //$NON-NLS-1$
     /**
      * Command line option for specifying tracepoint events.
      */
@@ -168,6 +180,10 @@ public class LTTngControlService implements ILttngControlService {
      * Optional command line option for configuring a channel's read timer interval.
      */
     private final static String OPTION_READ_TIMER = " --read-timer ";  //$NON-NLS-1$
+    /**
+     * Command line option for printing the help of a specif command 
+     */
+    private final static String OPTION_HELP = " -h ";  //$NON-NLS-1$
     
     // Parsing constants
     /**
@@ -284,6 +300,15 @@ public class LTTngControlService implements ILttngControlService {
      * Pattern to match for session command output for "session name not found".
      */
     private final static Pattern SESSION_NOT_FOUND_ERROR_PATTERN = Pattern.compile("\\s*Error:\\s+Session\\s+name\\s+not\\s+found"); //$NON-NLS-1$
+    /**
+     * Pattern to match introduction line of context list.
+     */
+    private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_INTRO = Pattern.compile("\\s*TYPE can\\s+be\\s+one\\s+of\\s+the\\s+strings\\s+below.*"); //$NON-NLS-1$
+    
+    /**
+     * Pattern to match introduction line of context list.
+     */
+    private final static Pattern ADD_CONTEXT_HELP_CONTEXTS_END_LINE = Pattern.compile("\\s*Example.*"); //$NON-NLS-1$
     
     // ------------------------------------------------------------------------
     // Attributes
@@ -949,7 +974,91 @@ public class LTTngControlService implements ILttngControlService {
             throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
         }
     }
-    
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#getContexts(org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public List<String> getContextList(IProgressMonitor monitor) throws ExecutionException {
+
+        String command = COMMAND_ADD_CONTEXT + OPTION_HELP;
+
+        ICommandResult result = fCommandShell.executeCommand(command, monitor);
+
+        if (isError(result)) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        String[] output = result.getOutput(); 
+        
+        List<String> contexts = new ArrayList<String>(0);
+        
+        int index = 0;
+        boolean inList = false;
+        while (index < output.length) {
+            String line = result.getOutput()[index];
+            
+            Matcher startMatcher = ADD_CONTEXT_HELP_CONTEXTS_INTRO.matcher(line);
+            Matcher endMatcher = ADD_CONTEXT_HELP_CONTEXTS_END_LINE.matcher(line);
+
+            if (startMatcher.matches()) {
+                inList = true;
+            } else if (endMatcher.matches()) {
+                break;
+            } else if (inList == true) {
+                String[] tmp = line.split(","); //$NON-NLS-1$
+                for (int i = 0; i < tmp.length; i++) {
+                    contexts.add(tmp[i].trim());
+                }
+            }
+            index++;
+        }
+        return contexts;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService#addContexts(java.lang.String, java.lang.String, java.lang.String, boolean, java.util.List, org.eclipse.core.runtime.IProgressMonitor)
+     */
+    @Override
+    public void addContexts(String sessionName, String channelName, String eventName, boolean isKernel, List<String> contextNames, IProgressMonitor monitor) throws ExecutionException {
+        
+        String newSessionName = formatParameter(sessionName);
+        StringBuffer command = new StringBuffer(COMMAND_ADD_CONTEXT);
+
+        command.append(OPTION_SESSION);
+        command.append(newSessionName);
+        
+        if (channelName != null) {
+            command.append(OPTION_CHANNEL);
+            command.append(channelName);
+        }
+
+        if (eventName != null) {
+            command.append(OPTION_EVENT);
+            command.append(eventName);
+        }
+
+        if (isKernel) {
+            command.append(OPTION_KERNEL);
+        } else {
+            command.append(OPTION_UST);
+        }
+        
+        for (Iterator<String> iterator = contextNames.iterator(); iterator.hasNext();) {
+            String context = (String) iterator.next();
+            command.append(OPTION_CONTEXT_TYPE);
+            command.append(context);
+        }
+
+        ICommandResult result = fCommandShell.executeCommand(command.toString(), monitor);
+        
+        if (isError(result)) {
+            throw new ExecutionException(Messages.TraceControl_CommandError + " " + command + "\n" + formatOutput(result.getOutput())); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+    }
+
     // ------------------------------------------------------------------------
     // Helper methods
     // ------------------------------------------------------------------------
@@ -1238,5 +1347,4 @@ public class LTTngControlService implements ILttngControlService {
         }
         return null;
     }
-    
 }
This page took 0.064014 seconds and 5 git commands to generate.