Search in sources :

Example 1 with TraceElementType

use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType in project tracecompass by tracecompass.

the class TmfTraceTypeUIUtils method getEventTable.

/**
 * Get the Event Table type specified by the trace type's extension point,
 * if there is one.
 *
 * @param trace
 *            The trace for which we want the events table.
 * @param parent
 *            The parent composite that the event table will have
 * @param cacheSize
 *            The cache size to use with this event table. Should be defined
 *            by the trace type.
 * @return The corresponding Event Table, or 'null' if this trace type did
 *         not specify any.
 */
@Nullable
public static TmfEventsTable getEventTable(ITmfTrace trace, Composite parent, int cacheSize) {
    final String traceType = getTraceType(trace);
    if (traceType == null) {
        return null;
    }
    TraceElementType elType = (trace instanceof TmfExperiment) ? TraceElementType.EXPERIMENT : TraceElementType.TRACE;
    for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements(elType)) {
        if (ce.getAttribute(TmfTraceTypeUIUtils.TRACETYPE_ATTR).equals(traceType)) {
            final IConfigurationElement[] eventsTableTypeCE = ce.getChildren(TmfTraceTypeUIUtils.EVENTS_TABLE_TYPE_ELEM);
            if (eventsTableTypeCE.length != 1) {
                break;
            }
            final String eventsTableType = eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.CLASS_ATTR);
            final boolean useTraceAspects = Boolean.parseBoolean(eventsTableTypeCE[0].getAttribute(TmfTraceTypeUIUtils.USE_TRACE_ASPECTS_ATTR));
            if ((eventsTableType == null) || eventsTableType.isEmpty()) {
                break;
            }
            try {
                final Bundle bundle = Platform.getBundle(ce.getContributor().getName());
                final Class<?> c = bundle.loadClass(eventsTableType);
                Class<?>[] constructorArgs = null;
                Object[] args = null;
                if (useTraceAspects) {
                    args = new Object[] { parent, cacheSize, trace.getEventAspects() };
                    constructorArgs = new Class[] { Composite.class, int.class, Iterable.class };
                } else {
                    args = new Object[] { parent, cacheSize };
                    constructorArgs = new Class[] { Composite.class, int.class };
                }
                final Constructor<?> constructor = c.getConstructor(constructorArgs);
                return (TmfEventsTable) constructor.newInstance(args);
            } catch (NoSuchMethodException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
                return null;
            }
        }
    }
    return null;
}
Also used : TraceElementType(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType) Bundle(org.osgi.framework.Bundle) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) InvocationTargetException(java.lang.reflect.InvocationTargetException) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) TmfEventsTable(org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 2 with TraceElementType

use of org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType in project tracecompass by tracecompass.

the class TmfTraceTypeUIUtils method getPerspectiveId.

/**
 * Get the perspective id specified by the trace type's extension point, if
 * there is one.
 *
 * @param trace
 *            The trace for which we want the perspective id.
 * @return The corresponding perspective id, or 'null' if this trace type
 *         did not specify any.
 * @since 2.3
 */
@Nullable
public static String getPerspectiveId(ITmfTrace trace) {
    final String traceType = getTraceType(trace);
    if (traceType == null) {
        return null;
    }
    TraceElementType elType = (trace instanceof TmfExperiment) ? TraceElementType.EXPERIMENT : TraceElementType.TRACE;
    for (final IConfigurationElement ce : TmfTraceTypeUIUtils.getTypeUIElements(elType)) {
        if (ce.getAttribute(TRACETYPE_ATTR).equals(traceType)) {
            final IConfigurationElement[] perspectiveCE = ce.getChildren(PERSPECTIVE_ELEM);
            if (perspectiveCE.length != 1) {
                break;
            }
            final String perspectiveId = perspectiveCE[0].getAttribute(ID_ATTR);
            if (!perspectiveId.isEmpty()) {
                return perspectiveId;
            }
            break;
        }
    }
    return null;
}
Also used : TraceElementType(org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType) TmfExperiment(org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 Nullable (org.eclipse.jdt.annotation.Nullable)2 TraceElementType (org.eclipse.tracecompass.tmf.core.project.model.TmfTraceType.TraceElementType)2 TmfExperiment (org.eclipse.tracecompass.tmf.core.trace.experiment.TmfExperiment)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 TmfEventsTable (org.eclipse.tracecompass.tmf.ui.viewers.events.TmfEventsTable)1 Bundle (org.osgi.framework.Bundle)1