use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class CsvInputDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
props.setLook(shell);
setShellImage(shell, inputMeta);
ModifyListener lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
inputMeta.setChanged();
}
};
changed = inputMeta.hasChanged();
ModifyListener lsContent = new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
// asyncUpdatePreview();
}
};
initializing = true;
previewBusy = new AtomicBoolean(false);
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "CsvInputDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Step name line
//
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "CsvInputDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
Control lastControl = wStepname;
// See if the step receives input. If so, we don't ask for the filename, but
// for the filename field.
//
isReceivingInput = transMeta.findNrPrevSteps(stepMeta) > 0;
if (isReceivingInput) {
RowMetaInterface previousFields;
try {
previousFields = transMeta.getPrevStepFields(stepMeta);
} catch (KettleStepException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "CsvInputDialog.ErrorDialog.UnableToGetInputFields.Title"), BaseMessages.getString(PKG, "CsvInputDialog.ErrorDialog.UnableToGetInputFields.Message"), e);
previousFields = new RowMeta();
}
// The filename field ...
//
Label wlFilename = new Label(shell, SWT.RIGHT);
wlFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("FILENAME_FIELD")));
props.setLook(wlFilename);
FormData fdlFilename = new FormData();
fdlFilename.top = new FormAttachment(lastControl, margin);
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);
wFilenameField = new CCombo(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wFilenameField.setItems(previousFields.getFieldNames());
props.setLook(wFilenameField);
wFilenameField.addModifyListener(lsMod);
FormData fdFilename = new FormData();
fdFilename.top = new FormAttachment(lastControl, margin);
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.right = new FormAttachment(100, 0);
wFilenameField.setLayoutData(fdFilename);
lastControl = wFilenameField;
// Checkbox to include the filename in the output...
//
Label wlIncludeFilename = new Label(shell, SWT.RIGHT);
wlIncludeFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("INCLUDE_FILENAME")));
props.setLook(wlIncludeFilename);
FormData fdlIncludeFilename = new FormData();
fdlIncludeFilename.top = new FormAttachment(lastControl, margin);
fdlIncludeFilename.left = new FormAttachment(0, 0);
fdlIncludeFilename.right = new FormAttachment(middle, -margin);
wlIncludeFilename.setLayoutData(fdlIncludeFilename);
wIncludeFilename = new Button(shell, SWT.CHECK);
props.setLook(wIncludeFilename);
wFilenameField.addModifyListener(lsMod);
FormData fdIncludeFilename = new FormData();
fdIncludeFilename.top = new FormAttachment(lastControl, margin);
fdIncludeFilename.left = new FormAttachment(middle, 0);
fdIncludeFilename.right = new FormAttachment(100, 0);
wIncludeFilename.setLayoutData(fdIncludeFilename);
lastControl = wIncludeFilename;
} else {
// Filename...
//
// The filename browse button
//
wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbbFilename);
wbbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
wbbFilename.setToolTipText(BaseMessages.getString(PKG, "System.Tooltip.BrowseForFileOrDirAndAdd"));
FormData fdbFilename = new FormData();
fdbFilename.top = new FormAttachment(lastControl, margin);
fdbFilename.right = new FormAttachment(100, 0);
wbbFilename.setLayoutData(fdbFilename);
// The field itself...
//
Label wlFilename = new Label(shell, SWT.RIGHT);
wlFilename.setText(BaseMessages.getString(PKG, inputMeta.getDescription("FILENAME")));
props.setLook(wlFilename);
FormData fdlFilename = new FormData();
fdlFilename.top = new FormAttachment(lastControl, margin);
fdlFilename.left = new FormAttachment(0, 0);
fdlFilename.right = new FormAttachment(middle, -margin);
wlFilename.setLayoutData(fdlFilename);
wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wFilename);
wFilename.addModifyListener(lsMod);
FormData fdFilename = new FormData();
fdFilename.top = new FormAttachment(lastControl, margin);
fdFilename.left = new FormAttachment(middle, 0);
fdFilename.right = new FormAttachment(wbbFilename, -margin);
wFilename.setLayoutData(fdFilename);
/*
* wFilename.addFocusListener(new FocusAdapter() {
*
* @Override public void focusLost(FocusEvent arg0) { asyncUpdatePreview(); } });
*/
lastControl = wFilename;
}
// delimiter
Label wlDelimiter = new Label(shell, SWT.RIGHT);
wlDelimiter.setText(BaseMessages.getString(PKG, inputMeta.getDescription("DELIMITER")));
props.setLook(wlDelimiter);
FormData fdlDelimiter = new FormData();
fdlDelimiter.top = new FormAttachment(lastControl, margin);
fdlDelimiter.left = new FormAttachment(0, 0);
fdlDelimiter.right = new FormAttachment(middle, -margin);
wlDelimiter.setLayoutData(fdlDelimiter);
wbDelimiter = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbDelimiter);
wbDelimiter.setText(BaseMessages.getString(PKG, "CsvInputDialog.Delimiter.Button"));
FormData fdbDelimiter = new FormData();
fdbDelimiter.top = new FormAttachment(lastControl, margin);
fdbDelimiter.right = new FormAttachment(100, 0);
wbDelimiter.setLayoutData(fdbDelimiter);
wDelimiter = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wDelimiter);
wDelimiter.addModifyListener(lsMod);
FormData fdDelimiter = new FormData();
fdDelimiter.top = new FormAttachment(lastControl, margin);
fdDelimiter.left = new FormAttachment(middle, 0);
fdDelimiter.right = new FormAttachment(wbDelimiter, -margin);
wDelimiter.setLayoutData(fdDelimiter);
wDelimiter.addModifyListener(lsContent);
lastControl = wDelimiter;
// enclosure
Label wlEnclosure = new Label(shell, SWT.RIGHT);
wlEnclosure.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ENCLOSURE")));
props.setLook(wlEnclosure);
FormData fdlEnclosure = new FormData();
fdlEnclosure.top = new FormAttachment(lastControl, margin);
fdlEnclosure.left = new FormAttachment(0, 0);
fdlEnclosure.right = new FormAttachment(middle, -margin);
wlEnclosure.setLayoutData(fdlEnclosure);
wEnclosure = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wEnclosure);
wEnclosure.addModifyListener(lsMod);
FormData fdEnclosure = new FormData();
fdEnclosure.top = new FormAttachment(lastControl, margin);
fdEnclosure.left = new FormAttachment(middle, 0);
fdEnclosure.right = new FormAttachment(100, 0);
wEnclosure.setLayoutData(fdEnclosure);
wEnclosure.addModifyListener(lsContent);
lastControl = wEnclosure;
// bufferSize
//
Label wlBufferSize = new Label(shell, SWT.RIGHT);
wlBufferSize.setText(BaseMessages.getString(PKG, inputMeta.getDescription("BUFFERSIZE")));
props.setLook(wlBufferSize);
FormData fdlBufferSize = new FormData();
fdlBufferSize.top = new FormAttachment(lastControl, margin);
fdlBufferSize.left = new FormAttachment(0, 0);
fdlBufferSize.right = new FormAttachment(middle, -margin);
wlBufferSize.setLayoutData(fdlBufferSize);
wBufferSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wBufferSize);
wBufferSize.addModifyListener(lsMod);
FormData fdBufferSize = new FormData();
fdBufferSize.top = new FormAttachment(lastControl, margin);
fdBufferSize.left = new FormAttachment(middle, 0);
fdBufferSize.right = new FormAttachment(100, 0);
wBufferSize.setLayoutData(fdBufferSize);
lastControl = wBufferSize;
// performingLazyConversion?
//
Label wlLazyConversion = new Label(shell, SWT.RIGHT);
wlLazyConversion.setText(BaseMessages.getString(PKG, inputMeta.getDescription("LAZY_CONVERSION")));
props.setLook(wlLazyConversion);
FormData fdlLazyConversion = new FormData();
fdlLazyConversion.top = new FormAttachment(lastControl, margin);
fdlLazyConversion.left = new FormAttachment(0, 0);
fdlLazyConversion.right = new FormAttachment(middle, -margin);
wlLazyConversion.setLayoutData(fdlLazyConversion);
wLazyConversion = new Button(shell, SWT.CHECK);
props.setLook(wLazyConversion);
FormData fdLazyConversion = new FormData();
fdLazyConversion.top = new FormAttachment(lastControl, margin);
fdLazyConversion.left = new FormAttachment(middle, 0);
fdLazyConversion.right = new FormAttachment(100, 0);
wLazyConversion.setLayoutData(fdLazyConversion);
lastControl = wLazyConversion;
// header row?
//
Label wlHeaderPresent = new Label(shell, SWT.RIGHT);
wlHeaderPresent.setText(BaseMessages.getString(PKG, inputMeta.getDescription("HEADER_PRESENT")));
props.setLook(wlHeaderPresent);
FormData fdlHeaderPresent = new FormData();
fdlHeaderPresent.top = new FormAttachment(lastControl, margin);
fdlHeaderPresent.left = new FormAttachment(0, 0);
fdlHeaderPresent.right = new FormAttachment(middle, -margin);
wlHeaderPresent.setLayoutData(fdlHeaderPresent);
wHeaderPresent = new Button(shell, SWT.CHECK);
props.setLook(wHeaderPresent);
FormData fdHeaderPresent = new FormData();
fdHeaderPresent.top = new FormAttachment(lastControl, margin);
fdHeaderPresent.left = new FormAttachment(middle, 0);
fdHeaderPresent.right = new FormAttachment(100, 0);
wHeaderPresent.setLayoutData(fdHeaderPresent);
/*
* wHeaderPresent.addSelectionListener(new SelectionAdapter() {
*
* @Override public void widgetSelected(SelectionEvent arg0) { asyncUpdatePreview(); } });
*/
lastControl = wHeaderPresent;
wlAddResult = new Label(shell, SWT.RIGHT);
wlAddResult.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ADD_FILENAME_RESULT")));
props.setLook(wlAddResult);
fdlAddResult = new FormData();
fdlAddResult.left = new FormAttachment(0, 0);
fdlAddResult.top = new FormAttachment(wHeaderPresent, margin);
fdlAddResult.right = new FormAttachment(middle, -margin);
wlAddResult.setLayoutData(fdlAddResult);
wAddResult = new Button(shell, SWT.CHECK);
props.setLook(wAddResult);
wAddResult.setToolTipText(BaseMessages.getString(PKG, inputMeta.getTooltip("ADD_FILENAME_RESULT")));
fdAddResult = new FormData();
fdAddResult.left = new FormAttachment(middle, 0);
fdAddResult.top = new FormAttachment(wHeaderPresent, margin);
wAddResult.setLayoutData(fdAddResult);
lastControl = wAddResult;
// The field itself...
//
Label wlRowNumField = new Label(shell, SWT.RIGHT);
wlRowNumField.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ROW_NUM_FIELD")));
props.setLook(wlRowNumField);
FormData fdlRowNumField = new FormData();
fdlRowNumField.top = new FormAttachment(lastControl, margin);
fdlRowNumField.left = new FormAttachment(0, 0);
fdlRowNumField.right = new FormAttachment(middle, -margin);
wlRowNumField.setLayoutData(fdlRowNumField);
wRowNumField = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wRowNumField);
wRowNumField.addModifyListener(lsMod);
FormData fdRowNumField = new FormData();
fdRowNumField.top = new FormAttachment(lastControl, margin);
fdRowNumField.left = new FormAttachment(middle, 0);
fdRowNumField.right = new FormAttachment(100, 0);
wRowNumField.setLayoutData(fdRowNumField);
lastControl = wRowNumField;
// running in parallel?
//
wlRunningInParallel = new Label(shell, SWT.RIGHT);
wlRunningInParallel.setText(BaseMessages.getString(PKG, inputMeta.getDescription("PARALLEL")));
props.setLook(wlRunningInParallel);
FormData fdlRunningInParallel = new FormData();
fdlRunningInParallel.top = new FormAttachment(lastControl, margin);
fdlRunningInParallel.left = new FormAttachment(0, 0);
fdlRunningInParallel.right = new FormAttachment(middle, -margin);
wlRunningInParallel.setLayoutData(fdlRunningInParallel);
wRunningInParallel = new Button(shell, SWT.CHECK);
props.setLook(wRunningInParallel);
FormData fdRunningInParallel = new FormData();
fdRunningInParallel.top = new FormAttachment(lastControl, margin);
fdRunningInParallel.left = new FormAttachment(middle, 0);
wRunningInParallel.setLayoutData(fdRunningInParallel);
lastControl = wRunningInParallel;
// Is a new line possible in a field?
//
Label wlNewlinePossible = new Label(shell, SWT.RIGHT);
wlNewlinePossible.setText(BaseMessages.getString(PKG, inputMeta.getDescription("NEWLINE_POSSIBLE")));
props.setLook(wlNewlinePossible);
FormData fdlNewlinePossible = new FormData();
fdlNewlinePossible.top = new FormAttachment(lastControl, margin);
fdlNewlinePossible.left = new FormAttachment(0, 0);
fdlNewlinePossible.right = new FormAttachment(middle, -margin);
wlNewlinePossible.setLayoutData(fdlNewlinePossible);
wNewlinePossible = new Button(shell, SWT.CHECK);
props.setLook(wNewlinePossible);
FormData fdNewlinePossible = new FormData();
fdNewlinePossible.top = new FormAttachment(lastControl, margin);
fdNewlinePossible.left = new FormAttachment(middle, 0);
wNewlinePossible.setLayoutData(fdNewlinePossible);
wNewlinePossible.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
setFlags();
}
});
wNewlinePossible.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
asyncUpdatePreview();
}
});
lastControl = wNewlinePossible;
// Encoding
Label wlEncoding = new Label(shell, SWT.RIGHT);
wlEncoding.setText(BaseMessages.getString(PKG, inputMeta.getDescription("ENCODING")));
props.setLook(wlEncoding);
FormData fdlEncoding = new FormData();
fdlEncoding.top = new FormAttachment(lastControl, margin);
fdlEncoding.left = new FormAttachment(0, 0);
fdlEncoding.right = new FormAttachment(middle, -margin);
wlEncoding.setLayoutData(fdlEncoding);
wEncoding = new ComboVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wEncoding);
wEncoding.addModifyListener(lsMod);
FormData fdEncoding = new FormData();
fdEncoding.top = new FormAttachment(lastControl, margin);
fdEncoding.left = new FormAttachment(middle, 0);
fdEncoding.right = new FormAttachment(100, 0);
wEncoding.setLayoutData(fdEncoding);
wEncoding.addModifyListener(lsContent);
lastControl = wEncoding;
wEncoding.addFocusListener(new FocusListener() {
public void focusLost(org.eclipse.swt.events.FocusEvent e) {
}
public void focusGained(org.eclipse.swt.events.FocusEvent e) {
Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
shell.setCursor(busy);
setEncodings();
shell.setCursor(null);
busy.dispose();
}
});
// Some buttons first, so that the dialog scales nicely...
//
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
wPreview = new Button(shell, SWT.PUSH);
wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
wPreview.setEnabled(!isReceivingInput);
wGet = new Button(shell, SWT.PUSH);
wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
wGet.setEnabled(!isReceivingInput);
setButtonPositions(new Button[] { wOK, wGet, wPreview, wCancel }, margin, null);
// Fields
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_NAME")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_TYPE")), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames(), true), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_FORMAT")), ColumnInfo.COLUMN_TYPE_FORMAT, 2), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_LENGTH")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_PRECISION")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_CURRENCY")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_DECIMAL")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_GROUP")), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, inputMeta.getDescription("FIELD_TRIM_TYPE")), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaString.trimTypeDesc) };
colinf[2].setComboValuesSelectionListener(new ComboValuesSelectionListener() {
public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
String[] comboValues = new String[] {};
int type = ValueMetaFactory.getIdForValueMeta(tableItem.getText(colNr - 1));
switch(type) {
case ValueMetaInterface.TYPE_DATE:
comboValues = Const.getDateFormats();
break;
case ValueMetaInterface.TYPE_INTEGER:
case ValueMetaInterface.TYPE_BIGNUMBER:
case ValueMetaInterface.TYPE_NUMBER:
comboValues = Const.getNumberFormats();
break;
default:
break;
}
return comboValues;
}
});
wFields = new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);
FormData fdFields = new FormData();
fdFields.top = new FormAttachment(lastControl, margin * 2);
fdFields.bottom = new FormAttachment(wOK, -margin * 2);
fdFields.left = new FormAttachment(0, 0);
fdFields.right = new FormAttachment(100, 0);
wFields.setLayoutData(fdFields);
wFields.setContentListener(lsContent);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsPreview = new Listener() {
public void handleEvent(Event e) {
preview();
}
};
lsGet = new Listener() {
public void handleEvent(Event e) {
getCSV();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener(SWT.Selection, lsOK);
wPreview.addListener(SWT.Selection, lsPreview);
wGet.addListener(SWT.Selection, lsGet);
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
if (wFilename != null) {
wFilename.addSelectionListener(lsDef);
}
if (wFilenameField != null) {
wFilenameField.addSelectionListener(lsDef);
}
wDelimiter.addSelectionListener(lsDef);
wEnclosure.addSelectionListener(lsDef);
wBufferSize.addSelectionListener(lsDef);
wRowNumField.addSelectionListener(lsDef);
// Allow the insertion of tabs as separator...
wbDelimiter.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent se) {
Text t = wDelimiter.getTextWidget();
if (t != null) {
t.insert("\t");
}
}
});
if (wbbFilename != null) {
// Listen to the browse button next to the file name
wbbFilename.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.txt;*.csv", "*.csv", "*.txt", "*" });
if (wFilename.getText() != null) {
String fname = transMeta.environmentSubstitute(wFilename.getText());
dialog.setFileName(fname);
}
dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.CSVFiles") + ", " + BaseMessages.getString(PKG, "System.FileType.TextFiles"), BaseMessages.getString(PKG, "System.FileType.CSVFiles"), BaseMessages.getString(PKG, "System.FileType.TextFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
if (dialog.open() != null) {
String str = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
wFilename.setText(str);
}
}
});
}
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
inputMeta.setChanged(changed);
initializing = false;
// Update the preview window.
//
// asyncUpdatePreview();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class SelectValuesDialog 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() {
if (!bPreviousFieldsLoaded) {
MessageDialog.openError(shell, BaseMessages.getString(PKG, "SelectValuesDialog.ColumnInfo.Loading"), BaseMessages.getString(PKG, "SelectValuesDialog.ColumnInfo.Loading"));
return;
}
if ((wRemove.getItemCount() > 0) || (wMeta.getItemCount() > 0)) {
for (int i = 0; i < wRemove.getItemCount(); i++) {
String[] columns = wRemove.getItem(i);
for (int a = 0; a < columns.length; a++) {
if (columns[a].length() > 0) {
MessageDialog.openError(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMetaTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMeta"));
return;
}
}
}
for (int i = 0; i < wMeta.getItemCount(); i++) {
String[] columns = wMeta.getItem(i);
for (int a = 0; a < columns.length; a++) {
String col = columns[a];
if (col.length() > 0) {
MessageDialog.openError(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMetaTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoDeletOrMeta"));
return;
}
}
}
}
RowMetaInterface nextStepRequiredFields = null;
StepMeta stepMeta = new StepMeta(stepname, input);
List<StepMeta> nextSteps = transMeta.findNextSteps(stepMeta);
if (nextSteps.size() == 0 || nextSteps.size() > 1) {
MessageDialog.openError(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoNextStepTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.NoNextStep"));
return;
}
StepMeta outputStepMeta = nextSteps.get(0);
StepMetaInterface stepMetaInterface = outputStepMeta.getStepMetaInterface();
try {
nextStepRequiredFields = stepMetaInterface.getRequiredFields(transMeta);
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.UnableToFindOutput"));
nextStepRequiredFields = new RowMeta();
}
String[] inputNames = new String[prevFields.size()];
for (int i = 0; i < prevFields.size(); i++) {
ValueMetaInterface value = prevFields.getValueMeta(i);
inputNames[i] = value.getName() + EnterMappingDialog.STRING_ORIGIN_SEPARATOR + value.getOrigin() + ")";
}
String[] outputNames = new String[nextStepRequiredFields.size()];
for (int i = 0; i < nextStepRequiredFields.size(); i++) {
outputNames[i] = nextStepRequiredFields.getValueMeta(i).getName();
}
String[] selectName = new String[wFields.getItemCount()];
String[] selectRename = new String[wFields.getItemCount()];
for (int i = 0; i < wFields.getItemCount(); i++) {
selectName[i] = wFields.getItem(i, 1);
selectRename[i] = wFields.getItem(i, 2);
}
List<SourceToTargetMapping> mappings = new ArrayList<SourceToTargetMapping>();
StringBuilder missingFields = new StringBuilder();
for (int i = 0; i < selectName.length; i++) {
String valueName = selectName[i];
String valueRename = selectRename[i];
int inIndex = prevFields.indexOfValue(valueName);
if (inIndex < 0) {
missingFields.append(Const.CR + " " + valueName + " --> " + valueRename);
continue;
}
if (null == valueRename || valueRename.equals("")) {
valueRename = valueName;
}
int outIndex = nextStepRequiredFields.indexOfValue(valueRename);
if (outIndex < 0) {
missingFields.append(Const.CR + " " + valueName + " --> " + valueRename);
continue;
}
SourceToTargetMapping mapping = new SourceToTargetMapping(inIndex, outIndex);
mappings.add(mapping);
}
// show a confirm dialog if some misconfiguration was found
if (missingFields.length() > 0) {
MessageDialog.setDefaultImage(GUIResource.getInstance().getImageSpoon());
boolean goOn = MessageDialog.openConfirm(shell, BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.SomeFieldsNotFoundTitle"), BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.SomeFieldsNotFound", missingFields.toString()));
if (!goOn) {
return;
}
}
EnterMappingDialog d = new EnterMappingDialog(SelectValuesDialog.this.shell, inputNames, outputNames, mappings);
mappings = d.open();
//
if (mappings != null) {
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(1, prevFields.getValueMeta(mapping.getSourcePosition()).getName());
item.setText(2, outputNames[mapping.getTargetPosition()]);
}
wFields.setRowNums();
wFields.optWidth(true);
wTabFolder.setSelection(0);
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class SetValueConstantDialog method get.
private void get() {
try {
RowMetaInterface r = transMeta.getPrevStepFields(stepMeta);
if (r != null) {
TableItemInsertListener insertListener = new TableItemInsertListener() {
public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
return true;
}
};
BaseStepDialog.getFieldsFromPrevious(r, wFields, 1, new int[] { 1 }, new int[] {}, -1, -1, insertListener);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Title"), BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"), ke);
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class SetValueConstantDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
props.setLook(shell);
setShellImage(shell, input);
lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
changed = input.hasChanged();
oldlsMod = lsMod;
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
middle = props.getMiddlePct();
margin = Const.MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "SetValueConstantDialog.Shell.Title"));
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "SetValueConstantDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
// Use variable?
wluseVars = new Label(shell, SWT.RIGHT);
wluseVars.setText(BaseMessages.getString(PKG, "SetValueConstantDialog.useVars.Label"));
props.setLook(wluseVars);
FormData fdlUpdate = new FormData();
fdlUpdate.left = new FormAttachment(0, 0);
fdlUpdate.right = new FormAttachment(middle, -margin);
fdlUpdate.top = new FormAttachment(wStepname, 2 * margin);
wluseVars.setLayoutData(fdlUpdate);
wuseVars = new Button(shell, SWT.CHECK);
wuseVars.setToolTipText(BaseMessages.getString(PKG, "SetValueConstantDialog.useVars.Tooltip"));
props.setLook(wuseVars);
FormData fdUpdate = new FormData();
fdUpdate.left = new FormAttachment(middle, 0);
fdUpdate.top = new FormAttachment(wStepname, 2 * margin);
fdUpdate.right = new FormAttachment(100, 0);
wuseVars.setLayoutData(fdUpdate);
// Table with fields
wlFields = new Label(shell, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "SetValueConstantDialog.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wuseVars, margin);
wlFields.setLayoutData(fdlFields);
int FieldsCols = 4;
final int FieldsRows = input.getFieldName().length;
colinf = new ColumnInfo[FieldsCols];
colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueConstantDialog.Fieldname.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] {}, false);
colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueConstantDialog.Value.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false);
colinf[2] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueConstantDialog.Value.ConversionMask"), ColumnInfo.COLUMN_TYPE_CCOMBO, Const.getDateFormats());
colinf[3] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueConstantDialog.Value.SetEmptyString"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.Yes"), BaseMessages.getString(PKG, "System.Combo.No") });
wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, oldlsMod, props);
fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, -50);
wFields.setLayoutData(fdFields);
//
// Search the fields in the background
//
final Runnable runnable = new Runnable() {
public void run() {
StepMeta stepMeta = transMeta.findStep(stepname);
if (stepMeta != null) {
try {
RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
// Remember these fields...
for (int i = 0; i < row.size(); i++) {
inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
}
setComboBoxes();
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
}
}
}
};
new Thread(runnable).start();
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wGet = new Button(shell, SWT.PUSH);
wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wGet, wCancel }, margin, wFields);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsGet = new Listener() {
public void handleEvent(Event e) {
get();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener(SWT.Selection, lsOK);
wGet.addListener(SWT.Selection, lsGet);
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
input.setChanged(changed);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class SetValueFieldDialog method open.
public String open() {
Shell parent = getParent();
Display display = parent.getDisplay();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MAX | SWT.MIN);
props.setLook(shell);
setShellImage(shell, input);
ModifyListener lsMod = new ModifyListener() {
public void modifyText(ModifyEvent e) {
input.setChanged();
}
};
changed = input.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "SetValueFieldDialog.Shell.Label"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "SetValueFieldDialog.Stepname.Label"));
props.setLook(wlStepname);
fdlStepname = new FormData();
fdlStepname.left = new FormAttachment(0, 0);
fdlStepname.right = new FormAttachment(middle, -margin);
fdlStepname.top = new FormAttachment(0, margin);
wlStepname.setLayoutData(fdlStepname);
wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wStepname.setText(stepname);
props.setLook(wStepname);
wStepname.addModifyListener(lsMod);
fdStepname = new FormData();
fdStepname.left = new FormAttachment(middle, 0);
fdStepname.top = new FormAttachment(0, margin);
fdStepname.right = new FormAttachment(100, 0);
wStepname.setLayoutData(fdStepname);
wlFields = new Label(shell, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "SetValueFieldDialog.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wStepname, margin);
wlFields.setLayoutData(fdlFields);
final int FieldsCols = 2;
final int FieldsRows = input.getFieldName().length;
colinf = new ColumnInfo[FieldsCols];
colinf[0] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueFieldDialog.ColumnInfo.Name"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
colinf[1] = new ColumnInfo(BaseMessages.getString(PKG, "SetValueFieldDialog.ColumnInfo.ValueFromField"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false);
wFields = new TableView(transMeta, shell, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI, colinf, FieldsRows, lsMod, props);
fdFields = new FormData();
fdFields.left = new FormAttachment(0, 0);
fdFields.top = new FormAttachment(wlFields, margin);
fdFields.right = new FormAttachment(100, 0);
fdFields.bottom = new FormAttachment(100, -50);
wFields.setLayoutData(fdFields);
//
// Search the fields in the background
final Runnable runnable = new Runnable() {
public void run() {
StepMeta stepMeta = transMeta.findStep(stepname);
if (stepMeta != null) {
try {
RowMetaInterface row = transMeta.getPrevStepFields(stepMeta);
// Remember these fields...
for (int i = 0; i < row.size(); i++) {
inputFields.put(row.getValueMeta(i).getName(), Integer.valueOf(i));
}
setComboBoxes();
} catch (KettleException e) {
logError("It was not possible to get the list of input fields from previous steps", e);
}
}
}
};
new Thread(runnable).start();
// Some buttons
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wGet = new Button(shell, SWT.PUSH);
wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wGet, wCancel }, margin, wFields);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
lsGet = new Listener() {
public void handleEvent(Event e) {
get();
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wGet.addListener(SWT.Selection, lsGet);
wOK.addListener(SWT.Selection, lsOK);
lsDef = new SelectionAdapter() {
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
input.setChanged(changed);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return stepname;
}
Aggregations