Skip to content

Commit

Permalink
Introduce ITextViewerLifecycle API
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Oct 28, 2022
1 parent 1900585 commit a5c5564
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* - Angelo ZERR (Red Hat Inc.) - initial implementation
*******************************************************************************/
package org.eclipse.jface.text;

/**
* {@link ITextViewer} lifecycle API to track install / uninstall of a given {@link ITextViewer}.
*
* @since 3.21
*
*/
public interface ITextViewerLifecycle {

/**
* Installs a text viewer.
*
* @param textViewer the text viewer
*/
void install(ITextViewer textViewer);

/**
* Uninstalls the registered text viewer.
*/
void uninstall();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jface.text.contentassist;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;


/**
Expand Down Expand Up @@ -76,7 +77,7 @@
* @see org.eclipse.jface.text.ITextViewer
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor
*/
public interface IContentAssistant {
public interface IContentAssistant extends ITextViewerLifecycle {

//------ proposal popup orientation styles ------------
/** The context info list will overlay the list of completion proposals. */
Expand All @@ -98,12 +99,14 @@ public interface IContentAssistant {
*
* @param textViewer the text viewer on which content assist will work
*/
@Override
void install(ITextViewer textViewer);

/**
* Uninstalls content assist support from the text viewer it has
* previously be installed on.
*/
@Override
void uninstall();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jface.text.hyperlink;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;


/**
Expand All @@ -39,7 +40,7 @@
* @see IHyperlinkPresenterExtension2
* @since 3.1
*/
public interface IHyperlinkPresenter {
public interface IHyperlinkPresenter extends ITextViewerLifecycle {

/**
* Tells whether this presenter is able to handle
Expand Down Expand Up @@ -73,10 +74,12 @@ public interface IHyperlinkPresenter {
*
* @param textViewer the text viewer
*/
@Override
void install(ITextViewer textViewer);

/**
* Uninstalls this hyperlink presenter.
*/
@Override
void uninstall();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jface.text.information;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;


/**
Expand Down Expand Up @@ -46,7 +47,7 @@
* @see org.eclipse.jface.text.information.IInformationProvider
* @since 2.0
*/
public interface IInformationPresenter {
public interface IInformationPresenter extends ITextViewerLifecycle {

/**
* Installs the information presenter on the given text viewer. After this method has been
Expand All @@ -55,12 +56,14 @@ public interface IInformationPresenter {
*
* @param textViewer the viewer on which the presenter is installed
*/
@Override
void install(ITextViewer textViewer);

/**
* Removes the information presenter from the text viewer it has previously been
* installed on.
*/
@Override
void uninstall();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;


/**
Expand Down Expand Up @@ -55,7 +56,7 @@
* @see org.eclipse.jface.text.presentation.IPresentationRepairer
* @see org.eclipse.jface.text.TextPresentation
*/
public interface IPresentationReconciler {
public interface IPresentationReconciler extends ITextViewerLifecycle {

/**
* Installs this presentation reconciler on the given text viewer. After
Expand All @@ -71,12 +72,14 @@ public interface IPresentationReconciler {
* @param viewer the viewer on which this presentation reconciler is
* installed
*/
@Override
void install(ITextViewer viewer);

/**
* Removes the reconciler from the text viewer it has previously been
* installed on.
*/
@Override
void uninstall();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.eclipse.jface.text.reconciler;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;


/**
Expand Down Expand Up @@ -47,7 +48,7 @@
* @see ITextViewer
* @see IReconcilingStrategy
*/
public interface IReconciler {
public interface IReconciler extends ITextViewerLifecycle {

/**
* Installs the reconciler on the given text viewer. After this method has been
Expand All @@ -56,12 +57,14 @@ public interface IReconciler {
*
* @param textViewer the viewer on which the reconciler is installed
*/
@Override
void install(ITextViewer textViewer);

/**
* Removes the reconciler from the text viewer it has
* previously been installed on.
*/
@Override
void uninstall();

/**
Expand Down
28 changes: 28 additions & 0 deletions org.eclipse.ui.genericeditor/schema/reconcilers.exsd
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@
</complexType>
</element>

<element name="reconcilingStrategy">
<complexType>
<sequence>
<element ref="enabledWhen" minOccurs="0" maxOccurs="1"/>
</sequence>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>
The fully qualified class name implementing the interface &lt;code&gt;org.eclipse.jface.text.reconciler.IReconcilingStrategy&lt;/code&gt;
</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.eclipse.jface.text.reconciler.IReconcilingStrategy"/>
</appinfo>
</annotation>
</attribute>
<attribute name="contentType" type="string" use="required">
<annotation>
<documentation>
The target content-type for this extension. Content-types are defined as extension to the org.eclipse.core.contenttype.contentTypes extension point.
</documentation>
<appinfo>
<meta.attribute kind="identifier" basedOn="org.eclipse.core.contenttype.contentTypes/content-type/@id"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="enabledWhen">
<annotation>
<documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.text.IAutoEditStrategy;
import org.eclipse.jface.text.ITextViewerLifecycle;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;

Expand Down Expand Up @@ -57,20 +58,22 @@ public AutoEditStrategyRegistry() {
* @param sourceViewer
* the source viewer we're hooking completion to.
* @param editor the text editor
* @param textViewerLifecycles the list of text viewer lifecycle to fill
* @param contentTypes
* the content types of the document we're editing.
* @return the list of {@link IAutoEditStrategy} contributed for at least
* one of the content types.
*/
public List<IAutoEditStrategy> getAutoEditStrategies(ISourceViewer sourceViewer, ITextEditor editor, Set<IContentType> contentTypes) {
public List<IAutoEditStrategy> getAutoEditStrategies(ISourceViewer sourceViewer, ITextEditor editor,
List<ITextViewerLifecycle> textViewerLifecycles, Set<IContentType> contentTypes) {
if (this.outOfSync) {
sync();
}
return this.extensions.values().stream()
.filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<IAutoEditStrategy>())
.map(GenericContentTypeRelatedExtension<IAutoEditStrategy>::createDelegate)
return this.extensions.values().stream() //
.filter(ext -> contentTypes.contains(ext.targetContentType)) //
.filter(ext -> ext.matches(sourceViewer, editor)) //
.sorted(new ContentTypeSpecializationComparator<IAutoEditStrategy>()) //
.map(ext -> ext.createDelegate(textViewerLifecycles)) //
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.text.ITextViewerLifecycle;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.ITextEditor;
Expand Down Expand Up @@ -51,21 +52,23 @@ public CharacterPairMatcherRegistry() {
* Get the contributed {@link IPresentationReconciliers}s that are relevant to
* hook on source viewer according to document content types.
*
* @param sourceViewer the source viewer we're hooking completion to.
* @param editor the text editor
* @param contentTypes the content types of the document we're editing.
* @param sourceViewer the source viewer we're hooking completion to.
* @param editor the text editor
* @param textViewerLifecycles the list of text viewer lifecycle to fill
* @param contentTypes the content types of the document we're editing.
* @return the list of {@link ICharacterPairMatcher} contributed for at least
* one of the content types.
*/
public List<ICharacterPairMatcher> getCharacterPairMatchers(ISourceViewer sourceViewer, ITextEditor editor,
Set<IContentType> contentTypes) {
List<ITextViewerLifecycle> textViewerLifecycles, Set<IContentType> contentTypes) {
if (this.outOfSync) {
sync();
}
return this.extensions.values().stream().filter(ext -> contentTypes.contains(ext.targetContentType))
.filter(ext -> ext.matches(sourceViewer, editor))
.sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>())
.map(GenericContentTypeRelatedExtension<ICharacterPairMatcher>::createDelegate)
return this.extensions.values().stream() //
.filter(ext -> contentTypes.contains(ext.targetContentType)) //
.filter(ext -> ext.matches(sourceViewer, editor)) //
.sorted(new ContentTypeSpecializationComparator<ICharacterPairMatcher>()) //
.map(ext -> ext.createDelegate(textViewerLifecycles)) //
.collect(Collectors.toList());
}

Expand Down
Loading

0 comments on commit a5c5564

Please sign in to comment.