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();
}
}
});
}
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;
}
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);
}
}
}
Aggregations