From ac44ef715fd4a6f200b650e91d4f012a327ca4ca Mon Sep 17 00:00:00 2001 From: Ansgar Radermacher Date: Wed, 16 Jan 2013 18:19:54 +0100 Subject: [PATCH] tmf: Support the model URI of a trace event Fixes bug 396956. Change-Id: I03cc2b1b34760fe3d9f9c9139cd4c0dca77a6670 Reviewed-on: https://git.eclipse.org/r/9699 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Reviewed-by: Ansgar Radermacher Reviewed-by: Patrick Tasse IP-Clean: Patrick Tasse Tested-by: Patrick Tasse Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir --- .../core/ctfadaptor/CtfCustomAttributes.java | 25 +++++++ .../META-INF/MANIFEST.MF | 2 + .../linuxtools/internal/tmf/ui/Messages.java | 1 + .../internal/tmf/ui/messages.properties | 1 + .../tmf/ui/viewers/events/TmfEventsTable.java | 71 +++++++++++++++++++ org.eclipse.linuxtools.tmf/feature.xml | 2 + 6 files changed, 102 insertions(+) create mode 100644 org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfCustomAttributes.java diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfCustomAttributes.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfCustomAttributes.java new file mode 100644 index 0000000000..44ccdb45a4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfCustomAttributes.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2011-2013 Ericsson, Ecole Polytechnique de Montreal and others + * + * 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: + * Ansgar Radermacher - support for model URI + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.ctfadaptor; + +/** + * Set of constants defining common custom attribute names (key within hash table) + * + * @since 2.0 + */ +public abstract class CtfCustomAttributes { + /** + * Model URI for traces related to EMF models + */ + public final static String MODEL_URI_KEY = "model.emf.uri"; //$NON-NLS-1$ +} diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 943a7c4a03..d2ce307d45 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -60,3 +60,5 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model, org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets, org.eclipse.linuxtools.tmf.ui.widgets.virtualtable +Import-Package: org.eclipse.emf.common.util, + org.eclipse.emf.ecore diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java index 7f00f9c5ee..428771cfc3 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/Messages.java @@ -68,6 +68,7 @@ public class Messages extends NLS { public static String TmfEventsTable_AddBookmarkDialogTitle; public static String TmfEventsTable_ApplyPresetFilterMenuName; public static String TmfEventsTable_ClearFiltersActionText; + public static String TmfEventsTable_NavigateToModelActionText; public static String TmfEventsTable_ContentColumnHeader; public static String TmfEventsTable_FilterHint; public static String TmfEventsTable_HideRawActionText; diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties index f804e502f4..5794b6fcd5 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/messages.properties @@ -50,6 +50,7 @@ TmfEventsTable_AddBookmarkDialogMessage=Enter Bookmark description: TmfEventsTable_AddBookmarkDialogTitle=Add Bookmark TmfEventsTable_ApplyPresetFilterMenuName=Apply preset filter... TmfEventsTable_ClearFiltersActionText=Clear Filters +TmfEventsTable_NavigateToModelActionText=Navigate to Associated Model Element TmfEventsTable_ContentColumnHeader=Content TmfEventsTable_FilterHint= TmfEventsTable_HideRawActionText=Hide Raw diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java index b6079c022e..9028830e06 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/events/TmfEventsTable.java @@ -11,6 +11,7 @@ * Patrick Tasse - Factored out from events view * Francois Chouinard - Replaced Table by TmfVirtualTable * Patrick Tasse - Filter implementation (inspired by www.eclipse.org/mat) + * Ansgar Radermacher - Support navigation to model URIs (Bug 396956) *******************************************************************************/ package org.eclipse.linuxtools.tmf.ui.viewers.events; @@ -27,12 +28,17 @@ import java.util.regex.PatternSyntaxException; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.ListenerList; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EValidator; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; @@ -44,6 +50,7 @@ import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.FontDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.util.OpenStrategy; import org.eclipse.jface.util.SafeRunnable; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; @@ -56,6 +63,8 @@ import org.eclipse.linuxtools.internal.tmf.ui.Messages; import org.eclipse.linuxtools.internal.tmf.ui.dialogs.MultiLineInputDialog; import org.eclipse.linuxtools.tmf.core.component.ITmfDataProvider; import org.eclipse.linuxtools.tmf.core.component.TmfComponent; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfCustomAttributes; +import org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.event.ITmfEventField; import org.eclipse.linuxtools.tmf.core.event.ITmfTimestamp; @@ -114,7 +123,9 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.ide.IGotoMarker; import org.eclipse.ui.themes.ColorUtil; @@ -566,6 +577,56 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS } }; + final IAction navigateToEventAction = new Action(Messages.TmfEventsTable_NavigateToModelActionText) { + @Override + public void run() { + + final TableItem items[] = fTable.getSelection(); + if (items.length != 1) { + return; + } + final TableItem item = items[0]; + + final Object eventData = item.getData(); + if (eventData instanceof CtfTmfEvent) { + String modelURI = ((CtfTmfEvent) eventData).getCustomAttribute(CtfCustomAttributes.MODEL_URI_KEY); + + if (modelURI != null) { + IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + + IFile file = null; + final URI uri = URI.createURI(modelURI); + if (uri.isPlatformResource()) { + IPath path = new Path(uri.toPlatformString(true)); + file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); + } else if (uri.isFile() && !uri.isRelative()) { + file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation( + new Path(uri.toFileString())); + } + + if (file != null) { + try { + /* + * create a temporary validation marker on the + * model file, remove it afterwards thus, + * navigation works with all model editors + * supporting the navigation to a marker + */ + IMarker marker = file.createMarker(EValidator.MARKER); + marker.setAttribute(EValidator.URI_ATTRIBUTE, modelURI); + marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO); + + IDE.openEditor(activePage, marker, OpenStrategy.activateOnOpen()); + marker.delete(); + } + catch (CoreException e) { + displayException(e); + } + } + } + } + } + }; final IAction showSearchBarAction = new Action(Messages.TmfEventsTable_ShowSearchBarActionText) { @Override public void run() { @@ -647,6 +708,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS tablePopupMenu.add(showRawAction); } tablePopupMenu.add(new Separator()); + if (item != null) { + // add navigation action, if event meta data contain a model URI + final Object eventData = item.getData(); + if (eventData instanceof CtfTmfEvent) { + if (((CtfTmfEvent) eventData).listCustomAttributes().contains(CtfCustomAttributes.MODEL_URI_KEY)) { + tablePopupMenu.add(navigateToEventAction); + tablePopupMenu.add(new Separator()); + } + } + } tablePopupMenu.add(clearFiltersAction); final ITmfFilterTreeNode[] savedFilters = FilterManager.getSavedFilters(); if (savedFilters.length > 0) { diff --git a/org.eclipse.linuxtools.tmf/feature.xml b/org.eclipse.linuxtools.tmf/feature.xml index a573238e1e..b51a977df3 100644 --- a/org.eclipse.linuxtools.tmf/feature.xml +++ b/org.eclipse.linuxtools.tmf/feature.xml @@ -37,6 +37,8 @@ + +