use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class UIManager method moveRecord.
public void moveRecord(TreeViewer schemaTreeViewer, boolean left) {
if (schemaTreeViewer == null) {
return;
}
ISelection selection = schemaTreeViewer.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) element;
SchemasKeyData parent = data.getParent();
if (left) {
SchemasKeyData grandfather = parent.getParent();
if (grandfather != null) {
// not in root.
List<SchemasKeyData> children = grandfather.getChildren();
int index = -1;
for (int i = 0; i < children.size(); i++) {
if (children.get(i) == parent) {
index = i;
break;
}
}
if (index > -1) {
int index2 = index + 1;
if (index2 > children.size()) {
grandfather.addChild(data);
} else {
grandfather.addChild(index2, data);
}
}
}
} else {
SchemasKeyData sibling = null;
for (SchemasKeyData skd : parent.getChildren()) {
if (skd == data) {
break;
} else {
sibling = skd;
}
}
if (sibling != null) {
sibling.addChild(data);
}
}
schemaTreeViewer.refresh();
}
}
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasUI method addFieldsListenersGroupFileSettings.
private void addFieldsListenersGroupFileSettings() {
// Event encodingCombo
encodingCombo.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
getConnection().setEncoding(encodingCombo.getText());
checkFieldsValue();
}
});
// Separator Combo (field and row)
fieldSeparatorCombo.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
// Label Custom of fieldSeparatorText
fieldSeparatorManager();
}
});
rowSeparatorCombo.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
// Label Custom of rowSeparatorText
rowSeparatorManager();
}
});
// Separator Text (field and row)
fieldSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
getConnection().setFieldSeparatorValue(fieldSeparatorText.getText());
checkFieldsValue();
}
});
multiSeparatorsText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
getConnection().setFieldSeparatorValue(multiSeparatorsText.getText());
previewBtn.setEnabled(checkFieldsValue());
}
});
keyIndexText.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.character > '9' || e.character < '0') {
if (e.character != '\b' || e.keyCode == '') {
e.doit = false;
}
}
}
});
keyIndexText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
boolean modify = false;
if (keyIndexText.getText() == null || "".equals(keyIndexText.getText())) {
multiSchemaManager.setSelectedColumnIndex(0);
modify = true;
} else {
int index = 0;
try {
index = Integer.parseInt(keyIndexText.getText());
} catch (Exception ex) {
index = 0;
keyIndexText.setText(String.valueOf(index));
}
multiSchemaManager.setSelectedColumnIndex(index);
modify = true;
}
if (modify) {
// refreshPreview();
}
previewBtn.setEnabled(checkFieldsValue());
if (previewBtn.isEnabled()) {
refreshPreview();
}
}
});
keyValuesText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
previewBtn.setEnabled(checkFieldsValue());
}
});
rowSeparatorText.addModifyListener(new ModifyListener() {
public void modifyText(final ModifyEvent e) {
getConnection().setRowSeparatorValue(rowSeparatorText.getText());
checkFieldsValue();
}
});
cardText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
IStructuredSelection selection = (IStructuredSelection) schemaTreeViewer.getSelection();
Object element = selection.getFirstElement();
if (element != null && (element instanceof SchemasKeyData)) {
((SchemasKeyData) element).setCard(cardText.getText());
}
}
});
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasUI method addButtonListeners.
protected void addButtonListeners() {
// Event PreviewButton
previewBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
refreshPreview();
}
});
fetchBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
fetchCodes();
}
});
leftBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
getUIManager().moveRecord(schemaTreeViewer, true);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
rightBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
getUIManager().moveRecord(schemaTreeViewer, false);
getUIManager().packSchemaTreeFirstColumn(schemaTreeViewer);
}
});
addRow.addSelectionListener(new // hywang for 10263
SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SchemasKeyData root = (SchemasKeyData) schemaTreeViewer.getInput();
AddRowDialog dialog = new AddRowDialog(MultiSchemasUI.this.getShell(), root);
if (Window.OK == dialog.open()) {
Object input = schemaTreeViewer.getInput();
if (input instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) input;
List<SchemasKeyData> all = data.getChildren();
SchemasKeyData newData = new SchemasKeyData(dialog.getRecordValue());
newData.setSeparator(dialog.getSepValue());
newData.setUniqueRecord(dialog.getKeyValue());
final IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), dialog.getKeyValue());
if (metadataTable != null) {
multiSchemaManager.createMultiSchemasColumns(newData, metadataTable.clone(true));
} else {
List<MultiMetadataColumn> colums = multiSchemaManager.createPropertiesColumns(newData);
newData.setMetadataColumns(colums);
}
all.add(newData);
data.addChild(newData);
newData.setParent(data);
schemaTreeViewer.refresh();
int len = schemaTreeViewer.getTree().getItems().length;
schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
}
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
});
removeRow.addSelectionListener(new // hywang for 10263
SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
boolean needRefresh = false;
if (schemaTreeViewer == null) {
return;
}
SchemasKeyData removeData = null;
ISelection selection = schemaTreeViewer.getSelection();
Object input = schemaTreeViewer.getInput();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof SchemasKeyData) {
removeData = (SchemasKeyData) element;
}
}
if (input instanceof SchemasKeyData) {
SchemasKeyData data = (SchemasKeyData) input;
List<SchemasKeyData> all = data.getChildren();
if (all.contains(removeData)) {
all.remove(removeData);
schemaTreeViewer.setInput(data);
needRefresh = true;
}
if (needRefresh) {
schemaTreeViewer.refresh();
int len = schemaTreeViewer.getTree().getItems().length;
if (len > 0) {
schemaTreeViewer.getTree().select(schemaTreeViewer.getTree().getItems()[len - 1]);
}
removeRow.setEnabled(!all.isEmpty());
editSchema.setEnabled(!all.isEmpty());
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
}
});
editSchema.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ISelection selection = schemaTreeViewer.getSelection();
SchemasKeyData selectedData = null;
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof SchemasKeyData) {
selectedData = (SchemasKeyData) element;
IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), selectedData.getUniqueRecord());
if (metadataTable == null) {
metadataTable = new org.talend.core.model.metadata.MetadataTable();
}
metadataTable.getListColumns().clear();
SchemasKeyData keydata = (SchemasKeyData) schemaTreeViewer.getInput();
for (int i = 0; i < keydata.getChildren().size(); i++) {
if (selectedData.getUniqueRecord().equals(keydata.getChildren().get(i).getUniqueRecord())) {
metadataTable.getListColumns().addAll(keydata.getChildren().get(i).getMetadataColumns());
break;
}
}
MetadataDialog dialog = new MetadataDialog(MultiSchemasUI.this.getShell(), metadataTable, getMultiSchemasComponent(), new CommandStackForComposite(MultiSchemasUI.this.getShell()));
dialog.setText("Schema of " + selectedData.getUniqueRecord());
if (Window.OK == dialog.open()) {
metadataTable = dialog.getOutputMetaData();
if (!selectedData.getMetadataColumns().isEmpty()) {
selectedData.getMetadataColumns().clear();
}
multiSchemaManager.createMultiSchemasColumns(selectedData, metadataTable);
getUIManager().refreshSchemasDetailView(schemaTreeViewer, schemaDetailsViewer, getSchemaDetailModel());
}
}
}
}
});
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasManager method createSimpleDatas.
public void createSimpleDatas(SchemasKeyData rootData, List<Map<String, String>> schemasValues) {
for (Map<String, String> line : schemasValues) {
String code = line.get(IMultiSchemaConstant.RECORD);
if (code != null) {
// code = MultiSchemasManager.removeQuotes(code);
code = TalendTextUtils.trimParameter(code);
SchemasKeyData data = new SchemasKeyData(code);
final String schemaName = line.get(IMultiSchemaConstant.SCHEMA);
if (schemaName != null) {
final IMetadataTable metadataTable = MetadataToolHelper.getMetadataTableFromNode(getMultiSchemasComponent(), schemaName);
if (metadataTable != null) {
data.setUniqueRecord(schemaName);
createMultiSchemasColumns(data, metadataTable.clone(true));
}
rootData.addChild(data);
}
String text = line.get(IMultiSchemaConstant.KEY_COLUMN_INDEX);
if (text == null) {
//$NON-NLS-1$
text = "";
}
final String keyColumnIndex = TalendTextUtils.removeQuotes(text);
//$NON-NLS-1$
String[] keys = keyColumnIndex.split(",");
for (String name : keys) {
try {
List<MultiMetadataColumn> metadataColumns = data.getMetadataColumns();
int index = Integer.parseInt(name);
for (int i = 0; i < metadataColumns.size(); i++) {
MultiMetadataColumn multiMetadataColumn = metadataColumns.get(i);
if (index == i) {
multiMetadataColumn.setKey(true);
} else {
multiMetadataColumn.setKey(false);
}
}
} catch (NumberFormatException e) {
//
}
}
String card = line.get(IMultiSchemaConstant.CARDINALITY);
if (card == null) {
//$NON-NLS-1$
card = TalendTextUtils.addQuotes("");
}
data.setCard(card);
String keyIndex = line.get(IMultiSchemaConstant.FIELDDELIMITED);
if (keyIndex == null) {
//$NON-NLS-1$
keyIndex = "";
} else {
keyIndex = TalendTextUtils.removeQuotes(keyIndex);
}
data.setSeparator(keyIndex);
}
}
}
use of org.talend.designer.filemultischemas.data.SchemasKeyData in project tdi-studio-se by Talend.
the class MultiSchemasManager method retrieveRelativeParent.
private void retrieveRelativeParent(SchemasKeyData rootData, List<Map<String, String>> schemasValues) {
for (Map<String, String> line : schemasValues) {
String code = line.get(IMultiSchemaConstant.RECORD);
if (code != null) {
code = TalendTextUtils.removeQuotes(code);
SchemasKeyData currentData = findKeyData(rootData, code);
if (currentData != null) {
String codeParent = line.get(IMultiSchemaConstant.PARENT_RECORD);
if (codeParent != null) {
codeParent = TalendTextUtils.removeQuotes(codeParent);
}
if (codeParent == null || "".equals(codeParent.trim())) {
// root //$NON-NLS-1$
rootData.addChild(currentData);
} else {
SchemasKeyData parentData = findKeyData(rootData, codeParent.trim());
if (parentData != null) {
parentData.addChild(currentData);
// set the added column, last column.
List<MultiMetadataColumn> metadataColumns = currentData.getMetadataColumns();
if (!metadataColumns.isEmpty()) {
MultiMetadataColumn multiMetadataColumn = metadataColumns.get(metadataColumns.size() - 1);
metadataColumns.remove(multiMetadataColumn);
currentData.setAddedColumn(multiMetadataColumn);
}
}
}
}
}
}
}
Aggregations