/*******************************************************************************
- * 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.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.IPropertySheetEntry;
import org.eclipse.ui.views.properties.IPropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetPage;
-import org.eclipse.ui.views.properties.PropertySheetSorter;
import org.osgi.framework.Bundle;
/**
*
* @version 1.0
* @author Patrick Tasse
+ * @since 2.0
*/
-public class TmfEventsEditor extends TmfEditor implements ITmfTraceEditor, IReusableEditor, IPropertyListener, IResourceChangeListener, ISelectionProvider, ISelectionChangedListener {
+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 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);
int cacheSize = Integer.MAX_VALUE;
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.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);
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);
// 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) {
@Override
public void setFocus() {
fEventsTable.setFocus();
- if (fTrace != null) {
- broadcast(new TmfTraceSelectedSignal(this, fTrace));
- }
}
@Override
if (IGotoMarker.class.equals(adapter)) {
return fEventsTable;
} else if (IPropertySheetPage.class.equals(adapter)) {
- // Override for unsorted property sheet page
- return new PropertySheetPage() {
- @Override
- public void createControl(Composite parent) {
- super.createControl(parent);
- setSorter(new PropertySheetSorter() {
- @Override
- public void sort(IPropertySheetEntry[] entries) {
- }
- });
- }
- };
+ return new UnsortedPropertySheetPage();
}
return super.getAdapter(adapter);
}
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
*/
@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.addSelectionChangedListener(this);
- 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);
- fEventsTable.addSelectionChangedListener(this);
+ 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();
}
}