use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class CategoryComposite method getProposals.
/**
* yzhang Comment method "getProposals".
*
* @return
*/
public IContentProposal[] getProposals(String categoryFunction, int position) {
String category = null;
String function = null;
boolean displayFunction = false;
if (categoryFunction.indexOf(".") != -1) {
//$NON-NLS-1$
//$NON-NLS-1$
String[] cf = categoryFunction.split("\\.");
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < cf.length - 1; i++) {
buffer.append(cf[i]);
if (i != cf.length - 2) {
//$NON-NLS-1$
buffer.append(".");
}
}
if (cf.length == 1) {
category = cf[cf.length - 1];
} else {
function = cf[cf.length - 1];
category = buffer.toString();
}
displayFunction = true;
} else {
category = categoryFunction;
}
java.util.List<IContentProposal> proposals = new LinkedList<IContentProposal>();
java.util.List<Category> categories = manager.getInputCategory("java");
//$NON-NLS-1$
boolean addAllCategory = category.equals("*C") ? true : false;
if (!displayFunction) {
for (Category cg : categories) {
if (!cg.getName().startsWith("*") && (addAllCategory || cg.getName().startsWith(category))) {
//$NON-NLS-1$
//$NON-NLS-1$
proposals.add(new ExpressionContentProposal(cg.getName(), "", position));
}
}
java.util.List<Variable> vars = ExpressionBuilderDialog.getTestComposite().getVariableList();
for (Variable var : vars) {
if (addAllCategory || var.getName().startsWith(category)) {
proposals.add(new ExpressionContentProposal(var.getName(), var.getValue(), position));
}
}
} else {
for (Category cg : categories) {
if (cg.getName().equals(category)) {
java.util.List<Function> funs = cg.getFunctions();
boolean addAll = (function == null ? true : false);
for (Function fun : funs) {
if (addAll || fun.getName().startsWith(function)) {
proposals.add(new //$NON-NLS-1$
ExpressionContentProposal(//$NON-NLS-1$
fun.getName() + "()", //$NON-NLS-1$
fun.getDescription(), position));
}
}
}
}
}
Collections.sort(proposals, new CategoryFunctionCompartor());
String replaceString;
if (displayFunction) {
//$NON-NLS-1$
replaceString = function == null ? "" : function;
} else {
replaceString = category;
}
ExpressionBuilderDialog.getExpressionComposite().setReplacedText(replaceString);
return proposals.toArray(new IContentProposal[proposals.size()]);
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionBuilderDialog method createButtonsForButtonBar.
/**
* Create contents of the button bar
*
* @param parent
*/
@Override
protected void createButtonsForButtonBar(Composite parent) {
((GridLayout) parent.getLayout()).numColumns++;
Composite buttons = new Composite(parent, SWT.NONE);
buttons.setLayout(new GridLayout(2, false));
final Button importButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
importButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.import"));
importButton.setImage(ImageProvider.getImage(EImage.IMPORT_ICON));
final Button exportButton = new Button(buttons, SWT.PUSH);
//$NON-NLS-1$
exportButton.setToolTipText(Messages.getString("ExpressionBuilderDialog.export"));
exportButton.setImage(ImageProvider.getImage(EImage.EXPORT_ICON));
//$NON-NLS-1$
createButton(parent, IDialogConstants.OK_ID, Messages.getString("ExpressionBuilderDialog.ok.button"), true);
//$NON-NLS-1$
createButton(parent, IDialogConstants.CANCEL_ID, Messages.getString("ExpressionBuilderDialog.cancel.button"), false);
exportButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
String expresionContent = expressionComposite.getExpression();
List<Variable> variables = new ArrayList<Variable>();
variables = testComposite.getVariableList();
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
if (file != null) {
file.createNewFile();
}
operation.saveExpressionToFile(file, variables, expresionContent);
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
importButton.addMouseListener(new MouseAdapter() {
/*
* (non-Javadoc)
*
* @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
*/
@Override
public void mouseUp(MouseEvent e) {
FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
//$NON-NLS-1$
dialog.setFilterExtensions(new String[] { "*.xml" });
String filePath = dialog.open();
if (filePath != null) {
File file = new File(filePath);
ExpressionFileOperation operation = new ExpressionFileOperation();
try {
List list = operation.importExpressionFromFile(file, getShell());
if (list != null && list.size() != 0) {
expressionComposite.setExpression((String) list.get(0), false);
list.remove(0);
if (list.size() > 0) {
testComposite.addVariables(list);
}
}
} catch (IOException e1) {
RuntimeExceptionHandler.process(e1);
} catch (ParserConfigurationException e1) {
RuntimeExceptionHandler.process(e1);
} catch (SAXException e1) {
RuntimeExceptionHandler.process(e1);
}
}
}
});
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionFileOperation method importExpressionFromFile.
/**
* yzhang Comment method "getExpressionFromFile".
*
* @param file
* @return
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException
*/
public List importExpressionFromFile(File file, Shell shell) throws IOException, ParserConfigurationException, SAXException {
if (file != null) {
List list = new ArrayList();
if (!file.isFile()) {
openDialog(shell);
return list;
} else {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final Bundle b = Platform.getBundle(PLUGIN_ID);
final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
final File schema = new File(url.getPath());
final Document document = XSDValidator.checkXSD(file, schema);
final NodeList expressionNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.expression"));
if (expressionNodes.getLength() == 1) {
Node expressionNode = expressionNodes.item(0);
NamedNodeMap epxressionAttrs = expressionNode.getAttributes();
Node contentNode = epxressionAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.content"));
list.add(contentNode.getNodeValue());
}
final NodeList variableNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.variable"));
for (int i = 0; i < variableNodes.getLength(); i++) {
Node variableNode = variableNodes.item(i);
NamedNodeMap varAttrs = variableNode.getAttributes();
//$NON-NLS-1$
Node nameNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.name"));
//$NON-NLS-1$
Node valueNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.value"));
Node talendTypeNode = varAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
"ExpressionFileOperation.talendType"));
//$NON-NLS-1$
Node nullableNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.nullable"));
Variable variable = new Variable();
variable.setName(nameNode.getNodeValue());
variable.setValue(valueNode.getNodeValue());
variable.setTalendType(talendTypeNode.getNodeValue());
String s = nullableNode.getNodeValue();
Boolean boo = Boolean.valueOf(s);
if (boo == null) {
boo = false;
}
variable.setNullable(boo);
list.add(variable);
}
return list;
}
}
return null;
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionFileOperation method saveExpressionToFile.
/**
* yzhang Comment method "savingExpression".
*
* @return
* @throws IOException
* @throws ParserConfigurationException
*/
public boolean saveExpressionToFile(File file, List<Variable> variables, String expressionContent) throws IOException, ParserConfigurationException {
final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
final Bundle b = Platform.getBundle(PLUGIN_ID);
final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
final File schema = new File(url.getPath());
//$NON-NLS-1$
fabrique.setAttribute(SCHEMA_LANGUAGE, "http://www.w3.org/2001/XMLSchema");
fabrique.setAttribute(SCHEMA_VALIDATOR, schema);
fabrique.setValidating(true);
final DocumentBuilder analyseur = fabrique.newDocumentBuilder();
analyseur.setErrorHandler(new ErrorHandler() {
public void error(final SAXParseException exception) throws SAXException {
throw exception;
}
public void fatalError(final SAXParseException exception) throws SAXException {
throw exception;
}
public void warning(final SAXParseException exception) throws SAXException {
throw exception;
}
});
Document document = analyseur.newDocument();
//$NON-NLS-1$
Element expressionElement = document.createElement("expression");
document.appendChild(expressionElement);
//$NON-NLS-1$
Attr content = document.createAttribute(Messages.getString("ExpressionFileOperation.content"));
content.setNodeValue(expressionContent);
expressionElement.setAttributeNode(content);
for (Variable variable : variables) {
//$NON-NLS-1$
Element variableElement = document.createElement("variable");
expressionElement.appendChild(variableElement);
//$NON-NLS-1$
Attr name = document.createAttribute(Messages.getString("ExpressionFileOperation.name"));
name.setNodeValue(variable.getName());
variableElement.setAttributeNode(name);
//$NON-NLS-1$
Attr value = document.createAttribute(Messages.getString("ExpressionFileOperation.value"));
value.setNodeValue(variable.getValue());
variableElement.setAttributeNode(value);
//$NON-NLS-1$
Attr talendType = document.createAttribute(Messages.getString("ExpressionFileOperation.talendType"));
//$NON-NLS-1$
talendType.setNodeValue(variable.getTalendType());
variableElement.setAttributeNode(talendType);
//$NON-NLS-1$
Attr nullable = document.createAttribute(Messages.getString("ExpressionFileOperation.nullable"));
//$NON-NLS-1$
nullable.setNodeValue(String.valueOf(variable.isNullable()));
variableElement.setAttributeNode(nullable);
}
// use specific Xerces class to write DOM-data to a file:
XMLSerializer serializer = new XMLSerializer();
OutputFormat outputFormat = new OutputFormat();
outputFormat.setIndenting(true);
serializer.setOutputFormat(outputFormat);
FileWriter writer = new FileWriter(file);
serializer.setOutputCharStream(writer);
serializer.serialize(document);
writer.close();
return true;
}
use of org.talend.commons.runtime.model.expressionbuilder.Variable in project tdi-studio-se by Talend.
the class ExpressionGenerator method generate.
public String generate(Object argument) {
final StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(TEXT_1);
ExpressionArguments args = (ExpressionArguments) argument;
String expression = args.getExpression();
List<Variable> variables = args.getVariables();
stringBuffer.append(TEXT_2);
for (Variable var : variables) {
stringBuffer.append(TEXT_3);
stringBuffer.append(var.getName());
stringBuffer.append(TEXT_4);
stringBuffer.append(var.getValue());
stringBuffer.append(TEXT_5);
}
stringBuffer.append(TEXT_6);
stringBuffer.append(expression);
stringBuffer.append(TEXT_7);
stringBuffer.append(TEXT_8);
return stringBuffer.toString();
}
Aggregations