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;
}
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;
}
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();
}
}
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++;
}
}
}
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;
}
Aggregations