use of org.pentaho.di.ui.core.dialog.EnterMappingDialog in project pentaho-kettle by pentaho.
the class OraBulkLoaderDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields;
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
try {
targetFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "OraBulkLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(OraBulkLoaderDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.pentaho.di.ui.core.dialog.EnterMappingDialog in project pentaho-kettle by pentaho.
the class PGBulkLoaderDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields;
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
try {
targetFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "PGBulkLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(PGBulkLoaderDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.pentaho.di.ui.core.dialog.EnterMappingDialog in project pentaho-kettle by pentaho.
the class SynchronizeAfterMergeDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields;
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(transMeta.findDatabase(wConnection.getText()));
input.setTableName(transMeta.environmentSubstitute(wTable.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
try {
targetFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wReturn.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wReturn.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR).append(" ").append(source).append(" --> ").append(target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SynchronizeAfterMergeDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SynchronizeAfterMergeDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wReturn.table.removeAll();
wReturn.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wReturn.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wReturn.setRowNums();
wReturn.optWidth(true);
}
}
use of org.pentaho.di.ui.core.dialog.EnterMappingDialog in project pentaho-kettle by pentaho.
the class MappingDialog method addMappingDefinitionTab.
private void addMappingDefinitionTab(List<MappingIODefinition> definitions, final String tabTitle, String listLabel, String addToolTip, String removeToolTip, String inputStepLabel, String outputStepLabel, String descriptionLabel, String sourceColumnLabel, String targetColumnLabel, String noItemsLabel, final boolean input) {
final CTabItem wTab = new CTabItem(wTabFolder, SWT.NONE);
wTab.setText(tabTitle);
Composite wInputComposite = new Composite(wTabFolder, SWT.NONE);
props.setLook(wInputComposite);
FormLayout tabLayout = new FormLayout();
tabLayout.marginWidth = 15;
tabLayout.marginHeight = 15;
wInputComposite.setLayout(tabLayout);
Label wAvailableInputs = new Label(wInputComposite, SWT.LEFT);
props.setLook(wAvailableInputs);
wAvailableInputs.setText(listLabel);
FormData fdwAvailableInputs = new FormData();
fdwAvailableInputs.left = new FormAttachment(0);
fdwAvailableInputs.top = new FormAttachment(0);
Label wRemoveButton = new Label(wInputComposite, SWT.NONE);
wRemoveButton.setImage(GUIResource.getInstance().getImage("ui/images/generic-delete.svg"));
wRemoveButton.setToolTipText(removeToolTip);
props.setLook(wRemoveButton);
FormData fdwAddInputButton = new FormData();
fdwAddInputButton.top = new FormAttachment(0);
fdwAddInputButton.right = new FormAttachment(30);
wRemoveButton.setLayoutData(fdwAddInputButton);
Label wAddButton = new Label(wInputComposite, SWT.NONE);
wAddButton.setImage(GUIResource.getInstance().getImage("ui/images/Add.svg"));
wAddButton.setToolTipText(addToolTip);
props.setLook(wAddButton);
FormData fdwAddButton = new FormData();
fdwAddButton.top = new FormAttachment(0);
fdwAddButton.right = new FormAttachment(wRemoveButton, -5);
wAddButton.setLayoutData(fdwAddButton);
org.eclipse.swt.widgets.List wInputList = new org.eclipse.swt.widgets.List(wInputComposite, SWT.BORDER);
FormData fdwInputList = new FormData();
fdwInputList.left = new FormAttachment(0);
fdwInputList.top = new FormAttachment(wAvailableInputs, 5);
fdwInputList.bottom = new FormAttachment(100);
fdwInputList.right = new FormAttachment(30);
wInputList.setLayoutData(fdwInputList);
for (int i = 0; i < definitions.size(); i++) {
String label = !Utils.isEmpty(definitions.get(i).getInputStepname()) ? definitions.get(i).getInputStepname() : tabTitle + (i > 0 ? String.valueOf(i + 1) : "");
wInputList.add(label);
}
final Label wlNoItems = new Label(wInputComposite, SWT.CENTER);
wlNoItems.setText(noItemsLabel);
props.setLook(wlNoItems);
FormData fdlNoItems = new FormData();
fdlNoItems.left = new FormAttachment(wInputList, 30);
fdlNoItems.right = new FormAttachment(100);
fdlNoItems.top = new FormAttachment(50);
wlNoItems.setLayoutData(fdlNoItems);
wlNoItems.setVisible(false);
Composite wFieldsComposite = new Composite(wInputComposite, SWT.NONE);
props.setLook(wFieldsComposite);
FormLayout fieldLayout = new FormLayout();
fieldLayout.marginWidth = 0;
fieldLayout.marginHeight = 0;
wFieldsComposite.setLayout(fieldLayout);
final Button wMainPath = new Button(wFieldsComposite, SWT.CHECK);
wMainPath.setText(BaseMessages.getString(PKG, "MappingDialog.input.MainDataPath"));
props.setLook(wMainPath);
FormData fdMainPath = new FormData();
fdMainPath.top = new FormAttachment(0);
fdMainPath.left = new FormAttachment(0);
wMainPath.setLayoutData(fdMainPath);
wMainPath.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
definitions.get(wInputList.getSelectionIndex()).setMainDataPath(!definitions.get(wInputList.getSelectionIndex()).isMainDataPath());
}
});
final Label wlInputStep = new Label(wFieldsComposite, SWT.RIGHT);
props.setLook(wlInputStep);
wlInputStep.setText(inputStepLabel);
FormData fdlInputStep = new FormData();
fdlInputStep.top = new FormAttachment(wMainPath, 10);
fdlInputStep.left = new FormAttachment(0);
wlInputStep.setLayoutData(fdlInputStep);
// What's the stepname to read from? (empty is OK too)
//
final Button wbInputStep = new Button(wFieldsComposite, SWT.PUSH);
props.setLook(wbInputStep);
wbInputStep.setText(BaseMessages.getString(PKG, "MappingDialog.button.SourceStepName"));
FormData fdbInputStep = new FormData();
fdbInputStep.top = new FormAttachment(wlInputStep, 5);
// First one in the
fdbInputStep.right = new FormAttachment(100);
// left top corner
wbInputStep.setLayoutData(fdbInputStep);
final Text wInputStep = new Text(wFieldsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wInputStep);
wInputStep.addModifyListener(lsMod);
FormData fdInputStep = new FormData();
fdInputStep.top = new FormAttachment(wlInputStep, 5);
// To the right of
fdInputStep.left = new FormAttachment(0);
// the label
fdInputStep.right = new FormAttachment(wbInputStep, -5);
wInputStep.setLayoutData(fdInputStep);
wInputStep.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent event) {
definitions.get(wInputList.getSelectionIndex()).setInputStepname(wInputStep.getText());
String label = !Utils.isEmpty(wInputStep.getText()) ? wInputStep.getText() : tabTitle + (wInputList.getSelectionIndex() > 0 ? String.valueOf(wInputList.getSelectionIndex() + 1) : "");
wInputList.setItem(wInputList.getSelectionIndex(), label);
}
});
wbInputStep.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
String stepName = selectTransformationStepname(input, input);
if (stepName != null) {
wInputStep.setText(stepName);
definitions.get(wInputList.getSelectionIndex()).setInputStepname(stepName);
}
}
});
// What's the step name to read from? (empty is OK too)
//
final Label wlOutputStep = new Label(wFieldsComposite, SWT.RIGHT);
props.setLook(wlOutputStep);
wlOutputStep.setText(outputStepLabel);
FormData fdlOutputStep = new FormData();
fdlOutputStep.top = new FormAttachment(wInputStep, 10);
fdlOutputStep.left = new FormAttachment(0);
wlOutputStep.setLayoutData(fdlOutputStep);
final Button wbOutputStep = new Button(wFieldsComposite, SWT.PUSH);
props.setLook(wbOutputStep);
wbOutputStep.setText(BaseMessages.getString(PKG, "MappingDialog.button.SourceStepName"));
FormData fdbOutputStep = new FormData();
fdbOutputStep.top = new FormAttachment(wlOutputStep, 5);
fdbOutputStep.right = new FormAttachment(100);
wbOutputStep.setLayoutData(fdbOutputStep);
final Text wOutputStep = new Text(wFieldsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wOutputStep);
wOutputStep.addModifyListener(lsMod);
FormData fdOutputStep = new FormData();
fdOutputStep.top = new FormAttachment(wlOutputStep, 5);
// To the right of
fdOutputStep.left = new FormAttachment(0);
// the label
fdOutputStep.right = new FormAttachment(wbOutputStep, -5);
wOutputStep.setLayoutData(fdOutputStep);
// Allow for a small description
//
Label wlDescription = new Label(wFieldsComposite, SWT.RIGHT);
props.setLook(wlDescription);
wlDescription.setText(descriptionLabel);
FormData fdlDescription = new FormData();
fdlDescription.top = new FormAttachment(wOutputStep, 5);
// First one in the left
fdlDescription.left = new FormAttachment(0);
wlDescription.setLayoutData(fdlDescription);
final Text wDescription = new Text(wFieldsComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wDescription);
wDescription.addModifyListener(lsMod);
FormData fdDescription = new FormData();
fdDescription.top = new FormAttachment(wlDescription, 5);
// To the right of
fdDescription.left = new FormAttachment(0);
// the label
fdDescription.right = new FormAttachment(100);
wDescription.setLayoutData(fdDescription);
wDescription.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent event) {
definitions.get(wInputList.getSelectionIndex()).setDescription(wDescription.getText());
}
});
final Button wbEnterMapping = new Button(wFieldsComposite, SWT.PUSH);
props.setLook(wbEnterMapping);
wbEnterMapping.setText(BaseMessages.getString(PKG, "MappingDialog.button.EnterMapping"));
FormData fdbEnterMapping = new FormData();
fdbEnterMapping.bottom = new FormAttachment(100);
fdbEnterMapping.right = new FormAttachment(100);
wbEnterMapping.setLayoutData(fdbEnterMapping);
wbEnterMapping.setEnabled(input);
ColumnInfo[] colinfo = new ColumnInfo[] { new ColumnInfo(sourceColumnLabel, ColumnInfo.COLUMN_TYPE_TEXT, false, false), new ColumnInfo(targetColumnLabel, ColumnInfo.COLUMN_TYPE_TEXT, false, false) };
final TableView wFieldMappings = new TableView(transMeta, wFieldsComposite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER, colinfo, 1, false, lsMod, props, false);
props.setLook(wFieldMappings);
FormData fdMappings = new FormData();
fdMappings.top = new FormAttachment(wDescription, 20);
fdMappings.bottom = new FormAttachment(wbEnterMapping, -5);
fdMappings.left = new FormAttachment(0);
fdMappings.right = new FormAttachment(100);
wFieldMappings.setLayoutData(fdMappings);
wFieldMappings.getTable().addListener(SWT.Resize, new ColumnsResizer(0, 50, 50));
wbEnterMapping.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
RowMetaInterface sourceRowMeta = getFieldsFromStep(wInputStep.getText(), true, input);
RowMetaInterface targetRowMeta = getFieldsFromStep(wOutputStep.getText(), false, input);
String[] sourceFields = sourceRowMeta.getFieldNames();
String[] targetFields = targetRowMeta.getFieldNames();
EnterMappingDialog dialog = new EnterMappingDialog(shell, sourceFields, targetFields);
List<SourceToTargetMapping> mappings = dialog.open();
if (mappings != null) {
// first clear the dialog...
wFieldMappings.clearAll(false);
//
definitions.get(wInputList.getSelectionIndex()).getValueRenames().clear();
// Now add the new values...
for (SourceToTargetMapping mapping : mappings) {
TableItem item = new TableItem(wFieldMappings.table, SWT.NONE);
item.setText(1, mapping.getSourceString(sourceFields));
item.setText(2, mapping.getTargetString(targetFields));
String source = input ? item.getText(1) : item.getText(2);
String target = input ? item.getText(2) : item.getText(1);
definitions.get(wInputList.getSelectionIndex()).getValueRenames().add(new MappingValueRename(source, target));
}
wFieldMappings.removeEmptyRows();
wFieldMappings.setRowNums();
wFieldMappings.optWidth(true);
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "MappingDialog.Exception.ErrorGettingMappingSourceAndTargetFields", e.toString()), e);
}
}
});
wOutputStep.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent event) {
definitions.get(wInputList.getSelectionIndex()).setOutputStepname(wOutputStep.getText());
try {
enableMappingButton(wbEnterMapping, input, wInputStep.getText(), wOutputStep.getText());
} catch (KettleException e) {
// Show the missing/wrong step name error
//
new ErrorDialog(shell, "Error", "Unexpected error", e);
}
}
});
wbOutputStep.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
String stepName = selectTransformationStepname(!input, input);
if (stepName != null) {
wOutputStep.setText(stepName);
definitions.get(wInputList.getSelectionIndex()).setOutputStepname(stepName);
try {
enableMappingButton(wbEnterMapping, input, wInputStep.getText(), wOutputStep.getText());
} catch (KettleException e) {
// Show the missing/wrong stepname error
new ErrorDialog(shell, "Error", "Unexpected error", e);
}
}
}
});
final Button wRenameOutput;
if (input) {
// Add a checkbox to indicate that all output mappings need to rename
// the values back...
//
wRenameOutput = new Button(wFieldsComposite, SWT.CHECK);
wRenameOutput.setText(BaseMessages.getString(PKG, "MappingDialog.input.RenamingOnOutput"));
props.setLook(wRenameOutput);
FormData fdRenameOutput = new FormData();
fdRenameOutput.top = new FormAttachment(wFieldMappings, 5);
fdRenameOutput.left = new FormAttachment(0);
wRenameOutput.setLayoutData(fdRenameOutput);
wRenameOutput.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
definitions.get(wInputList.getSelectionIndex()).setRenamingOnOutput(!definitions.get(wInputList.getSelectionIndex()).isRenamingOnOutput());
}
});
} else {
wRenameOutput = null;
}
FormData fdInputComposite = new FormData();
fdInputComposite.left = new FormAttachment(0);
fdInputComposite.top = new FormAttachment(0);
fdInputComposite.right = new FormAttachment(100);
fdInputComposite.bottom = new FormAttachment(100);
wInputComposite.setLayoutData(fdInputComposite);
FormData fdFieldsComposite = new FormData();
fdFieldsComposite.left = new FormAttachment(wInputList, 30);
fdFieldsComposite.right = new FormAttachment(100);
fdFieldsComposite.bottom = new FormAttachment(100);
fdFieldsComposite.top = new FormAttachment(0);
wFieldsComposite.setLayoutData(fdFieldsComposite);
wInputComposite.layout();
wTab.setControl(wInputComposite);
wMainPath.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
setTabFlags(wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription);
}
});
wInputList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent selectionEvent) {
updateFields(definitions.get(wInputList.getSelectionIndex()), input, wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription, wFieldMappings, wRenameOutput);
}
});
wAddButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent mouseEvent) {
MappingIODefinition definition = new MappingIODefinition();
definition.setMainDataPath(true);
definitions.add(definition);
wInputList.add(tabTitle + (definitions.size() > 1 ? String.valueOf(definitions.size()) : ""));
wInputList.select(definitions.size() - 1);
updateFields(definitions.get(wInputList.getSelectionIndex()), input, wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription, wFieldMappings, wRenameOutput);
wlNoItems.setVisible(false);
wFieldsComposite.setVisible(true);
wRemoveButton.setEnabled(true);
}
});
wRemoveButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseUp(MouseEvent mouseEvent) {
MessageBox box = new MessageBox(shell, SWT.YES | SWT.NO);
box.setText(BaseMessages.getString(PKG, "MappingDialog.CloseDefinitionTabAreYouSure.Title"));
box.setMessage(BaseMessages.getString(PKG, "MappingDialog.CloseDefinitionTabAreYouSure.Message"));
int answer = box.open();
if (answer != SWT.YES) {
return;
}
int index = wInputList.getSelectionIndex();
definitions.remove(index);
wInputList.removeAll();
for (int i = 0; i < definitions.size(); i++) {
String label = !Utils.isEmpty(definitions.get(i).getInputStepname()) ? definitions.get(i).getInputStepname() : tabTitle + (i > 0 ? String.valueOf(i + 1) : "");
wInputList.add(label);
}
if (index > 0) {
wInputList.select(index - 1);
} else if (definitions.size() > 0) {
wInputList.select(index);
} else {
index = -1;
}
if (index != -1) {
updateFields(definitions.get(wInputList.getSelectionIndex()), input, wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription, wFieldMappings, wRenameOutput);
}
if (definitions.size() == 0) {
wlNoItems.setVisible(true);
wFieldsComposite.setVisible(false);
wRemoveButton.setEnabled(false);
}
}
});
if (definitions.size() > 0) {
wInputList.select(0);
updateFields(definitions.get(0), input, wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription, wFieldMappings, wRenameOutput);
} else {
wlNoItems.setVisible(true);
wFieldsComposite.setVisible(false);
wRemoveButton.setEnabled(false);
}
setTabFlags(wMainPath, wlInputStep, wInputStep, wbInputStep, wlOutputStep, wOutputStep, wbOutputStep, wlDescription, wDescription);
wTabFolder.setSelection(wTab);
}
use of org.pentaho.di.ui.core.dialog.EnterMappingDialog in project pentaho-kettle by pentaho.
the class IngresVectorwiseLoaderDialog method generateMappings.
/**
* Reads in the fields from the previous steps and from the ONE next step and opens an EnterMappingDialog with this
* information. After the user did the mapping, those information is put into the Select/Rename table.
*/
private void generateMappings() {
// Determine the source and target fields...
//
RowMetaInterface sourceFields;
RowMetaInterface targetFields;
try {
sourceFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.UnableToFindSourceFields.Title"), BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.UnableToFindSourceFields.Message"), e);
return;
}
// refresh data
input.setDatabaseMeta(transMeta.findDatabase(serverConnection.getText()));
input.setTablename(transMeta.environmentSubstitute(wTable.getText()));
StepMetaInterface stepMetaInterface = stepMeta.getStepMetaInterface();
try {
targetFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.UnableToFindTargetFields.Title"), BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.UnableToFindTargetFields.Message"), e);
return;
}
String[] inputNames = new String[sourceFields.size()];
for (int i = 0; i < sourceFields.size(); i++) {
ValueMetaInterface value = sourceFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
// Create the existing mapping list...
//
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingSourceFields = new StringBuilder();
StringBuilder missingTargetFields = new StringBuilder();
int nrFields = wFields.nrNonEmpty();
for (int i = 0; i < nrFields; i++) {
TableItem item = wFields.getNonEmpty(i);
String source = item.getText(2);
String target = item.getText(1);
int sourceIndex = sourceFields.indexOfValue(source);
if (sourceIndex < 0) {
missingSourceFields.append(Const.CR + " " + source + " --> " + target);
}
int targetIndex = targetFields.indexOfValue(target);
if (targetIndex < 0) {
missingTargetFields.append(Const.CR + " " + source + " --> " + target);
}
if (sourceIndex < 0 || targetIndex < 0) {
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(sourceIndex, targetIndex);
mappings.add(mapping);
}
//
if (missingSourceFields.length() > 0 || missingTargetFields.length() > 0) {
String message = "";
if (missingSourceFields.length() > 0) {
message += BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.SomeSourceFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
if (missingTargetFields.length() > 0) {
message += BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.SomeTargetFieldsNotFound", missingSourceFields.toString()) + Const.CR;
}
message += Const.CR;
message += BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.SomeFieldsNotFoundContinue") + Const.CR;
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "IngresVectorWiseLoaderDialog.DoMapping.SomeFieldsNotFoundTitle"), message);
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(IngresVectorwiseLoaderDialog.this.shell, sourceFields.getFieldNames(), targetFields.getFieldNames(), mappings);
mappings = d.open();
//
if (mappings != null) {
// Clear and re-populate!
//
wFields.table.removeAll();
wFields.table.setItemCount(mappings.size());
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
TableItem item = wFields.table.getItem(i);
item.setText(2, sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(1, targetFields.getValueMeta(mapping.getTargetPosition()).getName());
}
wFields.setRowNums();
wFields.optWidth(true);
}
}
Aggregations