Author: dazarov
Date: 2009-03-20 08:24:37 -0400 (Fri, 20 Mar 2009)
New Revision: 14280
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
Log:
JBIDE-3901, JBIDE-4002
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/META-INF/MANIFEST.MF 2009-03-20
04:30:29 UTC (rev 14279)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/META-INF/MANIFEST.MF 2009-03-20
12:24:37 UTC (rev 14280)
@@ -27,7 +27,8 @@
org.jboss.tools.jsf,
org.jboss.tools.seam.core,
org.eclipse.jdt.ui,
- org.jboss.tools.jsf.text.ext
+ org.jboss.tools.jsf.text.ext,
+ org.eclipse.jst.j2ee;bundle-version="1.1.200"
Export-Package: org.jboss.tools.seam.text.ext,
org.jboss.tools.seam.text.ext.hyperlink
Bundle-Version: 2.0.0
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2009-03-20 04:30:29 UTC
(rev 14279)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2009-03-20 12:24:37 UTC
(rev 14280)
@@ -202,6 +202,23 @@
</contentType>
</hyperlinkPartitioner>
+ <!-- JBIDE-4002 <bpm:process-definitions> and <bpm:pageflow-definitions>
in components.xml -->
+ <!-- JBIDE-3901 <drools:rule-files> in components.xml -->
+ <hyperlinkPartitioner
+
id="org.jboss.tools.seam.text.ext.hyperlink.ComponentsHyperlinkPartitioner"
+
class="org.jboss.tools.seam.text.ext.hyperlink.ComponentsHyperlinkPartitioner">
+
+ <contentType id="org.jboss.tools.common.model.ui.xml">
+ <partitionType
id="org.jboss.tools.common.text.ext.xml.XML_TEXT">
+ <!-- TODO replace bpm with [
http://jboss.com/products/seam/bpm] -->
+ <axis path="*/bpm:process-definitions/value/" />
+ <!-- TODO replace bpm with [
http://jboss.com/products/seam/bpm] -->
+ <axis path="*/bpm:pageflow-definitions/value/" />
+ <!-- TODO replace drools with [
http://http://jboss.com/products/seam/drools]
-->
+ <axis path="*/drools:rule-files/value/" />
+ </partitionType>
+ </contentType>
+ </hyperlinkPartitioner>
</extension>
<extension
@@ -297,6 +314,16 @@
</contenttypeidentifier>
</hyperlink>
+ <!-- JBIDE-4002 <bpm:process-definitions> and <bpm:pageflow-definitions>
in components.xml -->
+ <!-- JBIDE-3901 <drools:rule-files> in components.xml -->
+ <hyperlink
+ class="org.jboss.tools.seam.text.ext.hyperlink.ComponentsHyperlink"
+ id="org.jboss.tools.seam.text.ext.hyperlink.ComponentsHyperlink">
+ <contenttypeidentifier
id="org.jboss.tools.common.model.ui.xml">
+ <partitiontype id="org.jboss.tools.seam.text.ext.BPM_DEFINITION" />
+ <partitiontype id="org.jboss.tools.seam.text.ext.DROOLS_RULE_DEFINITION"
/>
+ </contenttypeidentifier>
+ </hyperlink>
</extension>
<extension
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java 2009-03-20
12:24:37 UTC (rev 14280)
@@ -0,0 +1,125 @@
+/*******************************************************************************
+ * 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.seam.text.ext.hyperlink;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+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.jst.j2ee.componentcore.util.EARVirtualComponent;
+import org.eclipse.wst.common.componentcore.ComponentCore;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.seam.text.ext.SeamExtPlugin;
+import org.w3c.dom.Node;
+
+public class ComponentsHyperlink extends AbstractHyperlink {
+ private String hyperlinkText = "";
+ private static final String folder = "EarContent/";
+
+ private String partitionType = null;
+
+ @Override
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ Node node = ComponentsHyperlinkPartitioner.getNode(getDocument(),
+ offset);
+ partitionType = ComponentsHyperlinkPartitioner.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) {
+ SeamExtPlugin.getPluginLog().logError(ex);
+ }
+
+ if (partitionType == ComponentsHyperlinkPartitioner.BPM_DEFINITION_PARTITION)
+ doBpmDefinitionHyperlink(region);
+ else if (partitionType == ComponentsHyperlinkPartitioner.DROOLS_RULE_PARTITION)
+ doDroolsRuleHyperlink(region);
+
+ }
+
+ private void doDroolsRuleHyperlink(IRegion region) {
+ IProject project = getProject();
+ IResource[] sources = EclipseResourceUtil.getJavaSourceRoots(project);
+
+ for (IResource resource : sources) {
+ String path = resource.getFullPath().removeFirstSegments(1)
+ + hyperlinkText;
+ IFile file = project.getFile(path);
+ if (file.exists()) {
+ openFileInEditor(file);
+ return;
+ }
+ }
+ }
+
+ private void doBpmDefinitionHyperlink(IRegion region) {
+ IProject earProject = getEarProject();
+ if (earProject == null)
+ return;
+
+ IFile file = earProject.getFile(folder + hyperlinkText);
+ if (file != null)
+ openFileInEditor(file);
+ }
+
+ private IProject getEarProject() {
+ IVirtualComponent component = ComponentCore
+ .createComponent(getProject());
+ IVirtualComponent[] vComponents = component.getReferencingComponents();
+ for (IVirtualComponent vc : vComponents) {
+ if (vc instanceof EARVirtualComponent) {
+ return ((EARVirtualComponent) vc).getProject();
+ }
+ }
+ return null;
+ }
+
+ 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/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlink.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java 2009-03-20
12:24:37 UTC (rev 14280)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.seam.text.ext.hyperlink;
+
+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;
+
+@SuppressWarnings("restriction")
+public class ComponentsHyperlinkPartitioner extends
+ AbstractHyperlinkPartitioner {
+ public static final String BPM_DEFINITION_PARTITION =
"org.jboss.tools.seam.text.ext.BPM_DEFINITION";
+ public static final String DROOLS_RULE_PARTITION =
"org.jboss.tools.seam.text.ext.DROOLS_RULE_DEFINITION";
+
+ static final String textNodeName = "#text";
+ static final String valueNodeName = "value";
+
+ static final String processDefinitionsNodeName = "bpm:process-definitions";
+ static final String pageflowDefinitionsNodeName = "bpm:pageflow-definitions";
+
+ static final String droolsRuleFileNodeName = "drools:rule-files";
+
+ 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 valueNode = node.getParentNode(); // value node
+ if (valueNode == null)
+ return null;
+
+ Node parentNode = valueNode.getParentNode(); // parent node
+ if (parentNode == null)
+ return null;
+
+ if (node.getNodeName().equalsIgnoreCase(textNodeName)
+ && valueNode.getNodeName().equalsIgnoreCase(valueNodeName)) {
+ if (parentNode.getNodeName().equalsIgnoreCase(
+ processDefinitionsNodeName)
+ || parentNode.getNodeName().equalsIgnoreCase(
+ pageflowDefinitionsNodeName)) {
+ return BPM_DEFINITION_PARTITION;
+ } else if (parentNode.getNodeName().equalsIgnoreCase(
+ droolsRuleFileNodeName)) {
+ return DROOLS_RULE_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/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/ComponentsHyperlinkPartitioner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain