Search in sources :

Example 1 with Proposal

use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.

the class ParameterContentProvider method listResult.

@Override
public AutoCompleteResult listResult(ContentDescriptor desc, int limit) {
    String content = desc.getValue();
    if (content.startsWith(ParameterContentParser.PARA_SOURCE)) {
        content = content.substring(ParameterContentParser.PARA_SOURCE.length());
    }
    content = AutoCompleteHelper.trimWildcards(content);
    Pattern namePattern = AutoCompleteHelper.convertToPattern(content);
    namePattern = Pattern.compile(namePattern.pattern(), Pattern.CASE_INSENSITIVE);
    AutoCompleteResult pvs = new AutoCompleteResult();
    int matchCount = 0;
    for (ParameterInfo para : ParameterCatalogue.getInstance().getMetaParameters()) {
        Matcher m = namePattern.matcher(para.getQualifiedName());
        if (m.find()) {
            Proposal p = new Proposal(para.getQualifiedName(), false);
            p.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
            pvs.addProposal(p);
            matchCount++;
            if (matchCount >= limit)
                break;
        }
    }
    pvs.setCount(matchCount);
    return pvs;
}
Also used : Pattern(java.util.regex.Pattern) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) ParameterInfo(org.yamcs.protobuf.Mdb.ParameterInfo) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 2 with Proposal

use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.

the class ContentProposalPopup method open.

/**
 * Opens this ContentProposalPopup. This method is extended in order to add the control listener when the popup is
 * opened and to invoke the secondary popup if applicable.
 *
 * @return the return code
 *
 * @see org.eclipse.jface.window.Window#open()
 */
@Override
public int open() {
    int value = super.open();
    if (popupCloser == null) {
        popupCloser = new PopupCloserListener();
    }
    popupCloser.installListeners();
    Proposal p = getSelectedProposal();
    if (p != null) {
        showProposalDescription();
    }
    return value;
}
Also used : Point(org.eclipse.swt.graphics.Point) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 3 with Proposal

use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.

the class ContentProposalPopup method acceptCurrentProposal.

/*
     * Accept the current proposal.
     */
private void acceptCurrentProposal(boolean addToHistory) {
    // Close before accepting the proposal. This is important
    // so that the cursor position can be properly restored at
    // acceptance, which does not work without focus on some controls.
    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=127108
    Proposal proposal = getSelectedProposal();
    if (proposal != null) {
        adapter.proposalAccepted(proposal, addToHistory);
        close();
    }
}
Also used : Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 4 with Proposal

use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.

the class ContentProposalPopup method handleSetData.

/*
     * Handle the set data event. Set the item data of the requested item to the corresponding proposal in the proposal
     * cache.
     */
private void handleSetData(Event event) {
    TableItem item = (TableItem) event.item;
    int index = proposalTable.indexOf(item);
    Display display = Display.getCurrent();
    int proposalIndex = 0;
    for (Proposal proposal : proposalList.getTopProposalList()) {
        if (index == proposalIndex) {
            item.setData(proposal);
            return;
        }
        proposalIndex++;
    }
    for (String provider : proposalList.getProviderList()) {
        if (index == proposalIndex) {
            // Data == null => not selectable
            item.setData(null);
            item.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
            return;
        }
        proposalIndex++;
        for (Proposal proposal : proposalList.getProposals(provider)) {
            if (index == proposalIndex) {
                item.setData(proposal);
                return;
            }
            proposalIndex++;
        }
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Point(org.eclipse.swt.graphics.Point) Proposal(org.csstudio.autocomplete.proposals.Proposal) Display(org.eclipse.swt.widgets.Display)

Example 5 with Proposal

use of org.csstudio.autocomplete.proposals.Proposal in project yamcs-studio by yamcs.

the class AutoCompleteHistoryProvider method listResult.

@Override
public AutoCompleteResult listResult(final ContentDescriptor desc, final int limit) {
    String content = desc.getOriginalContent();
    int startIndex = 0;
    if (desc.getContentType().equals(ContentType.PVName)) {
        content = desc.getValue();
        startIndex = desc.getStartIndex();
    }
    AutoCompleteResult result = new AutoCompleteResult();
    String cleanedName = AutoCompleteHelper.trimWildcards(content);
    Pattern namePattern = AutoCompleteHelper.convertToPattern(cleanedName);
    if (namePattern == null)
        return result;
    String entryType = AutoCompleteTypes.PV;
    if (content.startsWith("="))
        entryType = AutoCompleteTypes.Formula;
    LinkedList<String> fifo = new LinkedList<String>();
    fifo.addAll(AutoCompleteUIPlugin.getDefault().getHistory(entryType));
    if (fifo.isEmpty())
        // Empty result
        return result;
    int count = 0;
    for (String entry : fifo) {
        Matcher m = namePattern.matcher(entry);
        if (m.find()) {
            if (count < limit) {
                Proposal proposal = new Proposal(entry, false);
                proposal.addStyle(ProposalStyle.getDefault(m.start(), m.end() - 1));
                proposal.setInsertionPos(startIndex);
                result.addProposal(proposal);
            }
            count++;
        }
    }
    result.setCount(count);
    TopProposalFinder trf = new TopProposalFinder(Preferences.getSeparators());
    for (Proposal p : trf.getTopProposals(Pattern.quote(cleanedName), fifo)) result.addTopProposal(p);
    return result;
}
Also used : Pattern(java.util.regex.Pattern) TopProposalFinder(org.csstudio.autocomplete.proposals.TopProposalFinder) AutoCompleteResult(org.csstudio.autocomplete.AutoCompleteResult) Matcher(java.util.regex.Matcher) LinkedList(java.util.LinkedList) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Aggregations

Proposal (org.csstudio.autocomplete.proposals.Proposal)19 AutoCompleteResult (org.csstudio.autocomplete.AutoCompleteResult)9 Matcher (java.util.regex.Matcher)5 Pattern (java.util.regex.Pattern)5 Point (org.eclipse.swt.graphics.Point)5 ArrayList (java.util.ArrayList)3 ProposalStyle (org.csstudio.autocomplete.proposals.ProposalStyle)3 Display (org.eclipse.swt.widgets.Display)3 TableItem (org.eclipse.swt.widgets.TableItem)3 FunctionDescriptor (org.csstudio.autocomplete.parser.FunctionDescriptor)2 TopProposalFinder (org.csstudio.autocomplete.proposals.TopProposalFinder)2 ControlEvent (org.eclipse.swt.events.ControlEvent)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 FocusEvent (org.eclipse.swt.events.FocusEvent)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 SelectionListener (org.eclipse.swt.events.SelectionListener)2 Color (org.eclipse.swt.graphics.Color)2 Font (org.eclipse.swt.graphics.Font)2 FontData (org.eclipse.swt.graphics.FontData)2