Author: vrubezhny
Date: 2008-11-28 12:58:16 -0500 (Fri, 28 Nov 2008)
New Revision: 12138
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
Log:
JBIDE-1975 OpenOn for #{messages.***} in Seam EL.
Issue is fixed for Seam EL in Java-Strings
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.java 2008-11-28
17:55:49 UTC (rev 12137)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.java 2008-11-28
17:58:16 UTC (rev 12138)
@@ -12,7 +12,9 @@
package org.jboss.tools.seam.text.ext.hyperlink;
import java.text.MessageFormat;
+import java.util.Map;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.JavaModelException;
@@ -21,14 +23,18 @@
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PartInitException;
+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.xpl.Messages;
+import org.jboss.tools.seam.internal.core.SeamMessagesComponent;
import org.jboss.tools.seam.text.ext.SeamExtPlugin;
public class SeamELInJavaStringHyperlink implements IHyperlink {
private final IRegion fRegion;
private final IJavaElement[] fElements;
-
+ private final Map<String, SeamMessagesComponent> fMessages;
/**
* Creates a new Seam EL in Java string hyperlink.
*/
@@ -38,8 +44,21 @@
fRegion = region;
fElements = elements;
+ fMessages = null;
}
+ /**
+ * Creates a new Seam EL in Java string hyperlink for messages.
+ */
+ SeamELInJavaStringHyperlink(IRegion region, Map<String, SeamMessagesComponent>
messages) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(messages);
+
+ fRegion = region;
+ fElements = null;
+ fMessages = messages;
+ }
+
/*
* @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkRegion()
* @since 3.1
@@ -53,24 +72,62 @@
* @since 3.1
*/
public void open() {
- try {
- IEditorPart part = null;
- for (int i = 0; fElements != null && i < fElements.length; i++) {
- part = JavaUI.openInEditor(fElements[i]);
- if (part != null) {
- if (fElements[i] != null)
- JavaUI.revealInEditor(part, fElements[i]);
- break;
- }
+ if (fMessages != null && fElements == null) {
+ openMessages();
+ } else if (fElements != null && fMessages == null) {
+ try {
+ IEditorPart part = null;
+ for (int i = 0; fElements != null && i < fElements.length; i++) {
+ part = JavaUI.openInEditor(fElements[i]);
+ if (part != null) {
+ if (fElements[i] != null)
+ JavaUI.revealInEditor(part, fElements[i]);
+ break;
+ }
+ }
+
+ } catch (PartInitException e) {
+ SeamExtPlugin.getPluginLog().logError(e);
+ } catch (JavaModelException e) {
+ // Ignore. It is probably because of Java element is not found
}
+ }
+ }
+
+ private void openMessages() {
+ Map <String, SeamMessagesComponent> messages = fMessages;
+ if (messages == null || messages.size() == 0) {
+ // Nothing to open
+ return;
+ }
- } catch (PartInitException e) {
- SeamExtPlugin.getPluginLog().logError(e);
- } catch (JavaModelException e) {
- // Ignore. It is probably because of Java element is not found
+ 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
+
}
-
+
/*
* @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
* @since 3.1
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-11-28
17:55:49 UTC (rev 12137)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-11-28
17:58:16 UTC (rev 12138)
@@ -11,7 +11,10 @@
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;
@@ -30,9 +33,20 @@
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.ui.texteditor.ITextEditor;
+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.ELInvocationExpression;
+import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
+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;
public class SeamELInJavaStringHyperlinkDetector extends
@@ -86,6 +100,10 @@
if(range == null) range = new int[]{0, document.getLength()};
+ Map<String, SeamMessagesComponent> messages = findMessagesComponents(document,
file, wordRegion, range[0], range[1]);
+ if (messages != null && messages.size() > 0)
+ return new IHyperlink[] {new SeamELInJavaStringHyperlink(wordRegion, messages)};
+
IJavaElement[] elements = findJavaElements(document, file, wordRegion, range[0],
range[1]);
if (elements != null && elements.length > 0)
return new IHyperlink[] {new SeamELInJavaStringHyperlink(wordRegion, elements)};
@@ -119,7 +137,110 @@
return javaElements == null ? new IJavaElement[0] : javaElements.toArray(new
IJavaElement[0]);
}
+
+ public static Map<String, SeamMessagesComponent> findMessagesComponents(IDocument
document, IFile file, IRegion region, int start, int end) {
+ 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= engine.getJavaElementExpression(document, region.getOffset(), region,
start, end);
+ prefix = (prefix == null ? "" : prefix);
+
+ 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(region.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;
+
+
+ }
+
/*
* Checks if the EL start starting characters are present
* @param viewer