use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method unregister.
private void unregister() {
if (fDocumentListener != null) {
IDocument document = fViewer.getDocument();
if (document != null)
document.removeDocumentListener(fDocumentListener);
fDocumentListener = null;
}
fDocumentEvents.clear();
StyledText styledText = fViewer.getTextWidget();
if (fKeyListener != null && styledText != null && !styledText.isDisposed())
styledText.removeKeyListener(fKeyListener);
if (fLastProposal != null) {
if (fLastProposal instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 extension = (ICompletionProposalExtension2) fLastProposal;
extension.unselected(fViewer);
}
fLastProposal = null;
}
fFilteredProposals = null;
fContentAssistant.possibleCompletionsClosed();
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method computeFilteredProposals.
/**
* Computes the subset of already computed propsals that are still valid for
* the given offset.
*
* @param offset the offset
* @param event the merged document event
* @return the set of filtered proposals
* @since 2.0
*/
private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event) {
if (offset == fInvocationOffset && event == null)
return fComputedProposals;
if (offset < fInvocationOffset) {
return null;
}
ICompletionProposal[] proposals = fComputedProposals;
if (offset > fFilterOffset)
proposals = fFilteredProposals;
if (proposals == null)
return null;
IDocument document = fViewer.getDocument();
int length = proposals.length;
List<Object> filtered = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
if (proposals[i] instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 p = (ICompletionProposalExtension2) proposals[i];
if (p.validate(document, offset, event))
filtered.add(p);
} else if (proposals[i] instanceof ICompletionProposalExtension) {
ICompletionProposalExtension p = (ICompletionProposalExtension) proposals[i];
if (p.isValidFor(document, offset))
filtered.add(p);
} else {
// restore original behavior
fInvocationOffset = offset;
fComputedProposals = computeProposals(fInvocationOffset);
return fComputedProposals;
}
}
ICompletionProposal[] p = new ICompletionProposal[filtered.size()];
filtered.toArray(p);
return p;
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method setProposals.
/**
* Initializes the proposal selector with these given proposals.
*
* @param proposals the proposals
*/
private void setProposals(ICompletionProposal[] proposals) {
if (Helper2.okToUse(fProposalTable)) {
ICompletionProposal oldProposal = getSelectedProposal();
if (oldProposal instanceof ICompletionProposalExtension2)
((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
fFilteredProposals = proposals;
int selectionIndex = 0;
fProposalTable.setRedraw(false);
try {
fProposalTable.removeAll();
Point selection = fViewer.getSelectedRange();
int endOffset;
endOffset = selection.x + selection.y;
IDocument document = fViewer.getDocument();
boolean validate = false;
if (selection.y != 0 && document != null)
validate = true;
TableItem item;
ICompletionProposal p;
for (int i = 0; i < proposals.length; i++) {
p = proposals[i];
item = new TableItem(fProposalTable, SWT.NULL);
if (p.getImage() != null)
item.setImage(p.getImage());
String displayString;
StyleRange[] styleRanges = null;
if (fIsColoredLabelsSupportEnabled && p instanceof ICompletionProposalExtension6) {
StyledString styledString = ((ICompletionProposalExtension6) p).getStyledDisplayString();
displayString = styledString.getString();
styleRanges = styledString.getStyleRanges();
} else
displayString = p.getDisplayString();
item.setText(displayString);
if (fIsColoredLabelsSupportEnabled)
TableOwnerDrawSupport.storeStyleRanges(item, 0, styleRanges);
item.setData(p);
if (validate && validateProposal(document, p, endOffset, null)) {
selectionIndex = i;
validate = false;
}
}
} finally {
fProposalTable.setRedraw(true);
}
resizeProposalSelector(false);
selectProposal(selectionIndex, false);
}
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project eclipse.platform.text by eclipse.
the class CompletionProposalPopup2 method selectProposal.
/**
* Selects the entry with the given index in the proposal selector and feeds
* the selection to the additional info controller.
*
* @param index the index in the list
* @param smartToggle <code>true</code> if the smart toogle key has been pressed
* @since 2.1
*/
private void selectProposal(int index, boolean smartToggle) {
ICompletionProposal oldProposal = getSelectedProposal();
if (oldProposal instanceof ICompletionProposalExtension2)
((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
ICompletionProposal proposal = fFilteredProposals[index];
if (proposal instanceof ICompletionProposalExtension2)
((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
fLastProposal = proposal;
fProposalTable.setSelection(index);
fProposalTable.showSelection();
if (fAdditionalInfoController != null)
fAdditionalInfoController.handleTableSelectionChanged();
}
use of org.eclipse.jface.text.contentassist.ICompletionProposalExtension2 in project liferay-ide by liferay.
the class LiferayCustomXmlHoverControl method _apply.
private void _apply(ICompletionProposal p, ITextViewer viewer, int offset, boolean multiFix) {
// Focus needs to be in the text viewer, otherwise linked mode does not
// work
dispose();
IRewriteTarget target = null;
try {
IDocument document = viewer.getDocument();
if (viewer instanceof ITextViewerExtension) {
ITextViewerExtension extension = (ITextViewerExtension) viewer;
target = extension.getRewriteTarget();
}
if (target != null) {
target.beginCompoundChange();
}
if (p instanceof ICompletionProposalExtension2) {
ICompletionProposalExtension2 e = (ICompletionProposalExtension2) p;
e.apply(viewer, (char) 0, multiFix ? SWT.CONTROL : SWT.NONE, offset);
} else if (p instanceof ICompletionProposalExtension) {
ICompletionProposalExtension e = (ICompletionProposalExtension) p;
e.apply(document, (char) 0, offset);
} else {
p.apply(document);
}
Point selection = p.getSelection(document);
if (selection != null) {
viewer.setSelectedRange(selection.x, selection.y);
viewer.revealRange(selection.x, selection.y);
}
} catch (Exception e) {
} finally {
if (target != null) {
target.endCompoundChange();
}
}
}
Aggregations