use of org.eclipse.titan.common.parsers.cfg.indices.ModuleParameterSectionHandler.ModuleParameter in project titan.EclipsePlug-ins by eclipse.
the class ModuleParameterSectionDropTargetListener method drop.
@Override
public void drop(final DropTargetEvent event) {
if (ModuleParameterTransfer.getInstance().isSupportedType(event.currentDataType)) {
if (event.item != null && viewer.getInput() != null) {
ModuleParameterSectionHandler moduleParameterSectionHandler = (ModuleParameterSectionHandler) viewer.getInput();
ModuleParameter element = (ModuleParameter) event.item.getData();
ModuleParameter[] items = (ModuleParameter[]) event.data;
int baseindex = moduleParameterSectionHandler.getModuleParameters().indexOf(element);
final ParseTree parent = moduleParameterSectionHandler.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++) {
moduleParameterSectionHandler.getModuleParameters().add(++baseindex, items[i]);
}
moduleParameterSectionHandler.getModuleParameters().add(++baseindex, items[items.length - 1]);
}
viewer.refresh(true);
editor.setDirty();
}
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.ModuleParameterSectionHandler.ModuleParameter in project titan.EclipsePlug-ins by eclipse.
the class ModuleParameterSectionPage method createModuleParameterTable.
private void createModuleParameterTable(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);
moduleParametersTable = toolkit.createTable(client, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
moduleParametersTable.setEnabled(moduleParametersHandler != null);
TableColumn column = new TableColumn(moduleParametersTable, SWT.LEFT, 0);
column.setText("Module name");
column.setWidth(150);
column.setMoveable(false);
column = new TableColumn(moduleParametersTable, SWT.LEFT, 1);
column.setText("Module parameter name");
column.setMoveable(false);
column.setWidth(200);
moduleParametersTable.setHeaderVisible(true);
moduleParametersTable.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;
moduleParametersTable.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(moduleParametersHandler != null);
add.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// Do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (moduleParametersHandler == null) {
return;
}
if (moduleParametersHandler.getLastSectionRoot() == null) {
createNewModuleParameterSection();
}
ModuleParameter newModuleParameter = createNewParameter();
if (newModuleParameter == null) {
return;
}
ConfigTreeNodeUtilities.addChild(moduleParametersHandler.getLastSectionRoot(), newModuleParameter.getRoot());
moduleParametersHandler.getModuleParameters().add(newModuleParameter);
internalRefresh();
moduleParametersTableViewer.setSelection(new StructuredSelection(newModuleParameter));
parameterValueText.setText(newModuleParameter.getValue().getText());
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(moduleParametersHandler != null);
remove.addSelectionListener(new SelectionListener() {
@Override
public void widgetDefaultSelected(final SelectionEvent e) {
// Do nothing
}
@Override
public void widgetSelected(final SelectionEvent e) {
if (moduleParametersTableViewer == null || moduleParametersHandler == null) {
return;
}
removeSelectedParameters();
if (moduleParametersHandler.getModuleParameters().isEmpty()) {
removeModuleParameterSection();
}
/*
* ASTFrame frame = new
* ASTFrame("Tree structure"
* ,editor.parseTreeRoot);
* frame.setVisible(true);
*/
internalRefresh();
editor.setDirty();
}
});
totalModuleParametersLabel = toolkit.createLabel(buttons, "Total: 0");
gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
totalModuleParametersLabel.setLayoutData(gd);
section.setText("Module parameters");
section.setDescription("Specify the list of module parameters 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);
moduleParametersTableViewer = new TableViewer(moduleParametersTable);
moduleParametersTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(final SelectionChangedEvent event) {
StructuredSelection selection = (StructuredSelection) event.getSelection();
if (selection.size() != 1) {
parameterValueText.setEnabled(false);
return;
}
ModuleParameter moduleParameter = (ModuleParameter) selection.getFirstElement();
if (moduleParameter != null) {
if (moduleParameter.getValue() != null) {
final String moduleParamValueText = CfgParseTreePrinter.toStringWithHidden(moduleParameter.getValue(), editor.getTokens(), false);
parameterValueText.setText(moduleParamValueText);
}
valueChanged = true;
}
parameterValueText.setEnabled(moduleParametersHandler != null && moduleParameter != null);
}
});
moduleParametersTableViewer.setContentProvider(new ModuleParameterDataContentProvider());
moduleParametersTableViewer.setLabelProvider(new ModuleParameterDataLabelProvider());
moduleParametersTableViewer.setInput(moduleParametersHandler);
moduleParametersTableViewer.setColumnProperties(COLUMN_NAMES);
moduleParametersTableViewer.setCellEditors(new TextCellEditor[] { new TextCellEditor(moduleParametersTable), new TextCellEditor(moduleParametersTable) });
moduleParametersTableViewer.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);
ModuleParameterDataLabelProvider labelProvider = (ModuleParameterDataLabelProvider) moduleParametersTableViewer.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) {
ModuleParameter moduleParameter = (ModuleParameter) ((TableItem) element).getData();
switch(columnIndex) {
case 0:
// MODULE_NAME
if (moduleParameter.getModuleName() != null) {
String newValue = ((String) value).trim();
if (newValue != null) {
ConfigTreeNodeUtilities.setText(moduleParameter.getModuleName(), newValue);
ConfigTreeNodeUtilities.setText(moduleParameter.getSeparator(), "".equals(newValue) ? "" : ".");
}
}
break;
case 1:
// PARAMETER_NAME
ConfigTreeNodeUtilities.setText(moduleParameter.getParameterName(), ((String) value).trim());
break;
default:
break;
}
moduleParametersTableViewer.refresh(moduleParameter);
editor.setDirty();
}
}
});
moduleParametersTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ModuleParameterTransfer.getInstance() }, new ModuleParameterSectionDragSourceListener(this, moduleParametersTableViewer));
moduleParametersTableViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { ModuleParameterTransfer.getInstance() }, new ModuleParameterSectionDropTargetListener(moduleParametersTableViewer, editor));
}
use of org.eclipse.titan.common.parsers.cfg.indices.ModuleParameterSectionHandler.ModuleParameter in project titan.EclipsePlug-ins by eclipse.
the class ModuleParameterTransfer method nativeToJava.
@Override
protected ModuleParameter[] nativeToJava(final TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
try {
int n = in.readInt();
ModuleParameter[] items = new ModuleParameter[n];
for (int i = 0; i < n; i++) {
ModuleParameter newModuleParameter = new ModuleParameterSectionHandler.ModuleParameter();
final ParseTree root = new ParserRuleContext();
newModuleParameter.setRoot(root);
// module name part
final String hiddenBeforeModuleName = in.readUTF();
final String moduleName = in.readUTF();
final String hiddenBeforeSeparator = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree("\n"));
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBeforeModuleName));
newModuleParameter.setModuleName(new AddedParseTree(moduleName));
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBeforeSeparator));
ConfigTreeNodeUtilities.addChild(root, newModuleParameter.getModuleName());
final boolean isModuleNameEmpty = moduleName == null || moduleName.isEmpty();
newModuleParameter.setSeparator(new AddedParseTree(isModuleNameEmpty ? "" : "."));
ConfigTreeNodeUtilities.addChild(root, newModuleParameter.getSeparator());
// parameter name part
final String hiddenBeforeParameterName = in.readUTF();
final String parameterName = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBeforeParameterName));
newModuleParameter.setParameterName(new AddedParseTree(parameterName));
ConfigTreeNodeUtilities.addChild(root, newModuleParameter.getParameterName());
// the := sign and the hidden stuff before it
final String hiddenBeforeOperator = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBeforeOperator));
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(" := "));
// the value part
final String hiddenBeforeValue = in.readUTF();
final String value = in.readUTF();
ConfigTreeNodeUtilities.addChild(root, new AddedParseTree(hiddenBeforeValue));
newModuleParameter.setValue(new AddedParseTree(value));
ConfigTreeNodeUtilities.addChild(root, newModuleParameter.getValue());
// put it under the root node
items[i] = newModuleParameter;
}
return items;
} catch (IOException e) {
ErrorReporter.logExceptionStackTrace(e);
return new ModuleParameter[] {};
}
}
use of org.eclipse.titan.common.parsers.cfg.indices.ModuleParameterSectionHandler.ModuleParameter in project titan.EclipsePlug-ins by eclipse.
the class ModuleParameterTransfer method javaToNative.
@Override
protected void javaToNative(final Object object, final TransferData transferData) {
ModuleParameter[] items = (ModuleParameter[]) 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.ModuleParameterSectionHandler.ModuleParameter in project titan.EclipsePlug-ins by eclipse.
the class ModuleParameterSectionDragSourceListener method dragSetData.
@Override
public void dragSetData(final DragSourceEvent event) {
if (ModuleParameterTransfer.getInstance().isSupportedType(event.dataType)) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
List<ModuleParameter> items = new ArrayList<ModuleParameter>();
if (!selection.isEmpty()) {
for (Iterator<?> it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
if (element instanceof ModuleParameter) {
items.add((ModuleParameter) element);
}
}
event.data = items.toArray(new ModuleParameter[items.size()]);
}
}
}
Aggregations