use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefineItemTransfer method javaToNative.
@Override
protected void javaToNative(final Object object, final TransferData transferData) {
Definition[] items = (Definition[]) object;
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOut);
byte[] bytes = null;
try {
out.writeInt(items.length);
for (int i = 0; i < items.length; i++) {
out.writeUTF(convertToString(items[i].getRoot()));
}
out.close();
bytes = byteOut.toByteArray();
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
}
if (bytes != null) {
super.javaToNative(bytes, transferData);
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefineItemTransfer method nativeToJava.
@Override
protected Definition[] nativeToJava(final TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
int n = in.readInt();
Definition[] items = new Definition[n];
String name;
String value;
String hiddenBefore;
for (int i = 0; i < n; i++) {
items[i] = new DefineSectionHandler.Definition();
final ParseTree root = new ParserRuleContext();
items[i].setRoot(root);
hiddenBefore = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
name = in.readUTF();
final ParseTree nameNode = new AddedParseTree(name);
items[i].setDefinitionName(nameNode);
ConfigTreeNodeUtilities.addChild(root, nameNode);
hiddenBefore = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(":="));
hiddenBefore = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, ConfigTreeNodeUtilities.createHiddenTokenNode(hiddenBefore));
value = in.readUTF();
final ParseTree valueNode = new AddedParseTree(value);
items[i].setDefinitionValue(valueNode);
ConfigTreeNodeUtilities.addChild(root, valueNode);
}
return items;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
return new Definition[] {};
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefineSectionDragSourceListener method dragSetData.
@Override
public void dragSetData(final DragSourceEvent event) {
if (DefineItemTransfer.getInstance().isSupportedType(event.dataType)) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
List<Definition> items = new ArrayList<Definition>();
if (!selection.isEmpty()) {
for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
if (element instanceof Definition) {
items.add((Definition) element);
}
}
event.data = items.toArray(new Definition[items.size()]);
}
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefineSectionDropTargetListener method drop.
@Override
public void drop(final DropTargetEvent event) {
if (DefineItemTransfer.getInstance().isSupportedType(event.currentDataType)) {
if (event.item != null && viewer.getInput() != null) {
DefineSectionHandler defineSectionHandler = (DefineSectionHandler) viewer.getInput();
Definition element = (Definition) event.item.getData();
Definition[] items = (Definition[]) event.data;
int baseindex = defineSectionHandler.getDefinitions().indexOf(element);
final ParseTree parent = defineSectionHandler.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++) {
defineSectionHandler.getDefinitions().add(++baseindex, items[i]);
}
defineSectionHandler.getDefinitions().add(++baseindex, items[items.length - 1]);
}
viewer.refresh(true);
editor.setDirty();
}
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.DefineSectionHandler.Definition in project titan.EclipsePlug-ins by eclipse.
the class DefineSubPage method createDefinitionSection.
void createDefinitionSection(final Composite parent, final ScrolledForm form, final FormToolkit toolkit) {
Section section = toolkit.createSection(parent, ExpandableComposite.TWISTIE | 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);
defineElementsTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
defineElementsTable.setEnabled(defineSectionHandler != null);
TableColumn column = new TableColumn(defineElementsTable, SWT.LEFT, 0);
column.setText("Definition name");
column.setMoveable(false);
column.setWidth(150);
column = new TableColumn(defineElementsTable, SWT.LEFT, 1);
column.setText("Definition value");
column.setWidth(300);
column.setMoveable(false);
defineElementsTable.setHeaderVisible(true);
defineElementsTable.setLinesVisible(true);
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;
defineElementsTable.setLayoutData(gd);
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(defineSectionHandler != null);
add.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// Do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (defineSectionHandler == null) {
return;
}
if (defineSectionHandler.getLastSectionRoot() == null) {
createNewDefineSection();
}
final Definition newItem = createNewDefineItem();
if (newItem == null) {
return;
}
ConfigTreeNodeUtilities.addChild(defineSectionHandler.getLastSectionRoot(), newItem.getRoot());
defineSectionHandler.getDefinitions().add(newItem);
internalRefresh();
defineElementsTable.select(defineSectionHandler.getDefinitions().size() - 1);
defineElementsTable.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(defineSectionHandler != null);
remove.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// Do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (defineElementsTableViewer == null || defineSectionHandler == null) {
return;
}
removeSelectedDefineItems();
if (defineSectionHandler.getDefinitions().isEmpty()) {
removeDefineSection();
}
internalRefresh();
editor.setDirty();
}
});
totalDefineElementsLabel = toolkit.createLabel(buttons, "Total defined: 0");
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
totalDefineElementsLabel.setLayoutData(gd);
section.setText("Definitions");
section.setDescription("Specify the list of Definitions 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);
defineElementsTableViewer = new TableViewer(defineElementsTable);
defineElementsTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
// not needed this time
}
});
defineElementsTableViewer.setContentProvider(new DefineDataContentProvider());
defineElementsTableViewer.setLabelProvider(new DefineDataLabelProvider());
defineElementsTableViewer.setInput(defineSectionHandler);
defineElementsTableViewer.setColumnProperties(COLUMN_NAMES);
defineElementsTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(defineElementsTable), new TextCellEditor(defineElementsTable) });
defineElementsTableViewer.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);
DefineDataLabelProvider labelProvider = (DefineDataLabelProvider) defineElementsTableViewer.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) {
Definition definition = (Definition) ((TableItem) element).getData();
switch(columnIndex) {
case 0:
ConfigTreeNodeUtilities.setText(definition.getDefinitionName(), ((String) value).trim());
break;
case 1:
ConfigTreeNodeUtilities.setText(definition.getDefinitionValue(), ((String) value).trim());
break;
default:
break;
}
defineElementsTableViewer.refresh(definition);
editor.setDirty();
}
}
});
defineElementsTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { DefineItemTransfer.getInstance() }, new DefineSectionDragSourceListener(this, defineElementsTableViewer));
defineElementsTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_DEFAULT, new Transfer[] { DefineItemTransfer.getInstance() }, new DefineSectionDropTargetListener(defineElementsTableViewer, editor));
internalRefresh();
}
Aggregations