tmf: Add support for custom event type by text line or XML element
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 23 Jun 2016 22:32:55 +0000 (18:32 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 15 Jul 2016 20:20:56 +0000 (16:20 -0400)
The text line or XML element can have an associated event type that will
override the definition name as the default event type.

If a custom event field or attribute is defined to set the event type,
it will override that default.

Change-Id: I9e38a0cdb5dc1b4442ca8028bbbbee220dc6001c
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/75892
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtEvent.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomTxtTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlInputElement.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTrace.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomXmlTraceDefinition.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/Messages.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/messages.properties
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomTxtParserInputWizardPage.java
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/parsers/wizards/CustomXmlParserInputWizardPage.java

index 02f3954c3d78b132ffe814b88273c6a36b705e2a..d555f2028894a4d532a4a0f3258a18659d527aa3 100644 (file)
@@ -83,6 +83,9 @@ public class CustomTxtEvent extends CustomEvent {
      *            The regex matcher to use
      */
     public void processGroups(InputLine input, Matcher matcher) {
+        if (input.eventType != null) {
+            fData.put(CustomTraceDefinition.TAG_EVENT_TYPE, input.eventType);
+        }
         if (input.columns == null) {
             return;
         }
index 2de73280a88ea9618a503b777b9a35b37cd71bb3..f7e3df49fdd1d665ce04611310b591192eb77079 100644 (file)
@@ -107,6 +107,7 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
     private static final String MIN_ATTRIBUTE = Messages.CustomTxtTraceDefinition_min;
     private static final String MAX_ATTRIBUTE = Messages.CustomTxtTraceDefinition_max;
     private static final String REGEX_ELEMENT = Messages.CustomTxtTraceDefinition_regEx;
+    private static final String EVENT_TYPE_ELEMENT = Messages.CustomTxtTraceDefinition_eventType;
     private static final String INPUT_DATA_ELEMENT = Messages.CustomTxtTraceDefinition_inputData;
     private static final String ACTION_ATTRIBUTE = Messages.CustomTxtTraceDefinition_action;
     private static final String FORMAT_ATTRIBUTE = Messages.CustomTxtTraceDefinition_format;
@@ -165,6 +166,10 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
         /** Children of this line (if one "event" spans many lines) */
         public List<InputLine> childrenInputs;
 
+        /** Event type associated with this line
+         * @since 2.1*/
+        public String eventType;
+
         private String regex;
         private Pattern pattern;
 
@@ -563,6 +568,12 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
         inputLineElement.appendChild(regexElement);
         regexElement.appendChild(doc.createTextNode(inputLine.regex));
 
+        if (inputLine.eventType != null) {
+            Element eventTypeElement = doc.createElement(EVENT_TYPE_ELEMENT);
+            inputLineElement.appendChild(eventTypeElement);
+            eventTypeElement.appendChild(doc.createTextNode(inputLine.eventType));
+        }
+
         if (inputLine.columns != null) {
             for (InputData inputData : inputLine.columns) {
                 Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
@@ -826,6 +837,9 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             } else if (nodeName.equals(REGEX_ELEMENT)) {
                 Element regexElement = (Element) node;
                 inputLine.regex = regexElement.getTextContent();
+            } else if (nodeName.equals(EVENT_TYPE_ELEMENT)) {
+                Element eventTypeElement = (Element) node;
+                inputLine.eventType = eventTypeElement.getTextContent();
             } else if (nodeName.equals(INPUT_DATA_ELEMENT)) {
                 Element inputDataElement = (Element) node;
                 InputData inputData = new InputData();
index 79fbf333eabbefc0c00ba1c78cc4728ff8c5ca71..75d4b82c7d0135e7c1498310a9dc8e080e2a66fa 100644 (file)
@@ -48,6 +48,9 @@ public final class CustomXmlInputElement {
     /** Child elements */
     private List<CustomXmlInputElement> fChildElements;
 
+    /** Event type associated with this input element */
+    private String fEventType;
+
     /**
      * Default (empty) constructor
      */
@@ -205,6 +208,23 @@ public final class CustomXmlInputElement {
         fInputName = inputName;
     }
 
+    /**
+     * @return the eventType, or null
+     * @since 2.1
+     */
+    public String getEventType() {
+        return fEventType;
+    }
+
+    /**
+     * @param eventType
+     *            the eventType to set, or null
+     * @since 2.1
+     */
+    public void setEventType(String eventType) {
+        fEventType = eventType;
+    }
+
     /**
      * @return the inputAction
      */
index 1ac4a245cf898b0dffdc63bb8271f931b6ad83b8..cca70ea65a108efeda0f1560913eb071ee406e90 100644 (file)
@@ -517,6 +517,10 @@ public class CustomXmlTrace extends TmfTrace implements ITmfPersistentlyIndexabl
     }
 
     private void parseElement(final Element element, final CustomXmlEvent event, final CustomXmlInputElement inputElement) {
+        String eventType = inputElement.getEventType();
+        if (eventType != null && event.getType() instanceof CustomEventType) {
+            ((CustomEventType) event.getType()).setName(eventType);
+        }
         if (inputElement.getInputName() != null && !inputElement.getInputName().equals(CustomXmlTraceDefinition.TAG_IGNORE)) {
             event.parseInput(parseElement(element, new StringBuffer()).toString(), inputElement.getInputName(), inputElement.getInputAction(), inputElement.getInputFormat());
         }
index d95783237a1d47292522d6816116190df932b28e..2f3496f54a339dda55e5269d59a5947dec498db8 100644 (file)
@@ -106,6 +106,7 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
     private static final String CATEGORY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_category;
     private static final String NAME_ATTRIBUTE = Messages.CustomXmlTraceDefinition_name;
     private static final String LOG_ENTRY_ATTRIBUTE = Messages.CustomXmlTraceDefinition_logEntry;
+    private static final String EVENT_TYPE_ATTRIBUTE = Messages.CustomXmlTraceDefinition_eventType;
     private static final String TIME_STAMP_OUTPUT_FORMAT_ELEMENT = Messages.CustomXmlTraceDefinition_timestampOutputFormat;
     private static final String INPUT_ELEMENT_ELEMENT = Messages.CustomXmlTraceDefinition_inputElement;
     private static final String ATTRIBUTE_ELEMENT = Messages.CustomXmlTraceDefinition_attribute;
@@ -233,6 +234,10 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
             inputElementElement.setAttribute(LOG_ENTRY_ATTRIBUTE, Boolean.toString(inputElement.isLogEntry()));
         }
 
+        if (inputElement.getEventType() != null) {
+            inputElementElement.setAttribute(EVENT_TYPE_ATTRIBUTE, inputElement.getEventType());
+        }
+
         if (inputElement.getParentElement() != null) {
             Element inputDataElement = doc.createElement(INPUT_DATA_ELEMENT);
             inputElementElement.appendChild(inputDataElement);
@@ -532,6 +537,8 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
         CustomXmlInputElement inputElement = new CustomXmlInputElement();
         inputElement.setElementName(inputElementElement.getAttribute(NAME_ATTRIBUTE));
         inputElement.setLogEntry((Boolean.toString(true).equals(inputElementElement.getAttribute(LOG_ENTRY_ATTRIBUTE))) ? true : false);
+        String eventType = inputElementElement.getAttribute(EVENT_TYPE_ATTRIBUTE);
+        inputElement.setEventType(eventType.isEmpty() ? null : eventType);
         NodeList nodeList = inputElementElement.getChildNodes();
         for (int i = 0; i < nodeList.getLength(); i++) {
             Node node = nodeList.item(i);
index 282862bfe749c4c809d6de33c3a9c80154b0e70d..ec9b0a3face6c3f73648276cdbc312e4d6c4532b 100644 (file)
@@ -31,6 +31,8 @@ public class Messages extends NLS {
     public static String CustomTxtTraceDefinition_category;
     public static String CustomTxtTraceDefinition_definition;
     public static String CustomTxtTraceDefinition_definitionRootElement;
+    /** @since 2.1 */
+    public static String CustomTxtTraceDefinition_eventType;
     public static String CustomTxtTraceDefinition_format;
     public static String CustomTxtTraceDefinition_inputData;
     public static String CustomTxtTraceDefinition_inputLine;
@@ -45,6 +47,8 @@ public class Messages extends NLS {
     public static String CustomXmlTraceDefinition_category;
     public static String CustomXmlTraceDefinition_definition;
     public static String CustomXmlTraceDefinition_definitionRootElement;
+    /** @since 2.1 */
+    public static String CustomXmlTraceDefinition_eventType;
     public static String CustomXmlTraceDefinition_format;
     public static String CustomXmlTraceDefinition_ignoreTag;
     public static String CustomXmlTraceDefinition_inputData;
index 996150ebdb204998c247d62118a80f30d8df3070..ca8da7d6bd8a796b708be2341f16873b2a7efa60 100644 (file)
@@ -21,6 +21,7 @@ CustomTxtTraceDefinition_cardinality=Cardinality
 CustomTxtTraceDefinition_category=category
 CustomTxtTraceDefinition_definition=Definition
 CustomTxtTraceDefinition_definitionRootElement=CustomTxtTraceDefinitionList
+CustomTxtTraceDefinition_eventType=EventType
 CustomTxtTraceDefinition_format=format
 CustomTxtTraceDefinition_inputData=InputData
 CustomTxtTraceDefinition_inputLine=InputLine
@@ -35,6 +36,7 @@ CustomXmlTraceDefinition_attribute=Attribute
 CustomXmlTraceDefinition_category=category
 CustomXmlTraceDefinition_definition=Definition
 CustomXmlTraceDefinition_definitionRootElement=CustomXMLTraceDefinitionList
+CustomXmlTraceDefinition_eventType=eventtype
 CustomXmlTraceDefinition_format=format
 CustomXmlTraceDefinition_ignoreTag=Ignore
 CustomXmlTraceDefinition_inputData=InputData
index ee43e12fb21dd2cf98e9d5c09722af646beca0e4..7bae0aa043badab3987532ba564c0871bfcfcd88 100644 (file)
@@ -184,6 +184,7 @@ public class Messages extends NLS {
     public static String CustomTxtParserInputWizardPage_category;
     public static String CustomTxtParserInputWizardPage_desccriptionEdit;
     public static String CustomTxtParserInputWizardPage_descriptionNew;
+    public static String CustomTxtParserInputWizardPage_eventType;
     public static String CustomTxtParserInputWizardPage_format;
     public static String CustomTxtParserInputWizardPage_group;
     public static String CustomTxtParserInputWizardPage_highlightAll;
@@ -223,6 +224,7 @@ public class Messages extends NLS {
     public static String CustomTxtParserOutputWizardPage_moveBefore;
     public static String CustomTxtParserOutputWizardPage_visible;
     public static String CustomXmlParserInputWizardPage_emptyCategoryError;
+    public static String CustomXmlParserInputWizardPage_emptyEventTypeError;
     public static String CustomXmlParserInputWizardPage_emptyLogTypeError;
     public static String CustomXmlParserInputWizardPage_invalidCategoryError;
     public static String CustomXmlParserInputWizardPage_invalidLogTypeError;
index acd5432b20de8dc3ba5257d777ff4b4ece157062..1b784a930b8a11496e0492c5b250657d909ea8a6 100644 (file)
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2013, 2015 Ericsson
+# Copyright (c) 2013, 2016 Ericsson
 #
 # All rights reserved. This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License v1.0
@@ -184,6 +184,7 @@ CustomTxtParserInputWizardPage_cardinality=Cardinality:
 CustomTxtParserInputWizardPage_category=Category:
 CustomTxtParserInputWizardPage_desccriptionEdit=Edit an existing custom parser for text trace files
 CustomTxtParserInputWizardPage_descriptionNew=Create a new custom parser for text trace files
+CustomTxtParserInputWizardPage_eventType=Event type:
 CustomTxtParserInputWizardPage_format=format:
 CustomTxtParserInputWizardPage_group=Group {0}:
 CustomTxtParserInputWizardPage_highlightAll=Highlight All
@@ -223,6 +224,7 @@ CustomTxtParserOutputWizardPage_moveAfter=Move After
 CustomTxtParserOutputWizardPage_moveBefore=Move Before
 CustomTxtParserOutputWizardPage_visible=Visible
 CustomXmlParserInputWizardPage_emptyCategoryError=Enter a category for the new trace type.
+CustomXmlParserInputWizardPage_emptyEventTypeError=Enter the event type for the element (Element {0}).
 CustomXmlParserInputWizardPage_emptyLogTypeError=Enter a name for the new trace type.
 CustomXmlParserInputWizardPage_invalidCategoryError=Invalid character ':' in category.
 CustomXmlParserInputWizardPage_invalidLogTypeError=Invalid character ':' in trace type.
index 44b3b2914f5e012fd51392fe92b7ecea46e44cec..1d8284ceb82de91cbbdf0661211adfaebe31e5ba 100644 (file)
@@ -1051,6 +1051,8 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
         private Label cardinalityMaxLabel;
         private Text cardinalityMaxText;
         private Button infiniteButton;
+        private Button eventTypeButton;
+        private Text eventTypeText;
         private List<InputGroup> inputs = new ArrayList<>();
         private Button addGroupButton;
         private Label addGroupLabel;
@@ -1224,6 +1226,35 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             cardinalityMinText.addVerifyListener(digitsListener);
             cardinalityMaxText.addVerifyListener(digitsListener);
 
+            eventTypeButton = new Button(group, SWT.CHECK);
+            eventTypeButton.setText(Messages.CustomTxtParserInputWizardPage_eventType);
+            eventTypeButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+            eventTypeButton.addSelectionListener(new SelectionAdapter() {
+                @Override
+                public void widgetSelected(SelectionEvent e) {
+                    if (eventTypeButton.getSelection()) {
+                        eventTypeText.setEnabled(true);
+                    } else {
+                        eventTypeText.setEnabled(false);
+                    }
+                }
+            });
+            eventTypeButton.addSelectionListener(updateListener);
+
+            eventTypeText = new Text(group, SWT.BORDER | SWT.SINGLE);
+            gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+            gd.widthHint = 0;
+            eventTypeText.setLayoutData(gd);
+            if (inputLine.eventType != null) {
+                eventTypeText.setText(inputLine.eventType);
+                eventTypeButton.setSelection(true);
+            } else {
+                eventTypeText.setEnabled(false);
+                eventTypeButton.setSelection(false);
+            }
+            eventTypeText.addModifyListener(updateListener);
+
+
             if (inputLine.columns != null) {
                 for (InputData inputData : inputLine.columns) {
                     InputGroup inputGroup = new InputGroup(group, this, inputs.size() + 1);
@@ -1301,6 +1332,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
 
         private void extractInputs() {
             inputLine.setRegex(selectedLine.regexText.getText());
+            inputLine.eventType = selectedLine.eventTypeButton.getSelection() ? selectedLine.eventTypeText.getText().trim() : null;
             switch (cardinalityCombo.getSelectionIndex()) {
             case 0:
                 inputLine.cardinality = Cardinality.ZERO_OR_MORE;
@@ -1624,6 +1656,16 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                 line.cardinalityMaxText.setBackground(COLOR_TEXT_BACKGROUND);
             }
         }
+        if (inputLine.eventType != null && inputLine.eventType.trim().isEmpty()) {
+            errors.append("Enter the event type (Line " + name + "). "); //$NON-NLS-1$ //$NON-NLS-2$
+            if (line != null) {
+                line.eventTypeText.setBackground(COLOR_LIGHT_RED);
+            }
+        } else {
+            if (line != null) {
+                line.eventTypeText.setBackground(COLOR_TEXT_BACKGROUND);
+            }
+        }
         for (int i = 0; inputLine.columns != null && i < inputLine.columns.size(); i++) {
             InputData inputData = inputLine.columns.get(i);
             InputGroup group = null;
index bd6ff9c02d8eeeab5f751af4ba70b398df932f7b..d430d865f8364fdb07c588f31797af5820700db8 100644 (file)
@@ -872,6 +872,8 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
         private Label previewLabel;
         private Text previewText;
         private Button logEntryButton;
+        private Button eventTypeButton;
+        private Text eventTypeText;
         private Label fillerLabel;
         private Composite addAttributeComposite;
         private Button addAttributeButton;
@@ -1032,6 +1034,34 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                     tagText.setText(inputElement.getInputName());
                     tagText.addModifyListener(updateListener);
                 }
+
+                eventTypeButton = new Button(group, SWT.CHECK);
+                eventTypeButton.setText(Messages.CustomTxtParserInputWizardPage_eventType);
+                eventTypeButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
+                eventTypeButton.addSelectionListener(new SelectionAdapter() {
+                    @Override
+                    public void widgetSelected(SelectionEvent e) {
+                        if (eventTypeButton.getSelection()) {
+                            eventTypeText.setEnabled(true);
+                        } else {
+                            eventTypeText.setEnabled(false);
+                        }
+                    }
+                });
+                eventTypeButton.addSelectionListener(updateListener);
+
+                eventTypeText = new Text(group, SWT.BORDER | SWT.SINGLE);
+                gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
+                gd.widthHint = 0;
+                eventTypeText.setLayoutData(gd);
+                if (inputElement.getEventType() != null) {
+                    eventTypeText.setText(inputElement.getEventType());
+                    eventTypeButton.setSelection(true);
+                } else {
+                    eventTypeText.setEnabled(false);
+                    eventTypeButton.setSelection(false);
+                }
+                eventTypeText.addModifyListener(updateListener);
             }
 
             if (inputElement.getAttributes() != null) {
@@ -1191,6 +1221,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             inputElement.setElementName(elementNameText.getText().trim());
             if (inputElement.getParentElement() != null) {
                 inputElement.setLogEntry(logEntryButton.getSelection());
+                inputElement.setEventType(eventTypeButton.getSelection() ? eventTypeText.getText().trim() : null);
                 if (tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
                     inputElement.setInputName(tagText.getText().trim());
                 } else {
@@ -1634,6 +1665,16 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                     elementNode.tagText.setBackground(COLOR_TEXT_BACKGROUND);
                 }
             }
+            if (inputElement.getEventType() != null && inputElement.getEventType().trim().isEmpty()) {
+                errors.add(NLS.bind(Messages.CustomXmlParserInputWizardPage_emptyEventTypeError, getName(inputElement)));
+                if (elementNode != null) {
+                    elementNode.eventTypeText.setBackground(COLOR_LIGHT_RED);
+                }
+            } else {
+                if (elementNode != null) {
+                    elementNode.eventTypeText.setBackground(COLOR_TEXT_BACKGROUND);
+                }
+            }
         }
         if (inputElement.getAttributes() != null) {
             if (elementNode != null) {
This page took 0.03326 seconds and 5 git commands to generate.