Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilos Kleint2011-02-03 16:13:56 +0000
committerMilos Kleint2011-02-03 16:13:56 +0000
commit7f8ba0b767a2d3a198213f0c0420a808d68924eb (patch)
tree939d565c53729f01fc06351199404f81eb6e2475 /org.eclipse.m2e.editor.xml
parent0a59f936e1a454811e13588b1d8f5cae83a15727 (diff)
downloadm2e-core-7f8ba0b767a2d3a198213f0c0420a808d68924eb.tar.gz
m2e-core-7f8ba0b767a2d3a198213f0c0420a808d68924eb.tar.xz
m2e-core-7f8ba0b767a2d3a198213f0c0420a808d68924eb.zip
336205 reuse the hover component in the form editor's header
Diffstat (limited to 'org.eclipse.m2e.editor.xml')
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java4
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java13
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java128
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java (renamed from org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MarkerHoverControl.java)17
-rw-r--r--org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java3
5 files changed, 153 insertions, 12 deletions
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
index fea5d533..d9059cac 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomHyperlinkDetector.java
@@ -616,7 +616,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
- static class ExpressionRegion implements IRegion {
+ public static class ExpressionRegion implements IRegion {
final String property;
private int length;
@@ -640,7 +640,7 @@ public class PomHyperlinkDetector implements IHyperlinkDetector {
}
}
- static class ManagedArtifactRegion implements IRegion {
+ public static class ManagedArtifactRegion implements IRegion {
private int length;
private int offset;
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
index 201de826..8b5ac6c3 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/PomTextHover.java
@@ -40,6 +40,7 @@ import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ExpressionRegion;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ManagedArtifactRegion;
+import org.eclipse.m2e.editor.xml.internal.MarkerHoverControl;
import org.eclipse.m2e.editor.xml.internal.Messages;
import org.eclipse.m2e.editor.xml.internal.NodeOperation;
import org.eclipse.m2e.editor.xml.internal.XmlUtils;
@@ -64,7 +65,7 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
/**
* @param region
*/
- static StyledString getLabelForRegion(ManagedArtifactRegion region) {
+ public static StyledString getLabelForRegion(ManagedArtifactRegion region) {
MavenProject mavprj = region.project;
if (mavprj != null) {
String version = null;
@@ -100,7 +101,7 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
/**
* @param hoverRegion
*/
- static StyledString getLabelForRegion(ExpressionRegion region) {
+ public static StyledString getLabelForRegion(ExpressionRegion region) {
MavenProject mavprj = region.project;
if (mavprj != null) {
String value = PomTemplateContext.simpleInterpolate(region.project, "${" + region.property + "}"); //$NON-NLS-1$ //$NON-NLS-2$
@@ -188,7 +189,7 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
}
- static class MarkerRegion implements IRegion {
+ public static class MarkerRegion implements IRegion {
private final MarkerAnnotation ann;
final int offset;
@@ -214,13 +215,13 @@ public class PomTextHover implements ITextHover, ITextHoverExtension, ITextHover
}
- static class CompoundRegion implements IRegion {
+ public static class CompoundRegion implements IRegion {
private int length = Integer.MIN_VALUE;
private int offset = Integer.MAX_VALUE;
private List<IRegion> regions = new ArrayList<IRegion>();
- final ITextViewer textViewer;
- final int textOffset;
+ public final ITextViewer textViewer;
+ public final int textOffset;
public CompoundRegion(ITextViewer textViewer, int textOffset) {
this.textViewer = textViewer;
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java
new file mode 100644
index 00000000..4c3fdf63
--- /dev/null
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/FormHoverProvider.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2008-2011 Sonatype, Inc.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Sonatype, Inc. - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.m2e.editor.xml.internal;
+
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlExtension3;
+import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.util.Geometry;
+import org.eclipse.swt.SWT;
+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.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.texteditor.MarkerAnnotation;
+
+import org.eclipse.m2e.editor.xml.PomTextHover;
+import org.eclipse.m2e.editor.xml.PomTextHover.MarkerRegion;
+
+public final class FormHoverProvider {
+
+ public static Execute createHoverRunnable(final Shell parentShell, final IMarker[] markers, final ISourceViewer sourceViewer) {
+ if (markers.length > 0) {
+ return new Execute() {
+ public void run(Point position) {
+ List<IMarker> markersSet = Arrays.asList(markers);
+ PomTextHover.CompoundRegion compound = new PomTextHover.CompoundRegion(sourceViewer, 0);
+ Iterator<Annotation> it = sourceViewer.getAnnotationModel().getAnnotationIterator();
+ while (it.hasNext()) {
+ Annotation ann = it.next();
+ if (ann instanceof MarkerAnnotation) {
+ MarkerAnnotation mann = (MarkerAnnotation) ann;
+ if (markersSet.contains(mann.getMarker()));
+ compound.addRegion(new MarkerRegion(0, 0, mann));
+ }
+ }
+ final MarkerHoverControl mhc = new MarkerHoverControl(parentShell);
+ final Display fDisplay= mhc.getMyShell().getDisplay();
+
+ final Listener displayListener = new Listener() {
+ public void handleEvent(Event event) {
+ if (event.type == SWT.MouseMove) {
+ if (!(event.widget instanceof Control) || event.widget.isDisposed())
+ return;
+
+ IInformationControl infoControl= mhc;
+ if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3) {
+ IInformationControlExtension3 iControl3= (IInformationControlExtension3) infoControl;
+ Rectangle controlBounds= iControl3.getBounds();
+ if (controlBounds != null) {
+ Point mouseLoc= event.display.map((Control) event.widget, null, event.x, event.y);
+ int margin= 20;
+ Geometry.expand(controlBounds, margin, margin, margin, margin);
+ if (!controlBounds.contains(mouseLoc)) {
+ mhc.setVisible(false);
+ }
+ }
+
+// } else {
+// System.out.println("removing mouse move..");
+// /*
+// * TODO: need better understanding of why/if this is needed.
+// * Looks like the same panic code we have in org.eclipse.jface.text.AbstractHoverInformationControlManager.Closer.handleMouseMove(Event)
+// */
+// if (fDisplay != null && !fDisplay.isDisposed())
+// fDisplay.removeFilter(SWT.MouseMove, this);
+ }
+
+ } else if (event.type == SWT.FocusOut) {
+ IInformationControl iControl= mhc;
+ if (iControl != null && ! iControl.isFocusControl())
+ mhc.setVisible(false);
+ }
+ }
+ };
+ mhc.setInput(compound);
+ mhc.setLocation(new Point(position.x, position.y));
+ Point hint = mhc.computeSizeHint();
+ mhc.setSize(hint.x, hint.y);
+ if (!fDisplay.getBounds().contains(position.x + hint.x, position.y + hint.y)) {
+ mhc.setLocation(new Point(position.x - (position.x + hint.x - fDisplay.getBounds().width), position.y));
+ }
+// mhc.getMyShell().addShellListener(new ShellAdapter() {
+// public void shellActivated(ShellEvent e) {
+// mhc.setFocus();
+// }
+// });
+ if (!fDisplay.isDisposed()) {
+ fDisplay.addFilter(SWT.MouseMove, displayListener);
+ fDisplay.addFilter(SWT.FocusOut, displayListener);
+ }
+ mhc.addDisposeListener(new DisposeListener() {
+ public void widgetDisposed(DisposeEvent e) {
+ fDisplay.removeFilter(SWT.MouseMove, displayListener);
+ fDisplay.removeFilter(SWT.FocusOut, displayListener);
+ }
+ });
+ mhc.setVisible(true);
+ }
+ };
+ } else {
+ return null;
+ }
+ }
+
+ public static interface Execute {
+ void run(Point location);
+ }
+}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MarkerHoverControl.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java
index 61dba421..23377599 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/MarkerHoverControl.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/MarkerHoverControl.java
@@ -9,7 +9,7 @@
* Sonatype, Inc. - initial API and implementation
*******************************************************************************/
-package org.eclipse.m2e.editor.xml;
+package org.eclipse.m2e.editor.xml.internal;
import java.util.ArrayList;
import java.util.List;
@@ -67,13 +67,14 @@ import org.eclipse.ui.editors.text.EditorsUI;
import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess;
+import org.eclipse.m2e.editor.xml.PomHyperlinkDetector;
+import org.eclipse.m2e.editor.xml.PomTextHover;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ExpressionRegion;
import org.eclipse.m2e.editor.xml.PomHyperlinkDetector.ManagedArtifactRegion;
import org.eclipse.m2e.editor.xml.PomTextHover.CompoundRegion;
import org.eclipse.m2e.editor.xml.PomTextHover.MarkerRegion;
-import org.eclipse.m2e.editor.xml.internal.Messages;
-class MarkerHoverControl extends AbstractInformationControl implements IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension5 {
+public class MarkerHoverControl extends AbstractInformationControl implements IInformationControlExtension2, IInformationControlExtension3, IInformationControlExtension5 {
private CompoundRegion region;
private Control focusControl;
@@ -99,6 +100,15 @@ class MarkerHoverControl extends AbstractInformationControl implements IInformat
disposeDeferredCreatedContent();
deferredCreateContent();
}
+
+ Shell getMyShell() {
+ return super.getShell();
+ }
+
+ Control getRoot() {
+ return parent;
+ }
+
/*
* @see org.eclipse.jface.text.IInformationControlExtension#hasContents()
@@ -113,6 +123,7 @@ class MarkerHoverControl extends AbstractInformationControl implements IInformat
public void setFocus() {
super.setFocus();
if (focusControl != null) {
+ System.out.println("setting focus to my comp");
focusControl.setFocus();
}
}
diff --git a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
index 00162b95..408ca308 100644
--- a/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
+++ b/org.eclipse.m2e.editor.xml/src/main/java/org/eclipse/m2e/editor/xml/internal/XmlUtils.java
@@ -266,7 +266,8 @@ public class XmlUtils {
if (domModel != null) {
domModel.releaseFromRead();
}
- } }
+ }
+ }
/*
* calculates the path of the node up in the hierarchy, example of result is project/build/plugins/plugin

Back to the top