Skip to main content
summaryrefslogtreecommitdiffstats
path: root/jpa
diff options
context:
space:
mode:
authorPaul Fullbright2012-08-02 18:39:59 +0000
committerPaul Fullbright2012-08-02 18:39:59 +0000
commitf0eedeec8d680bd4287ad6d5029a744d306bab80 (patch)
treebb4bf86099d0566b978b5166208e505c4dcf18fd /jpa
parentff28b0e964b50b836670bddfd936f5069249ef57 (diff)
downloadwebtools.dali-f0eedeec8d680bd4287ad6d5029a744d306bab80.tar.gz
webtools.dali-f0eedeec8d680bd4287ad6d5029a744d306bab80.tar.xz
webtools.dali-f0eedeec8d680bd4287ad6d5029a744d306bab80.zip
Pascal's JPQL changes
Diffstat (limited to 'jpa')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkBuilder.java318
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkDetector.java46
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java58
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkBuilder.java417
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkDetector.java97
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenDeclarationHyperlink.java107
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenMemberDeclarationHyperlink.java111
11 files changed, 1158 insertions, 28 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
index 00fef0994b..7167d5b2ad 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.properties
@@ -76,3 +76,6 @@ JptCreationActionSet.label = Jpt Creation
JptCreationActionSet.description = Jpt Creation Action Set
NewEntityAction.label = New Entity
+
+jpaJpqlHyperlinkTarget = JPQL Editor
+jpaJpqlHyperlinkDetector = JPQL Query \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
index d13e1aa1e8..bed77ab200 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/plugin.xml
@@ -1232,4 +1232,25 @@
</extension>
+
+ <!-- ***** JPQL query editor ***** -->
+
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ activate="true"
+ class="org.eclipse.jpt.jpa.ui.internal.jpql.GenericJpaJpqlHyperlinkDetector"
+ id="org.eclipse.jpt.jpa.ui.jpql.generic"
+ name="%jpaJpqlHyperlinkDetector"
+ targetId="org.eclipse.jpt.jpa.ui.jpql">
+ </hyperlinkDetector>
+ </extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectorTargets">
+ <target
+ id="org.eclipse.jpt.jpa.ui.jpql"
+ name="%jpaJpqlHyperlinkTarget">
+ </target>
+ </extension>
+
</plugin>
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
index ab6ae15110..85e4283c4e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/property_files/jpt_ui.properties
@@ -146,9 +146,11 @@ JpaEntityGenPreferencePage_Description=Configure entity generation preferences f
JpaEntityGenPreferencePage_generalGroup_title=Entity generation from tables
JpaEntityGenPreferencePage_defaultPackageLabel=Default package:
-JpqlContentProposalProvider_Description=Content Assist Available ({0})
+JpaJpqlHyperlinkBuilder_OpenDeclaration=Open Declaration
+JpaJpqlHyperlinkBuilder_OpenDeclaredType=Open Declared Type
JpaJpqlJavaCompletionProposalComputer_Error=Can't retrieve JPQL proposals due to an internal error.
JpaJpqlSseCompletionProposalComputer_Error=Can't retrieve JPQL proposals due to an internal error.
+JpqlContentProposalProvider_Description=Content Assist Available ({0})
MappingFileWizard_title=New Mapping File
MappingFileWizardPage_newFile_title=Mapping file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
index de4ca05d99..eb4c5efb44 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/JptUiMessages.java
@@ -14,7 +14,7 @@ import org.eclipse.osgi.util.NLS;
/**
* Localized messages used by Dali UI.
*
- * @version 3.0
+ * @version 3.3
* @since 1.0
*/
// TODO bjv rename...
@@ -99,6 +99,8 @@ public class JptUiMessages {
public static String JpaFacetWizardPage_title;
public static String JpaFacetWizardPage_userLibsLink;
public static String JpaFacetWizardPage_userServerLibLabel;
+ public static String JpaJpqlHyperlinkBuilder_OpenDeclaration;
+ public static String JpaJpqlHyperlinkBuilder_OpenDeclaredType;
public static String JpaJpqlJavaCompletionProposalComputer_Error;
public static String JpaJpqlSseCompletionProposalComputer_Error;
public static String JpaLibraryProviderInstallPanel_includeLibraries;
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkBuilder.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkBuilder.java
new file mode 100644
index 0000000000..187e9e28f0
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkBuilder.java
@@ -0,0 +1,318 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.NamedQuery;
+import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
+import org.eclipse.persistence.jpa.jpql.Resolver;
+import org.eclipse.persistence.jpa.jpql.parser.AbstractPathExpression;
+import org.eclipse.persistence.jpa.jpql.parser.AbstractSchemaName;
+import org.eclipse.persistence.jpa.jpql.parser.AbstractTraverseParentVisitor;
+import org.eclipse.persistence.jpa.jpql.parser.CollectionValuedPathExpression;
+import org.eclipse.persistence.jpa.jpql.parser.ConstructorExpression;
+import org.eclipse.persistence.jpa.jpql.parser.EntityTypeLiteral;
+import org.eclipse.persistence.jpa.jpql.parser.Expression;
+import org.eclipse.persistence.jpa.jpql.parser.QueryPosition;
+import org.eclipse.persistence.jpa.jpql.parser.RangeVariableDeclaration;
+import org.eclipse.persistence.jpa.jpql.parser.StateFieldPathExpression;
+import org.eclipse.persistence.jpa.jpql.spi.IType;
+
+/**
+ * The default implementation of the builder that visit an {@link Expression} and creates {@link
+ * IHyperlink} objects.
+ *
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public class GenericJpaJpqlHyperlinkBuilder extends JpaJpqlHyperlinkBuilder {
+
+ private RangeVariableDeclarationVisitor rangeVariableDeclarationVisitor;
+
+ /**
+ * Creates a new <code>GenericJpaJpqlHyperlinkBuilder</code>.
+ *
+ * @param queryHelper This helper provides functionality related to JPQL queries
+ * @param namedQuery The model object representing the JPQL query
+ * @param queryPosition This object determines the position of the cursor within the parsed tree
+ */
+ public GenericJpaJpqlHyperlinkBuilder(JpaJpqlQueryHelper queryHelper,
+ NamedQuery namedQuery,
+ QueryPosition queryPosition) {
+
+ super(queryHelper, namedQuery, queryPosition);
+ }
+
+ /**
+ * Creates the visitor that can determine if the parent of an {@link Expression} is a {@link
+ * RangeVariableDeclarationVisitor}.
+ *
+ * @return A new {@link RangeVariableDeclarationVisitor}
+ */
+ protected RangeVariableDeclarationVisitor buildRangeVariableDeclarationVisitor() {
+ return new RangeVariableDeclarationVisitor();
+ }
+
+ /**
+ * Determines whether the given {@link CollectionValuedPathExpression} is a direct child of {@link
+ * RangeVariableDeclaration}.
+ *
+ * @param expression The {@link CollectionValuedPathExpression} to start the visit
+ * @return <code>true</code> if the parent of the given {@link CollectionValuedPathExpression} is
+ * {@link RangeVariableDeclaration}; <code>false</code> otherwise
+ */
+ protected final boolean isRangeVariableDeclaration(Expression expression) {
+ RangeVariableDeclarationVisitor visitor = rangeVariableDeclarationVisitor();
+ expression.accept(visitor);
+ try {
+ return visitor.rangeVariableDeclaration;
+ }
+ finally {
+ visitor.rangeVariableDeclaration = false;
+ }
+ }
+
+ /**
+ * Returns the visitor that can determine if the parent of an {@link Expression} is a {@link
+ * RangeVariableDeclaration}.
+ *
+ * @return {@link RangeVariableDeclarationVisitor}
+ */
+ protected final RangeVariableDeclarationVisitor rangeVariableDeclarationVisitor() {
+ if (rangeVariableDeclarationVisitor == null) {
+ rangeVariableDeclarationVisitor = buildRangeVariableDeclarationVisitor();
+ }
+ return rangeVariableDeclarationVisitor;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(AbstractSchemaName expression) {
+
+ String text = expression.getText();
+
+ // First check for an entity
+ Entity entity = getEntityNamed(text);
+
+ if (entity != null) {
+ IType type = getType(entity.getPersistentType().getName());
+ addOpenDeclarationHyperlink(type, buildRegion(expression));
+ }
+ // Now check for a derived path
+ else {
+
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(CollectionValuedPathExpression expression) {
+
+ // Check to see if the entity name is actually a fully qualified class name
+ if (!expression.startsWithDot() && isRangeVariableDeclaration(expression)) {
+ IType type = getType(expression.toActualText());
+ if (type.isResolvable()) {
+ addOpenDeclarationHyperlink(type, buildRegion(expression));
+ }
+ }
+ else {
+ visitPathExpression(expression);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(ConstructorExpression expression) {
+
+ String className = expression.getClassName();
+
+ int length = className.length();
+ int startOffset = 3 /* NEW */ + (expression.hasSpaceAfterNew() ? 1 : 0);
+ int startPosition = expression.getOffset() + startOffset;
+ int endPosition = startPosition + length;
+ int position = getPosition();
+
+ // Make sure the cursor position is within the class name
+ if ((position >= startPosition) && (position <= endPosition)) {
+
+ IType type = getType(className);
+
+ // Make sure the type is resolvable
+ if (type.isResolvable()) {
+ IRegion region = buildRegion(expression, startOffset, length);
+ addOpenDeclarationHyperlink(type, region);
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(EntityTypeLiteral expression) {
+
+ String text = expression.getEntityTypeName();
+ Entity entity = getEntityNamed(text);
+
+ if (entity != null) {
+ IType type = getType(entity.getPersistentType().getName());
+ addOpenDeclarationHyperlink(type, buildRegion(expression));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(StateFieldPathExpression expression) {
+ visitPathExpression(expression);
+ }
+
+ /**
+ * Visits the given {@link AbstractPathExpression} and determines the possible usages a path
+ * expression can be used for:
+ * <ul>
+ * <li>An actual path expression, example: e.name</li>
+ * <li>A fully qualified enum constant, example: javax.persistence.AccessType.FIELD</li>
+ * </ul>
+ *
+ * @param expression The {@link AbstractPathExpression} being visited
+ */
+ protected void visitPathExpression(AbstractPathExpression expression) {
+
+ // Nothing to do
+ if (!expression.hasIdentificationVariable() ||
+ expression.startsWithDot()) {
+
+ return;
+ }
+
+ int position = getPosition();
+ int offset = expression.getOffset();
+
+ // First, check for an enum type
+ String fullPath = expression.toActualText();
+ IType enumType = getQueryContext().getTypeRepository().getEnumType(fullPath);
+
+ // The path expression is a fully qualified enum constant
+ if (enumType != null) {
+
+ int stopIndex = expression.pathSize() - 1;
+ String enumConstant = expression.getPath(stopIndex);
+ int enumTypeLength = expression.toParsedText(0, stopIndex).length();
+
+ // The cursor is within the fully qualified enum type
+ if (position <= offset + enumTypeLength) {
+ addOpenDeclarationHyperlink(
+ enumType,
+ buildRegion(expression, 0, enumTypeLength)
+ );
+ }
+ // The cursor is within the enum constant name
+ else {
+ for (String constantName : enumType.getEnumConstants()) {
+ if (enumConstant.equals(constantName)) {
+
+ // TODO: field type
+ addFieldHyperlinks(
+ expression,
+ enumType,
+ enumType,
+ constantName,
+ enumTypeLength + 1 /* DOT */
+ );
+
+ break;
+ }
+ }
+ }
+ }
+ else {
+
+ // Check to see if the position is within the general identification variable
+ Expression identificationVariable = expression.getIdentificationVariable();
+ String variable = identificationVariable.toActualText();
+ int length = variable.length();
+
+ // The cursor is over the general identification variable
+ if (position <= offset + length + 1 /* DOT */) {
+ return;
+ }
+
+ // Resolve the general identification variable
+ Resolver resolver = getQueryContext().getResolver(identificationVariable);
+
+ // Can't continue to resolve the path expression
+ if (resolver == null) {
+ return;
+ }
+
+ // Dot between general identification variable and the first path
+ length++;
+
+ // Now traverse the path expression after the identification variable
+// for (int index = expression.hasVirtualIdentificationVariable() ? 0 : 1, count = expression.pathSize(); index < count; index++) {
+
+ // Retrieve the mapping for the path at the current position
+// String path = expression.getPath(index);
+// Resolver childResolver = resolver.getChild(path);
+
+// if (childResolver == null) {
+// childResolver = new StateFieldResolver(resolver, path);
+// resolver.addChild(path, childResolver);
+// }
+
+// IMapping mapping = childResolver.getMapping();
+
+ // Invalid path expression
+// if (mapping == null) {
+// break;
+// }
+
+ // The position is within the current path
+// if (position <= offset + length + path.length()) {
+// addFieldHyperlinks(expression, mapping, length);
+// break;
+// }
+
+// length += path.length() + 1 /* DOT */;
+// resolver = childResolver;
+// }
+ }
+ }
+
+ protected class RangeVariableDeclarationVisitor extends AbstractTraverseParentVisitor {
+
+ /**
+ * Determines whether the parent of the visited {@link Expression} is {@link RangeVariableDeclaration}.
+ */
+ protected boolean rangeVariableDeclaration;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void visit(RangeVariableDeclaration expression) {
+ rangeVariableDeclaration = true;
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkDetector.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkDetector.java
new file mode 100644
index 0000000000..128c8cf919
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/GenericJpaJpqlHyperlinkDetector.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+import org.eclipse.jpt.jpa.core.context.NamedQuery;
+import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
+import org.eclipse.persistence.jpa.jpql.parser.QueryPosition;
+
+/**
+ * The generic implementation of a hyperlink detector used in the JPQL query text editor.
+ *
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public class GenericJpaJpqlHyperlinkDetector extends JpaJpqlHyperlinkDetector {
+
+ /**
+ * Creates a new <code>GenericJpaJpqlHyperlinkDetector</code>.
+ */
+ public GenericJpaJpqlHyperlinkDetector() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected JpaJpqlHyperlinkBuilder buildHyperlinkBuilder(JpaJpqlQueryHelper queryHelper,
+ NamedQuery namedQuery,
+ QueryPosition queryPosition) {
+
+ return new GenericJpaJpqlHyperlinkBuilder(queryHelper, namedQuery, queryPosition);
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
index a47da63408..ca40e838e8 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlContentProposalProvider.java
@@ -16,8 +16,10 @@ package org.eclipse.jpt.jpa.ui.internal.jpql;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Map;
import java.util.ResourceBundle;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
@@ -28,6 +30,7 @@ import org.eclipse.core.expressions.EvaluationResult;
import org.eclipse.core.expressions.Expression;
import org.eclipse.core.expressions.ExpressionInfo;
import org.eclipse.core.expressions.IEvaluationContext;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.bindings.Binding;
import org.eclipse.jface.bindings.Trigger;
import org.eclipse.jface.bindings.keys.KeyStroke;
@@ -37,14 +40,12 @@ import org.eclipse.jface.fieldassist.FieldDecorationRegistry;
import org.eclipse.jface.internal.text.html.HTMLTextPresenter;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultInformationControl;
-import org.eclipse.jface.text.DefaultTextHover;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentListener;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.contentassist.ContentAssistant;
@@ -55,11 +56,8 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
-import org.eclipse.jface.text.source.DefaultAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jpt.common.ui.internal.listeners.SWTPropertyChangeListenerWrapper;
import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent;
@@ -77,7 +75,6 @@ import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
@@ -86,6 +83,7 @@ import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.editors.text.TextSourceViewerConfiguration;
import org.eclipse.ui.handlers.IHandlerActivation;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
@@ -102,7 +100,7 @@ import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;
* <p>
* TODO. Add syntax highlight for the JPQL identifiers.
*
- * @version 3.2
+ * @version 3.3
* @since 3.0
* @author Pascal Filion
*/
@@ -186,6 +184,12 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
private static final String ERROR_TYPE = "org.eclipse.jdt.ui.error";
/**
+ * The unique identifier of the ID used to register {@link org.eclipse.jface.text.hyperlink.IHyperlinkDetector
+ * IHyperlinkDetector} with the JPQL query text editor.
+ */
+ public static final String HYPERLINK_DETECTOR_ID = "org.eclipse.jpt.jpa.ui.jpql";
+
+ /**
* Creates a new <code>JpaJpqlContentProposalProvider</code>.
*
* @param parent The parent {@link Composite} where to add the JPQL query editor
@@ -646,13 +650,29 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
}
}
- private class JpqlSourceViewerConfiguration extends SourceViewerConfiguration {
+ private class JpqlSourceViewerConfiguration extends TextSourceViewerConfiguration {
/**
* Keeps track of the content assist since we need to know when the popup is opened or not.
*/
ContentAssistant contentAssistant;
+ JpqlSourceViewerConfiguration() {
+ super(EditorsPlugin.getDefault().getPreferenceStore());
+ }
+
+ private IAdaptable buildAdaptable() {
+ return new IAdaptable() {
+ @SuppressWarnings("rawtypes")
+ public Object getAdapter(Class adapter) {
+ if (adapter == NamedQuery.class) {
+ return query();
+ }
+ return null;
+ }
+ };
+ }
+
private IInformationControlCreator buildInformationControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
@@ -669,14 +689,6 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
* {@inheritDoc}
*/
@Override
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return new DefaultAnnotationHover();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
contentAssistant = new ContentAssistant();
contentAssistant.setContentAssistProcessor(new ContentAssistProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
@@ -688,16 +700,10 @@ public final class JpaJpqlContentProposalProvider extends JpqlCompletionProposal
* {@inheritDoc}
*/
@Override
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- return new DefaultTextHover(sourceViewer);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
- return new DefaultTextHover(sourceViewer);
+ protected Map<String, IAdaptable> getHyperlinkDetectorTargets(ISourceViewer sourceViewer) {
+ Map<String, IAdaptable> targets = new HashMap<String, IAdaptable>();
+ targets.put(HYPERLINK_DETECTOR_ID, buildAdaptable());
+ return targets;
}
}
} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkBuilder.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkBuilder.java
new file mode 100644
index 0000000000..fdbe57aa2a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkBuilder.java
@@ -0,0 +1,417 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jpt.jpa.core.context.Entity;
+import org.eclipse.jpt.jpa.core.context.NamedQuery;
+import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
+import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.persistence.jpa.jpql.ExpressionTools;
+import org.eclipse.persistence.jpa.jpql.JPQLQueryContext;
+import org.eclipse.persistence.jpa.jpql.parser.AbstractExpressionVisitor;
+import org.eclipse.persistence.jpa.jpql.parser.Expression;
+import org.eclipse.persistence.jpa.jpql.parser.QueryPosition;
+import org.eclipse.persistence.jpa.jpql.spi.IMapping;
+import org.eclipse.persistence.jpa.jpql.spi.IType;
+
+/**
+ * The abstract definition of a builder that visit an {@link Expression} and creates the supported
+ * list of {@link IHyperlink} objects, which can open the associated object. For instance, a {@link
+ * IHyperlink} for the entity name (abstract schema name) opens the Java editor on the associated
+ * Java file.
+ *
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public abstract class JpaJpqlHyperlinkBuilder extends AbstractExpressionVisitor {
+
+ private Collection<IHyperlink> hyperlinks;
+ private NamedQuery namedQuery;
+ private JpaJpqlQueryHelper queryHelper;
+ private QueryPosition queryPosition;
+
+ /**
+ * Creates a new <code>JpaJpqlHyperlinkBuilder</code>.
+ *
+ * @param queryHelper This helper provides functionality related to JPQL queries
+ * @param namedQuery The model object representing the JPQL query
+ * @param queryPosition This object determines the position of the cursor within the parsed tree
+ */
+ protected JpaJpqlHyperlinkBuilder(JpaJpqlQueryHelper queryHelper,
+ NamedQuery namedQuery,
+ QueryPosition queryPosition) {
+
+ super();
+ this.namedQuery = namedQuery;
+ this.queryHelper = queryHelper;
+ this.queryPosition = queryPosition;
+ this.hyperlinks = new ArrayList<IHyperlink>();
+ }
+
+ /**
+ * Adds two {@link IHyperlink} actions for the given {@link IMapping}: 'Open Declaration' and
+ * 'Open Declared Type}.
+ *
+ * @param expression The {@link Expression} being visited where {@link IHyperlink} objects can be
+ * created for the given {@link IMapping}
+ * @param mapping The {@link IMapping} for which a {@link IHyperlink} will be created, which will
+ * target the actual object: field or method
+ * @param offset The offset to be added to the {@link IRegion}'s offset, which is the beginning
+ * of the {@link IHyperlink}
+ */
+ protected final void addFieldHyperlinks(Expression expression,
+ IMapping mapping,
+ int offset) {
+
+ addFieldHyperlinks(
+ expression,
+ mapping.getParent().getType(),
+ mapping.getType(),
+ mapping.getName(),
+ offset
+ );
+ }
+
+ /**
+ * Adds two {@link IHyperlink} actions for the given {@link IMapping}: 'Open Declaration' and
+ * 'Open Declared Type}.
+ *
+ * @param expression The {@link Expression} being visited where {@link IHyperlink} objects can be
+ * created for the given {@link IMapping}
+ * @param parentType The {@link IType} of the parent of the mapping
+ * @param fieldType The {@link IType} of the mapping
+ * @param memberName The name of the mapping, which should either be the field name or the method name
+ * @param offset The offset to be added to the {@link IRegion}'s offset, which is the beginning
+ * of the {@link IHyperlink}
+ */
+ protected final void addFieldHyperlinks(Expression expression,
+ IType parentType,
+ IType fieldType,
+ String memberName,
+ int offset) {
+
+ IRegion region = buildRegion(expression, offset, memberName.length());
+
+ // 'Open Declaration' opens the declaration of the persistent type
+ addOpenMemberDeclarationHyperlink(
+ parentType,
+ memberName,
+ region,
+ JptUiMessages.JpaJpqlHyperlinkBuilder_OpenDeclaration
+ );
+
+ // 'Open Declared Type' opens the mapping type
+ addOpenDeclarationHyperlink(
+ fieldType,
+ region,
+ JptUiMessages.JpaJpqlHyperlinkBuilder_OpenDeclaredType
+ );
+ }
+
+ /**
+ * Adds the given {@link IHyperlink}.
+ *
+ * @param hyperlink A {@link IHyperlink} that can open the object represented by the visited
+ * {@link Expression}
+ */
+ protected final void addHyperlink(IHyperlink hyperlink) {
+ hyperlinks.add(hyperlink);
+ }
+
+ /**
+ * Adds the given {@link IHyperlink}.
+ *
+ * @param hyperlink A {@link IHyperlink} that can open the object represented by the visited
+ * {@link Expression}.
+ */
+ protected final void addOpenDeclarationHyperlink(IType type, IRegion region) {
+ addHyperlink(buildOpenDeclarationHyperlink(type, region));
+ }
+
+ /**
+ * Adds the given {@link IHyperlink}.
+ *
+ * @param type
+ * @param region
+ * @param hyperlinkText
+ */
+ protected final void addOpenDeclarationHyperlink(IType type, IRegion region, String hyperlinkText) {
+ addHyperlink(buildOpenDeclarationHyperlink(type, region, hyperlinkText));
+ }
+
+ /**
+ * Adds the given {@link IHyperlink}.
+ *
+ * @param type
+ * @param memberName
+ * @param region
+ * @param hyperlinkText
+ */
+ protected final void addOpenMemberDeclarationHyperlink(IType type,
+ String memberName,
+ IRegion region,
+ String hyperlinkText) {
+
+ addHyperlink(buildOpenMemberDeclarationHyperlink(type, memberName, region, hyperlinkText));
+ }
+
+ /**
+ * Returns the position of the given {@link Expression} relative to the actual JPQL query.
+ *
+ * @param expression The {@link Expression} to retrieve its offset within the JPQL query
+ * @return The offset of the given {@link Expression} within the JPQL query but based on the
+ * actual string representation of the JPQL query
+ */
+ protected final int adjustedPosition(Expression expression) {
+ return adjustedPosition(expression, 0);
+ }
+
+ /**
+ * Returns the position of the given {@link Expression} relative to the actual JPQL query.
+ *
+ * @param expression The {@link Expression} to retrieve its offset within the JPQL query
+ * @param offset The offset to be added to the {@link IRegion}'s offset, which is the beginning
+ * of the {@link IHyperlink}
+ * @return The offset of the given {@link Expression} within the JPQL query but based on the
+ * actual string representation of the JPQL query
+ */
+ protected final int adjustedPosition(Expression expression, int offset) {
+
+ int position = ExpressionTools.repositionCursor(
+ expression.getRoot().toParsedText(),
+ expression.getOffset(),
+ namedQuery.getQuery()
+ );
+
+ return position + offset;
+ }
+
+ /**
+ * Creates a new {@link IHyperlink} that can open the editor on the given {@link IType}.
+ *
+ * @param type The {@link IType} to open if the hyperlink is chosen
+ * @param region The {@link IRegion} represents the region to display the hyperlink within the JPQL query
+ * @return A new {@link IHyperlink}
+ */
+ protected final IHyperlink buildOpenDeclarationHyperlink(IType type, IRegion region) {
+ return buildOpenDeclarationHyperlink(
+ type,
+ region,
+ JptUiMessages.JpaJpqlHyperlinkBuilder_OpenDeclaration
+ );
+ }
+
+ /**
+ * Creates a new {@link IHyperlink} that can open the editor on the given {@link IType}.
+ *
+ * @param type The {@link IType} to open if the hyperlink is chosen
+ * @param region The {@link IRegion} represents the region to display the hyperlink within the JPQL query
+ * @param hyperlinkText The text of the {@link IHyperlink}
+ * @return A new {@link IHyperlink}
+ */
+ protected final IHyperlink buildOpenDeclarationHyperlink(IType type,
+ IRegion region,
+ String hyperlinkText) {
+
+ return new OpenDeclarationHyperlink(javaProject(), type.getName(), region, hyperlinkText);
+ }
+
+ /**
+ * Creates a new {@link IHyperlink} that can open the editor on a member of the given {@link IType}.
+ *
+ * @param type The {@link IType} to open if the hyperlink is chosen
+ * @param memberName The name of the member, a child element of the type, to select
+ * @param region The {@link IRegion} represents the region to display the hyperlink within the JPQL query
+ * @param hyperlinkText The text of the {@link IHyperlink}
+ * @return A new {@link IHyperlink}
+ */
+ protected final IHyperlink buildOpenMemberDeclarationHyperlink(IType type,
+ String memberName,
+ IRegion region,
+ String hyperlinkText) {
+
+ return new OpenMemberDeclarationHyperlink(
+ javaProject(),
+ type.getName(),
+ memberName,
+ region,
+ hyperlinkText
+ );
+ }
+
+ /**
+ * Creates
+ *
+ * @param expression
+ * @return A new {@link IRegion}
+ */
+ protected final IRegion buildRegion(Expression expression) {
+ return buildRegion(expression, 0);
+ }
+
+ /**
+ * Creates
+ *
+ * @param expression
+ * @param offset The offset to be added to the {@link IRegion}'s offset, which is the beginning
+ * of the {@link IHyperlink}
+ * @return A new {@link IRegion}
+ */
+ protected final IRegion buildRegion(Expression expression, int offset) {
+ return buildRegion(expression, offset, expression.toActualText().length());
+ }
+
+ /**
+ * Creates
+ *
+ * @param expression
+ * @param offset The offset to be added to the {@link IRegion}'s offset, which is the beginning
+ * of the {@link IHyperlink}
+ * @return A new {@link IRegion}
+ */
+ protected final IRegion buildRegion(Expression expression, int offset, int length) {
+ return new Region(
+ adjustedPosition(expression, offset),
+ length
+ );
+ }
+
+ /**
+ * Returns
+ *
+ * @param typeName
+ * @return
+ */
+ protected Entity getEntity(String typeName) {
+ return getNamedQuery().getPersistenceUnit().getEntity(typeName);
+ }
+
+ /**
+ * Returns
+ *
+ * @param entityName
+ * @return
+ */
+ protected Entity getEntityNamed(String entityName) {
+
+ for (Entity entity : getNamedQuery().getPersistenceUnit().getEntities()) {
+ if (entity.getName().equals(entityName)) {
+ return entity;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the model object of the JPQL query being edited.
+ *
+ * @return The {@link NamedQuery} being edited
+ */
+ protected NamedQuery getNamedQuery() {
+ return namedQuery;
+ }
+
+ /**
+ * Returns the position of the cursor in the query.
+ *
+ * @return The position of the cursor in the query
+ */
+ public int getPosition() {
+ return queryPosition.getPosition();
+ }
+
+ /**
+ * Returns the position of the cursor within the given {@link Expression}
+ *
+ * @param expression The {@link Expression} for which the position of the cursor is requested
+ * @return Either the position of the cursor within the given {@link Expression} or -1 if the
+ * cursor is not within it
+ */
+ public int getPosition(Expression expression) {
+ return queryPosition.getPosition(expression);
+ }
+
+ /**
+ * Returns the {@link JPQLQueryContext} that contains information about the JPQL query.
+ *
+ * @return The {@link JPQLQueryContext} that contains information contained in the JPQL query
+ */
+ protected JPQLQueryContext getQueryContext() {
+ return queryHelper.getQueryContext();
+ }
+
+ /**
+ * Returns the helper that can provide functionality related to JPQL query.
+ *
+ * @return The helper that contained cached information related to the JPQL query
+ */
+ protected JpaJpqlQueryHelper getQueryHelper() {
+ return queryHelper;
+ }
+
+ /**
+ * Returns the object that contains the position of the cursor within the parsed tree.
+ *
+ * @return The stack of {@link Expression} mapped to the position starting from the root to the
+ * child {@link Expression}
+ */
+ protected QueryPosition getQueryPosition() {
+ return queryPosition;
+ }
+
+ /**
+ * Retrieves the external class for the given fully qualified class name.
+ *
+ * @param typeName The fully qualified class name of the class to retrieve
+ * @return The external form of the class to retrieve
+ */
+ protected final IType getType(String typeName) {
+ return queryHelper.getTypeRepository().getType(typeName);
+ }
+
+ /**
+ * Returns an array of the {@link IHyperlink} objects that can open the corresponding object
+ * represented by the visited {@link Expression}.
+ *
+ * @return A non-<code>null</code> array
+ */
+ protected final IHyperlink[] hyperlinks() {
+
+ int size = hyperlinks.size();
+
+ // HyperlinkManager throws an exception for an empty array
+ if (size == 0) {
+ return null;
+ }
+
+ return hyperlinks.toArray(new IHyperlink[size]);
+ }
+
+ /**
+ * Returns the Java project associated with the JPA project.
+ *
+ * @return The {@link IJavaProject} owning the JPA project
+ */
+ protected final IJavaProject javaProject() {
+ return namedQuery.getJpaProject().getJavaProject();
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkDetector.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkDetector.java
new file mode 100644
index 0000000000..f673cb2bb6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/JpaJpqlHyperlinkDetector.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+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.jpt.jpa.core.context.NamedQuery;
+import org.eclipse.jpt.jpa.core.jpql.JpaJpqlQueryHelper;
+import org.eclipse.persistence.jpa.jpql.parser.QueryPosition;
+
+/**
+ * The abstract implementation of a hyperlink detector that is used to retrieve hyperlinks that are
+ * supported for a JPQL query.
+ * <p>
+ * The detector is registered with the JPQL query editor's hyperlink detector target, which is
+ * <code>org.eclipse.jpt.jpa.ui.jpql</code>.
+ *
+ * @see JpaJpqlContentProposalProvider#HYPERLINK_DETECTOR_ID
+ *
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public abstract class JpaJpqlHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ /**
+ * Creates a new <code>JpaJpqlHyperlinkDetector</code>.
+ */
+ protected JpaJpqlHyperlinkDetector() {
+ super();
+ }
+
+ /**
+ * Creates a new {@link HyperlinkBuilder}, which will visit the {@link
+ * org.eclipse.persistence.jpa.jpql.parser.Expression Expression} which is the parsed object of
+ * the region where to detect hyperlinks.
+ *
+ * @param queryHelper This helper provides functionality related to JPQL queries
+ * @param namedQuery The model object representing the JPQL query
+ * @param queryPosition This object determines the position of the cursor within the parsed tree
+ * @return A new concrete {@link HyperlinkBuilder}
+ */
+ protected abstract JpaJpqlHyperlinkBuilder buildHyperlinkBuilder(JpaJpqlQueryHelper queryHelper,
+ NamedQuery namedQuery,
+ QueryPosition queryPosition);
+
+ /**
+ * {@inheritDoc}
+ */
+ public final IHyperlink[] detectHyperlinks(ITextViewer textViewer,
+ IRegion region,
+ boolean canShowMultipleHyperlinks) {
+
+
+ NamedQuery namedQuery = (NamedQuery) getAdapter(NamedQuery.class);
+ JpaJpqlQueryHelper queryHelper = namedQuery.getPersistenceUnit().createJpqlQueryHelper();
+
+ try {
+ String jpqlQuery = textViewer.getTextWidget().getText();
+
+ // Populate the helper
+ queryHelper.setQuery(namedQuery, jpqlQuery);
+
+ // Build the position within the parsed tree
+ QueryPosition queryPosition = queryHelper.getJPQLExpression().buildPosition(
+ jpqlQuery,
+ region.getOffset()
+ );
+
+ // Gather the possible hyperlinks by visiting the Expression
+ JpaJpqlHyperlinkBuilder builder = buildHyperlinkBuilder(
+ queryHelper,
+ namedQuery,
+ queryPosition
+ );
+
+ queryPosition.getExpression().accept(builder);
+ return builder.hyperlinks();
+ }
+ finally {
+ queryHelper.dispose();
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenDeclarationHyperlink.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenDeclarationHyperlink.java
new file mode 100644
index 0000000000..e63a931a9a
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenDeclarationHyperlink.java
@@ -0,0 +1,107 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * This {@link IHyperlink} is responsible to open either the Java file or the Mappings file for a
+ * certain {@link Entity}.
+ *
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public final class OpenDeclarationHyperlink implements IHyperlink {
+
+ private String typeName;
+ private IJavaProject javaProject;
+ private IRegion region;
+ private String hyperlinkText;
+
+ /**
+ * Creates a new <code>OpenDeclarationHyperlink</code>.
+ *
+ * @param javaProject The {@link IJavaProject} will be used to retrieve the {@link IType}
+ * @param typeName The fully qualified type name to open in the editor
+ * @param region The {@link IRegion} represents the region to display the hyperlink within the JPQL query
+ * @param hyperlinkText The text of this {@link IHyperlink}
+ */
+ public OpenDeclarationHyperlink(IJavaProject javaProject,
+ String typeName,
+ IRegion region,
+ String hyperlinkText) {
+
+ super();
+ this.region = region;
+ this.typeName = typeName;
+ this.javaProject = javaProject;
+ this.hyperlinkText = hyperlinkText;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IRegion getHyperlinkRegion() {
+ return region;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getHyperlinkText() {
+ return hyperlinkText;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getTypeLabel() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void open() {
+
+ try {
+
+ // Retrieve the Java element
+ IType type = javaProject.findType(typeName);
+ IJavaElement javaElement = type.getParent();
+
+ // Open the editor
+ IEditorPart editorPart = JavaUI.openInEditor(javaElement, true, false);
+
+ // Now select the class name
+ if (editorPart instanceof ITextEditor) {
+ ISourceRange range = type.getNameRange();
+ ((ITextEditor) editorPart).selectAndReveal(range.getOffset(), range.getLength());
+ }
+ }
+ catch (Exception e) {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+ }
+} \ No newline at end of file
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenMemberDeclarationHyperlink.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenMemberDeclarationHyperlink.java
new file mode 100644
index 0000000000..6e5439afe3
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/jpql/OpenMemberDeclarationHyperlink.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
+ * which accompanies this distribution.
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ *
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.ui.internal.jpql;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ * @version 3.3
+ * @since 3.3
+ * @author Pascal Filion
+ */
+public class OpenMemberDeclarationHyperlink implements IHyperlink {
+
+ private String typeName;
+ private IJavaProject javaProject;
+ private IRegion region;
+ private String hyperlinkText;
+ private String memberName;
+
+ /**
+ * Creates a new <code>OpenMemberDeclarationHyperlink</code>.
+ */
+ public OpenMemberDeclarationHyperlink(IJavaProject javaProject,
+ String typeName,
+ String memberName,
+ IRegion region,
+ String hyperlinkText) {
+
+ super();
+ this.region = region;
+ this.typeName = typeName;
+ this.memberName = memberName;
+ this.javaProject = javaProject;
+ this.hyperlinkText = hyperlinkText;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public IRegion getHyperlinkRegion() {
+ return region;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getHyperlinkText() {
+ return hyperlinkText;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getTypeLabel() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void open() {
+
+ try {
+
+ // Retrieve the Java element
+ IType type = javaProject.findType(typeName);
+ IJavaElement javaElement = type.getParent();
+
+ // Open the editor
+ IEditorPart editorPart = JavaUI.openInEditor(javaElement, true, false);
+
+ // Now select the class name
+ if (editorPart instanceof ITextEditor) {
+
+ for (IJavaElement child : type.getChildren()) {
+ if (memberName.equals(child.getElementName())) {
+ javaElement = child;
+ break;
+ }
+ }
+
+ // TODO
+ ISourceRange range = type.getNameRange();
+ ((ITextEditor) editorPart).selectAndReveal(range.getOffset(), range.getLength());
+ }
+ }
+ catch (Exception e) {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+ }
+} \ No newline at end of file

Back to the top