use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class SelectValuesDialog method setComboValues.
private void setComboValues() {
Runnable fieldLoader = new Runnable() {
public void run() {
try {
prevFields = transMeta.getPrevStepFields(stepname);
} catch (KettleException e) {
prevFields = new RowMeta();
String msg = BaseMessages.getString(PKG, "SelectValuesDialog.DoMapping.UnableToFindInput");
logError(msg);
}
String[] prevStepFieldNames = prevFields != null ? prevFields.getFieldNames() : new String[0];
Arrays.sort(prevStepFieldNames);
bPreviousFieldsLoaded = true;
for (int i = 0; i < fieldColumns.size(); i++) {
ColumnInfo colInfo = fieldColumns.get(i);
colInfo.setComboValues(prevStepFieldNames);
}
}
};
shell.getDisplay().asyncExec(fieldLoader);
}
use of org.pentaho.di.core.exception.KettleException 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.exception.KettleException 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.exception.KettleException 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;
}
use of org.pentaho.di.core.exception.KettleException 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);
}
Aggregations