custom information control on annotation bar
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
index a9f475d..da9e0c2 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
@@ -13,13 +13,17 @@
import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.jface.text.AbstractHoverInformationControlManager;
import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IInformationControlCreatorExtension;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewerExtension3;
@@ -39,6 +43,16 @@
private IVerticalRulerInfo fVerticalRulerInfo;
/** The annotation hover the manager uses to retrieve the information to display */
private IAnnotationHover fAnnotationHover;
+ /**
+ * The custom information control creator.
+ * @since 3.0
+ */
+ private volatile IInformationControlCreator fCustomInformationControlCreator;
+ /**
+ * Tells whether a custom information control is in use.
+ * @since 3.0
+ */
+ private boolean fIsCustomInformtionControl= false;
/**
@@ -83,6 +97,11 @@
* @see AbstractHoverInformationControlManager#computeInformation()
*/
protected void computeInformation() {
+
+ fCustomInformationControlCreator= null;
+ if (fAnnotationHover instanceof IAnnotationHoverExtension)
+ fCustomInformationControlCreator= ((IAnnotationHoverExtension) fAnnotationHover).getInformationControlCreator();
+
Point location= getHoverEventLocation();
int line= fVerticalRulerInfo.toDocumentLineNumber(location.y);
setInformation(fAnnotationHover.getHoverInfo(fSourceViewer, line), computeArea(line));
@@ -153,5 +172,41 @@
protected IVerticalRulerInfo getVerticalRulerInfo() {
return fVerticalRulerInfo;
}
+
+ /*
+ * @see org.eclipse.jface.text.AbstractInformationControlManager#getInformationControl()
+ * @since 3.0
+ */
+ protected IInformationControl getInformationControl() {
+
+ if (fCustomInformationControlCreator == null || fDisposed) {
+ if (fIsCustomInformtionControl) {
+ fInformationControl.dispose();
+ fInformationControl= null;
+ }
+ fIsCustomInformtionControl= false;
+ return super.getInformationControl();
+ }
+
+ if ((fCustomInformationControlCreator instanceof IInformationControlCreatorExtension)
+ && ((IInformationControlCreatorExtension) fCustomInformationControlCreator).canBeReused(fInformationControl))
+ return fInformationControl;
+
+ if (fInformationControl != null)
+ fInformationControl.dispose();
+
+ fInformationControl= fCustomInformationControlCreator.createInformationControl(getSubjectControl().getShell());
+ fIsCustomInformtionControl= true;
+ fInformationControl.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ handleInformationControlDisposed();
+ }
+ });
+
+ if (fInformationControlCloser != null)
+ fInformationControlCloser.setInformationControl(fInformationControl);
+
+ return fInformationControl;
+ }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java
new file mode 100644
index 0000000..093f7d2
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+import org.eclipse.jface.text.IInformationControlCreator;
+
+/**
+ * Extension to <code>IAnnotationHover</code> for providing its own information control creator.
+ *
+ * @see org.eclipse.jface.text.IInformationControlCreator
+ * @see org.eclipse.jface.text.source.IAnnotationHover
+ * @since 3.0
+ */
+public interface IAnnotationHoverExtension {
+
+ /**
+ * Returns the information control creator of this annotation hover.
+ *
+ * @return the information control creator
+ */
+ IInformationControlCreator getInformationControlCreator();
+}
\ No newline at end of file