Search in sources :

Example 41 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ExecuteSubPage method createNewExecuteItem.

private ExecuteItem createNewExecuteItem() {
    if (executeSectionHandler == null) {
        return null;
    }
    final ExecuteItem item = new ExecuteSectionHandler.ExecuteItem();
    final ParseTree root = new ParserRuleContext();
    item.setRoot(root);
    final ParseTree moduleName = new AddedParseTree("module_name");
    final ParseTree testcaseName = new AddedParseTree("testcase_name");
    item.setModuleName(moduleName);
    item.setTestcaseName(testcaseName);
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, moduleName);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree("."));
    ConfigTreeNodeUtilities.addChild(root, testcaseName);
    return item;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ExecuteItem(org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 42 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ExternalCommandsSubPage method createExternalcommandsSection.

void createExternalcommandsSection(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | Section.DESCRIPTION | ExpandableComposite.TITLE_BAR);
    section.setActiveToggleColor(toolkit.getHyperlinkGroup().getActiveForeground());
    section.setToggleColor(toolkit.getColors().getColor(IFormColors.SEPARATOR));
    section.setText("External commands");
    section.setDescription("Specify the external commands to be called at execution time for this configuration.");
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    section.setLayoutData(gd);
    Composite client = toolkit.createComposite(section, SWT.WRAP);
    section.setClient(client);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    client.setLayout(layout);
    toolkit.paintBordersFor(client);
    valueChanged = true;
    toolkit.createLabel(client, "Begin control part:");
    beginControlPartText = toolkit.createText(client, "", SWT.SINGLE);
    beginControlPartText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    beginControlPartText.setEnabled(executeCommandSectionHandler != null);
    beginControlPartText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = beginControlPartText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getBeginControlPartRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(), executeCommandSectionHandler.getBeginControlPartRoot());
                }
                executeCommandSectionHandler.setBeginControlPart(null);
                executeCommandSectionHandler.setBeginControlPartRoot(null);
                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getBeginControlPart() == null) {
                // create the node
                createExternalCommandsSection();
                ParseTree beginControlPartRoot = new ParserRuleContext();
                executeCommandSectionHandler.setBeginControlPartRoot(beginControlPartRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(), beginControlPartRoot);
                ConfigTreeNodeUtilities.addChild(beginControlPartRoot, new AddedParseTree("\nbeginControlPart := "));
                ParseTree beginControlPart = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setBeginControlPart(beginControlPart);
                ConfigTreeNodeUtilities.addChild(beginControlPartRoot, beginControlPart);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getBeginControlPart(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getBeginControlPart() != null) {
        beginControlPartText.setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getBeginControlPart()));
    }
    Button browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(beginControlPartText, (IFile) editor.getEditorInput().getAdapter(IFile.class)));
    toolkit.createLabel(client, "Begin testcase:");
    beginTestCaseText = toolkit.createText(client, "", SWT.SINGLE);
    beginTestCaseText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    beginTestCaseText.setEnabled(executeCommandSectionHandler != null);
    beginTestCaseText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = beginTestCaseText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getBeginTestcaseRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(), executeCommandSectionHandler.getBeginTestcaseRoot());
                }
                executeCommandSectionHandler.setBeginTestcase(null);
                executeCommandSectionHandler.setBeginTestcaseRoot(null);
                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getBeginTestcase() == null) {
                // create the node
                createExternalCommandsSection();
                ParseTree beginTestcaseRoot = new ParserRuleContext();
                executeCommandSectionHandler.setBeginTestcaseRoot(beginTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(), beginTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(beginTestcaseRoot, new AddedParseTree("\nbeginTestcase := "));
                ParseTree beginTestcase = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setBeginTestcase(beginTestcase);
                ConfigTreeNodeUtilities.addChild(beginTestcaseRoot, beginTestcase);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getBeginTestcase(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getBeginTestcase() != null) {
        beginTestCaseText.setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getBeginTestcase()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(beginTestCaseText, (IFile) editor.getEditorInput().getAdapter(IFile.class)));
    toolkit.createLabel(client, "End control part:");
    endControlPartText = toolkit.createText(client, "", SWT.SINGLE);
    endControlPartText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    endControlPartText.setEnabled(executeCommandSectionHandler != null);
    endControlPartText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = endControlPartText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getEndControlPartRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(), executeCommandSectionHandler.getEndControlPartRoot());
                }
                executeCommandSectionHandler.setEndControlPart(null);
                executeCommandSectionHandler.setEndControlPartRoot(null);
                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getEndControlPart() == null) {
                // create the node
                createExternalCommandsSection();
                ParseTree endControlPartRoot = new ParserRuleContext();
                executeCommandSectionHandler.setEndControlPartRoot(endControlPartRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(), endControlPartRoot);
                ConfigTreeNodeUtilities.addChild(endControlPartRoot, new AddedParseTree("\nendControlPart := "));
                ParseTree endControlPart = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setEndControlPart(endControlPart);
                ConfigTreeNodeUtilities.addChild(endControlPartRoot, endControlPart);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getEndControlPart(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getEndControlPart() != null) {
        endControlPartText.setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getEndControlPart()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(endControlPartText, (IFile) editor.getEditorInput().getAdapter(IFile.class)));
    toolkit.createLabel(client, "End testcase:");
    endTestCaseText = toolkit.createText(client, "", SWT.SINGLE);
    endTestCaseText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    endTestCaseText.setEnabled(executeCommandSectionHandler != null);
    endTestCaseText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || executeCommandSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = endTestCaseText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (executeCommandSectionHandler.getEndTestcaseRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(executeCommandSectionHandler.getLastSectionRoot(), executeCommandSectionHandler.getEndTestcaseRoot());
                }
                executeCommandSectionHandler.setEndTestcase(null);
                executeCommandSectionHandler.setEndTestcaseRoot(null);
                removeExternalCommandsSection();
            } else if (executeCommandSectionHandler.getEndTestcase() == null) {
                // create the node
                createExternalCommandsSection();
                ParseTree endTestcaseRoot = new ParserRuleContext();
                executeCommandSectionHandler.setEndTestcaseRoot(endTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(executeCommandSectionHandler.getLastSectionRoot(), endTestcaseRoot);
                ConfigTreeNodeUtilities.addChild(endTestcaseRoot, new AddedParseTree("\nendTestcase := "));
                ParseTree endTestcase = new AddedParseTree(temp.trim());
                executeCommandSectionHandler.setEndTestcase(endTestcase);
                ConfigTreeNodeUtilities.addChild(endTestcaseRoot, endTestcase);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(executeCommandSectionHandler.getEndTestcase(), temp.trim());
            }
        }
    });
    if (executeCommandSectionHandler != null && executeCommandSectionHandler.getEndTestcase() != null) {
        endTestCaseText.setText(ConfigTreeNodeUtilities.toString(executeCommandSectionHandler.getEndTestcase()));
    }
    browse = toolkit.createButton(client, "Browse...", SWT.PUSH);
    browse.addSelectionListener(new ExternalCommandBrowser(endTestCaseText, (IFile) editor.getEditorInput().getAdapter(IFile.class)));
    valueChanged = false;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) Section(org.eclipse.ui.forms.widgets.Section) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 43 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ComponentItemTransfer method nativeToJava.

