lttng: Fix more Sonar warnings in LTTng Tracer Control
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / GetEventInfoDialog.java
index 2392d3604abef3492834744ba58db4f4134920f7..28ebd7fb4ca70cb00dc9f543a936ddf0009fc999 100644 (file)
@@ -1,13 +1,14 @@
 /**********************************************************************
- * Copyright (c) 2012 Ericsson
- * 
+ * Copyright (c) 2012, 2013 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: 
+ *
+ * Contributors:
  *   Bernd Hufmann - Initial API and implementation
+ *   Bernd Hufmann - Updated for support of LTTng Tools 2.1
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
 
@@ -17,7 +18,7 @@ import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.MessageDialog;
 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.messages.Messages;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceDomainComponent;
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
@@ -25,18 +26,21 @@ import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+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;
+import org.eclipse.swt.widgets.Text;
 
 /**
- * <b><u>EnableEventsDialog</u></b>
  * <p>
  * Dialog box for collecting information about the events to enable.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
 
@@ -46,23 +50,11 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
     /**
      * The icon file for this dialog box.
      */
-    public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/edit.gif"; //$NON-NLS-1$ 
+    public static final String TARGET_NEW_CONNECTION_ICON_FILE = "icons/elcl16/enable_event.gif"; //$NON-NLS-1$
 
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
-    /**
-     * The dialog composite.
-     */
-    private Composite fDialogComposite = null;
-    /**
-     * The Group for the session combo box.
-     */
-    private Group fSessionsGroup = null;
-    /**
-     * The Group for the channel combo box.
-     */
-    private Group fChannelsGroup = null;
     /**
      * The session combo box.
      */
@@ -71,6 +63,10 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
      * The channel combo box.
      */
     private CCombo fChannelsCombo = null;
+    /**
+     * The filter text
+     */
+    private Text fFilterText;
     /**
      * The list of available sessions.
      */
@@ -84,13 +80,17 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
      */
     private int fSessionIndex = 0;
     /**
-     * The Channel where the events should be enabled. 
+     * The Channel where the events should be enabled.
      */
     private TraceChannelComponent fChannel;
     /**
      * List of available channels of the selected session.
      */
     private TraceChannelComponent[] fChannels;
+    /**
+     * The filter expression
+     */
+    private String fFilterExpression;
 
     // ------------------------------------------------------------------------
     // Constructors
