Search in sources :

Example 16 with ExpansionEvent

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

the class GroupsSubPage method createMainGroupsSection.

void createMainGroupsSection(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);
    groupsTable = toolkit.createTable(client, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    groupsTable.setEnabled(groupSectionHandler != null);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 200;
    gd.widthHint = 100;
    groupsTable.setLayoutData(gd);
    toolkit.paintBordersFor(client);
    groupsTable.setLinesVisible(true);
    groupsTable.setHeaderVisible(true);
    Composite buttons = toolkit.createComposite(client);
    buttons.setLayout(new GridLayout());
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    addGroup = toolkit.createButton(buttons, "Add group", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    addGroup.setLayoutData(gd);
    addGroup.setEnabled(groupSectionHandler != null);
    addGroup.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (groupSectionHandler == null) {
                return;
            }
            if (groupSectionHandler.getLastSectionRoot() == null) {
                createNewGroupsSection();
            }
            Group newGroup = createNewGroup();
            if (newGroup == null) {
                return;
            }
            ConfigTreeNodeUtilities.addChild(groupSectionHandler.getLastSectionRoot(), newGroup.getRoot());
            groupSectionHandler.getGroups().add(newGroup);
            internalRefresh();
            groupsTable.select(groupSectionHandler.getGroups().size() - 1);
            groupsTable.showSelection();
            selectedGroup = newGroup;
            itemsTableViewer.setInput(newGroup);
            refreshItemsbTableViewer();
            editor.setDirty();
        }
    });
    removeGroup = toolkit.createButton(buttons, "Remove group", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    removeGroup.setLayoutData(gd);
    removeGroup.setEnabled(groupSectionHandler != null);
    removeGroup.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (groupsTableViewer == null || groupSectionHandler == null) {
                return;
            }
            removeSelectedGroups();
            if (groupSectionHandler.getGroups().isEmpty()) {
                removeGroupsSection();
            }
            internalRefresh();
            editor.setDirty();
        }
    });
    totalGroupsLabel = toolkit.createLabel(buttons, "Total: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalGroupsLabel.setLayoutData(gd);
    section.setText("Groups");
    section.setDescription("Specify groups of components 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);
    TableColumn column = new TableColumn(groupsTable, SWT.LEFT, 0);
    column.setText("Group name");
    column.setWidth(150);
    column.setMoveable(false);
    groupsTableViewer = new TableViewer(groupsTable);
    groupsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            Group group = (Group) ((StructuredSelection) event.getSelection()).getFirstElement();
            selectedGroup = group;
            itemsTable.setEnabled(groupSectionHandler != null && selectedGroup != null);
            addItem.setEnabled(groupSectionHandler != null && selectedGroup != null);
            removeItem.setEnabled(groupSectionHandler != null && selectedGroup != null);
            itemsTableViewer.setInput(group);
            refreshItemsbTableViewer();
        }
    });
    groupsTableViewer.setContentProvider(new GroupDataContentProvider());
    groupsTableViewer.setLabelProvider(new GroupDataLabelProvider());
    groupsTableViewer.setInput(groupSectionHandler);
    groupsTableViewer.setColumnProperties(new String[] { "groupName" });
    groupsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(groupsTable) });
    groupsTableViewer.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) {
            GroupDataLabelProvider labelProvider = (GroupDataLabelProvider) groupsTableViewer.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) {
                Group group = (Group) ((TableItem) element).getData();
                ConfigTreeNodeUtilities.setText(group.getGroupName(), (String) value);
                groupsTableViewer.refresh(group);
                editor.setDirty();
            }
        }
    });
    refreshGroupsbTableViewer();
}
Also used : Group(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group) 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) 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) 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)

Example 17 with ExpansionEvent

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

the class MCSubPage method createMainControllerSection.

