From fc9ff6c4d03e6ab88d8237132a84881b6780ef94 Mon Sep 17 00:00:00 2001 From: Bernd Hufmann Date: Mon, 3 Aug 2015 09:04:43 -0400 Subject: [PATCH] control: Add LTTng profile preference page Change-Id: Iaf8f420eadf4747866a8eee2b3b9a9bc723d7396 Signed-off-by: Bernd Hufmann Reviewed-on: https://git.eclipse.org/r/57682 Reviewed-by: Hudson CI Reviewed-by: Patrick Tasse Tested-by: Patrick Tasse --- .../control/core/LttngProfileManager.java | 9 + .../plugin.properties | 1 + .../plugin.xml | 6 + .../control/ui/views/dialogs/LoadDialog.java | 102 ++------ .../control/ui/views/messages/Messages.java | 15 +- .../ui/views/messages/messages.properties | 17 +- .../ControlRemoteProfilesPreferencePage.java | 221 ++++++++++++++++++ .../views/preferences/LTTngProfileViewer.java | 118 ++++++++++ 8 files changed, 408 insertions(+), 81 deletions(-) create mode 100644 lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/ControlRemoteProfilesPreferencePage.java create mode 100644 lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/LTTngProfileViewer.java diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/LttngProfileManager.java b/lttng/org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/LttngProfileManager.java index 09e47d0567..f4ef946066 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/LttngProfileManager.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.core/src/org/eclipse/tracecompass/internal/lttng2/control/core/LttngProfileManager.java @@ -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; + } } diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties b/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties index 6c3311ae3f..a74074897c 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.properties @@ -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 diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml b/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml index 3b41eb268e..d8bf2f3c32 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/plugin.xml @@ -1292,6 +1292,12 @@ id="org.eclipse.linuxtools.internal.lttng2.ui.views.control.preferences" name="%preference.page.control.name"> + + diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/LoadDialog.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/LoadDialog.java index ddb14a90f7..0671aade9d 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/LoadDialog.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/dialogs/LoadDialog.java @@ -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); - } - } } diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java index 772cd093cd..4c28b47333 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/Messages.java @@ -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 diff --git a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties index d47a45cd16..25b6d9db38 100644 --- a/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/messages/messages.properties @@ -306,8 +306,23 @@ TraceControl_UnknownNode= 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 index 0000000000..311802270a --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/ControlRemoteProfilesPreferencePage.java @@ -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 index 0000000000..0b38634a96 --- /dev/null +++ b/lttng/org.eclipse.tracecompass.lttng2.control.ui/src/org/eclipse/tracecompass/internal/lttng2/control/ui/views/preferences/LTTngProfileViewer.java @@ -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); + } + } + +} -- 2.34.1