/*******************************************************************************
- * Copyright (c) 2010 Ericsson
+ * 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
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.project.handlers.Messages;
import org.eclipse.linuxtools.tmf.core.TmfCommonConstants;
import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfEvent;
-import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;
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.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.signal.TmfTraceClosedSignal;
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceOpenedSignal;
-import org.eclipse.linuxtools.tmf.ui.signal.TmfTraceParserUpdatedSignal;
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.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;
/**
*
* @version 1.0
* @author Patrick Tasse
+ * @since 2.0
*/
-public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener {
+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;
- @SuppressWarnings("rawtypes")
private ITmfTrace fTrace;
private Composite fParent;
+ private ListenerList fSelectionChangedListeners = new ListenerList();
+ private boolean fTraceSelected;
@Override
public void doSave(final IProgressMonitor monitor) {
public void doSaveAs() {
}
- @SuppressWarnings({ "unchecked", "rawtypes" })
@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();
- input = new FileEditorInput(fFile);
+ /* change the input to a FileEditorInput to allow open handlers to find this editor */
+ fileEditorInput = new FileEditorInput(fFile);
} else if (input instanceof IFileEditorInput) {
- fFile = ((IFileEditorInput) input).getFile();
- if (fFile == null)
- {
- throw new PartInitException("Invalid IFileEditorInput: " + input); //$NON-NLS-1$
+ 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);
final List<TmfTraceElement> traceEntries = experimentElement.getTraces();
final int nbTraces = traceEntries.size();
int cacheSize = Integer.MAX_VALUE;
- final ITmfTrace<?>[] traces = new ITmfTrace[nbTraces];
+ final ITmfTrace[] traces = new ITmfTrace[nbTraces];
for (int i = 0; i < nbTraces; i++) {
- final TmfTraceElement traceElement = traceEntries.get(i);
+ final TmfTraceElement traceElement = traceEntries.get(i).getElementUnderTraceFolder();
final ITmfTrace trace = traceElement.instantiateTrace();
final ITmfEvent traceEvent = traceElement.instantiateEvent();
if ((trace == null) || (traceEvent == null)) {
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) {
- @Override
- public void initTrace(IResource resource, String path, Class type) {
- super.initTrace(resource, path, type);
- getIndexer().buildIndex(getNbEvents(), TmfTimeRange.ETERNITY, false);
- }
- };
+ final TmfExperiment experiment = new TmfExperiment(ITmfEvent.class, experimentElement.getName(), traces, cacheSize, experimentElement.getResource());
experiment.setBookmarksFile(fFile);
fTrace = experiment;
- experiment.initTrace(null, null, null);
break;
}
}
try {
trace.initTrace(traceElement.getResource(), traceElement.getLocation().getPath(), traceEvent.getClass());
} catch (final TmfTraceException e) {
+ throw new PartInitException(Messages.OpenTraceHandler_InitError, e);
}
fTrace = trace;
break;
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 {
+ } else {
throw new PartInitException("Invalid IEditorInput: " + input.getClass()); //$NON-NLS-1$
}
- if (fTrace == null)
- {
+ if (fTrace == null) {
throw new PartInitException("Invalid IEditorInput: " + fFile.getName()); //$NON-NLS-1$
}
super.setSite(site);
- super.setInput(input);
+ super.setInput(fileEditorInput);
}
@Override
@Override
public void propertyChanged(final Object source, final int propId) {
- if (propId == IEditorPart.PROP_INPUT) {
+ 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);
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+
+ /* 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();
}
if (fTrace != null) {
setPartName(fTrace.getName());
fEventsTable = createEventsTable(parent, fTrace.getCacheSize());
+ fEventsTable.addSelectionChangedListener(this);
fEventsTable.setTrace(fTrace, true);
fEventsTable.refreshBookmarks(fFile);
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+
+ /* 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) {
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) {
private TmfEventsTable getEventsTable(final Composite parent, final int cacheSize) {
if (fTrace instanceof TmfExperiment) {
- return getExperimentEventsTable((TmfExperiment<?>) fTrace, parent, cacheSize);
+ return getExperimentEventsTable((TmfExperiment) fTrace, parent, cacheSize);
}
TmfEventsTable eventsTable = null;
try {
* @return an events table of the appropriate type
*/
private static TmfEventsTable getExperimentEventsTable(
- final TmfExperiment<?> experiment, final Composite parent,
+ final TmfExperiment experiment, final Composite parent,
final int cacheSize) {
TmfEventsTable eventsTable = null;
String commonTraceType = null;
try {
- for (final ITmfTrace<?> trace : experiment.getTraces()) {
+ for (final ITmfTrace trace : experiment.getTraces()) {
final IResource resource = trace.getResource();
if (resource == null) {
return null;
}
@Override
- public ITmfTrace<?> getTrace() {
+ public ITmfTrace getTrace() {
return fTrace;
}
@Override
public void setFocus() {
fEventsTable.setFocus();
- if (fTrace != null) {
- broadcast(new TmfTraceSelectedSignal(this, fTrace));
- }
}
@Override
- @SuppressWarnings("rawtypes")
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);
}
}
}
+ // ------------------------------------------------------------------------
+ // 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
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
/**
- * Handler for the Trace Parser Updated signal
+ * Handler for the Trace Selected signal
*
* @param signal The incoming signal
*/
- @SuppressWarnings("unchecked")
@TmfSignalHandler
- public void traceParserUpdated(final TmfTraceParserUpdatedSignal signal) {
- if (signal.getTraceResource().equals(fFile)) {
- broadcast(new TmfTraceClosedSignal(this, fTrace));
- try {
- fTrace.getName();
- fTrace = null;
- final String traceTypeId = fFile.getPersistentProperty(TmfCommonConstants.TRACETYPE);
- if (traceTypeId != null) {
- for (final IConfigurationElement ce : TmfTraceType.getTypeElements()) {
- if (traceTypeId.equals(ce.getAttribute(TmfTraceType.ID_ATTR))) {
- fTrace = (ITmfTrace<?>) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
- final ITmfEvent event = (TmfEvent) ce.createExecutableExtension(TmfTraceType.EVENT_TYPE_ATTR);
- final String path = fFile.getLocationURI().getPath();
- fTrace.initTrace(null, path, event.getClass());
- break;
- }
- }
- }
- } catch (final InvalidRegistryObjectException e) {
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
- } catch (final TmfTraceException e) {
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
- } catch (final CoreException e) {
- Activator.getDefault().logError("Error handling signal TmfTraceParserUpdatedSignal", e); //$NON-NLS-1$
- }
- fEventsTable.dispose();
- if (fTrace != null) {
- fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());
- fEventsTable.setTrace(fTrace, true);
- broadcast(new TmfTraceOpenedSignal(this, fTrace, fFile, fEventsTable));
+ public void traceSelected(final TmfTraceSelectedSignal signal) {
+ if ((signal.getSource() != this)) {
+ if (signal.getTrace().equals(fTrace)) {
+ getSite().getPage().bringToTop(this);
} else {
- fEventsTable = new TmfEventsTable(fParent, 0);
+ fTraceSelected = false;
}
- fParent.layout();
}
}
/**
- * Handler for the Trace Selected signal
+ * Update the display to use the updated timestamp format
*
- * @param signal The incoming signal
+ * @param signal the incoming signal
+ * @since 2.0
*/
@TmfSignalHandler
- public void traceSelected(final TmfTraceSelectedSignal signal) {
- if ((signal.getSource() != this) && signal.getTrace().equals(fTrace)) {
- getSite().getPage().bringToTop(this);
- }
+ public void timestampFormatUpdated(TmfTimestampFormatUpdateSignal signal) {
+ fEventsTable.refresh();
}
}