@@ -107,49 +107,36 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getSession()
-     */
+
     @Override
     public TraceSessionComponent getSession() {
         return fSessions[fSessionIndex];
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IEnableEventsDialog#getChannel()
-     */
     @Override
     public TraceChannelComponent getChannel() {
         return fChannel;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setIsKernel(boolean)
-     */
     @Override
     public void setIsKernel(boolean isKernel) {
         fIsKernel = isKernel;
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IGetEventInfoDialog#setSessions(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent[])
-     */
+
     @Override
     public void setSessions(TraceSessionComponent[] sessions) {
         fSessions = Arrays.copyOf(sessions, sessions.length);
     }
 
+    @Override
+    public String getFilterExpression() {
+       return fFilterExpression;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
-     */
+
     @Override
     protected void configureShell(Shell newShell) {
         super.configureShell(newShell);
@@ -157,30 +144,26 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
         newShell.setImage(Activator.getDefault().loadIcon(TARGET_NEW_CONNECTION_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);
+        Composite dialogComposite = new Composite(parent, SWT.NONE);
         GridLayout layout = new GridLayout(1, true);
-        fDialogComposite.setLayout(layout);
-        fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
-        
-        fSessionsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-        fSessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName);
+        dialogComposite.setLayout(layout);
+        dialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        Group sessionsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
+        sessionsGroup.setText(Messages.TraceControl_EnableEventsSessionGroupName);
         layout = new GridLayout(1, true);
-        fSessionsGroup.setLayout(layout); 
+        sessionsGroup.setLayout(layout);
         GridData data = new GridData(GridData.FILL_HORIZONTAL);
-        fSessionsGroup.setLayoutData(data);
+        sessionsGroup.setLayoutData(data);
 
-        fSessionsCombo = new CCombo(fSessionsGroup, SWT.READ_ONLY);
+        fSessionsCombo = new CCombo(sessionsGroup, SWT.READ_ONLY);
         fSessionsCombo.setToolTipText(Messages.TraceControl_EnableEventsSessionsTooltip);
         fSessionsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-        
+
         String items[] = new String[fSessions.length];
         for (int i = 0; i < items.length; i++) {
             items[i] = String.valueOf(fSessions[i].getName());
@@ -188,15 +171,15 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
 
         fSessionsCombo.setItems(items);
         fSessionsCombo.setEnabled(fSessions.length > 0);
-        
-        fChannelsGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-        fChannelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName);
+
+        Group channelsGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
+        channelsGroup.setText(Messages.TraceControl_EnableEventsChannelGroupName);
         layout = new GridLayout(1, true);
-        fChannelsGroup.setLayout(layout);
+        channelsGroup.setLayout(layout);
         data = new GridData(GridData.FILL_HORIZONTAL);
-        fChannelsGroup.setLayoutData(data);
-        
-        fChannelsCombo = new CCombo(fChannelsGroup, SWT.READ_ONLY);
+        channelsGroup.setLayoutData(data);
+
+        fChannelsCombo = new CCombo(channelsGroup, SWT.READ_ONLY);
         fChannelsCombo.setToolTipText(Messages.TraceControl_EnableEventsChannelsTooltip);
         fChannelsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
         fChannelsCombo.setEnabled(false);
@@ -205,7 +188,7 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 fSessionIndex = fSessionsCombo.getSelectionIndex();
-                
+
                 if (fSessionIndex >= 0) {
                     TraceDomainComponent domain = null;
                     TraceDomainComponent[] domains = fSessions[fSessionIndex].getDomains();
@@ -219,13 +202,13 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
 
                     if (domain != null) {
                         fChannels = domain.getChannels();
-                        String items[] = new String[fChannels.length];
-                        for (int i = 0; i < items.length; i++) {
-                            items[i] = String.valueOf(fChannels[i].getName());
+                        String selectionItems[] = new String[fChannels.length];
+                        for (int i = 0; i < selectionItems.length; i++) {
+                            selectionItems[i] = String.valueOf(fChannels[i].getName());
                         }
-                        fChannelsCombo.setItems(items);
+                        fChannelsCombo.setItems(selectionItems);
                         fChannelsCombo.setEnabled(fChannels.length > 0);
-                    } else { 
+                    } else {
                         fChannelsCombo.setItems(new String[0]);
                         fChannelsCombo.setEnabled(false);
                         fChannels = null;
@@ -238,45 +221,61 @@ public class GetEventInfoDialog extends Dialog implements IGetEventInfoDialog {
             public void widgetDefaultSelected(SelectionEvent e) {
             }
         });
-        return fDialogComposite;
+
+        // take first session to test whether events filtering is supported or not
+        if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
+            Group filterMainGroup = new Group(dialogComposite, SWT.SHADOW_NONE);
+            filterMainGroup.setText(Messages.TraceControl_EnableEventsFilterGroupName);
+            layout = new GridLayout(2, false);
+            filterMainGroup.setLayout(layout);
+            data = new GridData(GridData.FILL_HORIZONTAL);
+            filterMainGroup.setLayoutData(data);
+
+            fFilterText = new Text(filterMainGroup, SWT.LEFT);
+            fFilterText.setToolTipText(Messages.TraceControl_EnableEventsFilterTooltip);
+            data = new GridData(GridData.FILL_HORIZONTAL);
+            fFilterText.setLayoutData(data);
+        }
+
+        getShell().setMinimumSize(new Point(300, 200));
+
+        return dialogComposite;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
-     */
     @Override
     protected void createButtonsForButtonBar(Composite parent) {
+        createButton(parent, IDialogConstants.CANCEL_ID, "&Cancel", true); //$NON-NLS-1$
         createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.dialogs.Dialog#okPressed()
-     */
     @Override
     protected void okPressed() {
-        
+
         if (fSessionsCombo.getSelectionIndex() < 0) {
             MessageDialog.openError(getShell(),
                   Messages.TraceControl_EnableEventsDialogTitle,
-                  Messages.TraceControl_EnableEventsNoSessionError);  
+                  Messages.TraceControl_EnableEventsNoSessionError);
             return;
         }
 
         fSessionIndex = fSessionsCombo.getSelectionIndex();
 
-        if ((fChannels != null) && (fChannels.length > 0) && (fChannelsCombo.getSelectionIndex() < 0)) {
-            MessageDialog.openError(getShell(),
-                    Messages.TraceControl_EnableEventsDialogTitle,
-                    Messages.TraceControl_EnableEventsNoChannelError);  
-              return;
-        }
-        
-        if ((fChannels != null) && (fChannels.length > 0)) {
+        // if no channel is available or no channel is selected use default channel indicated by fChannel=null
+        fChannel = null;
+        if ((fChannels != null) && (fChannelsCombo.getSelectionIndex() >= 0)) {
             fChannel = fChannels[fChannelsCombo.getSelectionIndex()];
         }
 
+        // initialize filter with null
+        fFilterExpression = null;
+        if (fSessions[0].isEventFilteringSupported() && !fIsKernel) {
+            String tempFilter = fFilterText.getText();
+
+            if(!tempFilter.matches("\\s*")) { //$NON-NLS-1$
+                fFilterExpression = tempFilter;
+            }
+        }
+
         super.okPressed();
     }
 }
This page took 0.031319 seconds and 5 git commands to generate.