@Override
protected Component[] nativeToJava(final TransferData transferData) {
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
    try {
        int n = in.readInt();
        Component[] items = new Component[n];
        String componentName;
        String hostName;
        String hiddenBefore;
        for (int i = 0; i < n; i++) {
            items[i] = new Component();
            final ParseTree root = new ParserRuleContext();
            items[i].setRoot(root);
            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            componentName = in.readUTF();
            final ParseTree componentNameNode = new AddedParseTree(componentName);
            items[i].setComponentName(componentNameNode);
            ConfigTreeNodeUtilities.addChild(root, componentNameNode);
            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(":="));
            hiddenBefore = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
            hostName = in.readUTF();
            final ParseTree hostNameNode = new AddedParseTree(hostName);
            items[i].setHostName(hostNameNode);
            ConfigTreeNodeUtilities.addChild(root, hostNameNode);
        }
        return items;
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return new Component[] {};
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Component(org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 44 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ComponentsSubPage method createNewComponentsSection.

private void createNewComponentsSection() {
    if (componentsSectionHandler == null) {
        return;
    }
    ParserRuleContext sectionRoot = new ParserRuleContext();
    componentsSectionHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[COMPONENTS]");
    ConfigTreeNodeUtilities.addChild(sectionRoot, header);
    ParserRuleContext root = editor.getParseTreeRoot();
    if (root != null) {
        root.addChild(sectionRoot);
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 45 with AddedParseTree

use of org.eclipse.titan.common.parsers.AddedParseTree in project titan.EclipsePlug-ins by eclipse.

the class ComponentsSubPage method createNewComponent.

private Component createNewComponent() {
    if (componentsSectionHandler == null) {
        return null;
    }
    final Component newcomponent = new Component();
    final ParseTree root = new ParserRuleContext();
    newcomponent.setRoot(root);
    final ParseTree componentName = new AddedParseTree("component_name");
    final ParseTree hostName = new AddedParseTree("host_name");
    newcomponent.setComponentName(componentName);
    newcomponent.setHostName(hostName);
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, componentName);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
    ConfigTreeNodeUtilities.addChild(root, hostName);
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    return newcomponent;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Component(org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)45 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)41 ParseTree (org.antlr.v4.runtime.tree.ParseTree)32 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 IOException (java.io.IOException)6 TerminalNodeImpl (org.antlr.v4.runtime.tree.TerminalNodeImpl)3 GridData (org.eclipse.swt.layout.GridData)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Composite (org.eclipse.swt.widgets.Composite)3 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)3 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)3 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)3 Section (org.eclipse.ui.forms.widgets.Section)3 Token (org.antlr.v4.runtime.Token)2 ModifyEvent (org.eclipse.swt.events.ModifyEvent)2 ModifyListener (org.eclipse.swt.events.ModifyListener)2 Component (org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component)2 Definition (org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition)2 ExecuteItem (org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem)2