Author: vrubezhny
Date: 2009-04-30 13:42:05 -0400 (Thu, 30 Apr 2009)
New Revision: 14984
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/Messages.properties
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/SeamExtMessages.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlink.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlinkDetector.java
Log:
JBIDE-4068 Add option (Open On) to open the correspondent Seam component when we have a
@In annotation in a field and click on the field name .
- New open-on is added for the members annotated by @In annotation
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/Messages.properties
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/Messages.properties
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/Messages.properties 2009-04-30
17:42:05 UTC (rev 14984)
@@ -0,0 +1,5 @@
+OpenAs=Open ''{0}'' as {1}
+SeamComponent=Component
+SeamRole=Role
+SeamFactory=Factory
+SeamBijected=Bijected Attribute
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/Messages.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/SeamExtMessages.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/SeamExtMessages.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/SeamExtMessages.java 2009-04-30
17:42:05 UTC (rev 14984)
@@ -0,0 +1,22 @@
+package org.jboss.tools.seam.text.ext;
+
+import org.eclipse.osgi.util.NLS;
+
+public class SeamExtMessages extends NLS {
+ private static final String BUNDLE_NAME =
"org.jboss.tools.seam.text.ext.Messages"; //$NON-NLS-1$
+
+ public static String OpenAs;
+ public static String SeamComponent;
+ public static String SeamRole;
+ public static String SeamFactory;
+ public static String SeamBijected;
+
+ //
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, SeamExtMessages.class);
+ }
+
+ private SeamExtMessages() {
+ }
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/SeamExtMessages.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/SeamComponentHyperlink.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlink.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlink.java 2009-04-30
17:42:05 UTC (rev 14984)
@@ -0,0 +1,157 @@
+package org.jboss.tools.seam.text.ext.hyperlink;
+
+import java.text.MessageFormat;
+import java.util.Set;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
+import org.jboss.tools.seam.text.ext.SeamExtMessages;
+import org.jboss.tools.seam.text.ext.SeamExtPlugin;
+
+public class SeamComponentHyperlink implements IHyperlink {
+
+ private IRegion fRegion;
+ private IJavaElement fElement;
+ private IOpenableElement fOpenable;
+ private String fLabel;
+ private String fName;
+
+ /**
+ * Creates a new Seam Component hyperlink.
+ */
+ SeamComponentHyperlink(IRegion region, IJavaElement element, String name) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(element);
+ Assert.isNotNull(name);
+
+ fRegion = region;
+ fElement = element;
+ fOpenable = null;
+ fLabel = SeamExtMessages.SeamFactory;
+ fName = name;
+ }
+
+ /**
+ * Creates a new Seam Component hyperlink.
+ */
+ SeamComponentHyperlink(IRegion region, ISeamComponent element, String name) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(element);
+ Assert.isNotNull(name);
+
+ fRegion = region;
+ fElement = null;
+ fLabel = SeamExtMessages.SeamComponent;
+ fName = name;
+ fOpenable = null;
+
+ ISeamJavaComponentDeclaration javaDeclaration = element.getJavaDeclaration();
+ if (javaDeclaration != null && javaDeclaration instanceof IOpenableElement) {
+ fOpenable = (IOpenableElement)javaDeclaration;
+ } else {
+ Set<ISeamComponentDeclaration> declarations = element.getAllDeclarations();
+ for (ISeamComponentDeclaration componentDeclaration : declarations) {
+ if (componentDeclaration instanceof IOpenableElement) {
+ fOpenable = (IOpenableElement)componentDeclaration;
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Creates a new Seam Component hyperlink.
+ */
+ SeamComponentHyperlink(IRegion region, IBijectedAttribute element, String name) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(element);
+ Assert.isNotNull(name);
+
+ fRegion = region;
+ fElement = element.getSourceMember();
+ fLabel = SeamExtMessages.SeamBijected;
+ fName = name;
+ fOpenable = null;
+ }
+
+ /**
+ * Creates a new Seam Component hyperlink.
+ */
+ SeamComponentHyperlink(IRegion region, IRole element, String name) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(element);
+ Assert.isTrue(element instanceof IOpenableElement);
+ Assert.isNotNull(name);
+
+ fRegion = region;
+ fElement = null;
+ fOpenable = (IOpenableElement)element;
+ fLabel = SeamExtMessages.SeamRole;
+ fName = name;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkRegion()
+ * @since 3.1
+ */
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#open()
+ * @since 3.1
+ */
+ public void open() {
+
+ if (fOpenable != null) {
+ fOpenable.open();
+ return;
+ }
+
+ if (fElement != null) {
+ try {
+ IEditorPart part = null;
+ part = JavaUI.openInEditor(fElement);
+ if (part != null) {
+ JavaUI.revealInEditor(part, fElement);
+ }
+ } catch (PartInitException e) {
+ SeamExtPlugin.getPluginLog().logError(e);
+ } catch (JavaModelException e) {
+ // Ignore. It is probably because of Java element is not found
+ }
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
+ * @since 3.1
+ */
+ public String getTypeLabel() {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see IHyperlink#getHyperlinkText()
+ */
+ public String getHyperlinkText() {
+ return MessageFormat.format(SeamExtMessages.OpenAs, fName, fLabel);
+ }
+
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlink.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/SeamComponentHyperlinkDetector.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlinkDetector.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlinkDetector.java 2009-04-30
17:42:05 UTC (rev 14984)
@@ -0,0 +1,186 @@
+package org.jboss.tools.seam.text.ext.hyperlink;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IAnnotatable;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICodeAssist;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMemberValuePair;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.common.text.ext.hyperlink.HyperlinkBuilder;
+import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamMessages;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.internal.core.scanner.ScannerException;
+import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
+import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+import org.jboss.tools.seam.text.ext.SeamExtPlugin;
+
+
+public class SeamComponentHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ /*
+ * If the hyperlink is performed on the field name that is annotated as @In then
+ * the hyperlink will open a correspondent Seam component
+ *
+ * (non-Javadoc)
+ * @see
org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer,
org.eclipse.jface.text.IRegion, boolean)
+ */
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean
canShowMultipleHyperlinks) {
+ ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
+ if (region == null ||
+// canShowMultipleHyperlinks ||
+ !(textEditor instanceof JavaEditor))
+ return null;
+
+ int offset= region.getOffset();
+
+ IJavaElement input= EditorUtility.getEditorInputJavaElement(textEditor, false);
+ if (input == null)
+ return null;
+
+ if (input.getResource() == null || input.getResource().getProject() == null)
+ return null;
+
+ ISeamProject seamProject =
SeamCorePlugin.getSeamProject(input.getResource().getProject(), true);
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
+
+ IDocument document=
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IRegion wordRegion= JavaWordFinder.findWord(document, offset);
+ if (wordRegion == null)
+ return null;
+
+ IFile file = null;
+
+ try {
+ IResource resource = input.getCorrespondingResource();
+ if (resource instanceof IFile)
+ file = (IFile) resource;
+ } catch (JavaModelException e) {
+ // Ignore. It is probably because of Java element's resource is not found
+ }
+
+ int[] range = new int[]{wordRegion.getOffset(), wordRegion.getOffset() +
wordRegion.getLength()};
+
+ IJavaElement[] elements = null;
+
+ try {
+ elements = ((ICodeAssist)input).codeSelect(wordRegion.getOffset(),
wordRegion.getLength());
+ if (elements == null)
+ return null;
+
+ ArrayList<IHyperlink> hyperlinks = new ArrayList<IHyperlink>();
+ for (IJavaElement element : elements) {
+ if (element instanceof IAnnotatable) {
+ IAnnotatable annotatable = (IAnnotatable)element;
+
+ IAnnotation annotation = annotatable.getAnnotation("In");
+ if (annotation == null)
+ continue;
+
+ String nameToSearch = element.getElementName();
+
+ IMemberValuePair[] mvPairs = annotation.getMemberValuePairs();
+ if (mvPairs != null) {
+ for (IMemberValuePair mvPair : mvPairs) {
+ if ("value".equals(mvPair.getMemberName()) && mvPair.getValue()
!= null) {
+ String name = mvPair.getValue().toString();
+ if (name != null && name.trim().length() != 0) {
+ nameToSearch = name;
+ break;
+ }
+ }
+ }
+ }
+
+
+ if (nameToSearch == null && nameToSearch.trim().length() == 0)
+ continue;
+
+ Set<ISeamContextVariable> vars = seamProject.getVariables(true);
+ if (vars != null) {
+ for (ISeamContextVariable var : vars) {
+ if (nameToSearch.equals(var.getName())){
+ while (var instanceof ISeamContextShortVariable) {
+ var = ((ISeamContextShortVariable)var).getOriginal();
+ }
+ if (var == null)
+ continue;
+
+ if (var instanceof ISeamXmlFactory) {
+ ISeamXmlFactory xmlFactory = (ISeamXmlFactory)var;
+
+ String value = xmlFactory.getValue();
+ if (value == null || value.trim().length() == 0) {
+ value = xmlFactory.getMethod();
+ }
+
+ if (value == null || value.trim().length() == 0)
+ continue;
+
+ List<IJavaElement> javaElements = null;
+
+ try {
+ javaElements = engine.getJavaElementsForExpression(
+ seamProject, file, value);
+ } catch (StringIndexOutOfBoundsException e) {
+ } catch (BadLocationException e) {
+ }
+ if (javaElements != null) {
+ for (IJavaElement javaElement : javaElements) {
+ hyperlinks.add(new SeamComponentHyperlink(wordRegion, javaElement,
nameToSearch));
+ }
+ }
+ } else if (var instanceof ISeamComponent) {
+ hyperlinks.add(new SeamComponentHyperlink(wordRegion, (ISeamComponent)var,
nameToSearch));
+ } else if (var instanceof IRole) {
+ hyperlinks.add(new SeamComponentHyperlink(wordRegion, (IRole)var,
nameToSearch));
+ } else if (var instanceof IBijectedAttribute) {
+ IBijectedAttribute attr = (IBijectedAttribute)var;
+ if (attr.getSourceMember() != null) {
+ hyperlinks.add(new SeamComponentHyperlink(wordRegion, (IBijectedAttribute)var,
nameToSearch));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (hyperlinks != null && hyperlinks.size() > 0) {
+ return (IHyperlink[])hyperlinks.toArray(new IHyperlink[hyperlinks.size()]);
+ }
+ } catch (JavaModelException jme) {
+ // ignore
+ }
+ return null;
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamComponentHyperlinkDetector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Show replies by date