use of org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component in project titan.EclipsePlug-ins by eclipse.
the class ComponentSectionDropTargetListener method drop.
@Override
public void drop(final DropTargetEvent event) {
if (ComponentItemTransfer.getInstance().isSupportedType(event.currentDataType)) {
if (event.item != null && viewer.getInput() != null) {
ComponentSectionHandler componentSectionHandler = (ComponentSectionHandler) viewer.getInput();
Component element = (Component) event.item.getData();
Component[] items = (Component[]) event.data;
int baseindex = componentSectionHandler.getComponents().indexOf(element);
final ParseTree parent = componentSectionHandler.getLastSectionRoot();
ConfigTreeNodeUtilities.removeChild(parent, element.getRoot());
ConfigTreeNodeUtilities.addChild(parent, element.getRoot(), baseindex);
if (items.length > 0) {
for (int i = 0; i < items.length - 1; i++) {
componentSectionHandler.getComponents().add(++baseindex, items[i]);
}
componentSectionHandler.getComponents().add(++baseindex, items[items.length - 1]);
}
viewer.refresh(true);
editor.setDirty();
}
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component in project titan.EclipsePlug-ins by eclipse.
the class ComponentsDataLabelProvider method getColumnText.
@Override
public String getColumnText(final Object element, final int columnIndex) {
if (element != null && element instanceof Component) {
Component parameter = (Component) element;
String text;
switch(columnIndex) {
case 0:
if (parameter.getComponentName() == null) {
return "";
}
text = parameter.getComponentName().getText();
if (text == null || text.length() == 0) {
text = ConfigTreeNodeUtilities.toString(parameter.getComponentName());
}
return text;
case 1:
if (parameter.getHostName() == null) {
return "";
}
text = parameter.getHostName().getText();
if (text == null || text.length() == 0) {
text = ConfigTreeNodeUtilities.toString(parameter.getHostName());
}
return text;
default:
return "";
}
}
return "";
}
use of org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component in project titan.EclipsePlug-ins by eclipse.
the class ComponentsSubPage method createComponentsSection.
void createComponentsSection(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);
componentsTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
componentsTable.setEnabled(componentsSectionHandler != 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;
componentsTable.setLayoutData(gd);
componentsTable.setLinesVisible(true);
componentsTable.setHeaderVisible(true);
TableColumn column = new TableColumn(componentsTable, SWT.LEFT, 0);
column.setText("Component name");
column.setWidth(130);
column.setMoveable(false);
column = new TableColumn(componentsTable, SWT.LEFT, 1);
column.setText("Host name");
column.setWidth(100);
column.setMoveable(false);
componentsTableViewer = new TableViewer(componentsTable);
componentsTableViewer.setContentProvider(new ComponentsDataContentProvider());
componentsTableViewer.setLabelProvider(new ComponentsDataLabelProvider());
componentsTableViewer.setInput(componentsSectionHandler);
componentsTableViewer.setColumnProperties(COLUMN_NAMES);
final TextCellEditor[] cellEditors = new TextCellEditor[] { new TextCellEditor(componentsTable), new TextCellEditor(componentsTable) };
componentsTableViewer.setCellEditors(cellEditors);
componentsTableViewer.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);
ComponentsDataLabelProvider labelProvider = (ComponentsDataLabelProvider) componentsTableViewer.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) {
Component component = (Component) ((TableItem) element).getData();
switch(columnIndex) {
case 0:
ConfigTreeNodeUtilities.setText(component.getComponentName(), ((String) value).trim());
break;
case 1:
ConfigTreeNodeUtilities.setText(component.getHostName(), ((String) value).trim());
break;
default:
break;
}
componentsTableViewer.refresh(component);
editor.setDirty();
}
}
});
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(componentsSectionHandler != null);
add.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (componentsSectionHandler == null) {
return;
}
if (componentsSectionHandler.getLastSectionRoot() == null) {
createNewComponentsSection();
}
Component newComponent = createNewComponent();
if (newComponent == null) {
return;
}
ConfigTreeNodeUtilities.addChild(componentsSectionHandler.getLastSectionRoot(), newComponent.getRoot());
componentsSectionHandler.getComponents().add(newComponent);
internalRefresh();
componentsTable.select(componentsSectionHandler.getComponents().size() - 1);
componentsTable.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(componentsSectionHandler != null);
remove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (componentsTableViewer == null || componentsSectionHandler == null) {
return;
}
removeSelectedComponents();
if (componentsSectionHandler.getComponents().isEmpty()) {
removeComponentsSection();
}
internalRefresh();
editor.setDirty();
}
});
totalComponentsLabel = toolkit.createLabel(buttons, "Total: 0");
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
totalComponentsLabel.setLayoutData(gd);
section.setText("Components");
section.setDescription("Specify the list of remote 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(SWT.FILL, SWT.FILL, true, true);
section.setLayoutData(gd);
final ComponentItemTransfer instance = ComponentItemTransfer.getInstance();
componentsTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { instance }, new ComponentSectionDragSourceListener(this, componentsTableViewer));
componentsTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, new Transfer[] { instance }, new ComponentSectionDropTargetListener(componentsTableViewer, editor));
internalRefresh();
}
use of org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component in project titan.EclipsePlug-ins by eclipse.
the class ComponentSectionDragSourceListener method dragStart.
@Override
public void dragStart(final DragSourceEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
event.doit = !selection.isEmpty() && (selection.getFirstElement() instanceof Component);
}
use of org.eclipse.titan.common.parsers.cfg.indices.ComponentSectionHandler.Component in project titan.EclipsePlug-ins by eclipse.
the class ComponentSectionDragSourceListener method dragSetData.
@Override
public void dragSetData(final DragSourceEvent event) {
if (ComponentItemTransfer.getInstance().isSupportedType(event.dataType)) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
List<Component> items = new ArrayList<Component>();
if (!selection.isEmpty()) {
for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
if (element instanceof Component) {
items.add((Component) element);
}
}
event.data = items.toArray(new Component[items.size()]);
}
}
}
Aggregations