-/*******************************************************************************\r
- * Copyright (c) 2010 Ericsson\r
- * \r
- * All rights reserved. This program and the accompanying materials are\r
- * made available under the terms of the Eclipse Public License v1.0 which\r
- * accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- * \r
- * Contributors:\r
- * Patrick Tasse - Initial API and implementation\r
- *******************************************************************************/\r
-\r
-package org.eclipse.linuxtools.tmf.ui.editors;\r
-\r
-import org.eclipse.core.resources.IMarker;\r
-import org.eclipse.core.resources.IMarkerDelta;\r
-import org.eclipse.core.resources.IResource;\r
-import org.eclipse.core.resources.IResourceChangeEvent;\r
-import org.eclipse.core.resources.IResourceChangeListener;\r
-import org.eclipse.core.resources.IResourceDelta;\r
-import org.eclipse.core.resources.ResourcesPlugin;\r
-import org.eclipse.core.runtime.CoreException;\r
-import org.eclipse.core.runtime.IProgressMonitor;\r
-import org.eclipse.linuxtools.tmf.signal.TmfSignalHandler;\r
-import org.eclipse.linuxtools.tmf.signal.TmfTraceSelectedSignal;\r
-import org.eclipse.linuxtools.tmf.trace.ITmfTrace;\r
-import org.eclipse.linuxtools.tmf.ui.parsers.ParserProviderManager;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceClosedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal;\r
-import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;\r
-import org.eclipse.linuxtools.tmf.ui.views.project.ProjectView;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.ui.IEditorInput;\r
-import org.eclipse.ui.IEditorPart;\r
-import org.eclipse.ui.IEditorSite;\r
-import org.eclipse.ui.IFileEditorInput;\r
-import org.eclipse.ui.IPropertyListener;\r
-import org.eclipse.ui.IReusableEditor;\r
-import org.eclipse.ui.PartInitException;\r
-import org.eclipse.ui.ide.FileStoreEditorInput;\r
-import org.eclipse.ui.ide.IGotoMarker;\r
-\r
-/**\r
- * <b><u>TmfEventsEditor</u></b>\r
- */\r
-public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener {\r
-\r
- public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$\r
- \r
- private TmfEventsTable fEventsTable;\r
- private IResource fResource;\r
- private ITmfTrace fTrace;\r
- private Composite fParent;\r
-\r
- @Override\r
- public void doSave(IProgressMonitor monitor) {\r
- }\r
-\r
- @Override\r
- public void doSaveAs() {\r
- }\r
-\r
- @Override\r
- public void init(IEditorSite site, IEditorInput input) throws PartInitException {\r
- if (input instanceof TmfEditorInput) {\r
- fResource = ((TmfEditorInput) input).getResource();\r
- fTrace = ((TmfEditorInput) input).getTrace();\r
- } else if (input instanceof IFileEditorInput) {\r
- fResource = ((IFileEditorInput) input).getFile();\r
- fTrace = ParserProviderManager.getTrace(fResource);\r
- input = new TmfEditorInput(fResource, fTrace);\r
- } else if (input instanceof FileStoreEditorInput) {\r
- try {\r
- FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) input;\r
- fResource = ProjectView.createLink(fileStoreEditorInput.getURI());\r
- fTrace = ParserProviderManager.getTrace(fResource);\r
- input = new TmfEditorInput(fResource, fTrace);\r
- } catch (CoreException e) {\r
- throw new PartInitException(e.getMessage());\r
- }\r
- } else {\r
- throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$\r
- }\r
- if (fTrace == null) {\r
- throw new PartInitException("Invalid IEditorInput: " + fResource.getName()); //$NON-NLS-1$\r
- }\r
- super.setSite(site);\r
- super.setInput(input);\r
- }\r
-\r
- @Override\r
- public boolean isDirty() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public boolean isSaveAsAllowed() {\r
- return false;\r
- }\r
-\r
- @Override\r
- public void setInput(IEditorInput input) {\r
- super.setInput(input);\r
- firePropertyChange(IEditorPart.PROP_INPUT);\r
- }\r
-\r
- @Override\r
- public void propertyChanged(Object source, int propId) {\r
- if (propId == IEditorPart.PROP_INPUT) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- fResource = ((TmfEditorInput) getEditorInput()).getResource();\r
- fTrace = ((TmfEditorInput) getEditorInput()).getTrace();\r
- fEventsTable.dispose();\r
- if (fTrace != null) {\r
- fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- fEventsTable.refreshBookmarks(fResource);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fResource, fEventsTable));\r
- } else {\r
- fEventsTable = new TmfEventsTable(fParent, 0);\r
- }\r
- fParent.layout();\r
- }\r
- }\r
-\r
- @Override\r
- public void createPartControl(Composite parent) {\r
- fParent = parent;\r
- setPartName(getEditorInput().getName());\r
- if (fTrace != null) {\r
- fEventsTable = createEventsTable(parent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- fEventsTable.refreshBookmarks(fResource);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fResource, fEventsTable));\r
- } else {\r
- fEventsTable = new TmfEventsTable(parent, 0);\r
- }\r
- addPropertyListener(this);\r
- ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);\r
- }\r
-\r
- @Override\r
- public void dispose() {\r
- ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);\r
- removePropertyListener(this);\r
- if (fTrace != null) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- }\r
- if (fEventsTable != null) {\r
- fEventsTable.dispose();\r
- }\r
- super.dispose();\r
- }\r
-\r
- protected TmfEventsTable createEventsTable(Composite parent, int cacheSize) {\r
- TmfEventsTable eventsTable = ParserProviderManager.getEventsTable(fTrace, parent, cacheSize);\r
- if (eventsTable == null) {\r
- eventsTable = new TmfEventsTable(parent, cacheSize);\r
- }\r
- return eventsTable;\r
- }\r
- \r
- @Override\r
- public ITmfTrace getTrace() {\r
- return fTrace;\r
- }\r
-\r
- @Override\r
- public IResource getResource() {\r
- return fResource;\r
- }\r
-\r
- @Override\r
- public void setFocus() {\r
- fEventsTable.setFocus();\r
- if (fTrace != null) {\r
- broadcast(new TmfTraceSelectedSignal(this, fTrace));\r
- }\r
- }\r
-\r
- @Override\r
- @SuppressWarnings("rawtypes")\r
- public Object getAdapter(Class adapter) {\r
- if (IGotoMarker.class.equals(adapter)) {\r
- return fEventsTable;\r
- }\r
- return super.getAdapter(adapter);\r
- }\r
-\r
- @Override\r
- public void resourceChanged(IResourceChangeEvent event) {\r
- for (IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {\r
- if (delta.getResource().equals(fResource) && delta.getKind() == IResourceDelta.REMOVED) {\r
- final IMarker bookmark = delta.getMarker();\r
- Display.getDefault().asyncExec(new Runnable() {\r
- @Override\r
- public void run() {\r
- fEventsTable.removeBookmark(bookmark);\r
- }\r
- });\r
- }\r
- }\r
- }\r
- \r
- // ------------------------------------------------------------------------\r
- // Global commands\r
- // ------------------------------------------------------------------------\r
-\r
- public void addBookmark() {\r
- fEventsTable.addBookmark(fResource);\r
- }\r
- \r
-\r
- // ------------------------------------------------------------------------\r
- // Signal handlers\r
- // ------------------------------------------------------------------------\r
- \r
- @TmfSignalHandler\r
- public void traceParserUpdated(TmfTraceParserUpdatedSignal signal) {\r
- if (signal.getTraceResource().equals(fResource)) {\r
- broadcast(new TmfTraceClosedSignal(this, fTrace));\r
- fTrace = ParserProviderManager.getTrace(fResource);\r
- fEventsTable.dispose();\r
- if (fTrace != null) {\r
- fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());\r
- fEventsTable.setTrace(fTrace, true);\r
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fResource, fEventsTable));\r
- } else {\r
- fEventsTable = new TmfEventsTable(fParent, 0);\r
- }\r
- fParent.layout();\r
- }\r
- }\r
-\r
- @TmfSignalHandler\r
- public void traceSelected(TmfTraceSelectedSignal signal) {\r
- if (signal.getSource() != this && signal.getTrace().equals(fTrace)) {\r
- getSite().getPage().bringToTop(this);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2010, 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:
+ * Patrick Tasse - Initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.linuxtools.tmf.ui.editors;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.IMarkerDelta;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceChangeEvent;
+import org.eclipse.core.resources.IResourceChangeListener;
+import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.InvalidRegistryObjectException;
+import org.eclipse.core.runtime.ListenerList;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.jface.util.SafeRunnable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.linuxtools.internal.tmf.ui.Activator;
+import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomEventsTable;
+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.handlers.Messages;
+import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
+import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
+import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException;
+import org.eclipse.linuxtools.tmf.core.signal.TmfSignalHandler;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTimestampFormatUpdateSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceClosedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal;
+import org.eclipse.linuxtools.tmf.core.signal.TmfTraceSelectedSignal;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfContext;
+import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
+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.linuxtools.tmf.ui.project.model.TmfTraceType;
+import org.eclipse.linuxtools.tmf.ui.viewers.events.TmfEventsTable;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPropertyListener;
+import org.eclipse.ui.IReusableEditor;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.ide.IGotoMarker;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.views.properties.IPropertySheetPage;
+import org.osgi.framework.Bundle;
+
+/**
+ * Editor for TMF events
+ *
+ * @version 1.0
+ * @author Patrick Tasse
+ * @since 2.0
+ */
+public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener, ISelectionProvider, ISelectionChangedListener, IPartListener {
+
+ /** ID for this class */
+ public static final String ID = "org.eclipse.linuxtools.tmf.ui.editors.events"; //$NON-NLS-1$
+
+ private TmfEventsTable fEventsTable;
+ private IFile fFile;
+ private ITmfTrace fTrace;
+ private Composite fParent;
+ private ListenerList fSelectionChangedListeners = new ListenerList();
+ private boolean fTraceSelected;
+
+ @Override
+ public void doSave(final IProgressMonitor monitor) {
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public void init(final IEditorSite site, IEditorInput input) throws PartInitException {
+ IFileEditorInput fileEditorInput;
+ if (input instanceof TmfEditorInput) {
+ fFile = ((TmfEditorInput) input).getFile();
+ fTrace = ((TmfEditorInput) input).getTrace();
+ /* change the input to a FileEditorInput to allow open handlers to find this editor */
+ fileEditorInput = new FileEditorInput(fFile);
+ } else if (input instanceof IFileEditorInput) {
+ fileEditorInput = (IFileEditorInput) input;
+ fFile = fileEditorInput.getFile();
+ if (fFile == null) {
+ throw new PartInitException("Invalid IFileEditorInput: " + fileEditorInput); //$NON-NLS-1$
+ }
+ try {
+ final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceTypeId == null) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ if (traceTypeId.equals(TmfExperiment.class.getCanonicalName())) {
+ // Special case: experiment bookmark resource
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ if (project == null) {
+ throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);
+ }
+ for (final ITmfProjectModelElement projectElement : project.getExperimentsFolder().getChildren()) {
+ final String traceName = fFile.getParent().getName();
+ if (projectElement.getName().equals(traceName)) {
+ final TmfExperimentElement experimentElement = (TmfExperimentElement) projectElement;
+ // Instantiate the experiment's traces
+ final List<TmfTraceElement> traceEntries = experimentElement.getTraces();
+ final int nbTraces = traceEntries.size();
+ int cacheSize = Integer.MAX_VALUE;
+ final ITmfTrace[] traces = new ITmfTrace[nbTraces];
+ for (int i = 0; i < nbTraces; i++) {
+ final TmfTraceElement traceElement = traceEntries.get(i).getElementUnderTraceFolder();
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ for (int j = 0; j < i; j++) {
+ traces[j].dispose();
+ }
+ throw new PartInitException(Messages.OpenExperimentHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ throw new PartInitException(Messages.OpenTraceHandler_InitError, e);
+ }
+ cacheSize = Math.min(cacheSize, trace.getCacheSize());
+ traces[i] = trace;
+ }
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource());
+ experiment.setBookmarksFile(fFile);
+ fTrace = experiment;
+ break;
+ }
+ }
+ } else if (traceTypeId.equals(TmfTrace.class.getCanonicalName())) {
+ // Special case: trace bookmark resource
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ final String traceName = fFile.getParent().getName();
+ if (projectElement.getName().equals(traceName)) {
+ final TmfTraceElement traceElement = (TmfTraceElement) projectElement;
+ // Instantiate the trace
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ throw new PartInitException(Messages.OpenTraceHandler_InitError, e);
+ }
+ fTrace = trace;
+ break;
+ }
+ }
+ } else {
+ final TmfNavigatorContentProvider ncp = new TmfNavigatorContentProvider();
+ ncp.getChildren(fFile.getProject()); // force the model to be populated
+ final TmfProjectElement project = TmfProjectRegistry.getProject(fFile.getProject());
+ for (final ITmfProjectModelElement projectElement : project.getTracesFolder().getChildren()) {
+ if (projectElement.getResource().equals(fFile)) {
+ final TmfTraceElement traceElement = (TmfTraceElement) projectElement;
+ // Instantiate the trace
+ final ITmfTrace trace = traceElement.instantiateTrace();
+ final ITmfEvent traceEvent = traceElement.instantiateEvent();
+ if ((trace == null) || (traceEvent == null)) {
+ throw new PartInitException(Messages.OpenTraceHandler_NoTraceType);
+ }
+ try {
+ trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
+ } catch (final TmfTraceException e) {
+ throw new PartInitException(Messages.OpenTraceHandler_InitError, e);
+ }
+ fTrace = trace;
+ break;
+ }
+ }
+ }
+ } catch (final PartInitException e) {
+ throw e;
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error initializing TmfEventsEditor", e); //$NON-NLS-1$
+ }
+ } else {
+ throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$
+ }
+ if (fTrace == null) {
+ throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$
+ }
+ super.setSite(site);
+ super.setInput(fileEditorInput);
+ }
+
+ @Override
+ public boolean isDirty() {
+ return false;
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ @Override
+ public void setInput(final IEditorInput input) {
+ super.setInput(input);
+ firePropertyChange(IEditorPart.PROP_INPUT);
+ }
+
+ @Override
+ public void propertyChanged(final Object source, final int propId) {
+ if (propId == IEditorPart.PROP_INPUT && getEditorInput() instanceof TmfEditorInput) {
+ broadcast(new TmfTraceClosedSignal(this, fTrace));
+ fFile = ((TmfEditorInput) getEditorInput()).getFile();
+ fTrace = ((TmfEditorInput) getEditorInput()).getTrace();
+ /* change the input to a FileEditorInput to allow open handlers to find this editor */
+ super.setInput(new FileEditorInput(fFile));
+ fEventsTable.dispose();
+ if (fTrace != null) {
+ fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());
+ fEventsTable.addSelectionChangedListener(this);
+ fEventsTable.setTrace(fTrace, true);
+ fEventsTable.refreshBookmarks(fFile);
+
+ /* ensure start time is set */
+ final ITmfContext context = fTrace.seekEvent(0);
+ fTrace.getNext(context);
+ context.dispose();
+
+ broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile));
+ } else {
+ fEventsTable = new TmfEventsTable(fParent, 0);
+ fEventsTable.addSelectionChangedListener(this);
+ }
+ fParent.layout();
+ }
+ }
+
+ @Override
+ public void createPartControl(final Composite parent) {
+ fParent = parent;
+ if (fTrace != null) {
+ setPartName(fTrace.getName());
+ fEventsTable = createEventsTable(parent, fTrace.getCacheSize());
+ fEventsTable.addSelectionChangedListener(this);
+ fEventsTable.setTrace(fTrace, true);
+ fEventsTable.refreshBookmarks(fFile);
+
+ /* ensure start time is set */
+ final ITmfContext context = fTrace.seekEvent(0);
+ fTrace.getNext(context);
+ context.dispose();
+
+ broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile));
+ } else {
+ setPartName(getEditorInput().getName());
+ fEventsTable = new TmfEventsTable(parent, 0);
+ fEventsTable.addSelectionChangedListener(this);
+ }
+ addPropertyListener(this);
+ ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
+ // we need to wrap the ISelectionProvider interface in the editor because
+ // the events table can be replaced later while the selection changed listener
+ // is only added once by the platform to the selection provider set here
+ getSite().setSelectionProvider(this);
+ getSite().getPage().addPartListener(this);
+ }
+
+ @Override
+ public void dispose() {
+ if (getSite() != null) {
+ getSite().getPage().removePartListener(this);
+ }
+ ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
+ removePropertyListener(this);
+ if (fTrace != null) {
+ broadcast(new TmfTraceClosedSignal(this, fTrace));
+ }
+ if (fEventsTable != null) {
+ fEventsTable.dispose();
+ }
+ super.dispose();
+ }
+
+ /**
+ * Create the events table
+ *
+ * @param parent the parent composite
+ * @param cacheSize the cache size
+ * @return an events table instance
+ */
+ protected TmfEventsTable createEventsTable(final Composite parent, final int cacheSize) {
+ TmfEventsTable eventsTable = getEventsTable(parent, cacheSize);
+ if (eventsTable == null) {
+ eventsTable = new TmfEventsTable(parent, cacheSize);
+ }
+ return eventsTable;
+ }
+
+ private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) {
+ if (fTrace instanceof TmfExperiment) {
+ return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize);
+ }
+ TmfEventsTable eventsTable = null;
+ try {
+ if (fTrace.getResource() == null) {
+ return null;
+ }
+ final String traceType = fTrace.getResource().getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if (traceType == null) {
+ return null;
+ }
+ if (traceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomTxtTrace) fTrace).getDefinition(), parent, cacheSize);
+ }
+ if (traceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomXmlTrace) fTrace).getDefinition(), parent, cacheSize);
+ }
+ for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(traceType)) {
+ final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);
+ if (eventsTableTypeCE.length != 1) {
+ break;
+ }
+ final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
+ if ((eventsTableType == null) || (eventsTableType.length() == 0)) {
+ break;
+ }
+ final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
+ final Class<?> c = bundle.loadClass(eventsTableType);
+ final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };
+ final Constructor<?> constructor = c.getConstructor(constructorArgs);
+ final Object[] args = new Object[] { parent, cacheSize };
+ eventsTable = (TmfEventsTable) constructor.newInstance(args);
+ break;
+ }
+ }
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final ClassNotFoundException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final SecurityException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final NoSuchMethodException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final IllegalArgumentException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final InstantiationException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final IllegalAccessException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ } catch (final InvocationTargetException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable", e); //$NON-NLS-1$
+ }
+ return eventsTable;
+ }
+
+ /**
+ * Get the events table for an experiment. If all traces in the experiment
+ * are of the same type, use the extension point specified event table
+ *
+ * @param experiment
+ * the experiment
+ * @param parent
+ * the parent Composite
+ * @param cacheSize
+ * the event table cache size
+ * @return an events table of the appropriate type
+ */
+ private static TmfEventsTable getExperimentEventsTable(
+ final TmfExperiment experiment, final Composite parent,
+ final int cacheSize) {
+ TmfEventsTable eventsTable = null;
+ String commonTraceType = null;
+ try {
+ for (final ITmfTrace trace : experiment.getTraces()) {
+ final IResource resource = trace.getResource();
+ if (resource == null) {
+ return null;
+ }
+ final String traceType = resource.getPersistentProperty(TmfCommonConstants.TRACETYPE);
+ if ((commonTraceType != null) && !commonTraceType.equals(traceType)) {
+ return null;
+ }
+ commonTraceType = traceType;
+ }
+ if (commonTraceType == null) {
+ return null;
+ }
+ if (commonTraceType.startsWith(CustomTxtTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomTxtTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);
+ }
+ if (commonTraceType.startsWith(CustomXmlTrace.class.getCanonicalName())) {
+ return new CustomEventsTable(((CustomXmlTrace) experiment.getTraces()[0]).getDefinition(), parent, cacheSize);
+ }
+ for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
+ if (ce.getAttribute(TmfTraceType.ID_ATTR).equals(commonTraceType)) {
+ final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceType.EVENTS_TABLE_TYPE_ELEM);
+ if (eventsTableTypeCE.length != 1) {
+ break;
+ }
+ final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceType.CLASS_ATTR);
+ if ((eventsTableType == null) || (eventsTableType.length() == 0)) {
+ break;
+ }
+ final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
+ final Class<?> c = bundle.loadClass(eventsTableType);
+ final Class<?>[] constructorArgs = new Class[] { Composite.class, int.class };
+ final Constructor<?> constructor = c.getConstructor(constructorArgs);
+ final Object[] args = new Object[] { parent, cacheSize };
+ eventsTable = (TmfEventsTable) constructor.newInstance(args);
+ break;
+ }
+ }
+ } catch (final CoreException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InvalidRegistryObjectException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final SecurityException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final IllegalArgumentException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final ClassNotFoundException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final NoSuchMethodException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InstantiationException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final IllegalAccessException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ } catch (final InvocationTargetException e) {
+ Activator.getDefault().logError("Error getting TmfEventsTable for experiment", e); //$NON-NLS-1$
+ }
+ return eventsTable;
+ }
+
+ @Override
+ public ITmfTrace getTrace() {
+ return fTrace;
+ }
+
+ @Override
+ public IFile getBookmarksFile() {
+ return fFile;
+ }
+
+ @Override
+ public void setFocus() {
+ fEventsTable.setFocus();
+ }
+
+ @Override
+ public Object getAdapter(final Class adapter) {
+ if (IGotoMarker.class.equals(adapter)) {
+ return fEventsTable;
+ } else if (IPropertySheetPage.class.equals(adapter)) {
+ return new UnsortedPropertySheetPage();
+ }
+ return super.getAdapter(adapter);
+ }
+
+ @Override
+ public void resourceChanged(final IResourceChangeEvent event) {
+ for (final IMarkerDelta delta : event.findMarkerDeltas(IMarker.BOOKMARK, false)) {
+ if (delta.getResource().equals(fFile)) {
+ if (delta.getKind() == IResourceDelta.REMOVED) {
+ final IMarker bookmark = delta.getMarker();
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ fEventsTable.removeBookmark(bookmark);
+ }
+ });
+ } else if (delta.getKind() == IResourceDelta.CHANGED) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ fEventsTable.getTable().refresh();
+ }
+ });
+ }
+ }
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // ISelectionProvider
+ // ------------------------------------------------------------------------
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void addSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionChangedListeners.add(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public ISelection getSelection() {
+ if (fEventsTable == null) {
+ return StructuredSelection.EMPTY;
+ }
+ return fEventsTable.getSelection();
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void removeSelectionChangedListener(ISelectionChangedListener listener) {
+ fSelectionChangedListeners.remove(listener);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void setSelection(ISelection selection) {
+ // not implemented
+ }
+
+ /**
+ * Notifies any selection changed listeners that the viewer's selection has changed.
+ * Only listeners registered at the time this method is called are notified.
+ *
+ * @param event a selection changed event
+ *
+ * @see ISelectionChangedListener#selectionChanged
+ * @since 2.0
+ */
+ protected void fireSelectionChanged(final SelectionChangedEvent event) {
+ Object[] listeners = fSelectionChangedListeners.getListeners();
+ for (int i = 0; i < listeners.length; ++i) {
+ final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
+ SafeRunnable.run(new SafeRunnable() {
+ @Override
+ public void run() {
+ l.selectionChanged(event);
+ }
+ });
+ }
+ }
+
+ // ------------------------------------------------------------------------
+ // ISelectionChangedListener
+ // ------------------------------------------------------------------------
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void selectionChanged(SelectionChangedEvent event) {
+ fireSelectionChanged(event);
+ }
+
+ // ------------------------------------------------------------------------
+ // IPartListener
+ // ------------------------------------------------------------------------
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void partActivated(IWorkbenchPart part) {
+ if (part == this && fTrace != null) {
+ if (fTraceSelected) {
+ return;
+ }
+ fTraceSelected = true;
+ broadcast(new TmfTraceSelectedSignal(this, fTrace));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void partBroughtToTop(IWorkbenchPart part) {
+ if (part == this && fTrace != null) {
+ if (fTraceSelected) {
+ return;
+ }
+ fTraceSelected = true;
+ broadcast(new TmfTraceSelectedSignal(this, fTrace));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void partClosed(IWorkbenchPart part) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
+ */
+ /**
+ * @since 2.0
+ */
+ @Override
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ // ------------------------------------------------------------------------
+ // Global commands
+ // ------------------------------------------------------------------------
+
+ /**
+ * Add a bookmark
+ */
+ public void addBookmark() {
+ fEventsTable.addBookmark(fFile);
+ }
+
+
+ // ------------------------------------------------------------------------
+ // Signal handlers
+ // ------------------------------------------------------------------------
+
+ /**
+ * Handler for the Trace Selected signal
+ *
+ * @param signal The incoming signal
+ */
+ @TmfSignalHandler
+ public void traceSelected(final TmfTraceSelectedSignal signal) {
+ if ((signal.getSource() != this)) {
+ if (signal.getTrace().equals(fTrace)) {
+ getSite().getPage().bringToTop(this);
+ } else {
+ fTraceSelected = false;
+ }
+ }
+ }
+
+ /**
+ * Update the display to use the updated timestamp format
+ *
+ * @param signal the incoming signal
+ * @since 2.0
+ */
+ @TmfSignalHandler
+ public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
+ fEventsTable.refresh();
+ }
+
+}