void createMainControllerSection(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));
    section.setText("Main Controller options");
    section.setDescription("Specify the Main Controller directing options for this configuration.");
    section.setExpanded(true);
    section.addExpansionListener(new ExpansionAdapter() {

        @Override
        public void expansionStateChanged(final ExpansionEvent e) {
            form.reflow(false);
        }
    });
    GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
    section.setLayoutData(gd);
    Composite client = toolkit.createComposite(section, SWT.WRAP);
    section.setClient(client);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    client.setLayout(layout);
    toolkit.paintBordersFor(client);
    valueChanged = true;
    toolkit.createLabel(client, "Local Address:");
    localAddressText = toolkit.createText(client, "", SWT.SINGLE);
    localAddressText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    localAddressText.setEnabled(mcSectionHandler != null);
    localAddressText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = localAddressText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getLocalAddressRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getLocalAddressRoot());
                }
                mcSectionHandler.setLocalAddress(null);
                mcSectionHandler.setLocalAddressRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getLocalAddress() == null) {
                // create the node
                createMCSection();
                ParseTree localAddressRoot = new ParserRuleContext();
                mcSectionHandler.setLocalAddressRoot(localAddressRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), localAddressRoot);
                ConfigTreeNodeUtilities.addChild(localAddressRoot, new AddedParseTree("\nlocalAddress := "));
                ParseTree localAddress = new AddedParseTree(temp.trim());
                mcSectionHandler.setLocalAddress(localAddress);
                ConfigTreeNodeUtilities.addChild(localAddressRoot, localAddress);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getLocalAddress(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getLocalAddress() != null) {
        localAddressText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getLocalAddress()));
    }
    toolkit.createLabel(client, "TCP port:");
    tcpPortText = toolkit.createText(client, "", SWT.SINGLE);
    tcpPortText.setEnabled(mcSectionHandler != null);
    tcpPortText.setLayoutData(new GridData(75, SWT.DEFAULT));
    tcpPortText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = tcpPortText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getTcpPortRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getTcpPortRoot());
                }
                mcSectionHandler.setTcpPort(null);
                mcSectionHandler.setTcpPortRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getTcpPort() == null) {
                // create the node
                createMCSection();
                ParseTree tcpPortRoot = new ParserRuleContext();
                mcSectionHandler.setTcpPortRoot(tcpPortRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), tcpPortRoot);
                ConfigTreeNodeUtilities.addChild(tcpPortRoot, new AddedParseTree("\nTCPPort := "));
                ParseTree tcpPort = new AddedParseTree(temp.trim());
                mcSectionHandler.setTcpPort(tcpPort);
                ConfigTreeNodeUtilities.addChild(tcpPortRoot, tcpPort);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getTcpPort(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getTcpPort() != null) {
        tcpPortText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getTcpPort()));
    }
    toolkit.createLabel(client, "Kill timer:");
    killTimerText = toolkit.createText(client, "", SWT.SINGLE);
    killTimerText.setEnabled(mcSectionHandler != null);
    killTimerText.setLayoutData(new GridData(75, SWT.DEFAULT));
    killTimerText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = killTimerText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getKillTimerRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getKillTimerRoot());
                }
                mcSectionHandler.setKillTimer(null);
                mcSectionHandler.setKillTimerRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getKillTimer() == null) {
                // create the node
                createMCSection();
                ParseTree killTimerRoot = new ParserRuleContext();
                mcSectionHandler.setKillTimerRoot(killTimerRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), killTimerRoot);
                ConfigTreeNodeUtilities.addChild(killTimerRoot, new AddedParseTree("\nkillTimer := "));
                ParseTree killTimer = new AddedParseTree(temp.trim());
                mcSectionHandler.setTcpPort(killTimer);
                ConfigTreeNodeUtilities.addChild(killTimerRoot, killTimer);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getKillTimer(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getKillTimer() != null) {
        killTimerText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getKillTimer()));
    }
    toolkit.createLabel(client, "Number of Host Contollers:");
    numHCsText = toolkit.createText(client, "", SWT.SINGLE);
    numHCsText.setEnabled(mcSectionHandler != null);
    numHCsText.setLayoutData(new GridData(75, SWT.DEFAULT));
    numHCsText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = numHCsText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getNumHCsTextRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getNumHCsTextRoot());
                }
                mcSectionHandler.setNumHCsText(null);
                mcSectionHandler.setNumHCsTextRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getNumHCsText() == null) {
                // create the node
                createMCSection();
                ParseTree numHCsTextRoot = new ParserRuleContext();
                mcSectionHandler.setKillTimerRoot(numHCsTextRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), numHCsTextRoot);
                ConfigTreeNodeUtilities.addChild(numHCsTextRoot, new AddedParseTree("\nnumHCs := "));
                ParseTree numHCsText = new AddedParseTree(temp.trim());
                mcSectionHandler.setNumHCsText(numHCsText);
                ConfigTreeNodeUtilities.addChild(numHCsTextRoot, numHCsText);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getNumHCsText(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getNumHCsText() != null) {
        numHCsText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getNumHCsText()));
    }
    toolkit.createLabel(client, "Use of unix domain socket communication:");
    unixDomainSocketText = new CCombo(client, SWT.FLAT);
    unixDomainSocketText.setEnabled(mcSectionHandler != null);
    unixDomainSocketText.setLayoutData(new GridData(75, SWT.DEFAULT));
    unixDomainSocketText.add("Yes");
    unixDomainSocketText.add("No");
    unixDomainSocketText.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (valueChanged || mcSectionHandler == null) {
                return;
            }
            editor.setDirty();
            String temp = unixDomainSocketText.getText();
            if (temp == null || temp.length() == 0) {
                // remove the node
                if (mcSectionHandler.getUnixDomainSocketRoot() != null) {
                    ConfigTreeNodeUtilities.removeChild(mcSectionHandler.getLastSectionRoot(), mcSectionHandler.getUnixDomainSocketRoot());
                }
                mcSectionHandler.setUnixDomainSocket(null);
                mcSectionHandler.setUnixDomainSocketRoot(null);
                removeMCSection();
            } else if (mcSectionHandler.getUnixDomainSocket() == null) {
                // create the node
                createMCSection();
                ParseTree unixDomainSocketRoot = new ParserRuleContext();
                mcSectionHandler.setUnixDomainSocketRoot(unixDomainSocketRoot);
                ConfigTreeNodeUtilities.addChild(mcSectionHandler.getLastSectionRoot(), unixDomainSocketRoot);
                ConfigTreeNodeUtilities.addChild(unixDomainSocketRoot, new AddedParseTree("\nUnixSocketsEnabled := "));
                ParseTree unixDomainSocket = new AddedParseTree(temp.trim());
                mcSectionHandler.setUnixDomainSocket(unixDomainSocket);
                ConfigTreeNodeUtilities.addChild(unixDomainSocketRoot, unixDomainSocket);
            } else {
                // simple modification
                ConfigTreeNodeUtilities.setText(mcSectionHandler.getUnixDomainSocket(), temp.trim());
            }
        }
    });
    if (mcSectionHandler != null && mcSectionHandler.getUnixDomainSocket() != null) {
        unixDomainSocketText.setText(ConfigTreeNodeUtilities.toString(mcSectionHandler.getUnixDomainSocket()));
    }
    valueChanged = false;
}
Also used : ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) Section(org.eclipse.ui.forms.widgets.Section) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CCombo(org.eclipse.swt.custom.CCombo) GridData(org.eclipse.swt.layout.GridData) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 18 with ExpansionEvent

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

