Author: vrubezhny
Date: 2009-12-18 18:04:41 -0500 (Fri, 18 Dec 2009)
New Revision: 19481
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextHoverInformationProvider.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/Utils.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ChainTextHover.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
Log:
JBIDE-4946: Tool tip for tag/attributes in XHTML editor.
Issue is fixed
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-12-18 22:32:28 UTC (rev
19480)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/plugin.xml 2009-12-18 23:04:41 UTC (rev
19481)
@@ -109,7 +109,10 @@
target="org.jboss.tools.jst.jsp.jspeditor.HTMLTextEditor"
type="structuredtextfoldingprovider">
</provisionalConfiguration>
-
+
+
+ <documentationTextHover
class="org.jboss.tools.jst.jsp.jspeditor.info.FaceletTagInfoHoverProcessor"
target="org.eclipse.wst.html.HTML_DEFAULT" />
+
</extension>
<extension point="org.eclipse.ui.preferencePages">
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java 2009-12-18
22:32:28 UTC (rev 19480)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java 2009-12-18
23:04:41 UTC (rev 19481)
@@ -10,27 +10,28 @@
******************************************************************************/
package org.jboss.tools.jst.jsp;
-import java.util.ArrayList;
-import java.util.Dictionary;
import java.util.List;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Plugin;
+import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
import org.eclipse.wst.html.core.text.IHTMLPartitions;
import org.eclipse.wst.html.ui.StructuredTextViewerConfigurationHTML;
+import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
+import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.format.StructuredFormattingStrategy;
-import
org.jboss.tools.common.text.xml.contentassist.SortingCompoundContentAssistProcessor;
+import org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor;
+import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
+import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager;
import org.jboss.tools.jst.jsp.format.HTMLFormatProcessor;
-import org.osgi.framework.Bundle;
+import org.jboss.tools.jst.jsp.jspeditor.info.ChainTextHover;
+@SuppressWarnings("restriction")
public class HTMLTextViewerConfiguration extends StructuredTextViewerConfigurationHTML
implements ITextViewerConfiguration{
TextViewerConfigurationDelegate configurationDelegate;
@@ -39,7 +40,6 @@
configurationDelegate = new TextViewerConfigurationDelegate(this);
}
- @SuppressWarnings("restriction")
protected IContentAssistProcessor[] getContentAssistProcessors(ISourceViewer
sourceViewer, String partitionType) {
return configurationDelegate.getContentAssistProcessors(sourceViewer, partitionType);
}
@@ -68,4 +68,63 @@
ISourceViewer sourceViewer, String partitionType) {
return super.getContentAssistProcessors(sourceViewer, partitionType);
}
+
+ /**
+ * Create documentation hovers based on hovers contributed via
+ * <code>org.eclipse.wst.sse.ui.editorConfiguration</code> extension
+ * point
+ *
+ * Copied from {@link org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration} because
of private modifier
+ *
+ * @param partitionType
+ * @return
+ */
+ @SuppressWarnings("unchecked")
+ private ITextHover[] createDocumentationHovers(String partitionType) {
+ List extendedTextHover =
ExtendedConfigurationBuilder.getInstance().getConfigurations(ExtendedConfigurationBuilder.DOCUMENTATIONTEXTHOVER,
partitionType);
+ ITextHover[] hovers = (ITextHover[]) extendedTextHover.toArray(new
ITextHover[extendedTextHover.size()]);
+ return hovers;
+ }
+
+ @Override
+ protected IInformationProvider getInformationProvider(
+ ISourceViewer sourceViewer, String partitionType) {
+
+ ITextHover chainTextHover = new
ChainTextHover(createDocumentationHovers(partitionType));
+ return new TextHoverInformationProvider(chainTextHover);
+ }
+
+ @Override
+ public ITextHover getTextHover(ISourceViewer sourceViewer,
+ String contentType, int stateMask) {
+ ITextHover textHover = null;
+
+ /*
+ * Returns a default problem, annotation, and best match hover
+ * depending on stateMask
+ */
+ TextHoverManager.TextHoverDescriptor[] hoverDescs =
SSEUIPlugin.getDefault().getTextHoverManager().getTextHovers();
+ int i = 0;
+ while (i < hoverDescs.length && textHover == null) {
+ if (hoverDescs[i].isEnabled() &&
computeStateMask(hoverDescs[i].getModifierString()) == stateMask) {
+ String hoverType = hoverDescs[i].getId();
+ if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType))
+ textHover = new ProblemAnnotationHoverProcessor();
+ else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType))
+ textHover = new AnnotationHoverProcessor();
+ else if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType))
+ textHover = new ChainTextHover(createDocumentationHovers(contentType));
+ else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) {
+ ITextHover[] hovers = createDocumentationHovers(contentType);
+ if (hovers.length > 0) {
+ textHover = hovers[0];
+ }
+ }
+ }
+ i++;
+ }
+ return textHover;
+ }
+
+
}
\ No newline at end of file
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextHoverInformationProvider.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextHoverInformationProvider.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextHoverInformationProvider.java 2009-12-18
23:04:41 UTC (rev 19481)
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp;
+
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextHoverExtension2;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.IInformationProviderExtension;
+import org.eclipse.jface.text.information.IInformationProviderExtension2;
+
+/**
+ *
+ * @author Victor Rubezhny
+ *
+ */
+class TextHoverInformationProvider implements IInformationProvider,
IInformationProviderExtension, IInformationProviderExtension2 {
+ private ITextHover fTextHover;
+
+ public TextHoverInformationProvider(ITextHover hover) {
+ fTextHover = hover;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer,
org.eclipse.jface.text.IRegion)
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ return (String) getInformation2(textViewer, subject);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer,
org.eclipse.jface.text.IRegion)
+ */
+ public Object getInformation2(ITextViewer textViewer, IRegion subject) {
+ return (fTextHover instanceof ITextHoverExtension2 ?
+ ((ITextHoverExtension2)fTextHover).getHoverInfo2(textViewer, subject) :
+ fTextHover.getHoverInfo(textViewer, subject));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator()
+ */
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer,
int)
+ */
+ public IRegion getSubject(ITextViewer textViewer, int offset) {
+ return fTextHover.getHoverRegion(textViewer, offset);
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextHoverInformationProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/Utils.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/Utils.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/Utils.java 2009-12-18
23:04:41 UTC (rev 19481)
@@ -0,0 +1,173 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.contentassist;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.KbQuery.Type;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @author Victor Rubezhny
+ *
+ */
+@SuppressWarnings("restriction")
+public class Utils {
+ private static final String JSFC_ATTRIBUTE_NAME = "jsfc"; //$NON-NLS-1$
+
+ /**
+ * Creates and fills the KbQuery object
+ *
+ * @param type
+ * @param offset
+ * @param query
+ * @param stringQuery
+ * @param prefix
+ * @param uri
+ * @param parentTags
+ * @param parent
+ * @param mask
+ * @return
+ */
+ public static KbQuery createKbQuery(Type type, int offset, String query,
+ String stringQuery, String prefix, String uri, String[] parentTags, String parent,
boolean mask) {
+ KbQuery kbQuery = new KbQuery();
+
+ kbQuery.setPrefix(prefix);
+ kbQuery.setUri(uri);
+ kbQuery.setParentTags(parentTags);
+ kbQuery.setParent(parent);
+ kbQuery.setMask(mask);
+ kbQuery.setType(type);
+ kbQuery.setOffset(offset);
+ kbQuery.setValue(query);
+ kbQuery.setStringQuery(stringQuery);
+
+ return kbQuery;
+ }
+
+ /**
+ * Returns the name for the tag
+ *
+ * @param tag
+ * @param useJsfcTags
+ * @return
+ */
+ public static String getTagName(Node tag, boolean useJsfcTags) {
+ String tagName = tag.getNodeName();
+ if(useJsfcTags) {
+ // Only HTML tags
+ if(tagName.indexOf(':')>0) {
+ return tagName;
+ }
+ if (!(tag instanceof Element))
+ return tagName;
+
+ Element element = (Element)tag;
+
+ NamedNodeMap attributes = element.getAttributes();
+ Node jsfC = attributes.getNamedItem(JSFC_ATTRIBUTE_NAME);
+ if(jsfC==null || (!(jsfC instanceof Attr))) {
+ return tagName;
+ }
+ Attr jsfCAttribute = (Attr)jsfC;
+ String jsfTagName = jsfCAttribute.getValue();
+ if(jsfTagName==null || jsfTagName.indexOf(':')<1) {
+ return tagName;
+ }
+ tagName = jsfTagName;
+ }
+ return tagName;
+ }
+
+ /**
+ * Returns name of the parent attribute/tag name
+ *
+ * @return
+ */
+ public static String getParent(IDOMNode xmlnode, boolean returnAttributeName, boolean
returnThisElement,
+ boolean useJsfcAttribute) {
+
+ Node node = xmlnode;
+ while ((node != null) && (node.getNodeType() == Node.TEXT_NODE) &&
(node.getParentNode() != null)) {
+ node = node.getParentNode();
+ }
+
+ if (!returnAttributeName && (node instanceof IDOMAttr)) {
+ node = ((IDOMAttr)node).getOwnerElement();
+ }
+
+ if (node == null)
+ return null;
+
+ // Find the first parent tag
+ if (!(node instanceof IDOMElement)) {
+ if (node instanceof IDOMAttr) {
+ if (returnAttributeName) {
+ String parentAttrName = node.getNodeName();
+ return parentAttrName;
+ }
+ node = ((IDOMAttr) node).getOwnerElement();
+ } else {
+ node = node.getParentNode();
+ }
+ } else {
+ if (!returnThisElement)
+ node = node.getParentNode();
+ }
+ if (node == null)
+ return null;
+
+ return getTagName(node, useJsfcAttribute);
+ }
+
+ private static final String[] EMPTY_TAGS = new String[0];
+ /**
+ * Returns array of the parent tags
+ *
+ * @return
+ */
+ public static String[] getParentTags(IDOMNode xmlnode, boolean includeThisTag, boolean
useJsfcAttribute) {
+ List<String> parentTags = new ArrayList<String>();
+
+ // Find the first parent tag
+ Node node = xmlnode;
+ while ((node != null) && (node.getNodeType() != Node.ELEMENT_NODE) &&
(node.getParentNode() != null)) {
+ node = node.getNodeType() == Node.ATTRIBUTE_NODE ? ((Attr)node).getOwnerElement() :
node.getParentNode();
+ }
+
+ if (!includeThisTag) {
+ node = node.getParentNode();
+ }
+
+ if (node == null)
+ return EMPTY_TAGS;
+
+ // Store all the parents
+ while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ String tagName = getTagName(node, useJsfcAttribute);
+ parentTags.add(0, tagName);
+ node = node.getParentNode();
+ }
+
+ return (String[])parentTags.toArray(new String[parentTags.size()]);
+ }
+
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/Utils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ChainTextHover.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ChainTextHover.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ChainTextHover.java 2009-12-18
23:04:41 UTC (rev 19481)
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.info;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextHoverExtension;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.wst.sse.ui.internal.Logger;
+import org.eclipse.wst.sse.ui.internal.taginfo.AnnotationHoverProcessor;
+import org.eclipse.wst.sse.ui.internal.taginfo.DebugInfoHoverProcessor;
+import org.eclipse.wst.sse.ui.internal.taginfo.ProblemAnnotationHoverProcessor;
+
+
+/**
+ * Provides the best hover help documentation (by using other hover help
+ * processors) Priority of hover help processors is: ProblemHoverProcessor,
+ * FaceletTagInfoProcessor, TagInfoProcessor, AnnotationHoverProcessor
+ *
+ * The processors are acquired in order of their priorities. If a hover doesn'n
returns an information
+ * (i.e. returns null as a display string) the next processor will be acquired.
+ *
+ * @author Victor Rubezhny
+ *
+ */
+@SuppressWarnings("restriction")
+public class ChainTextHover implements ITextHover, ITextHoverExtension {
+ private ITextHover fBestMatchHover; // current best match text hover
+ private ITextHover[] fTagInfoHovers; // documentation/information hover
+ private List<ITextHover> fTextHovers; // list of text hovers to consider in best
+ // match
+
+ public ChainTextHover(ITextHover infoTagHover) {
+ this(new ITextHover[]{infoTagHover});
+ }
+
+ public ChainTextHover(ITextHover[] infoTagHovers) {
+ fTagInfoHovers = infoTagHovers;
+ }
+
+ /**
+ * Create a list of text hovers applicable to this best match hover
+ * processor
+ *
+ * @return List of ITextHover - in abstract class this is empty list
+ */
+ private List<ITextHover> createTextHoversList() {
+ List<ITextHover> hoverList = new ArrayList<ITextHover>();
+ // if currently debugging, then add the debug hover to the list of
+ // best match
+ if (Logger.isTracing(DebugInfoHoverProcessor.TRACEFILTER)) {
+ hoverList.add(new DebugInfoHoverProcessor());
+ }
+
+ hoverList.add(new ProblemAnnotationHoverProcessor());
+
+ if (fTagInfoHovers != null) {
+ for (int i = 0; i < fTagInfoHovers.length; i++) {
+ if (fTagInfoHovers[i] instanceof FaceletTagInfoHoverProcessor) {
+ hoverList.add(fTagInfoHovers[i]);
+ }
+ }
+ for (int i = 0; i < fTagInfoHovers.length; i++) {
+ if (!(fTagInfoHovers[i] instanceof FaceletTagInfoHoverProcessor)) {
+ hoverList.add(fTagInfoHovers[i]);
+ }
+ }
+ }
+ hoverList.add(new AnnotationHoverProcessor());
+ return hoverList;
+ }
+
+ public IInformationControlCreator getHoverControlCreator() {
+ IInformationControlCreator creator = null;
+
+ if (fBestMatchHover instanceof ITextHoverExtension) {
+ creator = ((ITextHoverExtension) fBestMatchHover).getHoverControlCreator();
+ }
+ return creator;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
+ * org.eclipse.jface.text.IRegion)
+ */
+ public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
+ String displayInfo = null;
+
+ // already have a best match hover picked out from getHoverRegion call
+ if (fBestMatchHover != null) {
+ displayInfo = fBestMatchHover.getHoverInfo(viewer, hoverRegion);
+ }
+ // either had no best match hover or best match hover returned null
+ if (displayInfo == null) {
+ // go through list of text hovers and return first display string
+ Iterator<ITextHover> i = getTextHovers().iterator();
+ while ((i.hasNext()) && (displayInfo == null)) {
+ ITextHover hover = (ITextHover) i.next();
+ displayInfo = hover.getHoverInfo(viewer, hoverRegion);
+ }
+ }
+ return displayInfo;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer,
+ * int)
+ */
+ public IRegion getHoverRegion(ITextViewer viewer, int offset) {
+ IRegion hoverRegion = null;
+
+ // go through list of text hovers and return first hover region
+ ITextHover hover = null;
+ Iterator<ITextHover> i = getTextHovers().iterator();
+ while ((i.hasNext()) && (hoverRegion == null)) {
+ hover = i.next();
+ hoverRegion = hover.getHoverRegion(viewer, offset);
+ }
+
+ // store the text hover processor that found region
+ if (hoverRegion != null)
+ fBestMatchHover = hover;
+ else
+ fBestMatchHover = null;
+
+ return hoverRegion;
+ }
+
+ private List<ITextHover> getTextHovers() {
+ if (fTextHovers == null) {
+ fTextHovers = createTextHoversList();
+ }
+ return fTextHovers;
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/ChainTextHover.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java 2009-12-18
23:04:41 UTC (rev 19481)
@@ -0,0 +1,193 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.jsp.jspeditor.info;
+
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.ui.internal.taginfo.XMLTagInfoHoverProcessor;
+import org.jboss.tools.common.el.core.resolver.ELContext;
+import org.jboss.tools.common.text.TextProposal;
+import org.jboss.tools.jst.jsp.contentassist.Utils;
+import org.jboss.tools.jst.web.kb.IPageContext;
+import org.jboss.tools.jst.web.kb.KbQuery;
+import org.jboss.tools.jst.web.kb.PageContextFactory;
+import org.jboss.tools.jst.web.kb.PageProcessor;
+import org.jboss.tools.jst.web.kb.KbQuery.Type;
+import org.jboss.tools.jst.web.kb.taglib.INameSpace;
+
+/**
+ *
+ * @author Victor Rubezhny
+ *
+ */
+@SuppressWarnings("restriction")
+public class FaceletTagInfoHoverProcessor extends XMLTagInfoHoverProcessor {
+ private ELContext fContext;
+ private int fDocumentPosition;
+
+ public FaceletTagInfoHoverProcessor() {
+ super();
+ }
+
+ @Override
+ protected String computeHoverHelp(ITextViewer textViewer,
+ int documentPosition) {
+ this.fDocumentPosition = documentPosition;
+ this.fContext = null;
+
+ IFile file = getResource(textViewer.getDocument());
+ if (file == null)
+ return null;
+
+ fContext = PageContextFactory.createPageContext(file);
+ if (fContext == null)
+ return null;
+
+ return super.computeHoverHelp(textViewer, documentPosition);
+ }
+
+ @Override
+ protected String computeTagAttNameHelp(IDOMNode xmlnode,
+ IDOMNode parentNode, IStructuredDocumentRegion flatNode,
+ ITextRegion region) {
+ if (fContext == null)
+ return null;
+
+ String tagName = Utils.getTagName(xmlnode, true);
+ String query = flatNode.getText(region);
+ String prefix = getPrefix(tagName);
+ String uri = getUri(prefix);
+ String[] parentTags = Utils.getParentTags(xmlnode, true, true);
+ String parent = Utils.getParent(xmlnode, true, true, true);
+
+ KbQuery kbQuery = Utils.createKbQuery(Type.ATTRIBUTE_NAME, fDocumentPosition, query,
query, //$NON-NLS-1$
+ prefix, uri, parentTags, parent, false);
+
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
fContext);
+ if (proposals == null)
+ return null;
+
+ for(TextProposal proposal : proposals) {
+ if (proposal != null && proposal.getContextInfo() != null &&
+ proposal.getContextInfo().trim().length() > 0) {
+ return proposal.getContextInfo();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ protected String computeTagAttValueHelp(IDOMNode xmlnode,
+ IDOMNode parentNode, IStructuredDocumentRegion flatNode,
+ ITextRegion region) {
+ return null;
+ }
+
+ @Override
+ protected String computeTagNameHelp(IDOMNode xmlnode, IDOMNode parentNode,
+ IStructuredDocumentRegion flatNode, ITextRegion region) {
+ if (fContext == null)
+ return null;
+
+ String query = Utils.getTagName(xmlnode, true);
+ String prefix = getPrefix(query);
+ String uri = getUri(prefix);
+ String[] parentTags = Utils.getParentTags(xmlnode, false, true);
+ String parent = Utils.getParent(xmlnode, false, false, true);
+
+ KbQuery kbQuery = Utils.createKbQuery(Type.TAG_NAME, fDocumentPosition, query,
"<" + query, //$NON-NLS-1$
+ prefix, uri, parentTags, parent, false);
+
+ TextProposal[] proposals = PageProcessor.getInstance().getProposals(kbQuery,
fContext);
+ if (proposals == null)
+ return null;
+
+ for(TextProposal proposal : proposals) {
+ if (proposal != null && proposal.getContextInfo() != null &&
+ proposal.getContextInfo().trim().length() > 0) {
+ return proposal.getContextInfo();
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns IFile resource of the document
+ *
+ * @return
+ */
+ protected IFile getResource(IDocument document) {
+ IStructuredModel sModel =
StructuredModelManager.getModelManager().getExistingModelForRead(document);
+ try {
+ if (sModel != null) {
+ String baseLocation = sModel.getBaseLocation();
+ IPath location = new Path(baseLocation).makeAbsolute();
+ return FileBuffers.getWorkspaceFileAtLocation(location);
+ }
+ }
+ finally {
+ if (sModel != null) {
+ sModel.releaseFromRead();
+ }
+ }
+ return null;
+ }
+
+
+ private String getPrefix(String tagname) {
+ String prefix = null;
+
+ int index = tagname == null ? -1 : tagname.indexOf(':');
+ if (tagname != null && index != -1) {
+ prefix = tagname.substring(0, index);
+ }
+
+ if (prefix != null)
+ return prefix;
+
+ String uri = getUri(""); //$NON-NLS-1$
+ return uri == null ? null : ""; //$NON-NLS-1$
+ }
+
+ private String getUri(String prefix) {
+ if (prefix == null || fContext == null)
+ return null;
+ if (!(fContext instanceof IPageContext))
+ return null;
+
+ Map<String, List<INameSpace>> nameSpaces =
((IPageContext)fContext).getNameSpaces(fDocumentPosition);
+ if (nameSpaces == null || nameSpaces.isEmpty())
+ return null;
+
+ for (List<INameSpace> nameSpace : nameSpaces.values()) {
+ for (INameSpace n : nameSpace) {
+ if (prefix.equals(n.getPrefix())) {
+ return n.getURI();
+ }
+ }
+ }
+ return null;
+ }
+}
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/jspeditor/info/FaceletTagInfoHoverProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain