use of org.pentaho.di.ui.core.dialog.ErrorDialog 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.ErrorDialog in project pentaho-kettle by pentaho.
the class PGPEncryptStreamDialog method get.
private void get() {
if (!gotPreviousFields) {
try {
String fieldvalue = wStreamFieldName.getText();
wStreamFieldName.removeAll();
String Keyfieldvalue = wKeyNameFieldName.getText();
wKeyNameFieldName.removeAll();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
wStreamFieldName.setItems(r.getFieldNames());
wKeyNameFieldName.setItems(r.getFieldNames());
}
if (fieldvalue != null) {
wStreamFieldName.setText(fieldvalue);
}
if (Keyfieldvalue != null) {
wKeyNameFieldName.setText(Keyfieldvalue);
}
gotPreviousFields = true;
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "PGPEncryptStreamDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "PGPEncryptStreamDialog.FailedToGetFields.DialogMessage"), ke);
}
}
}
use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.
the class ProcessFilesDialog method get.
private void get() {
if (!gotPreviousFields) {
gotPreviousFields = true;
try {
String source = wSourceFileNameField.getText();
String target = wTargetFileNameField.getText();
wSourceFileNameField.removeAll();
wTargetFileNameField.removeAll();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
wSourceFileNameField.setItems(r.getFieldNames());
wTargetFileNameField.setItems(r.getFieldNames());
if (source != null) {
wSourceFileNameField.setText(source);
}
if (target != null) {
wTargetFileNameField.setText(target);
}
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ProcessFilesDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "ProcessFilesDialog.FailedToGetFields.DialogMessage"), ke);
}
}
}
use of org.pentaho.di.ui.core.dialog.ErrorDialog in project pentaho-kettle by pentaho.
the class OraBulkLoaderDialog method getUpdate.
private void getUpdate() {
try {
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
TableItemInsertListener listener = new TableItemInsertListener() {
public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
if (v.getType() == ValueMetaInterface.TYPE_DATE) {
// The default is date mask.
tableItem.setText(3, BaseMessages.getString(PKG, "OraBulkLoaderDialog.DateMask.Label"));
} else {
tableItem.setText(3, "");
}
return true;
}
};
BaseStepDialog.getFieldsFromPrevious(r, wReturn, 1, new int[] { 1, 2 }, new int[] {}, -1, -1, listener);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "OraBulkLoaderDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "OraBulkLoaderDialog.FailedToGetFields.DialogMessage"), ke);
}
}
use of org.pentaho.di.ui.core.dialog.ErrorDialog 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);
}
}
Aggregations