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;
+ }
}
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
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">
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.
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) {
}
@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);
}
}
}
- /**
- * 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);
- }
- }
}
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
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?
+
--- /dev/null
+/*******************************************************************************
+ * 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$
+ }
+ }
+
+}
--- /dev/null
+/**********************************************************************
+ * 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);
+ }
+ }
+
+}