Search in sources :

Example 11 with Proposal

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

the class ContentProposalList method addProposals.

public void addProposals(String provider, Proposal[] proposals, Integer count, Integer index) {
    for (Proposal p : proposals) {
        p.setOriginalValue(originalValue);
        if (p.getValue().equals(originalValue))
            hasContentMatchingProposal = true;
    }
    proposalMap.put(provider, proposals);
    countMap.put(provider, count);
    length += proposals.length;
    providerMap.put(index, provider);
}
Also used : Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 12 with Proposal

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

the class ContentProposalPopup method getSelectedProposal.

/*
     * Return the current selected proposal.
     */
private Proposal getSelectedProposal() {
    if (isValid()) {
        int index = proposalTable.getSelectionIndex();
        if (proposalList == null || index < 0 || index >= getTableLength()) {
            return null;
        }
        int proposalIndex = 0;
        for (Proposal proposal : proposalList.getTopProposalList()) {
            if (index == proposalIndex) {
                return proposal;
            }
            proposalIndex++;
        }
        for (String provider : proposalList.getProviderList()) {
            if (index == proposalIndex) {
                return null;
            }
            proposalIndex++;
            for (Proposal proposal : proposalList.getProposals(provider)) {
                if (index == proposalIndex) {
                    return proposal;
                }
                proposalIndex++;
            }
        }
    }
    return null;
}
Also used : Point(org.eclipse.swt.graphics.Point) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 13 with Proposal

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

the class ContentProposalPopup method adjustBounds.

/*
     * (non-Javadoc)
     *
     * @see org.eclipse.jface.dialogs.PopupDialog.adjustBounds()
     */
