use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class BaseStepDialog method getFieldsFromPrevious.
/**
* Gets fields from previous steps and populate a ComboVar.
*
* @param comboVar the Combo Box (with Variables) to populate
* @param transMeta the transformation metadata
* @param stepMeta the step metadata
*/
public static final void getFieldsFromPrevious(ComboVar comboVar, TransMeta transMeta, StepMeta stepMeta) {
String selectedField = null;
int indexField = -1;
try {
RowMetaInterface r = transMeta.getPrevStepFields(stepMeta);
selectedField = comboVar.getText();
comboVar.removeAll();
if (r != null && !r.isEmpty()) {
r.getFieldNames();
comboVar.setItems(r.getFieldNames());
indexField = r.indexOfValue(selectedField);
}
// Select value if possible...
if (indexField > -1) {
comboVar.select(indexField);
} else {
if (selectedField != null) {
comboVar.setText(selectedField);
}
}
} catch (KettleException ke) {
new ErrorDialog(comboVar.getShell(), BaseMessages.getString(PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogTitle"), BaseMessages.getString(PKG, "BaseStepDialog.FailedToGetFieldsPrevious.DialogMessage"), ke);
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class CalculatorDialog method open.
@Override
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, currentMeta);
ModifyListener lsMod = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
currentMeta.setChanged();
}
};
changed = currentMeta.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "CalculatorDialog.DialogTitle"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "System.Label.StepName"));
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, "CalculatorDialog.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 FieldsRows = currentMeta.getCalculation() != null ? currentMeta.getCalculation().length : 1;
colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.NewFieldColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.CalculationColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldAColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldBColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.FieldCColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.ValueTypeColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.LengthColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.PrecisionColumn.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.RemoveColumn.Column"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { BaseMessages.getString(PKG, "System.Combo.No"), BaseMessages.getString(PKG, "System.Combo.Yes") }), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.ConversionMask.Column"), ColumnInfo.COLUMN_TYPE_FORMAT, 6), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.DecimalSymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.GroupingSymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "CalculatorDialog.CurrencySymbol.Column"), ColumnInfo.COLUMN_TYPE_TEXT, false) };
colinf[1].setSelectionAdapter(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EnterSelectionDialog esd = new EnterSelectionDialog(shell, CalculatorMetaFunction.calcLongDesc, BaseMessages.getString(PKG, "CalculatorDialog.SelectCalculationType.Title"), BaseMessages.getString(PKG, "CalculatorDialog.SelectCalculationType.Message"));
String string = esd.open();
if (string != null) {
TableView tv = (TableView) e.widget;
tv.setText(string, e.x, e.y);
currentMeta.setChanged();
}
}
});
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() {
@Override
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, "CalculatorDialog.Log.UnableToFindInput"));
}
}
}
};
new Thread(runnable).start();
wFields.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent arg0) {
// Now set the combo's
shell.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
setComboBoxes();
}
});
}
});
// Some buttons
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"));
setButtonPositions(new Button[] { wOK, wCancel }, margin, null);
// Add listeners
lsCancel = new Listener() {
@Override
public void handleEvent(Event e) {
cancel();
}
};
lsOK = new Listener() {
@Override
public void handleEvent(Event e) {
ok();
}
};
wCancel.addListener(SWT.Selection, lsCancel);
wOK.addListener(SWT.Selection, lsOK);
lsDef = new SelectionAdapter() {
@Override
public void widgetDefaultSelected(SelectionEvent e) {
ok();
}
};
wStepname.addSelectionListener(lsDef);
// Detect X or ALT-F4 or something that kills this window...
shell.addShellListener(new ShellAdapter() {
@Override
public void shellClosed(ShellEvent e) {
cancel();
}
});
// Set the shell size, based upon previous time...
setSize();
getData();
currentMeta.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 ChangeFileEncodingDialog method get.
private void get() {
if (!gotPreviousFields) {
try {
String filefield = wFileName.getText();
String targetfilefield = wTargetFileName.getText();
wFileName.removeAll();
wTargetFileName.removeAll();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
wFileName.setItems(r.getFieldNames());
wTargetFileName.setItems(r.getFieldNames());
}
if (filefield != null) {
wFileName.setText(filefield);
}
if (targetfilefield != null) {
wTargetFileName.setText(targetfilefield);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ChangeFileEncodingDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "ChangeFileEncodingDialog.FailedToGetFields.DialogMessage"), ke);
}
gotPreviousFields = true;
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class ConcatFieldsDialog method get.
private void get() {
try {
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
TableItemInsertListener listener = new TableItemInsertListener() {
@Override
public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
if (v.isNumber()) {
if (v.getLength() > 0) {
int le = v.getLength();
int pr = v.getPrecision();
if (v.getPrecision() <= 0) {
pr = 0;
}
String mask = "";
for (int m = 0; m < le - pr; m++) {
mask += "0";
}
if (pr > 0) {
mask += ".";
}
for (int m = 0; m < pr; m++) {
mask += "0";
}
tableItem.setText(3, mask);
}
}
return true;
}
};
BaseStepDialog.getFieldsFromPrevious(r, wFields, 1, new int[] { 1 }, new int[] { 2 }, 4, 5, listener);
}
} 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 CreditCardValidatorDialog method get.
private void get() {
if (!gotPreviousFields) {
try {
String columnName = wFieldName.getText();
wFieldName.removeAll();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
r.getFieldNames();
for (int i = 0; i < r.getFieldNames().length; i++) {
wFieldName.add(r.getFieldNames()[i]);
}
}
wFieldName.setText(columnName);
gotPreviousFields = true;
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "CreditCardValidatorDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "CreditCardValidatorDialog.FailedToGetFields.DialogMessage"), ke);
}
}
}
Aggregations