use of org.pentaho.di.core.exception.KettleException 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.exception.KettleException 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);
}
}
}
use of org.pentaho.di.core.exception.KettleException in project pentaho-kettle by pentaho.
the class ScriptDialog 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);
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, "ScriptDialog.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Filename line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "ScriptDialog.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);
wSash = new SashForm(shell, SWT.VERTICAL);
// Top sash form
//
wTop = new Composite(wSash, SWT.NONE);
props.setLook(wTop);
FormLayout topLayout = new FormLayout();
topLayout.marginWidth = Const.FORM_MARGIN;
topLayout.marginHeight = Const.FORM_MARGIN;
wTop.setLayout(topLayout);
// Script line
wlScriptFunctions = new Label(wTop, SWT.NONE);
wlScriptFunctions.setText(BaseMessages.getString(PKG, "ScriptDialog.JavascriptFunctions.Label"));
props.setLook(wlScriptFunctions);
fdlScriptFunctions = new FormData();
fdlScriptFunctions.left = new FormAttachment(0, 0);
fdlScriptFunctions.top = new FormAttachment(0, 0);
wlScriptFunctions.setLayoutData(fdlScriptFunctions);
// Tree View Test
wTree = new Tree(wTop, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
props.setLook(wTree);
fdlTree = new FormData();
fdlTree.left = new FormAttachment(0, 0);
fdlTree.top = new FormAttachment(wlScriptFunctions, margin);
fdlTree.right = new FormAttachment(20, 0);
fdlTree.bottom = new FormAttachment(100, -margin);
wTree.setLayoutData(fdlTree);
// Script line
wlScript = new Label(wTop, SWT.NONE);
wlScript.setText(BaseMessages.getString(PKG, "ScriptDialog.Javascript.Label"));
props.setLook(wlScript);
fdlScript = new FormData();
fdlScript.left = new FormAttachment(wTree, margin);
fdlScript.top = new FormAttachment(0, 0);
wlScript.setLayoutData(fdlScript);
folder = new CTabFolder(wTop, SWT.BORDER | SWT.RESIZE);
folder.setSimple(false);
folder.setUnselectedImageVisible(true);
folder.setUnselectedCloseVisible(true);
fdScript = new FormData();
fdScript.left = new FormAttachment(wTree, margin);
fdScript.top = new FormAttachment(wlScript, margin);
fdScript.right = new FormAttachment(100, -5);
fdScript.bottom = new FormAttachment(100, -50);
folder.setLayoutData(fdScript);
wlPosition = new Label(wTop, SWT.NONE);
wlPosition.setText(BaseMessages.getString(PKG, "ScriptDialog.Position.Label"));
props.setLook(wlPosition);
fdlPosition = new FormData();
fdlPosition.left = new FormAttachment(wTree, margin);
fdlPosition.right = new FormAttachment(30, 0);
fdlPosition.top = new FormAttachment(folder, margin);
wlPosition.setLayoutData(fdlPosition);
wlHelpLabel = new Text(wTop, SWT.V_SCROLL | SWT.LEFT);
wlHelpLabel.setEditable(false);
wlHelpLabel.setText("Hallo");
props.setLook(wlHelpLabel);
fdHelpLabel = new FormData();
fdHelpLabel.left = new FormAttachment(wlPosition, margin);
fdHelpLabel.top = new FormAttachment(folder, margin);
fdHelpLabel.right = new FormAttachment(100, -5);
fdHelpLabel.bottom = new FormAttachment(100, 0);
wlHelpLabel.setLayoutData(fdHelpLabel);
wlHelpLabel.setVisible(false);
fdTop = new FormData();
fdTop.left = new FormAttachment(0, 0);
fdTop.top = new FormAttachment(0, 0);
fdTop.right = new FormAttachment(100, 0);
fdTop.bottom = new FormAttachment(100, 0);
wTop.setLayoutData(fdTop);
wBottom = new Composite(wSash, SWT.NONE);
props.setLook(wBottom);
FormLayout bottomLayout = new FormLayout();
bottomLayout.marginWidth = Const.FORM_MARGIN;
bottomLayout.marginHeight = Const.FORM_MARGIN;
wBottom.setLayout(bottomLayout);
wSeparator = new Label(wBottom, SWT.SEPARATOR | SWT.HORIZONTAL);
fdSeparator = new FormData();
fdSeparator.left = new FormAttachment(0, 0);
fdSeparator.right = new FormAttachment(100, 0);
fdSeparator.top = new FormAttachment(0, -margin + 2);
wSeparator.setLayoutData(fdSeparator);
wlFields = new Label(wBottom, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "ScriptDialog.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wSeparator, 0);
wlFields.setLayoutData(fdlFields);
final int FieldsRows = input.getFieldname().length;
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Filename"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.RenameTo"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Length"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Precision"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptDialog.ColumnInfo.Replace"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO) };
wFields = new TableView(transMeta, wBottom, 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, 0);
wFields.setLayoutData(fdFields);
fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(0, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
wBottom.setLayoutData(fdBottom);
fdSash = new FormData();
fdSash.left = new FormAttachment(0, 0);
fdSash.top = new FormAttachment(wStepname, 0);
fdSash.right = new FormAttachment(100, 0);
fdSash.bottom = new FormAttachment(100, -50);
wSash.setLayoutData(fdSash);
wSash.setWeights(new int[] { 75, 25 });
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wVars = new Button(shell, SWT.PUSH);
wVars.setText(BaseMessages.getString(PKG, "ScriptDialog.GetVariables.Button"));
wTest = new Button(shell, SWT.PUSH);
wTest.setText(BaseMessages.getString(PKG, "ScriptDialog.TestScript.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel, wVars, wTest }, margin, null);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
// lsGet = new Listener() { public void handleEvent(Event e) { get(); } };
lsTest = new Listener() {
public void handleEvent(Event e) {
newTest();
}
};
lsVars = new Listener() {
public void handleEvent(Event e) {
test(true, true);
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsTree = new Listener() {
public void handleEvent(Event e) {
treeDblClick(e);
}
};
// lsHelp = new Listener(){public void handleEvent(Event e){ wlHelpLabel.setVisible(true); }};
wCancel.addListener(SWT.Selection, lsCancel);
// wGet.addListener (SWT.Selection, lsGet );
wTest.addListener(SWT.Selection, lsTest);
wVars.addListener(SWT.Selection, lsVars);
wOK.addListener(SWT.Selection, lsOK);
wTree.addListener(SWT.MouseDoubleClick, lsTree);
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) {
if (!cancel()) {
e.doit = false;
}
}
});
folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
CTabItem cItem = (CTabItem) event.item;
event.doit = false;
if (cItem != null && folder.getItemCount() > 1) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.NO | SWT.YES);
messageBox.setText(BaseMessages.getString(PKG, "ScriptDialog.DeleteItem.Label"));
messageBox.setMessage(BaseMessages.getString(PKG, "ScriptDialog.ConfirmDeleteItem.Label", cItem.getText()));
switch(messageBox.open()) {
case SWT.YES:
modifyScriptTree(cItem, DELETE_ITEM);
event.doit = true;
break;
default:
break;
}
}
}
});
cMenu = new Menu(shell, SWT.POP_UP);
buildingFolderMenu();
tMenu = new Menu(shell, SWT.POP_UP);
buildingTreeMenu();
// Adding the Default Transform Scripts Item to the Tree
wTreeScriptsItem = new TreeItem(wTree, SWT.NULL);
wTreeScriptsItem.setImage(guiresource.getImageBol());
wTreeScriptsItem.setText(BaseMessages.getString(PKG, "ScriptDialog.TransformScript.Label"));
// Set the shell size, based upon previous time...
setSize();
getData();
// Adding the Rest (Functions, InputItems, etc.) to the Tree
buildSpecialFunctionsTree();
// Input Fields
iteminput = new TreeItem(wTree, SWT.NULL);
iteminput.setImage(imageInputFields);
iteminput.setText(BaseMessages.getString(PKG, "ScriptDialog.InputFields.Label"));
// Output Fields
itemoutput = new TreeItem(wTree, SWT.NULL);
itemoutput.setImage(imageOutputFields);
itemoutput.setText(BaseMessages.getString(PKG, "ScriptDialog.OutputFields.Label"));
// Display waiting message for input
itemWaitFieldsIn = new TreeItem(iteminput, SWT.NULL);
itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "ScriptDialog.GettingFields.Label"));
itemWaitFieldsIn.setForeground(guiresource.getColorDirectory());
iteminput.setExpanded(true);
// Display waiting message for output
itemWaitFieldsOut = new TreeItem(itemoutput, SWT.NULL);
itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "ScriptDialog.GettingFields.Label"));
itemWaitFieldsOut.setForeground(guiresource.getColorDirectory());
itemoutput.setExpanded(true);
//
// Search the fields in the background
//
final Runnable runnable = new Runnable() {
public void run() {
StepMeta stepMeta = transMeta.findStep(stepname);
if (stepMeta != null) {
try {
rowPrevStepFields = transMeta.getPrevStepFields(stepMeta);
if (rowPrevStepFields != null) {
setInputOutputFields();
} else {
// Can not get fields...end of wait message
iteminput.removeAll();
itemoutput.removeAll();
}
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
}
}
}
};
new Thread(runnable).start();
// rebuildInputFieldsTree();
// buildOutputFieldsTree();
buildAddClassesListTree();
addRenameTowTreeScriptItems();
input.setChanged(changed);
// Create the drag source on the tree
DragSource ds = new DragSource(wTree, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
TreeItem item = wTree.getSelection()[0];
// Qualifikation where the Drag Request Comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeScriptsItem)) {
event.doit = false;
} else if (!item.getData().equals("Function")) {
String strInsert = (String) item.getData();
if (strInsert.equals("jsFunction")) {
event.doit = true;
} else {
event.doit = false;
}
} else {
event.doit = false;
}
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Set the data to be the first selected item's text
event.data = wTree.getSelection()[0].getText();
}
});
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 ScriptValuesModDialog 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);
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, "ScriptValuesDialogMod.Shell.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Filename line
wlStepname = new Label(shell, SWT.RIGHT);
wlStepname.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.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);
wSash = new SashForm(shell, SWT.VERTICAL);
// Top sash form
//
wTop = new Composite(wSash, SWT.NONE);
props.setLook(wTop);
FormLayout topLayout = new FormLayout();
topLayout.marginWidth = Const.FORM_MARGIN;
topLayout.marginHeight = Const.FORM_MARGIN;
wTop.setLayout(topLayout);
// Script line
wlScriptFunctions = new Label(wTop, SWT.NONE);
wlScriptFunctions.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.JavascriptFunctions.Label"));
props.setLook(wlScriptFunctions);
fdlScriptFunctions = new FormData();
fdlScriptFunctions.left = new FormAttachment(0, 0);
fdlScriptFunctions.top = new FormAttachment(0, 0);
wlScriptFunctions.setLayoutData(fdlScriptFunctions);
// Tree View Test
wTree = new Tree(wTop, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
props.setLook(wTree);
fdlTree = new FormData();
fdlTree.left = new FormAttachment(0, 0);
fdlTree.top = new FormAttachment(wlScriptFunctions, margin);
fdlTree.right = new FormAttachment(20, 0);
fdlTree.bottom = new FormAttachment(100, -margin);
wTree.setLayoutData(fdlTree);
// Script line
wlScript = new Label(wTop, SWT.NONE);
wlScript.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Javascript.Label"));
props.setLook(wlScript);
fdlScript = new FormData();
fdlScript.left = new FormAttachment(wTree, margin);
fdlScript.top = new FormAttachment(0, 0);
wlScript.setLayoutData(fdlScript);
folder = new CTabFolder(wTop, SWT.BORDER | SWT.RESIZE);
folder.setSimple(false);
folder.setUnselectedImageVisible(true);
folder.setUnselectedCloseVisible(true);
fdScript = new FormData();
fdScript.left = new FormAttachment(wTree, margin);
fdScript.top = new FormAttachment(wlScript, margin);
fdScript.right = new FormAttachment(100, -5);
fdScript.bottom = new FormAttachment(100, -50);
folder.setLayoutData(fdScript);
wlPosition = new Label(wTop, SWT.NONE);
wlPosition.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Position.Label"));
props.setLook(wlPosition);
fdlPosition = new FormData();
fdlPosition.left = new FormAttachment(wTree, margin);
fdlPosition.right = new FormAttachment(30, 0);
fdlPosition.top = new FormAttachment(folder, margin);
wlPosition.setLayoutData(fdlPosition);
Label wlCompatible = new Label(wTop, SWT.NONE);
wlCompatible.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Compatible.Label"));
props.setLook(wlCompatible);
FormData fdlCompatible = new FormData();
fdlCompatible.left = new FormAttachment(wTree, margin);
fdlCompatible.right = new FormAttachment(middle, 0);
fdlCompatible.top = new FormAttachment(wlPosition, margin);
wlCompatible.setLayoutData(fdlCompatible);
wCompatible = new Button(wTop, SWT.CHECK);
wCompatible.setToolTipText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Compatible.Tooltip"));
props.setLook(wCompatible);
FormData fdCompatible = new FormData();
fdCompatible.left = new FormAttachment(wlCompatible, margin);
fdCompatible.top = new FormAttachment(wlPosition, margin);
wCompatible.setLayoutData(fdCompatible);
wCompatible.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
setInputOutputFields();
input.setChanged(true);
}
});
Label wlOptimizationLevel = new Label(wTop, SWT.NONE);
wlOptimizationLevel.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OptimizationLevel.Label"));
props.setLook(wlOptimizationLevel);
FormData fdlOptimizationLevel = new FormData();
fdlOptimizationLevel.left = new FormAttachment(wCompatible, margin * 2);
fdlOptimizationLevel.top = new FormAttachment(wlPosition, margin);
wlOptimizationLevel.setLayoutData(fdlOptimizationLevel);
wOptimizationLevel = new TextVar(transMeta, wTop, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
wOptimizationLevel.setToolTipText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OptimizationLevel.Tooltip"));
props.setLook(wOptimizationLevel);
FormData fdOptimizationLevel = new FormData();
fdOptimizationLevel.left = new FormAttachment(wlOptimizationLevel, margin);
fdOptimizationLevel.top = new FormAttachment(wlPosition, margin);
fdOptimizationLevel.right = new FormAttachment(100, margin);
wOptimizationLevel.setLayoutData(fdOptimizationLevel);
wOptimizationLevel.addModifyListener(lsMod);
wlHelpLabel = new Text(wTop, SWT.V_SCROLL | SWT.LEFT);
wlHelpLabel.setEditable(false);
wlHelpLabel.setText("Hallo");
props.setLook(wlHelpLabel);
fdHelpLabel = new FormData();
fdHelpLabel.left = new FormAttachment(wlPosition, margin);
fdHelpLabel.top = new FormAttachment(folder, margin);
fdHelpLabel.right = new FormAttachment(100, -5);
fdHelpLabel.bottom = new FormAttachment(100, 0);
wlHelpLabel.setLayoutData(fdHelpLabel);
wlHelpLabel.setVisible(false);
fdTop = new FormData();
fdTop.left = new FormAttachment(0, 0);
fdTop.top = new FormAttachment(0, 0);
fdTop.right = new FormAttachment(100, 0);
fdTop.bottom = new FormAttachment(100, 0);
wTop.setLayoutData(fdTop);
wBottom = new Composite(wSash, SWT.NONE);
props.setLook(wBottom);
FormLayout bottomLayout = new FormLayout();
bottomLayout.marginWidth = Const.FORM_MARGIN;
bottomLayout.marginHeight = Const.FORM_MARGIN;
wBottom.setLayout(bottomLayout);
wSeparator = new Label(wBottom, SWT.SEPARATOR | SWT.HORIZONTAL);
fdSeparator = new FormData();
fdSeparator.left = new FormAttachment(0, 0);
fdSeparator.right = new FormAttachment(100, 0);
fdSeparator.top = new FormAttachment(0, -margin + 2);
wSeparator.setLayoutData(fdSeparator);
wlFields = new Label(wBottom, SWT.NONE);
wlFields.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Fields.Label"));
props.setLook(wlFields);
fdlFields = new FormData();
fdlFields.left = new FormAttachment(0, 0);
fdlFields.top = new FormAttachment(wSeparator, 0);
wlFields.setLayoutData(fdlFields);
final int FieldsRows = input.getFieldname().length;
ColumnInfo[] colinf = new ColumnInfo[] { new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Filename"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.RenameTo"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Type"), ColumnInfo.COLUMN_TYPE_CCOMBO, ValueMetaFactory.getValueMetaNames()), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Length"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Precision"), ColumnInfo.COLUMN_TYPE_TEXT, false), new ColumnInfo(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ColumnInfo.Replace"), ColumnInfo.COLUMN_TYPE_CCOMBO, YES_NO_COMBO) };
wFields = new TableView(transMeta, wBottom, 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, 0);
wFields.setLayoutData(fdFields);
fdBottom = new FormData();
fdBottom.left = new FormAttachment(0, 0);
fdBottom.top = new FormAttachment(0, 0);
fdBottom.right = new FormAttachment(100, 0);
fdBottom.bottom = new FormAttachment(100, 0);
wBottom.setLayoutData(fdBottom);
fdSash = new FormData();
fdSash.left = new FormAttachment(0, 0);
fdSash.top = new FormAttachment(wStepname, 0);
fdSash.right = new FormAttachment(100, 0);
fdSash.bottom = new FormAttachment(100, -50);
wSash.setLayoutData(fdSash);
wSash.setWeights(new int[] { 75, 25 });
wOK = new Button(shell, SWT.PUSH);
wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wVars = new Button(shell, SWT.PUSH);
wVars.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.GetVariables.Button"));
wTest = new Button(shell, SWT.PUSH);
wTest.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestScript.Button"));
wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
setButtonPositions(new Button[] { wOK, wCancel, wVars, wTest }, margin, null);
// Add listeners
lsCancel = new Listener() {
public void handleEvent(Event e) {
cancel();
}
};
// lsGet = new Listener() { public void handleEvent(Event e) { get(); } };
lsTest = new Listener() {
public void handleEvent(Event e) {
newTest();
}
};
lsVars = new Listener() {
public void handleEvent(Event e) {
test(true, true);
}
};
lsOK = new Listener() {
public void handleEvent(Event e) {
ok();
}
};
lsTree = new Listener() {
public void handleEvent(Event e) {
treeDblClick(e);
}
};
// lsHelp = new Listener(){public void handleEvent(Event e){ wlHelpLabel.setVisible(true); }};
wCancel.addListener(SWT.Selection, lsCancel);
// wGet.addListener (SWT.Selection, lsGet );
wTest.addListener(SWT.Selection, lsTest);
wVars.addListener(SWT.Selection, lsVars);
wOK.addListener(SWT.Selection, lsOK);
wTree.addListener(SWT.MouseDoubleClick, lsTree);
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) {
if (!cancel()) {
e.doit = false;
}
}
});
folder.addCTabFolder2Listener(new CTabFolder2Adapter() {
public void close(CTabFolderEvent event) {
CTabItem cItem = (CTabItem) event.item;
event.doit = false;
if (cItem != null && folder.getItemCount() > 1) {
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.NO | SWT.YES);
messageBox.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.DeleteItem.Label"));
messageBox.setMessage(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ConfirmDeleteItem.Label", cItem.getText()));
switch(messageBox.open()) {
case SWT.YES:
modifyScriptTree(cItem, DELETE_ITEM);
event.doit = true;
break;
default:
break;
}
}
}
});
cMenu = new Menu(shell, SWT.POP_UP);
buildingFolderMenu();
tMenu = new Menu(shell, SWT.POP_UP);
buildingTreeMenu();
// Adding the Default Transform Scripts Item to the Tree
wTreeScriptsItem = new TreeItem(wTree, SWT.NULL);
wTreeScriptsItem.setImage(guiresource.getImageBol());
wTreeScriptsItem.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.TransformScript.Label"));
// Set the shell size, based upon previous time...
setSize();
getData();
// Adding the Rest (Functions, InputItems, etc.) to the Tree
buildSpecialFunctionsTree();
// Input Fields
iteminput = new TreeItem(wTree, SWT.NULL);
iteminput.setImage(imageInputFields);
iteminput.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.InputFields.Label"));
// Output Fields
itemoutput = new TreeItem(wTree, SWT.NULL);
itemoutput.setImage(imageOutputFields);
itemoutput.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.OutputFields.Label"));
// Display waiting message for input
itemWaitFieldsIn = new TreeItem(iteminput, SWT.NULL);
itemWaitFieldsIn.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.GettingFields.Label"));
itemWaitFieldsIn.setForeground(guiresource.getColorDirectory());
iteminput.setExpanded(true);
// Display waiting message for output
itemWaitFieldsOut = new TreeItem(itemoutput, SWT.NULL);
itemWaitFieldsOut.setText(BaseMessages.getString(PKG, "ScriptValuesDialogMod.GettingFields.Label"));
itemWaitFieldsOut.setForeground(guiresource.getColorDirectory());
itemoutput.setExpanded(true);
//
// Search the fields in the background
//
final Runnable runnable = new Runnable() {
public void run() {
StepMeta stepMeta = transMeta.findStep(stepname);
if (stepMeta != null) {
try {
rowPrevStepFields = transMeta.getPrevStepFields(stepMeta);
if (rowPrevStepFields != null) {
setInputOutputFields();
} else {
// Can not get fields...end of wait message
iteminput.removeAll();
itemoutput.removeAll();
}
} catch (KettleException e) {
logError(BaseMessages.getString(PKG, "System.Dialog.GetFieldsFailed.Message"));
}
}
}
};
new Thread(runnable).start();
// rebuildInputFieldsTree();
// buildOutputFieldsTree();
buildAddClassesListTree();
addRenameTowTreeScriptItems();
input.setChanged(changed);
// Create the drag source on the tree
DragSource ds = new DragSource(wTree, DND.DROP_MOVE);
ds.setTransfer(new Transfer[] { TextTransfer.getInstance() });
ds.addDragListener(new DragSourceAdapter() {
public void dragStart(DragSourceEvent event) {
TreeItem item = wTree.getSelection()[0];
// Qualifikation where the Drag Request Comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeScriptsItem)) {
event.doit = false;
} else if (!item.getData().equals("Function")) {
String strInsert = (String) item.getData();
if (strInsert.equals("jsFunction")) {
event.doit = true;
} else {
event.doit = false;
}
} else {
event.doit = false;
}
} else {
event.doit = false;
}
}
public void dragSetData(DragSourceEvent event) {
// Set the data to be the first selected item's text
event.data = wTree.getSelection()[0].getText();
}
});
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 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);
}
}
Aggregations