/*******************************************************************************
- * Copyright (c) 2010, 2014 Ericsson
+ * Copyright (c) 2010, 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
import java.io.InputStreamReader;
import java.net.URL;
import java.text.ParseException;
+import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.Messages;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition;
+import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTraceDefinition.Tag;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.Cardinality;
import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition.InputData;
private static final String DEFAULT_TIMESTAMP_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS"; //$NON-NLS-1$
private static final String TIMESTAMP_FORMAT_BUNDLE = "org.eclipse.tracecompass.doc.user"; //$NON-NLS-1$
private static final String TIMESTAMP_FORMAT_PATH = "reference/api/org/eclipse/tracecompass/tmf/core/timestamp/TmfTimestampFormat.html"; //$NON-NLS-1$
- private static final String PATTERN_URL = "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
+ private static final String PATTERN_URL = "http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html#sum"; //$NON-NLS-1$
private static final Image LINE_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/line_icon.gif"); //$NON-NLS-1$
private static final Image ADD_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/add_button.gif"); //$NON-NLS-1$
private static final Image ADD_NEXT_IMAGE = Activator.getDefault().getImageFromPath("/icons/elcl16/addnext_button.gif"); //$NON-NLS-1$
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;
CustomTxtTraceDefinition definition) {
super("CustomParserWizardPage"); //$NON-NLS-1$
if (definition == null) {
- setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleNew);
+ setTitle(Messages.CustomTxtParserInputWizardPage_titleNew);
defaultDescription = Messages.CustomTxtParserInputWizardPage_descriptionNew;
} else {
- setTitle(Messages.CustomTxtParserInputWizardPage_windowTitleEdit);
+ setTitle(Messages.CustomTxtParserInputWizardPage_titleEdit);
defaultDescription = Messages.CustomTxtParserInputWizardPage_desccriptionEdit;
}
setDescription(defaultDescription);
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);
if (inputLine.parentInput == null) {
definition.inputs.remove(inputLine);
} else {
+ int index = inputLine.parentInput.childrenInputs.indexOf(inputLine);
+ if (index > 0) {
+ inputLine.parentInput.childrenInputs.get(index - 1).nextInput = inputLine.nextInput;
+ }
inputLine.parentInput.childrenInputs.remove(inputLine);
}
treeViewer.refresh();
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));
if (definition == null) {
definition = new CustomTxtTraceDefinition();
definition.inputs.add(new InputLine(Cardinality.ZERO_OR_MORE, DEFAULT_REGEX,
- Arrays.asList(new InputData(CustomTraceDefinition.TAG_MESSAGE, CustomTraceDefinition.ACTION_SET))));
+ Arrays.asList(new InputData(Tag.MESSAGE, CustomTraceDefinition.ACTION_SET))));
}
loadDefinition(definition);
treeViewer.expandAll();
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);
}
/**
- * Get the global list of input names.
+ * Get the global list of inputs.
*
- * @return The list of input names
+ * @return The list of inputs
*/
- public List<String> getInputNames() {
- List<String> inputs = new ArrayList<>();
+ public List<Entry<Tag, String>> getInputs() {
+ List<Entry<Tag, String>> inputs = new ArrayList<>();
for (InputLine inputLine : definition.inputs) {
- for (String inputName : getInputNames(inputLine)) {
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ for (Entry<Tag, String> input : getInputs(inputLine)) {
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
}
/**
- * Get the list of input names for the given input line.
+ * Get the list of inputs for the given input line, recursively.
*
* @param inputLine
* The input line
- * @return The list of input names
+ * @return The list of inputs
*/
- public List<String> getInputNames(InputLine inputLine) {
- List<String> inputs = new ArrayList<>();
+ private List<Entry<Tag, String>> getInputs(InputLine inputLine) {
+ List<Entry<Tag, String>> inputs = new ArrayList<>();
if (inputLine.columns != null) {
for (InputData inputData : inputLine.columns) {
- String inputName = inputData.name;
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ Entry<Tag, String> input = new SimpleEntry<>(inputData.tag, inputData.name);
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
if (inputLine.childrenInputs != null) {
for (InputLine childInputLine : inputLine.childrenInputs) {
- for (String inputName : getInputNames(childInputLine)) {
- if (!inputs.contains(inputName)) {
- inputs.add(inputName);
+ for (Entry<Tag, String> input : getInputs(childInputLine)) {
+ if (!inputs.contains(input)) {
+ inputs.add(input);
}
}
}
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
- sb.append(line + "\n"); //$NON-NLS-1$
+ sb.append(line);
+ sb.append('\n');
}
return sb.toString();
} catch (CoreException e) {
}
}
- Map<String, String> data = new HashMap<>();
+ Map<Object, String> data = new HashMap<>();
int rootLineMatches = 0;
String firstEntryTimeStamp = null;
String firstEntryTimeStampInputFormat = null;
timeStampFormat = null;
updatePreviewLine(rootInputLine, matcher, data, rawPos, rootLineMatches);
if (rootLineMatches == 1) {
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
firstEntryTimeStampInputFormat = timeStampFormat;
}
HashMap<InputLine, Integer> countMap = new HashMap<>();
}
if (rootLineMatches == 1) {
- firstEntryTimeStamp = data.get(CustomTraceDefinition.TAG_TIMESTAMP);
+ firstEntryTimeStamp = data.get(Tag.TIMESTAMP);
firstEntryTimeStampInputFormat = timeStampFormat;
}
if (firstEntryTimeStamp == null) {
timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noTimestampGroup);
if (selectedLine != null) {
for (InputGroup group : selectedLine.inputs) {
- if (group.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (group.tagCombo.getText().equals(Tag.TIMESTAMP.toString())) {
timestampPreviewText.setText(Messages.CustomTxtParserInputWizardPage_noMatchingTimestamp);
break;
}
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$
}
}
- private void updatePreviewLine(InputLine line, Matcher matcher, Map<String, String> data, int rawPos, int rootLineMatches) {
+ private void updatePreviewLine(InputLine line, Matcher matcher, Map<Object, String> data, int rawPos, int rootLineMatches) {
for (int i = 0; i < line.columns.size(); i++) {
InputData input = line.columns.get(i);
if (i < matcher.groupCount() && matcher.group(i + 1) != null) {
if (value.length() == 0) {
continue;
}
+ Object key = (input.tag.equals(Tag.OTHER) ? input.name : input.tag);
if (input.action == CustomTraceDefinition.ACTION_SET) {
- data.put(input.name, value);
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ data.put(key, value);
+ if (input.tag.equals(Tag.TIMESTAMP)) {
timeStampFormat = input.format;
}
} else if (input.action == CustomTraceDefinition.ACTION_APPEND) {
- String s = data.get(input.name);
+ String s = data.get(key);
if (s != null) {
- data.put(input.name, s + value);
+ data.put(key, s + value);
} else {
- data.put(input.name, value);
+ data.put(key, value);
}
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (input.tag.equals(Tag.TIMESTAMP)) {
if (timeStampFormat != null) {
timeStampFormat += input.format;
} else {
}
}
} else if (input.action == CustomTraceDefinition.ACTION_APPEND_WITH_SEPARATOR) {
- String s = data.get(input.name);
+ String s = data.get(key);
if (s != null) {
- data.put(input.name, s + " | " + value); //$NON-NLS-1$
+ data.put(key, s + " | " + value); //$NON-NLS-1$
} else {
- data.put(input.name, value);
+ data.put(key, value);
}
- if (input.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (input.tag.equals(Tag.TIMESTAMP)) {
if (timeStampFormat != null) {
timeStampFormat += " | " + input.format; //$NON-NLS-1$
} else {
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;
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);
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
inputGroup.tagCombo.select(0);
inputGroup.tagText.setText(inputData.format);
inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_format);
inputGroup.tagLabel.setVisible(true);
inputGroup.tagText.setVisible(true);
inputGroup.tagText.addModifyListener(updateListener);
- } else if (inputData.name.equals(CustomTraceDefinition.TAG_MESSAGE)) {
+ } else if (inputData.tag.equals(Tag.EVENT_TYPE)) {
inputGroup.tagCombo.select(1);
- } else {
+ } else if (inputData.tag.equals(Tag.MESSAGE)) {
inputGroup.tagCombo.select(2);
+ } else {
+ inputGroup.tagCombo.select(3);
inputGroup.tagText.setText(inputData.name);
inputGroup.tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);
inputGroup.tagLabel.setVisible(true);
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;
for (int i = 0; i < inputs.size(); i++) {
InputGroup grp = inputs.get(i);
InputData inputData = new InputData();
- if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_OTHER)) {
+ inputData.tag = Tag.fromLabel(grp.tagCombo.getText());
+ if (inputData.tag.equals(Tag.OTHER)) {
inputData.name = grp.tagText.getText().trim();
} else {
- inputData.name = grp.tagCombo.getText();
- if (grp.tagCombo.getText().equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ inputData.name = inputData.tag.toString();
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
inputData.format = grp.tagText.getText().trim();
}
}
tagComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
tagCombo = new Combo(tagComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
- tagCombo.setItems(new String[] { CustomTraceDefinition.TAG_TIMESTAMP,
- CustomTraceDefinition.TAG_MESSAGE,
- CustomTraceDefinition.TAG_OTHER });
- tagCombo.select(1);
+ tagCombo.setItems(new String[] {
+ Tag.TIMESTAMP.toString(),
+ Tag.EVENT_TYPE.toString(),
+ Tag.MESSAGE.toString(),
+ Tag.OTHER.toString()});
+ tagCombo.select(2);
tagCombo.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
tagText.setVisible(true);
tagText.addModifyListener(updateListener);
break;
- case 1: // Message
+ case 1: // Event type
+ tagLabel.setVisible(false);
+ tagText.setVisible(false);
+ break;
+ case 2: // Message
tagLabel.setVisible(false);
tagText.setVisible(false);
break;
- case 2: // Other
+ case 3: // Other
tagLabel.setText(Messages.CustomTxtParserInputWizardPage_name);
tagLabel.setVisible(true);
tagText.setVisible(true);
tagText.addModifyListener(updateListener);
break;
- case 3: // Continue
- tagLabel.setVisible(false);
- tagText.setVisible(false);
- break;
default:
break;
}
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);
}
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;
if (line != null) {
group = line.inputs.get(i);
}
- if (inputData.name.equals(CustomTraceDefinition.TAG_TIMESTAMP)) {
+ if (inputData.tag.equals(Tag.TIMESTAMP)) {
timestampFound = true;
if (inputData.format.length() == 0) {
errors.append("Enter the input format for the Time Stamp (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
}
}
- } else if (inputData.name.length() == 0) {
- errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- if (group != null) {
- group.tagText.setBackground(COLOR_LIGHT_RED);
+ } else if (inputData.tag.equals(Tag.OTHER)) {
+ if (inputData.name.isEmpty()) {
+ errors.append("Enter a name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else if (Tag.fromLabel(inputData.name) != null) {
+ errors.append("Cannot use reserved name for the data group (Line " + name + " Group " + (i + 1) + "). "); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ if (group != null) {
+ group.tagText.setBackground(COLOR_LIGHT_RED);
+ }
+ } else {
+ if (group != null) {
+ group.tagText.setBackground(COLOR_TEXT_BACKGROUND);
+ }
}
} else {
if (group != null) {