use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionComposite method getReplaceExpression.
/**
* yzhang Comment method "getExpression".
*
* @return
*/
public String getReplaceExpression() {
if (document != null) {
IRegion region = viewer.getViewerRegion();
try {
String doc = document.get(region.getOffset(), region.getLength());
List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
for (Variable variable : variables) {
doc = doc.replaceAll(variable.getName(), variable.getValue());
}
return doc;
// return document.get(region.getOffset(), region.getLength());
} catch (BadLocationException e) {
MessageBoxExceptionHandler.process(e);
}
}
return null;
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class VirtualRowGeneratorNode method getArray.
/**
* yzhang Comment method "initArray".
*/
private Object getArray() {
List<Map<String, String>> map = new ArrayList<Map<String, String>>();
MetadataTable table = (MetadataTable) this.getMetadataList().get(0);
for (IMetadataColumn col : table.getListColumns()) {
VirtualMetadataColumn ext = (VirtualMetadataColumn) col;
Map<String, String> value = new HashMap<String, String>();
value.put(RowGeneratorComponent.COLUMN_NAME, ext.getLabel());
List<Variable> variables = ExpressionBuilderDialog.getTestComposite().getVariableList();
String expression = ExpressionBuilderDialog.getExpressionComposite().getExpression();
// modify for bug 9471
try {
for (Variable varible : variables) {
if (valueContains(expression, varible.getName())) {
Integer.parseInt(varible.getValue());
}
}
for (Variable var : variables) {
String talendType = var.getTalendType();
JavaType javaTypeFromId = JavaTypesManager.getJavaTypeFromId(talendType);
String label = null;
String value2 = var.getValue();
if (javaTypeFromId != null) {
label = javaTypeFromId.getLabel();
if ("BigDecimal".equals(label)) {
//$NON-NLS-1$
//$NON-NLS-1$//$NON-NLS-1$
value2 = " new BigDecimal(" + value2 + ")";
}
}
expression = renameValues(expression, var.getName(), value2);
}
} catch (NumberFormatException e1) {
for (Variable var : variables) {
//$NON-NLS-1$ //$NON-NLS-2$
expression = renameValues(expression, var.getName(), "\"" + var.getValue() + "\"");
}
}
//$NON-NLS-1$//$NON-NLS-1$
value.put(RowGeneratorComponent.ARRAY, "\"\"+(" + expression + ")+\"\"");
map.add(value);
}
return map;
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionBuilderDialog method openDialog.
/*
* (non-Javadoc)
*
* @see org.talend.expressionbuilder.ui.IExpressionBuilderDialogController#openDialog()
*/
@Override
public void openDialog(Object obj) {
if (obj instanceof IExpressionDataBean) {
List<Variable> vars = new ArrayList<Variable>();
IExpressionDataBean bean = (IExpressionDataBean) obj;
setDefaultExpression(bean.getExpression());
ExpressionPersistance persistance = ExpressionPersistance.getInstance();
persistance.setOwnerId(bean.getOwnerId());
persistance.setPath(getExpressionStorePath());
List<Variable> varList = new ArrayList<Variable>(persistance.loadExpression().getVariables());
vars.addAll(varList);
if (bean.getVariables() != null) {
for (Variable var1 : bean.getVariables()) {
boolean needAdd = true;
for (Variable var2 : varList) {
if (var1.getName() != null && var1.getName().equals(var2.getName())) {
needAdd = false;
break;
}
}
if (var1.getName() != null && needAdd) {
vars.add(var1);
}
}
}
addVariables(vars);
}
open();
setBlockOnOpen(true);
}
Aggregations