use of org.diirt.datasource.formula.FormulaFunctionSet in project yamcs-studio by yamcs.
the class FunctionsView method createPartControl.
@Override
public void createPartControl(Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
TreeColumnLayout tcl_composite = new TreeColumnLayout();
composite.setLayout(tcl_composite);
treeViewer = new TreeViewer(composite, SWT.BORDER);
Tree tree = treeViewer.getTree();
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
TreeViewerColumn treeViewerColumn = new TreeViewerColumn(treeViewer, SWT.NONE);
treeViewerColumn.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
if (element instanceof FormulaFunctionSet) {
return ((FormulaFunctionSet) element).getName();
} else if (element instanceof FormulaFunction) {
return FormulaFunctions.formatSignature((FormulaFunction) element);
}
return "";
}
});
TreeColumn trclmnNewColumn = treeViewerColumn.getColumn();
tcl_composite.setColumnData(trclmnNewColumn, new ColumnWeightData(10, ColumnWeightData.MINIMUM_WIDTH, true));
trclmnNewColumn.setText("Name");
TreeViewerColumn treeViewerColumn_1 = new TreeViewerColumn(treeViewer, SWT.NONE);
treeViewerColumn_1.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
return null;
}
@Override
public String getText(Object element) {
if (element instanceof FormulaFunction) {
return ((FormulaFunction) element).getDescription();
} else if (element instanceof FormulaFunctionSet) {
return ((FormulaFunctionSet) element).getDescription();
}
return "";
}
});
TreeColumn trclmnNewColumn_1 = treeViewerColumn_1.getColumn();
tcl_composite.setColumnData(trclmnNewColumn_1, new ColumnWeightData(7, ColumnWeightData.MINIMUM_WIDTH, true));
trclmnNewColumn_1.setText("Description");
treeViewer.setContentProvider(new FunctionTreeContentProvider());
List<String> functionSetNames = new ArrayList<>(FormulaRegistry.getDefault().listFunctionSets());
Collections.sort(functionSetNames);
List<FormulaFunctionSet> functionSets = new ArrayList<>();
for (String functionSetName : functionSetNames) {
functionSets.add(FormulaRegistry.getDefault().findFunctionSet(functionSetName));
}
treeViewer.setInput(functionSets);
}
use of org.diirt.datasource.formula.FormulaFunctionSet in project yamcs-studio by yamcs.
the class FormulaFunctionProvider method listResult.
@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
AutoCompleteResult result = new AutoCompleteResult();
FunctionDescriptor functionDesc = null;
if (desc instanceof FunctionDescriptor) {
functionDesc = (FunctionDescriptor) desc;
} else {
// empty result
return result;
}
String nameToFind = functionDesc.getFunctionName();
// handle proposals
int count = 0;
// insertionPos is not yet provided for formula
// TODO: improve parser
String originalContent = desc.getOriginalContent();
int insertionPos = originalContent.lastIndexOf(nameToFind);
if (!functionDesc.hasOpenBracket()) {
Proposal topProposal = null;
String closestMatchingFunction = null;
for (String functionName : functions.keySet()) {
if (functionName.startsWith(nameToFind)) {
Proposal proposal = new Proposal(functionName + "(", false);
String description = functions.get(functionName).get(0).getDescription() + "\n\n";
for (FormulaFunction ff : functions.get(functionName)) description += generateSignature(ff);
proposal.setDescription(description);
for (FormulaFunction ff : functions.get(functionName)) proposal.addTooltipData(generateTooltipData(ff, 0));
proposal.addStyle(ProposalStyle.getDefault(0, nameToFind.length() - 1));
proposal.setInsertionPos(insertionPos);
// display function icon
proposal.setFunction(true);
result.addProposal(proposal);
count++;
if (closestMatchingFunction == null || closestMatchingFunction.compareTo(functionName) > 0) {
closestMatchingFunction = functionName;
topProposal = proposal;
}
}
}
// handle top proposals
if (closestMatchingFunction != null)
result.addTopProposal(topProposal);
}
result.setCount(count);
// handle tooltip
if (functionDesc.hasOpenBracket() && !functionDesc.isComplete()) {
for (String setName : FormulaRegistry.getDefault().listFunctionSets()) {
FormulaFunctionSet set = FormulaRegistry.getDefault().findFunctionSet(setName);
for (FormulaFunction function : set.findFunctions(nameToFind)) {
if (function.getName().equals(nameToFind))
if (function.getArgumentNames().size() >= functionDesc.getArgs().size() || function.isVarArgs())
result.addTooltipData(generateTooltipData(function, functionDesc.getCurrentArgIndex()));
}
}
}
return result;
}
Aggregations