lttng: Add snapshot support - LTTng Tools v2.3
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui / src / org / eclipse / linuxtools / internal / lttng2 / ui / views / control / dialogs / ImportDialog.java
index 26e1da6a2f23c022defdf49a47309560c0866eb1..03eae31441cedd79f1a656fbacbb27acd75c76b6 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 - Added handling of streamed traces
  **********************************************************************/
 package org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs;
 
@@ -32,6 +33,7 @@ import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceS
 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
 import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
 import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.rse.core.subsystems.RemoteChildrenContentsType;
 import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
 import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
 import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
@@ -51,23 +53,29 @@ import org.eclipse.ui.model.WorkbenchContentProvider;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 
 /**
- * <b><u>ImportDialog</u></b>
  * <p>
  * Dialog box for collecting trace import information.
  * </p>
+ *
+ * @author Bernd Hufmann
  */
 public class ImportDialog extends Dialog implements IImportDialog {
 
     // ------------------------------------------------------------------------
     // Constants
     // ------------------------------------------------------------------------
-    /**
-     * The icon file for this dialog box.
-     */
+    /** The icon file for this dialog box. */
     public static final String IMPORT_ICON_FILE = "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
-    
+
+    /** Parent directory for UST traces */
     public static final String UST_PARENT_DIRECTORY = "ust"; //$NON-NLS-1$
 
+    /** Name of metadata file of trace */
+    public static final String METADATA_FILE_NAME = "metadata"; //$NON-NLS-1$
+
+    /** Default name of kernel traces */
+    public static final String DEFAULT_KERNEL_TRACE_NAME = "kernel"; //$NON-NLS-1$
+
     // ------------------------------------------------------------------------
     // Attributes
     // ------------------------------------------------------------------------
@@ -84,7 +92,7 @@ public class ImportDialog extends Dialog implements IImportDialog {
      */
     private CCombo fCombo;
     /**
-     * The overwrite button 
+     * The overwrite button
      */
     private Button fOverwriteButton;
     /**
@@ -95,19 +103,24 @@ public class ImportDialog extends Dialog implements IImportDialog {
      * The parent where the new node should be added.
      */
     private TraceSessionComponent fSession = null;
+
     /**
-     * List of traces to import  
+     * The name of the default project name
      */
-    private List<ImportFileInfo> fTraces = new ArrayList<ImportFileInfo>();
+    private String fDefaultProjectName = null;
     /**
-     * Selection index in project combo box. 
+     * List of traces to import
+     */
+    private final List<ImportFileInfo> fTraces = new ArrayList<ImportFileInfo>();
+    /**
+     * Selection index in project combo box.
      */
     private int fProjectIndex;
     /**
      * Flag to indicate that something went wrong when creating the dialog box.
      */
     private boolean fIsError = false;
-    
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -123,10 +136,7 @@ public class ImportDialog extends Dialog implements IImportDialog {
     // ------------------------------------------------------------------------
     // Accessors
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#getTracePathes()
-     */
+
     @Override
     public List<ImportFileInfo> getTracePathes() {
         List<ImportFileInfo> retList = new ArrayList<ImportFileInfo>();
@@ -134,31 +144,25 @@ public class ImportDialog extends Dialog implements IImportDialog {
         return retList;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#getProject()
-     */
     @Override
     public IProject getProject() {
         return fProjects.get(fProjectIndex);
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#setSession(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent)
-     */
+
     @Override
     public void setSession(TraceSessionComponent session) {
         fSession = session;
     }
 
+    @Override
+    public void setDefaultProject(String defaultProject) {
+        fDefaultProjectName = defaultProject;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
-    /*
-     * (non-Javadoc)
-     * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
-     */
+
     @Override
     protected void configureShell(Shell newShell) {
         super.configureShell(newShell);
@@ -166,124 +170,37 @@ public class ImportDialog extends Dialog implements IImportDialog {
         newShell.setImage(Activator.getDefault().loadIcon(IMPORT_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));
 
-        Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-        contextGroup.setText(Messages.TraceControl_ImportDialogTracesGroupName);
-        layout = new GridLayout(1, true);
-        contextGroup.setLayout(layout);
-        contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
-        
-        IRemoteSystemProxy proxy = fSession.getTargetNode().getRemoteSystemProxy();
-        
-        IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
-
         try {
-            IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSession.getSessionPath(), new NullProgressMonitor());
-
-            fFolderViewer = new CheckboxTreeViewer(contextGroup, SWT.BORDER);
-            GridData data = new GridData(GridData.FILL_BOTH);
-            Tree tree = fFolderViewer.getTree();
-            tree.setLayoutData(data);
-            tree.setFont(parent.getFont());
-            tree.setToolTipText(Messages.TraceControl_ImportDialogTracesTooltip);
-            
-            fFolderViewer.setContentProvider(new FolderContentProvider());
-            fFolderViewer.setLabelProvider(new WorkbenchLabelProvider());
-            
-            fFolderViewer.addCheckStateListener(new ICheckStateListener() {
-                @Override
-                public void checkStateChanged(CheckStateChangedEvent event) {
-                    Object elem = event.getElement();
-                    if (elem instanceof IRemoteFile) {
-                        IRemoteFile element = (IRemoteFile) elem;
-                        if (!element.isDirectory()) {
-                            // A trick to keep selection of a file in sync with the directory
-                            boolean p = fFolderViewer.getChecked((element.getParentRemoteFile()));
-                            fFolderViewer.setChecked(element, p);
-                            return;
-                        }
-                        fFolderViewer.setSubtreeChecked(event.getElement(), event.getChecked());
-                        if (!event.getChecked()) { 
-                            fFolderViewer.setChecked(element.getParentRemoteFile(), false);
-                        }
-                    }
-                }
-            });
-            fFolderViewer.setInput(remoteFolder);
-
-            Group projectGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-            projectGroup.setText(Messages.TraceControl_ImportDialogProjectsGroupName);
-            layout = new GridLayout(1, true);
-            projectGroup.setLayout(layout);
-            projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
-            fProjects = new ArrayList<IProject>();
-            List<String> projectNames = new ArrayList<String>();
-            for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
-                try {
-                    if (project.isOpen() && project.hasNature(TmfProjectNature.ID)) {
-                        fProjects.add(project);
-                        projectNames.add(project.getName());
-                    }
-                } catch (CoreException e) {
-                    createErrorComposite(parent, e.fillInStackTrace());
-                    return fDialogComposite;
-                }
-            }
-
-            fCombo = new CCombo(projectGroup, SWT.READ_ONLY);
-            fCombo.setToolTipText(Messages.TraceControl_ImportDialogProjectsTooltip);
-            fCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1));
-            fCombo.setItems(projectNames.toArray(new String[projectNames.size()]));
-            
-            Group overrideGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
-            layout = new GridLayout(1, true);
-            overrideGroup.setLayout(layout);
-            overrideGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
-            fOverwriteButton = new Button(overrideGroup, SWT.CHECK);
-            fOverwriteButton.setText(Messages.TraceControl_ImportDialogOverwriteButtonText);
-
-            getShell().setMinimumSize(new Point(500, 400));
-
-            
+            createRemoteComposite();
+        } catch (CoreException e) {
+            createErrorComposite(parent, e.fillInStackTrace());
+            return fDialogComposite;
         } catch (SystemMessageException e) {
             createErrorComposite(parent, e.fillInStackTrace());
             return fDialogComposite;
         }
-        
         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.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 (!fIsError) {
+
             // Validate input data
             fTraces.clear();
 
@@ -312,20 +229,35 @@ public class ImportDialog extends Dialog implements IImportDialog {
             Object[] checked = fFolderViewer.getCheckedElements();
             for (int i = 0; i < checked.length; i++) {
                 IRemoteFile file = (IRemoteFile) checked[i];
-                
-                // Only add actual trace directories  
-                if (file.isDirectory() && !UST_PARENT_DIRECTORY.equals(file.getName())) {
-                    
-                    ImportFileInfo info = new ImportFileInfo(file, file.getName(), overwriteAll);
-                    String traceName = info.getLocalTraceName();
-                    IFolder folder = traceFolder.getFolder(traceName);
-
-                    // Verify if trace directory already exists (and not overwrite) 
+                if (!file.isDirectory() && file.getName().equals(METADATA_FILE_NAME)) {
+                    IRemoteFile trace = file.getParentRemoteFile();
+                    IRemoteFile parent = trace.getParentRemoteFile();
+                    boolean isKernel = false;
+                    if (trace.getName().equals(DEFAULT_KERNEL_TRACE_NAME)) {
+                        isKernel = true;
+                    }
+                    StringBuffer traceName = new StringBuffer();
+                    traceName.append(trace.getName());
+                    traceName.insert(0, '-');
+
+                    String path = fSession.isSnapshotSession() ? fSession.getSnapshotInfo().getSnapshotPath() : fSession.getSessionPath();
+
+                    while (!parent.getAbsolutePath().equals(path)) {
+                        traceName.insert(0, parent.getName());
+                        traceName.insert(0, '-');
+                        parent = parent.getParentRemoteFile();
+                    }
+                    traceName.insert(0, parent.getName());
+
+                    ImportFileInfo info = new ImportFileInfo(trace, traceName.toString(), overwriteAll, isKernel);
+                    IFolder folder = traceFolder.getFolder(traceName.toString());
+
+                    // Verify if trace directory already exists (and not overwrite)
                     if (folder.exists() && !overwriteAll) {
 
                         // Ask user for overwrite or new name
                         IImportConfirmationDialog conf = TraceControlDialogFactory.getInstance().getImportConfirmationDialog();
-                        conf.setTraceName(traceName);
+                        conf.setTraceName(traceName.toString());
 
                         // Don't add trace to list if dialog was cancelled.
                         if (conf.open() == Window.OK) {
@@ -335,7 +267,7 @@ public class ImportDialog extends Dialog implements IImportDialog {
                             }
                             fTraces.add(info);
                         }
-                    } else { 
+                    } else {
                         fTraces.add(info);
                     }
                 }
@@ -356,6 +288,12 @@ public class ImportDialog extends Dialog implements IImportDialog {
     // ------------------------------------------------------------------------
     // Helper methods and classes
     // ------------------------------------------------------------------------
+
+    /**
+     * Helper class for the contents of a folder in a tracing project
+     *
+     * @author Bernd Hufmann
+     */
     public static class FolderContentProvider extends WorkbenchContentProvider {
         @Override
         public Object[] getChildren(Object o) {
@@ -369,22 +307,22 @@ public class ImportDialog extends Dialog implements IImportDialog {
             return super.getChildren(o);
         }
     }
-    
+
     /**
      * Creates a dialog composite with an error message which can be used
      * when an exception occurred during creation time of the dialog box.
      * @param parent - a parent composite
-     * @param e - a error causing exception 
+     * @param e - a error causing exception
      */
     private void createErrorComposite(Composite parent, Throwable e) {
         fIsError = true;
         fDialogComposite.dispose();
-        
+
         fDialogComposite = new Composite(parent, SWT.NONE);
         GridLayout layout = new GridLayout(1, true);
         fDialogComposite.setLayout(layout);
         fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
-        
+
         Text errorText = new Text(fDialogComposite, SWT.MULTI);
         StringBuffer error = new StringBuffer();
         error.append(Messages.TraceControl_ImportDialogCreationError);
@@ -395,5 +333,97 @@ public class ImportDialog extends Dialog implements IImportDialog {
         errorText.setLayoutData(new GridData(GridData.FILL_BOTH));
     }
 
-    
+    private void createRemoteComposite() throws CoreException, SystemMessageException{
+        Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        contextGroup.setText(Messages.TraceControl_ImportDialogTracesGroupName);
+        GridLayout layout = new GridLayout(1, true);
+        contextGroup.setLayout(layout);
+        contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+        IRemoteSystemProxy proxy = fSession.getTargetNode().getRemoteSystemProxy();
+
+        IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
+
+        final String path = fSession.isSnapshotSession() ? fSession.getSnapshotInfo().getSnapshotPath() : fSession.getSessionPath();
+        final IRemoteFile remoteFolder = fsss.getRemoteFileObject(path, new NullProgressMonitor());
+        // make sure that remote directory is read and not cached
+        remoteFolder.markStale(true, true);
+
+        fFolderViewer = new CheckboxTreeViewer(contextGroup, SWT.BORDER);
+        GridData data = new GridData(GridData.FILL_BOTH);
+        Tree tree = fFolderViewer.getTree();
+        tree.setLayoutData(data);
+        tree.setFont(fDialogComposite.getFont());
+        tree.setToolTipText(Messages.TraceControl_ImportDialogTracesTooltip);
+
+        fFolderViewer.setContentProvider(new FolderContentProvider());
+        fFolderViewer.setLabelProvider(new WorkbenchLabelProvider());
+
+        fFolderViewer.addCheckStateListener(new ICheckStateListener() {
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent event) {
+                Object elem = event.getElement();
+                if (elem instanceof IRemoteFile) {
+                    IRemoteFile element = (IRemoteFile) elem;
+                    if (!element.isDirectory()) {
+                        // A trick to keep selection of a file in sync with the directory
+                        boolean p = fFolderViewer.getChecked((element.getParentRemoteFile()));
+                        fFolderViewer.setChecked(element, p);
+                        return;
+                    }
+                    fFolderViewer.setSubtreeChecked(event.getElement(), event.getChecked());
+                    if (!event.getChecked()) {
+                        fFolderViewer.setChecked(element.getParentRemoteFile(), false);
+                    }
+                }
+            }
+        });
+        fFolderViewer.setInput(remoteFolder);
+
+        Object[] children = remoteFolder.getContents(RemoteChildrenContentsType.getInstance());
+        // children can be null if there the path doesn't exist. This happens when a trace
+        // session hadn't been started and no output was created.
+        if (children != null) {
+            // Select all traces by default
+            for (int i = 0; i < children.length; i++) {
+                fFolderViewer.setSubtreeChecked(children[i], true);
+            }
+        }
+
+        Group projectGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        projectGroup.setText(Messages.TraceControl_ImportDialogProjectsGroupName);
+        layout = new GridLayout(1, true);
+        projectGroup.setLayout(layout);
+        projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+        fProjects = new ArrayList<IProject>();
+        List<String> projectNames = new ArrayList<String>();
+
+        for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+            if (project.isOpen() && project.hasNature(TmfProjectNature.ID)) {
+                fProjects.add(project);
+                projectNames.add(project.getName());
+            }
+        }
+
+        fCombo = new CCombo(projectGroup, SWT.READ_ONLY);
+        fCombo.setToolTipText(Messages.TraceControl_ImportDialogProjectsTooltip);
+        fCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1));
+        fCombo.setItems(projectNames.toArray(new String[projectNames.size()]));
+
+        if (fDefaultProjectName != null) {
+            int select = projectNames.indexOf(fDefaultProjectName);
+            fCombo.select(select);
+        }
+
+        Group overrideGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+        layout = new GridLayout(1, true);
+        overrideGroup.setLayout(layout);
+        overrideGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+        fOverwriteButton = new Button(overrideGroup, SWT.CHECK);
+        fOverwriteButton.setText(Messages.TraceControl_ImportDialogOverwriteButtonText);
+        getShell().setMinimumSize(new Point(500, 400));
+    }
+
  }
This page took 0.028656 seconds and 5 git commands to generate.