From 459a073612709cd759444624e1d910abd12f2563 Mon Sep 17 00:00:00 2001 From: Alexandre Montplaisir Date: Sat, 9 Apr 2016 21:38:08 -0400 Subject: [PATCH] tmf: Update event properties to use aspects By using all defined aspects as property descriptors, we can do away with some of the hard-coded ones, like timestamp and even type. Event content could keep its own descriptor though, since it puts the event fields into a nice sub-tree. This also makes sure that any extra aspect defined by the trace type also shows up in the Properties View. Bug: 460635 Change-Id: Ibea43dd9c6491e660b9732f93419057b6ea721e6 Signed-off-by: Alexandre Montplaisir --- .../btf/ui/BtfEventPropertySource.java | 3 +- .../events/TmfEventPropertySource.java | 117 +++++++----------- 2 files changed, 46 insertions(+), 74 deletions(-) diff --git a/btf/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java b/btf/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java index d9abc0055f..8a5881bc73 100644 --- a/btf/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java +++ b/btf/org.eclipse.tracecompass.btf.ui/src/org/eclipse/tracecompass/btf/ui/BtfEventPropertySource.java @@ -15,6 +15,7 @@ package org.eclipse.tracecompass.btf.ui; import java.util.Arrays; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.tracecompass.btf.core.event.BTFPayload; import org.eclipse.tracecompass.btf.core.event.BtfEvent; import org.eclipse.tracecompass.btf.core.trace.BtfColumnNames; @@ -57,7 +58,7 @@ public class BtfEventPropertySource extends TmfEventPropertySource { * @param event * the event */ - public BtfEventPropertySource(BtfEvent event) { + public BtfEventPropertySource(@NonNull BtfEvent event) { super(event); fEvent = event; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventPropertySource.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventPropertySource.java index ef02db0252..4c88480976 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventPropertySource.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventPropertySource.java @@ -17,14 +17,19 @@ import static org.eclipse.tracecompass.common.core.NonNullUtils.nullToEmptyStrin import java.util.ArrayList; import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.tracecompass.common.core.StreamUtils; import org.eclipse.tracecompass.tmf.core.event.ITmfCustomAttributes; import org.eclipse.tracecompass.tmf.core.event.ITmfEvent; import org.eclipse.tracecompass.tmf.core.event.ITmfEventField; +import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect; +import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects; import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfCallsite; import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfModelLookup; import org.eclipse.tracecompass.tmf.core.event.lookup.ITmfSourceLookup; -import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.tracecompass.tmf.ui.properties.ReadOnlyTextPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertyDescriptor; import org.eclipse.ui.views.properties.IPropertySource; @@ -34,17 +39,11 @@ import org.eclipse.ui.views.properties.IPropertySource; */ public class TmfEventPropertySource implements IPropertySource { - private static final String ID_TIMESTAMP = "event_timestamp"; //$NON-NLS-1$ - private static final String ID_TYPE = "event_type"; //$NON-NLS-1$ - private static final String ID_TRACE = "trace_attribute"; //$NON-NLS-1$ private static final String ID_CONTENT = "event_content"; //$NON-NLS-1$ private static final String ID_SOURCE_LOOKUP = "event_lookup"; //$NON-NLS-1$ private static final String ID_MODEL_URI = "model_uri"; //$NON-NLS-1$ private static final String ID_CUSTOM_ATTRIBUTE = "custom_attribute"; //$NON-NLS-1$ - private static final String NAME_TIMESTAMP = "Timestamp"; //$NON-NLS-1$ - private static final String NAME_TYPE = "Type"; //$NON-NLS-1$ - private static final String NAME_TRACE = "Trace"; //$NON-NLS-1$ private static final String NAME_CONTENT = "Content"; //$NON-NLS-1$ private static final String NAME_SOURCE_LOOKUP = "Source Lookup"; //$NON-NLS-1$ private static final String NAME_MODEL_URI = "Model URI"; //$NON-NLS-1$ @@ -52,56 +51,7 @@ public class TmfEventPropertySource implements IPropertySource { private static final String EMPTY_STRING = ""; //$NON-NLS-1$ - private ITmfEvent fEvent; - - private static class TimestampPropertySource implements IPropertySource { - private static final String ID_TIMESTAMP_VALUE = "timestamp_value"; //$NON-NLS-1$ - private static final String ID_TIMESTAMP_SCALE = "timestamp_scale"; //$NON-NLS-1$ - private static final String NAME_TIMESTAMP_VALUE = "value"; //$NON-NLS-1$ - private static final String NAME_TIMESTAMP_SCALE = "scale"; //$NON-NLS-1$ - - private ITmfTimestamp fTimestamp; - - public TimestampPropertySource(ITmfTimestamp timestamp) { - fTimestamp = timestamp; - } - - @Override - public Object getEditableValue() { - return fTimestamp.toString(); - } - - @Override - public IPropertyDescriptor[] getPropertyDescriptors() { - IPropertyDescriptor[] descriptors = new IPropertyDescriptor[2]; - descriptors[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE); - descriptors[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE); - return descriptors; - } - - @Override - public Object getPropertyValue(Object id) { - if (id.equals(ID_TIMESTAMP_VALUE)) { - return Long.toString(fTimestamp.getValue()); - } else if (id.equals(ID_TIMESTAMP_SCALE)) { - return Integer.toString(fTimestamp.getScale()); - } - return null; - } - - @Override - public boolean isPropertySet(Object id) { - return false; - } - - @Override - public void resetPropertyValue(Object id) { - } - - @Override - public void setPropertyValue(Object id, Object value) { - } - } + private final @NonNull ITmfEvent fEvent; private static class ContentPropertySource implements IPropertySource { private ITmfEventField fContent; @@ -274,7 +224,7 @@ public class TmfEventPropertySource implements IPropertySource { * * @param event the event */ - public TmfEventPropertySource(ITmfEvent event) { + public TmfEventPropertySource(@NonNull ITmfEvent event) { super(); this.fEvent = event; } @@ -288,13 +238,19 @@ public class TmfEventPropertySource implements IPropertySource { public IPropertyDescriptor[] getPropertyDescriptors() { List descriptors= new ArrayList<>(); - /* Display basic event information */ - descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP)); - descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE)); - descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TRACE, NAME_TRACE)); - - /* Display event fields */ - descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT)); + /* Display properties for event aspects */ + getTraceAspects().forEach(aspect -> { + /* + * Contents has its special property source, which puts the fields + * in a sub-tree. + */ + if (aspect == TmfBaseAspects.getContentsAspect()) { + descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT)); + } else { + String name = aspect.getName(); + descriptors.add(new ReadOnlyTextPropertyDescriptor(name, name)); + } + }); /* Display source lookup information, if the event supplies it */ if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) { @@ -318,14 +274,14 @@ public class TmfEventPropertySource implements IPropertySource { } @Override - public Object getPropertyValue(Object id) { - if (id.equals(ID_TIMESTAMP)) { - return new TimestampPropertySource(fEvent.getTimestamp()); - } else if (id.equals(ID_TYPE) && fEvent.getType() != null) { - return fEvent.getType().toString(); - } else if (id.equals(ID_TRACE)) { - return fEvent.getTrace().getName(); - } else if (id.equals(ID_MODEL_URI)) { + public Object getPropertyValue(Object objectId) { + if (!(objectId instanceof String)) { + return null; + } + + String id = (String) objectId; + + if (id.equals(ID_MODEL_URI)) { return ((ITmfModelLookup)fEvent).getModelUri(); } else if (id.equals(ID_SOURCE_LOOKUP)) { return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent)); @@ -334,9 +290,24 @@ public class TmfEventPropertySource implements IPropertySource { } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) { return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent); } + + /* Look for the ID in the aspect names */ + Optional> potentialAspect = getTraceAspects() + .filter(aspect -> aspect.getName().equals(id)) + .findFirst(); + + if (potentialAspect.isPresent()) { + Object res = potentialAspect.get().resolve(fEvent); + return (res == null ? "" : res.toString()); //$NON-NLS-1$ + } + return null; } + private Stream> getTraceAspects() { + return StreamUtils.getStream(fEvent.getTrace().getEventAspects()); + } + @Override public boolean isPropertySet(Object id) { return false; -- 2.34.1