Search in sources :

Example 1 with TestportParameter

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

the class TestportParameterDataLabelProvider method getColumnText.

@Override
public String getColumnText(final Object element, final int columnIndex) {
    if (element != null && element instanceof TestportParameter) {
        TestportParameter parameter = (TestportParameter) element;
        String text;
        switch(columnIndex) {
            case 0:
                if (parameter.getComponentName() == null) {
                    return "";
                }
                text = parameter.getComponentName().getText();
                if (text == null || text.length() == 0) {
                    text = ConfigTreeNodeUtilities.toString(parameter.getComponentName());
                }
                return text;
            case 1:
                if (parameter.getTestportName() == null) {
                    return "";
                }
                text = parameter.getTestportName().getText();
                if (text == null || text.length() == 0) {
                    text = ConfigTreeNodeUtilities.toString(parameter.getTestportName());
                }
                return text;
            case 2:
                return parameter.getParameterName().getText();
            default:
                return "";
        }
    }
    return "";
}
Also used : TestportParameter(org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter)

Example 2 with TestportParameter

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

the class TestportParameterSectionDragSourceListener method dragStart.

@Override
public void dragStart(final DragSourceEvent event) {
    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
    event.doit = !selection.isEmpty() && (selection.getFirstElement() instanceof TestportParameter);
}
Also used : TestportParameter(org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with TestportParameter

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

the class TestportParameterTransfer method nativeToJava.

@Override
protected TestportParameter[] nativeToJava(final TransferData transferData) {
    byte[] bytes = (byte[]) super.nativeToJava(transferData);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
    try {
        int n = in.readInt();
        TestportParameter[] items = new TestportParameter[n];
        String componentName;
        String testportName;
        String parameterName;
        String hiddenBefore1;
        String hiddenBefore2;
        String value;
        for (int i = 0; i < n; i++) {
            TestportParameter item = new TestportParameterSectionHandler.TestportParameter();
            final ParseTree root = new ParserRuleContext();
            item.setRoot(root);
            // component name part
            hiddenBefore1 = in.readUTF();
            componentName = in.readUTF();
            hiddenBefore2 = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBefore1));
            item.setComponentName(new AddedParseTree(componentName));
            ConfigTreeNodeUtilities.addChild(root, item.getComponentName());
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBefore2));
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree("".equals(componentName) ? "" : "."));
            // testport name part
            hiddenBefore1 = in.readUTF();
            testportName = in.readUTF();
            hiddenBefore2 = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBefore2));
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree("".equals(testportName) ? "" : "."));
            // parameter name part
            hiddenBefore1 = in.readUTF();
            parameterName = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBefore1));
            item.setParameterName(new AddedParseTree(parameterName));
            ConfigTreeNodeUtilities.addChild(root, item.getParameterName());
            // the := sign and the hidden stuff before it
            hiddenBefore1 = in.readUTF();
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBefore1));
            ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(":="));
            // the value part
            value = in.readUTF();
            item.setValue(new AddedParseTree(value));
            ConfigTreeNodeUtilities.addChild(root, item.getValue());
            items[i] = item;
        }
        return items;
    } catch (IOException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return new TestportParameter[] {};
    }
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) TestportParameter(org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 4 with TestportParameter

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

the class TestportParameterTransfer method javaToNative.

@Override
protected void javaToNative(final Object object, final TransferData transferData) {
    TestportParameter[] items = (TestportParameter[]) 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 : TestportParameter(org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 5 with TestportParameter

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

the class TestportParametersSectionPage method createTestportParameterTable.

private void createTestportParameterTable(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, 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);
    testportParametersTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    testportParametersTable.setEnabled(testportParametersHandler != null);
    TableColumn column = new TableColumn(testportParametersTable, SWT.LEFT, 0);
    column.setText("Parameter name");
    column.setWidth(150);
    column.setMoveable(false);
    column = new TableColumn(testportParametersTable, SWT.LEFT, 0);
    column.setText("Testport name");
    column.setMoveable(false);
    column.setWidth(130);
    column = new TableColumn(testportParametersTable, SWT.LEFT, 0);
    column.setText("Component name");
    column.setMoveable(false);
    column.setWidth(130);
    testportParametersTable.setHeaderVisible(true);
    testportParametersTable.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;
    testportParametersTable.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(testportParametersHandler != null);
    add.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (testportParametersHandler == null) {
                return;
            }
            if (testportParametersHandler.getLastSectionRoot() == null) {
                createNewTestportParameterSection();
            }
            TestportParameter newTestportParameter = createNewParameter();
            if (newTestportParameter == null) {
                return;
            }
            ConfigTreeNodeUtilities.addChild(testportParametersHandler.getLastSectionRoot(), newTestportParameter.getRoot());
            testportParametersHandler.getTestportParameters().add(newTestportParameter);
            internalRefresh();
            testportParametersTableViewer.setSelection(new StructuredSelection(newTestportParameter));
            parameterValueText.setText(newTestportParameter.getValue().getText());
            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(testportParametersHandler != null);
    remove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (testportParametersTableViewer == null || testportParametersHandler == null) {
                return;
            }
            removeSelectedParameters();
            if (testportParametersHandler.getTestportParameters().isEmpty()) {
                removeTestportParameterSection();
            }
            internalRefresh();
            editor.setDirty();
        }
    });
    totalTestportParametersLabel = toolkit.createLabel(buttons, "Total: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalTestportParametersLabel.setLayoutData(gd);
    section.setText("Testport parameters");
    section.setDescription("Specify the list of testport parameters 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);
    testportParametersTableViewer = new TableViewer(testportParametersTable);
    testportParametersTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.size() != 1) {
                parameterValueText.setEnabled(false);
                return;
            }
            TestportParameter testportParameter = (TestportParameter) selection.getFirstElement();
            if (testportParameter != null) {
                if (testportParameter.getValue() != null) {
                    if (testportParameter.getValue().getText().length() == 0) {
                        String temp = ConfigTreeNodeUtilities.toString(testportParameter.getValue());
                        ConfigTreeNodeUtilities.setText(testportParameter.getValue(), temp);
                    }
                    parameterValueText.setText(testportParameter.getValue().getText());
                }
                valueChanged = true;
            }
            parameterValueText.setEnabled(testportParametersHandler != null && testportParameter != null);
        }
    });
    testportParametersTableViewer.setContentProvider(new TestportParameterDataContentProvider());
    testportParametersTableViewer.setLabelProvider(new TestportParameterDataLabelProvider());
    testportParametersTableViewer.setInput(testportParametersHandler);
    testportParametersTableViewer.setColumnProperties(columnNames);
    testportParametersTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(testportParametersTable), new TextCellEditor(testportParametersTable), new TextCellEditor(testportParametersTable) });
    testportParametersTableViewer.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(columnNames).indexOf(property);
            TestportParameterDataLabelProvider labelProvider = (TestportParameterDataLabelProvider) testportParametersTableViewer.getLabelProvider();
            return labelProvider.getColumnText(element, columnIndex);
        }

        @Override
        public void modify(final Object element, final String property, final Object value) {
            int columnIndex = Arrays.asList(columnNames).indexOf(property);
            if (element != null && element instanceof TableItem && value instanceof String) {
                TestportParameter testportParameter = (TestportParameter) ((TableItem) element).getData();
                switch(columnIndex) {
                    case 0:
                        // COMPONENT_NAME
                        ConfigTreeNodeUtilities.setText(testportParameter.getComponentName(), ((String) value).trim());
                        break;
                    case 1:
                        // TESTPORT_NAME
                        ConfigTreeNodeUtilities.setText(testportParameter.getTestportName(), ((String) value).trim());
                        break;
                    case 2:
                        // PARAMETER_NAME
                        ConfigTreeNodeUtilities.setText(testportParameter.getParameterName(), ((String) value).trim());
                        break;
                    default:
                        break;
                }
                testportParametersTableViewer.refresh(testportParameter);
                editor.setDirty();
            }
        }
    });
    testportParametersTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TestportParameterTransfer.getInstance() }, new TestportParameterSectionDragSourceListener(this, testportParametersTableViewer));
    testportParametersTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { TestportParameterTransfer.getInstance() }, new TestportParameterSectionDropTargetListener(testportParametersTableViewer, editor));
}
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) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) 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) TestportParameter(org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter) 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

TestportParameter (org.eclipse.titan.common.parsers.cfg.indices.TestportParameterSectionHandler.TestportParameter)10 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 IOException (java.io.IOException)2 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)2 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)2 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)2 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)2 Section (org.eclipse.ui.forms.widgets.Section)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 Iterator (java.util.Iterator)1