control: Add LTTng profile preference page
authorBernd Hufmann <Bernd.Hufmann@ericsson.com>
Mon, 3 Aug 2015 13:04:43 +0000 (09:04 -0400)
committerBernd Hufmann <bernd.hufmann@ericsson.com>
Wed, 28 Oct 2015 14:30:11 +0000 (10:30 -0400)
Change-Id: Iaf8f420eadf4747866a8eee2b3b9a9bc723d7396
Signed-off-by: Bernd Hufmann <Bernd.Hufmann@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/57682
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
lttng/org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/LttngProfileManager.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties
lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/LoadDialog.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/ControlRemoteProfilesPreferencePage.java [new file with mode: 0644]
lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/LTTngProfileViewer.java [new file with mode: 0644]

index 09e47d0567af17a17147e526bc38b2eb08025a32..f4ef9460662f61291fa582b7142c7a89667837f7 100644 (file)
@@ -43,4 +43,13 @@ public class LttngProfileManager {
     public static File[] getProfiles() {
         return SAVED_PROFILE_PATH.toFile().listFiles();
     }
+
+    /**
+     * Gets the path where the profiles are located in the workspace.
+     *
+     * @return the profile path
+     */
+    public static IPath getProfilePath() {
+        return SAVED_PROFILE_PATH;
+    }
 }
index 6c3311ae3fd510b27a25ad53d0b1c35d88cc2112..a74074897c0d5b1bb47e8688fd22831b5db0c67c 100644 (file)
@@ -146,6 +146,7 @@ commands.control.load=Load...
 commands.control.load.description=Load session(s)
 
 preference.page.control.name=LTTng Tracer Control Preferences
+preferences.page.remote.profiles.name=LTTng Remote Profiles
 
 commandParameter.remoteServicesId.name = Remote Services ID
 commandParameter.connectionName.name = Connection Name
index 3b41eb268e03e55278f33036b713fef5d4684467..d8bf2f3c32f2d6417d1964e80a7577789c463706 100644 (file)
             id="org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences"
             name="%preference.page.control.name">
       </page>
+      <page
+            category="org.eclipse.linuxtools.tmf.ui.TmfTracingPreferences"
+            class="org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlRemoteProfilesPreferencePage"
+            id="org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlRemoteProfilesPreferencePage"
+            name="%preferences.page.remote.profiles.name">
+      </page>
    </extension>
    <extension
          point="org.eclipse.core.runtime.preferences">
index ddb14a90f7ed25ac70ec03f4f845ec89c481c70a..0671aade9d2c0d7c8388e71948e203f6920d4ec3 100644 (file)
@@ -22,33 +22,29 @@ import org.eclipse.core.filesystem.EFS;
 import org.eclipse.core.filesystem.IFileStore;
 import org.eclipse.jface.dialogs.IDialogConstants;
 import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.jface.preference.PreferenceDialog;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTreeViewer;
 import org.eclipse.jface.viewers.ICheckStateListener;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.LabelProvider;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.remote.core.IRemoteConnection;
 import org.eclipse.remote.ui.widgets.RemoteResourceBrowserWidget;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.tracecompass.internal.lttng2.control.core.LttngProfileManager;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.Activator;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlRemoteProfilesPreferencePage;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.LTTngProfileViewer;
 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.service.LTTngControlServiceConstants;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.PreferencesUtil;
 
 /**
  * Dialog box for collecting parameter for loading a session.
@@ -202,19 +198,8 @@ public class LoadDialog extends TitleAreaDialog implements ILoadDialog {
             fLocalComposite.setLayout(new GridLayout(2, false));
             fLocalComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
 
-            Composite viewerComposite = new Composite(fLocalComposite, SWT.NONE);
-            viewerComposite.setLayout(new GridLayout(1, false));
-            viewerComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
-
-            fFolderViewer = new CheckboxTreeViewer(viewerComposite);
-            fFolderViewer.setContentProvider(new ProfileContentProvider());
-            fFolderViewer.setLabelProvider(new ProfileLabelProvider());
-            fFolderViewer.setInput(LttngProfileManager.getProfiles());
-
-            GridData data = new GridData(GridData.FILL_BOTH);
-            Tree tree = fFolderViewer.getTree();
-            tree.setLayoutData(data);
-
+            fFolderViewer = LTTngProfileViewer.createLTTngProfileViewer(fLocalComposite, SWT.NONE);
+            fFolderViewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
             fFolderViewer.addCheckStateListener(new ICheckStateListener() {
                 @Override
                 public void checkStateChanged(CheckStateChangedEvent event) {
@@ -289,8 +274,24 @@ public class LoadDialog extends TitleAreaDialog implements ILoadDialog {
     }
 
     @Override
-    protected void createButtonsForButtonBar(Composite parent) {
+    protected void createButtonsForButtonBar(final Composite parent) {
         createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
+        Button manageButton = createButton(parent, IDialogConstants.CLIENT_ID + 1, Messages.TraceControl_ManageButtonText, false);
+        manageButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                PreferenceDialog dialog =
+                        PreferencesUtil.createPreferenceDialogOn(parent.getShell(),
+                                ControlRemoteProfilesPreferencePage.ID,
+                                new String[] { ControlRemoteProfilesPreferencePage.ID },
+                                null);
+                dialog.open();
+                if (fLocalComposite != null) {
+                    fFolderViewer.setInput(LTTngProfileViewer.getViewerInput());
+                    enableLocalButtons();
+                }
+            }
+        });
         Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, false);
         button.setEnabled(false);
     }
@@ -319,61 +320,4 @@ public class LoadDialog extends TitleAreaDialog implements ILoadDialog {
         }
     }
 
-    /**
-     * Helper class for the contents of a folder in a tracing project
-     *
-     * @author Bernd Hufmann
-     */
-    public static class ProfileContentProvider implements ITreeContentProvider {
-        @Override
-        public Object[] getChildren(Object o) {
-
-            if (o instanceof File[]) {
-                return (File[]) o;
-            }
-            File store = (File) o;
-            if (store.isDirectory()) {
-                return store.listFiles();
-            }
-            return new Object[0];
-        }
-
-        @Override
-        public Object getParent(Object element) {
-            return ((File) element).getParent();
-        }
-
-        @Override
-        public void dispose() {
-        }
-
-        @Override
-        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-        }
-
-        @Override
-        public Object[] getElements(Object inputElement) {
-            return getChildren(inputElement);
-        }
-
-        @Override
-        public boolean hasChildren(Object element) {
-            return ((File) element).isDirectory();
-        }
-    }
-
-    static class ProfileLabelProvider extends LabelProvider {
-        @Override
-        public String getText(Object element) {
-            return ((File) element).getName();
-        }
-
-        @Override
-        public Image getImage(Object element) {
-            if (((File) element).isDirectory()) {
-                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
-            }
-            return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
-        }
-    }
 }
