Search in sources :

Example 81 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class ModuleParameterSectionPage method createNewModuleParameterSection.

private void createNewModuleParameterSection() {
    if (moduleParametersHandler == null) {
        return;
    }
    ParserRuleContext sectionRoot = new ParserRuleContext();
    moduleParametersHandler.setLastSectionRoot(sectionRoot);
    ParseTree header = new AddedParseTree("\n[MODULE_PARAMETERS]");
    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 82 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class IncludeSectionDropTargetListener method drop.

@Override
public void drop(final DropTargetEvent event) {
    if (IncludeItemTransfer.getInstance().isSupportedType(event.currentDataType)) {
        if (event.item != null && viewer.getInput() != null) {
            IncludeSectionHandler includeSectionHandler = (IncludeSectionHandler) viewer.getInput();
            ParseTree element = (ParseTree) event.item.getData();
            ParseTree[] items = (ParseTree[]) event.data;
            int baseindex = includeSectionHandler.getFiles().indexOf(element);
            final ParseTree parent = includeSectionHandler.getLastSectionRoot();
            ConfigTreeNodeUtilities.removeChild(parent, element);
            ConfigTreeNodeUtilities.addChild(parent, element, baseindex);
            if (items.length > 0) {
                for (int i = 0; i < items.length - 1; i++) {
                    includeSectionHandler.getFiles().add(++baseindex, items[i]);
                }
                includeSectionHandler.getFiles().add(++baseindex, items[items.length - 1]);
            }
            viewer.refresh(true);
            editor.setDirty();
        }
    }
}
Also used : IncludeSectionHandler(org.eclipse.titan.common.parsers.cfg.indices.IncludeSectionHandler) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 83 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class IncludeSubPage method createIncludeSection.

void createIncludeSection(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));
    Composite client = toolkit.createComposite(section, SWT.WRAP);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    client.setLayout(layout);
    toolkit.paintBordersFor(client);
    includeElementsTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    includeElementsTable.setEnabled(includeSectionHandler != null);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 100;
    gd.heightHint = 200;
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    includeElementsTable.setLayoutData(gd);
    TableColumn column = new TableColumn(includeElementsTable, SWT.LEFT, 0);
    column.setText("File name");
    column.setMoveable(false);
    column.setWidth(100);
    includeElementsTable.setLinesVisible(true);
    includeElementsTable.setHeaderVisible(true);
    Composite buttons = toolkit.createComposite(client);
    buttons.setLayout(new GridLayout());
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.GRAB_VERTICAL));
    add = toolkit.createButton(buttons, "Add...", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    add.setEnabled(includeSectionHandler != null);
    add.setLayoutData(gd);
    add.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (includeSectionHandler == null) {
                return;
            }
            if (includeSectionHandler.getLastSectionRoot() == null) {
                createNewIncludeSection();
            }
            ParseTree newItem = createNewIncludeItem();
            if (newItem == null) {
                return;
            }
            ParseTree root = includeSectionHandler.getLastSectionRoot();
            // a new line before every item
            ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
            ConfigTreeNodeUtilities.addChild(root, newItem);
            includeSectionHandler.getFiles().add(newItem);
            internalRefresh();
            includeElementsTable.select(includeSectionHandler.getFiles().size() - 1);
            includeElementsTable.showSelection();
            editor.setDirty();
        }
    });
    remove = toolkit.createButton(buttons, "Remove", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    remove.setLayoutData(gd);
    remove.setEnabled(includeSectionHandler != null);
    remove.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (includeElementsTableViewer == null || includeSectionHandler == null) {
                return;
            }
            removeSelectedIncludeItems();
            if (includeSectionHandler.getFiles().isEmpty()) {
                removeIncludeSection();
            }
            internalRefresh();
            editor.setDirty();
        }
    });
    totalIncludeElementsLabel = toolkit.createLabel(buttons, "Total: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalIncludeElementsLabel.setLayoutData(gd);
    section.setText("Included configurations");
    section.setDescription("Specify the list of included configuration files for this configuration.");
    section.setClient(client);
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    gd = new GridData(GridData.FILL_HORIZONTAL);
    section.setLayoutData(gd);
    includeElementsTableViewer = new TableViewer(includeElementsTable);
    includeElementsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
        // not needed this time
        }
    });
    includeElementsTableViewer.setContentProvider(new IncludeDataContentProvider());
    includeElementsTableViewer.setLabelProvider(new IncludeDataLabelProvider());
    includeElementsTableViewer.setInput(includeSectionHandler);
    includeElementsTableViewer.setColumnProperties(new String[] { "file_name" });
    includeElementsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(includeElementsTable) });
    includeElementsTableViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(final Object element, final String property) {
            return true;
        }

        @Override
        public String getValue(final Object element, final String property) {
            IncludeDataLabelProvider labelProvider = (IncludeDataLabelProvider) includeElementsTableViewer.getLabelProvider();
            return labelProvider.getColumnText(element, 0);
        }

        @Override
        public void modify(final Object element, final String property, final Object value) {
            if (element != null && element instanceof TableItem && value instanceof String) {
                ParseTree item = (ParseTree) ((TableItem) element).getData();
                ConfigTreeNodeUtilities.setText(item, (String) value);
                includeElementsTableViewer.refresh(item);
                editor.setDirty();
            }
        }
    });
    includeElementsTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { IncludeItemTransfer.getInstance() }, new IncludeSectionDragSourceListener(this, includeElementsTableViewer));
    includeElementsTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, new Transfer[] { IncludeItemTransfer.getInstance() }, new IncludeSectionDropTargetListener(includeElementsTableViewer, editor));
    internalRefresh();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableItem(org.eclipse.swt.widgets.TableItem) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Section(org.eclipse.ui.forms.widgets.Section) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 84 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class LoggingBitsSubPage method createConsoleMaskRootNode.

