summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorBernd Hufmann2012-12-17 20:37:43 (EST)
committer Bernd Hufmann2012-12-18 11:27:49 (EST)
commit9a1872ba9b25f127eec83309dd14b58fbd0b3cf7 (patch)
tree2d697a2023a887efe801c8ea90ed781023a413fd
parentdfa9d33684f0d08d12169313844e1bb27bd79cf5 (diff)
downloadorg.eclipse.linuxtools-9a1872ba9b25f127eec83309dd14b58fbd0b3cf7.zip
org.eclipse.linuxtools-9a1872ba9b25f127eec83309dd14b58fbd0b3cf7.tar.gz
org.eclipse.linuxtools-9a1872ba9b25f127eec83309dd14b58fbd0b3cf7.tar.bz2
Add support for link with editor in tracing projectsrefs/changes/46/9246/3
- Extend extension org.eclipse.ui.navigator.linkHelper - Add implementation of ILinkHelper interface - Implement getParent() in TmfNavigatorContentProvider Change-Id: I6e37bff9b7891866a61f2a0960e789d8bfbc5fa5 Reviewed-on: https://git.eclipse.org/r/9246 Tested-by: Hudson CI Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com> IP-Clean: Patrick Tasse <patrick.tasse@gmail.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF1
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml23
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfEditorLinkHelper.java152
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java29
4 files changed, 205 insertions, 0 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
index 9b51a98..943a7c4 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF
@@ -25,6 +25,7 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l
org.eclipse.linuxtools.internal.tmf.ui.preferences;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.project.dialogs;x-internal:=true,
org.eclipse.linuxtools.internal.tmf.ui.project.handlers;x-internal:=true,
+ org.eclipse.linuxtools.internal.tmf.ui.project.model;x-internal:=true,
org.eclipse.linuxtools.tmf.ui.editors,
org.eclipse.linuxtools.tmf.ui.project.model,
org.eclipse.linuxtools.tmf.ui.project.wizards,
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml b/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
index ce6443d..85a5a1a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/plugin.xml
@@ -247,6 +247,9 @@
<contentExtension
pattern="org.eclipse.ui.navigator.resources.filters.*">
</contentExtension>
+ <contentExtension
+ pattern="org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfEditorLinkHelper">
+ </contentExtension>
</includes>
</viewerContentBinding>
</extension>
@@ -1160,5 +1163,25 @@
trace_type="org.eclipse.linuxtools.tmf.core.ctfadaptor.CtfTmfTrace">
</type>
</extension>
+ <extension
+ point="org.eclipse.ui.navigator.linkHelper">
+ <linkHelper
+ class="org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfEditorLinkHelper"
+ id="org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfEditorLinkHelper">
+ <editorInputEnablement>
+ <instanceof value="org.eclipse.ui.IFileEditorInput"/>
+ </editorInputEnablement>
+ <selectionEnablement>
+ <or>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement">
+ </instanceof>
+ <instanceof
+ value="org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement">
+ </instanceof>
+ </or>
+ </selectionEnablement>
+ </linkHelper>
+ </extension>
</plugin>
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfEditorLinkHelper.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfEditorLinkHelper.java
new file mode 100644
index 0000000..b7c3330
--- /dev/null
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/model/TmfEditorLinkHelper.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * 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.tmf.ui.project.model;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.trace.TmfExperiment;
+import org.eclipse.linuxtools.tmf.core.trace.TmfTrace;
+import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.ResourceUtil;
+import org.eclipse.ui.navigator.ILinkHelper;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * Implementation of ILinkHelper interface for linking with editor extension for traces and
+ * experiments.
+ *
+ * @author Bernd Hufmann
+ */
+public class TmfEditorLinkHelper implements ILinkHelper {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
+ */
+ @Override
+ public IStructuredSelection findSelection(IEditorInput anInput) {
+ IFile file = ResourceUtil.getFile(anInput);
+ if (file != null) {
+
+ try {
+ // Get the trace type ID
+ String traceTypeId = file.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceTypeId == null) {
+ return StructuredSelection.EMPTY;
+ }
+
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(file.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(file.getProject());
+
+ // Check for experiments, traces which are folders or traces which are files
+ if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) {
+ // Case 1: Experiment
+ for (final ITmfProjectModelElement projectElement : project.getExperimentsFolder().getChildren()) {
+ if (projectElement.getName().equals(file.getParent().getName())) {
+ return new StructuredSelection(projectElement);
+ }
+ }
+ } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) {
+ // Case 2: Trace that is a folder
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ if (projectElement.getName().equals(file.getParent().getName())) {
+ return new StructuredSelection(projectElement);
+ }
+ }
+ } else {
+ // Case 3: Trace that is a file
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ if (projectElement.getResource().equals(file)) {
+ return new StructuredSelection(projectElement);
+ }
+ }
+ }
+ } catch (CoreException e) {
+ return StructuredSelection.EMPTY;
+ }
+ }
+ return StructuredSelection.EMPTY;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
+ */
+ @Override
+ public void activateEditor(IWorkbenchPage aPage, IStructuredSelection aSelection) {
+ if (aSelection == null || aSelection.isEmpty()) {
+ return;
+ }
+
+ IFile file = null;
+
+ if ((aSelection.getFirstElement() instanceof TmfTraceElement)) {
+ TmfTraceElement traceElement = ((TmfTraceElement)aSelection.getFirstElement());
+
+ // If trace is under an experiment, use the original trace from the traces folder
+ traceElement = traceElement.getElementUnderTraceFolder();
+
+ // Get the editor resource
+ final IResource resource = traceElement.getResource();
+ if (resource instanceof IFile) {
+ file = (IFile) resource;
+ } else if (resource instanceof IFolder) {
+ file = ((IFolder) resource).getFile(traceElement.getName() + '_');
+ }
+ } else if ((aSelection.getFirstElement() instanceof TmfExperimentElement)) {
+ TmfExperimentElement experimentElement = (TmfExperimentElement) aSelection.getFirstElement();
+ file = experimentElement.getResource().getFile(experimentElement.getName() + '_');
+ }
+
+ if (file != null) {
+ IEditorInput tmpInput = new FileEditorInput(file);
+ IEditorPart localEditor = aPage.findEditor(tmpInput);
+ if (localEditor != null) {
+ // Editor found.
+ aPage.activate(localEditor);
+ aPage.bringToTop(localEditor);
+ } else {
+ // Search in references for corresponding editor
+ IEditorReference[] refs = aPage.getEditorReferences();
+ for (IEditorReference editorReference : refs) {
+ try {
+ if (editorReference.getEditorInput().equals(tmpInput)) {
+ localEditor = editorReference.getEditor(true);
+ if (localEditor != null) {
+ aPage.bringToTop(localEditor);
+ }
+ }
+ } catch (PartInitException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+}
+
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java
index 0f6c9b3..21bd32a 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfNavigatorContentProvider.java
@@ -8,6 +8,7 @@
*
* Contributors:
* Francois Chouinard - Initial API and implementation
+ * Bernd Hufmann - Implement getParent()
*******************************************************************************/
package org.eclipse.linuxtools.tmf.ui.project.model;
@@ -55,6 +56,34 @@ public class TmfNavigatorContentProvider implements IPipelinedTreeContentProvide
*/
@Override
public Object getParent(Object element) {
+ if (element instanceof IProject) {
+ IProject project = (IProject) element;
+ return project.getParent();
+ }
+
+ if (element instanceof TmfTraceFolder) {
+ TmfTraceFolder folder = (TmfTraceFolder) element;
+ // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent.
+ // The IProject is needed e.g. for link with Editor to work correctly.
+ return folder.getParent().getResource();
+ }
+
+ if (element instanceof TmfTraceElement) {
+ TmfTraceElement traceElement = (TmfTraceElement) element;
+ return traceElement.getParent();
+ }
+
+ if (element instanceof TmfExperimentFolder) {
+ TmfExperimentFolder folder = (TmfExperimentFolder) element;
+ // Return the corresponding IProject as parent because from CNF point of view the IProject is the parent.
+ // The IProject is needed e.g. for link with Editor to work correctly.
+ return folder.getParent().getResource();
+ }
+
+ if (element instanceof TmfExperimentElement) {
+ TmfExperimentElement expElement = (TmfExperimentElement) element;
+ return expElement.getParent();
+ }
return null;
}