Search in sources :

Example 16 with ExpansionAdapter

use of org.eclipse.ui.forms.events.ExpansionAdapter in project titan.EclipsePlug-ins by eclipse.

the class StatisticalView method createSection.

private Section createSection() {
    Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION | ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR | ExpandableComposite.EXPANDED);
    TableWrapData td = new TableWrapData(TableWrapData.FILL);
    td.colspan = 2;
    section.setLayoutData(td);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(true);
        }
    });
    File file = new File(this.logFileMetaData.getFilePath());
    Date date = new Date(file.lastModified());
    section.setText(file.getName());
    section.setData(this.logFileMetaData.getProjectRelativePath());
    // $NON-NLS-1$
    section.setDescription(this.logFileMetaData.getProjectRelativePath() + " " + date.toString());
    Composite sectionClient = toolkit.createComposite(section);
    sectionClient.setLayout(new GridLayout());
    createAmountTable(sectionClient);
    this.ecError = toolkit.createExpandableComposite(sectionClient, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    // $NON-NLS-1$
    ecError.setText("Error test cases");
    this.errorTestCasesTable = createTestCaseTable(ecError);
    ecError.setClient(this.errorTestCasesTable);
    ecError.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(true);
        }
    });
    this.ecFail = toolkit.createExpandableComposite(sectionClient, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    // $NON-NLS-1$
    ecFail.setText("Fail test cases");
    this.failTestCasesTable = createTestCaseTable(ecFail);
    ecFail.setClient(this.failTestCasesTable);
    ecFail.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(true);
        }
    });
    this.ecTestCases = toolkit.createExpandableComposite(sectionClient, ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
    // $NON-NLS-1$
    ecTestCases.setText("Test cases");
    this.testCases = createTestCaseTable(ecTestCases);
    ecTestCases.setClient(this.testCases);
    ecTestCases.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(true);
        }
    });
    section.setClient(sectionClient);
    cachedSections.put(this.logFileMetaData.getProjectRelativePath(), section);
    return section;
}
Also used : TableWrapData(org.eclipse.ui.forms.widgets.TableWrapData) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Section(org.eclipse.ui.forms.widgets.Section) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) IFile(org.eclipse.core.resources.IFile) File(java.io.File) Date(java.util.Date)

Example 17 with ExpansionAdapter

use of org.eclipse.ui.forms.events.ExpansionAdapter 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 18 with ExpansionAdapter

use of org.eclipse.ui.forms.events.ExpansionAdapter in project titan.EclipsePlug-ins by eclipse.

the class DebugPreferencePage method createExtendableComposite.

/**
 * Creates an expandable composite on the user interface.
 *
 * @param parent
 *                the parent composite where this one can be added to.
 * @param title
 *                the title of the new composite.
 *
 * @return the created composite.
 */
private ExpandableComposite createExtendableComposite(final Composite parent, final String title) {
    final ExpandableComposite ex = new ExpandableComposite(parent, SWT.NONE, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT | ExpandableComposite.COMPACT);
    ex.setText(title);
    ex.setExpanded(false);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    ex.setLayoutData(data);
    ex.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            Composite temp = parent;
            while (temp != null && !(temp instanceof ScrolledComposite)) {
                temp = temp.getParent();
            }
            if (temp != null) {
                Point point = pagecomp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                ((ScrolledComposite) temp).setMinSize(point);
                ((ScrolledComposite) temp).layout(true, true);
            }
        }
    });
    return ex;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) GridData(org.eclipse.swt.layout.GridData) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) Point(org.eclipse.swt.graphics.Point) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent)

Example 19 with ExpansionAdapter

use of org.eclipse.ui.forms.events.ExpansionAdapter 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)

Example 20 with ExpansionAdapter

use of org.eclipse.ui.forms.events.ExpansionAdapter 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

ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)53 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)53 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)43 Composite (org.eclipse.swt.widgets.Composite)42 GridData (org.eclipse.swt.layout.GridData)40 GridLayout (org.eclipse.swt.layout.GridLayout)33 Section (org.eclipse.ui.forms.widgets.Section)28 TableViewer (org.eclipse.jface.viewers.TableViewer)11 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 ICellModifier (org.eclipse.jface.viewers.ICellModifier)7 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)7 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)7 TableColumn (org.eclipse.swt.widgets.TableColumn)7 TableItem (org.eclipse.swt.widgets.TableItem)7 ArrayList (java.util.ArrayList)6 ParseTree (org.antlr.v4.runtime.tree.ParseTree)6 Point (org.eclipse.swt.graphics.Point)6 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5