tmf: Support default timestamp output format in custom parsers
authorPatrick Tasse <patrick.tasse@gmail.com>
Mon, 18 Jul 2016 19:26:57 +0000 (15:26 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Thu, 21 Jul 2016 14:10:05 +0000 (10:10 -0400)
The timestamp output format can now be left blank to use the default
Time Format preference. In that case the Timestamp base aspect will be
used.

When the default format is used, the Timestamp is no longer stored as a
content field, as it is already stored in the event's timestamp.

Change-Id: I1e6f83ffb35f44be7828e3d25ee43f87fa8a97e1
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/77497
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
doc/org.eclipse.tracecompass.doc.user/doc/User-Guide.mediawiki
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/parsers/custom/CustomEventAspects.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/tmf/core/parsers/custom/CustomEvent.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/CustomXmlTraceDefinition.java
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 b4a37db26ca8d31458dbbc5bb2b33986359ae4a7..b439829ae24c593460060107f17725217b2dffef 100644 (file)
@@ -928,7 +928,7 @@ Fill out the first wizard page with the following information:
 
 * '''Category:''' Enter a category name for the trace type.
 * '''Trace type:''' Enter a name for the trace type, which is also the name of the custom parser. This will also be the default event type name.
-* '''Time Stamp format:''' Enter the date and time pattern that will be used to output the Time Stamp.<br>
+* '''Time Stamp format:''' Enter the date and time pattern that will be used to output the Time Stamp, or leave blank to use the default Time Format preference.<br>
 Note: information about date and time patterns can be found here: [http://archive.eclipse.org/tracecompass/doc/stable/org.eclipse.tracecompass.doc.user/reference/api/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.html TmfTimestampFormat]
 
 Click the '''Add next line''', '''Add child line''' or '''Remove line''' buttons to create a new line of input or delete it. For each line of input, enter the following information:
@@ -999,7 +999,7 @@ Fill out the first wizard page with the following information:
 
 * '''Category:''' Enter a category name for the trace type.
 * '''Trace type:''' Enter a name for the trace type, which is also the name of the custom parser. This will also be the default event type name.
-* '''Time Stamp format:''' Enter the date and time pattern that will be used to output the Time Stamp.<br>
+* '''Time Stamp format:''' Enter the date and time pattern that will be used to output the Time Stamp, or leave blank to use the default Time Format preference.<br>
 Note: information about date and time patterns can be found here: [http://archive.eclipse.org/tracecompass/doc/stable/org.eclipse.tracecompass.doc.user/reference/api/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.html TmfTimestampFormat]
 
 Click the '''Add document element''' button to create a new document element and enter a name for the root-level document element of the XML file.
index 5987f25ccabd60589a08aea8e8815a5579e17e7d..23fb11a067e78c9613e496b8bafa084b5a8b1229 100644 (file)
@@ -47,7 +47,8 @@ public class CustomEventAspects {
     public static @NonNull Iterable<ITmfEventAspect<?>> generateAspects(CustomTraceDefinition definition) {
         ImmutableList.Builder<ITmfEventAspect<?>> builder = new ImmutableList.Builder<>();
         for (OutputColumn output : definition.outputs) {
-            if (output.tag.equals(Tag.TIMESTAMP) && definition.timeStampOutputFormat == null) {
+            if (output.tag.equals(Tag.TIMESTAMP) &&
+                    (definition.timeStampOutputFormat == null || definition.timeStampOutputFormat.isEmpty())) {
                 builder.add(TmfBaseAspects.getTimestampAspect());
             } else if (output.tag.equals(Tag.EVENT_TYPE)) {
                 builder.add(TmfBaseAspects.getEventTypeAspect());
index cc6b43302a865b38229815484a748edefed5a8c2..8b1a4eca0f834f5a073aab4225c2212e480477fa 100644 (file)
@@ -270,9 +270,11 @@ public class CustomEvent extends TmfEvent {
         List<ITmfEventField> fields = new ArrayList<>(fDefinition.outputs.size());
         for (OutputColumn outputColumn : fDefinition.outputs) {
             Object key = (outputColumn.tag.equals(Tag.OTHER) ? outputColumn.name : outputColumn.tag);
-            if (outputColumn.tag.equals(Tag.TIMESTAMP) && timestamp != null) {
-                TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
-                fields.add(new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null));
+            if (outputColumn.tag.equals(Tag.TIMESTAMP)) {
+                if (timestamp != null && fDefinition.timeStampOutputFormat != null && !fDefinition.timeStampOutputFormat.isEmpty()) {
+                    TmfTimestampFormat timestampFormat = new TmfTimestampFormat(fDefinition.timeStampOutputFormat);
+                    fields.add(new TmfEventField(outputColumn.name, timestampFormat.format(timestamp.getValue()), null));
+                }
             } else if (!outputColumn.tag.equals(Tag.EVENT_TYPE)){
                 fields.add(new TmfEventField(outputColumn.name, nullToEmptyString(fData.get(key)), null));
             }
index 4364a23b3ee634b0714f6cb87e6d20eeb44217f8..20371425db4065c1f603e673edc61f819e00702a 100644 (file)
@@ -539,9 +539,11 @@ public class CustomTxtTraceDefinition extends CustomTraceDefinition {
             definitionElement.setAttribute(CATEGORY_ATTRIBUTE, categoryName);
             definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
 
-            Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
-            definitionElement.appendChild(formatElement);
-            formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+            if (timeStampOutputFormat != null && !timeStampOutputFormat.isEmpty()) {
+                Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
+                definitionElement.appendChild(formatElement);
+                formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+            }
 
             if (inputs != null) {
                 for (InputLine inputLine : inputs) {
index 6fc26120c84935436e917455b19893c4c2f7d10a..a2319a2fcb0bcff847cad5014a606a267a987825 100644 (file)
@@ -195,9 +195,11 @@ public class CustomXmlTraceDefinition extends CustomTraceDefinition {
             definitionElement.setAttribute(CATEGORY_ATTRIBUTE, categoryName);
             definitionElement.setAttribute(NAME_ATTRIBUTE, definitionName);
 
-            Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
-            definitionElement.appendChild(formatElement);
-            formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+            if (timeStampOutputFormat != null && !timeStampOutputFormat.isEmpty()) {
+                Element formatElement = doc.createElement(TIME_STAMP_OUTPUT_FORMAT_ELEMENT);
+                definitionElement.appendChild(formatElement);
+                formatElement.appendChild(doc.createTextNode(timeStampOutputFormat));
+            }
 
             if (rootInputElement != null) {
                 definitionElement.appendChild(createInputElementElement(rootInputElement, doc));
index 7aa2c6499b3f34a11c9cbc5c933d46dd899bf864..d1ec202d25ceb503200d02d418a84ea0e877d07d 100644 (file)
@@ -182,6 +182,7 @@ public class Messages extends NLS {
     public static String CustomTxtParserInputWizardPage_capturedGroup;
     public static String CustomTxtParserInputWizardPage_cardinality;
     public static String CustomTxtParserInputWizardPage_category;
+    public static String CustomTxtParserInputWizardPage_default;
     public static String CustomTxtParserInputWizardPage_desccriptionEdit;
     public static String CustomTxtParserInputWizardPage_descriptionNew;
     public static String CustomTxtParserInputWizardPage_eventType;
@@ -223,6 +224,7 @@ public class Messages extends NLS {
     public static String CustomTxtParserOutputWizardPage_moveAfter;
     public static String CustomTxtParserOutputWizardPage_moveBefore;
     public static String CustomTxtParserOutputWizardPage_visible;
+    public static String CustomXmlParserInputWizardPage_default;
     public static String CustomXmlParserInputWizardPage_emptyCategoryError;
     public static String CustomXmlParserInputWizardPage_emptyEventTypeError;
     public static String CustomXmlParserInputWizardPage_emptyLogTypeError;
@@ -231,7 +233,6 @@ public class Messages extends NLS {
     public static String CustomXmlParserInputWizardPage_duplicatelogTypeError;
     public static String CustomXmlParserInputWizardPage_noDocumentError;
     public static String CustomXmlParserInputWizardPage_missingLogEntryError;
-    public static String CustomXmlParserInputWizardPage_missingTimestampFmtError;
     public static String CustomXmlParserInputWizardPage_missingDocumentElementError;
     public static String CustomXmlParserInputWizardPage_noTimestampElementOrAttribute;
     public static String CustomXmlParserInputWizardPage_elementMissingNameError;
index 736fdf19c258616ea321db8303eb62b8d63f9d5b..e2e0f058e7475dc0a0f0a9e004a258b9c94d19e6 100644 (file)
@@ -182,6 +182,7 @@ CustomTxtParserInputWizardPage_appendWith=Append with |
 CustomTxtParserInputWizardPage_capturedGroup=Captured group
 CustomTxtParserInputWizardPage_cardinality=Cardinality:
 CustomTxtParserInputWizardPage_category=Category:
+CustomTxtParserInputWizardPage_default=default
 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:
@@ -223,6 +224,7 @@ CustomTxtParserOutputWizardPage_description=Customize the output of the parser
 CustomTxtParserOutputWizardPage_moveAfter=Move After
 CustomTxtParserOutputWizardPage_moveBefore=Move Before
 CustomTxtParserOutputWizardPage_visible=Visible
+CustomXmlParserInputWizardPage_default=default
 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.
@@ -231,7 +233,6 @@ CustomXmlParserInputWizardPage_invalidLogTypeError=Invalid character ':' in trac
 CustomXmlParserInputWizardPage_duplicatelogTypeError=The trace type name already exists.
 CustomXmlParserInputWizardPage_noDocumentError=Add a document element.
 CustomXmlParserInputWizardPage_missingLogEntryError=Identify a Log Entry element.
-CustomXmlParserInputWizardPage_missingTimestampFmtError=Enter the output format for the Time Stamp field.
 CustomXmlParserInputWizardPage_missingDocumentElementError=Enter a name for the document element.
 CustomXmlParserInputWizardPage_noTimestampElementOrAttribute=*no time stamp element or attribute*
 CustomXmlParserInputWizardPage_elementMissingNameError=Enter a name for the element (Element {0}).
index 3b646a44a9787df1c15fe0280e97cc1649cd1b3e..dde744266ccb78e5765495b6f867f16382079a84 100644 (file)
@@ -124,6 +124,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
     private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);
     private static final Color COLOR_TEXT_BACKGROUND = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
     private static final Color COLOR_WIDGET_BACKGROUND = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
+    private static final Color COLOR_GRAY = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
 
     private final ISelection selection;
     private CustomTxtTraceDefinition definition;
@@ -201,6 +202,13 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
         timestampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
         timestampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
         timestampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);
+        timestampOutputFormatText.addPaintListener(e -> {
+            if (!timestampOutputFormatText.isFocusControl() && timestampOutputFormatText.getText().trim().isEmpty()) {
+                e.gc.setForeground(COLOR_GRAY);
+                int borderWidth = timestampOutputFormatText.getBorderWidth();
+                e.gc.drawText(Messages.CustomTxtParserInputWizardPage_default, borderWidth, borderWidth);
+            }
+        });
 
         Button timeStampFormatHelpButton = new Button(headerComposite, SWT.PUSH);
         timeStampFormatHelpButton.setImage(HELP_IMAGE);
@@ -359,7 +367,7 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
 
         SashForm vSash = new SashForm(container, SWT.VERTICAL);
         vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+        vSash.setBackground(COLOR_GRAY);
 
         SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
         hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -551,7 +559,11 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
     private void loadDefinition(CustomTxtTraceDefinition def) {
         categoryText.setText(def.categoryName);
         logtypeText.setText(def.definitionName);
-        timestampOutputFormatText.setText(def.timeStampOutputFormat);
+        if (def.timeStampOutputFormat != null) {
+            timestampOutputFormatText.setText(def.timeStampOutputFormat);
+        } else {
+            timestampOutputFormatText.setText(""); //$NON-NLS-1$
+        }
         treeViewer.setInput(def.inputs);
         if (def.inputs.size() > 0) {
             InputLine inputLine = def.inputs.get(0);
@@ -868,7 +880,11 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
                 try {
                     TmfTimestampFormat timestampFormat = new TmfTimestampFormat(firstEntryTimeStampInputFormat);
                     long timestamp = timestampFormat.parseValue(firstEntryTimeStamp);
-                    timestampFormat = new TmfTimestampFormat(timestampOutputFormatText.getText().trim());
+                    if (timestampOutputFormatText.getText().trim().isEmpty()) {
+                        timestampFormat = new TmfTimestampFormat();
+                    } else {
+                        timestampFormat = new TmfTimestampFormat(timestampOutputFormatText.getText().trim());
+                    }
                     timestampPreviewText.setText(timestampFormat.format(timestamp));
                 } catch (ParseException e) {
                     timestampPreviewText.setText("*parse exception* [" + firstEntryTimeStamp + "] <> [" + firstEntryTimeStampInputFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -1581,20 +1597,14 @@ public class CustomTxtParserInputWizardPage extends WizardPage {
             String name = Integer.toString(i + 1);
             errors.append(validateLine(inputLine, name));
         }
-        if (timestampFound) {
-            if (definition.timeStampOutputFormat.length() == 0) {
-                errors.append("Enter the output format for the Time Stamp field. "); //$NON-NLS-1$
+        if (timestampFound && !definition.timeStampOutputFormat.isEmpty()) {
+            try {
+                new TmfTimestampFormat(definition.timeStampOutputFormat);
+                timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+            } catch (IllegalArgumentException e) {
+                errors.append("Enter a valid output format for the Time Stamp field [" + e.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
                 timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);
-            } else {
-                try {
-                    new TmfTimestampFormat(definition.timeStampOutputFormat);
-                    timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
-                } catch (IllegalArgumentException e) {
-                    errors.append("Enter a valid output format for the Time Stamp field [" + e.getMessage() + "]."); //$NON-NLS-1$ //$NON-NLS-2$
-                    timestampOutputFormatText.setBackground(COLOR_LIGHT_RED);
-                }
             }
-
         } else {
             timestampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
         }
index 4f9cc2f6237abf604ff116e9f97c3998ca5b7f84..f574f08499f944078c37442c4abb7f6341c158be 100644 (file)
@@ -121,6 +121,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
     private static final Color COLOR_LIGHT_RED = new Color(Display.getDefault(), 255, 192, 192);
     private static final Color COLOR_TEXT_BACKGROUND = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
     private static final Color COLOR_WIDGET_BACKGROUND = Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
+    private static final Color COLOR_GRAY = Display.getDefault().getSystemColor(SWT.COLOR_GRAY);
 
     private final ISelection selection;
     private CustomXmlTraceDefinition definition;
@@ -207,6 +208,13 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
         timeStampOutputFormatText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
         timeStampOutputFormatText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
         timeStampOutputFormatText.setText(DEFAULT_TIMESTAMP_FORMAT);
+        timeStampOutputFormatText.addPaintListener(e -> {
+            if (!timeStampOutputFormatText.isFocusControl() && timeStampOutputFormatText.getText().trim().isEmpty()) {
+                e.gc.setForeground(COLOR_GRAY);
+                int borderWidth = timeStampOutputFormatText.getBorderWidth();
+                e.gc.drawText(Messages.CustomXmlParserInputWizardPage_default, borderWidth, borderWidth);
+            }
+        });
 
         Button timeStampFormatHelpButton = new Button(headerComposite, SWT.PUSH);
         timeStampFormatHelpButton.setImage(HELP_IMAGE);
@@ -243,7 +251,7 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
 
         SashForm vSash = new SashForm(container, SWT.VERTICAL);
         vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-        vSash.setBackground(vSash.getDisplay().getSystemColor(SWT.COLOR_GRAY));
+        vSash.setBackground(COLOR_GRAY);
 
         SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
         hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@@ -620,7 +628,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
     private void loadDefinition(CustomXmlTraceDefinition def) {
         categoryText.setText(def.categoryName);
         logtypeText.setText(def.definitionName);
-        timeStampOutputFormatText.setText(def.timeStampOutputFormat);
+        if (def.timeStampOutputFormat != null) {
+            timeStampOutputFormatText.setText(def.timeStampOutputFormat);
+        } else {
+            timeStampOutputFormatText.setText(""); //$NON-NLS-1$
+        }
         treeViewer.setInput(def);
 
         if (def.rootInputElement != null) {
@@ -807,7 +819,11 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
             try {
                 TmfTimestampFormat timestampFormat = new TmfTimestampFormat(timeStampFormat);
                 long timestamp = timestampFormat.parseValue(timeStampValue);
-                timestampFormat = new TmfTimestampFormat(timeStampOutputFormatText.getText().trim());
+                if (timeStampOutputFormatText.getText().trim().isEmpty()) {
+                    timestampFormat = new TmfTimestampFormat();
+                } else {
+                    timestampFormat = new TmfTimestampFormat(timeStampOutputFormatText.getText().trim());
+                }
                 timeStampPreviewText.setText(timestampFormat.format(timestamp));
             } catch (ParseException e) {
                 timeStampPreviewText.setText("*parse exception* [" + timeStampValue + "] <> [" + timeStampFormat + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -1589,21 +1605,19 @@ public class CustomXmlParserInputWizardPage extends WizardPage {
                     errors.add(Messages.CustomXmlParserInputWizardPage_missingLogEntryError);
                 }
 
-                if (timeStampFound) {
-                    if (timeStampOutputFormatText.getText().trim().length() == 0) {
-                        errors.add(Messages.CustomXmlParserInputWizardPage_missingTimestampFmtError);
+                if (timeStampFound && !definition.timeStampOutputFormat.isEmpty()) {
+                    try {
+                        new TmfTimestampFormat(timeStampOutputFormatText.getText().trim());
+                        timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+                    } catch (IllegalArgumentException e) {
+                        errors.add(Messages.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError);
                         timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
-                    } else {
-                        try {
-                            new TmfTimestampFormat(timeStampOutputFormatText.getText().trim());
-                            timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
-                        } catch (IllegalArgumentException e) {
-                            errors.add(Messages.CustomXmlParserInputWizardPage_elementInvalidTimestampFmtError);
-                            timeStampOutputFormatText.setBackground(COLOR_LIGHT_RED);
-                        }
                     }
                 } else {
-                    timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute);
+                    timeStampOutputFormatText.setBackground(COLOR_TEXT_BACKGROUND);
+                    if (!timeStampFound) {
+                        timeStampPreviewText.setText(Messages.CustomXmlParserInputWizardPage_noTimestampElementOrAttribute);
+                    }
                 }
             }
         } else {
This page took 0.032658 seconds and 5 git commands to generate.