Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to Track TextViewer install/uninstall #107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.23
*
*/
public interface ITextViewerLifecycle {
angelozerr marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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