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