Search in sources :

Example 1 with CustomXmlTraceDefinition

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition in project tracecompass by tracecompass.

the class CustomXmlIndexTest method createTrace.

@Override
protected TestTrace createTrace() throws Exception {
    CustomXmlTraceDefinition definition = createDefinition();
    final File file = new File(TRACE_PATH);
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
        writer.write("<trace>");
        for (int i = 0; i < NB_EVENTS; ++i) {
            SimpleDateFormat f = new SimpleDateFormat(TIMESTAMP_FORMAT);
            String eventStr = "<element time=\"" + f.format(new Date(i)) + "\">message</element>\n";
            writer.write(eventStr);
        }
        writer.write("</trace>");
    }
    return new TestXmlTrace(file.toString(), definition, BLOCK_SIZE);
}
Also used : CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) FileWriter(java.io.FileWriter) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter)

Example 2 with CustomXmlTraceDefinition

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition in project tracecompass by tracecompass.

the class ProjectExplorerTracesFolderTest method importCustomParsers.

private static void importCustomParsers() {
    // FIXME: We can't use Manage Custom Parsers > Import because it uses a native dialog. We'll still check that they show up in the dialog
    CustomTxtTraceDefinition[] txtDefinitions = CustomTxtTraceDefinition.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml"));
    txtDefinitions[0].save();
    CustomXmlTraceDefinition[] xmlDefinitions = CustomXmlTraceDefinition.loadAll(getPath("customParsers/ExampleCustomXmlParser.xml"));
    xmlDefinitions[0].save();
    SWTBotTreeItem traceFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
    traceFolder.contextMenu("Manage Custom Parsers...").click();
    SWTBotShell shell = fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).activate();
    SWTBot shellBot = shell.bot();
    // Make sure the custom text trace type is imported
    shellBot.list().select(CUSTOM_TEXT_LOG.getTraceType());
    // Make sure the custom xml trace type is imported
    shellBot.radio("XML").click();
    shellBot.list().select(CUSTOM_XML_LOG.getTraceType());
    shellBot.button("Close").click();
    shellBot.waitUntil(Conditions.shellCloses(shell), DISK_ACCESS_TIMEOUT);
}
Also used : CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) SWTBot(org.eclipse.swtbot.swt.finder.SWTBot) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition)

Example 3 with CustomXmlTraceDefinition

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition in project tracecompass by tracecompass.

the class ManageCustomParsersDialog method fillParserList.

private void fillParserList() {
    parserList.removeAll();
    if (txtButton.getSelection()) {
        for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll(false)) {
            parserList.add(def.categoryName + SEP + def.definitionName);
        }
    } else if (xmlButton.getSelection()) {
        for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll(false)) {
            parserList.add(def.categoryName + SEP + def.definitionName);
        }
    }
    editButton.setEnabled(false);
    deleteButton.setEnabled(false);
    exportButton.setEnabled(false);
}
Also used : CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition)

Example 4 with CustomXmlTraceDefinition

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition in project tracecompass by tracecompass.

the class CustomXmlParserInputWizardPage method createControl.

