use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasUI method checkKeyValue.
private boolean checkKeyValue(String oldValue, String newValue) {
String errorMsg = null;
boolean canModify = true;
if (!Pattern.matches(SCHEMA_NAME_PATTERN, newValue)) {
errorMsg = "'" + newValue + "' is invalid value.";
} else {
final Object input = schemaTreeViewer.getInput();
if (input instanceof SchemasKeyData) {
List<String> list = new ArrayList<String>();
final List<SchemasKeyData> children = ((SchemasKeyData) input).getChildren();
for (SchemasKeyData schema : children) {
final String name = schema.getUniqueRecord();
if (!name.equals(oldValue)) {
list.add(name.toUpperCase());
}
}
if (newValue != null && list.contains(newValue.toUpperCase())) {
errorMsg = "'" + newValue + "' already exist.";
}
}
}
if (errorMsg != null) {
MessageDialog.openError(schemaTreeViewer.getTree().getShell(), "Invalid value", errorMsg);
canModify = false;
}
return canModify;
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class UIManager method enableMovedRecord.
public boolean enableMovedRecord(TreeViewer schemaTreeViewer, boolean left) {
if (schemaTreeViewer == null) {
return false;
}
ISelection selection = schemaTreeViewer.getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.size() == 1) {
Object element = structuredSelection.getFirstElement();
if (element instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) element;
SchemasKeyData parent = data.getParent();
int index = parent.getChildren().indexOf(data);
if (left) {
SchemasKeyData grandfather = parent.getParent();
if (grandfather == null) {
// in root.
return false;
}
if (index != parent.getChildren().size() - 1) {
// not the end of children.
return false;
}
} else {
if (index == 0) {
// in first of children.
return false;
}
}
return true;
}
}
}
return false;
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasUI method addFieldListeners.
private void addFieldListeners() {
fileField.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setFilePath(fileField.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
refreshPreview();
}
});
rowSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setRowSeparatorValue(rowSeparatorText.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
}
});
fieldSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
previewBtn.setEnabled(checkFieldsValue());
clearPreview();
}
});
useMultiSaparators.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean selected = useMultiSaparators.getSelection();
fieldSeparatorCombo.setEnabled(!selected);
fieldSeparatorText.setEditable(!selected);
multiSeparatorsText.setEditable(selected);
keyValuesText.setEditable(selected);
keyIndexText.setEditable(selected);
escapeCharCombo.setEnabled(selected);
textEnclosureCombo.setEnabled(selected);
csvRadio.setSelection(selected);
delimitedRadio.setSelection(!selected);
delimitedRadio.setEnabled(!selected);
if (selected) {
getConnection().setFieldSeparatorValue(multiSeparatorsText.getText());
multiSchemaManager.setSelectedColumnIndex(Integer.parseInt(keyIndexText.getText()));
} else {
getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
}
clearPreview();
previewBtn.setEnabled(checkFieldsValue());
if (previewBtn.isEnabled()) {
refreshPreview();
}
}
});
schemaTreeViewer.getTree().addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
});
schemaTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
removeRow.setEnabled(true);
editSchema.setEnabled(true);
if (isReadOnly()) {
leftBtn.setEnabled(false);
rightBtn.setEnabled(false);
} else {
leftBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, true));
rightBtn.setEnabled(getUIManager().enableMovedRecord(schemaTreeViewer, false));
}
IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element != null && (element instanceof SchemasKeyData) && ((SchemasKeyData) element).getTagLevel() > 0) {
cardText.setText(((SchemasKeyData) element).getCard());
cardText.setEnabled(true);
} else {
//$NON-NLS-1$
cardText.setText("");
cardText.setEnabled(false);
}
}
});
schemaTreeViewer.getTree().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
//
}
@Override
public void keyReleased(KeyEvent e) {
//
}
});
schemaTreeViewer.addTreeListener(new ITreeViewerListener() {
public void treeCollapsed(TreeExpansionEvent event) {
// getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
public void treeExpanded(TreeExpansionEvent event) {
// getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasManager method createSchemasTree.
/**
*
* cLi Comment method "createSchemasTree".
*
* @param csvArray
* @return tree of data.
*/
public SchemasKeyData createSchemasTree(CSVArrayAndSeparator csvArrayBean, int selectColumnIndex) {
if (csvArrayBean == null) {
return null;
}
// final int columnIndex = 2;
//$NON-NLS-1$
final SchemasKeyData rootSchemasKeyData = new SchemasKeyData("");
List<String[]> rows = csvArrayBean.getCsvArray().getRows();
for (int i = 0; i < rows.size(); i++) {
// if (line.length < columnIndex) { // must contain 2 columns
// continue;
// }
String[] line = rows.get(i);
final String key = precessString(line[selectColumnIndex]);
if (key == null) {
continue;
}
String newKey = key + csvArrayBean.getSeparators().get(i);
//
SchemasKeyData schemaData = findSchemasKeyData(rootSchemasKeyData, newKey);
if (schemaData == null) {
schemaData = new SchemasKeyData(key);
// TDI-6803
String separator = csvArrayBean.getSeparators().get(i);
if (separator != null && separator.equals("\\")) {
schemaData.setSeparator("\\\\");
} else {
schemaData.setSeparator(separator);
}
schemaData.setUniqueRecord(generateUniqueRecordName(null, rootSchemasKeyData));
rootSchemasKeyData.addChild(schemaData);
}
//
MultiSchemaRowData rowData = createRowData(line, selectColumnIndex);
if (rowData != null) {
schemaData.addRowsData(rowData);
}
}
for (SchemasKeyData schemaData : rootSchemasKeyData.getChildren()) {
createPropertiesColumns(schemaData);
}
return rootSchemasKeyData;
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class UIManager method refreshSchemasDetailView.
public void refreshSchemasDetailView(TreeViewer schemaTreeViewer, TreeViewer schemaDetailsViewer, boolean model) {
if (schemaTreeViewer == null || schemaTreeViewer.getTree().isDisposed() || schemaDetailsViewer == null || schemaDetailsViewer.getTree().isDisposed()) {
return;
}
IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element == null || !(element instanceof SchemasKeyData)) {
return;
}
final Tree tree = schemaDetailsViewer.getTree();
tree.setRedraw(false);
SchemasKeyData schemasData = (SchemasKeyData) element;
final List<MultiMetadataColumn> metadataColumns = schemasData.getMetadataColumnsInModel();
if (model) {
schemaDetailsViewer.setInput(metadataColumns);
//
tree.setRedraw(true);
// type
final TreeColumn typeColumn = tree.getColumns()[EPropertyName.indexOf(EPropertyName.TYPE)];
typeColumn.pack();
} else {
final int colSize = metadataColumns.size();
if (colSize > 0) {
//
List<String> columnProperties = new ArrayList<String>();
// first column
columnProperties.add(new Integer(-1).toString());
final int columnNum = tree.getColumnCount() - 1;
for (int i = 0; i < colSize; i++) {
TreeColumn dataColumn = null;
if (i < columnNum) {
// existed column, only update data.
dataColumn = tree.getColumns()[i + 1];
} else {
// create new column
dataColumn = new TreeColumn(tree, SWT.NONE);
dataColumn.setWidth(100);
}
// MultiSchemasMetadataColumn metadataColumn = metadataColumns.get(i);
// dataColumn.setText(metadataColumn.getLabel());
// dataColumn.setData(metadataColumn);
columnProperties.add(new Integer(i).toString());
}
schemaDetailsViewer.setColumnProperties(columnProperties.toArray(new String[0]));
schemaDetailsViewer.setInput(schemasData);
} else {
schemaDetailsViewer.setInput(null);
}
//
tree.setRedraw(true);
updateColumns(tree, colSize);
}
}
Aggregations