From 76fccfb0b6c8a58e27f1e41fc0ebb53baeda390e Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Mon, 17 Jun 2013 21:40:41 -0400 Subject: [PATCH] lttng rcp: add tracing rcp "file->open" buttons there are two buttons added: * File-> Open Trace File... * File-> Open Trace Directory... The traces will be opened into the default directory and automatically select the trace type. If the trace viewer is ambiguous, it will pop-up a window to help. The trace is then opened. The reason that we have open file and open directory is since some traces are directories. Also, the code path of regular trace file opening has been re-routed through this patch to unify code. Change-Id: I28df30745bf47b64ce0ab0f15a8d425fef4dd91a Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/13863 Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir Tested-by: Alexandre Montplaisir --- .../handlers/OpenExperimentHandler.java | 2 +- .../ui/project/handlers/OpenTraceHandler.java | 87 +----- .../tmf/ui/project/model/TmfImportHelper.java | 90 +++++++ .../model/TmfTraceImportException.java | 44 +++ .../tmf/ui/project/model/Messages.java | 17 ++ .../ui/project/model/TmfOpenTraceHelper.java | 251 ++++++++++++++++++ .../tmf/ui/project/model/TmfTraceType.java | 242 ++++++++++++++++- .../tmf/ui/project/model/TraceTypeHelper.java | 9 + .../tmf/ui/project/model/messages.properties | 12 +- .../importtrace/BatchImportTraceWizard.java | 39 +-- .../timegraph/AbstractTimeGraphView.java | 2 +- .../doc/User-Guide.mediawiki | 7 + .../META-INF/MANIFEST.MF | 10 +- .../plugin.properties | 26 +- .../plugin.xml | 56 +++- .../ui/ApplicationWorkbenchWindowAdvisor.java | 40 ++- .../tracing/rcp/ui/TracingRcpPlugin.java | 67 ++++- .../tracing/rcp/ui/cli/CliParser.java | 75 ++++++ .../rcp/ui/cli/TracingRCPCliException.java | 40 +++ .../rcp/ui/commands/OpenDirHandler.java | 50 ++++ .../rcp/ui/commands/OpenFileHandler.java | 49 ++++ .../tracing/rcp/ui/messages/Messages.java | 8 + .../rcp/ui/messages/messages.properties | 4 + 23 files changed, 1077 insertions(+), 150 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfImportHelper.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfTraceImportException.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java create mode 100644 org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/CliParser.java create mode 100644 org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/TracingRCPCliException.java create mode 100644 org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenDirHandler.java create mode 100644 org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenFileHandler.java diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java index e4822e6048..4b70c4a5b7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenExperimentHandler.java @@ -153,7 +153,7 @@ public class OpenExperimentHandler extends AbstractHandler { try { trace.initTrace(element.getResource(), element.getLocation().getPath(), traceEvent.getClass()); } catch (final TmfTraceException e) { - TraceUtils.displayErrorMsg(Messages.OpenExperimentHandler_Title, Messages.OpenTraceHandler_InitError + "\n\n" + e); //$NON-NLS-1$ + TraceUtils.displayErrorMsg(Messages.OpenExperimentHandler_Title, Messages.OpenTraceHandler_InitError + '\n'+'\n' + e); for (int j = 0; j < i; j++) { traces[j].dispose(); } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java index dfd4a3f4fd..233cedae81 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/OpenTraceHandler.java @@ -15,31 +15,15 @@ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; -import org.eclipse.linuxtools.internal.tmf.ui.Activator; -import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; -import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput; -import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IReusableEditor; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.part.FileEditorInput; /** * OpenTraceHandler @@ -113,74 +97,7 @@ public class OpenTraceHandler extends AbstractHandler { } // If trace is under an experiment, use the original trace from the traces folder - final TmfTraceElement traceElement = fTrace.getElementUnderTraceFolder(); - - Thread thread = new Thread() { - @Override - public void run() { - - final ITmfTrace trace = traceElement.instantiateTrace(); - final ITmfEvent traceEvent = traceElement.instantiateEvent(); - if ((trace == null) || (traceEvent == null)) { - TraceUtils.displayErrorMsg(Messages.OpenTraceHandler_Title, Messages.OpenTraceHandler_NoTraceType); - if (trace != null) { - trace.dispose(); - } - return; - } - - // Get the editor_id from the extension point - String traceEditorId = traceElement.getEditorId(); - final String editorId = (traceEditorId != null) ? traceEditorId : TmfEventsEditor.ID; - - try { - trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); - } catch (final TmfTraceException e) { - TraceUtils.displayErrorMsg(Messages.OpenTraceHandler_Title, Messages.OpenTraceHandler_InitError + "\n\n" + e); //$NON-NLS-1$ - trace.dispose(); - return; - } - - final IFile file; - try { - file = traceElement.createBookmarksFile(); - } catch (final CoreException e) { - Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$ - TraceUtils.displayErrorMsg(Messages.OpenTraceHandler_Title, Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$ - trace.dispose(); - return; - } - - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - try { - final IEditorInput editorInput = new TmfEditorInput(file, trace); - final IWorkbench wb = PlatformUI.getWorkbench(); - final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); - - final IEditorPart editor = activePage.findEditor(new FileEditorInput(file)); - if ((editor != null) && (editor instanceof IReusableEditor)) { - activePage.reuseEditor((IReusableEditor) editor, editorInput); - activePage.activate(editor); - } else { - activePage.openEditor(editorInput, editorId); - IDE.setDefaultEditor(file, editorId); - // editor should dispose the trace on close - } - } catch (final PartInitException e) { - TraceUtils.displayErrorMsg(Messages.OpenTraceHandler_Title, Messages.OpenTraceHandler_Error + "\n\n" + e.getMessage()); //$NON-NLS-1$ - Activator.getDefault().logError("Error opening trace " + traceElement.getName(), e); //$NON-NLS-1$ - trace.dispose(); - } - } - }); - - } - }; - - thread.start(); - return null; + return TmfOpenTraceHelper.openTraceFromElement(fTrace.getElementUnderTraceFolder()); } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfImportHelper.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfImportHelper.java new file mode 100644 index 0000000000..60688a2219 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfImportHelper.java @@ -0,0 +1,90 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam - Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.model; + +import java.io.File; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider; + +/** + * Import helper used to import traces + * + * It has two purposes: - import files and directories into projects - set the + * resource types + * + * @author Matthew Khouzam + */ +public class TmfImportHelper { + + /** + * Create a link and replace what was already there. + * + * @param parentFolder + * the resource to import to, does not contain the element name + * @param location + * where the resource (file/directory) is located + * @param targetName + * the name to display + * @return the resource created. Should not be null + * @throws CoreException + * an exception made by createLink. + */ + public static IResource createLink(IFolder parentFolder, IPath location, String targetName) throws CoreException { + File source = new File(location.toString()); + IResource res = null; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + if (source.isDirectory()) { + IFolder folder = parentFolder.getFolder(targetName); + IStatus result = workspace.validateLinkLocation(folder, location); + if (result.isOK()) { + folder.createLink(location, IResource.REPLACE, new NullProgressMonitor()); + } else { + Activator.getDefault().logError(result.getMessage()); + } + } else { + IFile file = parentFolder.getFile(targetName); + IStatus result = workspace.validateLinkLocation(file, location); + if (result.isOK()) { + file.createLink(location, IResource.REPLACE, + new NullProgressMonitor()); + } else { + Activator.getDefault().logError(result.getMessage()); + } + } + forceFolderRefresh(parentFolder); + res = parentFolder.findMember(location.lastSegment()); + return res; + } + + /** + * Refresh the folders to have sub-folders + * + * @param parentFolder + * the folder to refresh + */ + public static void forceFolderRefresh(IFolder parentFolder) { + final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider(); + // force the model to be populated + ncp.getChildren(parentFolder.getProject()); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfTraceImportException.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfTraceImportException.java new file mode 100644 index 0000000000..c266f3badf --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfTraceImportException.java @@ -0,0 +1,44 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam - Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.model; + +/** + * Tmf trace import exception + * + * @author Matthew Khouzam + */ +public class TmfTraceImportException extends Exception { + + private static final long serialVersionUID = -6902068313782751330L; + + /** + * Constructs a new TmfTraceImportException with null as its + * detail message. The cause is not initialized, and may subsequently be + * initialized by a call to {@link #initCause}. + */ + public TmfTraceImportException() { + } + + /** + * Constructs a new exception with the specified detail message. The cause + * is not initialized, and may subsequently be initialized by a call to + * {@link #initCause}. + * + * @param message + * the detail message. The detail message is saved for later + * retrieval by the {@link #getMessage()} method. + */ + public TmfTraceImportException(String message) { + super(message); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java index f510694d5d..960bfdb170 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/Messages.java @@ -45,6 +45,23 @@ public class Messages extends NLS { /** The description for the linked property */ public static String TmfTraceElement_IsLinked; + /** Error opening a trace */ + public static String TmfOpenTraceHelper_ErrorOpeningTrace; + /** Could not link trace */ + public static String TmfOpenTraceHelper_LinkFailed; + /** No trace type match */ + public static String TmfOpenTraceHelper_NoTraceTypeMatch; + /** Open Trace*/ + public static String TmfOpenTraceHelper_OpenTrace; + /** Reduce was too efficient, no candidates found! */ + public static String TmfOpenTraceHelper_ReduceError; + /** No trace type */ + public static String TmfOpenTraceHelper_NoTraceType; + /** Init error */ + public static String TmfOpenTraceHelper_InitError; + /** Error */ + public static String TmfOpenTraceHelper_Error; + static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java new file mode 100644 index 0000000000..b917c06f4d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfOpenTraceHelper.java @@ -0,0 +1,251 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam - Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.project.model; + +import java.io.File; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper; +import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfTraceImportException; +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.ui.editors.TmfEditorInput; +import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IReusableEditor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.part.FileEditorInput; + +/** + * Open trace helper + * + * Helper class for opening trace resources and loading them to a tracing + * project. + * + * @author Matthew Khouzam + * @since 2.1 + */ +public class TmfOpenTraceHelper { + + private static final String ENDL = System.getProperty("line.separator"); //$NON-NLS-1$ + + /** + * Opens a trace from a path while importing it to the project + * "projectRoot". The trace is linked as a resource. + * + * @param projectRoot + * The project to import to + * @param path + * the file to import + * @param shell + * the shell to use for dialogs + * @return IStatus OK if successful + * @throws CoreException + * core exceptions if something is not well set up in the back + * end + */ + public IStatus openTraceFromPath(String projectRoot, String path, Shell shell) throws CoreException { + TmfTraceType tt = TmfTraceType.getInstance(); + TraceTypeHelper traceTypeToSet = null; + try { + traceTypeToSet = tt.selectTraceType(path, shell); + } catch (TmfTraceImportException e) { + MessageBox mb = new MessageBox(shell); + mb.setMessage(e.getMessage()); + mb.open(); + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage()); + } + if (traceTypeToSet == null) { + return Status.CANCEL_STATUS; + } + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectRoot); + IFolder folder = project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME); + String traceName = getTraceName(path, folder); + if (traceExists(path, folder)) { + return openTraceFromProject(projectRoot, traceName); + } + final IPath tracePath = folder.getFullPath().append(traceName); + final IPath pathString = Path.fromOSString(path); + IResource linkedTrace = TmfImportHelper.createLink(folder, pathString, traceName); + if (linkedTrace != null && linkedTrace.exists()) { + IStatus ret = TmfTraceType.setTraceType(tracePath, traceTypeToSet); + if (ret.isOK()) { + ret = openTraceFromProject(projectRoot, traceName); + } + return ret; + } + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, + Messages.TmfOpenTraceHelper_LinkFailed); + } + + private static boolean traceExists(String file, IFolder folder) { + String val = getTraceName(file, folder); + return (folder.findMember(val) != null); + } + + private static boolean isWrongMember(IFolder folder, String ret, final File traceFile) { + final IResource candidate = folder.findMember(ret); + if (candidate != null) { + final IPath rawLocation = candidate.getRawLocation(); + final File file = rawLocation.toFile(); + return !file.equals(traceFile); + } + return false; + } + + /** + * Gets the display name, either "filename" or "filename(n)" if there is + * already a filename existing where n is the next non-used integer starting + * from 2 + * + * @param file + * the file with path + * @param folder + * the folder to import to + * @return the filename + */ + private static String getTraceName(String file, IFolder folder) { + String ret; + final File traceFile = new File(file); + ret = traceFile.getName(); + for (int i = 2; isWrongMember(folder, ret, traceFile); i++) { + ret = traceFile.getName() + '(' + i + ')'; + } + return ret; + } + + /** + * Open a trace from a project + * + * @param projectRoot + * the root of the project + * @param traceName + * the trace name + * @return success or error + */ + public static IStatus openTraceFromProject(String projectRoot, String traceName) { + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final IWorkspaceRoot root = workspace.getRoot(); + IProject project = root.getProject(projectRoot); + TmfImportHelper.forceFolderRefresh(project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME)); + + final TmfProjectElement project2 = TmfProjectRegistry.getProject(project, true); + final TmfTraceFolder tracesFolder = project2.getTracesFolder(); + final List traces = tracesFolder.getTraces(); + TmfTraceElement found = null; + for (TmfTraceElement candidate : traces) { + if (candidate.getName().equals(traceName)) { + found = candidate; + } + } + if (found == null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TmfOpenTraceHelper_ErrorOpeningTrace); + } + return openTraceFromElement(found); + } + + /** + * Open a trace from a TmfTraceElement + * + * @param traceElement + * the {@link TmfTraceElement} to open + * @return Status.OK_STATUS + */ + public static IStatus openTraceFromElement(final TmfTraceElement traceElement) { + Thread thread = new Thread() { + @Override + public void run() { + + final ITmfTrace trace = traceElement.instantiateTrace(); + final ITmfEvent traceEvent = traceElement.instantiateEvent(); + if ((trace == null) || (traceEvent == null)) { + if (trace != null) { + TraceUtils.displayErrorMsg(Messages.TmfOpenTraceHelper_OpenTrace, Messages.TmfOpenTraceHelper_NoTraceType); + trace.dispose(); + } + return; + } + + // Get the editor_id from the extension point + String traceEditorId = traceElement.getEditorId(); + final String editorId = (traceEditorId != null) ? traceEditorId : TmfEventsEditor.ID; + try { + trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass()); + } catch (final TmfTraceException e) { + TraceUtils.displayErrorMsg(Messages.TmfOpenTraceHelper_OpenTrace, Messages.TmfOpenTraceHelper_InitError + ENDL + ENDL + e); + trace.dispose(); + return; + } + + final IFile file; + try { + file = traceElement.createBookmarksFile(); + } catch (final CoreException e) { + Activator.getDefault().logError(Messages.TmfOpenTraceHelper_ErrorOpeningTrace + traceElement.getName()); + TraceUtils.displayErrorMsg(Messages.TmfOpenTraceHelper_OpenTrace, Messages.TmfOpenTraceHelper_Error + ENDL + ENDL + e.getMessage()); + trace.dispose(); + return; + } + + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + try { + final IEditorInput editorInput = new TmfEditorInput(file, trace); + final IWorkbench wb = PlatformUI.getWorkbench(); + final IWorkbenchPage activePage = wb.getActiveWorkbenchWindow().getActivePage(); + final IEditorPart editor = activePage.findEditor(new FileEditorInput(file)); + if ((editor != null) && (editor instanceof IReusableEditor)) { + activePage.reuseEditor((IReusableEditor) editor, editorInput); + activePage.activate(editor); + } else { + activePage.openEditor(editorInput, editorId); + IDE.setDefaultEditor(file, editorId); + // editor should dispose the trace on close + } + } catch (final PartInitException e) { + TraceUtils.displayErrorMsg(Messages.TmfOpenTraceHelper_OpenTrace, Messages.TmfOpenTraceHelper_ErrorOpeningTrace + ENDL + ENDL + e.getMessage()); + Activator.getDefault().logError(Messages.TmfOpenTraceHelper_ErrorOpeningTrace + traceElement.getName()); + trace.dispose(); + } + } + }); + } + }; + thread.start(); + return Status.OK_STATUS; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java index 91d85fac3e..2b2c8d8faf 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceType.java @@ -22,16 +22,31 @@ import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Set; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTraceDefinition; +import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTraceDefinition; +import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfTraceImportException; import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.dialogs.FileSystemElement; /** @@ -44,6 +59,8 @@ import org.eclipse.ui.dialogs.FileSystemElement; */ public final class TmfTraceType { + private static final String DEFAULT_TRACE_ICON_PATH = "icons" + File.separator + "elcl16" + File.separator + "trace.gif"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + private static final char SEPARATOR = ':'; /** @@ -234,12 +251,12 @@ public final class TmfTraceType { // Generate the list of Category:TraceType to populate the ComboBox List traceTypes = new ArrayList(); - List customTypes = getCustomTraceTypes(); + // re-populate custom trace types + getCustomTraceTypes(); for (String key : this.fTraceTypes.keySet()) { TraceTypeHelper tt = this.fTraceTypes.get(key); traceTypes.add(tt.getCategoryName() + SEPARATOR + tt.getName()); } - traceTypes.addAll(customTypes); // Format result return traceTypes.toArray(new String[traceTypes.size()]); @@ -289,13 +306,13 @@ public final class TmfTraceType { // add the custom trace types for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) { String traceTypeName = CUSTOM_TXT_CATEGORY + SEPARATOR + def.definitionName; - TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_TXT_CATEGORY, def.definitionName, null); + TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_TXT_CATEGORY, def.definitionName, new CustomTxtTrace(def)); fTraceTypes.put(traceTypeName, tt); traceTypes.add(traceTypeName); } for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) { String traceTypeName = CUSTOM_XML_CATEGORY + SEPARATOR + def.definitionName; - TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_XML_CATEGORY, def.definitionName, null); + TraceTypeHelper tt = new TraceTypeHelper(traceTypeName, CUSTOM_XML_CATEGORY, def.definitionName, new CustomXmlTrace(def)); fTraceTypes.put(traceTypeName, tt); traceTypes.add(traceTypeName); } @@ -441,8 +458,7 @@ public final class TmfTraceType { * @since 2.0 */ public boolean validate(String traceTypeName, String fileName) { - if (traceTypeName != null && !"".equals(traceTypeName) && //$NON-NLS-1$ - !traceTypeName.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY) && !traceTypeName.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY)) { + if (traceTypeName != null && !traceTypeName.isEmpty()) { if (!fTraceTypes.get(traceTypeName).validate(fileName)) { return false; } @@ -529,4 +545,218 @@ public final class TmfTraceType { } return null; } + + /** + * Is the trace a custom (user-defined) trace type. These are the traces + * like : text and xml defined by the custom trace wizard. + * + * @param traceType + * the trace type in human form (category:name) + * @return true if the trace is a custom type + * @since 2.1 + */ + public static boolean isCustomTrace(String traceType) { + final boolean startsWithTxt = traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY); + final boolean startsWithXML = traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY); + return (startsWithTxt || startsWithXML); + } + + /** + * Gets the custom trace type ID from the custom trace name + * + * @param traceType + * The trace type in human form (category:name) + * @return the trace type ID or null if the trace is not a custom one + * @since 2.1 + */ + public static String getCustomTraceTypeId(String traceType) { + String traceTypeId = null; + + // do custom trace stuff here + String traceTypeToken[] = traceType.split(":", 2); //$NON-NLS-1$ + if (traceTypeToken.length == 2) { + final boolean startsWithTxt = traceType.startsWith(TmfTraceType.CUSTOM_TXT_CATEGORY); + final boolean startsWithXML = traceType.startsWith(TmfTraceType.CUSTOM_XML_CATEGORY); + if (startsWithTxt) { + traceTypeId = CustomTxtTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1]; + } else if (startsWithXML) { + traceTypeId = CustomXmlTrace.class.getCanonicalName() + SEPARATOR + traceTypeToken[1]; + } + } + return traceTypeId; + } + + /** + * Select a trace file for + * + * @param path + * The path of file to import + * @param shell + * a shell to display the message to. If it is null, it is + * assumed to be cancelled. + * @return null if the request is cancelled or a string in the form + * "category:type" if it passes. + * @throws TmfTraceImportException + * if the traces don't match or there are errors in the trace + * file + */ + TraceTypeHelper selectTraceType(String path, Shell shell) throws TmfTraceImportException { + List validCandidates = new ArrayList(); + getCustomTraceTypes(); + final Set traceTypes = fTraceTypes.keySet(); + for (String traceType : traceTypes) { + if (validate(traceType, path)) { + validCandidates.add(fTraceTypes.get(traceType)); + } + } + + TraceTypeHelper traceTypeToSet; + if (validCandidates.isEmpty()) { + final String errorMsg = Messages.TmfOpenTraceHelper_NoTraceTypeMatch + path; + throw new TmfTraceImportException(errorMsg); + } else if (validCandidates.size() != 1) { + List reducedCandidates = reduce(validCandidates); + if (reducedCandidates.size() == 0) { + throw new TmfTraceImportException(Messages.TmfOpenTraceHelper_ReduceError); + } else if (reducedCandidates.size() == 1) { + traceTypeToSet = reducedCandidates.get(0); + } else { + if (shell == null) { + return null; + } + traceTypeToSet = getTraceTypeToSet(reducedCandidates, shell); + } + + } else { + traceTypeToSet = validCandidates.get(0); + } + return traceTypeToSet; + } + + private static List reduce(List candidates) { + List retVal = new ArrayList(); + + // get all the tracetypes that are unique in that stage + for (TraceTypeHelper trace : candidates) { + if (isUnique(trace, candidates)) { + retVal.add(trace); + } + } + return retVal; + } + + /* + * Only return the leaves of the trace types. Ignore custom trace types. + */ + private static boolean isUnique(TraceTypeHelper trace, List set) { + if (TmfTraceType.isCustomTrace(trace.getCanonicalName())) { + return true; + } + // check if the trace type is the leaf. we make an instance of the trace + // type and if it is only an instance of itself, it is a leaf + final ITmfTrace tmfTrace = trace.getTrace(); + int count = -1; + for (TraceTypeHelper child : set) { + final ITmfTrace traceCandidate = child.getTrace(); + if (tmfTrace.getClass().isInstance(traceCandidate)) { + count++; + } + } + return count == 0; + } + + private TraceTypeHelper getTraceTypeToSet(List candidates, Shell shell) { + final Map names = new HashMap(); + Shell shellToShow = new Shell(shell); + final String candidatesToSet[] = new String[1]; + for (TraceTypeHelper candidate : candidates) { + Button b = new Button(shellToShow, SWT.RADIO); + final String displayName = candidate.getCategoryName() + ':' + candidate.getName(); + b.setText(displayName); + names.put(displayName, candidate.getCanonicalName()); + + b.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + final Button source = (Button) e.getSource(); + candidatesToSet[0] = (names.get(source.getText())); + source.getParent().dispose(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + + } + }); + } + shellToShow.setLayout(new RowLayout(SWT.VERTICAL)); + shellToShow.pack(); + shellToShow.open(); + + Display display = shellToShow.getDisplay(); + while (!shellToShow.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + return fTraceTypes.get(candidatesToSet[0]); + } + + /** + * Set the trace type of a {@Link TraceTypeHelper}. Should only be + * used internally by this project. + * + * @param path + * the {@link IPath} path of the resource to set + * @param traceType + * the {@link TraceTypeHelper} to set the trace type to. + * @return Status.OK_Status if successful, error is otherwise. + * @throws CoreException + * An exception caused by accessing eclipse project items. + */ + static IStatus setTraceType(IPath path, TraceTypeHelper traceType) throws CoreException { + IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(path); + String TRACE_NAME = path.lastSegment(); + String traceBundle = null, traceTypeId = traceType.getCanonicalName(), traceIcon = null; + if (TmfTraceType.isCustomTrace(traceTypeId)) { + traceTypeId = TmfTraceType.getCustomTraceTypeId(traceTypeId); + traceBundle = Activator.getDefault().getBundle().getSymbolicName(); + traceIcon = DEFAULT_TRACE_ICON_PATH; + } else { + IConfigurationElement ce = TmfTraceType.getInstance().getTraceAttributes(traceTypeId); + traceBundle = ce.getContributor().getName(); + traceIcon = ce.getAttribute(TmfTraceType.ICON_ATTR); + } + + resource.setPersistentProperty(TmfCommonConstants.TRACEBUNDLE, traceBundle); + resource.setPersistentProperty(TmfCommonConstants.TRACETYPE, traceTypeId); + resource.setPersistentProperty(TmfCommonConstants.TRACEICON, traceIcon); + + TmfProjectElement tmfProject = TmfProjectRegistry.getProject(resource.getProject()); + if (tmfProject != null) { + final TmfTraceFolder tracesFolder = tmfProject.getTracesFolder(); + tracesFolder.refresh(); + + List traces = tracesFolder.getTraces(); + boolean found = false; + for (TmfTraceElement traceElement : traces) { + if (traceElement.getName().equals(resource.getName())) { + traceElement.refreshTraceType(); + found = true; + break; + } + } + if (!found) { + TmfTraceElement te = new TmfTraceElement(TRACE_NAME, resource, tracesFolder); + te.refreshTraceType(); + traces = tracesFolder.getTraces(); + for (TmfTraceElement traceElement : traces) { + traceElement.refreshTraceType(); + } + } + } + return Status.OK_STATUS; + } + } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java index 7e602b059b..5dca67eae9 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TraceTypeHelper.java @@ -96,6 +96,15 @@ public class TraceTypeHelper { return valid; } + /** + * Get an object of the trace type + * @return an object of the trace type + * @since 2.1 + */ + public ITmfTrace getTrace(){ + return fTrace; + } + private boolean standardValidate(String path) { final boolean valid = fTrace.validate(null, path).equals(Status.OK_STATUS); return valid; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties index 03ba4b3d44..e1cddc5ef3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/messages.properties @@ -17,4 +17,14 @@ TmfTraceElement_Name = name TmfTraceElement_Path = path TmfTraceElement_Location = location TmfTraceElement_EventType = type -TmfTraceElement_IsLinked = linked \ No newline at end of file +TmfTraceElement_IsLinked = linked + +# Open trace error messages +TmfOpenTraceHelper_ErrorOpeningTrace=Error opening trace +TmfOpenTraceHelper_LinkFailed=Link creation failed +TmfOpenTraceHelper_NoTraceTypeMatch=No trace types found to match location +TmfOpenTraceHelper_OpenTrace=Open Trace +TmfOpenTraceHelper_ReduceError=Something went wrong +TmfOpenTraceHelper_NoTraceType=No trace type associated to that trace\nPlease select a valid type +TmfOpenTraceHelper_Error=Error opening trace. +TmfOpenTraceHelper_InitError = Error initializing trace. \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java index 5fae7eca85..0c01055ecb 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/wizards/importtrace/BatchImportTraceWizard.java @@ -30,7 +30,6 @@ import java.util.concurrent.BlockingQueue; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; @@ -50,6 +49,7 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.linuxtools.internal.tmf.ui.Activator; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtTrace; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomXmlTrace; +import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper; import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; @@ -252,8 +252,12 @@ public class BatchImportTraceWizard extends ImportTraceWizard { for (FileAndName traceToImport : fTraces) { try { if (fLinked) { - createLink(fTargetFolder, Path.fromOSString(traceToImport.getFile().getAbsolutePath()), traceToImport.getName()); - success = setTraceType(traceToImport).isOK(); + if (TmfImportHelper.createLink(fTargetFolder, Path.fromOSString(traceToImport.getFile().getAbsolutePath()), traceToImport.getName()) != null) { + success = false; + } + else { + success = setTraceType(traceToImport).isOK(); + } } else { List subList = new ArrayList(); @@ -266,7 +270,7 @@ public class BatchImportTraceWizard extends ImportTraceWizard { subList.add(parentFile); parentFile = parentFile.getParentFile(); final FileInputStream source = new FileInputStream(traceToImport.getFile()); - if( resource.exists()) { + if (resource.exists()) { resource.delete(IResource.FORCE, new NullProgressMonitor()); } resource.create(source, true, new NullProgressMonitor()); @@ -310,33 +314,6 @@ public class BatchImportTraceWizard extends ImportTraceWizard { return success; } - private static void createLink(IFolder parentFolder, IPath location, String targetName) { - File source = new File(location.toString()); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - try { - - if (source.isDirectory()) { - IFolder folder = parentFolder.getFolder(targetName); - IStatus result = workspace.validateLinkLocation(folder, location); - if (result.isOK()) { - folder.createLink(location, IResource.REPLACE, null); - } else { - Activator.getDefault().logError(result.getMessage()); - } - } else { - IFile file = parentFolder.getFile(targetName); - IStatus result = workspace.validateLinkLocation(file, location); - if (result.isOK()) { - file.createLink(location, IResource.REPLACE, null); - } else { - Activator.getDefault().logError(result.getMessage()); - } - } - } catch (CoreException e) { - - } - } - private IStatus setTraceType(FileAndName traceToImport) { IStatus validate = Status.OK_STATUS; IPath path = fTargetFolder.getFullPath().append(traceToImport.getName()); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java index 795b2529b2..4b538c7661 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/timegraph/AbstractTimeGraphView.java @@ -394,7 +394,7 @@ public abstract class AbstractTimeGraphView extends TmfView { if (columnIndex == 0) { return entry.getName(); } - return ""; //$NON-NLS-1$ + return new String(); } } diff --git a/org.eclipse.linuxtools.tracing.rcp.help/doc/User-Guide.mediawiki b/org.eclipse.linuxtools.tracing.rcp.help/doc/User-Guide.mediawiki index d5526c6bee..f39740aeb2 100644 --- a/org.eclipse.linuxtools.tracing.rcp.help/doc/User-Guide.mediawiki +++ b/org.eclipse.linuxtools.tracing.rcp.help/doc/User-Guide.mediawiki @@ -16,6 +16,13 @@ needed, a default tracing project called ''Tracing''. Now the application can be used as described in the User Guide for Linux Tools LTTng integration (see section [[#References | References]]). += Opening a Trace = +To open a trace, click on the '''File''' menu, '''Open''' and select a '''Open file...''' (logs and such) or '''Open directory...''' (Ctf trace). Select the file or directory, and the RCP will open it. It will attempt to autodetect the trace type. If many trace types can read this trace, a window will prompt the user to select a trace type. Once a trace type is selected, the trace loads. + +If the user prefers, they can launch the RCP with the argument '''--open '''. The trace will then automatically open. Conflicting trace types will be resolved the same way as opening from a menu, if there are conflicting types, the user will be prompted to select a trace type. + +In both of the above cases, the trace will be linked to the default project. + = References = * [http://www.eclipse.org/linuxtools/projectPages/lttng/ Linux Tools - LTTng integration] diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tracing.rcp.ui/META-INF/MANIFEST.MF index 18277c08bb..7bcd0498eb 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tracing.rcp.ui/META-INF/MANIFEST.MF @@ -8,13 +8,17 @@ Bundle-SymbolicName: org.eclipse.linuxtools.tracing.rcp.ui;singleton:=true Bundle-Activator: org.eclipse.linuxtools.internal.tracing.rcp.ui.TracingRcpPlugin Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Require-Bundle: org.eclipse.ui, +Require-Bundle: org.eclipse.core.commands, + org.eclipse.core.resources, org.eclipse.core.runtime, + org.eclipse.ui, + org.eclipse.ui.ide, + org.eclipse.ui.workbench, org.eclipse.linuxtools.tmf.ui;bundle-version="2.0.0", org.eclipse.linuxtools.tmf.core;bundle-version="2.0.0", - org.eclipse.core.resources, - org.eclipse.ui.ide, org.eclipse.update.configurator;bundle-version="3.3.200", org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.300" Export-Package: org.eclipse.linuxtools.internal.tracing.rcp.ui;x-internal:=true, + org.eclipse.linuxtools.internal.tracing.rcp.ui.cli;x-internal:=true, + org.eclipse.linuxtools.internal.tracing.rcp.ui.commands;x-internal:=true, org.eclipse.linuxtools.internal.tracing.rcp.ui.messages;x-internal:=true diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/plugin.properties b/org.eclipse.linuxtools.tracing.rcp.ui/plugin.properties index 1ae88f8b76..c29efe5519 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/plugin.properties +++ b/org.eclipse.linuxtools.tracing.rcp.ui/plugin.properties @@ -16,4 +16,28 @@ Bundle-Name = Linux Tools Trace Viewer UI Plug-in menu.main.file = File menu.main.window = Window -menu.main.help = Help \ No newline at end of file +menu.main.help = Help +product.name = Linux Tools Trace Viewer +activity.description = Tracing RCP +activity.name = Tracing RCP +activity.description.javaPerspective = (Unwanted) Java Perspective +activity.name.javaPerspective = Unwanted Java Perspective +activity.description.teamPerspective = (Unwanted) Team Perspective +activity.name.teamPerspective = Unwanted Team Perspective +activity.description.debugPerspective = (Unwanted) Debug Perspective +activity.name.debugPerspective = Unwanted Debug Perspective +activity.description.pluginDevPerspective = (Unwanted) PluginDev Perspective +activity.name.pluginDevPerspective = Unwanted PluginDev Perspective +activity.description.resourcePerspective = (Unwanted) Resource Perspective +activity.name.resourcePerspective = Unwanted Resource Perspective +activity.description.search = (Unwanted) Search Perspective +activity.name.search = Unwanted Search Perspective +command.OpenFile.description = Opens a file +command.OpenFile.name = Open File +command.OpenDirectory.description = Opens a directory +command.OpenDirectory.name = Open Directory +command.OpenFile.label = Open Trace File... +command.OpenDirectory.label = Open Trace Directory... +menu.mnemonic = F +menu.label = Open +menu.mnemonic.0 = H \ No newline at end of file diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/plugin.xml b/org.eclipse.linuxtools.tracing.rcp.ui/plugin.xml index b6b19f94a7..edd5e1d3b6 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/plugin.xml +++ b/org.eclipse.linuxtools.tracing.rcp.ui/plugin.xml @@ -45,16 +45,34 @@ - - --> + + + + + + + + - - - - - - - + + + + + + + @@ -71,13 +89,27 @@ + mnemonic="%menu.mnemonic"> + + + + + + + mnemonic="%menu.mnemonic.0"> diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/ApplicationWorkbenchWindowAdvisor.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/ApplicationWorkbenchWindowAdvisor.java index 88a5e8f0e7..d5fbf90963 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/ApplicationWorkbenchWindowAdvisor.java +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/ApplicationWorkbenchWindowAdvisor.java @@ -11,8 +11,16 @@ **********************************************************************/ package org.eclipse.linuxtools.internal.tracing.rcp.ui; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser; import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider; import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; import org.eclipse.ui.IPerspectiveDescriptor; import org.eclipse.ui.IPerspectiveListener; @@ -59,15 +67,15 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { // "org.eclipse.debug.ui.profileActionSet" }; - // ------------------------------------------------------------------------ // Constructors // ------------------------------------------------------------------------ /** * Standard constructor + * * @param configurer - * - the workbench window configurer + * - the workbench window configurer */ public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) { super(configurer); @@ -96,6 +104,27 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().addPerspectiveListener(new PerspectiveListener()); createDefaultProject(); hideActionSets(); + openTraceIfNecessary(); + } + + + + private static void openTraceIfNecessary() { + String traceToOpen = TracingRcpPlugin.getDefault().getCli().getArgument(CliParser.OPEN_FILE_LOCATION); + if (traceToOpen != null) { + final IWorkspace workspace = ResourcesPlugin.getWorkspace(); + final IWorkspaceRoot root = workspace.getRoot(); + IProject project = root.getProject(Messages.ApplicationWorkbenchWindowAdvisor_DefaultProjectName); + final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider(); + ncp.getChildren( project ); // force the model to be populated + TmfOpenTraceHelper oth = new TmfOpenTraceHelper(); + try { + oth.openTraceFromPath(Messages.ApplicationWorkbenchWindowAdvisor_DefaultProjectName,traceToOpen, TracingRcpPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell()); + } catch (CoreException e) { + TracingRcpPlugin.getDefault().logError(e.getMessage()); + } + + } } // ------------------------------------------------------------------------ @@ -119,13 +148,14 @@ public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor { } /** - * A perspective listener implementation - * @author Bernd Hufmann + * A perspective listener implementation + * + * @author Bernd Hufmann */ public class PerspectiveListener implements IPerspectiveListener { /** - * Default Constructor + * Default Constructor */ public PerspectiveListener() { } diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/TracingRcpPlugin.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/TracingRcpPlugin.java index c5f61bae49..c2863df1ee 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/TracingRcpPlugin.java +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/TracingRcpPlugin.java @@ -8,10 +8,16 @@ * * Contributors: * Bernd Hufmann - Initial API and implementation + * Matthew Khouzam - Implementation of File->Open **********************************************************************/ package org.eclipse.linuxtools.internal.tracing.rcp.ui; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.TracingRCPCliException; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.cli.CliParser; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; @@ -41,6 +47,7 @@ public class TracingRcpPlugin extends AbstractUIPlugin { // The shared instance private static TracingRcpPlugin fPlugin; + private static CliParser fCli; // ------------------------------------------------------------------------ // Constructor(s) @@ -79,22 +86,74 @@ public class TracingRcpPlugin extends AbstractUIPlugin { public void start(BundleContext context) throws Exception { super.start(context); fPlugin = this; + String args[] = Platform.getCommandLineArgs(); + fCli = null; + try { + fCli = new CliParser(args); + } catch (TracingRCPCliException e) { + logError(e.getMessage()); } + } @Override public void stop(BundleContext context) throws Exception { fPlugin = null; super.stop(context); -} + } + + /** + * Gets the command line parser + * + * @return the command line parser + */ + public CliParser getCli() { + return fCli; + } /** - * Returns an image descriptor for the image file at the given - * plug-in relative path + * Returns an image descriptor for the image file at the given plug-in + * relative path * - * @param path the path + * @param path + * the path * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String path) { return imageDescriptorFromPlugin(PLUGIN_ID, path); } + + /** + * Log an error + * + * @param message + * the error message to log + */ + public void logError(String message) { + getDefault().getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, message)); + } + + /** + * Log an error + * + * @param message + * the error message to log + * @param e + * the exception to log + */ + public void logError(String message, Exception e) { + getDefault().getLog().log( + new Status(IStatus.ERROR, PLUGIN_ID, message, e)); + } + + /** + * Log a warning + * + * @param message + * the warning message to log + */ + public void logWarning(String message) { + getDefault().getLog().log( + new Status(IStatus.WARNING, PLUGIN_ID, message)); + } + } diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/CliParser.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/CliParser.java new file mode 100644 index 0000000000..9f0cb21619 --- /dev/null +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/CliParser.java @@ -0,0 +1,75 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam- Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tracing.rcp.ui.cli; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages; + +/** + * Command line parser + * + * @author Matthew Khouzam + */ +public class CliParser { + + private static final String NOUI_ARG = "--NOUI"; //$NON-NLS-1$ + + private static final String OPEN_ARG = "--open"; //$NON-NLS-1$ + + private final Map params = new HashMap(); + + /** Open key */ + public static final String OPEN_FILE_LOCATION = ".,-=open=-,."; //$NON-NLS-1$ + /** No ui key */ + public static final String NO_UI = ".,-=noui=-,."; //$NON-NLS-1$ + + /** + * Constructor + * + * @param args + * the command line arguments + * @throws TracingRCPCliException + * an error occurred parsing the cli + */ + public CliParser(final String[] args) throws TracingRCPCliException { + for (int i = 0; i < args.length; i++) { + if (args[i].equals(OPEN_ARG)) { + put(OPEN_FILE_LOCATION, args, i); + // skip since we have two args + i++; + } + else if (args[i].equals(NOUI_ARG)) { + params.put(NO_UI, new String()); + } + } + } + + private void put(String key, String[] args, int pos) throws TracingRCPCliException { + if (args.length <= pos) { + throw new TracingRCPCliException(Messages.CliParser_MalformedCommand + ':' + ' ' + args[pos]); + } + params.put(key, args[pos + 1]); + } + + /** + * Get a parameter from the parsed command line + * @param key OPEN_FILE_LOCATION or NO_UI + * @return the value of the parameter, can be null + */ + public String getArgument(String key) { + return params.get(key); + } + +} diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/TracingRCPCliException.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/TracingRCPCliException.java new file mode 100644 index 0000000000..8c20e1bdc2 --- /dev/null +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/cli/TracingRCPCliException.java @@ -0,0 +1,40 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam- Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tracing.rcp.ui.cli; + +/** + * Command line exceptions. + * + * @author Matthew Khouzam + */ +public class TracingRCPCliException extends Exception { + + /** + * Serial UID + */ + private static final long serialVersionUID = -844846299720475123L; + + /** + * Constructs a new exception with the specified detail message. The cause + * is not initialized, and may subsequently be initialized by a call to + * {@link #initCause}. + * + * @param message + * the detail message. The detail message is saved for later + * retrieval by the {@link #getMessage()} method. + */ + public TracingRCPCliException(String message) { + super(message); + } + +} diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenDirHandler.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenDirHandler.java new file mode 100644 index 0000000000..958849d750 --- /dev/null +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenDirHandler.java @@ -0,0 +1,50 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam - Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tracing.rcp.ui.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.TracingRcpPlugin; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * Open a directory, not a file + * + * @author Matthew Khouzam + */ +public class OpenDirHandler extends AbstractHandler{ + + @Override + public Object execute(ExecutionEvent event) { + // Open a directory + final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + DirectoryDialog dd = new DirectoryDialog(shell); + dd.setText(Messages.OpenDirHandler_SelectTraceType); + String dir = dd.open(); + if (dir == null) { + return null; + } + TmfOpenTraceHelper oth = new TmfOpenTraceHelper(); + try { + oth.openTraceFromPath(Messages.ApplicationWorkbenchWindowAdvisor_DefaultProjectName, dir, shell); + } catch (CoreException e) { + TracingRcpPlugin.getDefault().logError(e.getMessage(), e); + } + return null; + } +} diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenFileHandler.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenFileHandler.java new file mode 100644 index 0000000000..3a84f11363 --- /dev/null +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/commands/OpenFileHandler.java @@ -0,0 +1,49 @@ +/********************************************************************** + * Copyright (c) 2013 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: + * Matthew Khouzam - Initial API and implementation + **********************************************************************/ + +package org.eclipse.linuxtools.internal.tracing.rcp.ui.commands; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.TracingRcpPlugin; +import org.eclipse.linuxtools.internal.tracing.rcp.ui.messages.Messages; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +/** + * Open file handler, used to open files (not directories) + * + * @author Matthew Khouzam + */ +public class OpenFileHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) { + final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); + FileDialog fd = new FileDialog(shell); + fd.setText(Messages.OpenFileHandler_SelectTraceFile); + String filePath = fd.open(); + if (filePath == null) { + return null; + } + TmfOpenTraceHelper oth = new TmfOpenTraceHelper(); + try { + oth.openTraceFromPath(Messages.ApplicationWorkbenchWindowAdvisor_DefaultProjectName,filePath, shell); + } catch (CoreException e) { + TracingRcpPlugin.getDefault().logError(e.getMessage(), e); + } + return null; + } +} diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/Messages.java b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/Messages.java index 4ea6ea9b3c..1d6018486f 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/Messages.java +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/Messages.java @@ -31,6 +31,14 @@ public class Messages extends NLS { public static String Application_WorkspaceRootNotExistError; /** Error message if workspace root is write protected */ public static String Application_WorkspaceRootPermissionError; + /** Malformed command */ + public static String CliParser_MalformedCommand; + /** Unkown command */ + public static String CliParser_UnknownCommand; + /** Select trace type title */ + public static String OpenDirHandler_SelectTraceType; + /** Select trace file */ + public static String OpenFileHandler_SelectTraceFile; static { // initialize resource bundle diff --git a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/messages.properties b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/messages.properties index f783086ab8..c6044a54c7 100644 --- a/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/messages.properties +++ b/org.eclipse.linuxtools.tracing.rcp.ui/src/org/eclipse/linuxtools/internal/tracing/rcp/ui/messages/messages.properties @@ -14,3 +14,7 @@ ApplicationWorkbenchWindowAdvisor_WindowTitle=Trace Viewer Application_WorkspaceCreationError=Workspace Creation Error Application_WorkspaceRootNotExistError=Workspace root {0} doesn't exists.\n\nPlease create the workspace root. Application_WorkspaceRootPermissionError=No permission to create workspace in workspace root {0}\n\nPlease change permission of the workspace root. +CliParser_MalformedCommand=malformed command +CliParser_UnknownCommand=unknown command +OpenDirHandler_SelectTraceType=Open trace directory +OpenFileHandler_SelectTraceFile=Open trace file \ No newline at end of file -- 2.34.1