Skip to content

Commit

Permalink
API to Track TextViewer install/uninstall in generic editor contribution
Browse files Browse the repository at this point in the history
Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Nov 10, 2022
1 parent d04589f commit d22a9ce
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 41 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jface.text/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jface.text
Bundle-Version: 3.21.100.qualifier
Bundle-Version: 3.22.0.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Export-Package:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* 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;

import org.eclipse.jface.text.DefaultInformationControl.IInformationPresenter;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.hyperlink.IHyperlinkPresenter;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.reconciler.IReconciler;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension2;

/**
* {@link ITextViewer} lifecycle API to track install / uninstall of a given {@link ITextViewer} for
* the given contribution which extends {@link ITextViewerLifecycle}:
*
* <ul>
* <li>{@link IReconciler}</li>
* <li>{@link IPresentationReconciler}</li>
* <li>{@link IHyperlinkPresenter}</li>
* <li>{@link IInformationPresenter}</li>
* <li>{@link IContentAssistant}</li>
* </ul>
*
* It is possible too to implement {@link ITextViewerLifecycle} to track install / uninstall of a
* given {@link ITextViewer} for implementation of:
*
* <ul>
* <li>{@link IReconcilingStrategy}</li>
* <li>{@link IAutoEditStrategy}</li>
* </ul>
*
* @since 3.22
*
*/
public interface ITextViewerLifecycle {

/**
* Installs a text viewer. This method is called when
* {@link ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)} is
* called.
*
* @param textViewer the text viewer
*/
void install(ITextViewer textViewer);

/**
* Uninstalls the registered text viewer. This method is called when
* {@link ISourceViewerExtension2#unconfigure()} is called.
*/
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import org.eclipse.core.runtime.IProgressMonitor;

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


Expand Down Expand Up @@ -98,4 +100,20 @@ protected void initialProcess() {
extension.initialReconcile();
}
}

@Override
public void install(ITextViewer textViewer) {
super.install(textViewer);
if (fStrategy instanceof ITextViewerLifecycle) {
((ITextViewerLifecycle) fStrategy).install(textViewer);
}
}

@Override
public void uninstall() {
if (fStrategy instanceof ITextViewerLifecycle) {
((ITextViewerLifecycle) fStrategy).uninstall();
}
super.uninstall();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension3;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerLifecycle;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
Expand Down Expand Up @@ -161,6 +163,35 @@ protected void reconcilerDocumentChanged(IDocument document) {
}
}


@Override
public void install(ITextViewer textViewer) {
super.install(textViewer);
if (fStrategies != null) {
Iterator<IReconcilingStrategy> e= fStrategies.values().iterator();
while (e.hasNext()) {
IReconcilingStrategy strategy= e.next();
if (strategy instanceof ITextViewerLifecycle) {
((ITextViewerLifecycle) strategy).install(textViewer);
}
}
}
}

@Override
public void uninstall() {
if (fStrategies != null) {
Iterator<IReconcilingStrategy> e= fStrategies.values().iterator();
while (e.hasNext()) {
IReconcilingStrategy strategy= e.next();
if (strategy instanceof ITextViewerLifecycle) {
((ITextViewerLifecycle) strategy).uninstall();
}
}
}
super.uninstall();
}

@Override
public void setProgressMonitor(IProgressMonitor monitor) {
super.setProgressMonitor(monitor);
Expand Down
Loading

0 comments on commit d22a9ce

Please sign in to comment.