@Override
public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout());
    updateListener = new UpdateListener();
    Composite headerComposite = new Composite(container, SWT.FILL);
    GridLayout headerLayout = new GridLayout(5, false);
    headerLayout.marginHeight = 0;
    headerLayout.marginWidth = 0;
    headerComposite.setLayout(headerLayout);
    headerComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    Label categoryLabel = new Label(headerComposite, SWT.NULL);
    categoryLabel.setText(Messages.CustomXmlParserInputWizardPage_category);
    categoryText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
    categoryText.setLayoutData(new GridData(120, SWT.DEFAULT));
    Label timeStampFormatLabel = new Label(headerComposite, SWT.NULL);
    timeStampFormatLabel.setText(Messages.CustomXmlParserInputWizardPage_timestampFormat);
    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);
    timeStampFormatHelpButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_timestampFormatHelp);
    timeStampFormatHelpButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Bundle plugin = Platform.getBundle(TIMESTAMP_FORMAT_BUNDLE);
            IPath path = new Path(TIMESTAMP_FORMAT_PATH);
            URL fileURL = FileLocator.find(plugin, path, null);
            try {
                URL pageURL = FileLocator.toFileURL(fileURL);
                openHelpShell(pageURL.toString());
            } catch (IOException e1) {
            }
        }
    });
    Label logtypeLabel = new Label(headerComposite, SWT.NULL);
    logtypeLabel.setText(Messages.CustomXmlParserInputWizardPage_logType);
    logtypeText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE);
    logtypeText.setLayoutData(new GridData(120, SWT.DEFAULT));
    logtypeText.setFocus();
    Label timeStampPreviewLabel = new Label(headerComposite, SWT.NULL);
    timeStampPreviewLabel.setText(Messages.CustomXmlParserInputWizardPage_preview);
    timestampPreviewText = new Text(headerComposite, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    timestampPreviewText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
    // $NON-NLS-1$
    timestampPreviewText.setText("*no time stamp element or attribute*");
    timestampPreviewText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    createButtonBar();
    SashForm vSash = new SashForm(container, SWT.VERTICAL);
    vSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    vSash.setBackground(COLOR_GRAY);
    SashForm hSash = new SashForm(vSash, SWT.HORIZONTAL);
    hSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    ScrolledComposite treeScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL | SWT.H_SCROLL);
    treeScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    Composite treeContainer = new Composite(treeScrolledComposite, SWT.NONE);
    treeContainer.setLayout(new FillLayout());
    treeScrolledComposite.setContent(treeContainer);
    treeScrolledComposite.setExpandHorizontal(true);
    treeScrolledComposite.setExpandVertical(true);
    treeViewer = new TreeViewer(treeContainer, SWT.SINGLE | SWT.BORDER);
    treeViewer.setContentProvider(new InputElementTreeNodeContentProvider());
    treeViewer.setLabelProvider(new InputElementTreeLabelProvider());
    treeViewer.addSelectionChangedListener(new InputElementTreeSelectionChangedListener());
    treeContainer.layout();
    fBGColor = treeViewer.getTree().getBackground();
    treeScrolledComposite.setMinSize(treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, treeContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    elementScrolledComposite = new ScrolledComposite(hSash, SWT.V_SCROLL);
    elementScrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    elementContainer = new Composite(elementScrolledComposite, SWT.NONE);
    GridLayout gl = new GridLayout();
    gl.marginHeight = 1;
    gl.marginWidth = 0;
    elementContainer.setLayout(gl);
    elementScrolledComposite.setContent(elementContainer);
    elementScrolledComposite.setExpandHorizontal(true);
    elementScrolledComposite.setExpandVertical(true);
    if (definition == null) {
        definition = new CustomXmlTraceDefinition();
    }
    loadDefinition(definition);
    treeViewer.expandAll();
    elementContainer.layout();
    categoryText.addModifyListener(updateListener);
    logtypeText.addModifyListener(updateListener);
    timestampOutputFormatText.addModifyListener(updateListener);
    elementScrolledComposite.setMinSize(elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, elementContainer.computeSize(SWT.DEFAULT, SWT.DEFAULT).y - 1);
    hSash.setWeights(new int[] { 1, 2 });
    if (definition.rootInputElement == null) {
        removeButton.setEnabled(false);
        addChildButton.setToolTipText(Messages.CustomXmlParserInputWizardPage_addDocumentElement);
        addNextButton.setEnabled(false);
        moveUpButton.setEnabled(false);
        moveDownButton.setEnabled(false);
    } else {
        // root is selected
        addNextButton.setEnabled(false);
    }
    Composite sashBottom = new Composite(vSash, SWT.NONE);
    GridLayout sashBottomLayout = new GridLayout(2, false);
    sashBottomLayout.marginHeight = 0;
    sashBottomLayout.marginWidth = 0;
    sashBottom.setLayout(sashBottomLayout);
    Label previewLabel = new Label(sashBottom, SWT.NULL);
    previewLabel.setText(Messages.CustomXmlParserInputWizardPage_previewInput);
    errorText = new Text(sashBottom, SWT.SINGLE | SWT.READ_ONLY);
    errorText.setBackground(fBGColor);
    errorText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    errorText.setVisible(false);
    inputText = new StyledText(sashBottom, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
    if (fixedFont == null) {
        if (System.getProperty("os.name").contains("Windows")) {
            // $NON-NLS-1$ //$NON-NLS-2$
            // $NON-NLS-1$
            fixedFont = new Font(Display.getCurrent(), new FontData("Courier New", 10, SWT.NORMAL));
        } else {
            // $NON-NLS-1$
            fixedFont = new Font(Display.getCurrent(), new FontData("Monospace", 10, SWT.NORMAL));
        }
    }
    inputText.setFont(fixedFont);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gd.heightHint = inputText.computeSize(SWT.DEFAULT, inputText.getLineHeight() * 4).y;
    gd.widthHint = 800;
    inputText.setLayoutData(gd);
    inputText.setText(getSelectionText());
    inputText.addModifyListener(e -> parseXmlInput(inputText.getText()));
    inputText.addModifyListener(updateListener);
    vSash.setWeights(new int[] { hSash.computeSize(SWT.DEFAULT, SWT.DEFAULT).y, sashBottom.computeSize(SWT.DEFAULT, SWT.DEFAULT).y });
    setControl(container);
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) Label(org.eclipse.swt.widgets.Label) URL(java.net.URL) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IPath(org.eclipse.core.runtime.IPath) Bundle(org.osgi.framework.Bundle) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FontData(org.eclipse.swt.graphics.FontData) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) FillLayout(org.eclipse.swt.layout.FillLayout) Point(org.eclipse.swt.graphics.Point) SashForm(org.eclipse.swt.custom.SashForm) CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) GridData(org.eclipse.swt.layout.GridData)

