Search in sources :

Example 1 with Definition

use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefineItemTransfer method javaToNative.

@Override
protected void javaToNative(final Object object, final TransferData transferData) {
    Definition[] items = (Definition[]) object;
    ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(byteOut);
    byte[] bytes = null;
    try {
        out.writeInt(items.length);
        for (int i = 0; i < items.length; i++) {
            out.writeUTF(convertToString(items[i].getRoot()));
        }
        out.close();
        bytes = byteOut.toByteArray();
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
    }
    if (bytes != null) {
        super.javaToNative(bytes, transferData);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with Definition

use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefineItemTransfer method nativeToJava.

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

Example 3 with Definition

use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefineSectionDragSourceListener method dragSetData.

@Override
public void dragSetData(final DragSourceEvent event) {
    if (DefineItemTransfer.getInstance().isSupportedType(event.dataType)) {
        IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
        List<Definition> items = new ArrayList<Definition>();
        if (!selection.isEmpty()) {
            for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
                Object element = it.next();
                if (element instanceof Definition) {
                    items.add((Definition) element);
                }
            }
            event.data = items.toArray(new Definition[items.size()]);
        }
    }
}
Also used : Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 4 with Definition

use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefineSectionDropTargetListener method drop.

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

Example 5 with Definition

use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.

the class DefineSubPage method createDefinitionSection.

void createDefinitionSection(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);
    defineElementsTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    defineElementsTable.setEnabled(defineSectionHandler != null);
    TableColumn column = new TableColumn(defineElementsTable, SWT.LEFT, 0);
    column.setText("Definition name");
    column.setMoveable(false);
    column.setWidth(150);
    column = new TableColumn(defineElementsTable, SWT.LEFT, 1);
    column.setText("Definition value");
    column.setWidth(300);
    column.setMoveable(false);
    defineElementsTable.setHeaderVisible(true);
    defineElementsTable.setLinesVisible(true);
    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;
    defineElementsTable.setLayoutData(gd);
    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.setLayoutData(gd);
    add.setEnabled(defineSectionHandler != null);
    add.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // Do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (defineSectionHandler == null) {
                return;
            }
            if (defineSectionHandler.getLastSectionRoot() == null) {
                createNewDefineSection();
            }
            final Definition newItem = createNewDefineItem();
            if (newItem == null) {
                return;
            }
            ConfigTreeNodeUtilities.addChild(defineSectionHandler.getLastSectionRoot(), newItem.getRoot());
            defineSectionHandler.getDefinitions().add(newItem);
            internalRefresh();
            defineElementsTable.select(defineSectionHandler.getDefinitions().size() - 1);
            defineElementsTable.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(defineSectionHandler != null);
    remove.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        // Do nothing
        }

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (defineElementsTableViewer == null || defineSectionHandler == null) {
                return;
            }
            removeSelectedDefineItems();
            if (defineSectionHandler.getDefinitions().isEmpty()) {
                removeDefineSection();
            }
            internalRefresh();
            editor.setDirty();
        }
    });
    totalDefineElementsLabel = toolkit.createLabel(buttons, "Total defined: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalDefineElementsLabel.setLayoutData(gd);
    section.setText("Definitions");
    section.setDescription("Specify the list of Definitions 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_BOTH);
    section.setLayoutData(gd);
    defineElementsTableViewer = new TableViewer(defineElementsTable);
    defineElementsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
        // not needed this time
        }
    });
    defineElementsTableViewer.setContentProvider(new DefineDataContentProvider());
    defineElementsTableViewer.setLabelProvider(new DefineDataLabelProvider());
    defineElementsTableViewer.setInput(defineSectionHandler);
    defineElementsTableViewer.setColumnProperties(COLUMN_NAMES);
    defineElementsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(defineElementsTable), new TextCellEditor(defineElementsTable) });
    defineElementsTableViewer.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) {
            int columnIndex = Arrays.asList(COLUMN_NAMES).indexOf(property);
            DefineDataLabelProvider labelProvider = (DefineDataLabelProvider) defineElementsTableViewer.getLabelProvider();
            return labelProvider.getColumnText(element, columnIndex);
        }

        @Override
        public void modify(final Object element, final String property, final Object value) {
            int columnIndex = Arrays.asList(COLUMN_NAMES).indexOf(property);
            if (element != null && element instanceof TableItem && value instanceof String) {
                Definition definition = (Definition) ((TableItem) element).getData();
                switch(columnIndex) {
                    case 0:
                        ConfigTreeNodeUtilities.setText(definition.getDefinitionName(), ((String) value).trim());
                        break;
                    case 1:
                        ConfigTreeNodeUtilities.setText(definition.getDefinitionValue(), ((String) value).trim());
                        break;
                    default:
                        break;
                }
                defineElementsTableViewer.refresh(definition);
                editor.setDirty();
            }
        }
    });
    defineElementsTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { DefineItemTransfer.getInstance() }, new DefineSectionDragSourceListener(this, defineElementsTableViewer));
    defineElementsTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, new Transfer[] { DefineItemTransfer.getInstance() }, new DefineSectionDropTargetListener(defineElementsTableViewer, editor));
    internalRefresh();
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableItem(org.eclipse.swt.widgets.TableItem) Definition(org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition) 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) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

Definition (org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition)8 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 IOException (java.io.IOException)2 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)2 DefineSectionHandler (org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1