use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.
the class LineNumberColumn method createControl.
@Override
public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
Assert.isTrue(fDelegate != null);
ITextViewer viewer = parentRuler.getTextViewer();
Assert.isLegal(viewer instanceof ISourceViewer);
fViewer = (ISourceViewer) viewer;
initialize();
Control control = fDelegate.createControl(parentRuler, parentControl);
return control;
}
use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.
the class LinkedModeUI method leave.
void leave(final int flags) {
if (!fIsActive)
return;
fIsActive = false;
endCompoundChangeIfNeeded();
Display display = null;
if (fCurrentTarget.fWidget != null && !fCurrentTarget.fWidget.isDisposed())
display = fCurrentTarget.fWidget.getDisplay();
if (fCurrentTarget.fAnnotationModel != null)
fCurrentTarget.fAnnotationModel.removeAllAnnotations();
disconnect();
for (LinkedModeUITarget fTarget : fTargets) {
LinkedModeUITarget target = fTarget;
ITextViewer viewer = target.getViewer();
if (target.fKeyListener != null) {
((ITextViewerExtension) viewer).removeVerifyKeyListener(target.fKeyListener);
target.fKeyListener = null;
}
viewer.removeTextInputListener(fCloser);
}
for (int i = 0; i < fTargets.length; i++) {
if (fTargets[i].fAnnotationModel != null) {
fTargets[i].fAnnotationModel.removeAllAnnotations();
fTargets[i].fAnnotationModel.disconnect(fTargets[i].getViewer().getDocument());
fTargets[i].fAnnotationModel = null;
}
uninstallAnnotationModel(fTargets[i]);
}
if ((flags & ILinkedModeListener.UPDATE_CARET) != 0 && fExitPosition != null && fFramePosition != fExitPosition && !fExitPosition.isDeleted())
switchPosition(fExitPosition, true, false);
final List<IDocument> docs = new ArrayList<>();
for (LinkedModeUITarget fTarget : fTargets) {
IDocument doc = fTarget.getViewer().getDocument();
if (doc != null)
docs.add(doc);
}
fModel.stopForwarding(flags);
Runnable runnable = new Runnable() {
@Override
public void run() {
if (fExitPosition != null)
fExitPosition.getDocument().removePosition(fExitPosition);
for (IDocument doc : docs) {
doc.removePositionUpdater(fPositionUpdater);
boolean uninstallCat = false;
String[] cats = doc.getPositionCategories();
for (String cat : cats) {
if (getCategory().equals(cat)) {
uninstallCat = true;
break;
}
}
if (uninstallCat)
try {
doc.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
// ignore
}
}
fModel.exit(flags);
}
};
// gets correct document offsets.
if (display != null)
display.asyncExec(runnable);
else
runnable.run();
}
use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.
the class LinkedModeUI method connect.
private void connect() {
Assert.isNotNull(fCurrentTarget);
ITextViewer viewer = fCurrentTarget.getViewer();
Assert.isNotNull(viewer);
fCurrentTarget.fWidget = viewer.getTextWidget();
if (fCurrentTarget.fWidget == null)
leave(ILinkedModeListener.EXIT_ALL);
if (fCurrentTarget.fKeyListener == null) {
fCurrentTarget.fKeyListener = new KeyListener();
((ITextViewerExtension) viewer).prependVerifyKeyListener(fCurrentTarget.fKeyListener);
} else
fCurrentTarget.fKeyListener.setEnabled(true);
registerAutoEditVetoer(viewer);
((IPostSelectionProvider) viewer).addPostSelectionChangedListener(fSelectionListener);
createAnnotationModel();
showSelection();
fCurrentTarget.fShell = fCurrentTarget.fWidget.getShell();
if (fCurrentTarget.fShell == null)
leave(ILinkedModeListener.EXIT_ALL);
fCurrentTarget.fShell.addShellListener(fCloser);
fAssistant.install(viewer);
viewer.addTextInputListener(fCloser);
viewer.getDocument().addDocumentListener(fDocumentListener);
}
use of org.eclipse.jface.text.ITextViewer in project eclipse.platform.text by eclipse.
the class AsyncCompletionProposalPopup method showProposals.
/**
* This methods differs from its super as it will show the list of proposals that
* gets augmented as the {@link IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)}
* complete. All computations operation happen in a non-UI Thread so they're not blocking UI.
*/
@Override
public String showProposals(boolean autoActivated) {
if (fKeyListener == null)
fKeyListener = new ProposalSelectionListener();
final Control control = fContentAssistSubjectControlAdapter.getControl();
if (!Helper.okToUse(fProposalShell) && control != null && !control.isDisposed()) {
// add the listener before computing the proposals so we don't move the caret
// when the user types fast.
fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener);
fInvocationOffset = fContentAssistSubjectControlAdapter.getSelectedRange().x;
fFilterOffset = fInvocationOffset;
fLastCompletionOffset = fFilterOffset;
// start invocation of processors as Futures, and make them populate the proposals upon completion
List<ICompletionProposal> computedProposals = Collections.synchronizedList(new ArrayList<>());
fFutures = buildCompletionFuturesOrJobs(fInvocationOffset);
List<CompletableFuture<Void>> populateFutures = new ArrayList<>(fFutures.size());
for (CompletableFuture<List<ICompletionProposal>> future : fFutures) {
populateFutures.add(future.thenAccept(proposals -> computedProposals.addAll(proposals)));
}
long requestBeginningTimestamp = System.currentTimeMillis();
long stillRemainingThreeshold = MAX_WAIT_IN_MS;
for (CompletableFuture<?> future : populateFutures) {
try {
future.get(stillRemainingThreeshold, TimeUnit.MILLISECONDS);
} catch (TimeoutException | ExecutionException | InterruptedException ex) {
// future failed or took more time than we want to wait
}
stillRemainingThreeshold = MAX_WAIT_IN_MS - (System.currentTimeMillis() - requestBeginningTimestamp);
if (stillRemainingThreeshold < 0) {
// we already spent too much time (more than MAX_WAIT_IN_MS), stop waiting.
break;
}
}
fComputedProposals = computedProposals;
if (stillRemainingThreeshold > 0) {
// everything ready in time, go synchronous
int count = computedProposals.size();
if (count == 0 && hideWhenNoProposals(autoActivated))
return null;
if (count == 1 && !autoActivated && canAutoInsert(computedProposals.get(0))) {
insertProposal(computedProposals.get(0), (char) 0, 0, fInvocationOffset);
hide();
} else {
createProposalSelector();
setProposals(computedProposals, false);
displayProposals();
}
} else {
// processors took too much time, go asynchronous
createProposalSelector();
ComputingProposal computingProposal = new ComputingProposal(fInvocationOffset, fFutures.size());
computedProposals.add(0, computingProposal);
fComputedProposals = computedProposals;
setProposals(fComputedProposals, false);
Set<CompletableFuture<Void>> remaining = Collections.synchronizedSet(new HashSet<>(populateFutures));
for (CompletableFuture<Void> populateFuture : populateFutures) {
populateFuture.thenRun(() -> {
remaining.removeIf(CompletableFuture::isDone);
computingProposal.setRemaining(remaining.size());
if (remaining.isEmpty()) {
computedProposals.remove(computingProposal);
}
List<ICompletionProposal> newProposals = new ArrayList<>(computedProposals);
fComputedProposals = newProposals;
Display.getDefault().asyncExec(() -> {
setProposals(newProposals, false);
displayProposals();
});
});
}
displayProposals();
}
} else {
fLastCompletionOffset = fFilterOffset;
handleRepeatedInvocation();
}
return getErrorMessage();
}
use of org.eclipse.jface.text.ITextViewer in project webtools.sourceediting by eclipse.
the class AbstractXMLCompletionProposalComputer method computeCompletionProposals.
/**
* <p>Return a list of proposed code completions based on the specified
* location within the document that corresponds to the current cursor
* position within the text-editor control.</p>
*
* @see org.eclipse.wst.sse.ui.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext, org.eclipse.core.runtime.IProgressMonitor)
*/
public List computeCompletionProposals(CompletionProposalInvocationContext context, IProgressMonitor monitor) {
ITextViewer textViewer = context.getViewer();
int documentPosition = context.getInvocationOffset();
setErrorMessage(null);
fTextViewer = textViewer;
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(textViewer, documentPosition);
Node node = (Node) treeNode;
while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) && (node.getParentNode() != null)) {
node = node.getParentNode();
}
IDOMNode xmlnode = (IDOMNode) node;
ContentAssistRequest contentAssistRequest = null;
IStructuredDocumentRegion sdRegion = getStructuredDocumentRegion(documentPosition);
ITextRegion completionRegion = getCompletionRegion(documentPosition, node);
String matchString = getMatchString(sdRegion, completionRegion, documentPosition);
// Handle empty Documents
if (completionRegion == null) {
if (((treeNode == null) || (((Node) treeNode).getNodeType() == Node.DOCUMENT_NODE)) && (completionRegion == null) && ((xmlnode == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
IStructuredModel sModel = null;
try {
if (textViewer.getDocument() instanceof IStructuredDocument) {
sModel = StructuredModelManager.getModelManager().getModelForRead((IStructuredDocument) textViewer.getDocument());
}
if (sModel != null) {
IDOMDocument docNode = ((IDOMModel) sModel).getDocument();
contentAssistRequest = new ContentAssistRequest(docNode, docNode, sdRegion, completionRegion, documentPosition, 0, null);
addEmptyDocumentProposals(contentAssistRequest, context);
}
} finally {
if (sModel != null) {
sModel.releaseFromRead();
}
}
if (contentAssistRequest == null) {
// $NON-NLS-1$
Logger.logException(new IllegalStateException("problem getting model"));
return new ArrayList(0);
}
ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
// MASSIVE ERROR CONDITION
// $NON-NLS-1$
Logger.logException(new IllegalStateException("completion region was null"));
setErrorMessage(XMLUIMessages.SEVERE_internal_error_occu_UI_);
// $NON-NLS-1$
contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
// catch documents where no region can be determined
if ((xmlnode.getNodeType() == Node.DOCUMENT_NODE) && ((completionRegion == null) || (xmlnode.getChildNodes() == null) || (xmlnode.getChildNodes().getLength() == 0))) {
contentAssistRequest = computeStartDocumentProposals(matchString, completionRegion, (IDOMNode) treeNode, xmlnode, context);
ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
// compute normal proposals
contentAssistRequest = computeCompletionProposals(matchString, completionRegion, (IDOMNode) treeNode, xmlnode, context);
if (contentAssistRequest == null) {
// $NON-NLS-1$
contentAssistRequest = new ContentAssistRequest((Node) treeNode, node.getParentNode(), sdRegion, completionRegion, documentPosition, 0, "");
setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
}
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=123892
* Only set this error message if nothing else was already set
**/
if (contentAssistRequest.getProposals().size() == 0 && getErrorMessage() == null) {
setErrorMessage(XMLUIMessages.Content_Assist_not_availab_UI_);
}
ICompletionProposal[] props = contentAssistRequest.getCompletionProposals();
return (props != null) ? Arrays.asList(props) : new ArrayList(0);
}
Aggregations