Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcvs2svn2004-01-30 17:46:38 +0000
committercvs2svn2004-01-30 17:46:38 +0000
commitd1e2a625d7c67efbbe7f3770267cc5db7bec8d01 (patch)
treef619aaa0c3f4448d212f996db7b4f3bf89329cc5
parentf8ce7d115860d7ff0a5a1f43060ea1662f7b6739 (diff)
downloadeclipse.platform.text-d1e2a625d7c67efbbe7f3770267cc5db7bec8d01.tar.gz
eclipse.platform.text-d1e2a625d7c67efbbe7f3770267cc5db7bec8d01.tar.xz
eclipse.platform.text-d1e2a625d7c67efbbe7f3770267cc5db7bec8d01.zip
This commit was manufactured by cvs2svn to create branch 'eclipse_look_3_0'.
Cherrypick from master 2004-01-30 17:46:37 UTC Kai Maetzel <kmaetzel> 'clean-up': org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpandHover.java org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpansionControl.java org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/LinearLayouter.java org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConfigurationElementSorter.java org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction2.java
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpandHover.java281
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpansionControl.java795
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/LinearLayouter.java58
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConfigurationElementSorter.java157
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction2.java98
5 files changed, 1389 insertions, 0 deletions
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpandHover.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpandHover.java
new file mode 100644
index 000000000..0baab3b05
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpandHover.java
@@ -0,0 +1,281 @@
+/*******************************************************************************
+ * 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.ui.internal.texteditor;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.jface.viewers.IDoubleClickListener;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IInformationControlCreatorExtension;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewerExtension3;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.IAnnotationHoverExtension;
+import org.eclipse.jface.text.source.IAnnotationHoverExtension2;
+import org.eclipse.jface.text.source.IAnnotationListener;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRulerExtension;
+import org.eclipse.jface.text.source.IVerticalRulerInfo;
+
+import org.eclipse.ui.internal.texteditor.AnnotationExpansionControl.AnnotationHoverInput;
+
+/**
+ *
+ *
+ * @since 3.0
+ */
+public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHoverExtension, IAnnotationHoverExtension2 {
+ private class InformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl createInformationControl(Shell parent) {
+ return new AnnotationExpansionControl(parent, SWT.NONE, fAnnotationAccess);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReuse(org.eclipse.jface.text.IInformationControl)
+ */
+ public boolean canReuse(IInformationControl control) {
+ return control instanceof AnnotationExpansionControl;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlCreatorExtension#canReplace(org.eclipse.jface.text.IInformationControlCreator)
+ */
+ public boolean canReplace(IInformationControlCreator creator) {
+ return creator == this;
+ }
+ }
+
+ private final IInformationControlCreator fgCreator= new InformationControlCreator();
+ protected IVerticalRulerInfo fVerticalRulerInfo;
+ protected IAnnotationListener fAnnotationListener;
+
+ protected IDoubleClickListener fDblClickListener;
+ protected IAnnotationAccess fAnnotationAccess;
+
+ /**
+ * Creates a new hover instance.
+ *
+ * @param ruler
+ * @param listener
+ * @param doubleClickListener
+ * @param access
+ */
+ public AnnotationExpandHover(IVerticalRulerInfo ruler, IAnnotationListener listener, IDoubleClickListener doubleClickListener, IAnnotationAccess access) {
+ fAnnotationListener= listener;
+ fVerticalRulerInfo= ruler;
+ fDblClickListener= doubleClickListener;
+ fAnnotationAccess= access;
+ }
+
+ /**
+ * @param ruler
+ * @param access
+ */
+ public AnnotationExpandHover(IVerticalRulerInfo ruler, IAnnotationAccess access) {
+ this(ruler, null, null, access);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int)
+ */
+ public String getHoverInfo(ISourceViewer sourceViewer, int line) {
+ // we don't have any sensible return value as text
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationHoverExtension2#getHoverInfo2(org.eclipse.jface.text.source.ISourceViewer, int)
+ */
+ public Object getHoverInfo2(ISourceViewer viewer, int line) {
+ IAnnotationModel model= viewer.getAnnotationModel();
+ IDocument document= viewer.getDocument();
+
+ if (model == null)
+ return null;
+
+ List exact= new ArrayList();
+ HashMap messagesAtPosition= new HashMap();
+
+ Iterator e= model.getAnnotationIterator();
+ while (e.hasNext()) {
+ Annotation annotation= (Annotation) e.next();
+ Position position= model.getPosition(annotation);
+ if (position == null)
+ continue;
+
+ if (compareRulerLine(position, document, line) == 1) {
+ if (isDuplicateMessage(messagesAtPosition, position, annotation.getText()))
+ continue;
+
+ exact.add(annotation);
+ }
+ }
+
+ if (exact.size() < 1)
+ return null;
+
+ sort(exact, model);
+
+ if (exact.size() > 0)
+ setLastRulerMouseLocation(viewer, line);
+
+ AnnotationHoverInput input= new AnnotationHoverInput();
+ input.fAnnotations= (Annotation[]) exact.toArray(new Annotation[0]);
+ input.fViewer= viewer;
+ input.fRulerInfo= fVerticalRulerInfo;
+ input.fAnnotationListener= fAnnotationListener;
+ input.fDoubleClickListener= fDblClickListener;
+ input.model= model;
+
+ return input;
+ }
+
+ protected void sort(List exact, final IAnnotationModel model) {
+ class AnnotationComparator implements Comparator {
+
+ /*
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(Object o1, Object o2) {
+ Annotation a1= (Annotation) o1;
+ Annotation a2= (Annotation) o2;
+
+ Position p1= model.getPosition(a1);
+ Position p2= model.getPosition(a2);
+
+ // annotation order:
+ // primary order: by position in line
+ // secondary: annotation importance
+ if (p1.offset == p2.offset)
+ return getOrder(a2) - getOrder(a1);
+ else
+ return p1.offset - p2.offset;
+ }
+ }
+
+ Collections.sort(exact, new AnnotationComparator());
+
+ }
+
+ protected int getOrder(Annotation annotation) {
+ // standard implementation: check for marker annotation level
+ return annotation.getLayer();
+ }
+
+ protected boolean isDuplicateMessage(Map messagesAtPosition, Position position, String message) {
+ if (messagesAtPosition.containsKey(position)) {
+ Object value= messagesAtPosition.get(position);
+ if (message == null || message.equals(value))
+ return true;
+
+ if (value instanceof List) {
+ List messages= (List)value;
+ if (messages.contains(message))
+ return true;
+ else
+ messages.add(message);
+ } else {
+ ArrayList messages= new ArrayList();
+ messages.add(value);
+ messages.add(message);
+ messagesAtPosition.put(position, messages);
+ }
+ } else
+ messagesAtPosition.put(position, message);
+ return false;
+ }
+
+ protected void setLastRulerMouseLocation(ISourceViewer viewer, int line) {
+ // set last mouse activity in order to get the correct context menu
+ if (fVerticalRulerInfo instanceof IVerticalRulerExtension) {
+ StyledText st= viewer.getTextWidget();
+ if (st != null && !st.isDisposed()) {
+ if (viewer instanceof ITextViewerExtension3) {
+ int widgetLine= ((ITextViewerExtension3)viewer).modelLine2WidgetLine(line);
+ Point loc= st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
+ ((IVerticalRulerExtension)fVerticalRulerInfo).setLocationOfLastMouseButtonActivity(0, loc.y);
+ } else if (viewer instanceof TextViewer) {
+ // TODO remove once TextViewer implements the extension
+ int widgetLine= ((TextViewer)viewer).modelLine2WidgetLine(line);
+ Point loc= st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
+ ((IVerticalRulerExtension)fVerticalRulerInfo).setLocationOfLastMouseButtonActivity(0, loc.y);
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns the distance to the ruler line.
+ */
+ protected int compareRulerLine(Position position, IDocument document, int line) {
+
+ if (position.getOffset() > -1 && position.getLength() > -1) {
+ try {
+ int firstLine= document.getLineOfOffset(position.getOffset());
+ if (line == firstLine)
+ return 1;
+ if (firstLine <= line && line <= document.getLineOfOffset(position.getOffset() + position.getLength()))
+ return 2;
+ } catch (BadLocationException x) {
+ }
+ }
+
+ return 0;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getInformationControlCreator()
+ */
+ public IInformationControlCreator getInformationControlCreator() {
+ return fgCreator;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int, int, int)
+ */
+ public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber, int first, int number) {
+ // use default implementation
+ return getHoverInfo(sourceViewer, lineNumber);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getLineRange(org.eclipse.jface.text.source.ISourceViewer, int, int, int)
+ */
+ public ITextSelection getLineRange(ISourceViewer viewer, int line, int first, int number) {
+ // use default implementation
+ return null;
+ }
+
+}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpansionControl.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpansionControl.java
new file mode 100644
index 000000000..ca09330cd
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/AnnotationExpansionControl.java
@@ -0,0 +1,795 @@
+/*******************************************************************************
+ * 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.ui.internal.texteditor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackAdapter;
+import org.eclipse.swt.events.MouseTrackListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Canvas;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Layout;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+
+import org.eclipse.jface.viewers.IDoubleClickListener;
+
+import org.eclipse.jface.text.AbstractInformationControlManager;
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IInformationControlExtension;
+import org.eclipse.jface.text.IInformationControlExtension2;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.IViewportListener;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.TextViewer;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.AnnotationEvent;
+import org.eclipse.jface.text.source.IAnnotationAccess;
+import org.eclipse.jface.text.source.IAnnotationAccessExtension;
+import org.eclipse.jface.text.source.IAnnotationListener;
+import org.eclipse.jface.text.source.IAnnotationModel;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRulerInfo;
+
+
+/**
+ * A control that can display a number of annotations. The control can decide how it layouts the
+ * annotations to present them to the user.
+ *
+ * <p>Each annotation can have its custom context menu and hover.</p>
+ *
+ * @since 3.0
+ */
+public class AnnotationExpansionControl implements IInformationControl, IInformationControlExtension, IInformationControlExtension2 {
+
+
+ public interface ICallback {
+ void run(IInformationControlExtension2 control);
+ }
+
+ /**
+ * Input used by the control to display the annotations.
+ * TODO move to top-level class
+ * TODO encapsulate fields
+ *
+ * @since 3.0
+ */
+ public static class AnnotationHoverInput {
+ public Annotation[] fAnnotations;
+ public ISourceViewer fViewer;
+ public IVerticalRulerInfo fRulerInfo;
+ public IAnnotationListener fAnnotationListener;
+ public IDoubleClickListener fDoubleClickListener;
+ public ICallback redoAction;
+ public IAnnotationModel model;
+ }
+
+ private final class Item {
+ Annotation fAnnotation;
+ Canvas canvas;
+ StyleRange[] oldStyles;
+
+ public void selected() {
+ Display disp= fShell.getDisplay();
+ canvas.setCursor(fHandCursor);
+ // TODO: shade - for now: set grey background
+ canvas.setBackground(getSelectionColor(disp));
+
+ // highlight the viewer background at its position
+ oldStyles= setViewerBackground(fAnnotation);
+
+ // set the selection
+ fSelection= this;
+
+ if (fHoverManager != null)
+ fHoverManager.showInformation();
+
+ if (fInput.fAnnotationListener != null) {
+ AnnotationEvent event= new AnnotationEvent(fAnnotation);
+ fInput.fAnnotationListener.annotationSelected(event);
+ }
+
+ }
+
+ public void defaultSelected() {
+ if (fInput.fAnnotationListener != null) {
+ AnnotationEvent event= new AnnotationEvent(fAnnotation);
+ fInput.fAnnotationListener.annotationDefaultSelected(event);
+ }
+
+ dispose();
+ }
+
+ public void showContextMenu(Menu menu) {
+ if (fInput.fAnnotationListener != null) {
+ AnnotationEvent event= new AnnotationEvent(fAnnotation);
+ fInput.fAnnotationListener.annotationContextMenuAboutToShow(event, menu);
+ }
+ }
+
+ public void deselect() {
+ // hide the popup
+// fHoverManager.disposeInformationControl();
+
+ // deselect
+ fSelection= null;
+
+ resetViewerBackground(oldStyles);
+ oldStyles= null;
+
+ Display disp= fShell.getDisplay();
+ canvas.setCursor(null);
+ // TODO: remove shading - for now: set standard background
+ canvas.setBackground(disp.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+
+ }
+
+ }
+
+ /**
+ * Disposes of an item
+ */
+ private final class MyDisposeListener implements DisposeListener {
+ /*
+ * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
+ */
+ public void widgetDisposed(DisposeEvent e) {
+ Item item= (Item) ((Widget) e.getSource()).getData();
+ item.deselect();
+ item.canvas= null;
+ item.fAnnotation= null;
+ item.oldStyles= null;
+
+ ((Widget) e.getSource()).setData(null);
+ }
+ }
+
+ /**
+ * Listener on context menu invocation on the items
+ */
+ private final class MyMenuDetectListener implements Listener {
+ /*
+ * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
+ */
+ public void handleEvent(Event event) {
+ if (event.type == SWT.MenuDetect) {
+ // TODO: show per-item menu
+ // for now: show ruler context menu
+ if (fInput != null) {
+ Control ruler= fInput.fRulerInfo.getControl();
+ if (ruler != null && !ruler.isDisposed()) {
+ Menu menu= ruler.getMenu();
+ if (menu != null && !menu.isDisposed()) {
+ menu.setLocation(event.x, event.y);
+ menu.addMenuListener(new MenuListener() {
+
+ public void menuHidden(MenuEvent e) {
+ dispose();
+ }
+
+ public void menuShown(MenuEvent e) {
+ }
+
+ });
+ menu.setVisible(true);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Listener on mouse events on the items.
+ */
+ private final class MyMouseListener extends MouseAdapter {
+ /*
+ * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseDoubleClick(MouseEvent e) {
+ Item item= (Item) ((Widget) e.getSource()).getData();
+ if (e.button == 1 && item.fAnnotation == fInput.fAnnotations[0] && fInput.fDoubleClickListener != null) {
+ fInput.fDoubleClickListener.doubleClick(null);
+ // special code for JDT to renew the annotation set.
+ if (fInput.redoAction != null)
+ fInput.redoAction.run(AnnotationExpansionControl.this);
+ }
+// dispose();
+ // TODO special action to invoke double-click action on the vertical ruler
+ // how about
+// Canvas can= (Canvas) e.getSource();
+// Annotation a= (Annotation) can.getData();
+// if (a != null) {
+// a.getDoubleClickAction().run();
+// }
+ }
+
+ /*
+ * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseUp(MouseEvent e) {
+ Item item= (Item) ((Widget) e.getSource()).getData();
+ // TODO for now, to make double click work: disable single click on the first item
+ // disable later when the annotationlistener selectively handles input
+ if (item != null && e.button == 1) // && item.fAnnotation != fInput.fAnnotations[0])
+ item.defaultSelected();
+ }
+
+ /*
+ * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseDown(MouseEvent e) {
+ // TODO Auto-generated method stub
+ super.mouseDown(e);
+ }
+ }
+
+ /**
+ * Listener on mouse track events on the items.
+ */
+ private final class MyMouseTrackListener implements MouseTrackListener {
+ /*
+ * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseEnter(MouseEvent e) {
+ Item item= (Item) ((Widget) e.getSource()).getData();
+ if (item != null)
+ item.selected();
+ }
+
+ /*
+ * @see org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseExit(MouseEvent e) {
+
+ Item item= (Item) ((Widget) e.getSource()).getData();
+ if (item != null)
+ item.deselect();
+
+ // if the event lies outside the entire popup, dispose
+ org.eclipse.swt.graphics.Region region= fShell.getRegion();
+ Canvas can= (Canvas) e.getSource();
+ Point p= can.toDisplay(e.x, e.y);
+ if (region == null) {
+ Rectangle bounds= fShell.getBounds();
+// p= fShell.toControl(p);
+ if (!bounds.contains(p))
+ dispose();
+ } else {
+ p= fShell.toControl(p);
+ if (!region.contains(p))
+ dispose();
+ }
+
+
+ }
+
+ /*
+ * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent)
+ */
+ public void mouseHover(MouseEvent e) {
+ if (fHoverManager == null) {
+ fHoverManager= new HoverManager();
+ fHoverManager.takesFocusWhenVisible(false);
+ fHoverManager.install(fComposite);
+ fHoverManager.showInformation();
+ }
+ }
+ }
+
+ /**
+ * Listener on paint events on the items. Paints the annotation image on the given <code>GC</code>.
+ */
+ private final class MyPaintListener implements PaintListener {
+ /*
+ * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
+ */
+ public void paintControl(PaintEvent e) {
+ Canvas can= (Canvas) e.getSource();
+ Annotation a= ((Item) can.getData()).fAnnotation;
+ if (a != null) {
+ Rectangle rect= new Rectangle(fLayouter.getBorderWidth(), fLayouter.getBorderWidth(), fLayouter.getAnnotationSize(), fLayouter.getAnnotationSize());
+ if (fAnnotationAccessExtension != null)
+ fAnnotationAccessExtension.paint(a, e.gc, can, rect);
+ }
+ }
+ }
+
+ /**
+ * Our own private hover manager used to shop per-item pop-ups.
+ */
+ private final class HoverManager extends AbstractInformationControlManager {
+
+ /**
+ *
+ */
+ public HoverManager() {
+ super(new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ return new DefaultInformationControl(parent);
+ }
+ });
+
+ setMargins(5, 10);
+ setAnchor(ANCHOR_BOTTOM);
+ setFallbackAnchors(new Anchor[] { ANCHOR_LEFT, ANCHOR_RIGHT} );
+ }
+
+ /*
+ * @see org.eclipse.jface.text.AbstractInformationControlManager#computeInformation()
+ */
+ protected void computeInformation() {
+ if (fSelection != null) {
+ Rectangle subjectArea= fSelection.canvas.getBounds();
+ Annotation annotation= fSelection.fAnnotation;
+ String msg;
+ if (annotation != null)
+ msg= annotation.getText();
+ else
+ msg= null;
+
+ setInformation(msg, subjectArea);
+ }
+ }
+
+
+ }
+
+ /** Model data. */
+ protected AnnotationHoverInput fInput;
+ /** The control's shell */
+ private Shell fShell;
+ /** The composite combining all the items. */
+ protected Composite fComposite;
+ /** The hand cursor. */
+ private Cursor fHandCursor;
+ /** The currently selected item, or <code>null</code> if none is selected. */
+ private Item fSelection;
+ /** The hover manager for the per-item hovers. */
+ private HoverManager fHoverManager;
+ /** The annotation access extension. */
+ private IAnnotationAccessExtension fAnnotationAccessExtension;
+
+
+ /* listener legion */
+ private final MyPaintListener fPaintListener;
+ private final MyMouseTrackListener fMouseTrackListener;
+ private final MyMouseListener fMouseListener;
+ private final MyMenuDetectListener fMenuDetectListener;
+ private final DisposeListener fDisposeListener;
+ private final IViewportListener fViewportListener;
+
+ private LinearLayouter fLayouter;
+
+ /**
+ * Creates a new control.
+ *
+ * @param parent
+ * @param shellStyle
+ * @param access
+ */
+ public AnnotationExpansionControl(Shell parent, int shellStyle, IAnnotationAccess access) {
+ fPaintListener= new MyPaintListener();
+ fMouseTrackListener= new MyMouseTrackListener();
+ fMouseListener= new MyMouseListener();
+ fMenuDetectListener= new MyMenuDetectListener();
+ fDisposeListener= new MyDisposeListener();
+ fViewportListener= new IViewportListener() {
+
+ public void viewportChanged(int verticalOffset) {
+ dispose();
+ }
+
+ };
+ fLayouter= new LinearLayouter();
+
+ if (access instanceof IAnnotationAccessExtension)
+ fAnnotationAccessExtension= (IAnnotationAccessExtension) access;
+
+ fShell= new Shell(parent, shellStyle | SWT.NO_FOCUS | SWT.ON_TOP);
+ Display display= fShell.getDisplay();
+ fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
+ fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM);
+// fComposite= new Composite(fShell, SWT.NO_FOCUS | SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.V_SCROLL);
+
+ GridLayout layout= new GridLayout(1, true);
+ layout.marginHeight= 0;
+ layout.marginWidth= 0;
+ fShell.setLayout(layout);
+
+ GridData data= new GridData(GridData.FILL_BOTH);
+ data.heightHint= fLayouter.getAnnotationSize() + 2 * fLayouter.getBorderWidth() + 4;
+ fComposite.setLayoutData(data);
+ fComposite.addMouseTrackListener(new MouseTrackAdapter() {
+
+ public void mouseExit(MouseEvent e) {
+ if (fComposite == null)
+ return;
+ Control[] children= fComposite.getChildren();
+ for (int i= 0; i < children.length; i++) {
+ if (children[i].getBounds().contains(e.x, e.y))
+ return;
+ }
+
+ // if none of the children contains the event, we left the popup
+ dispose();
+ }
+
+ });
+
+// fComposite.getVerticalBar().addListener(SWT.Selection, new Listener() {
+//
+// public void handleEvent(Event event) {
+// Rectangle bounds= fShell.getBounds();
+// int x= bounds.x - fLayouter.getAnnotationSize() - fLayouter.getBorderWidth();
+// int y= bounds.y;
+// fShell.setBounds(x, y, bounds.width, bounds.height);
+// }
+//
+// });
+
+ fHandCursor= new Cursor(display, SWT.CURSOR_HAND);
+ fShell.setCursor(fHandCursor);
+ fComposite.setCursor(fHandCursor);
+
+ setInfoSystemColor();
+ }
+
+ private void setInfoSystemColor() {
+ Display display= fShell.getDisplay();
+ setForegroundColor(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
+ setBackgroundColor(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControl#setInformation(java.lang.String)
+ */
+ public void setInformation(String information) {
+ setInput(null);
+ }
+
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object)
+ */
+ public void setInput(Object input) {
+ if (fInput != null && fInput.fViewer != null)
+ fInput.fViewer.removeViewportListener(fViewportListener);
+
+ if (input instanceof AnnotationHoverInput)
+ fInput= (AnnotationHoverInput) input;
+ else
+ fInput= null;
+
+ inputChanged(fInput, null);
+ }
+
+ protected void inputChanged(Object newInput, Object newSelection) {
+ refresh();
+ }
+
+ protected void refresh() {
+ adjustItemNumber();
+
+ if (fInput == null)
+ return;
+
+ if (fInput.fAnnotations == null)
+ return;
+
+ if (fInput.fViewer != null)
+ fInput.fViewer.addViewportListener(fViewportListener);
+
+ fShell.setRegion(fLayouter.getShellRegion(fInput.fAnnotations.length));
+
+ Layout layout= fLayouter.getLayout(fInput.fAnnotations.length);
+ fComposite.setLayout(layout);
+
+ Control[] children= fComposite.getChildren();
+ for (int i= 0; i < fInput.fAnnotations.length; i++) {
+ Canvas canvas= (Canvas) children[i];
+ Item item= new Item();
+ item.canvas= canvas;
+ item.fAnnotation= fInput.fAnnotations[i];
+ canvas.setData(item);
+ canvas.redraw();
+ }
+
+ }
+
+ protected void adjustItemNumber() {
+ if (fComposite == null)
+ return;
+
+ Control[] children= fComposite.getChildren();
+ int oldSize= children.length;
+ int newSize= fInput == null ? 0 : fInput.fAnnotations.length;
+
+ Display display= fShell.getDisplay();
+
+ // add missing items
+ for (int i= oldSize; i < newSize; i++) {
+ Canvas canvas= new Canvas(fComposite, SWT.NONE);
+ Object gridData= fLayouter.getLayoutData();
+ canvas.setLayoutData(gridData);
+ canvas.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
+
+ canvas.addPaintListener(fPaintListener);
+
+ canvas.addMouseTrackListener(fMouseTrackListener);
+
+ canvas.addMouseListener(fMouseListener);
+
+ canvas.addListener(SWT.MenuDetect, fMenuDetectListener);
+
+ canvas.addDisposeListener(fDisposeListener);
+ }
+
+ // dispose of exceeding resources
+ for (int i= oldSize; i > newSize; i--) {
+ Item item= (Item) children[i - 1].getData();
+ item.deselect();
+ children[i - 1].dispose();
+ }
+
+ }
+
+ /*
+ * @see IInformationControl#setVisible(boolean)
+ */
+ public void setVisible(boolean visible) {
+ fShell.setVisible(visible);
+ }
+
+ /*
+ * @see IInformationControl#dispose()
+ */
+ public void dispose() {
+ if (fShell != null) {
+ if (!fShell.isDisposed())
+ fShell.dispose();
+ fShell= null;
+ fComposite= null;
+ if (fHandCursor != null)
+ fHandCursor.dispose();
+ fHandCursor= null;
+ if (fHoverManager != null)
+ fHoverManager.dispose();
+ fHoverManager= null;
+ fSelection= null;
+ }
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControlExtension#hasContents()
+ */
+ public boolean hasContents() {
+ return fInput.fAnnotations != null && fInput.fAnnotations.length > 0;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControl#setSizeConstraints(int, int)
+ */
+ public void setSizeConstraints(int maxWidth, int maxHeight) {
+ //fMaxWidth= maxWidth;
+ //fMaxHeight= maxHeight;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IInformationControl#computeSizeHint()
+ */
+ public Point computeSizeHint() {
+ return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+ }
+
+ /*
+ * @see IInformationControl#setLocation(Point)
+ */
+ public void setLocation(Point location) {
+ fShell.setLocation(location);
+ }
+
+ /*
+ * @see IInformationControl#setSize(int, int)
+ */
+ public void setSize(int width, int height) {
+ fShell.setSize(width, height);
+ }
+
+ /*
+ * @see IInformationControl#addDisposeListener(DisposeListener)
+ */
+ public void addDisposeListener(DisposeListener listener) {
+ fShell.addDisposeListener(listener);
+ }
+
+ /*
+ * @see IInformationControl#removeDisposeListener(DisposeListener)
+ */
+ public void removeDisposeListener(DisposeListener listener) {
+ fShell.removeDisposeListener(listener);
+ }
+
+ /*
+ * @see IInformationControl#setForegroundColor(Color)
+ */
+ public void setForegroundColor(Color foreground) {
+ fComposite.setForeground(foreground);
+ }
+
+ /*
+ * @see IInformationControl#setBackgroundColor(Color)
+ */
+ public void setBackgroundColor(Color background) {
+ fComposite.setBackground(background);
+ }
+
+ /*
+ * @see IInformationControl#isFocusControl()
+ */
+ public boolean isFocusControl() {
+ if (fComposite.isFocusControl())
+ return true;
+ else {
+ Control[] children= fComposite.getChildren();
+ for (int i= 0; i < children.length; i++) {
+ if (children[i].isFocusControl())
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /*
+ * @see IInformationControl#setFocus()
+ */
+ public void setFocus() {
+ fShell.forceFocus();
+ }
+
+ /*
+ * @see IInformationControl#addFocusListener(FocusListener)
+ */
+ public void addFocusListener(FocusListener listener) {
+ fShell.addFocusListener(listener);
+ }
+
+ /*
+ * @see IInformationControl#removeFocusListener(FocusListener)
+ */
+ public void removeFocusListener(FocusListener listener) {
+ fShell.removeFocusListener(listener);
+ }
+
+ private StyleRange[] setViewerBackground(Annotation annotation) {
+ StyledText text= fInput.fViewer.getTextWidget();
+ if (text == null || text.isDisposed())
+ return null;
+
+ Display disp= text.getDisplay();
+
+ Position pos= fInput.model.getPosition(annotation);
+ if (pos == null)
+ return null;
+
+ IRegion region= ((TextViewer)fInput.fViewer).modelRange2WidgetRange(new Region(pos.offset, pos.length));
+
+ StyleRange[] ranges= text.getStyleRanges(region.getOffset(), region.getLength());
+
+ List undoRanges= new ArrayList(ranges.length);
+ for (int i= 0; i < ranges.length; i++) {
+ undoRanges.add(ranges[i].clone());
+ }
+
+ int offset= region.getOffset();
+ StyleRange current= undoRanges.size() > 0 ? (StyleRange) undoRanges.get(0) : null;
+ int curStart= current != null ? current.start : region.getOffset() + region.getLength();
+ int curEnd= current != null ? current.start + current.length : -1;
+ int index= 0;
+
+ // fill no-style regions
+ while (curEnd < region.getOffset() + region.getLength()) {
+ // add empty range
+ if (curStart > offset) {
+ StyleRange undoRange= new StyleRange(offset, curStart - offset, null, null);
+ undoRanges.add(index, undoRange);
+ index++;
+ }
+
+ // step
+ index++;
+ if (index < undoRanges.size()) {
+ offset= curEnd;
+ current= (StyleRange) undoRanges.get(index);
+ curStart= current.start;
+ curEnd= current.start + current.length;
+ } else if (index == undoRanges.size()) {
+ // last one
+ offset= curEnd;
+ current= null;
+ curStart= region.getOffset() + region.getLength();
+ curEnd= -1;
+ } else
+ curEnd= region.getOffset() + region.getLength();
+ }
+
+ // create modified styles (with background)
+ List shadedRanges= new ArrayList(undoRanges.size());
+ for (Iterator it= undoRanges.iterator(); it.hasNext(); ) {
+ StyleRange range= (StyleRange) ((StyleRange) it.next()).clone();
+ shadedRanges.add(range);
+ range.background= getHighlightColor(disp);
+ }
+
+ // set the ranges one by one
+ for (Iterator iter= shadedRanges.iterator(); iter.hasNext(); ) {
+ text.setStyleRange((StyleRange) iter.next());
+
+ }
+
+ return (StyleRange[]) undoRanges.toArray(undoRanges.toArray(new StyleRange[0]));
+ }
+
+ private void resetViewerBackground(StyleRange[] oldRanges) {
+
+ if (oldRanges == null)
+ return;
+
+ if (fInput == null)
+ return;
+
+ StyledText text= fInput.fViewer.getTextWidget();
+ if (text == null || text.isDisposed())
+ return;
+
+ // set the ranges one by one
+ for (int i= 0; i < oldRanges.length; i++) {
+ text.setStyleRange(oldRanges[i]);
+ }
+ }
+
+ private Color getHighlightColor(Display disp) {
+ return disp.getSystemColor(SWT.COLOR_GRAY);
+ }
+
+ private Color getSelectionColor(Display disp) {
+ return disp.getSystemColor(SWT.COLOR_GRAY);
+ }
+
+}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/LinearLayouter.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/LinearLayouter.java
new file mode 100644
index 000000000..0db0943b4
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/LinearLayouter.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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.ui.internal.texteditor;
+
+import org.eclipse.swt.graphics.Region;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Layout;
+
+/**
+ *
+ *
+ * @since 3.0
+ */
+public class LinearLayouter {
+
+ private static final int ANNOTATION_SIZE= 14;
+ private static final int BORDER_WIDTH= 2;
+
+ public Layout getLayout(int itemCount) {
+ // simple layout: a row of items
+ GridLayout layout= new GridLayout(itemCount, true);
+ layout.horizontalSpacing= 1;
+ layout.verticalSpacing= 0;
+ layout.marginHeight= 1;
+ layout.marginWidth= 1;
+ return layout;
+ }
+
+ public Object getLayoutData() {
+ GridData gridData= new GridData(ANNOTATION_SIZE + 2 * BORDER_WIDTH, ANNOTATION_SIZE + 2 * BORDER_WIDTH);
+ gridData.horizontalAlignment= GridData.CENTER;
+ gridData.verticalAlignment= GridData.CENTER;
+ return gridData;
+ }
+
+ public int getAnnotationSize() {
+ return ANNOTATION_SIZE;
+ }
+
+ public int getBorderWidth() {
+ return BORDER_WIDTH;
+ }
+
+ public Region getShellRegion(int itemCount) {
+ // no special region - set to null for default shell size
+ return null;
+ }
+
+}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConfigurationElementSorter.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConfigurationElementSorter.java
new file mode 100644
index 000000000..ab92a0838
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ConfigurationElementSorter.java
@@ -0,0 +1,157 @@
+/*******************************************************************************
+ * 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.ui.texteditor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IPluginDescriptor;
+import org.eclipse.core.runtime.IPluginPrerequisite;
+
+import org.eclipse.jface.text.Assert;
+
+/**
+ * Allows to sort an array based on their elements' configuration elements
+ * according to the prerequisite relation of their defining plug-ins.
+ * <p>
+ * This class can be directly used or subclassed.
+ * </p>
+ *
+ * @since 3.0
+ */
+public abstract class ConfigurationElementSorter {
+
+ /**
+ * Sorts the given array based on its elements' configuration elements
+ * according to the prerequisite relation of their defining plug-ins.
+ *
+ * @param elements the array to be sorted
+ */
+ public final void sort(Object[] elements) {
+ Arrays.sort(elements, new ConfigurationElementComparator(elements));
+ }
+
+ /**
+ * Returns the configuration element for the given object.
+ *
+ * @param object the object
+ * @return the object's configuration element, must not be <code>null</code>
+ */
+ public abstract IConfigurationElement getConfigurationElement(Object object);
+
+ /**
+ * Compare configuration elements according to the prerequisite relation
+ * of their defining plug-ins.
+ */
+ private class ConfigurationElementComparator implements Comparator {
+
+ private Map fDescriptorMapping;
+ private Set fDescriptorSet;
+ private Map fPrereqsMapping;
+
+ public ConfigurationElementComparator(Object[] elements) {
+ Assert.isNotNull(elements);
+ initialize(elements);
+ }
+
+ /*
+ * @see Comparator#compare(java.lang.Object, java.lang.Object)
+ * @since 2.0
+ */
+ public int compare(Object object0, Object object1) {
+
+ if (dependsOn(object0, object1))
+ return -1;
+
+ if (dependsOn(object1, object0))
+ return +1;
+
+ return 0;
+ }
+
+ /**
+ * Returns whether one configuration element depends on the other element.
+ * This is done by checking the dependency chain of the defining plug-ins.
+ *
+ * @param element0 the first element
+ * @param element1 the second element
+ * @return <code>true</code> if <code>element0</code> depends on <code>element1</code>.
+ * @since 2.0
+ */
+ private boolean dependsOn(Object element0, Object element1) {
+ if (element0 == null || element1 == null)
+ return false;
+
+ IPluginDescriptor pluginDesc0= (IPluginDescriptor)fDescriptorMapping.get(element0);
+ IPluginDescriptor pluginDesc1= (IPluginDescriptor)fDescriptorMapping.get(element1);
+
+ // performance tuning - code below would give same result
+ if (pluginDesc0.getUniqueIdentifier().equals(pluginDesc1.getUniqueIdentifier()))
+ return false;
+
+ Set prereqUIds0= (Set)fPrereqsMapping.get(pluginDesc0);
+
+ return prereqUIds0.contains(pluginDesc1.getUniqueIdentifier());
+ }
+
+ /**
+ * Initialize this comarator.
+ *
+ * @param elements an array of Java editor hover descriptors
+ */
+ private void initialize(Object[] elements) {
+ int length= elements.length;
+ fDescriptorMapping= new HashMap(length);
+ fPrereqsMapping= new HashMap(length);
+ fDescriptorSet= new HashSet(length);
+
+ for (int i= 0; i < length; i++) {
+ IPluginDescriptor descriptor= getConfigurationElement(elements[i]).getDeclaringExtension().getDeclaringPluginDescriptor();
+ fDescriptorMapping.put(elements[i], descriptor);
+ fDescriptorSet.add(descriptor);
+ }
+
+ Iterator iter= fDescriptorSet.iterator();
+ while (iter.hasNext()) {
+ IPluginDescriptor descriptor= (IPluginDescriptor)iter.next();
+ List toTest= new ArrayList(fDescriptorSet);
+ toTest.remove(descriptor);
+ Set prereqUIds= new HashSet(Math.max(0, toTest.size() - 1));
+ fPrereqsMapping.put(descriptor, prereqUIds);
+
+ IPluginPrerequisite[] prereqs= descriptor.getPluginPrerequisites();
+ int i= 0;
+ while (i < prereqs.length && !toTest.isEmpty()) {
+ String prereqUId= prereqs[i].getUniqueIdentifier();
+ for (int j= 0; j < toTest.size();) {
+ IPluginDescriptor toTest_j= (IPluginDescriptor)toTest.get(j);
+ if (toTest_j.getUniqueIdentifier().equals(prereqUId)) {
+ toTest.remove(toTest_j);
+ prereqUIds.add(toTest_j.getUniqueIdentifier());
+ } else
+ j++;
+ }
+ i++;
+ }
+ }
+ }
+
+ }
+}
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction2.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction2.java
new file mode 100644
index 000000000..90c6328b9
--- /dev/null
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SelectMarkerRulerAction2.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * 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.ui.texteditor;
+
+
+import java.util.ResourceBundle;
+
+import org.eclipse.swt.widgets.Menu;
+
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.source.*;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationModel;
+
+/**
+ * A ruler action which can select the textual range of a marker
+ * that has a visual representation in a vertical ruler.
+ * @since 3.0
+ */
+public class SelectMarkerRulerAction2 extends TextEditorAction implements IAnnotationListener {
+
+ /**
+ * Creates a new action for the given ruler and editor. The action configures
+ * its visual representation from the given resource bundle.
+ *
+ * @param bundle the resource bundle
+ * @param prefix a prefix to be prepended to the various resource keys
+ * (described in <code>ResourceAction</code> constructor), or <code>null</code> if none
+ * @param editor the editor
+ *
+ * @see ResourceAction#ResourceAction(ResourceBundle, String)
+ */
+ public SelectMarkerRulerAction2(ResourceBundle bundle, String prefix, ITextEditor editor) {
+ super(bundle, prefix, editor);
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(org.eclipse.ui.texteditor.ITextEditor)
+ */
+ public void setEditor(ITextEditor editor) {
+ if (getTextEditor() != null) {
+ IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class);
+ if (service instanceof IVerticalRulerInfoExtension)
+ ((IVerticalRulerInfoExtension) service).removeAnnotationListener(this);
+ }
+ super.setEditor(editor);
+ if (getTextEditor() != null) {
+ IVerticalRulerInfo service= (IVerticalRulerInfo) getTextEditor().getAdapter(IVerticalRulerInfo.class);
+ if (service instanceof IVerticalRulerInfoExtension)
+ ((IVerticalRulerInfoExtension) service).addAnnotationListener(this);
+ }
+ }
+
+ /**
+ * Returns the <code>AbstractMarkerAnnotationModel</code> of the editor's input.
+ *
+ * @return the marker annotation model or <code>null</code> if there's none
+ */
+ protected IAnnotationModel getAnnotationModel() {
+ IDocumentProvider provider= getTextEditor().getDocumentProvider();
+ return provider.getAnnotationModel(getTextEditor().getEditorInput());
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.IAnnotationListener#annotationSelected(org.eclipse.ui.texteditor.AnnotationEvent)
+ */
+ public void annotationSelected(AnnotationEvent event) {
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.IAnnotationListener#annotationDefaultSelected(org.eclipse.ui.texteditor.AnnotationEvent)
+ */
+ public void annotationDefaultSelected(AnnotationEvent event) {
+ Annotation a= event.getAnnotation();
+ IAnnotationModel model= getAnnotationModel();
+ Position position= model.getPosition(a);
+ if (position == null)
+ return;
+
+ getTextEditor().selectAndReveal(position.offset, position.length);
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.IAnnotationListener#annotationContextMenuAboutToShow(org.eclipse.ui.texteditor.AnnotationEvent, org.eclipse.swt.widgets.Menu)
+ */
+ public void annotationContextMenuAboutToShow(AnnotationEvent event, Menu menu) {
+ }
+}

Back to the top