use of org.apache.hop.ui.core.widget.StyledTextComp in project hop by apache.
the class ActionEvalTableContentDialog method open.
@Override
public IAction open() {
Shell parent = getParent();
shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.MIN | SWT.MAX | SWT.RESIZE);
props.setLook(shell);
WorkflowDialog.setShellImage(shell, action);
ModifyListener lsMod = e -> action.setChanged();
changed = action.hasChanged();
FormLayout formLayout = new FormLayout();
formLayout.marginWidth = Const.FORM_MARGIN;
formLayout.marginHeight = Const.FORM_MARGIN;
shell.setLayout(formLayout);
shell.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Title"));
int middle = props.getMiddlePct();
int margin = Const.MARGIN;
// Buttons go at the very bottom
//
Button wOk = new Button(shell, SWT.PUSH);
wOk.setText(BaseMessages.getString(PKG, "System.Button.OK"));
wOk.addListener(SWT.Selection, e -> ok());
Button wCancel = new Button(shell, SWT.PUSH);
wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));
wCancel.addListener(SWT.Selection, e -> cancel());
BaseTransformDialog.positionBottomButtons(shell, new Button[] { wOk, wCancel }, margin, null);
// Filename line
Label wlName = new Label(shell, SWT.RIGHT);
wlName.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Name.Label"));
props.setLook(wlName);
FormData fdlName = new FormData();
fdlName.left = new FormAttachment(0, 0);
fdlName.right = new FormAttachment(middle, -margin);
fdlName.top = new FormAttachment(0, margin);
wlName.setLayoutData(fdlName);
wName = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wName);
wName.addModifyListener(lsMod);
FormData fdName = new FormData();
fdName.left = new FormAttachment(middle, 0);
fdName.top = new FormAttachment(0, margin);
fdName.right = new FormAttachment(100, 0);
wName.setLayoutData(fdName);
// Connection line
wConnection = addConnectionLine(shell, wName, action.getDatabase(), lsMod);
// Schema name line
wlSchemaname = new Label(shell, SWT.RIGHT);
wlSchemaname.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Schemaname.Label"));
props.setLook(wlSchemaname);
FormData fdlSchemaname = new FormData();
fdlSchemaname.left = new FormAttachment(0, 0);
fdlSchemaname.right = new FormAttachment(middle, 0);
fdlSchemaname.top = new FormAttachment(wConnection, margin);
wlSchemaname.setLayoutData(fdlSchemaname);
wSchemaname = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wSchemaname);
wSchemaname.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.Schemaname.Tooltip"));
wSchemaname.addModifyListener(lsMod);
FormData fdSchemaname = new FormData();
fdSchemaname.left = new FormAttachment(middle, 0);
fdSchemaname.top = new FormAttachment(wConnection, margin);
fdSchemaname.right = new FormAttachment(100, 0);
wSchemaname.setLayoutData(fdSchemaname);
// Table name line
wlTablename = new Label(shell, SWT.RIGHT);
wlTablename.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Tablename.Label"));
props.setLook(wlTablename);
FormData fdlTablename = new FormData();
fdlTablename.left = new FormAttachment(0, 0);
fdlTablename.right = new FormAttachment(middle, 0);
fdlTablename.top = new FormAttachment(wSchemaname, margin);
wlTablename.setLayoutData(fdlTablename);
wbTable = new Button(shell, SWT.PUSH | SWT.CENTER);
props.setLook(wbTable);
wbTable.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
FormData fdbTable = new FormData();
fdbTable.right = new FormAttachment(100, 0);
fdbTable.top = new FormAttachment(wSchemaname, margin / 2);
wbTable.setLayoutData(fdbTable);
wbTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
getTableName();
}
});
wTablename = new TextVar(variables, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
props.setLook(wTablename);
wTablename.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.Tablename.Tooltip"));
wTablename.addModifyListener(lsMod);
FormData fdTablename = new FormData();
fdTablename.left = new FormAttachment(middle, 0);
fdTablename.top = new FormAttachment(wSchemaname, margin);
fdTablename.right = new FormAttachment(wbTable, -margin);
wTablename.setLayoutData(fdTablename);
// ////////////////////////
// START OF Success GROUP///
// ///////////////////////////////
Group wSuccessGroup = new Group(shell, SWT.SHADOW_NONE);
props.setLook(wSuccessGroup);
wSuccessGroup.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.SuccessGroup.Group.Label"));
FormLayout successGroupLayout = new FormLayout();
successGroupLayout.marginWidth = 10;
successGroupLayout.marginHeight = 10;
wSuccessGroup.setLayout(successGroupLayout);
// Success Condition
Label wlSuccessCondition = new Label(wSuccessGroup, SWT.RIGHT);
wlSuccessCondition.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.SuccessCondition.Label"));
props.setLook(wlSuccessCondition);
FormData fdlSuccessCondition = new FormData();
fdlSuccessCondition.left = new FormAttachment(0, -margin);
fdlSuccessCondition.right = new FormAttachment(middle, -2 * margin);
fdlSuccessCondition.top = new FormAttachment(0, margin);
wlSuccessCondition.setLayoutData(fdlSuccessCondition);
wSuccessCondition = new CCombo(wSuccessGroup, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER);
wSuccessCondition.setItems(ActionEvalTableContent.successConditionsDesc);
// +1: starts at -1
wSuccessCondition.select(0);
props.setLook(wSuccessCondition);
FormData fdSuccessCondition = new FormData();
fdSuccessCondition.left = new FormAttachment(middle, -margin);
fdSuccessCondition.top = new FormAttachment(0, margin);
fdSuccessCondition.right = new FormAttachment(100, 0);
wSuccessCondition.setLayoutData(fdSuccessCondition);
wSuccessCondition.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// disable selection event
}
});
// Success when number of errors less than
Label wlLimit = new Label(wSuccessGroup, SWT.RIGHT);
wlLimit.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Limit.Label"));
props.setLook(wlLimit);
FormData fdlLimit = new FormData();
fdlLimit.left = new FormAttachment(0, -margin);
fdlLimit.top = new FormAttachment(wSuccessCondition, margin);
fdlLimit.right = new FormAttachment(middle, -2 * margin);
wlLimit.setLayoutData(fdlLimit);
wLimit = new TextVar(variables, wSuccessGroup, SWT.SINGLE | SWT.LEFT | SWT.BORDER, BaseMessages.getString(PKG, "ActionEvalTableContent.Limit.Tooltip"));
props.setLook(wLimit);
wLimit.addModifyListener(lsMod);
FormData fdLimit = new FormData();
fdLimit.left = new FormAttachment(middle, -margin);
fdLimit.top = new FormAttachment(wSuccessCondition, margin);
fdLimit.right = new FormAttachment(100, -margin);
wLimit.setLayoutData(fdLimit);
FormData fdSuccessGroup = new FormData();
fdSuccessGroup.left = new FormAttachment(0, margin);
fdSuccessGroup.top = new FormAttachment(wbTable, margin);
fdSuccessGroup.right = new FormAttachment(100, -margin);
wSuccessGroup.setLayoutData(fdSuccessGroup);
// ///////////////////////////////////////////////////////////
// / END OF SuccessGroup GROUP
// ///////////////////////////////////////////////////////////
// ////////////////////////
// START OF Custom GROUP///
// ///////////////////////////////
Group wCustomGroup = new Group(shell, SWT.SHADOW_NONE);
props.setLook(wCustomGroup);
wCustomGroup.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.CustomGroup.Group.Label"));
FormLayout customGroupLayout = new FormLayout();
customGroupLayout.marginWidth = 10;
customGroupLayout.marginHeight = 10;
wCustomGroup.setLayout(customGroupLayout);
// custom Sql?
Label wlCustomSql = new Label(wCustomGroup, SWT.RIGHT);
wlCustomSql.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.customSQL.Label"));
props.setLook(wlCustomSql);
FormData fdlCustomSql = new FormData();
fdlCustomSql.left = new FormAttachment(0, -margin);
fdlCustomSql.top = new FormAttachment(0, margin);
fdlCustomSql.right = new FormAttachment(middle, -2 * margin);
wlCustomSql.setLayoutData(fdlCustomSql);
wCustomSql = new Button(wCustomGroup, SWT.CHECK);
props.setLook(wCustomSql);
wCustomSql.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.customSQL.Tooltip"));
FormData fdCustomSql = new FormData();
fdCustomSql.left = new FormAttachment(middle, -margin);
fdCustomSql.top = new FormAttachment(wlCustomSql, 0, SWT.CENTER);
fdCustomSql.right = new FormAttachment(100, 0);
wCustomSql.setLayoutData(fdCustomSql);
wCustomSql.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
setCustomSql();
action.setChanged();
}
});
// use Variable substitution?
wlUseSubs = new Label(wCustomGroup, SWT.RIGHT);
wlUseSubs.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.UseVariableSubst.Label"));
props.setLook(wlUseSubs);
FormData fdlUseSubs = new FormData();
fdlUseSubs.left = new FormAttachment(0, -margin);
fdlUseSubs.top = new FormAttachment(wlCustomSql, 2 * margin);
fdlUseSubs.right = new FormAttachment(middle, -2 * margin);
wlUseSubs.setLayoutData(fdlUseSubs);
wUseSubs = new Button(wCustomGroup, SWT.CHECK);
props.setLook(wUseSubs);
wUseSubs.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.UseVariableSubst.Tooltip"));
FormData fdUseSubs = new FormData();
fdUseSubs.left = new FormAttachment(middle, -margin);
fdUseSubs.top = new FormAttachment(wlUseSubs, 0, SWT.CENTER);
fdUseSubs.right = new FormAttachment(100, 0);
wUseSubs.setLayoutData(fdUseSubs);
wUseSubs.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
action.setChanged();
}
});
// clear result rows ?
wlClearResultList = new Label(wCustomGroup, SWT.RIGHT);
wlClearResultList.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.ClearResultList.Label"));
props.setLook(wlClearResultList);
FormData fdlClearResultList = new FormData();
fdlClearResultList.left = new FormAttachment(0, -margin);
fdlClearResultList.top = new FormAttachment(wlUseSubs, 2 * margin);
fdlClearResultList.right = new FormAttachment(middle, -2 * margin);
wlClearResultList.setLayoutData(fdlClearResultList);
wClearResultList = new Button(wCustomGroup, SWT.CHECK);
props.setLook(wClearResultList);
wClearResultList.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.ClearResultList.Tooltip"));
FormData fdClearResultList = new FormData();
fdClearResultList.left = new FormAttachment(middle, -margin);
fdClearResultList.top = new FormAttachment(wlClearResultList, 0, SWT.CENTER);
fdClearResultList.right = new FormAttachment(100, 0);
wClearResultList.setLayoutData(fdClearResultList);
wClearResultList.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
action.setChanged();
}
});
// add rows to result?
wlAddRowsToResult = new Label(wCustomGroup, SWT.RIGHT);
wlAddRowsToResult.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.AddRowsToResult.Label"));
props.setLook(wlAddRowsToResult);
FormData fdlAddRowsToResult = new FormData();
fdlAddRowsToResult.left = new FormAttachment(0, -margin);
fdlAddRowsToResult.top = new FormAttachment(wlClearResultList, 2 * margin);
fdlAddRowsToResult.right = new FormAttachment(middle, -2 * margin);
wlAddRowsToResult.setLayoutData(fdlAddRowsToResult);
wAddRowsToResult = new Button(wCustomGroup, SWT.CHECK);
props.setLook(wAddRowsToResult);
wAddRowsToResult.setToolTipText(BaseMessages.getString(PKG, "ActionEvalTableContent.AddRowsToResult.Tooltip"));
FormData fdAddRowsToResult = new FormData();
fdAddRowsToResult.left = new FormAttachment(middle, -margin);
fdAddRowsToResult.top = new FormAttachment(wlAddRowsToResult, 0, SWT.CENTER);
fdAddRowsToResult.right = new FormAttachment(100, 0);
wAddRowsToResult.setLayoutData(fdAddRowsToResult);
wAddRowsToResult.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
action.setChanged();
}
});
wlPosition = new Label(wCustomGroup, SWT.NONE);
props.setLook(wlPosition);
FormData fdlPosition = new FormData();
fdlPosition.left = new FormAttachment(0, 0);
fdlPosition.right = new FormAttachment(100, 0);
fdlPosition.bottom = new FormAttachment(100, -margin);
wlPosition.setLayoutData(fdlPosition);
// Script line
wlSql = new Label(wCustomGroup, SWT.NONE);
wlSql.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.Script.Label"));
props.setLook(wlSql);
FormData fdlSql = new FormData();
fdlSql.left = new FormAttachment(0, 0);
fdlSql.top = new FormAttachment(wlAddRowsToResult, 2 * margin);
wlSql.setLayoutData(fdlSql);
wbSqlTable = new Button(wCustomGroup, SWT.PUSH | SWT.CENTER);
props.setLook(wbSqlTable);
wbSqlTable.setText(BaseMessages.getString(PKG, "ActionEvalTableContent.GetSQLAndSelectStatement"));
FormData fdbSqlTable = new FormData();
fdbSqlTable.right = new FormAttachment(100, 0);
fdbSqlTable.top = new FormAttachment(wAddRowsToResult, margin);
wbSqlTable.setLayoutData(fdbSqlTable);
wbSqlTable.addListener(SWT.Selection, e -> getSql());
wSql = new StyledTextComp(action, wCustomGroup, SWT.MULTI | SWT.LEFT | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
props.setLook(wSql, Props.WIDGET_STYLE_FIXED);
wSql.addModifyListener(lsMod);
FormData fdSql = new FormData();
fdSql.left = new FormAttachment(0, 0);
fdSql.top = new FormAttachment(wbSqlTable, margin);
fdSql.right = new FormAttachment(100, -10);
fdSql.bottom = new FormAttachment(wlPosition, -margin);
wSql.setLayoutData(fdSql);
wSql.addModifyListener(arg0 -> setPosition());
wSql.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
setPosition();
}
@Override
public void keyReleased(KeyEvent e) {
setPosition();
}
});
wSql.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
setPosition();
}
@Override
public void focusLost(FocusEvent e) {
setPosition();
}
});
wSql.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
setPosition();
}
@Override
public void mouseDown(MouseEvent e) {
setPosition();
}
@Override
public void mouseUp(MouseEvent e) {
setPosition();
}
});
wSql.addModifyListener(lsMod);
FormData fdCustomGroup = new FormData();
fdCustomGroup.left = new FormAttachment(0, margin);
fdCustomGroup.top = new FormAttachment(wSuccessGroup, margin);
fdCustomGroup.right = new FormAttachment(100, -margin);
fdCustomGroup.bottom = new FormAttachment(wOk, -margin);
wCustomGroup.setLayoutData(fdCustomGroup);
// ///////////////////////////////////////////////////////////
// / END OF CustomGroup GROUP
// ///////////////////////////////////////////////////////////
getData();
setCustomSql();
BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());
return action;
}
use of org.apache.hop.ui.core.widget.StyledTextComp in project hop by apache.
the class UserDefinedJavaClassDialog method buildingFolderMenu.
private void buildingFolderMenu() {
MenuItem addNewItem = new MenuItem(cMenu, SWT.PUSH);
addNewItem.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.AddNewTab"));
addNewItem.addListener(SWT.Selection, e -> addCtab("", "", TabAddActions.ADD_BLANK));
MenuItem copyItem = new MenuItem(cMenu, SWT.PUSH);
copyItem.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.AddCopy"));
copyItem.addListener(SWT.Selection, e -> {
CTabItem item = folder.getSelection();
StyledTextComp st = (StyledTextComp) item.getControl();
addCtab(item.getText(), st.getText(), TabAddActions.ADD_COPY);
});
new MenuItem(cMenu, SWT.SEPARATOR);
MenuItem setActiveScriptItem = new MenuItem(cMenu, SWT.PUSH);
setActiveScriptItem.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.SetTransformClass"));
setActiveScriptItem.addListener(SWT.Selection, e -> {
CTabItem item = folder.getSelection();
for (int i = 0; i < folder.getItemCount(); i++) {
if (folder.getItem(i).equals(item)) {
if (item.getImage().equals(imageActiveScript)) {
strActiveScript = "";
}
item.setImage(imageActiveScript);
strActiveScript = item.getText();
} else if (folder.getItem(i).getImage().equals(imageActiveScript)) {
folder.getItem(i).setImage(imageInactiveScript);
}
}
modifyTabTree(item, TabActions.SET_ACTIVE_ITEM);
});
new MenuItem(cMenu, SWT.SEPARATOR);
MenuItem setRemoveScriptItem = new MenuItem(cMenu, SWT.PUSH);
setRemoveScriptItem.setText(BaseMessages.getString(PKG, "UserDefinedJavaClassDialog.RemoveClassType"));
setRemoveScriptItem.addListener(SWT.Selection, e -> {
CTabItem item = folder.getSelection();
input.setChanged(true);
if (item.getImage().equals(imageActiveScript)) {
strActiveScript = "";
}
item.setImage(imageInactiveScript);
});
folder.setMenu(cMenu);
}
use of org.apache.hop.ui.core.widget.StyledTextComp in project hop by apache.
the class UserDefinedJavaClassDialog method treeDblClick.
// Adds the Current item to the current Position
private void treeDblClick(Event event) {
StyledTextComp wScript = getStyledTextComp();
Point point = new Point(event.x, event.y);
TreeItem item = wTree.getItem(point);
// Qualification where the Click comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeClassesItem)) {
setActiveCtab(item.getText());
} else if (!item.getData().equals("Snippit")) {
int iStart = wScript.getTextWidget().getCaretPosition();
// this selection
int selCount = wScript.getSelectionCount();
// will be replaced
// by wScript.insert
// when a selection is already there
iStart = iStart - selCount;
// we need to subtract the position
if (iStart < 0) {
// just safety
iStart = 0;
}
String strInsert = (String) item.getData();
wScript.insert(strInsert);
wScript.setSelection(iStart, iStart + strInsert.length());
}
}
}
use of org.apache.hop.ui.core.widget.StyledTextComp in project hop by apache.
the class ScriptValuesDialog method test.
private boolean test(boolean getvars, boolean popup) {
boolean retval = true;
StyledTextComp wScript = getStyledTextComp();
String scr = wScript.getText();
HopException testException = null;
Context jscx;
Scriptable jsscope;
// Making Refresh to get Active Script State
refreshScripts();
jscx = ContextFactory.getGlobal().enterContext();
jscx.setOptimizationLevel(-1);
jsscope = jscx.initStandardObjects(null, false);
// Adding the existing Scripts to the Context
for (int i = 0; i < folder.getItemCount(); i++) {
StyledTextComp sItem = getStyledTextComp(folder.getItem(i));
Scriptable jsR = Context.toObject(sItem.getText(), jsscope);
jsscope.put(folder.getItem(i).getText(), jsscope, jsR);
}
// Adding the Name of the Pipeline to the Context
jsscope.put("_PipelineName_", jsscope, this.transformName);
try {
IRowMeta rowMeta = pipelineMeta.getPrevTransformFields(variables, transformName);
if (rowMeta != null) {
ScriptValuesDummy dummyTransform = new ScriptValuesDummy(rowMeta, pipelineMeta.getTransformFields(variables, transformName));
Scriptable jsvalue = Context.toObject(dummyTransform, jsscope);
jsscope.put("_transform_", jsscope, jsvalue);
// Modification for Additional Script parsing
try {
if (input.getAddClasses() != null) {
for (int i = 0; i < input.getAddClasses().length; i++) {
Object jsOut = Context.javaToJS(input.getAddClasses()[i].getAddObject(), jsscope);
ScriptableObject.putProperty(jsscope, input.getAddClasses()[i].getJSName(), jsOut);
}
}
} catch (Exception e) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddToContext", e.toString()));
retval = false;
}
// Adding some default JavaScriptFunctions to the System
try {
Context.javaToJS(ScriptValuesAddedFunctions.class, jsscope);
((ScriptableObject) jsscope).defineFunctionProperties(jsFunctionList, ScriptValuesAddedFunctions.class, ScriptableObject.DONTENUM);
} catch (Exception ex) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddDefaultFunctions", ex.toString()));
retval = false;
}
// Adding some Constants to the JavaScript
try {
jsscope.put("SKIP_PIPELINE", jsscope, SKIP_PIPELINE);
jsscope.put("ABORT_PIPELINE", jsscope, ABORT_PIPELINE);
jsscope.put("ERROR_PIPELINE", jsscope, ERROR_PIPELINE);
jsscope.put("CONTINUE_PIPELINE", jsscope, CONTINUE_PIPELINE);
} catch (Exception ex) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddPipelineConstants", ex.toString()));
retval = false;
}
try {
Object[] row = new Object[rowMeta.size()];
Scriptable jsRowMeta = Context.toObject(rowMeta, jsscope);
jsscope.put("rowMeta", jsscope, jsRowMeta);
for (int i = 0; i < rowMeta.size(); i++) {
IValueMeta valueMeta = rowMeta.getValueMeta(i);
Object valueData = null;
//
if (valueMeta.isDate()) {
valueData = new Date();
}
if (valueMeta.isString()) {
valueData = "test value test value test value test value test value " + "test value test value test value test value test value";
}
if (valueMeta.isInteger()) {
valueData = 0L;
}
if (valueMeta.isNumber()) {
valueData = 0.0;
}
if (valueMeta.isBigNumber()) {
valueData = BigDecimal.ZERO;
}
if (valueMeta.isBoolean()) {
valueData = Boolean.TRUE;
}
if (valueMeta.isBinary()) {
valueData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
}
if (valueMeta.isStorageBinaryString()) {
valueMeta.setStorageType(IValueMeta.STORAGE_TYPE_NORMAL);
}
row[i] = valueData;
Scriptable jsarg = Context.toObject(valueData, jsscope);
jsscope.put(valueMeta.getName(), jsscope, jsarg);
}
// OK, for these input values, we're going to allow the user to edit the default values...
// We are displaying a
// 2)
Scriptable jsRow = Context.toObject(row, jsscope);
jsscope.put("row", jsscope, jsRow);
} catch (Exception ev) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldNotAddInputFields", ev.toString()));
retval = false;
}
try {
// Checking for StartScript
if (strActiveStartScript != null && !folder.getSelection().getText().equals(strActiveStartScript) && strActiveStartScript.length() > 0) {
String strStartScript = getStyledTextComp(folder.getItem(getCTabPosition(strActiveStartScript))).getText();
/* Object startScript = */
jscx.evaluateString(jsscope, strStartScript, "pipeline_Start", 1, null);
}
} catch (Exception e) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.CouldProcessStartScript", e.toString()));
retval = false;
}
try {
Script evalScript = jscx.compileString(scr, "script", 1, null);
evalScript.exec(jscx, jsscope);
if (getvars) {
ScriptNode tree = parseVariables(jscx, jsscope, scr, "script", 1, null);
for (int i = 0; i < tree.getParamAndVarCount(); i++) {
String varname = tree.getParamOrVarName(i);
if (!varname.equalsIgnoreCase("row") && !varname.equalsIgnoreCase("pipeline_Status")) {
int type = IValueMeta.TYPE_STRING;
int length = -1;
int precision = -1;
Object result = jsscope.get(varname, jsscope);
if (result != null) {
String classname = result.getClass().getName();
if (classname.equalsIgnoreCase("java.lang.Byte")) {
// MAX = 127
type = IValueMeta.TYPE_INTEGER;
length = 3;
precision = 0;
} else if (classname.equalsIgnoreCase("java.lang.Integer")) {
// MAX = 2147483647
type = IValueMeta.TYPE_INTEGER;
length = 9;
precision = 0;
} else if (classname.equalsIgnoreCase("java.lang.Long")) {
// MAX = 9223372036854775807
type = IValueMeta.TYPE_INTEGER;
length = 18;
precision = 0;
} else if (classname.equalsIgnoreCase("java.lang.Double")) {
type = IValueMeta.TYPE_NUMBER;
length = 16;
precision = 2;
} else if (classname.equalsIgnoreCase("org.mozilla.javascript.NativeDate") || classname.equalsIgnoreCase("java.util.Date")) {
type = IValueMeta.TYPE_DATE;
} else if (classname.equalsIgnoreCase("java.lang.Boolean")) {
type = IValueMeta.TYPE_BOOLEAN;
}
}
TableItem ti = new TableItem(wFields.table, SWT.NONE);
ti.setText(1, varname);
ti.setText(2, "");
ti.setText(3, ValueMetaFactory.getValueMetaName(type));
ti.setText(4, length >= 0 ? ("" + length) : "");
ti.setText(5, precision >= 0 ? ("" + precision) : "");
// If the variable name exists in the input, suggest to replace the value
//
ti.setText(6, (rowMeta.indexOfValue(varname) >= 0) ? YES_NO_COMBO[1] : YES_NO_COMBO[0]);
}
}
wFields.removeEmptyRows();
wFields.setRowNums();
wFields.optWidth(true);
}
// End Script!
} catch (EvaluatorException e) {
String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
String message = BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript", position);
testException = new HopException(message, e);
retval = false;
} catch (JavaScriptException e) {
String position = "(" + e.lineNumber() + ":" + e.columnNumber() + ")";
String message = BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript", position);
testException = new HopException(message, e);
retval = false;
} catch (Exception e) {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotExecuteScript2"), e);
retval = false;
}
} else {
testException = new HopException(BaseMessages.getString(PKG, "ScriptValuesDialogMod.Exception.CouldNotGetFields"));
retval = false;
}
if (popup) {
if (retval) {
if (!getvars) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
mb.setMessage(BaseMessages.getString(PKG, "ScriptValuesDialogMod.ScriptCompilationOK") + Const.CR);
mb.setText("OK");
mb.open();
}
} else {
new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogMessage"), testException);
}
}
} catch (HopException ke) {
retval = false;
new ErrorDialog(shell, BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogTitle"), BaseMessages.getString(PKG, "ScriptValuesDialogMod.TestFailed.DialogMessage"), ke);
} finally {
if (jscx != null) {
Context.exit();
}
}
return retval;
}
use of org.apache.hop.ui.core.widget.StyledTextComp in project hop by apache.
the class ScriptValuesDialog method treeDblClick.
// Adds the Current item to the current Position
private void treeDblClick(Event event) {
StyledTextComp wScript = getStyledTextComp();
Point point = new Point(event.x, event.y);
TreeItem item = wTree.getItem(point);
// Qualification where the Click comes from
if (item != null && item.getParentItem() != null) {
if (item.getParentItem().equals(wTreeScriptsItem)) {
setActiveCtab(item.getText());
} else if (!item.getData().equals("Function")) {
int iStart = wScript.getTextWidget().getCaretPosition();
int selCount = // this selection will be replaced by wScript.insert
wScript.getSelectionCount();
iStart = // when a selection is already there we need to subtract the position
iStart - selCount;
if (iStart < 0) {
// just safety
iStart = 0;
}
String strInsert = (String) item.getData();
if (strInsert.equals("jsFunction")) {
strInsert = item.getText();
}
wScript.insert(strInsert);
wScript.setSelection(iStart, iStart + strInsert.length());
}
}
}
Aggregations