Search in sources :

Example 1 with FormulaFunctionSet

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);
}
Also used : FormulaFunctionSet(org.diirt.datasource.formula.FormulaFunctionSet) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) FormulaFunction(org.diirt.datasource.formula.FormulaFunction) Composite(org.eclipse.swt.widgets.Composite) TreeColumnLayout(org.eclipse.jface.layout.TreeColumnLayout) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree)

Example 2 with FormulaFunctionSet

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;
}
Also used : FormulaFunctionSet(org.diirt.datasource.formula.FormulaFunctionSet) FormulaFunction(org.diirt.datasource.formula.FormulaFunction) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) FunctionDescriptor(org.csstudio.autocomplete.parser.FunctionDescriptor) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Aggregations

FormulaFunction (org.diirt.datasource.formula.FormulaFunction)2 FormulaFunctionSet (org.diirt.datasource.formula.FormulaFunctionSet)2 ArrayList (java.util.ArrayList)1 AutoCompleteResult (org.csstudio.autocomplete.AutoCompleteResult)1 FunctionDescriptor (org.csstudio.autocomplete.parser.FunctionDescriptor)1 Proposal (org.csstudio.autocomplete.proposals.Proposal)1 TreeColumnLayout (org.eclipse.jface.layout.TreeColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 TreeViewerColumn (org.eclipse.jface.viewers.TreeViewerColumn)1 Image (org.eclipse.swt.graphics.Image)1 Composite (org.eclipse.swt.widgets.Composite)1 Tree (org.eclipse.swt.widgets.Tree)1 TreeColumn (org.eclipse.swt.widgets.TreeColumn)1