Search in sources :

Example 6 with ExecuteItem

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

the class ExecuteSubPage method createExecuteSection.

void createExecuteSection(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));
    section.setText("Elements to be executed");
    section.setDescription("Specify the list of testcases and control parts to be executed for this configuration.\n" + "Use drag&drop to change the order of elements.");
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(GridData.FILL_BOTH);
    section.setLayoutData(gd);
    Composite client = toolkit.createComposite(section, SWT.WRAP);
    section.setClient(client);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    client.setLayout(layout);
    gd = new GridData(GridData.FILL_BOTH);
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.grabExcessVerticalSpace = true;
    gd.verticalAlignment = SWT.FILL;
    client.setLayoutData(gd);
    toolkit.paintBordersFor(client);
    executeElementsTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    executeElementsTable.setEnabled(executeSectionHandler != null);
    TableColumn column = new TableColumn(executeElementsTable, SWT.LEFT, 0);
    column.setText("Module name");
    column.setWidth(200);
    column.setMoveable(false);
    column = new TableColumn(executeElementsTable, SWT.LEFT, 1);
    column.setText("Testcase name");
    column.setMoveable(false);
    column.setWidth(200);
    executeElementsTable.setHeaderVisible(true);
    executeElementsTable.setLinesVisible(true);
    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;
    executeElementsTable.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(executeSectionHandler != null);
    add.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (executeSectionHandler == null) {
                return;
            }
            if (executeSectionHandler.getLastSectionRoot() == null) {
                createNewExecuteSection();
            }
            ExecuteItem newItem = createNewExecuteItem();
            if (newItem == null) {
                return;
            }
            ConfigTreeNodeUtilities.addChild(executeSectionHandler.getLastSectionRoot(), newItem.getRoot());
            executeSectionHandler.getExecuteitems().add(newItem);
            internalRefresh();
            executeElementsTable.select(executeSectionHandler.getExecuteitems().size() - 1);
            executeElementsTable.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(executeSectionHandler != null);
    remove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (executeElementsTableViewer == null || executeSectionHandler == null) {
                return;
            }
            removeSelectedExecuteItems();
            if (executeSectionHandler.getExecuteitems().isEmpty()) {
                removeExecuteSection();
            }
            internalRefresh();
            editor.setDirty();
        }
    });
    totalExecuteElementsLabel = toolkit.createLabel(buttons, "Total: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalExecuteElementsLabel.setLayoutData(gd);
    executeElementsTableViewer = new TableViewer(executeElementsTable);
    executeElementsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
        // not needed this time
        }
    });
    executeElementsTableViewer.setContentProvider(new ExecuteDataContentProvider());
    executeElementsTableViewer.setLabelProvider(new ExecuteDataLabelProvider());
    executeElementsTableViewer.setInput(executeSectionHandler);
    executeElementsTableViewer.setColumnProperties(COLUMN_NAMES);
    executeElementsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(executeElementsTable), new TextCellEditor(executeElementsTable) });
    executeElementsTableViewer.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);
            ExecuteDataLabelProvider labelProvider = (ExecuteDataLabelProvider) executeElementsTableViewer.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) {
                ExecuteItem executeItem = (ExecuteItem) ((TableItem) element).getData();
                switch(columnIndex) {
                    case 0:
                        ConfigTreeNodeUtilities.setText(executeItem.getModuleName(), ((String) value).trim());
                        break;
                    case 1:
                        ConfigTreeNodeUtilities.setText(executeItem.getTestcaseName(), ((String) value).trim());
                        break;
                    default:
                        break;
                }
                executeElementsTableViewer.refresh(executeItem);
                editor.setDirty();
            }
        }
    });
    executeElementsTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ExecuteItemTransfer.getInstance() }, new ExecuteSectionDragSourceListener(this, executeElementsTableViewer));
    executeElementsTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, new Transfer[] { ExecuteItemTransfer.getInstance() }, new ExecuteSectionDropTargetListener(executeElementsTableViewer, 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) ExecuteItem(org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem) 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)

Example 7 with ExecuteItem

use of org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem 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 8 with ExecuteItem

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

the class ExecuteSubPage method removeSelectedExecuteItems.

public void removeSelectedExecuteItems() {
    if (executeSectionHandler == null || executeElementsTableViewer == null) {
        return;
    }
    StructuredSelection selection = (StructuredSelection) executeElementsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        ExecuteItem item = (ExecuteItem) iterator.next();
        if (item != null) {
            ConfigTreeNodeUtilities.removeChild(executeSectionHandler.getLastSectionRoot(), item.getRoot());
            executeSectionHandler.getExecuteitems().remove(item);
        }
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ExecuteItem(org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem)

Aggregations

ExecuteItem (org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler.ExecuteItem)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 ExecuteSectionHandler (org.eclipse.titan.common.parsers.cfg.indices.ExecuteSectionHandler)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