@Override
protected void adjustBounds() {
    adjustTableBounds();
    // Now set up a listener to monitor any changes in size.
    getShell().addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event e) {
            popupSize = getShell().getSize();
            if (infoPopup != null) {
                infoPopup.close();
                Proposal p = getSelectedProposal();
                if (p != null) {
                    showProposalDescription();
                }
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Proposal(org.csstudio.autocomplete.proposals.Proposal)

Example 14 with Proposal

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

the class ContentProposalPopup method initializeTextLayouts.

private void initializeTextLayouts() {
    Display display = Display.getCurrent();
    FontData defaultFontData = display.getSystemFont().getFontData()[0];
    String fontName = defaultFontData.getName();
    int fontHeight = defaultFontData.getHeight();
    Font headerFont = new Font(display, new FontData(fontName, fontHeight, SWT.ITALIC | SWT.BOLD));
    Font noFont = new Font(display, new FontData(fontName, fontHeight, SWT.NORMAL));
    Color black = display.getSystemColor(SWT.COLOR_BLACK);
    int index = 0;
    textLayouts = new SSTextLayout[getTableLength()];
    for (Proposal proposal : proposalList.getTopProposalList()) {
        textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
        String text = getString(proposal);
        textLayouts[index].init(display, text);
        textLayouts[index].addStyle(noFont, black, 0, text.length());
        if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
            for (ProposalStyle style : proposal.getStyles()) {
                FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
                Font font = new Font(display, newFontData);
                Color color = display.getSystemColor(style.fontColor);
                textLayouts[index].addStyle(font, color, style.from, style.to);
            }
        }
        index++;
    }
    for (String provider : proposalList.getProviderList()) {
        textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
        int count = proposalList.getCount(provider);
        String headerText = provider + " (" + count + " matching items)";
        textLayouts[index].init(display, headerText);
        textLayouts[index].addStyle(headerFont, black, 0, headerText.length());
        index++;
        for (Proposal proposal : proposalList.getProposals(provider)) {
            textLayouts[index] = AutoCompleteUIPlugin.getUIHelper().newTextLayout();
            String text = getString(proposal);
            textLayouts[index].init(display, text);
            textLayouts[index].addStyle(noFont, black, 0, text.length());
            if (proposal.getStyles() != null && !proposal.getStyles().isEmpty()) {
                for (ProposalStyle style : proposal.getStyles()) {
                    FontData newFontData = new FontData(fontName, fontHeight, style.fontStyle);
                    Font font = new Font(display, newFontData);
                    Color color = display.getSystemColor(style.fontColor);
                    textLayouts[index].addStyle(font, color, style.from, style.to);
                }
            }
            index++;
        }
    }
    for (SSTextLayout sstl : textLayouts) if (sstl != null && sstl.getBounds() != null && sstl.getBounds().width > maxItemWidth)
        maxItemWidth = sstl.getBounds().width;
    adjustTableBounds();
}
Also used : SSTextLayout(org.csstudio.autocomplete.ui.util.SSTextLayout) ProposalStyle(org.csstudio.autocomplete.proposals.ProposalStyle) FontData(org.eclipse.swt.graphics.FontData) Color(org.eclipse.swt.graphics.Color) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Proposal(org.csstudio.autocomplete.proposals.Proposal) Display(org.eclipse.swt.widgets.Display)

Example 15 with Proposal

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

the class ContentProposalPopup method setProposals.

/*
     * Caches the specified proposals and repopulates the table if it has been created.
     */
private void setProposals(ContentProposalList newProposalList) {
    if (newProposalList == null) {
        newProposalList = getEmptyProposalArray();
    }
    this.proposalList = newProposalList;
    if (!isValid())
        return;
    // Reset item width
    maxItemWidth = 0;
    nonSelectableItems.clear();
    int proposalIndex = proposalList.getTopProposalList().size();
    for (String provider : proposalList.getProviderList()) {
        nonSelectableItems.add(proposalIndex);
        proposalIndex += proposalList.getProposals(provider).length + 1;
    }
    // If there is a table
    if (isValid()) {
        if (USE_VIRTUAL) {
            // Set and clear the virtual table. Data will be
            // provided in the SWT.SetData event handler.
            proposalTable.setItemCount(getTableLength());
            proposalTable.clearAll();
            initializeTextLayouts();
        } else {
            // Populate the table manually
            proposalTable.setRedraw(false);
            proposalTable.setItemCount(getTableLength());
            TableItem[] items = proposalTable.getItems();
            int index = 0;
            for (Proposal proposal : newProposalList.getTopProposalList()) {
                TableItem item = items[index];
                item.setText("  " + getString(proposal));
                item.setImage(getImage(proposal, false));
                item.setData(proposal);
                index++;
            }
            for (String provider : newProposalList.getProviderList()) {
                TableItem item = items[index];
                int count = newProposalList.getCount(provider);
                String text = provider + " (" + count + " matching items)";
                item.setText(text);
                // Data == null => not selectable
                item.setData(null);
                Display display = Display.getCurrent();
                Color color = display.getSystemColor(SWT.COLOR_GRAY);
                FontData fontData = item.getFont().getFontData()[0];
                Font font = new Font(display, new FontData(fontData.getName(), fontData.getHeight(), SWT.ITALIC | SWT.BOLD));
                item.setBackground(color);
                item.setFont(font);
                index++;
                for (Proposal proposal : newProposalList.getProposals(provider)) {
                    item.setText("  " + getString(proposal));
                    item.setImage(getImage(proposal, false));
                    item.setData(proposal);
                    index++;
                }
            }
            proposalTable.setRedraw(true);
        }
        if (infoPopup != null) {
            infoPopup.close();
        }
    }
    footer.setText("");
    if (handleTopProposals) {
        adapter.handleTopProposals(newProposalList);
        // we stop handle
        if (adapter.hasSelectedTopProposal() || newProposalList.allResponded()) {
            handleTopProposals = false;
        }
    }
    // Select the top proposal that was displayed, if any
    proposalTable.deselectAll();
    if (adapter.hasSelectedTopProposal()) {
        int index = proposalList.getTopProposalList().indexOf(adapter.getSelectedTopProposal());
        if (index >= 0)
            selectProposal(index);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) Point(org.eclipse.swt.graphics.Point) Proposal(org.csstudio.autocomplete.proposals.Proposal) Font(org.eclipse.swt.graphics.Font) Display(org.eclipse.swt.widgets.Display)

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