Fix IllegalArgumentException in Colors view
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.core / src / org / eclipse / linuxtools / tmf / core / event / TmfEventPropertySource.java
index a22e0e0fda7de5c9c0247cdfe589b9a93eba7c35..539d10d8360e0ef49459ad2f580b17df91b75cac 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012 Ericsson
+ * Copyright (c) 2012, 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
@@ -8,6 +8,7 @@
  *
  * Contributors:
  *   Patrick Tasse - Initial API and implementation
+ *   Bernd Hufmann - Added call site and model URI properties
  *******************************************************************************/
 
 package org.eclipse.linuxtools.tmf.core.event;
@@ -15,10 +16,12 @@ package org.eclipse.linuxtools.tmf.core.event;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfModelLookup;
+import org.eclipse.linuxtools.tmf.core.event.lookup.ITmfSourceLookup;
 import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp;
+import org.eclipse.linuxtools.tmf.core.util.ReadOnlyTextPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertyDescriptor;
 import org.eclipse.ui.views.properties.IPropertySource;
-import org.eclipse.ui.views.properties.PropertyDescriptor;
 
 /**
  * Property source for events
@@ -32,11 +35,20 @@ public class TmfEventPropertySource implements IPropertySource {
     private static final String ID_TYPE = "event_type"; //$NON-NLS-1$
     private static final String ID_REFERENCE = "event_reference"; //$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_SOURCE = "Source"; //$NON-NLS-1$
     private static final String NAME_TYPE = "Type"; //$NON-NLS-1$
     private static final String NAME_REFERENCE = "Reference"; //$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$
+    private static final String NAME_CUSTOM_ATTRIBUTES = "Custom Attributes"; //$NON-NLS-1$
+
+    private static final String EMPTY_STRING = ""; //$NON-NLS-1$
 
     private ITmfEvent fEvent;
 
@@ -62,9 +74,9 @@ public class TmfEventPropertySource implements IPropertySource {
         @Override
         public IPropertyDescriptor[] getPropertyDescriptors() {
             IPropertyDescriptor[] descriptors = new IPropertyDescriptor[3];
-            descriptors[0] = new PropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE);
-            descriptors[1] = new PropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE);
-            descriptors[2] = new PropertyDescriptor(ID_TIMESTAMP_PRECISION, NAME_TIMESTAMP_PRECISION);
+            descriptors[0] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_VALUE, NAME_TIMESTAMP_VALUE);
+            descriptors[1] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_SCALE, NAME_TIMESTAMP_SCALE);
+            descriptors[2] = new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP_PRECISION, NAME_TIMESTAMP_PRECISION);
             return descriptors;
         }
 
@@ -111,7 +123,7 @@ public class TmfEventPropertySource implements IPropertySource {
             List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>(fContent.getFields().length);
             for (ITmfEventField field : fContent.getFields()) {
                 if (field != null) {
-                    descriptors.add(new PropertyDescriptor(field, field.getName()));
+                    descriptors.add(new ReadOnlyTextPropertyDescriptor(field, field.getName()));
                 }
             }
             return descriptors.toArray(new IPropertyDescriptor[0]);
@@ -123,7 +135,115 @@ public class TmfEventPropertySource implements IPropertySource {
             if (field.getFields() != null && field.getFields().length > 0) {
                 return new ContentPropertySource(field);
             }
-            return field.getValue();
+            return field.getFormattedValue();
+        }
+
+        @Override
+        public boolean isPropertySet(Object id) {
+            return false;
+        }
+
+        @Override
+        public void resetPropertyValue(Object id) {
+        }
+
+        @Override
+        public void setPropertyValue(Object id, Object value) {
+        }
+    }
+
+    private class SourceLookupPropertySource implements IPropertySource {
+
+        private static final String ID_FILE_NAME = "callsite_file"; //$NON-NLS-1$
+        private static final String ID_FUNCTION_NAME = "callsite_function"; //$NON-NLS-1$
+        private static final String ID_LINE_NUMBER = "callsite_line"; //$NON-NLS-1$
+
+        private static final String NAME_FILE_NAME = "File"; //$NON-NLS-1$
+        private static final String NAME_FUNCTION_NAME = "Function"; //$NON-NLS-1$
+        private static final String NAME_LINE_NUMBER = "Line"; //$NON-NLS-1$
+
+        final private ITmfSourceLookup fSourceLookup;
+
+        public SourceLookupPropertySource(ITmfSourceLookup lookup) {
+            fSourceLookup = lookup;
+        }
+
+        @Override
+        public Object getEditableValue() {
+            if (fSourceLookup.getCallsite() != null) {
+                return fSourceLookup.getCallsite().toString();
+            }
+            return null;
+        }
+
+        @Override
+        public IPropertyDescriptor[] getPropertyDescriptors() {
+            List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>();
+            if (fSourceLookup.getCallsite() != null) {
+                descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FILE_NAME, NAME_FILE_NAME));
+                descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_LINE_NUMBER, NAME_LINE_NUMBER));
+                // only display function if available
+                if (fSourceLookup.getCallsite().getFunctionName() != null) {
+                    descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_FUNCTION_NAME, NAME_FUNCTION_NAME));
+                }
+            }
+            return descriptors.toArray(new IPropertyDescriptor[0]);
+        }
+
+        @Override
+        public Object getPropertyValue(Object id) {
+            if  (id.equals(ID_FILE_NAME)) {
+                return fSourceLookup.getCallsite().getFileName();
+            } else if (id.equals(ID_FUNCTION_NAME)) {
+                return fSourceLookup.getCallsite().getFunctionName();
+            } else if (id.equals(ID_LINE_NUMBER)) {
+                return Long.valueOf(fSourceLookup.getCallsite().getLineNumber());
+            }
+            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 class CustomAttributePropertySource implements IPropertySource {
+
+        private final ITmfCustomAttributes event;
+
+        public CustomAttributePropertySource(ITmfCustomAttributes event) {
+            this.event = event;
+        }
+
+        @Override
+        public Object getEditableValue() {
+            return EMPTY_STRING;
+        }
+
+        @Override
+        public IPropertyDescriptor[] getPropertyDescriptors() {
+            List<IPropertyDescriptor> descriptors = new ArrayList<IPropertyDescriptor>();
+
+            for (String customAttribute : event.listCustomAttributes()) {
+                descriptors.add(new ReadOnlyTextPropertyDescriptor(customAttribute, customAttribute));
+            }
+
+            return descriptors.toArray(new IPropertyDescriptor[0]);
+        }
+
+        @Override
+        public Object getPropertyValue(Object id) {
+            return event.getCustomAttribute((String) id);
         }
 
         @Override
@@ -157,13 +277,36 @@ public class TmfEventPropertySource implements IPropertySource {
 
     @Override
     public IPropertyDescriptor[] getPropertyDescriptors() {
-        IPropertyDescriptor[] descriptors = new IPropertyDescriptor[5];
-        descriptors[0] = new PropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP);
-        descriptors[1] = new PropertyDescriptor(ID_SOURCE, NAME_SOURCE);
-        descriptors[2] = new PropertyDescriptor(ID_TYPE, NAME_TYPE);
-        descriptors[3] = new PropertyDescriptor(ID_REFERENCE, NAME_REFERENCE);
-        descriptors[4] = new PropertyDescriptor(ID_CONTENT, NAME_CONTENT);
-        return descriptors;
+        List<IPropertyDescriptor> descriptors= new ArrayList<IPropertyDescriptor>();
+
+        /* Display basic event information */
+        descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TIMESTAMP, NAME_TIMESTAMP));
+        descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE, NAME_SOURCE));
+        descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_TYPE, NAME_TYPE));
+        descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_REFERENCE, NAME_REFERENCE));
+
+        /* Display event fields */
+        descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CONTENT, NAME_CONTENT));
+
+        /* Display source lookup information, if the event supplies it */
+        if ((fEvent instanceof ITmfSourceLookup) && (((ITmfSourceLookup)fEvent).getCallsite() != null)) {
+            descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_SOURCE_LOOKUP, NAME_SOURCE_LOOKUP));
+        }
+
+        /* Display Model URI information, if the event supplies it */
+        if ((fEvent instanceof ITmfModelLookup) && (((ITmfModelLookup) fEvent).getModelUri() != null)) {
+            descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_MODEL_URI, NAME_MODEL_URI));
+        }
+
+        /* Display custom attributes, if available */
+        if (fEvent instanceof ITmfCustomAttributes) {
+            ITmfCustomAttributes event = (ITmfCustomAttributes) fEvent;
+            if (event.listCustomAttributes() != null && !event.listCustomAttributes().isEmpty()) {
+                descriptors.add(new ReadOnlyTextPropertyDescriptor(ID_CUSTOM_ATTRIBUTE, NAME_CUSTOM_ATTRIBUTES));
+            }
+        }
+
+        return descriptors.toArray(new IPropertyDescriptor[0]);
     }
 
     @Override
@@ -176,8 +319,14 @@ public class TmfEventPropertySource implements IPropertySource {
             return fEvent.getType().toString();
         } else if (id.equals(ID_REFERENCE) && fEvent.getReference() != null) {
             return fEvent.getReference().toString();
+        } else if (id.equals(ID_MODEL_URI)) {
+            return ((ITmfModelLookup)fEvent).getModelUri();
+        } else if (id.equals(ID_SOURCE_LOOKUP)) {
+            return new SourceLookupPropertySource(((ITmfSourceLookup)fEvent));
         } else if (id.equals(ID_CONTENT) && fEvent.getContent() != null) {
             return new ContentPropertySource(fEvent.getContent());
+        } else if (id.equals(ID_CUSTOM_ATTRIBUTE)) {
+            return new CustomAttributePropertySource((ITmfCustomAttributes) fEvent);
         }
         return null;
     }
This page took 0.026277 seconds and 5 git commands to generate.