Author: dazarov
Date: 2011-04-07 20:39:51 -0400 (Thu, 07 Apr 2011)
New Revision: 30431
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
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/JSPTextViewerConfiguration.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java
Log:
https://issues.jboss.org/browse/JBIDE-5475
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF 2011-04-07
23:35:21 UTC (rev 30430)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/META-INF/MANIFEST.MF 2011-04-08
00:39:51 UTC (rev 30431)
@@ -13,7 +13,9 @@
org.jboss.tools.jst.text.ext,
org.jboss.tools.jsf,
org.jboss.tools.common.el.core,
- org.eclipse.jdt.ui;bundle-version="3.5.0"
+ org.eclipse.jdt.ui;bundle-version="3.5.0",
+ org.jboss.tools.jst.jsp;bundle-version="3.3.0",
+ org.jboss.tools.common.model.ui;bundle-version="3.3.0"
Export-Package: org.jboss.tools.jsf.text.ext,
org.jboss.tools.jsf.text.ext.hyperlink
Bundle-Version: 3.2.0.qualifier
Modified: trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2011-04-07 23:35:21 UTC (rev
30430)
+++ trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/plugin.xml 2011-04-08 00:39:51 UTC (rev
30431)
@@ -1071,8 +1071,8 @@
<partitionType
id="org.jboss.tools.common.text.ext.jsp.JSP_TAG_ATTRIBUTE" />
</contentType>
</hyperlinkPartitioner>
-
- <hyperlinkPartitioner
+
+ <!--hyperlinkPartitioner
id="org.jboss.tools.common.text.ext.jsf.hyperlink.JsfJSPTagNameHyperlinkPartitioner"
class="org.jboss.tools.jsf.text.ext.hyperlink.JsfJSPTagNameHyperlinkPartitioner">
<contentType id="org.eclipse.jst.jsp.core.jspsource">
@@ -1090,9 +1090,19 @@
<contentType id="org.jboss.tools.jst.jsp.jspincludesource">
<partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ELEMENT_NAME" />
</contentType>
- </hyperlinkPartitioner>
+ </hyperlinkPartitioner-->
- </extension>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+
class="org.jboss.tools.jsf.text.ext.hyperlink.JsfJSPTagNameHyperlinkDetector"
+
id="org.jboss.tools.jsf.text.ext.hyperlink.JsfJSPTagNameHyperlinkDetector"
+ name="%JsfJSPTagNameHyperlinkDetector"
+ targetId="org.eclipse.wst.html.core.htmlsource">
+ </hyperlinkDetector>
+ </extension>
<extension
point="org.jboss.tools.common.text.ext.hyperlink"
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java 2011-04-08
00:39:51 UTC (rev 30431)
@@ -0,0 +1,117 @@
+package org.jboss.tools.jsf.text.ext.hyperlink;
+
+import java.util.ArrayList;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.common.core.resources.XModelObjectEditorInput;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor;
+import org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor.JSPStructuredTextViewer;
+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.internal.taglib.AbstractComponent;
+import org.jboss.tools.jst.web.kb.internal.taglib.FaceletTag;
+import org.jboss.tools.jst.web.kb.internal.taglib.TLDTag;
+import org.jboss.tools.jst.web.kb.taglib.IComponent;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+public class JsfJSPTagNameHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+
+ if(!(textViewer instanceof JSPStructuredTextViewer))
+ return null;
+
+ JSPStructuredTextViewer viewer = (JSPStructuredTextViewer) textViewer;
+
+ JSPTextEditor editor = viewer.getEditor();
+
+ XModelObjectEditorInput xInput = (XModelObjectEditorInput) editor.getEditorInput();
+
+ IFile file = xInput.getFile();
+
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(textViewer.getDocument());
+
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null)
+ return null;
+
+ IDOMNode node = (IDOMNode)Utils.findNodeForOffset((Node)xmlDocument,
region.getOffset());
+ if(node != null){
+ KbQuery query = new KbQuery();
+ query.setType(KbQuery.Type.TAG_NAME);
+
+
+ IStructuredDocumentRegion sRegion = node.getStartStructuredDocumentRegion();
+
+ if(sRegion == null)
+ return null;
+
+ if(region.getOffset() > (sRegion.getStartOffset()+sRegion.getLength()))
+ sRegion = node.getEndStructuredDocumentRegion();
+
+ final IStructuredDocumentRegion reg = sRegion;
+
+ if(reg != null){
+ query.setOffset(sRegion.getStartOffset());
+ query.setValue(node.getNodeName());
+ query.setMask(false);
+
+ IPageContext context = (IPageContext)PageContextFactory.createPageContext(file);
+
+ IComponent[] components = PageProcessor.getInstance().getComponents(query, context);
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for(IComponent component : components){
+ if(component instanceof TLDTag || component instanceof FaceletTag){
+ TLDTagHyperlink link = new TLDTagHyperlink((AbstractComponent)component, new
IRegion(){
+ public int getLength() {
+ return reg.getLength();
+ }
+
+ public int getOffset() {
+ return reg.getStartOffset();
+ }
+ });
+ link.setDocument(textViewer.getDocument());
+ hyperlinks.add(link);
+ }
+ }
+ sortHyperlinks(hyperlinks);
+ if(hyperlinks.size() > 0)
+ return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
+ }
+
+ }
+
+ return null;
+ }
+
+ private void sortHyperlinks(ArrayList<IHyperlink> hyperlinks){
+ for(IHyperlink link : hyperlinks){
+ if(link instanceof TLDTagHyperlink){
+ AbstractComponent tag = ((TLDTagHyperlink)link).getComponent();
+ if(tag instanceof TLDTag){
+ int index = hyperlinks.indexOf(link);
+ if(index != 0){
+ IHyperlink first = hyperlinks.get(0);
+ hyperlinks.set(0,link);
+ hyperlinks.set(index, first);
+ }
+ }
+ }
+ }
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/JsfJSPTagNameHyperlinkDetector.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java
(rev 0)
+++
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java 2011-04-08
00:39:51 UTC (rev 30431)
@@ -0,0 +1,79 @@
+package org.jboss.tools.jsf.text.ext.hyperlink;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.impl.FileAnyImpl;
+import org.jboss.tools.common.model.util.FindObjectHelper;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.jst.web.kb.internal.taglib.AbstractComponent;
+import org.jboss.tools.jst.web.kb.taglib.ITagLibrary;
+
+public class TLDTagHyperlink extends AbstractHyperlink {
+ private AbstractComponent tag;
+ private XModelObject xmodelObject;
+ private String xmodelObjectName = null;
+ private IFile file = null;
+ private IRegion region;
+
+ public TLDTagHyperlink(AbstractComponent tag, IRegion region){
+ this.tag = tag;
+ ITagLibrary tagLib = tag.getTagLib();
+ this.region = region;
+ IResource r = tagLib.getResource();
+ if(r instanceof IFile) {
+ IFile file = (IFile)r;
+ if(file.getFullPath() != null &&
file.getFullPath().toString().endsWith(".jar")) {
+ Object id = tag.getId();
+ if(id instanceof XModelObject) {
+ xmodelObject = (XModelObject)id;
+ FileAnyImpl fai = null;
+ XModelObject f = xmodelObject;
+ while(f != null && f.getFileType() != XModelObject.FILE) f = f.getParent();
+ if(f instanceof FileAnyImpl) fai = (FileAnyImpl)f;
+ xmodelObjectName = FileAnyImpl.toFileName(fai);
+ }
+ }
+ }
+
+
+ }
+
+ public AbstractComponent getComponent(){
+ return tag;
+ }
+
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ return region;
+ }
+
+ @Override
+ protected void doHyperlink(IRegion region) {
+ if(xmodelObject != null){
+ int q = FindObjectHelper.findModelObject(xmodelObject,
FindObjectHelper.IN_EDITOR_ONLY);
+ if(q == 1) {
+ openFileFailed();
+ }
+ } else if(file != null){
+ IEditorPart part = null;
+ part = openFileInEditor(file);
+ if(part == null) {
+ openFileFailed();
+ }
+ }else
+ openFileFailed();
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ if(xmodelObjectName != null)
+ return "Open "+xmodelObjectName;
+ else if(file != null)
+ return "Open "+file.getName();
+ else
+ return "Open...";
+ }
+
+}
Property changes on:
trunk/jsf/plugins/org.jboss.tools.jsf.text.ext/src/org/jboss/tools/jsf/text/ext/hyperlink/TLDTagHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2011-04-07
23:35:21 UTC (rev 30430)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/HTMLTextViewerConfiguration.java 2011-04-08
00:39:51 UTC (rev 30431)
@@ -40,6 +40,7 @@
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.common.text.ext.hyperlink.HyperlinkDetector;
import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
import org.jboss.tools.common.text.xml.xpl.MarkerProblemAnnotationHoverProcessor;
import org.jboss.tools.jst.jsp.format.HTMLFormatProcessor;
@@ -112,11 +113,20 @@
* @since 3.1
*/
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- return configurationDelegate
- .getHyperlinkDetectors(
- sourceViewer,
- fPreferenceStore
- .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED));
+ List<IHyperlinkDetector> allDetectors = new
ArrayList<IHyperlinkDetector>();
+
+ IHyperlinkDetector extHyperlinkDetector = HyperlinkDetector.getInstance();
+
+ if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
+
+ IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
+ for (IHyperlinkDetector detector : superDetectors) {
+ if (!allDetectors.contains(detector)) {
+ allDetectors.add(detector);
+ }
+ }
+
+ return allDetectors.toArray(new IHyperlinkDetector[0]);
}
/*
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java 2011-04-07
23:35:21 UTC (rev 30430)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/JSPTextViewerConfiguration.java 2011-04-08
00:39:51 UTC (rev 30431)
@@ -28,6 +28,7 @@
import org.eclipse.wst.sse.ui.internal.SSEUIPlugin;
import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider;
import org.eclipse.wst.sse.ui.internal.taginfo.TextHoverManager;
+import org.jboss.tools.common.text.ext.hyperlink.HyperlinkDetector;
import org.jboss.tools.common.text.xml.contentassist.ProposalSorter;
import org.jboss.tools.common.text.xml.xpl.MarkerProblemAnnotationHoverProcessor;
@@ -135,9 +136,20 @@
* @since 3.1
*/
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
- return configurationDelegate.getHyperlinkDetectors(
- sourceViewer,
- fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED));
+ List<IHyperlinkDetector> allDetectors = new
ArrayList<IHyperlinkDetector>();
+
+ IHyperlinkDetector extHyperlinkDetector = HyperlinkDetector.getInstance();
+
+ if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
+
+ IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
+ for (IHyperlinkDetector detector : superDetectors) {
+ if (!allDetectors.contains(detector)) {
+ allDetectors.add(detector);
+ }
+ }
+
+ return allDetectors.toArray(new IHyperlinkDetector[0]);
}
/**
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java 2011-04-07
23:35:21 UTC (rev 30430)
+++
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/TextViewerConfigurationDelegate.java 2011-04-08
00:39:51 UTC (rev 30431)
@@ -44,26 +44,26 @@
* @see
org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer)
* @since 3.1
*/
- public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer, boolean
enabled) {
- IHyperlinkDetector[] result = ITextViewerConfiguration.NO_CA_DETECTORS;
- if (enabled) {
- List<IHyperlinkDetector> allDetectors = new
ArrayList<IHyperlinkDetector>(0);
-
- IHyperlinkDetector extHyperlinkDetector = HyperlinkDetector.getInstance();
-
- if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
-
- /* IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer);
- for (int m = 0; m < superDetectors.length; m++) {
- IHyperlinkDetector detector = superDetectors[m];
- if (!allDetectors.contains(detector)) {
- allDetectors.add(detector);
- }
- }
- */
- result = allDetectors.toArray(new IHyperlinkDetector[0]);
- }
- return result;
- }
+// public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer, boolean
enabled) {
+// IHyperlinkDetector[] result = ITextViewerConfiguration.NO_CA_DETECTORS;
+// if (enabled) {
+// List<IHyperlinkDetector> allDetectors = new
ArrayList<IHyperlinkDetector>(0);
+//
+// IHyperlinkDetector extHyperlinkDetector = HyperlinkDetector.getInstance();
+//
+// if (extHyperlinkDetector != null) allDetectors.add(extHyperlinkDetector);
+//
+//// IHyperlinkDetector[] superDetectors = target.getHyperlinkDetectors(sourceViewer);
+//// for (int m = 0; m < superDetectors.length; m++) {
+//// IHyperlinkDetector detector = superDetectors[m];
+//// if (!allDetectors.contains(detector)) {
+//// allDetectors.add(detector);
+//// }
+//// }
+//
+// result = allDetectors.toArray(new IHyperlinkDetector[0]);
+// }
+// return result;
+// }
}