Example 5 with CustomXmlTraceDefinition

use of org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition in project tracecompass by tracecompass.

the class TmfTraceElement method instantiateTrace.

/**
 * Instantiate a <code>ITmfTrace</code> object based on the trace type and
 * the corresponding extension.
 *
 * @return the <code>ITmfTrace</code> or <code>null</code> for an error
 */
@Override
public ITmfTrace instantiateTrace() {
    try {
        // make sure that supplementary folder exists
        refreshSupplementaryFolder();
        String traceTypeId = getTraceType();
        if (traceTypeId != null) {
            if (CustomTxtTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomTxtTraceDefinition def : CustomTxtTraceDefinition.loadAll()) {
                    String id = CustomTxtTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomTxtTrace(def);
                    }
                }
            }
            if (CustomXmlTrace.isCustomTraceTypeId(traceTypeId)) {
                for (CustomXmlTraceDefinition def : CustomXmlTraceDefinition.loadAll()) {
                    String id = CustomXmlTrace.buildTraceTypeId(def.categoryName, def.definitionName);
                    if (traceTypeId.equals(id)) {
                        return new CustomXmlTrace(def);
                    }
                }
            }
            IConfigurationElement ce = TRACE_TYPE_ATTRIBUTES.get(traceTypeId);
            if (ce == null) {
                return null;
            }
            ITmfTrace trace = (ITmfTrace) ce.createExecutableExtension(TmfTraceType.TRACE_TYPE_ATTR);
            return trace;
        }
    } catch (CoreException e) {
        // $NON-NLS-1$
        Activator.getDefault().logError("Error instantiating ITmfTrace object for trace " + getName(), e);
    }
    return null;
}
Also used : ITmfTrace(org.eclipse.tracecompass.tmf.core.trace.ITmfTrace) CustomXmlTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition) CoreException(org.eclipse.core.runtime.CoreException) CustomXmlTrace(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace) CustomTxtTrace(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace) CustomTxtTraceDefinition(org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Aggregations

CustomXmlTraceDefinition (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition)8 CustomTxtTraceDefinition (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition)6 CustomTxtTrace (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTrace)3 CustomXmlTrace (org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTrace)3 CoreException (org.eclipse.core.runtime.CoreException)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 ITmfTrace (org.eclipse.tracecompass.tmf.core.trace.ITmfTrace)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 URL (java.net.URL)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 AbstractTreeViewer (org.eclipse.jface.viewers.AbstractTreeViewer)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 SashForm (org.eclipse.swt.custom.SashForm)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1