org.eclipse.core.filesystem;bundle-version="1.3.100",
org.eclipse.core.runtime;bundle-version="3.7.0",
org.eclipse.linuxtools.lttng2.core;bundle-version="0.1.0",
+ org.eclipse.linuxtools.tmf.core;bundle-version="0.5.0",
org.eclipse.linuxtools.tmf.ui;bundle-version="0.5.0",
org.eclipse.rse.core;bundle-version="3.2.0",
org.eclipse.rse.services;bundle-version="3.2.100",
commands.control.add.context=Add Context
commands.control.add.context.description=Add Context to Channel(s) and/or Event(s)
+
+commands.control.import=Import
+commands.control.import.description=Import Traces to LTTng Project
id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.destroySession"
name="%commands.control.destroy.session">
</command>
+ <command
+ categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+ description="%commands.control.import.description"
+ id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.import"
+ name="%commands.control.import">
+ </command>
<command
categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
description="%commands.control.create.channel.description"
name="%commands.control.add.context">
</command>
+ <command
+ categoryId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.category"
+ description="%commands.control.import.description"
+ id="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.import"
+ name="%commands.control.import">
+ </command>
+
+
</extension>
<extension
point="org.eclipse.ui.menus">
label="%commands.control.destroy.session"
style="push">
</command>
+ <separator
+ name="org.eclipse.linuxtools.internal.lttng2.ui.views.control.toolbar.separator2"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.import"
+ icon="icons/elcl16/import_trace.gif"
+ label="%commands.control.import"
+ style="push">
+ </command>
</menuContribution>
<menuContribution
name="org.eclipse.linuxtools.internal.lttng2.ui.views.control.popup.separator1"
visible="true">
</separator>
+ <command
+ commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.import"
+ icon="icons/elcl16/import_trace.gif"
+ label="%commands.control.import"
+ style="push">
+ <visibleWhen
+ checkEnabled="false">
+ <with
+ variable="activeMenuSelection">
+ <and>
+ <iterate
+ operator="or">
+ <instanceof
+ value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent">
+ </instanceof>
+ </iterate>
+ <count
+ value="1">
+ </count>
+ </and>
+ </with>
+ </visibleWhen>
+ </command>
+ <separator
+ name="org.eclipse.linuxtools.internal.lttng2.ui.views.control.popup.separator2"
+ visible="true">
+ </separator>
<command
commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.createChannelOnSession"
icon="icons/elcl16/add_button.gif"
</with>
</activeWhen>
</handler>
+ <handler
+ class="org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.ImportHandler"
+ commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.import">
+ <activeWhen>
+ <with
+ variable="selection">
+ <and>
+ <iterate
+ operator="or">
+ <instanceof
+ value="org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent">
+ </instanceof>
+ </iterate>
+ <count
+ value="1">
+ </count>
+ </and>
+ </with>
+ </activeWhen>
+ </handler>
<handler
class="org.eclipse.linuxtools.internal.lttng2.ui.views.control.handlers.CreateChannelOnSessionHandler"
commandId="org.eclipse.linuxtools.internal.lttng2.ui.commands.control.createChannelOnSession">
public static String TraceControl_DestroySessionJob;
public static String TraceControl_DestroyConfirmationTitle;
public static String TraceControl_DestroyConfirmationMessage;
+
+ public static String TraceControl_ImportJob;
public static String TraceControl_StartSessionJob;
public static String TraceControl_StopSessionJob;
public static String TraceControl_AddContextAvailableContextsLabel;
public static String TraceControl_AddContextAvailableContextsTooltip;
public static String TraceControl_AddContextAllLabel;
+
+ public static String TraceControl_ImportDialogTitle;
+ public static String TraceControl_ImportDialogTracesGroupName;
+ public static String TraceControl_ImportDialogTracesTooltip;
+ public static String TraceControl_ImportDialogProjectsGroupName;
+ public static String TraceControl_ImportDialogProjectsTooltip;
+ public static String TraceControl_ImportDialogOverwriteButtonText;
+ public static String TraceControl_ImportDialogCreationError;
+ public static String TraceControl_ImportDialogNoProjectSelectedError;
+ public static String TraceControl_ImportDialogInvalidTracingProject;
+ public static String TraceControl_ImportDialogNoTraceSelectedError;
+ public static String TraceControl_ImportDialogConfirmationTitle;
+ public static String TraceControl_ImportDialogConfirmationOverwriteLabel;
+ public static String TraceControl_ImportDialogConfirmationRenameLabel;
+ public static String TraceControl_ImportDialogConfirmationNewNameLabel;
+ public static String TraceControl_InvalidTraceNameError;
+ public static String TraceControl_ImportDialogTraceAlreadyExistError;
+
// Tree structure strings
public static String TraceControl_KernelDomainDisplayName;
public static String TraceControl_UstDisplayName;
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+
+/**
+ * <b><u>IImportConfirmationDialog</u></b>
+ * <p>
+ * Interface for dialog box for updating file import information.
+ * </p>
+ */
+public interface IImportConfirmationDialog {
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+ /**
+ * @param name old trace name.
+ */
+ public void setTraceName(String name);
+
+ /**
+ * @return the new trace name if not overwrite.
+ */
+ public String getNewTraceName();
+
+ /**
+ *
+ * @return true to overwrite existing trace.
+ */
+ public boolean isOverwrite();
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+ /**
+ * @return the open return value
+ */
+ int open();
+}
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+
+/**
+ * <b><u>IImportDialog</u></b>
+ * <p>
+ * Interface for import traces dialog.
+ * </p>
+ */
+public interface IImportDialog {
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+ /**
+ * @return a list of trace paths to import.
+ */
+ public List<ImportFileInfo> getTracePathes();
+
+ /**
+ * @return the project to import the traces to
+ */
+ public IProject getProject();
+
+ /**
+ * Sets the session containing the traces to import
+ * @param session
+ */
+ public void setSession(TraceSessionComponent session);
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+ /**
+ * @return the open return value
+ */
+ int open();
+}
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Point;
+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.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/**
+ * <b><u>CreateSessionDialog</u></b>
+ * <p>
+ * Dialog box for collecting session creation information.
+ * </p>
+ */
+public class ImportConfirmationDialog extends Dialog implements IImportConfirmationDialog {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+ /**
+ * The icon file for this dialog box.
+ */
+ public static final String IMPORT_ICON_FILE = "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+ /**
+ * The dialog composite.
+ */
+ private Composite fDialogComposite = null;
+ /**
+ * The radio button for selecting the overwrite action
+ */
+ private Button fOverwriteButton = null;
+ /**
+ * The radio button for selecting the renaming action
+ */
+ private Button fRenameButton = null;
+ /**
+ * The text widget for the session name
+ */
+ private Text fNewTraceNameText = null;
+ /**
+ * The trace name which already exists in the project
+ */
+ private String fTraceName = null;
+ /**
+ * The session name string.
+ */
+ private String fNewTraceName = null;
+ /**
+ * Flag whether default location (path) shall be used or not
+ */
+ private boolean fIsOverride = true;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+ /**
+ * Constructor
+ * @param shell - a shell for the display of the dialog
+ */
+ public ImportConfirmationDialog(Shell shell) {
+ super(shell);
+ setShellStyle(SWT.RESIZE);
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#setTraceName(java.lang.String)
+ */
+ @Override
+ public void setTraceName(String name) {
+ fTraceName = name;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#getNewTraceName()
+ */
+ @Override
+ public String getNewTraceName() {
+ return fNewTraceName;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportConfirmationDialog#isOverwrite()
+ */
+ @Override
+ public boolean isOverwrite() {
+ return fIsOverride;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(Messages.TraceControl_ImportDialogConfirmationTitle);
+ newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ // Main dialog panel
+ fDialogComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ fDialogComposite.setLayout(layout);
+ fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Label sessionNameLabel = new Label(fDialogComposite, SWT.RIGHT);
+ sessionNameLabel.setText(Messages.TraceControl_ImportDialogTraceAlreadyExistError + ": " + fTraceName); //$NON-NLS-1$
+
+ fOverwriteButton = new Button(fDialogComposite, SWT.RADIO);
+ fOverwriteButton.setText(Messages.TraceControl_ImportDialogConfirmationOverwriteLabel);
+
+ fOverwriteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fNewTraceNameText.setEnabled(false);
+ fNewTraceNameText.setText(fTraceName);
+ }
+ });
+
+ fRenameButton = new Button(fDialogComposite, SWT.RADIO);
+ fRenameButton.setText(Messages.TraceControl_ImportDialogConfirmationRenameLabel);
+
+ fRenameButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ fNewTraceNameText.setEnabled(true);
+ }
+ });
+
+ fNewTraceNameText = new Text(fDialogComposite, SWT.NONE);
+ fNewTraceNameText.setToolTipText(Messages.TraceControl_ImportDialogConfirmationNewNameLabel);
+ fNewTraceNameText.setText(fTraceName);
+
+ // Default
+ fOverwriteButton.setSelection(true);
+ fNewTraceNameText.setEnabled(false);
+
+
+ // layout widgets
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+
+ fNewTraceNameText.setLayoutData(data);
+
+ getShell().setMinimumSize(new Point(300, 150));
+
+ return fDialogComposite;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ @Override
+ protected void okPressed() {
+
+ fIsOverride = fOverwriteButton.getSelection();
+
+ if (fIsOverride) {
+ // new name is old name
+ fNewTraceName = fTraceName;
+ } else {
+ fNewTraceName = fNewTraceNameText.getText();
+ }
+
+ // Check for invalid names
+ if (!fNewTraceName.matches("^[a-zA-Z0-9\\-\\_]{1,}$")) { //$NON-NLS-1$
+ MessageDialog.openError(getShell(),
+ Messages.TraceControl_ImportDialogConfirmationTitle,
+ Messages.TraceControl_InvalidTraceNameError + " (" + fNewTraceName + ") \n"); //$NON-NLS-1$ //$NON-NLS-2$
+ return;
+ }
+
+ // validation successful -> call super.okPressed()
+ super.okPressed();
+ }
+}
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
+import org.eclipse.jface.viewers.CheckboxTreeViewer;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.remote.IRemoteSystemProxy;
+import org.eclipse.linuxtools.tmf.core.TmfProjectNature;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
+import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.graphics.Point;
+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.Group;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+/**
+ * <b><u>ImportDialog</u></b>
+ * <p>
+ * Dialog box for collecting trace import information.
+ * </p>
+ */
+public class ImportDialog extends Dialog implements IImportDialog {
+
+ // ------------------------------------------------------------------------
+ // Constants
+ // ------------------------------------------------------------------------
+ /**
+ * The icon file for this dialog box.
+ */
+ public static final String IMPORT_ICON_FILE = "icons/elcl16/import_trace.gif"; //$NON-NLS-1$
+
+ public static final String UST_PARENT_DIRECTORY = "ust"; //$NON-NLS-1$
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+ /**
+ * The dialog composite.
+ */
+ private Composite fDialogComposite = null;
+ /**
+ * The checkbox tree viewer for selecting available traces
+ */
+ private CheckboxTreeViewer fFolderViewer;
+ /**
+ * The combo box for selecting a project.
+ */
+ private CCombo fCombo;
+ /**
+ * The overwrite button
+ */
+ private Button fOverwriteButton;
+ /**
+ * List of available LTTng 2.0 projects
+ */
+ private List<IProject> fProjects;
+ /**
+ * The parent where the new node should be added.
+ */
+ private TraceSessionComponent fSession = null;
+ /**
+ * List of traces to import
+ */
+ private List<ImportFileInfo> fTraces = new ArrayList<ImportFileInfo>();
+ /**
+ * Selection index in project combo box.
+ */
+ private int fProjectIndex;
+ /**
+ * Flag to indicate that something went wrong when creating the dialog box.
+ */
+ private boolean fIsError = false;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+ /**
+ * Constructor
+ * @param shell - a shell for the display of the dialog
+ */
+ public ImportDialog(Shell shell) {
+ super(shell);
+ setShellStyle(SWT.RESIZE);
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#getTracePathes()
+ */
+ @Override
+ public List<ImportFileInfo> getTracePathes() {
+ List<ImportFileInfo> retList = new ArrayList<ImportFileInfo>();
+ retList.addAll(fTraces);
+ return retList;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#getProject()
+ */
+ @Override
+ public IProject getProject() {
+ return fProjects.get(fProjectIndex);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog#setSession(org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent)
+ */
+ @Override
+ public void setSession(TraceSessionComponent session) {
+ fSession = session;
+ }
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
+ */
+ @Override
+ protected void configureShell(Shell newShell) {
+ super.configureShell(newShell);
+ newShell.setText(Messages.TraceControl_ImportDialogTitle);
+ newShell.setImage(Activator.getDefault().loadIcon(IMPORT_ICON_FILE));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected Control createDialogArea(Composite parent) {
+
+ // Main dialog panel
+ fDialogComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ fDialogComposite.setLayout(layout);
+ fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Group contextGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+ contextGroup.setText(Messages.TraceControl_ImportDialogTracesGroupName);
+ layout = new GridLayout(1, true);
+ contextGroup.setLayout(layout);
+ contextGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ IRemoteSystemProxy proxy = fSession.getTargetNode().getRemoteSystemProxy();
+
+ IFileServiceSubSystem fsss = proxy.getFileServiceSubSystem();
+
+ try {
+ IRemoteFile remoteFolder = fsss.getRemoteFileObject(fSession.getSessionPath(), new NullProgressMonitor());
+
+ fFolderViewer = new CheckboxTreeViewer(contextGroup, SWT.BORDER);
+ GridData data = new GridData(GridData.FILL_BOTH);
+ Tree tree = fFolderViewer.getTree();
+ tree.setLayoutData(data);
+ tree.setFont(parent.getFont());
+ tree.setToolTipText(Messages.TraceControl_ImportDialogTracesTooltip);
+
+ fFolderViewer.setContentProvider(new FolderContentProvider());
+ fFolderViewer.setLabelProvider(new WorkbenchLabelProvider());
+
+ fFolderViewer.addCheckStateListener(new ICheckStateListener() {
+ @Override
+ public void checkStateChanged(CheckStateChangedEvent event) {
+ Object elem = event.getElement();
+ if (elem instanceof IRemoteFile) {
+ IRemoteFile element = (IRemoteFile) elem;
+ if (!element.isDirectory()) {
+ // A trick to keep selection of a file in sync with the directory
+ boolean p = fFolderViewer.getChecked((element.getParentRemoteFile()));
+ fFolderViewer.setChecked(element, p);
+ return;
+ }
+ fFolderViewer.setSubtreeChecked(event.getElement(), event.getChecked());
+ if (!event.getChecked()) {
+ fFolderViewer.setChecked(element.getParentRemoteFile(), false);
+ }
+ }
+ }
+ });
+ fFolderViewer.setInput(remoteFolder);
+
+ Group projectGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+ projectGroup.setText(Messages.TraceControl_ImportDialogProjectsGroupName);
+ layout = new GridLayout(1, true);
+ projectGroup.setLayout(layout);
+ projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ fProjects = new ArrayList<IProject>();
+ List<String> projectNames = new ArrayList<String>();
+ for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
+ try {
+ if (project.isOpen() && project.hasNature(TmfProjectNature.ID)) {
+ fProjects.add(project);
+ projectNames.add(project.getName());
+ }
+ } catch (CoreException e) {
+ createErrorComposite(parent, e.fillInStackTrace());
+ return fDialogComposite;
+ }
+ }
+
+ fCombo = new CCombo(projectGroup, SWT.READ_ONLY);
+ fCombo.setToolTipText(Messages.TraceControl_ImportDialogProjectsTooltip);
+ fCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false, 1, 1));
+ fCombo.setItems(projectNames.toArray(new String[projectNames.size()]));
+
+ Group overrideGroup = new Group(fDialogComposite, SWT.SHADOW_NONE);
+ layout = new GridLayout(1, true);
+ overrideGroup.setLayout(layout);
+ overrideGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ fOverwriteButton = new Button(overrideGroup, SWT.CHECK);
+ fOverwriteButton.setText(Messages.TraceControl_ImportDialogOverwriteButtonText);
+
+ getShell().setMinimumSize(new Point(500, 400));
+
+
+ } catch (SystemMessageException e) {
+ createErrorComposite(parent, e.fillInStackTrace());
+ return fDialogComposite;
+ }
+
+ return fDialogComposite;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
+ */
+ @Override
+ protected void createButtonsForButtonBar(Composite parent) {
+ createButton(parent, IDialogConstants.OK_ID, "&Ok", true); //$NON-NLS-1$
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.dialogs.Dialog#okPressed()
+ */
+ @Override
+ protected void okPressed() {
+ if (!fIsError) {
+ // Validate input data
+ fTraces.clear();
+
+ fProjectIndex = fCombo.getSelectionIndex();
+
+ if (fProjectIndex < 0) {
+ MessageDialog.openError(getShell(),
+ Messages.TraceControl_ImportDialogTitle,
+ Messages.TraceControl_ImportDialogNoProjectSelectedError);
+ return;
+ }
+
+ IProject project = fProjects.get(fProjectIndex);
+ IFolder traceFolder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
+
+ if (!traceFolder.exists()) {
+ // Invalid LTTng 2.0 project
+ MessageDialog.openError(getShell(),
+ Messages.TraceControl_ImportDialogTitle,
+ Messages.TraceControl_ImportDialogInvalidTracingProject + " (" + TmfTraceFolder.TRACE_FOLDER_NAME + ")"); //$NON-NLS-1$//$NON-NLS-2$
+ return;
+ }
+
+ boolean overwriteAll = fOverwriteButton.getSelection();
+
+ Object[] checked = fFolderViewer.getCheckedElements();
+ for (int i = 0; i < checked.length; i++) {
+ IRemoteFile file = (IRemoteFile) checked[i];
+
+ // Only add actual trace directories
+ if (file.isDirectory() && !UST_PARENT_DIRECTORY.equals(file.getName())) {
+
+ ImportFileInfo info = new ImportFileInfo(file, file.getName(), overwriteAll);
+ String traceName = info.getLocalTraceName();
+ IFolder folder = traceFolder.getFolder(traceName);
+
+ // Verify if trace directory already exists (and not overwrite)
+ if (folder.exists() && !overwriteAll) {
+
+ // Ask user for overwrite or new name
+ IImportConfirmationDialog conf = TraceControlDialogFactory.getInstance().getImportConfirmationDialog();
+ conf.setTraceName(traceName);
+
+ // Don't add trace to list if dialog was cancelled.
+ if (conf.open() == Window.OK) {
+ info.setOverwrite(conf.isOverwrite());
+ if (!conf.isOverwrite()) {
+ info.setLocalTraceName(conf.getNewTraceName());
+ }
+ fTraces.add(info);
+ }
+ } else {
+ fTraces.add(info);
+ }
+ }
+ }
+
+ if (fTraces.isEmpty()) {
+ MessageDialog.openError(getShell(),
+ Messages.TraceControl_ImportDialogTitle,
+ Messages.TraceControl_ImportDialogNoTraceSelectedError);
+ return;
+ }
+ }
+
+ // validation successful -> call super.okPressed()
+ super.okPressed();
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper methods and classes
+ // ------------------------------------------------------------------------
+ public class FolderContentProvider extends WorkbenchContentProvider {
+ @Override
+ public Object[] getChildren(Object o) {
+ if (o instanceof IRemoteFile) {
+ IRemoteFile element = (IRemoteFile) o;
+ // For our purpose, we need folders + files
+ if (!element.isDirectory()) {
+ return new Object[0];
+ }
+ }
+ return super.getChildren(o);
+ }
+ }
+
+ /**
+ * Creates a dialog composite with an error message which can be used
+ * when an exception occurred during creation time of the dialog box.
+ * @param parent - a parent composite
+ * @param e - a error causing exception
+ */
+ private void createErrorComposite(Composite parent, Throwable e) {
+ fIsError = true;
+ fDialogComposite.dispose();
+
+ fDialogComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout(1, true);
+ fDialogComposite.setLayout(layout);
+ fDialogComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ Text errorText = new Text(fDialogComposite, SWT.MULTI);
+ StringBuffer error = new StringBuffer();
+ error.append(Messages.TraceControl_ImportDialogCreationError);
+ error.append(System.getProperty("line.separator")); //$NON-NLS-1$
+ error.append(System.getProperty("line.separator")); //$NON-NLS-1$
+ error.append(e.toString());
+ errorText.setText(error.toString());
+ errorText.setLayoutData(new GridData(GridData.FILL_BOTH));
+ }
+
+
+ }
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.dialogs;
+
+import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
+
+/**
+ * <b><u>ImportFileInfo</u></b>
+ * <p>
+ * Helper class for storing information about a remote file to import.
+ * </p>
+ */
+public class ImportFileInfo {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+ private IRemoteFile fRemoteFile;
+ private String fLocalTraceName;
+ private boolean fIsOverwrite;
+
+ // ------------------------------------------------------------------------
+ // Constructors
+ // ------------------------------------------------------------------------
+ public ImportFileInfo(IRemoteFile file, String traceName, boolean isOverwrite) {
+ fRemoteFile = file;
+ fLocalTraceName = traceName;
+ fIsOverwrite = isOverwrite;
+ }
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+ /**
+ * @return name of traces after importing
+ */
+ public String getLocalTraceName() {
+ return fLocalTraceName;
+ }
+ /**
+ * Sets the local trace name
+ * @param importTraceName - local name of trace to set (name after importing)
+ */
+ public void setLocalTraceName(String importTraceName) {
+ this.fLocalTraceName = importTraceName;
+ }
+ /**
+ * @return true if local trace should be overwritten if a trace with the same name already exists.
+ */
+ public boolean isOverwrite() {
+ return fIsOverwrite;
+ }
+ /**
+ * Sets the overwrite flag.
+ * @param isOverwrite
+ */
+ public void setOverwrite(boolean isOverwrite) {
+ this.fIsOverwrite = isOverwrite;
+ }
+ /**
+ * @return the remote file implementation.
+ */
+ public IRemoteFile getImportFile() {
+ return fRemoteFile;
+ }
+ /**
+ * Sets the remote file implementation
+ * @param the remote file implementation.
+ */
+ public void setRemoteFile(IRemoteFile remoteFile) {
+ fRemoteFile = remoteFile;
+ }
+}
+
private IGetEventInfoDialog fGetEventInfoDialog;
/**
- * The confirmation dialog implementation
+ * The confirmation dialog implementation.
*/
private IConfirmDialog fConfirmDialog;
/**
- * The add context dialog implementation
+ * The add context dialog implementation.
*/
private IAddContextDialog fAddContextDialog;
+
+ /**
+ * The import dialog implementation.
+ */
+ private IImportDialog fImportDialog;
+
+ /**
+ * The import confirmation dialog.
+ */
+ private IImportConfirmationDialog fImportConfirmationDialog;
// ------------------------------------------------------------------------
// Constructors
/**
* Sets the confirmation dialog implementation
- * @param confirmDialog
+ * @param confirmDialog - a confirmation dialog implementation
*/
public void setConfirmDialog(IConfirmDialog confirmDialog) {
fConfirmDialog = confirmDialog;
/**
* Sets the add context dialog information
- * @param addContextDialog
+ * @param addContextDialog - a add context dialog implementation
*/
public void setAddContextDialog(IAddContextDialog addContextDialog) {
fAddContextDialog = addContextDialog;
}
+
+ /**
+ * @return the import dialog implementation
+ */
+ public IImportDialog getImportDialog() {
+ if (fImportDialog == null) {
+ fImportDialog = new ImportDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ }
+ return fImportDialog;
+ }
+
+ /**
+ * Sets the import dialog implementation.
+ * @param importDialog - a import dialog implementation
+ */
+ public void setImportDialog(IImportDialog importDialog) {
+ fImportDialog = importDialog;
+ }
+
+ /**
+ * @return the import confirmation dialog implementation.
+ */
+ public IImportConfirmationDialog getImportConfirmationDialog() {
+ if (fImportConfirmationDialog == null) {
+ fImportConfirmationDialog = new ImportConfirmationDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ }
+ return fImportConfirmationDialog;
+ }
+
+ /**
+ * Sets the import confirmation dialog implementation.
+ * @param confirmDialog - a import confirmation dialog implementation.
+ */
+ public void setImportConfirmationDialog(IImportConfirmationDialog confirmDialog) {
+ fImportConfirmationDialog = confirmDialog;
+ }
}
-
--- /dev/null
+/**********************************************************************
+ * Copyright (c) 2012 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.linuxtools.internal.lttng2.ui.views.control.handlers;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.linuxtools.internal.lttng2.ui.Activator;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.ControlView;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.Messages;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.ImportFileInfo;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.IImportDialog;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.TraceSessionState;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
+import org.eclipse.rse.services.files.IFileService;
+import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
+import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * <b><u>ImportHandler</u></b>
+ * <p>
+ * Command handler implementation to import traces from a (remote) session to a tracing project.
+ * </p>
+ */
+public class ImportHandler extends BaseControlViewHandler {
+
+ // ------------------------------------------------------------------------
+ // Attributes
+ // ------------------------------------------------------------------------
+ protected CommandParameter fParam;
+
+ // ------------------------------------------------------------------------
+ // Accessors
+ // ------------------------------------------------------------------------
+
+ // ------------------------------------------------------------------------
+ // Operations
+ // ------------------------------------------------------------------------
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+
+ if (window == null) {
+ return false;
+ }
+
+ fLock.lock();
+ try {
+ final CommandParameter param = fParam.clone();
+
+ final IImportDialog dialog = TraceControlDialogFactory.getInstance().getImportDialog();
+ dialog.setSession(param.getSession());
+
+ if (dialog.open() != Window.OK) {
+ return null;
+ }
+
+ Job job = new Job(Messages.TraceControl_ImportJob) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ List<ImportFileInfo> traces = dialog.getTracePathes();
+ IProject project = dialog.getProject();
+
+ for (Iterator<ImportFileInfo> iterator = traces.iterator(); iterator.hasNext();) {
+ ImportFileInfo remoteFile = (ImportFileInfo) iterator.next();
+ downloadTrace(remoteFile, project);
+ }
+
+ } catch (ExecutionException e) {
+ return new Status(Status.ERROR, Activator.PLUGIN_ID, e.toString());
+ }
+ return Status.OK_STATUS;
+ }
+ };
+ job.setUser(true);
+ job.schedule();
+ } finally {
+ fLock.unlock();
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#isEnabled()
+ */
+ @Override
+ public boolean isEnabled() {
+ // Get workbench page for the Control View
+ IWorkbenchPage page = getWorkbenchPage();
+ if (page == null) {
+ return false;
+ }
+
+ // Check if one or more session are selected
+ ISelection selection = page.getSelection(ControlView.ID);
+ TraceSessionComponent session = null;
+ if (selection instanceof StructuredSelection) {
+ StructuredSelection structered = ((StructuredSelection) selection);
+ for (Iterator<?> iterator = structered.iterator(); iterator.hasNext();) {
+ Object element = (Object) iterator.next();
+ if (element instanceof TraceSessionComponent) {
+ // Add only TraceSessionComponents that are inactive and not destroyed
+ TraceSessionComponent tmpSession = (TraceSessionComponent) element;
+ if ((tmpSession.getSessionState() == TraceSessionState.INACTIVE) && (!tmpSession.isDestroyed())) {
+ session = tmpSession;
+ }
+ }
+ }
+ }
+ boolean isEnabled = session != null;
+
+ fLock.lock();
+ try {
+ fParam = null;
+ if (isEnabled) {
+ fParam = new CommandParameter(session);
+ }
+ } finally {
+ fLock.unlock();
+ }
+ return isEnabled;
+ }
+
+ // ------------------------------------------------------------------------
+ // Helper methods
+ // ------------------------------------------------------------------------
+ /**
+ * Downloads a trace from the remote host to the given project.
+ * @param trace - trace information of trace to import
+ * @param project - project to import to
+ * @throws ExecutionException
+ */
+ private void downloadTrace(ImportFileInfo trace, IProject project) throws ExecutionException {
+ try {
+ IRemoteFileSubSystem fsss = trace.getImportFile().getParentRemoteFileSubSystem();
+
+ IFolder traceFolder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME);
+ if (!traceFolder.exists()) {
+ throw new ExecutionException(Messages.TraceControl_ImportDialogInvalidTracingProject + " (" + TmfTraceFolder.TRACE_FOLDER_NAME + ")"); //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ String traceName = trace.getLocalTraceName();
+ IFolder folder = traceFolder.getFolder(traceName);
+ if (folder.exists()) {
+ if(!trace.isOverwrite()) {
+ throw new ExecutionException(Messages.TraceControl_ImportDialogTraceAlreadyExistError + ": " + traceName); //$NON-NLS-1$
+ }
+ } else {
+ folder.create(true, true, null);
+ }
+
+ IRemoteFile[] sources = fsss.list(trace.getImportFile(), IFileService.FILE_TYPE_FILES, new NullProgressMonitor());
+
+ String[] destinations = new String[sources.length];
+ String[] encodings = new String[sources.length];
+ for (int i = 0; i < sources.length; i++) {
+ destinations[i] = folder.getLocation().addTrailingSeparator().append(sources[i].getName()).toString();
+ encodings[i] = null;
+ }
+
+ fsss.downloadMultiple(sources, destinations, encodings, new NullProgressMonitor());
+
+ } catch (SystemMessageException e) {
+ throw new ExecutionException(e.fillInStackTrace().toString());
+ } catch (CoreException e) {
+ throw new ExecutionException(e.fillInStackTrace().toString());
+ }
+ }
+}
TraceControl_DestroyConfirmationTitle=Destroy Confirmation
TraceControl_DestroyConfirmationMessage=Do you want to delete all selected sessions?
+TraceControl_ImportJob=Importing Traces...
+
TraceControl_StartSessionJob=Starting Session...
TraceControl_StopSessionJob=Stopping Session...
TraceControl_AddContextAvailableContextsTooltip=Available Contexts
TraceControl_AddContextAllLabel=All Contexts
+TraceControl_ImportDialogTitle=Import Traces
+TraceControl_ImportDialogTracesGroupName=Available Traces
+TraceControl_ImportDialogTracesTooltip=The available traces of current session to import
+TraceControl_ImportDialogProjectsGroupName=Available Projects
+TraceControl_ImportDialogProjectsTooltip=The available projects to select from
+TraceControl_ImportDialogOverwriteButtonText=Overwrite existing trace without warning
+TraceControl_ImportDialogCreationError=Dialog box cannot be created
+TraceControl_ImportDialogNoProjectSelectedError=No tracing project selected or available
+TraceControl_ImportDialogInvalidTracingProject=Invalid tracing project. Missing directory
+TraceControl_ImportDialogNoTraceSelectedError=No trace selected or available
+
+TraceControl_ImportDialogConfirmationTitle=Import Confirmation Dialog
+TraceControl_ImportDialogConfirmationOverwriteLabel=Overwrite
+TraceControl_ImportDialogConfirmationRenameLabel=Rename
+TraceControl_ImportDialogConfirmationNewNameLabel=New Trace Name
+TraceControl_InvalidTraceNameError=Invalid trace name
+TraceControl_ImportDialogTraceAlreadyExistError=Trace already exists in project
+
# Tree structure strings
TraceControl_KernelDomainDisplayName=Kernel
TraceControl_UstGlobalDomainDisplayName=UST global