Author: vrubezhny
Date: 2008-11-28 12:13:25 -0500 (Fri, 28 Nov 2008)
New Revision: 12135
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamMessagesBeanHyperlink.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
Log:
JBIDE-1975 OpenOn for #{messages.***} in Seam EL.
Issue is fixed
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2008-11-28 17:11:00 UTC
(rev 12134)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2008-11-28 17:13:25 UTC
(rev 12135)
@@ -230,6 +230,41 @@
<partitiontype id="org.jboss.tools.seam.text.ext.SEAM_BEAN" />
</contenttypeidentifier>
</hyperlink>
+
+ <hyperlink
+ class="org.jboss.tools.seam.text.ext.hyperlink.SeamMessagesBeanHyperlink"
+ id="org.jboss.tools.seam.text.ext.hyperlink.SeamBeanHyperlink">
+ <contenttypeidentifier id="org.eclipse.jst.jsp.core.jspsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.eclipse.wst.html.core.htmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.eclipse.core.runtime.xml">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier id="org.jboss.tools.common.model.ui.xml">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages12xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page12xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages20xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page20xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.pages21xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ <contenttypeidentifier
id="org.jboss.tools.seam.xml.ui.page21xmlsource">
+ <partitiontype id="org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN"
/>
+ </contenttypeidentifier>
+ </hyperlink>
<hyperlink
class="org.jboss.tools.seam.text.ext.hyperlink.SeamViewHyperlink"
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-11-28
17:11:00 UTC (rev 12134)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-11-28
17:13:25 UTC (rev 12135)
@@ -10,17 +10,31 @@
******************************************************************************/
package org.jboss.tools.seam.text.ext.hyperlink;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IJavaElement;
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.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.jboss.tools.common.el.core.model.ELArgumentInvocation;
import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.model.ELObjectType;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
@@ -29,11 +43,18 @@
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.hyperlink.jsp.JSPRootHyperlinkPartitioner;
+import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
import org.jboss.tools.common.text.ext.util.StructuredModelWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
+import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.SeamMessagesComponent;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.internal.core.el.SeamExpressionResolver;
import org.jboss.tools.seam.text.ext.SeamExtPlugin;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -45,7 +66,10 @@
*/
public class SeamBeanHyperlinkPartitioner extends AbstractHyperlinkPartitioner implements
IHyperlinkPartitionRecognizer, IHyperLinkPartitionPriority {
public static final String SEAM_BEAN_PARTITION =
"org.jboss.tools.seam.text.ext.SEAM_BEAN";
+ public static final String SEAM_MESSAGES_BEAN_PARTITION =
"org.jboss.tools.seam.text.ext.SEAM_MESSAGES_BEAN";
+ private ELParserFactory factory = ELParserUtil.getJbossFactory();
+
/**
* @see
com.ibm.sse.editor.hyperlink.AbstractHyperlinkPartitioner#parse(org.eclipse.jface.text.IDocument,
com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
*/
@@ -62,19 +86,40 @@
if (r == null) return null;
r = getWordRegion(document, superRegion.getOffset());
if (r == null) return null;
+
+ Map<String, SeamMessagesComponent> messages = findMessagesComponents(document,
superRegion);
- String axis = getAxis(document, superRegion);
- String contentType = superRegion.getContentType();
- String type = SEAM_BEAN_PARTITION;
- int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
- int offset = superRegion.getOffset();
+ if (messages != null && messages.size() > 0) {
+ String axis = getAxis(document, superRegion);
+ String contentType = superRegion.getContentType();
+ String type = SEAM_MESSAGES_BEAN_PARTITION;
+
+ int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
+ int offset = superRegion.getOffset();
+
+ IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
+ return region;
+ }
- IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
- return region;
+ List<IJavaElement> javaElements = findJavaElements(document, superRegion);
+ if (javaElements != null && javaElements.size() > 0) {///
+ String axis = getAxis(document, superRegion);
+ String contentType = superRegion.getContentType();
+ String type = SEAM_BEAN_PARTITION;
+ int length = r.getLength() - (superRegion.getOffset() - r.getOffset());
+ int offset = superRegion.getOffset();
+
+ IHyperlinkRegion region = new HyperlinkRegion(offset, length, axis, contentType,
type);
+ return region;
+ }
+
+ return null;
} finally {
smw.dispose();
}
}
+
+
protected String getAxis(IDocument document, IHyperlinkRegion superRegion) {
if (superRegion.getAxis() == null || superRegion.getAxis().length() == 0) {
@@ -233,9 +278,17 @@
Utils.findNodeForOffset(xmlDocument, region.getOffset());
+ Map<String, SeamMessagesComponent> messages = findMessagesComponents(document,
region);
+ if (messages != null && messages.size() > 0) {
+ return true;
+ }
+
List<IJavaElement> javaElements = findJavaElements(document, region);
-
- return (javaElements != null && javaElements.size() > 0);
+ if (javaElements != null || javaElements.size() > 0) {
+ return true;
+ }
+
+ return false;
} finally {
smw.dispose();
}
@@ -329,6 +382,186 @@
}
}
+ public static Map<String, SeamMessagesComponent> findMessagesComponents(IDocument
document, IRegion region) {
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ try {
+ smw.init(document);
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ IHyperlinkRegion r = getRegion(document, region.getOffset());
+ if (r == null) return null;
+
+ String propText = document.get(r.getOffset(), r.getLength());
+
+
+ IFile file = smw.getFile();
+ IProject project = (file == null ? null : file.getProject());
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject == null)
+ return null;
+
+ SeamELCompletionEngine engine= new SeamELCompletionEngine(seamProject);
+
+ String prefix = propText;
+ ELExpression exp = engine.parseOperand(prefix);
+ if (exp == null)
+ return null; // No EL Operand found
+
+ Map<ELInvocationExpression, List<ISeamContextVariable>> map = new
HashMap<ELInvocationExpression, List<ISeamContextVariable>>();
+
+ exp.getModel().shift(r.getOffset() - exp.getFirstToken().getStart());
+
+ if ( !(exp instanceof ELInvocationExpression) &&
+ !(exp instanceof ELPropertyInvocation) &&
+ !(exp instanceof ELArgumentInvocation))
+ return null;
+
+ String propertyName = null;
+ if (exp instanceof ELPropertyInvocation) {
+ propertyName = ((ELPropertyInvocation)exp).getMemberName();
+ } else if (exp instanceof ELArgumentInvocation) {
+ propertyName = Utils.trimQuotes(
+ ((ELArgumentInvocation)exp).getArgument().getArgument().getText());
+
+ }
+
+ if (propertyName == null)
+ return null;
+
+ ScopeType scope = SeamELCompletionEngine.getScope(seamProject, file);
+
+ ELInvocationExpression expr = (ELInvocationExpression)exp;
+
+ ELInvocationExpression left = expr;
+
+ if (expr.getLeft() != null) {
+ while (left != null) {
+ List<ISeamContextVariable> resolvedVars = new
ArrayList<ISeamContextVariable>();
+ resolvedVars = engine.resolveVariables(scope, left,
+ left == expr, true);
+ if (resolvedVars != null && !resolvedVars.isEmpty()) {
+ map.put(left, resolvedVars);
+ break;
+ }
+ left = (ELInvocationExpression) left.getLeft();
+ }
+ }
+
+
+ // At the moment map contains the resolved EL parts mapped to their vars
+ // And now we need to extract SeamXmlFactory vars to the real ones
+ // and filter out all non-SeamMessagesComponent vars
+ // Next we need to map the SeamMessagesComponent vars to properties
+ Map<String, SeamMessagesComponent> messages = new HashMap<String,
SeamMessagesComponent>();
+ if (map != null && !map.isEmpty()) {
+ for (ELInvocationExpression l : map.keySet()) {
+ List<ISeamContextVariable> variables = map.get(l);
+ for (ISeamContextVariable variable : variables) {
+ if (variable instanceof SeamMessagesComponent) {
+ messages.put(propertyName, (SeamMessagesComponent)variable);
+ } else if (variable instanceof ISeamXmlFactory) {
+ ISeamXmlFactory factory = (ISeamXmlFactory)variable;
+ String value = factory.getValue();
+ if (value != null && value.length() > 0) {
+ if (value.startsWith("#{") || value.startsWith("${"))
//$NON-NLS-1$ //$NON-NLS-2$
+ value = value.substring(2);
+ if (value.endsWith("}")) //$NON-NLS-1$
+ value = value.substring(0, value.length() - 1);
+ }
+ if (value != null && value.length() > 0) {
+ // TODO: Need to make sure that it's correct way to get the project and
+ // the scope from the factory
+ ISeamProject p = ((ISeamElement)factory).getSeamProject();
+ if (p != null) {
+ List<ISeamContextVariable> resolvedValues =
SeamExpressionResolver.resolveVariables(p, null, value, true);
+ for (ISeamContextVariable var : resolvedValues) {
+ if (var.getName().equals(value)) {
+ if (var instanceof SeamMessagesComponent) {
+ messages.put(propertyName,(SeamMessagesComponent)var);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ return messages;
+ } catch (BadLocationException x) {
+ SeamExtPlugin.getPluginLog().logError(x);
+ return null;
+ } finally {
+ smw.dispose();
+ }
+ }
+
+ public static IHyperlinkRegion getMessagesPropertyRegion(IDocument document, int offset)
{
+ StructuredModelWrapper smw = new StructuredModelWrapper();
+ try {
+ smw.init(document);
+ Document xmlDocument = smw.getDocument();
+ if (xmlDocument == null) return null;
+
+ IHyperlinkRegion r = getRegion(document, offset);
+ if (r == null) return null;
+
+ String propText = document.get(r.getOffset(), r.getLength());
+
+ IFile file = smw.getFile();
+ IProject project = (file == null ? null : file.getProject());
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject == null)
+ return null;
+
+ SeamELCompletionEngine engine= new SeamELCompletionEngine(seamProject);
+
+ String prefix = propText;
+ ELExpression exp = engine.parseOperand(prefix);
+ if (exp == null)
+ return null; // No EL Operand found
+
+ Map<ELInvocationExpression, List<ISeamContextVariable>> map = new
HashMap<ELInvocationExpression, List<ISeamContextVariable>>();
+
+ exp.getModel().shift(r.getOffset() - exp.getFirstToken().getStart());
+
+ if ( !(exp instanceof ELInvocationExpression) &&
+ !(exp instanceof ELPropertyInvocation) &&
+ !(exp instanceof ELArgumentInvocation))
+ return null;
+
+ String propertyName = null;
+ if (exp instanceof ELPropertyInvocation) {
+ propertyName = ((ELPropertyInvocation)exp).getMemberName();
+
+ int start = ((ELPropertyInvocation)exp).getLastToken().getStart();
+ int length = ((ELPropertyInvocation)exp).getLastToken().getLength();
+
+ return new HyperlinkRegion(start, length);
+ } else if (exp instanceof ELArgumentInvocation) {
+ propertyName = Utils.trimQuotes(
+ ((ELArgumentInvocation)exp).getArgument().getArgument().getText());
+ int start =
((ELArgumentInvocation)exp).getArgument().getArgument().getStartPosition();
+ int length = ((ELArgumentInvocation)exp).getArgument().getArgument().getEndPosition()
-
+ ((ELArgumentInvocation)exp).getArgument().getArgument().getStartPosition();
+
+ return new HyperlinkRegion(start, length);
+ }
+
+ return null;
+ } catch (BadLocationException x) {
+ SeamExtPlugin.getPluginLog().logError(x);
+ return null;
+ } finally {
+ smw.dispose();
+ }
+ }
+
public int getPriority() {
return 0; // to be first
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamMessagesBeanHyperlink.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamMessagesBeanHyperlink.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamMessagesBeanHyperlink.java 2008-11-28
17:13:25 UTC (rev 12135)
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 java.text.MessageFormat;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.ui.IEditorPart;
+import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.model.util.FindObjectHelper;
+import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
+import org.jboss.tools.common.text.ext.hyperlink.xpl.Messages;
+import org.jboss.tools.seam.internal.core.SeamMessagesComponent;
+
+/**
+ * @author Jeremy
+ */
+
+public class SeamMessagesBeanHyperlink extends AbstractHyperlink {
+
+ /**
+ * @see
com.ibm.sse.editor.AbstractHyperlink#doHyperlink(org.eclipse.jface.text.IRegion)
+ */
+ protected void doHyperlink(IRegion region) {
+ Map <String, SeamMessagesComponent> messages =
SeamBeanHyperlinkPartitioner.findMessagesComponents(getDocument(), region);
+ if (messages == null || messages.size() == 0) {
+ // Nothing to open
+ openFileFailed();
+ return;
+ }
+
+ for (String property : messages.keySet()) {
+ SeamMessagesComponent messagesComponent = messages.get(property);
+ Map <String, IResource> resources = messagesComponent.getResourcesMap();
+ if (resources == null || resources.size() == 0)
+ continue;
+
+ for (String bundle : resources.keySet()) {
+ IResource resource = resources.get(bundle);
+ XModelObject xmo = EclipseResourceUtil.getObjectByResource(resource);
+ if (xmo == null)
+ continue;
+
+ XModelObject xmoChild = xmo.getChildByPath(property);
+ if (xmoChild == null)
+ continue;
+
+ int result = FindObjectHelper.findModelObject(xmoChild,
FindObjectHelper.IN_EDITOR_ONLY);
+ if (result == 0) {
+ // Success
+ return;
+ }
+ }
+ }
+ // could not open editor
+ openFileFailed();
+ }
+
+ IRegion fLastRegion = null;
+ /**
+ * @see com.ibm.sse.editor.AbstractHyperlink#doGetHyperlinkRegion(int)
+ */
+ protected IRegion doGetHyperlinkRegion(int offset) {
+ fLastRegion = SeamBeanHyperlinkPartitioner.getMessagesPropertyRegion(getDocument(),
offset);
+ return fLastRegion;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see IHyperlink#getHyperlinkText()
+ */
+ public String getHyperlinkText() {
+
+ String beanName;
+ try {
+ beanName = getDocument().get(fLastRegion.getOffset(), fLastRegion.getLength());
+ } catch (BadLocationException e) {
+ beanName = null;
+ }
+
+ if (beanName == null)
+ return MessageFormat.format(Messages.NotFound, Messages.Bean);
+
+ return MessageFormat.format(Messages.OpenBean, beanName);
+ }
+}
\ No newline at end of file