the class ModuleParameterSectionPage method createModuleParameterTable.

private void createModuleParameterTable(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);
    moduleParametersTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    moduleParametersTable.setEnabled(moduleParametersHandler != null);
    TableColumn column = new TableColumn(moduleParametersTable, SWT.LEFT, 0);
    column.setText("Module name");
    column.setWidth(150);
    column.setMoveable(false);
    column = new TableColumn(moduleParametersTable, SWT.LEFT, 1);
    column.setText("Module parameter name");
    column.setMoveable(false);
    column.setWidth(200);
    moduleParametersTable.setHeaderVisible(true);
    moduleParametersTable.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;
    moduleParametersTable.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(moduleParametersHandler != null);
    add.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (moduleParametersHandler == null) {
                return;
            }
            if (moduleParametersHandler.getLastSectionRoot() == null) {
                createNewModuleParameterSection();
            }
            ModuleParameter newModuleParameter = createNewParameter();
            if (newModuleParameter == null) {
                return;
            }
            ConfigTreeNodeUtilities.addChild(moduleParametersHandler.getLastSectionRoot(), newModuleParameter.getRoot());
            moduleParametersHandler.getModuleParameters().add(newModuleParameter);
            internalRefresh();
            moduleParametersTableViewer.setSelection(new StructuredSelection(newModuleParameter));
            parameterValueText.setText(newModuleParameter.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(moduleParametersHandler != null);
    remove.addSelectionListener(new SelectionListener() {

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

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (moduleParametersTableViewer == null || moduleParametersHandler == null) {
                return;
            }
            removeSelectedParameters();
            if (moduleParametersHandler.getModuleParameters().isEmpty()) {
                removeModuleParameterSection();
            }
            /*
				 * ASTFrame frame = new
				 * ASTFrame("Tree structure"
				 * ,editor.parseTreeRoot);
				 * frame.setVisible(true);
				 */
            internalRefresh();
            editor.setDirty();
        }
    });
    totalModuleParametersLabel = toolkit.createLabel(buttons, "Total: 0");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalModuleParametersLabel.setLayoutData(gd);
    section.setText("Module parameters");
    section.setDescription("Specify the list of module 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);
    moduleParametersTableViewer = new TableViewer(moduleParametersTable);
    moduleParametersTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            StructuredSelection selection = (StructuredSelection) event.getSelection();
            if (selection.size() != 1) {
                parameterValueText.setEnabled(false);
                return;
            }
            ModuleParameter moduleParameter = (ModuleParameter) selection.getFirstElement();
            if (moduleParameter != null) {
                if (moduleParameter.getValue() != null) {
                    final String moduleParamValueText = CfgParseTreePrinter.toStringWithHidden(moduleParameter.getValue(), editor.getTokens(), false);
                    parameterValueText.setText(moduleParamValueText);
                }
                valueChanged = true;
            }
            parameterValueText.setEnabled(moduleParametersHandler != null && moduleParameter != null);
        }
    });
    moduleParametersTableViewer.setContentProvider(new ModuleParameterDataContentProvider());
    moduleParametersTableViewer.setLabelProvider(new ModuleParameterDataLabelProvider());
    moduleParametersTableViewer.setInput(moduleParametersHandler);
    moduleParametersTableViewer.setColumnProperties(COLUMN_NAMES);
    moduleParametersTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(moduleParametersTable), new TextCellEditor(moduleParametersTable) });
    moduleParametersTableViewer.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);
            ModuleParameterDataLabelProvider labelProvider = (ModuleParameterDataLabelProvider) moduleParametersTableViewer.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) {
                ModuleParameter moduleParameter = (ModuleParameter) ((TableItem) element).getData();
                switch(columnIndex) {
                    case 0:
                        // MODULE_NAME
                        if (moduleParameter.getModuleName() != null) {
                            String newValue = ((String) value).trim();
                            if (newValue != null) {
                                ConfigTreeNodeUtilities.setText(moduleParameter.getModuleName(), newValue);
                                ConfigTreeNodeUtilities.setText(moduleParameter.getSeparator(), "".equals(newValue) ? "" : ".");
                            }
                        }
                        break;
                    case 1:
                        // PARAMETER_NAME
                        ConfigTreeNodeUtilities.setText(moduleParameter.getParameterName(), ((String) value).trim());
                        break;
                    default:
                        break;
                }
                moduleParametersTableViewer.refresh(moduleParameter);
                editor.setDirty();
            }
        }
    });
    moduleParametersTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ModuleParameterTransfer.getInstance() }, new ModuleParameterSectionDragSourceListener(this, moduleParametersTableViewer));
    moduleParametersTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ModuleParameterTransfer.getInstance() }, new ModuleParameterSectionDropTargetListener(moduleParametersTableViewer, 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) ModuleParameter(org.eclipse.titan.common.parsers.cfg.indices.ModuleParameterSectionHandler.ModuleParameter) 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 19 with ExpansionEvent

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

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

Aggregations

ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)58 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)53 GridData (org.eclipse.swt.layout.GridData)46 Composite (org.eclipse.swt.widgets.Composite)46 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)46 GridLayout (org.eclipse.swt.layout.GridLayout)38 Section (org.eclipse.ui.forms.widgets.Section)30 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 TableViewer (org.eclipse.jface.viewers.TableViewer)11 ArrayList (java.util.ArrayList)7 ICellModifier (org.eclipse.jface.viewers.ICellModifier)7 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)7 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)7 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Point (org.eclipse.swt.graphics.Point)7 Label (org.eclipse.swt.widgets.Label)7 TableColumn (org.eclipse.swt.widgets.TableColumn)7 TableItem (org.eclipse.swt.widgets.TableItem)7 ParseTree (org.antlr.v4.runtime.tree.ParseTree)6 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)6