Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf / src / org / eclipse / linuxtools / tmf / event / TmfEventContent.java
index 662ad85fb894e8233e6270eed8bd92cd31a576c8..bd9f701e31c1b5cc3eebb7909f324f3dbac830df 100644 (file)
 
 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
     // ------------------------------------------------------------------------
@@ -99,12 +105,28 @@ public class TmfEventContent {
         * @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()
@@ -124,6 +146,13 @@ public class TmfEventContent {
     // 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. 
@@ -155,6 +184,7 @@ public class TmfEventContent {
     }
 
     @Override
+    @SuppressWarnings("nls")
        public String toString() {
        Object[] fields = getFields();
        StringBuilder result = new StringBuilder("[TmfEventContent(");
@@ -166,4 +196,18 @@ public class 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;
+       }
 }
This page took 0.027059 seconds and 5 git commands to generate.