index 772cd093cdc75fa904d2973a6923b6f75ea745cd..4c28b473333538e1680881ad65ce1328ef4d839e 100644 (file)
@@ -321,13 +321,26 @@ public final class Messages extends NLS {
 
     public static String TraceControl_LoadDialogTitle;
 
+    public static String TraceControl_ForceButtonText;
+    public static String TraceControl_ManageButtonText;
     public static String TraceControl_UnknownNode;
 
     public static String TraceControl_SelectProfileText;
     public static String TraceControl_LocalButtonText;
     public static String TraceControl_RemoteButtonText;
 
-    public static String TraceControl_ForceButtonText;
+    public static String TraceControl_DeleteButtonText;
+    public static String TraceControl_ImportButtonText;
+    public static String TraceControl_ExportButtonText;
+
+    public static String TraceControl_ImportProfileTitle;
+    public static String TraceControl_ExportProfileTitle;
+
+    public static String TraceControl_ProfileAlreadyExists;
+    public static String TraceControl_OverwriteQuery;
+
+    public static String TraceControl_DeleteProfileTitle;
+    public static String TraceControl_DeleteQuery;
 
     static {
         // initialize resource bundle
index d47a45cd165bcbf34bc7db59d5a43e8464b5c48f..25b6d9db38aadcdec5e455e629db7fe645dfb377 100644 (file)
@@ -306,8 +306,23 @@ TraceControl_UnknownNode=<unknown>
 
 TraceControl_LoadDialogTitle=Load Sessions
 
+TraceControl_ForceButtonText=force
+TraceControl_ManageButtonText=&Manage...
+
 TraceControl_SelectProfileText=Select LTTng profile to load
 TraceControl_LocalButtonText=Local
 TraceControl_RemoteButtonText=Remote
 
-TraceControl_ForceButtonText=force
\ No newline at end of file
+TraceControl_ImportButtonText=Import...
+TraceControl_ExportButtonText=Export...
+TraceControl_DeleteButtonText=Delete...
+
+TraceControl_ImportProfileTitle=Import LTTng Profiles
+TraceControl_ExportProfileTitle=Export LTTng Profiles
+
+TraceControl_ProfileAlreadyExists=LTTng Profile already exists
+TraceControl_OverwriteQuery=Do you want to overwrite file {0}?
+
+TraceControl_DeleteProfileTitle=Delete LTTng Profiles
+TraceControl_DeleteQuery=Do you want to delete the following profiles?
+
diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/ControlRemoteProfilesPreferencePage.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/ControlRemoteProfilesPreferencePage.java
new file mode 100644 (file)
index 0000000..3118022
--- /dev/null
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * 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.lttng2.control.ui.views.preferences;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.tracecompass.internal.lttng2.control.core.LttngProfileManager;
+import org.eclipse.tracecompass.internal.lttng2.control.ui.views.messages.Messages;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.eclipse.ui.dialogs.FilteredTree;
+import org.eclipse.ui.dialogs.PatternFilter;
+
+/**
+ * LTTng control remote profile preferences page.
+ *
+ * @author Bernd Hufmann
+ */
+public class ControlRemoteProfilesPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+
+    /** Preference page ID */
+    public static String ID = "org.eclipse.tracecompass.internal.lttng2.control.ui.views.preferences.ControlRemoteProfilesPreferencePage"; //$NON-NLS-1$
+
+    private CheckboxTreeViewer fFolderViewer;
+
+    private Button fDeleteButton = null;
+    private Button fImportButton = null;
+    private Button fExportButton = null;
+
+    @Override
+    public void init(IWorkbench workbench) {
+    }
+
+    @Override
+    protected Control createContents(Composite parent) {
+        Composite composite;
+        composite = new Composite(parent, SWT.NONE);
+        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+        composite.setLayout(new GridLayout(2, false));
+
+        final FilteredTree filteredTree = new FilteredTree(composite,
+                SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER, new PatternFilter(), true) {
+            @Override
+            protected TreeViewer doCreateTreeViewer(Composite aParent, int style) {
+                fFolderViewer = LTTngProfileViewer.createLTTngProfileViewer(aParent, style);
+                return fFolderViewer;
+            }
+        };
+
+        filteredTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+        Composite buttonComposite = createVerticalButtonBar(composite);
+        buttonComposite.setLayout(new GridLayout());
+        buttonComposite.setLayoutData(new GridData(GridData.CENTER, GridData.BEGINNING, false, false));
+
+        fFolderViewer.addCheckStateListener(new ICheckStateListener() {
+            @Override
+            public void checkStateChanged(CheckStateChangedEvent event) {
+                enableButtons();
+            }
+        });
+
+        return composite;
+    }
+
+    private Composite createVerticalButtonBar(Composite composite) {
+        Composite buttonComposite = new Composite(composite, SWT.NONE);
+
+        fDeleteButton = createVerticalButton(buttonComposite, Messages.TraceControl_DeleteButtonText);
+        fDeleteButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                Object[] checkedElements = fFolderViewer.getCheckedElements();
+                StringBuffer files = new StringBuffer();
+                for (Object element : checkedElements) {
+                    if (element instanceof File) {
+                        files.append(((File) element).toString()).append("\n"); //$NON-NLS-1$
+                    }
+                }
+
+                boolean delete = MessageDialog.openConfirm(getShell(),
+                        Messages.TraceControl_DeleteProfileTitle,
+                        Messages.TraceControl_DeleteQuery+ "\n" + files.toString()); //$NON-NLS-1$
+
+                if (!delete) {
+                    return;
+                }
+
+                for (Object element : checkedElements) {
+                    if (element instanceof File) {
+                        File sourceFile = (File) element;
+                        Path source = FileSystems.getDefault().getPath(sourceFile.getAbsolutePath());
+                        try {
+                            Files.delete(source);
+                        } catch (IOException e1) {
+                            MessageDialog.openError(getShell(),
+                                    Messages.TraceControl_DeleteProfileTitle,
+                                    "Error deleting profile:\n" + e1.toString());  //$NON-NLS-1$
+                        }
+                    }
+                }
+                fFolderViewer.setInput(LTTngProfileViewer.getViewerInput());
+                enableButtons();
+            }
+        });
+
+        fImportButton = createVerticalButton(buttonComposite, Messages.TraceControl_ImportButtonText);
+        fExportButton = createVerticalButton(buttonComposite, Messages.TraceControl_ExportButtonText);
+
+        fImportButton.addSelectionListener(new SelectionListener() {
+            @Override
+            public void widgetDefaultSelected(SelectionEvent e) {}
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                FileDialog dialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN);
+                dialog.setText(Messages.TraceControl_ImportProfileTitle);
+                dialog.setFilterExtensions(new String[] { "*.lttng", "*" }); //$NON-NLS-1$ //$NON-NLS-2$
+                String sourceFile = dialog.open();
+                if (sourceFile != null) {
+                    Path source = FileSystems.getDefault().getPath(sourceFile);
+                    Path destPath = FileSystems.getDefault().getPath(LttngProfileManager.getProfilePath().toFile().toString());
+                    copyProfileFile(source, destPath, Messages.TraceControl_ImportProfileTitle);
+                    fFolderViewer.setInput(LTTngProfileViewer.getViewerInput());
+                }
+            }
+        });
+
+        fExportButton.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                DirectoryDialog dialog = new DirectoryDialog(Display.getCurrent().getActiveShell());
+                dialog.setText(Messages.TraceControl_ExportProfileTitle);
+                String path = dialog.open();
+                if (path != null) {
+                    Object[] checkedElements = fFolderViewer.getCheckedElements();
+                    for (Object element : checkedElements) {
+                        if (element instanceof File) {
+                            File sourceFile = (File) element;
+                            Path source = FileSystems.getDefault().getPath(sourceFile.getAbsolutePath());
+                            Path destPath = FileSystems.getDefault().getPath(path);
+                            copyProfileFile(source, destPath, Messages.TraceControl_ExportProfileTitle);
+                        }
+                    }
+                }
+            }
+        });
+
+        enableButtons();
+        return buttonComposite;
+    }
+
+    private static Button createVerticalButton(Composite parent, String text) {
+        Button button = new Button(parent, SWT.PUSH);
+        button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
+        button.setText(text);
+        return button;
+    }
+
+    private void enableButtons() {
+        Object[] checked = fFolderViewer.getCheckedElements();
+        boolean enabled = (checked != null) && (checked.length > 0);
+        fDeleteButton.setEnabled(enabled);
+        fExportButton.setEnabled(enabled);
+        fImportButton.setEnabled(true);
+    }
+
+    private void copyProfileFile(Path source, Path destPath, String errorTitle) {
+        Path destFile = destPath.resolve(source.getFileName());
+        if (destFile.toFile().exists()) {
+            boolean overwrite = MessageDialog.openConfirm(getShell(),
+                    Messages.TraceControl_ProfileAlreadyExists,
+                    NLS.bind(Messages.TraceControl_OverwriteQuery, destFile.getFileName()));
+
+            if (!overwrite) {
+                return;
+            }
+        }
+        try {
+            Files.copy(source, destFile, StandardCopyOption.REPLACE_EXISTING);
+        } catch (IOException e1) {
+            MessageDialog.openError(getShell(),
+                    errorTitle,
+                    "Error copying profile:\n" + e1.toString()); //$NON-NLS-1$
+        }
+    }
+
+}
diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/LTTngProfileViewer.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/LTTngProfileViewer.java
new file mode 100644 (file)
index 0000000..0b38634
--- /dev/null
@@ -0,0 +1,118 @@
+/**********************************************************************
+ * 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.lttng2.control.ui.views.preferences;
+
+import java.io.File;
+
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tracecompass.internal.lttng2.control.core.LttngProfileManager;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Class to create LTTng Profiles viewer (CheckboxTreeViewer).
+ */
+public class LTTngProfileViewer  {
+
+    /**
+     * Creates a CheckboxTreeViewer for selection available LTTng profiles.
+     * @param parent
+     *                A parent composite
+     * @param style
+     *                The style bits
+     * @return LTTng Profiles CheckboxTreeViewer
+     */
+    public static CheckboxTreeViewer createLTTngProfileViewer(Composite parent, int style) {
+        CheckboxTreeViewer fFolderViewer = new CheckboxTreeViewer(parent, style);
+        fFolderViewer.setContentProvider(new ProfileContentProvider());
+        fFolderViewer.setLabelProvider(new ProfileLabelProvider());
+        fFolderViewer.setInput(getViewerInput());
+        return fFolderViewer;
+    }
+
+    /**
+     * Gets the viewer input
+     *
+     * @return the viewer input
+     */
+    public static File[] getViewerInput() {
+        return LttngProfileManager.getProfiles();
+    }
+
+    /**
+     * Helper class for the contents of a folder in a tracing project
+     */
+    public static class ProfileContentProvider implements ITreeContentProvider {
+        @Override
+        public Object[] getChildren(Object o) {
+            File store = (File) o;
+            if (store.isDirectory()) {
+                return store.listFiles();
+            }
+            return new Object[0];
+        }
+
+        @Override
+        public Object getParent(Object element) {
+            if (element instanceof File) {
+                return ((File) element).getParent();
+            }
+            return null;
+        }
+
+        @Override
+        public void dispose() {
+        }
+
+        @Override
+        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+        }
+
+        @Override
+        public Object[] getElements(Object inputElement) {
+            if (inputElement instanceof File[]) {
+                return (File[]) inputElement;
+            }
+            return getChildren(inputElement);
+        }
+
+        @Override
+        public boolean hasChildren(Object element) {
+            return ((File) element).isDirectory();
+        }
+    }
+
+    /**
+     * Helper label provider for LTTng profiles.
+     */
+    public static class ProfileLabelProvider extends LabelProvider {
+        @Override
+        public String getText(Object element) {
+            return ((File) element).getName();
+        }
+
+        @Override
+        public Image getImage(Object element) {
+            if (((File) element).isDirectory()) {
+                return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
+            }
+            return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
+        }
+    }
+
+}
This page took 0.033917 seconds and 5 git commands to generate.