Author: dazarov
Date: 2009-06-23 13:41:55 -0400 (Tue, 23 Jun 2009)
New Revision: 16150
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
Modified:
trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml
Log:
https://jira.jboss.org/jira/browse/JBIDE-4106
Modified: trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml 2009-06-23 17:29:17
UTC (rev 16149)
+++ trunk/common/plugins/org.jboss.tools.common.text.ext/plugin.xml 2009-06-23 17:41:55
UTC (rev 16150)
@@ -648,6 +648,18 @@
</contentType>
</hyperlinkPartitioner>
<!--End of partiotioner for *.taglib.xml files -->
+
+ <hyperlinkPartitioner
+
id="org.jboss.tools.common.text.ext.hyperlink.xml.PortletHyperlinkPartitioner"
+
class="org.jboss.tools.common.text.ext.hyperlink.xml.PortletHyperlinkPartitioner">
+
+ <contentType id="org.eclipse.core.runtime.xml">
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_TEXT">
+ <axis path="*/portlet/portlet-class/" />
+ <axis path="*/portlet/resource-bundle/" />
+ </partitionType>
+ </contentType>
+ </hyperlinkPartitioner>
</extension>
<extension
@@ -908,6 +920,15 @@
<partitiontype
id="org.jboss.tools.common.text.ext.jsp.JSP_STYLESHEET_REL_LINK" />
</contenttypeidentifier>
</hyperlink>
+
+ <hyperlink
+ class="org.jboss.tools.common.text.ext.hyperlink.xml.PortletHyperlink"
+ id="org.jboss.tools.common.text.ext.hyperlink.xml.PortletHyperlink">
+ <contenttypeidentifier id="org.eclipse.core.runtime.xml">
+ <partitiontype
id="org.jboss.tools.common.text.ext.hyperlink.xml.PORTLET_CLASS" />
+ <partitiontype
id="org.jboss.tools.common.text.ext.hyperlink.xml.PORTLET_RESOURCE" />
+ </contenttypeidentifier>
+ </hyperlink>
</extension>
</plugin>
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java 2009-06-23
17:41:55 UTC (rev 16150)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.common.text.ext.hyperlink.xml;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.text.ext.ExtensionsPlugin;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.w3c.dom.Node;
+
+public class PortletHyperlink extends AbstractHyperlink {
+ private static final String PROP_EXTENSION = ".properties";
+ private String hyperlinkText = "";
+
+ private String partitionType = null;
+
+ @Override
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ Node node = PortletHyperlinkPartitioner.getNode(getDocument(),
+ offset);
+ partitionType = PortletHyperlinkPartitioner.getType(node);
+ if (partitionType == null)
+ return null;
+
+ IndexedRegion text = (IndexedRegion) node;
+
+ int regLength = text.getLength();
+ int regOffset = text.getStartOffset();
+
+ Region region = new Region(regOffset, regLength);
+ return region;
+ }
+
+ @Override
+ protected void doHyperlink(IRegion region) {
+ if (region == null)
+ return;
+
+ try {
+ IDocument document = getDocument();
+ hyperlinkText = document
+ .get(region.getOffset(), region.getLength());
+ } catch (BadLocationException ex) {
+ ExtensionsPlugin.getPluginLog().logError(ex);
+ }
+
+ if (partitionType == PortletHyperlinkPartitioner.PORTLET_CLASS_PARTITION)
+ doPortletClassHyperlink(region);
+ else if (partitionType ==
PortletHyperlinkPartitioner.PORTLET_RESOURCE_BUNDLE_PARTITION)
+ doPortletResourceBundleHyperlink(region);
+
+ }
+
+ private void doPortletClassHyperlink(IRegion region) {
+ IEditorPart part = null;
+ IProject project = getProject();
+ if(project != null){
+ IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
+ if(javaProject != null){
+ IType type = null;
+ try{
+ type = EclipseJavaUtil.findType(javaProject, hyperlinkText);
+ }catch(JavaModelException ex){
+ ExtensionsPlugin.getPluginLog().logError(ex);
+ }
+ if(type != null){
+ IResource resource = type.getResource();
+ if(resource != null && resource instanceof IFile){
+ IFile file = (IFile)resource;
+
+ if (file != null)
+ part = openFileInEditor(file);
+ }
+ }
+ }
+ }
+ if (part == null)
+ openFileFailed();
+ }
+
+ private void doPortletResourceBundleHyperlink(IRegion region) {
+ String fileName = new String(hyperlinkText);
+
+ if(!fileName.endsWith(PROP_EXTENSION))
+ fileName += PROP_EXTENSION;
+
+ IFile file = getFileFromProject(fileName);
+
+ IEditorPart part = null;
+ if (file != null)
+ part = openFileInEditor(file);
+
+ if (part == null)
+ openFileFailed();
+ }
+
+
+ private IProject getProject() {
+ IFile documentFile = getFile();
+ if (documentFile == null || !documentFile.isAccessible())
+ return null;
+
+ IProject project = documentFile.getProject();
+
+ return project;
+ }
+
+ @Override
+ public String getHyperlinkText() {
+ return hyperlinkText;
+ }
+
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlink.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java 2009-06-23
17:41:55 UTC (rev 16150)
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.common.text.ext.hyperlink.xml;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+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.IHyperlinkRegion;
+import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
+import org.jboss.tools.common.text.ext.util.Utils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+public class PortletHyperlinkPartitioner extends AbstractHyperlinkPartitioner {
+ public static final String PORTLET_CLASS_PARTITION =
"org.jboss.tools.common.text.ext.hyperlink.xml.PORTLET_CLASS";
+ public static final String PORTLET_RESOURCE_BUNDLE_PARTITION =
"org.jboss.tools.common.text.ext.hyperlink.xml.PORTLET_RESOURCE";
+
+ static final String textNodeName = "#text";
+
+ static final String portletNodeName = "portlet";
+ static final String portletClassNodeName = "portlet-class";
+ static final String portletResourceBundleNodeName = "resource-bundle";
+
+ public static Node getNode(IDocument document, int superOffset) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ try {
+ smw.init(document);
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null)
+ return null;
+
+ Node node = Utils.findNodeForOffset(xmlDocument, superOffset); // #text
+
+ return node;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ public static String getType(Node node) {
+ Node parentNode = node.getParentNode(); // parent node
+ if (parentNode == null)
+ return null;
+
+ Node portletNode = parentNode.getParentNode(); // portlet node
+ if (parentNode == null)
+ return null;
+
+ if (node.getNodeName().equalsIgnoreCase(textNodeName)
+ && portletNode.getNodeName().equalsIgnoreCase(portletNodeName)) {
+ if (parentNode.getNodeName().equalsIgnoreCase(portletClassNodeName)) {
+ return PORTLET_CLASS_PARTITION;
+ } else if (parentNode.getNodeName().equalsIgnoreCase(
+ portletResourceBundleNodeName)) {
+ return PORTLET_RESOURCE_BUNDLE_PARTITION;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected IHyperlinkRegion parse(IDocument document,
+ IHyperlinkRegion superRegion) {
+ Node node = getNode(document, superRegion.getOffset());
+ String type = getType(node);
+ if (type == null)
+ return null;
+
+ IndexedRegion text = (IndexedRegion) node;
+
+ int length = text.getLength();
+ int offset = text.getStartOffset();
+
+ String contentType = superRegion.getContentType();
+ String axis = getAxis(document, superRegion);
+
+ IHyperlinkRegion hyperRegion = new HyperlinkRegion(offset, length,
+ axis, contentType, type);
+ return hyperRegion;
+ }
+
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.text.ext/src/org/jboss/tools/common/text/ext/hyperlink/xml/PortletHyperlinkPartitioner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain