tmf-remote: Bug 460847: add model for remote fetching of traces
authorMarc-Andre Laperle <Marc-Andre.Laperle@ericsson.com>
Tue, 24 Mar 2015 17:36:01 +0000 (13:36 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 25 Mar 2015 21:06:48 +0000 (17:06 -0400)
Change-Id: I9d9ef176ac72ee93edf62df1797309b6d843b430
Signed-off-by: Marc-Andre Laperle <Marc-Andre.Laperle@ericsson.com>
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Signed-off-by: Patrick Tasse <Patrick.Tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/44526
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
17 files changed:
org.eclipse.tracecompass.tmf.remote.ui/META-INF/MANIFEST.MF
org.eclipse.tracecompass.tmf.remote.ui/build.properties
org.eclipse.tracecompass.tmf.remote.ui/icons/obj/connection_node.gif [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/icons/obj/profile.gif [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/icons/obj/trace_group.gif [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/schema/remote-profile.xsd [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/AbstractGenerateManifestOperation.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/ExtractRemoteProfilesOperation.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportConnectionNodeElement.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportFolderElement.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileConstants.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileElement.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesReader.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesWriter.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceFilesElement.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceGroupElement.java [new file with mode: 0644]
org.eclipse.tracecompass.tmf.ui/META-INF/MANIFEST.MF

index e2f3d0f4e0cf55fe187731cc2c8c4f9c91023d5d..8f7f8e4f0a80b1b694f2500f4a3e73a902ec0df8 100644 (file)
@@ -8,8 +8,19 @@ Bundle-SymbolicName: org.eclipse.tracecompass.tmf.remote.ui;singleton:=true
 Bundle-Activator: org.eclipse.tracecompass.internal.tmf.remote.ui.Activator
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.7
-Require-Bundle: org.eclipse.ui,
- org.eclipse.core.runtime,
- org.eclipse.tracecompass.tmf.remote.core
-Export-Package: org.eclipse.tracecompass.internal.tmf.remote.ui,
- org.eclipse.tracecompass.internal.tmf.remote.ui.preferences
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.filesystem,
+ org.eclipse.core.resources,
+ org.eclipse.remote.jsch.core,
+ org.eclipse.remote.ui;bundle-version="2.0.0",
+ org.eclipse.remote.core;bundle-version="2.0.0",
+ org.eclipse.tracecompass.tmf.core,
+ org.eclipse.tracecompass.tmf.ui,
+ org.eclipse.tracecompass.common.core,
+ org.eclipse.tracecompass.tmf.remote.core,
+ org.eclipse.ui,
+ org.eclipse.ui.ide,
+ org.eclipse.ui.views
+Export-Package: org.eclipse.tracecompass.internal.tmf.remote.ui;x-internal:=true,
+ org.eclipse.tracecompass.internal.tmf.remote.ui.preferences;x-internal:=true,
+ org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;x-internal:=true
index 3ee69f46373a2345599c4f91ca17daa9c20605e2..d988db7dc73f89af2a643ed6a5f24022dd432988 100644 (file)
@@ -15,7 +15,9 @@ bin.includes = META-INF/,\
                .,\
                plugin.xml,\
                plugin.properties,\
-               about.html
+               about.html,\
+               schema/,\
+               icons/
 src.includes = about.html
 additional.bundles = org.eclipse.jdt.annotation
 jars.extra.classpath = platform:/plugin/org.eclipse.jdt.annotation
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/connection_node.gif b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/connection_node.gif
new file mode 100644 (file)
index 0000000..def312a
Binary files /dev/null and b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/connection_node.gif differ
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/profile.gif b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/profile.gif
new file mode 100644 (file)
index 0000000..c984fba
Binary files /dev/null and b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/profile.gif differ
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/trace_group.gif b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/trace_group.gif
new file mode 100644 (file)
index 0000000..fca9c53
Binary files /dev/null and b/org.eclipse.tracecompass.tmf.remote.ui/icons/obj/trace_group.gif differ
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/schema/remote-profile.xsd b/org.eclipse.tracecompass.tmf.remote.ui/schema/remote-profile.xsd
new file mode 100644 (file)
index 0000000..ead1f88
--- /dev/null
@@ -0,0 +1,58 @@
+<!--
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *     Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+-->
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="profiles">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="version" maxOccurs="1" minOccurs="1"/>
+        <xs:element name="profile" maxOccurs="unbounded" minOccurs="0">
+          <xs:complexType>
+            <xs:sequence>
+              <xs:element name="node" maxOccurs="unbounded" minOccurs="1">
+                <xs:complexType>
+                  <xs:sequence>
+                    <xs:element name="uri" maxOccurs="1" minOccurs="1"/>
+                    <xs:element name="traceGroup" maxOccurs="unbounded" minOccurs="1">
+                      <xs:complexType>
+                        <xs:sequence>
+                          <xs:element name="trace" maxOccurs="unbounded" minOccurs="1">
+                            <xs:complexType>
+                              <xs:sequence>
+                                <xs:element name="file" maxOccurs="1" minOccurs="1">
+                                  <xs:complexType>
+                                    <xs:attribute type="xs:string" name="name" use="required"/>
+                                  </xs:complexType>
+                                </xs:element>
+                              </xs:sequence>
+                              <xs:attribute type="xs:string" name="name"/>
+                              <xs:attribute type="xs:string" name="type"/>
+                            </xs:complexType>
+                          </xs:element>
+                        </xs:sequence>
+                        <xs:attribute type="xs:string" name="root" use="required"/>
+                        <xs:attribute type="xs:string" name="recursive" use="required"/>
+                      </xs:complexType>
+                    </xs:element>
+                  </xs:sequence>
+                  <xs:attribute type="xs:string" name="name" use="required"/>
+                </xs:complexType>
+              </xs:element>
+            </xs:sequence>
+            <xs:attribute type="xs:string" name="name" use="required"/>
+          </xs:complexType>
+        </xs:element>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/AbstractGenerateManifestOperation.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/AbstractGenerateManifestOperation.java
new file mode 100644 (file)
index 0000000..a697cc6
--- /dev/null
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement;
+import org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType;
+
+/**
+ * Abstract operation that generates the manifest based on the content of a
+ * remote node or import package.
+ *
+ * @author Marc-Andre Laperle
+ * @author Bernd Hufmann
+ */
+abstract public class AbstractGenerateManifestOperation extends AbstractTracePackageOperation {
+
+    /** A pattern to find where to substitute groups in the trace name */
+    protected static final Pattern GROUP_PATTERN = Pattern.compile("\\(group(\\d+)\\)"); //$NON-NLS-1$
+
+    /** Name of metadata file of trace */
+    protected static final String METADATA_FILE_NAME = "metadata"; //$NON-NLS-1$
+    /** Map of pattern to trace element */
+    protected Map<Pattern, TracePackageTraceElement> fTemplatePatternsToTraceElements;
+
+    /**
+     * Constructs a new trace package operation
+     *
+     * @param fileName
+     *            the output file name
+     */
+    public AbstractGenerateManifestOperation(String fileName) {
+        super(fileName);
+    }
+
+    /**
+     * Generates regular expression patterns from the template element.
+     *
+     * @param templateElements
+     *            input template elements
+     * @return map of generated {@link Pattern} to corresponding
+     *         {@link TracePackageFilesElement}
+     */
+    protected Map<Pattern, TracePackageTraceElement> generatePatterns(TracePackageElement[] templateElements) {
+        Map<Pattern, TracePackageTraceElement> templatePatterns = new HashMap<>();
+        for (TracePackageElement templateElement : templateElements) {
+            if (templateElement instanceof TracePackageTraceElement) {
+                TracePackageElement[] children = templateElement.getChildren();
+                if (children != null) {
+                    for (TracePackageElement child : children) {
+                        if (child instanceof TracePackageFilesElement) {
+                            TracePackageFilesElement tracePackageFilesElement = (TracePackageFilesElement) child;
+                            Pattern pattern = Pattern.compile(tracePackageFilesElement.getFileName());
+                            templatePatterns.put(pattern, (TracePackageTraceElement) templateElement);
+                        }
+                    }
+                }
+            }
+        }
+        return templatePatterns;
+    }
+
+    /**
+     * Returns a matching pair of {@link Pattern} to corresponding
+     * {@link TracePackageFilesElement} from given path.
+     *
+     * @param fullArchivePath
+     *            the input path to match
+     * @return a matching pair of {@link Pattern} to corresponding
+     *         {@link TracePackageFilesElement}
+     */
+    protected Entry<Pattern, TracePackageTraceElement> getMatchingTemplateElement(IPath fullArchivePath) {
+        for (Entry<Pattern, TracePackageTraceElement> entry : fTemplatePatternsToTraceElements.entrySet()) {
+            // Check for CTF trace (metadata)
+            if (TmfTraceType.isDirectoryTraceType(entry.getValue().getTraceType())) {
+                if (matchesDirectoryTrace(fullArchivePath, entry)) {
+                    return entry;
+                }
+            } else if (entry.getKey().matcher(fullArchivePath.toPortableString()).matches()) {
+                return entry;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns whether {@link Pattern} and trace type of
+     * {@link TracePackageFilesElement} matches a directory trace or not.
+     *
+     * @param archivePath
+     *            the archive path
+     * @param entry
+     *            the map entry of {@link Pattern} to corresponding
+     *            {@link TracePackageFilesElement}
+     *
+     * @return <code>true</code> for directory trace else false
+     */
+    protected boolean matchesDirectoryTrace(IPath archivePath, Entry<Pattern, TracePackageTraceElement> entry) {
+        if (archivePath.lastSegment().equals(METADATA_FILE_NAME)) {
+            IPath archiveParentPath = archivePath.removeLastSegments(1);
+            if (entry.getKey().matcher(archiveParentPath.toPortableString()).matches()) {
+                if (TmfTraceType.isDirectoryTraceType(entry.getValue().getTraceType())) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Substitute group patterns inside the trace name with the groups found in
+     * the file name. This allows renaming traces in flexible ways. For example:
+     *
+     * Filename: folder/blah.1.txt Filename pattern: folder/blah.(\d+).txt Trace
+     * name: folder-blah.(group1).txt
+     *
+     * Result: folder-blah.1.txt
+     *
+     * @param traceName
+     *            the target trace name that will get it's groups substituted
+     * @param fileNamePattern
+     *            the file name pattern that matched the filename and contains
+     *            groups to be used in the substitutions
+     * @param fileName
+     *            the file name in the archive
+     * @return the resulting String, with the (group#) patterns substituted
+     */
+    protected String substituteGroups(String traceName, Pattern fileNamePattern, String fileName) {
+        String newString = traceName;
+
+        Matcher fileNameMatcher = fileNamePattern.matcher(fileName);
+        fileNameMatcher.find();
+        int groupCount = fileNameMatcher.groupCount();
+        Matcher matcher = GROUP_PATTERN.matcher(newString);
+        while (matcher.find()) {
+            // Found (group#), now get the #
+            if (matcher.groupCount() == 1) {
+                int groupNo = Integer.parseInt(matcher.group(1));
+                if (groupNo <= groupCount) {
+                    String substitutedString = newString.substring(0, matcher.start()) + fileNameMatcher.group(groupNo) + newString.substring(matcher.end());
+                    if (!substitutedString.equals(newString)) {
+                        // Since the string changed, create a new matcher so
+                        // that the next match is at a valid position
+                        newString = substitutedString;
+                        matcher = GROUP_PATTERN.matcher(newString);
+                    }
+                }
+            }
+        }
+
+        return newString;
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/ExtractRemoteProfilesOperation.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/ExtractRemoteProfilesOperation.java
new file mode 100644 (file)
index 0000000..b00b719
--- /dev/null
@@ -0,0 +1,79 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *     Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import java.io.File;
+import java.io.FileInputStream;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+
+/**
+ * An operation that extracts profiles information from a file
+ *
+ * @author Marc-Andre Laperle
+ */
+public class ExtractRemoteProfilesOperation extends AbstractTracePackageOperation {
+
+    /**
+     * Constructs a new import operation for reading the profiles
+     *
+     * @param fileName
+     *            the output file name
+     */
+    public ExtractRemoteProfilesOperation(String fileName) {
+        super(fileName);
+    }
+
+    /**
+     * Run the extract profiles operation. The status (result) of the operation
+     * can be obtained with {@link #getStatus}
+     *
+     * @param progressMonitor
+     *            the progress monitor to use to display progress and receive
+     *            requests for cancellation
+     */
+    @Override
+    public void run(IProgressMonitor progressMonitor) {
+        TracePackageElement[] elements = null;
+        try {
+            progressMonitor.worked(1);
+            File file = new File(getFileName());
+            progressMonitor.worked(1);
+            if (!file.exists()) {
+                setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Invalid format")); //$NON-NLS-1$
+                return;
+            }
+
+            // TODO backwards compatibility for location
+            try (FileInputStream inputStream = new FileInputStream(file)) {
+                RemoteImportProfilesReader.validate(inputStream);
+            }
+
+            try (FileInputStream inputStream = new FileInputStream(file)) {
+                elements = RemoteImportProfilesReader.loadElementsFromProfiles(inputStream);
+            }
+
+            progressMonitor.worked(1);
+
+            setResultElements(elements);
+            setStatus(Status.OK_STATUS);
+        } catch (Exception e) {
+            setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error reading profiles", e)); //$NON-NLS-1$
+        }
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportConnectionNodeElement.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportConnectionNodeElement.java
new file mode 100644 (file)
index 0000000..22ee6bb
--- /dev/null
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *     Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+
+/**
+ * An RemoteImportConnectionNodeElement representing a connection node.
+ *
+ * @author Marc-Andre Laperle
+ */
+public class RemoteImportConnectionNodeElement extends TracePackageElement {
+
+    private static final String IMAGE_PATH = "icons/obj/connection_node.gif"; //$NON-NLS-1$
+
+    private String fName;
+    private String fURI;
+
+    /**
+     * Constructs an instance of RemoteImportConnectionNodeElement.
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param name
+     *            the node name
+     * @param uri
+     *            the URI in string form to connect to the node
+     */
+    public RemoteImportConnectionNodeElement(TracePackageElement parent,
+            String name, String uri) {
+        super(parent);
+        fName = name;
+        fURI = uri;
+    }
+
+    @Override
+    public String getText() {
+        return fName + " (" + fURI + ")"; //$NON-NLS-1$//$NON-NLS-2$
+    }
+
+    @Override
+    public Image getImage() {
+        return Activator.getDefault().getImageFromImageRegistry(IMAGE_PATH);
+    }
+
+    /**
+     * Get the name of the connection.
+     *
+     * @return the name of the connection
+     */
+    public String getName() {
+        return fName;
+    }
+
+    /**
+     * Set the name of the connection.
+     *
+     * @param name the name of the connection
+     */
+    public void setName(String name) {
+        fName = name;
+    }
+
+    /**
+     * Get the URI of the connection.
+     *
+     * @return the URI of the connection
+     */
+    public String getURI() {
+        return fURI;
+    }
+
+    /**
+     * Set the URI of the connection.
+     *
+     * @param uri the URI of the connection
+     */
+    public void setURI(String uri) {
+        fURI = uri;
+    }
+
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportFolderElement.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportFolderElement.java
new file mode 100644 (file)
index 0000000..c8a29fe
--- /dev/null
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *     Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * An RemoteImportFolderElement representing a remote folder.
+ *
+ * @author Patrick Tasse
+ */
+public class RemoteImportFolderElement extends TracePackageElement {
+
+    private static final Image IMAGE = PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
+    private String fFolderName;
+
+    /**
+     * Constructs an instance of RemoteImportTraceGroupElement
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param folderName
+     *            the remote folder name
+     */
+    public RemoteImportFolderElement(TracePackageElement parent, String folderName) {
+        super(parent);
+        fFolderName = folderName;
+    }
+
+    @Override
+    public String getText() {
+        return fFolderName;
+    }
+
+    @Override
+    public Image getImage() {
+        return IMAGE;
+    }
+
+    /**
+     * Get the folder name.
+     *
+     * @return the folder name
+     */
+    public String getFolderName() {
+        return fFolderName;
+    }
+
+    /**
+     * Set the folder name.
+     *
+     * @param folderName
+     *            the folder name
+     */
+    public void setFolderName(String folderName) {
+        fFolderName = folderName;
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileConstants.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileConstants.java
new file mode 100644 (file)
index 0000000..ab9379d
--- /dev/null
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *   Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+/**
+ * Constants used in the remote import model (XML attribute and element names, etc).
+ *
+ * @author Marc-Andre Laperle
+ * @noimplement
+ */
+public interface RemoteImportProfileConstants {
+
+    /**
+     * The current version constant.
+     */
+    public static final String VERSION = "0.1"; //$NON-NLS-1$
+
+    /**
+     * Element representing the root of the profiles.
+     */
+    public static final String PROFILES_ELEMENT = "profiles"; //$NON-NLS-1$
+
+    /**
+     * Element representing the version the profiles file.
+     */
+    public static final String VERSION_ELEMENT = "version"; //$NON-NLS-1$
+
+    /**
+     * Element representing the root of a profile.
+     */
+    public static final String PROFILE_ELEMENT = "profile"; //$NON-NLS-1$
+
+    /**
+     * Attribute representing the name of a profile.
+     */
+    public static final String PROFILE_NAME_ATTRIB = "name"; //$NON-NLS-1$
+
+    /**
+     * Element representing the a group of traces.
+     */
+    public static final String TRACE_GROUP_ELEMENT = "traceGroup"; //$NON-NLS-1$
+
+    /**
+     * Attribute representing the root path of a trace group.
+     */
+    public static final String TRACE_GROUP_ROOT_ATTRIB = "root"; //$NON-NLS-1$
+
+    /**
+     * Attribute representing whether or not the group of traces should be
+     * imported recursively.
+     */
+    public static final String TRACE_GROUP_RECURSIVE_ATTRIB = "recursive"; //$NON-NLS-1$
+
+    /**
+     * Element representing the connection node.
+     */
+    public static final String NODE_ELEMENT = "node"; //$NON-NLS-1$
+
+    /**
+     * Attribute representing the name of the connection node.
+     */
+    public static final String NODE_NAME_ATTRIB = "name"; //$NON-NLS-1$
+
+    /**
+     * Element representing the URI of the connection node.
+     */
+    public static final String NODE_URI_ELEMENT = "uri"; //$NON-NLS-1$
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileElement.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfileElement.java
new file mode 100644 (file)
index 0000000..eaa7b3e
--- /dev/null
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *     Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+
+/**
+ * An RemoteImportProfileElement representing a profile for importing traces remotely.
+ *
+ * @author Marc-Andre Laperle
+ */
+public class RemoteImportProfileElement extends TracePackageElement {
+
+    private static final String IMAGE_PATH = "icons/obj/profile.gif"; //$NON-NLS-1$
+    private String fProfileName;
+
+    /**
+     * Constructs an instance of RemoteImportProfileElement
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param profileName
+     *            the profile name
+     */
+    public RemoteImportProfileElement(TracePackageElement parent,
+            String profileName) {
+        super(parent);
+        fProfileName = profileName;
+    }
+
+    @Override
+    public String getText() {
+        return fProfileName;
+    }
+
+    @Override
+    public Image getImage() {
+        return Activator.getDefault().getImageFromImageRegistry(IMAGE_PATH);
+    }
+
+    /**
+     * Get the name of the profile.
+     *
+     * @return the name of the profile
+     */
+    public String getProfileName() {
+        return fProfileName;
+    }
+
+    /**
+     * Set the name of the profile.
+     *
+     * @param profileName the name of the profile
+     */
+    public void setProfileName(String profileName) {
+        fProfileName = profileName;
+    }
+
+    /**
+     * Returns the list of remote connection elements
+     *
+     * @return a list of remote connection elements
+     */
+    public List<RemoteImportConnectionNodeElement> getConnectionNodeElements() {
+        List<RemoteImportConnectionNodeElement> remoteHosts = new ArrayList<>();
+        for (TracePackageElement element : getChildren()) {
+            if (element instanceof RemoteImportConnectionNodeElement) {
+                // only one node per profile is supported
+                remoteHosts.add((RemoteImportConnectionNodeElement) element);
+            }
+        }
+        return remoteHosts;
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesReader.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesReader.java
new file mode 100644 (file)
index 0000000..ed962f1
--- /dev/null
@@ -0,0 +1,188 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *   Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.importexport.ManifestReader;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.importexport.Messages;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * Reads a profiles file from an input stream
+ *
+ * @author Marc-Andre Laperle
+ */
+public class RemoteImportProfilesReader {
+
+    private static final String SCHEMA_FOLDER_NAME = "schema"; //$NON-NLS-1$
+    private static final String PROFILES_SCHEMA_FILE_NAME = "remote-profile.xsd"; //$NON-NLS-1$
+    private static final TracePackageElement[] EMPTY_ARRAY = new TracePackageElement[0];
+
+    /**
+     * Validate the content of the profiles file from an input stream
+     *
+     * @param input
+     *            the input stream to validate from
+     * @throws IOException
+     *             on error
+     * @throws SAXException
+     *             on error
+     */
+    public static void validate(InputStream input) throws IOException, SAXException {
+        URL schemaFileUrl = FileLocator.find(
+                Activator.getDefault().getBundle(),
+                new Path(SCHEMA_FOLDER_NAME).append(PROFILES_SCHEMA_FILE_NAME),
+                null);
+        if (schemaFileUrl == null) {
+            throw new IOException(
+                    MessageFormat.format(
+                            Messages.TracePackageExtractManifestOperation_SchemaFileNotFound,
+                            PROFILES_SCHEMA_FILE_NAME));
+        }
+
+        try {
+            SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+            Schema schema = factory.newSchema(new StreamSource(
+                    schemaFileUrl.openStream()));
+            Validator validator = schema.newValidator();
+            validator.validate(new StreamSource(input));
+        } catch (SAXException e) {
+            throw new SAXException(
+                    Messages.TracePackageExtractManifestOperation_ErrorManifestNotValid,
+                    e);
+        } catch (IOException e) {
+            throw new IOException(
+                    Messages.TracePackageExtractManifestOperation_ErrorManifestNotValid,
+                    e);
+        }
+    }
+
+    /**
+     * Load profile model elements the profiles file (input stream).
+     *
+     * The file format looks like this:
+     * <pre>
+     * &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?>
+     * &lt;profiles>
+     *   &lt;version>0.1&lt;/version>
+     *   &lt;profile name="myProfile">
+     *     &lt;node name="myhost">
+     *       &lt;uri>ssh://user@127.0.0.1:22&lt;/uri>
+     *       &lt;traceGroup root="/home/user/lttng-traces/" recursive="true">
+     *         &lt;trace name="" type="org.eclipse.linuxtools.tmf.ui.type.ctf">
+     *           &lt;file name=".*" />
+     *         &lt;/trace>
+     *       &lt;/traceGroup>
+     *     &lt;/node>
+     *   &lt;/profile>
+     * &lt;/profiles>
+     * </pre>
+     * See schema/remote-profile.xsd for details.
+     *
+     * @param inputStream
+     *            the input stream that contains the profiles
+     * @return the loaded elements
+     * @throws IOException
+     *             when an error occurs when parsing
+     * @throws SAXException
+     *             when an error occurs when parsing
+     * @throws ParserConfigurationException
+     *             when an error occurs when parsing
+     */
+    public static TracePackageElement[] loadElementsFromProfiles(InputStream inputStream)
+            throws IOException, SAXException, ParserConfigurationException {
+
+        List<TracePackageElement> packageElements = new ArrayList<>();
+        RemoteImportProfileElement profile = null;
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
+                inputStream);
+
+        NodeList profileNodes = doc.getDocumentElement().getElementsByTagName(
+                RemoteImportProfileConstants.PROFILE_ELEMENT);
+        for (int i = 0; i < profileNodes.getLength(); i++) {
+            Node profileNode = profileNodes.item(i);
+            if (profileNode.getNodeType() == Node.ELEMENT_NODE) {
+                Element profileElement = (Element) profileNode;
+                String traceName = profileElement.getAttribute(RemoteImportProfileConstants.PROFILE_NAME_ATTRIB);
+                profile = new RemoteImportProfileElement(null, traceName);
+
+                NodeList nodeNodes = profileElement.getElementsByTagName(RemoteImportProfileConstants.NODE_ELEMENT);
+                for (int j = 0; j < nodeNodes.getLength(); j++) {
+                    Node nodeNode = nodeNodes.item(j);
+                    if (nodeNode.getNodeType() == Node.ELEMENT_NODE) {
+                        Element nodeElement = (Element) nodeNode;
+                        String nameAttr = nodeElement.getAttribute(RemoteImportProfileConstants.NODE_NAME_ATTRIB);
+
+                        NodeList uriNodes = nodeElement.getElementsByTagName(RemoteImportProfileConstants.NODE_URI_ELEMENT);
+                        String uri = ""; //$NON-NLS-1$
+                        for (int k = 0; k < uriNodes.getLength(); k++) {
+                            Node uriNode = uriNodes.item(k);
+                            if (uriNode.getNodeType() == Node.ELEMENT_NODE) {
+                                Element uriElement = (Element) uriNode;
+                                uri = uriElement.getFirstChild().getNodeValue();
+                                break;
+                            }
+                        }
+
+                        RemoteImportConnectionNodeElement connectionNode = new RemoteImportConnectionNodeElement(profile,
+                                nameAttr, uri);
+
+                        NodeList traceGroupNodes = nodeElement.getElementsByTagName(RemoteImportProfileConstants.TRACE_GROUP_ELEMENT);
+                        for (int k = 0; k < traceGroupNodes.getLength(); k++) {
+                            Node traceGroupNode = traceGroupNodes.item(k);
+                            if (traceGroupNode.getNodeType() == Node.ELEMENT_NODE) {
+                                Element traceGroupElement = (Element) traceGroupNode;
+                                String rootAttr = traceGroupElement.getAttribute(RemoteImportProfileConstants.TRACE_GROUP_ROOT_ATTRIB);
+                                String recursiveAttr = traceGroupElement.getAttribute(RemoteImportProfileConstants.TRACE_GROUP_RECURSIVE_ATTRIB);
+                                RemoteImportTraceGroupElement traceGroup = new RemoteImportTraceGroupElement(
+                                        connectionNode, rootAttr);
+                                traceGroup.setRecursive(Boolean.TRUE.toString().equals(
+                                        recursiveAttr));
+                                TracePackageElement[] e = ManifestReader.loadElementsFromNode(traceGroupElement);
+                                for (TracePackageElement a : e) {
+                                    traceGroup.addChild(a);
+                                }
+                            }
+                        }
+
+                    }
+                }
+
+                packageElements.add(profile);
+            }
+        }
+        return packageElements.toArray(EMPTY_ARRAY);
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesWriter.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportProfilesWriter.java
new file mode 100644 (file)
index 0000000..18e194c
--- /dev/null
@@ -0,0 +1,163 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *   Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.ITracePackageConstants;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Writes profiles to XML format.
+ *
+ * @author Marc-Andre Laperle
+ */
+public class RemoteImportProfilesWriter {
+
+    /**
+     * Write the profiles to XML format.
+     *
+     * @param profiles
+     *            the profile elements to write to XML
+     *
+     * @return the generated XML
+     * @throws ParserConfigurationException
+     *             when an error occurs when parsing
+     * @throws TransformerException
+     *             when an error occurs when transforming the XML
+     */
+    public static String writeProfilesToXML(TracePackageElement[] profiles)
+            throws ParserConfigurationException, TransformerException {
+
+        Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+        Element profilesElement = doc.createElement(RemoteImportProfileConstants.PROFILES_ELEMENT);
+        doc.appendChild(profilesElement);
+        Element versionElement = doc.createElement(RemoteImportProfileConstants.VERSION_ELEMENT);
+        versionElement.setTextContent(RemoteImportProfileConstants.VERSION);
+        profilesElement.appendChild(versionElement);
+
+        for (TracePackageElement profile : profiles) {
+            if (profile instanceof RemoteImportProfileElement) {
+                exportProfile(profilesElement,
+                        (RemoteImportProfileElement) profile);
+            }
+        }
+
+        Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+        transformer.setOutputProperty(
+                "{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
+        DOMSource source = new DOMSource(doc);
+        StringWriter buffer = new StringWriter();
+        StreamResult result = new StreamResult(buffer);
+        transformer.transform(source, result);
+        String content = buffer.getBuffer().toString();
+
+        return content;
+    }
+
+    private static void exportProfile(Node profilesNode,
+            RemoteImportProfileElement profile) {
+        Element profileElement = profilesNode.getOwnerDocument().createElement(
+                RemoteImportProfileConstants.PROFILE_ELEMENT);
+        profileElement.setAttribute(
+                RemoteImportProfileConstants.PROFILE_NAME_ATTRIB,
+                profile.getProfileName());
+
+        for (TracePackageElement connectionNode : profile.getChildren()) {
+            if (connectionNode instanceof RemoteImportConnectionNodeElement) {
+                exportConnectionNode(profileElement,
+                        (RemoteImportConnectionNodeElement) connectionNode);
+            }
+        }
+        profilesNode.appendChild(profileElement);
+    }
+
+    private static void exportConnectionNode(Node profileNode,
+            RemoteImportConnectionNodeElement connectionNode) {
+        Element nodeElement = profileNode.getOwnerDocument().createElement(
+                RemoteImportProfileConstants.NODE_ELEMENT);
+        nodeElement.setAttribute(RemoteImportProfileConstants.NODE_NAME_ATTRIB,
+                connectionNode.getName());
+        profileNode.appendChild(nodeElement);
+        Element uriElement = profileNode.getOwnerDocument().createElement(
+                RemoteImportProfileConstants.NODE_URI_ELEMENT);
+        uriElement.setTextContent(connectionNode.getURI());
+        nodeElement.appendChild(uriElement);
+
+        for (TracePackageElement traceGroup : connectionNode.getChildren()) {
+            if (traceGroup instanceof RemoteImportTraceGroupElement) {
+                exportTraceGroup(nodeElement,
+                        (RemoteImportTraceGroupElement) traceGroup);
+            }
+        }
+    }
+
+    private static void exportTraceGroup(Node nodeNode,
+            RemoteImportTraceGroupElement traceGroup) {
+        Element traceGroupElement = nodeNode.getOwnerDocument().createElement(
+                RemoteImportProfileConstants.TRACE_GROUP_ELEMENT);
+        traceGroupElement.setAttribute(
+                RemoteImportProfileConstants.TRACE_GROUP_ROOT_ATTRIB,
+                traceGroup.getRootImportPath());
+        traceGroupElement.setAttribute(
+                RemoteImportProfileConstants.TRACE_GROUP_RECURSIVE_ATTRIB,
+                Boolean.toString(traceGroup.isRecursive()));
+        for (TracePackageElement trace : traceGroup.getChildren()) {
+            if (trace instanceof TracePackageTraceElement) {
+                exportTrace(traceGroupElement, (TracePackageTraceElement) trace);
+            }
+        }
+        nodeNode.appendChild(traceGroupElement);
+    }
+
+    private static void exportTrace(Node traceGroupNode,
+            TracePackageTraceElement trace) {
+        Element traceElement = traceGroupNode.getOwnerDocument().createElement(
+                ITracePackageConstants.TRACE_ELEMENT);
+        traceElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB,
+                trace.getImportName());
+        traceElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB,
+                trace.getTraceType());
+        for (TracePackageElement files : trace.getChildren()) {
+            if (files instanceof TracePackageFilesElement) {
+                exportTraceFiles(traceElement, (TracePackageFilesElement) files);
+                break;
+            }
+        }
+        traceGroupNode.appendChild(traceElement);
+    }
+
+    private static void exportTraceFiles(Node traceNode,
+            TracePackageFilesElement files) {
+        Element fileElement = traceNode.getOwnerDocument().createElement(
+                ITracePackageConstants.TRACE_FILE_ELEMENT);
+        fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB,
+                files.getFileName());
+        traceNode.appendChild(fileElement);
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceFilesElement.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceFilesElement.java
new file mode 100644 (file)
index 0000000..1e401fd
--- /dev/null
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement;
+
+/**
+ * An remote trace element representing the trace files of a trace.
+ *
+ * @author Bernd Hufmann
+ */
+public class RemoteImportTraceFilesElement extends TracePackageFilesElement {
+
+    private final IFileStore fRemoteFile;
+
+    /**
+     * Constructs an instance of ExportTraceFilesElement when exporting
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param resource
+     *            the resource representing the trace file or folder in the
+     *            workspace
+     */
+    public RemoteImportTraceFilesElement(TracePackageElement parent, IResource resource) {
+        super(parent, resource);
+        fRemoteFile = null;
+    }
+
+    /**
+     * Constructs an instance of ExportTraceFilesElement when importing
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param fileName
+     *            the name of the file to be imported
+     * @param remoteFile
+     *            the remote file representing the trace
+     */
+    public RemoteImportTraceFilesElement(TracePackageElement parent, String fileName, IFileStore remoteFile) {
+        super(parent, fileName);
+        fRemoteFile = remoteFile;
+    }
+
+    /**
+     * Returns the remote file representing the trace
+     * @return the remote file
+     */
+    public IFileStore getRemoteFile() {
+        return fRemoteFile;
+    }
+}
diff --git a/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceGroupElement.java b/org.eclipse.tracecompass.tmf.remote.ui/src/org/eclipse/tracecompass/internal/tmf/remote/ui/wizards/fetch/model/RemoteImportTraceGroupElement.java
new file mode 100644 (file)
index 0000000..04879df
--- /dev/null
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2015 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:
+ *   Marc-Andre Laperle - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model;
+
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.tracecompass.internal.tmf.remote.ui.Activator;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement;
+
+/**
+ * An RemoteImportTraceGroupElement representing the a group of traces under a
+ * root path.
+ *
+ * @author Marc-Andre Laperle
+ */
+public class RemoteImportTraceGroupElement extends TracePackageElement {
+
+    private static final String IMAGE_PATH = "icons/obj/trace_group.gif"; //$NON-NLS-1$
+    private String fRootImportPath;
+    private boolean fRecursive;
+
+    /**
+     * Constructs an instance of RemoteImportTraceGroupElement
+     *
+     * @param parent
+     *            the parent of this element, can be set to null
+     * @param rootImportPath
+     *            the root path where the traces should be imported from
+     */
+    public RemoteImportTraceGroupElement(TracePackageElement parent,
+            String rootImportPath) {
+        super(parent);
+        fRootImportPath = rootImportPath;
+        fRecursive = false;
+    }
+
+    @Override
+    public String getText() {
+        return fRootImportPath + (isRecursive() ? " (recursive)" : ""); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    /**
+     * Returns whether or not the group of traces should be imported recursively
+     * from the root path.
+     *
+     * @return whether or not the trace group is recursive
+     */
+    public boolean isRecursive() {
+        return fRecursive;
+    }
+
+    /**
+     * Sets whether or not the group of traces should be imported recursively
+     * from the root path.
+     *
+     * @param recursive
+     *            if the element should be recursive
+     */
+    public void setRecursive(boolean recursive) {
+        fRecursive = recursive;
+    }
+
+    @Override
+    public Image getImage() {
+        return Activator.getDefault().getImageFromImageRegistry(IMAGE_PATH);
+    }
+
+    /**
+     * Get the root path where the traces should be imported from.
+     *
+     * @return the root import path
+     */
+    public String getRootImportPath() {
+        return fRootImportPath;
+    }
+
+    /**
+     * Set the root path where the traces should be imported from.
+     *
+     * @param rootImportPath
+     *            the root import path
+     */
+    public void setRootImportPath(String rootImportPath) {
+        fRootImportPath = rootImportPath;
+    }
+}
index fe979eee57e80bc246b350da3610ec922003b589..2ae488611c980b2e4fcf8b17cf81f5c7410f85da 100644 (file)
@@ -32,10 +32,14 @@ Export-Package: org.eclipse.tracecompass.internal.tmf.ui;x-friends:="org.eclipse
  org.eclipse.tracecompass.internal.tmf.ui.project.dialogs.offset;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.ui.project.handlers;x-friends:="org.eclipse.tracecompass.tmf.ui.tests",
  org.eclipse.tracecompass.internal.tmf.ui.project.model;x-friends:="org.eclipse.tracecompass.lttng2.ui,org.eclipse.tracecompass.tmf.ui.tests,org.eclipse.tracecompass.tmf.ctf.ui.tests",
- org.eclipse.tracecompass.internal.tmf.ui.project.operations;x-internal:=true,
- org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;x-friends:="org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests,org.eclipse.tracecompass.tmf.ui,org.eclipse.tracecompass.lttng2.control.ui",
- org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg;x-internal:=true,
- org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.importexport;x-internal:=true,
+ org.eclipse.tracecompass.internal.tmf.ui.project.operations;x-friends:="org.eclipse.tracecompass.tmf.remote.ui",
+ org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace;
+  x-friends:="org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests,
+   org.eclipse.tracecompass.tmf.ui,
+   org.eclipse.tracecompass.lttng2.control.ui,
+   org.eclipse.tracecompass.tmf.remote.ui",
+ org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg;x-friends:="org.eclipse.tracecompass.tmf.remote.ui",
+ org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.importexport;x-friends:="org.eclipse.tracecompass.tmf.remote.ui",
  org.eclipse.tracecompass.tmf.ui,
  org.eclipse.tracecompass.tmf.ui.analysis,
  org.eclipse.tracecompass.tmf.ui.editors,
This page took 0.056054 seconds and 5 git commands to generate.