use of org.talend.expressionbuilder.model.Category 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()]);
}
Aggregations