Search in sources :

Example 1 with GroupItem

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

the class GroupsSubPage method createGroupItemsSection.

private void createGroupItemsSection(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);
    itemsTable = toolkit.createTable(client, SWT.NULL);
    itemsTable.setEnabled(groupSectionHandler != null && selectedGroup != null);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 200;
    gd.widthHint = 100;
    itemsTable.setLayoutData(gd);
    toolkit.paintBordersFor(client);
    itemsTable.setLinesVisible(true);
    itemsTable.setHeaderVisible(true);
    Composite buttons = toolkit.createComposite(client);
    buttons.setLayout(new GridLayout());
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    addItem = toolkit.createButton(buttons, "Add item", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    addItem.setLayoutData(gd);
    addItem.setEnabled(groupSectionHandler != null && selectedGroup != null);
    addItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (groupSectionHandler == null) {
                return;
            }
            if (selectedGroup == null) {
                return;
            }
            GroupItem newItem;
            ParseTree hidden = new AddedParseTree(", ");
            ConfigTreeNodeUtilities.addChild(selectedGroup.getRoot(), hidden);
            ParseTree node = new AddedParseTree("item");
            ConfigTreeNodeUtilities.addChild(selectedGroup.getRoot(), node);
            newItem = new GroupSectionHandler.GroupItem(node);
            selectedGroup.getGroupItems().add(newItem);
            internalRefresh();
            itemsTable.select(selectedGroup.getGroupItems().size() - 1);
            itemsTable.showSelection();
            editor.setDirty();
        }
    });
    removeItem = toolkit.createButton(buttons, "Remove item", SWT.PUSH);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    removeItem.setLayoutData(gd);
    removeItem.setEnabled(groupSectionHandler != null && selectedGroup != null);
    removeItem.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            if (itemsTableViewer == null || groupSectionHandler == null) {
                return;
            }
            removeSelectedItems();
            internalRefresh();
            editor.setDirty();
        }
    });
    totalGroupItemsLabel = toolkit.createLabel(buttons, "");
    if (selectedGroup == null) {
        totalGroupItemsLabel.setText("Total: ");
    } else {
        totalGroupItemsLabel.setText("Total: " + selectedGroup.getGroupItems().size());
    }
    gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    totalGroupItemsLabel.setLayoutData(gd);
    section.setText("Group items");
    section.setDescription("Specify items of the selected group.");
    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(itemsTable, SWT.LEFT, 0);
    column.setText("Group item");
    column.setWidth(150);
    column.setMoveable(false);
    itemsTableViewer = new TableViewer(itemsTable);
    itemsTableViewer.setContentProvider(new GroupItemDataContentProvider());
    itemsTableViewer.setLabelProvider(new GroupItemDataLabelProvider());
    itemsTableViewer.setInput(null);
    itemsTableViewer.setColumnProperties(new String[] { "groupItem" });
    itemsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(itemsTable) });
    itemsTableViewer.setCellModifier(new ICellModifier() {

        @Override
        public boolean canModify(final Object element, final String property) {
            return true;
        }

        @Override
        public Object getValue(final Object element, final String property) {
            GroupItemDataLabelProvider labelProvider = (GroupItemDataLabelProvider) itemsTableViewer.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) {
                GroupItem item = (GroupItem) ((TableItem) element).getData();
                ConfigTreeNodeUtilities.setText(item.getItem(), (String) value);
                itemsTableViewer.refresh(item);
                editor.setDirty();
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableItem(org.eclipse.swt.widgets.TableItem) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) 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) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem) 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 2 with GroupItem

use of org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem 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 3 with GroupItem

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

the class GroupsSubPage method removeSelectedItems.

private void removeSelectedItems() {
    if (itemsTableViewer == null || groupSectionHandler == null) {
        return;
    }
    StructuredSelection selection = (StructuredSelection) itemsTableViewer.getSelection();
    // remove the selected elements
    for (Iterator<?> iterator = selection.iterator(); iterator.hasNext(); ) {
        GroupItem item = (GroupItem) iterator.next();
        if (item != null) {
            final List<GroupItem> groupItems = selectedGroup.getGroupItems();
            final int size = groupItems.size();
            if (size == 1) {
                // Each group must have at least one item.
                return;
            }
            final ParseTree selected = item.getItem();
            final ParseTree parent = selectedGroup.getRoot();
            // items are separated by ","
            // first 2 items of the rule are: group name, ":=", they are not items
            ConfigTreeNodeUtilities.removeChildWithSeparator(parent, selected, ",", 2);
            selectedGroup.getGroupItems().remove(item);
        }
    }
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) GroupItem(org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem) AddedParseTree(org.eclipse.titan.common.parsers.AddedParseTree) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 AddedParseTree (org.eclipse.titan.common.parsers.AddedParseTree)3 GroupItem (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.GroupItem)3 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)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 GroupSectionHandler (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler)1 Group (org.eclipse.titan.common.parsers.cfg.indices.GroupSectionHandler.Group)1 ExpansionAdapter (org.eclipse.ui.forms.events.ExpansionAdapter)1 ExpansionEvent (org.eclipse.ui.forms.events.ExpansionEvent)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1