Author: vrubezhny
Date: 2007-10-08 14:30:55 -0400 (Mon, 08 Oct 2007)
New Revision: 4067
Added:
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
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.properties
trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
Log:
http://jira.jboss.org/jira/browse/JBIDE-1038 Ctrl click navigation for #{} EL expressions
in Java Strings
Seam EL hyperlink and detector are added for Java strings
Detector registration is done over plugin.xml
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.properties
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.properties 2007-10-08 16:55:53
UTC (rev 4066)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.properties 2007-10-08 18:30:55
UTC (rev 4067)
@@ -1 +1,2 @@
providerName=Red Hat, Inc.
+SeamELInJavaStringHyperlinkDetector= Seam EL in Java String
\ No newline at end of file
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2007-10-08 16:55:53 UTC
(rev 4066)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/plugin.xml 2007-10-08 18:30:55 UTC
(rev 4067)
@@ -61,4 +61,14 @@
</hyperlink>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+
class="org.jboss.tools.seam.text.ext.hyperlink.SeamELInJavaStringHyperlinkDetector"
+
id="org.jboss.tools.seam.text.ext.hyperlink.SeamELInJavaStringHyperlinkDetector"
+ name="%SeamELInJavaStringHyperlinkDetector"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+ </extension>
+
</plugin>
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.java 2007-10-08
18:30:55 UTC (rev 4067)
@@ -0,0 +1,86 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.seam.text.ext.hyperlink;
+
+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.text.ext.SeamExtPlugin;
+
+public class SeamELInJavaStringHyperlink implements IHyperlink {
+
+ private final IRegion fRegion;
+ private final IJavaElement[] fElements;
+
+ /**
+ * Creates a new Seam EL in Java string hyperlink.
+ */
+ SeamELInJavaStringHyperlink(IRegion region, IJavaElement[] elements) {
+ Assert.isNotNull(region);
+ Assert.isNotNull(elements);
+
+ fRegion = region;
+ fElements = elements;
+ }
+
+ /*
+ * @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() {
+ 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
+ }
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getTypeLabel()
+ * @since 3.1
+ */
+ public String getTypeLabel() {
+ return null;
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.IHyperlink#getHyperlinkText()
+ * @since 3.1
+ */
+ public String getHyperlinkText() {
+ return null;
+ }
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlink.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/SeamELInJavaStringHyperlinkDetector.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2007-10-08
18:30:55 UTC (rev 4067)
@@ -0,0 +1,138 @@
+/*******************************************************************************
+ * Copyright (c) 2007 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.seam.text.ext.hyperlink;
+
+import java.util.List;
+
+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.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlink;
+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.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
+import org.jboss.tools.seam.text.ext.SeamExtPlugin;
+
+public class SeamELInJavaStringHyperlinkDetector extends
+ AbstractHyperlinkDetector {
+
+ 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;
+
+ IDocument document=
textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IRegion wordRegion = JavaWordFinder.findWord(document, offset);
+
+ if (wordRegion == null)
+ return null;
+
+ if (!checkStartPosition(document, offset))
+ 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
+ }
+
+ IJavaElement[] elements = findJavaElements(document, file, wordRegion);
+ if (elements != null && elements.length > 0)
+ return new IHyperlink[] {new SeamELInJavaStringHyperlink(wordRegion, elements)};
+
+ return null;
+ }
+
+ public static IJavaElement[] findJavaElements(IDocument document, IFile file, IRegion
region) {
+
+ IProject project = (file == null ? null : file.getProject());
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject == null)
+ return null;
+
+ SeamELCompletionEngine engine= new SeamELCompletionEngine();
+
+ String prefix= engine.getJavaElementExpression(document.get(), region.getOffset(),
region);
+ prefix = (prefix == null ? "" : prefix);
+
+ List<IJavaElement> javaElements = null;
+
+ try {
+ javaElements = engine.getJavaElementsForExpression(
+ seamProject, file, prefix);
+ } catch (StringIndexOutOfBoundsException e) {
+ SeamExtPlugin.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ SeamExtPlugin.getPluginLog().logError(e);
+ }
+
+ return javaElements == null ? new IJavaElement[0] : javaElements.toArray(new
IJavaElement[0]);
+ }
+
+ /*
+ * Checks if the EL start starting characters are present
+ * @param viewer
+ * @param offset
+ * @return
+ * @throws BadLocationException
+ */
+ private boolean checkStartPosition(IDocument document, int offset) {
+ try {
+ while (--offset >= 0) {
+ if ('}' == document.getChar(offset))
+ return false;
+
+
+ if ('"' == document.getChar(offset) &&
+ (offset - 1) >= 0 && '\\' != document.getChar(offset - 1)) {
+ return false;
+ }
+
+
+ if ('{' == document.getChar(offset) &&
+ (offset - 1) >= 0 &&
+ ('#' == document.getChar(offset - 1) ||
+ '$' == document.getChar(offset - 1))) {
+ return true;
+ }
+ }
+ } catch (BadLocationException e) {
+ SeamExtPlugin.getPluginLog().logError(e);
+ }
+ return false;
+ }
+
+}
Property changes on:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain