Search in sources :

Example 1 with Group

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

the class GroupsSubPage method createNewGroup.

private Group createNewGroup() {
    if (groupSectionHandler == null) {
        return null;
    }
    final Group newGroup = new GroupSectionHandler.Group();
    final ParseTree root = new ParserRuleContext();
    newGroup.setRoot(root);
    final ParseTree groupName = new AddedParseTree("group_name");
    final ParseTree item = new AddedParseTree("item");
    newGroup.setGroupName(groupName);
    newGroup.setGroupItems(new ArrayList<GroupItem>());
    newGroup.getGroupItems().add(new GroupSectionHandler.GroupItem(item));
    ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode("\n"));
    ConfigTreeNodeUtilities.addChild(root, groupName);
    ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
    ConfigTreeNodeUtilities.addChild(root, item);
    return newGroup;
}
Also used : Group(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) GroupSectionHandler(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem)

Example 2 with Group

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

the class GroupsSubPage method removeSelectedGroups.

private void removeSelectedGroups() {
    if (groupsTableViewer == null || groupSectionHandler == null) {
        return;
    }
    StructuredSelection selection = (StructuredSelection) groupsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        Group group = (Group) iterator.next();
        if (group != null) {
            ConfigTreeNodeUtilities.removeChild(groupSectionHandler.getLastSectionRoot(), group.getRoot());
            groupSectionHandler.getGroups().remove(group);
        }
    }
}
Also used : Group(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 3 with Group

use of org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group 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)

Aggregations

Group (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1 TableItem (org.eclipse.swt.widgets.TableItem)1 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)1 GroupSectionHandler (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler)1 GroupItem (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem)1 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)1