Author: scabanovich
Date: 2011-05-03 18:37:47 -0400 (Tue, 03 May 2011)
New Revision: 31049
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties
Log:
JBIDE-8841
https://issues.jboss.org/browse/JBIDE-8841
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF 2011-05-03
22:37:12 UTC (rev 31048)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/META-INF/MANIFEST.MF 2011-05-03
22:37:47 UTC (rev 31049)
@@ -13,6 +13,9 @@
org.eclipse.jface.text;bundle-version="3.5.0",
org.eclipse.jdt.ui;bundle-version="3.5.0",
org.jboss.tools.cdi.ui;bundle-version="1.2.0",
+ org.jboss.tools.cdi.core,
+ org.jboss.tools.cdi.seam.config.core,
+ org.jboss.tools.jst.text.ext,
org.jboss.tools.jst.web;bundle-version="3.2.0"
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml 2011-05-03 22:37:12 UTC
(rev 31048)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/plugin.xml 2011-05-03 22:37:47 UTC
(rev 31049)
@@ -10,6 +10,48 @@
name="%CDISeamResourceLoadingHyperlinkDetector"
targetId="org.eclipse.jdt.ui.javaCode">
</hyperlinkDetector>
+
</extension>
+ <extension
+ point="org.jboss.tools.common.text.ext.hyperlinkPartitioner"
+ id="org.jboss.tools.cdi.text.ext.hyperlinkPartitioner"
+ name="org.jboss.tools.cdi.text.ext.hyperlinkPartitioner">
+ <hyperlinkPartitioner
+
id="org.jboss.tools.cdi.seam.text.ext.hyperlink.SeamConfigTagNameHyperlinkPartitioner"
+
class="org.jboss.tools.cdi.seam.text.ext.hyperlink.SeamConfigTagNameHyperlinkPartitioner">
+ <contentType id="org.jboss.tools.common.model.ui.xml">
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ELEMENT">
+ <axis path="/beans/*"/>
+ </partitionType>
+ </contentType>
+ <contentType id="org.eclipse.core.runtime.xml">
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_ELEMENT">
+ <axis path="/beans/*"/>
+ </partitionType>
+ </contentType>
+ </hyperlinkPartitioner>
+ </extension>
+
+<extension
+ point="org.jboss.tools.common.text.ext.hyperlink"
+ id="org.jboss.tools.common.text.ext.hyperlink"
+ name="org.jboss.tools.common.text.ext.hyperlink">
+
+ <hyperlink
+ class="org.jboss.tools.cdi.seam.text.ext.hyperlink.SeamConfigTagNameHyperlink"
+ id="org.jboss.tools.cdi.seam.text.ext.hyperlink.SeamConfigTagNameHyperlink">
+ <contenttypeidentifier id="org.eclipse.wst.xml.core.xmlsource">
+ <partitiontype
id="org.jboss.tools.common.text.ext.jsp.SEAM_CONFIG_TAG_NAME" />
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.eclipse.core.runtime.xml">
+ <partitiontype
id="org.jboss.tools.common.text.ext.jsp.SEAM_CONFIG_TAG_NAME" />
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.jboss.tools.common.model.ui.xml">
+ <partitiontype
id="org.jboss.tools.common.text.ext.jsp.SEAM_CONFIG_TAG_NAME" />
+ </contenttypeidentifier>
+ </hyperlink>
+
+</extension>
+
</plugin>
\ No newline at end of file
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java 2011-05-03
22:37:12 UTC (rev 31048)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/CDISeamExtMessages.java 2011-05-03
22:37:47 UTC (rev 31049)
@@ -20,4 +20,5 @@
}
public static String CDI_SEAM_EXT_PLUGIN_NO_MESSAGE;
public static String CDI_SEAM_RESOURCE_LOADING_HYPERLINK;
+ public static String CDI_SEAM_CONFIG_OPEN_TAG;
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java 2011-05-03
22:37:47 UTC (rev 31049)
@@ -0,0 +1,239 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.seam.text.ext.hyperlink;
+
+import java.text.MessageFormat;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.seam.text.ext.CDISeamExtMessages;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.common.util.EclipseJavaUtil;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.jboss.tools.cdi.seam.config.core.CDISeamConfigExtension;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamBeansDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamFieldDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamMemberDefinition;
+import org.jboss.tools.cdi.seam.config.core.definition.SeamMethodDefinition;
+import org.jboss.tools.cdi.seam.config.core.util.Util;
+
+/**
+ * @author Jeremy
+ */
+public class SeamConfigTagNameHyperlink extends AbstractHyperlink {
+
+ /**
+ * @see
com.ibm.sse.editor.AbstractHyperlink#doHyperlink(org.eclipse.jface.text.IRegion)
+ */
+ protected void doHyperlink(IRegion region) {
+ IFile documentFile = getFile();
+ if(documentFile == null) return;
+
+ IProject project = documentFile.getProject();
+ CDICoreNature cdi = CDICorePlugin.getCDI(project, true);
+ if(cdi == null) return;
+
+ String tagName = getTagName(region);
+ if(tagName == null) return;
+ int at = tagName.indexOf('@');
+ String attrName = null;
+ if(at >= 0) {
+ attrName = tagName.substring(at + 1);
+ tagName = tagName.substring(0, at);
+ }
+ String uri = getURI(region);
+
+ IJavaElement element = null;
+
+ IType type = Util.resolveType(tagName, uri, cdi);
+ if(type != null) {
+ element = type;
+ if(attrName != null) {
+ try {
+ if(type.isAnnotation()) {
+ IMethod m = type.getMethod(attrName, new String[0]);
+ if(m != null && m.exists()) element = m;
+ } else {
+ IField f = type.getField(attrName);
+ if(f != null && f.exists()) {
+ element = f;
+ }
+ }
+ } catch (CoreException e) {
+
+ }
+ }
+ } else {
+ SeamMemberDefinition def = find(cdi, region, documentFile);
+ if(def instanceof SeamFieldDefinition) {
+ element = ((SeamFieldDefinition)def).getField();
+ } else if(def instanceof SeamMethodDefinition) {
+ element = ((SeamMethodDefinition)def).getMethod();
+ }
+ }
+ if(element != null) {
+ try {
+ JavaUI.openInEditor(element);
+ } catch (JavaModelException e) {
+ } catch (PartInitException e) {
+
+ }
+ }
+ }
+
+ SeamMemberDefinition find(CDICoreNature cdi, IRegion region, IFile documentFile) {
+ CDISeamConfigExtension ext = CDISeamConfigExtension.getExtension(cdi);
+ if(ext == null) return null;
+ SeamBeansDefinition def = ext.getContext().getDefinition(documentFile.getFullPath());
+ if(def == null) return null;
+ return def.findExactly(region.getOffset());
+ }
+
+ private IType resolve(IJavaProject jp, String tagName, String uri) {
+ return null;
+ }
+
+ private String getURI(IRegion region) {
+ return getURI(region, getDocument());
+ }
+
+ public static String getURI(IRegion region, IDocument document) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+ Node n = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ if(n instanceof Attr) {
+ n = ((Attr)n).getOwnerElement();
+ }
+ if (!(n instanceof Element)) return null;
+ return getURI(n, document, region.getOffset());
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ public static String getURI(Node node, IDocument document, int offset) {
+ String nodeName = node.getNodeName();
+ if (nodeName.indexOf(':') == -1) return null;
+ String nodePrefix = nodeName.substring(0, nodeName.indexOf(":"));
//$NON-NLS-1$
+ if (nodePrefix == null || nodePrefix.length() == 0) return null;
+ Map trackers = JSPRootHyperlinkPartitioner.getTrackersMap(document, offset);
+ return (String)(trackers == null ? null : trackers.get(nodePrefix));
+ }
+
+ private String getTagName(IRegion region) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(getDocument());
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Node node = Utils.findNodeForOffset(xmlDocument, region.getOffset());
+
+ Attr attr = null;
+ Element elem = null;
+
+ if (node instanceof Element) {
+ elem = (Element)node;
+ } else if(node instanceof Attr) {
+ attr = (Attr)node;
+ elem = attr.getOwnerElement();
+ }
+
+ if(elem == null) return null;
+
+ String tagName = elem.getNodeName();
+ if (tagName.indexOf(':') == -1) return null;
+
+ tagName = tagName.substring(tagName.indexOf(':') + 1);
+ if(attr != null) {
+ tagName += "@" + attr.getName();
+ }
+
+ return tagName;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ IRegion fLastRegion = null;
+ /**
+ * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
+ */
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ fLastRegion = getRegion(offset);
+ return fLastRegion;
+ }
+
+ protected IRegion getRegion (int offset) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(getDocument());
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
+
+ if (n == null || !(n instanceof IDOMElement)) return null;
+
+ IDOMElement elem = (IDOMElement)n;
+ String tagName = elem.getTagName();
+ int start = elem.getStartOffset();
+ final int nameStart = start + (elem.isEndTag() ? "</" :
"<").length(); //$NON-NLS-1$ //$NON-NLS-2$
+ final int nameEnd = nameStart + tagName.length();
+
+ if (nameStart > offset || nameEnd <= offset) return null;
+
+ return new Region(nameStart,nameEnd - nameStart);
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see IHyperlink#getHyperlinkText()
+ */
+ public String getHyperlinkText() {
+ String tagName = getTagName(fLastRegion);
+ if (tagName == null)
+ return CDISeamExtMessages.CDI_SEAM_CONFIG_OPEN_TAG;
+
+ return MessageFormat.format(CDISeamExtMessages.CDI_SEAM_CONFIG_OPEN_TAG, tagName);
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlink.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java 2011-05-03
22:37:47 UTC (rev 31049)
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.seam.text.ext.hyperlink;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
+import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkPartitionRecognizer;
+import org.jboss.tools.common.text.ext.hyperlink.IHyperlinkRegion;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.jst.text.ext.hyperlink.jsp.JSPRootHyperlinkPartitioner;
+
+import org.jboss.tools.cdi.seam.config.core.util.Util;
+
+/**
+ * @author Jeremy
+ */
+public class SeamConfigTagNameHyperlinkPartitioner extends AbstractHyperlinkPartitioner
implements IHyperlinkPartitionRecognizer {
+ public static final String SEAM_CONFIG_TAG_NAME_PARTITION =
"org.jboss.tools.common.text.ext.jsp.SEAM_CONFIG_TAG_NAME"; //$NON-NLS-1$
+
+ /**
+ * @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
+ */
+ protected IHyperlinkRegion parse(IDocument document, IHyperlinkRegion superRegion) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Utils.findNodeForOffset(xmlDocument, superRegion.getOffset());
+ IRegion r = getRegion(document, superRegion.getOffset());
+ if (r == null) return null;
+
+ String axis = getAxis(document, superRegion);
+ String contentType = superRegion.getContentType();
+ String type = SEAM_CONFIG_TAG_NAME_PARTITION;
+ int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
+ int offset = superRegion.getOffset();
+
+ IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
+ return region;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ /**
+ * @see
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
+ */
+ public boolean recognize(IDocument document, IHyperlinkRegion region) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ try {
+ IFile documentFile = smw.getFile();
+ if(documentFile==null) {
+ return false;
+ }
+ IProject project = documentFile.getProject();
+ if(project == null) {
+ return false;
+ }
+ return true;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ protected IRegion getRegion(IDocument document, final int offset) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ smw.init(document);
+ try {
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ Node n = Utils.findNodeForOffset(xmlDocument, offset);
+ if(n == null) return null;
+ IDOMAttr attr = null;
+ IDOMElement elem = null;
+ if(n instanceof IDOMElement) {
+ elem = (IDOMElement)n;
+ } else if(n instanceof IDOMAttr) {
+ attr = (IDOMAttr)n;
+ if(attr.getOwnerElement() instanceof IDOMElement) {
+ elem = (IDOMElement)attr.getOwnerElement();
+ }
+ }
+
+ if (elem == null) return null;
+
+ String tagName = elem.getTagName();
+ String uri = SeamConfigTagNameHyperlink.getURI(elem, document, offset);
+ String[] pks = Util.getPackages(uri);
+ if(pks.length == 0) return null;;
+
+ if(attr != null) {
+ int nameStart = ((IndexedRegion)attr).getStartOffset();
+ int nameEnd = nameStart + attr.getName().length();
+ return new Region(nameStart,nameEnd - nameStart);
+ }
+
+ int start = Utils.getValueStart(elem);
+
+ int nameStart = start + (elem.isEndTag() ? "</" :
"<").length(); //$NON-NLS-1$ //$NON-NLS-2$
+ int nameEnd = nameStart + tagName.length();
+
+ if (nameStart > offset || nameEnd <= offset) return null;
+
+ return new Region(nameStart,nameEnd - nameStart);
+ } finally {
+ smw.dispose();
+ }
+
+ }
+
+ protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
+ if (superRegion.getAxis() == null || superRegion.getAxis().length() == 0) {
+ return JSPRootHyperlinkPartitioner.computeAxis(document, superRegion.getOffset()) +
"/"; //$NON-NLS-1$
+ }
+ return superRegion.getAxis();
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/hyperlink/SeamConfigTagNameHyperlinkPartitioner.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties 2011-05-03
22:37:12 UTC (rev 31048)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.seam.text.ext/src/org/jboss/tools/cdi/seam/text/ext/messages.properties 2011-05-03
22:37:47 UTC (rev 31049)
@@ -1,2 +1,3 @@
CDI_SEAM_EXT_PLUGIN_NO_MESSAGE=No message
-CDI_SEAM_RESOURCE_LOADING_HYPERLINK=Open Resource ''{0}''
\ No newline at end of file
+CDI_SEAM_RESOURCE_LOADING_HYPERLINK=Open Resource ''{0}''
+CDI_SEAM_CONFIG_OPEN_TAG=Open Seam Config tag {0}