use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class SimpleMappingDialog method addMappingDefinitionTab.
private void addMappingDefinitionTab(final MappingIODefinition definition, int index, final String tabTitle, final String tabTooltip, String sourceColumnLabel, String targetColumnLabel, final boolean input) {
final CTabItem wTab;
if (index >= wTabFolder.getItemCount()) {
wTab = new CTabItem(wTabFolder, SWT.CLOSE);
} else {
wTab = new CTabItem(wTabFolder, SWT.CLOSE, index);
}
setMappingDefinitionTabNameAndToolTip(wTab, tabTitle, tabTooltip, definition, input);
Composite wInputComposite = new Composite(wTabFolder, SWT.NONE);
props.setLook(wInputComposite);
FormLayout tabLayout = new FormLayout();
tabLayout.marginWidth = 15;
tabLayout.marginHeight = 15;
wInputComposite.setLayout(tabLayout);
// Now add a table view with the 2 columns to specify: input and output
// fields for the source and target steps.
//
final Button wbEnterMapping = new Button(wInputComposite, SWT.PUSH);
props.setLook(wbEnterMapping);
if (input) {
wbEnterMapping.setText(BaseMessages.getString(PKG, "SimpleMappingDialog.button.EnterMapping"));
} else {
wbEnterMapping.setText(BaseMessages.getString(PKG, "SimpleMappingDialog.button.GetFields"));
}
FormData fdbEnterMapping = new FormData();
fdbEnterMapping.bottom = new FormAttachment(100);
fdbEnterMapping.right = new FormAttachment(100);
wbEnterMapping.setLayoutData(fdbEnterMapping);
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, wInputComposite, SWT.FULL_SELECTION | SWT.SINGLE | SWT.BORDER, colinfo, 1, false, lsMod, props, false);
props.setLook(wFieldMappings);
FormData fdMappings = new FormData();
fdMappings.left = new FormAttachment(0);
fdMappings.right = new FormAttachment(100);
fdMappings.top = new FormAttachment(0);
fdMappings.bottom = new FormAttachment(wbEnterMapping, -10);
wFieldMappings.setLayoutData(fdMappings);
wFieldMappings.getTable().addListener(SWT.Resize, new ColumnsResizer(0, 50, 50));
for (MappingValueRename valueRename : definition.getValueRenames()) {
TableItem tableItem = new TableItem(wFieldMappings.table, SWT.NONE);
tableItem.setText(1, Const.NVL(valueRename.getSourceValueName(), ""));
tableItem.setText(2, Const.NVL(valueRename.getTargetValueName(), ""));
}
wFieldMappings.removeEmptyRows();
wFieldMappings.setRowNums();
wFieldMappings.optWidth(true);
wbEnterMapping.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent arg0) {
try {
if (input) {
// INPUT
//
RowMetaInterface sourceRowMeta = getFieldsFromStep(true, input);
RowMetaInterface targetRowMeta = getFieldsFromStep(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);
//
definition.getValueRenames().clear();
// Now add the new values...
for (int i = 0; i < mappings.size(); i++) {
SourceToTargetMapping mapping = mappings.get(i);
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);
definition.getValueRenames().add(new MappingValueRename(source, target));
}
wFieldMappings.removeEmptyRows();
wFieldMappings.setRowNums();
wFieldMappings.optWidth(true);
}
} else {
// OUTPUT
//
RowMetaInterface sourceRowMeta = getFieldsFromStep(true, input);
BaseStepDialog.getFieldsFromPrevious(sourceRowMeta, wFieldMappings, 1, new int[] { 1 }, new int[] {}, -1, -1, null);
}
} catch (KettleException e) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "System.Dialog.Error.Title"), BaseMessages.getString(PKG, "SimpleMappingDialog.Exception.ErrorGettingMappingSourceAndTargetFields", e.toString()), e);
}
}
});
if (input) {
Button wRenameOutput = new Button(wInputComposite, SWT.CHECK);
props.setLook(wRenameOutput);
wRenameOutput.setText(BaseMessages.getString(PKG, "SimpleMappingDialog.input.RenamingOnOutput"));
FormData fdRenameOutput = new FormData();
fdRenameOutput.top = new FormAttachment(wFieldMappings, 10);
fdRenameOutput.left = new FormAttachment(0, 0);
wRenameOutput.setLayoutData(fdRenameOutput);
wRenameOutput.setSelection(definition.isRenamingOnOutput());
wRenameOutput.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
// flip the switch
definition.setRenamingOnOutput(!definition.isRenamingOnOutput());
}
});
}
FormData fdParametersComposite = new FormData();
fdParametersComposite.left = new FormAttachment(0, 0);
fdParametersComposite.top = new FormAttachment(0, 0);
fdParametersComposite.right = new FormAttachment(100, 0);
fdParametersComposite.bottom = new FormAttachment(100, 0);
wInputComposite.setLayoutData(fdParametersComposite);
wInputComposite.layout();
wTab.setControl(wInputComposite);
final ApplyChanges applyChanges = new MappingDefinitionTab(definition, wFieldMappings);
changeList.add(applyChanges);
wTabFolder.setSelection(wTab);
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class ZipFileDialog method get.
private void get() {
if (!gotPreviousFields) {
gotPreviousFields = true;
String source = wSourceFileNameField.getText();
String target = wTargetFileNameField.getText();
String base = wBaseFolderField.getText();
try {
wSourceFileNameField.removeAll();
wTargetFileNameField.removeAll();
wBaseFolderField.removeAll();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
String[] fields = r.getFieldNames();
wSourceFileNameField.setItems(fields);
wTargetFileNameField.setItems(fields);
wBaseFolderField.setItems(fields);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ZipFileDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "ZipFileDialog.FailedToGetFields.DialogMessage"), ke);
} finally {
if (source != null) {
wSourceFileNameField.setText(source);
}
if (target != null) {
wTargetFileNameField.setText(target);
}
if (base != null) {
wBaseFolderField.setText(base);
}
}
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class TextFileOutputDialog method getFields.
private void getFields() {
if (!gotPreviousFields) {
try {
String field = wFileNameField.getText();
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
wFileNameField.setItems(r.getFieldNames());
}
if (field != null) {
wFileNameField.setText(field);
}
} catch (KettleException ke) {
new ErrorDialog(shell, BaseMessages.getString(PKG, "TextFileOutputDialog.FailedToGetFields.DialogTitle"), BaseMessages.getString(PKG, "TextFileOutputDialog.FailedToGetFields.DialogMessage"), ke);
}
gotPreviousFields = true;
}
}
use of org.pentaho.di.core.row.RowMetaInterface in project pentaho-kettle by pentaho.
the class TextFileOutputDialog method get.
private void get() {
try {
RowMetaInterface r = transMeta.getPrevStepFields(stepname);
if (r != null) {
TableItemInsertListener listener = new TableItemInsertListener() {
public boolean tableItemInserted(TableItem tableItem, ValueMetaInterface v) {
if (v.isNumeric()) {
// currency symbol
tableItem.setText(6, Const.NVL(v.getCurrencySymbol(), ""));
// decimal and grouping
tableItem.setText(7, Const.NVL(v.getDecimalSymbol(), ""));
tableItem.setText(8, Const.NVL(v.getGroupingSymbol(), ""));
}
// trim type
tableItem.setText(9, Const.NVL(ValueMetaString.getTrimTypeDesc(v.getTrimType()), ""));
// conversion mask
if (!Utils.isEmpty(v.getConversionMask())) {
tableItem.setText(3, v.getConversionMask());
} else {
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 UniqueRowsDialog 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);
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, "UniqueRowsDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Stepname line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.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);
// ///////////////////////////////
// START OF Settings GROUP //
// ///////////////////////////////
wSettings = new Group(shell, SWT.SHADOW_NONE);
props.setLook(wSettings);
wSettings.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Settings.Label"));
FormLayout SettingsgroupLayout = new FormLayout();
SettingsgroupLayout.marginWidth = 10;
SettingsgroupLayout.marginHeight = 10;
wSettings.setLayout(SettingsgroupLayout);
wlCount = new Label(wSettings, SWT.RIGHT);
wlCount.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Count.Label"));
props.setLook(wlCount);
fdlCount = new FormData();
fdlCount.left = new FormAttachment(0, 0);
fdlCount.top = new FormAttachment(wStepname, margin);
fdlCount.right = new FormAttachment(middle, -margin);
wlCount.setLayoutData(fdlCount);
wCount = new Button(wSettings, SWT.CHECK);
props.setLook(wCount);
wCount.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsDialog.Count.ToolTip", Const.CR));
fdCount = new FormData();
fdCount.left = new FormAttachment(middle, 0);
fdCount.top = new FormAttachment(wStepname, margin);
wCount.setLayoutData(fdCount);
wCount.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
input.setChanged();
setFlags();
}
});
wlCountField = new Label(wSettings, SWT.LEFT);
wlCountField.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.CounterField.Label"));
props.setLook(wlCountField);
fdlCountField = new FormData();
fdlCountField.left = new FormAttachment(wCount, margin);
fdlCountField.top = new FormAttachment(wStepname, margin);
wlCountField.setLayoutData(fdlCountField);
wCountField = new Text(wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wCountField);
wCountField.addModifyListener(lsMod);
fdCountField = new FormData();
fdCountField.left = new FormAttachment(wlCountField, margin);
fdCountField.top = new FormAttachment(wStepname, margin);
fdCountField.right = new FormAttachment(100, 0);
wCountField.setLayoutData(fdCountField);
wlRejectDuplicateRow = new Label(wSettings, SWT.RIGHT);
wlRejectDuplicateRow.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.RejectDuplicateRow.Label"));
props.setLook(wlRejectDuplicateRow);
fdlRejectDuplicateRow = new FormData();
fdlRejectDuplicateRow.left = new FormAttachment(0, 0);
fdlRejectDuplicateRow.top = new FormAttachment(wCountField, margin);
fdlRejectDuplicateRow.right = new FormAttachment(middle, -margin);
wlRejectDuplicateRow.setLayoutData(fdlRejectDuplicateRow);
wRejectDuplicateRow = new Button(wSettings, SWT.CHECK);
props.setLook(wRejectDuplicateRow);
wRejectDuplicateRow.setToolTipText(BaseMessages.getString(PKG, "UniqueRowsDialog.RejectDuplicateRow.ToolTip", Const.CR));
fdRejectDuplicateRow = new FormData();
fdRejectDuplicateRow.left = new FormAttachment(middle, margin);
fdRejectDuplicateRow.top = new FormAttachment(wCountField, margin);
wRejectDuplicateRow.setLayoutData(fdRejectDuplicateRow);
wRejectDuplicateRow.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
input.setChanged();
setErrorDesc();
}
});
wlErrorDesc = new Label(wSettings, SWT.LEFT);
wlErrorDesc.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.ErrorDescription.Label"));
props.setLook(wlErrorDesc);
fdlErrorDesc = new FormData();
fdlErrorDesc.left = new FormAttachment(wRejectDuplicateRow, margin);
fdlErrorDesc.top = new FormAttachment(wCountField, margin);
wlErrorDesc.setLayoutData(fdlErrorDesc);
wErrorDesc = new TextVar(transMeta, wSettings, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wErrorDesc);
wErrorDesc.addModifyListener(lsMod);
fdErrorDesc = new FormData();
fdErrorDesc.left = new FormAttachment(wlErrorDesc, margin);
fdErrorDesc.top = new FormAttachment(wCountField, margin);
fdErrorDesc.right = new FormAttachment(100, 0);
wErrorDesc.setLayoutData(fdErrorDesc);
fdSettings = new FormData();
fdSettings.left = new FormAttachment(0, margin);
fdSettings.top = new FormAttachment(wStepname, margin);
fdSettings.right = new FormAttachment(100, -margin);
wSettings.setLayoutData(fdSettings);
// ///////////////////////////////////////////////////////////
// / END OF Settings GROUP
// ///////////////////////////////////////////////////////////
// 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, "UniqueRowsDialog.Get.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
fdOK = new FormData();
setButtonPositions(new Button[] { wOK, wCancel, wGet }, margin, null);
wlFields = new Label(shell, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "UniqueRowsDialog.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wSettings, margin);
wlFields.setLayoutData(fdlFields);
final int FieldsRows = input.getCompareFields() == null ? 0 : input.getCompareFields().length;
colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "UniqueRowsDialog.ColumnInfo.Fieldname"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "" }, false), new ColumnInfo(BaseMessages.getString(PKG, "UniqueRowsDialog.ColumnInfo.IgnoreCase"), ColumnInfo.COLUMN_TYPE_CCOMBO, new String[] { "Y", "N" }, true) };
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(wOK, -2 * margin);
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();
// 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);
wCountField.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