private void createConsoleMaskRootNode(final LoggingSectionHandler.LoggerTreeElement lte, final LogParamEntry logentry) {
    ParseTree consoleMaskRoot = new ParserRuleContext();
    logentry.setConsoleMaskRoot(consoleMaskRoot);
    ConfigTreeNodeUtilities.addChild(consoleMaskRoot, new AddedParseTree("\n"));
    StringBuilder name = new StringBuilder();
    lte.writeNamePrefix(name);
    name.append("ConsoleMask := ");
    ParseTree node = new AddedParseTree(name.toString());
    ConfigTreeNodeUtilities.addChild(consoleMaskRoot, node);
    ParseTree consoleMask = new ParserRuleContext();
    logentry.setConsoleMask(consoleMask);
    ConfigTreeNodeUtilities.addChild(consoleMaskRoot, consoleMask);
    ConfigTreeNodeUtilities.addChild(loggingSectionHandler.getLastSectionRoot(), consoleMaskRoot);
}
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 85 with ParseTree

use of org.antlr.v4.runtime.tree.ParseTree in project titan.EclipsePlug-ins by eclipse.

the class LoggingBitsSubPage method removeLoggingBit.

private void removeLoggingBit(final Map<LoggingBit, ParseTree> aBitMask, final ParseTree aBitmaskRoot, final LoggingBit aBit) {
    final ParseTree removedBit = aBitMask.remove(aBit);
    ConfigTreeNodeUtilities.removeChildWithSeparator(aBitmaskRoot, removedBit);
}
Also used : AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)311 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)104 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)60 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)49 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)46 CharStream (org.antlr.v4.runtime.CharStream)43 Test (org.junit.Test)43 CommonToken (org.antlr.v4.runtime.CommonToken)35 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)35 JavadocContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.JavadocContext)31 TextContext (com.puppycrawl.tools.checkstyle.grammars.javadoc.JavadocParser.TextContext)29 File (java.io.File)26 ArrayList (java.util.ArrayList)22 TerminalNode (org.antlr.v4.runtime.tree.TerminalNode)22 CancellationException (java.util.concurrent.CancellationException)20 ConsoleErrorListener (org.antlr.v4.runtime.ConsoleErrorListener)20 Grammar (org.antlr.v4.tool.Grammar)20 ByteArrayInputStream (java.io.ByteArrayInputStream)19 IOException (java.io.IOException)19 LexerGrammar (org.antlr.v4.tool.LexerGrammar)16