package org.eclipse.linuxtools.tmf.event;
-
/**
* <b><u>TmfEventContent</u></b>
* <p>
* The event content.
*/
-public class TmfEventContent {
-
+public class TmfEventContent implements Cloneable {
+
+ // Default field ids
+ public static final String FIELD_ID_TIMESTAMP = ":timestamp:"; //$NON-NLS-1$
+ public static final String FIELD_ID_SOURCE = ":source:"; //$NON-NLS-1$
+ public static final String FIELD_ID_TYPE = ":type:"; //$NON-NLS-1$
+ public static final String FIELD_ID_REFERENCE = ":reference:"; //$NON-NLS-1$
+ public static final String FIELD_ID_CONTENT = ":content:"; //$NON-NLS-1$
+
// ------------------------------------------------------------------------
// Attributes
// ------------------------------------------------------------------------
* @return the corresponding field
* @throws TmfNoSuchFieldException
*/
- public Object getField(String id) throws TmfNoSuchFieldException {
- if (fFields == null) {
- parseContent();
- }
- return fFields[getType().getFieldIndex(id)];
- }
+ public Object getField(String id) throws TmfNoSuchFieldException {
+ if (fFields == null) {
+ parseContent();
+ }
+ try {
+ return fFields[getType().getFieldIndex(id)];
+ } catch (TmfNoSuchFieldException e) {
+ // Required for filtering from default TmfEventsTable columns
+ if (id.equals(FIELD_ID_CONTENT)) {
+ return fParentEvent.getContent().toString();
+ } else if (id.equals(FIELD_ID_TIMESTAMP)) {
+ return new Long(fParentEvent.getTimestamp().getValue()).toString();
+ } else if (id.equals(FIELD_ID_SOURCE)) {
+ return fParentEvent.getSource().getSourceId().toString();
+ } else if (id.equals(FIELD_ID_TYPE)) {
+ return fParentEvent.getType().getTypeId().toString();
+ } else if (id.equals(FIELD_ID_REFERENCE)) {
+ return fParentEvent.getReference().getReference().toString();
+ }
+ throw e;
+ }
+ }
/**
* @param n the field index as per TmfEventType.getLabels()
// Operators
// ------------------------------------------------------------------------
+ /**
+ * @param event
+ */
+ public void setEvent(TmfEvent event) {
+ fParentEvent = event;
+ }
+
/**
* Parse the content into fields. By default, a single field (the raw
* content) is returned.
}
@Override
+ @SuppressWarnings("nls")
public String toString() {
Object[] fields = getFields();
StringBuilder result = new StringBuilder("[TmfEventContent(");
return result.toString();
}
+ @Override
+ public TmfEventContent clone() {
+ TmfEventContent clone = null;
+ try {
+ clone = (TmfEventContent) super.clone();
+ clone.fParentEvent = fParentEvent;
+ clone.fRawContent = fRawContent;
+ clone.fFields = fFields;
+ }
+ catch (CloneNotSupportedException e) {
+ e.printStackTrace();
+ }
+ return clone;
+ }
}