Author: dgeraskov
Date: 2011-11-03 08:52:28 -0400 (Thu, 03 Nov 2011)
New Revision: 36160
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor2.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/CompletionProposalsResult.java
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLSourceViewerConfiguration.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
Log:
https://issues.jboss.org/browse/JBIDE-10098
Use appropriate Hibernate tools jar for code completion in multihibernate support plugins
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/META-INF/MANIFEST.MF 2011-11-03
12:52:28 UTC (rev 36160)
@@ -21,7 +21,8 @@
org.eclipse.ui.console,
org.eclipse.jface,
org.eclipse.jdt.apt.core,
- org.eclipse.datatools.connectivity
+ org.eclipse.datatools.connectivity,
+ org.eclipse.jface.text;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Eclipse-BuddyPolicy: registered
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ConsoleConfiguration.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -35,7 +35,6 @@
import java.util.Map;
import org.eclipse.osgi.util.NLS;
-import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
@@ -68,11 +67,6 @@
private HibernateExtension extension;
- //TODO do we need to create new instance every time???
- public HibernateExtension getConsoleConfigurationExtension(){
- return extension;
- }
-
private void loadHibernateExtension(){
String version = hibernateVersion == null ? "3.5" : hibernateVersion;//3.5 is
a default version
HibernateExtensionDefinition def =
ExtensionManager.findHibernateExtensionDefinition(version);
@@ -85,7 +79,7 @@
}
}
- private void setHibernateVersion(String hibernateVersion){
+ private void updateHibernateVersion(String hibernateVersion){
if (!StringUtils.equals(this.hibernateVersion, hibernateVersion)){
this.hibernateVersion = hibernateVersion;
loadHibernateExtension();
@@ -93,9 +87,10 @@
}
public HibernateExtension getHibernateExtension(){
+ updateHibernateVersion(prefs.getHibernateVersion());//reinit is necessary
return this.extension;
}
-
+
//****************************** EXTENSION **********************
public ConsoleConfiguration(ConsoleConfigurationPreferences config) {
@@ -209,7 +204,6 @@
public void build() {
configuration = buildWith(null, true);
- setHibernateVersion(prefs.getHibernateVersion());
getHibernateExtension().build();
fireConfigurationBuilt();
}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/CompletionProposalsResult.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/CompletionProposalsResult.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/CompletionProposalsResult.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.hibernate.console.ext;
+
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class CompletionProposalsResult {
+
+ private final List<ICompletionProposal> result;
+
+ private final String errorMessage;
+
+ public CompletionProposalsResult(List<ICompletionProposal> result, String
errorMessage){
+ this.result = result;
+ this.errorMessage = errorMessage;
+ }
+
+ public List<ICompletionProposal> getCompletionProposals() {
+ return result;
+ }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HQLQueryPage.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -43,7 +43,7 @@
private void updateQueryResults(){
try {
list = new ArrayList<Object>();
- queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
+ queryResult = getConsoleConfiguration().getHibernateExtension()
.executeHQLQuery(queryString, model);
if (!queryResult.hasExceptions()){
Iterator<?> iter = queryResult.list().iterator(); // need to be
user-controllable to toggle between iterate, scroll etc.
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtension.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -44,7 +44,7 @@
public Object getSessionFactory();
//FIXME remove this method
*/
-
+ public CompletionProposalsResult hqlCodeComplete(String query, int position);
}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/HibernateExtensionDefinition.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -44,27 +44,15 @@
public HibernateExtension createHibernateExtensionInstance() {
HibernateExtension hiberanteExtension = null;
- try {
- // hiberanteExtension = (HibernateExtension) ReflectHelper.classForName( classname
).newInstance();
- hiberanteExtension = (HibernateExtension)
element.createExecutableExtension(CLASSNAME);
- }
- /* catch (InstantiationException e) {
- throw new HibernateConsoleRuntimeException(NLS.bind(
- "Problem while creating hibernate extension instance {0}",
classname));
- }
- catch (IllegalAccessException e) {
- throw new HibernateConsoleRuntimeException(NLS.bind(
- "Problem while creating hibernate extension instance {0}",
classname)); }
- catch (ClassNotFoundException e) {
- throw new HibernateConsoleRuntimeException(NLS.bind(
- "Problem while creating hibernate extension instance {0}",
classname));
- } */catch (CoreException e) {
- // TODO Auto-generated catch block
+ try {
+ hiberanteExtension = (HibernateExtension) element
+ .createExecutableExtension(CLASSNAME);
+ } catch (CoreException e) {
e.printStackTrace();
}
- return hiberanteExtension;
- }
+ return hiberanteExtension;
+ }
/**
* @return the hibernateVersion
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse/src/org/hibernate/console/ext/JavaPage.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -51,7 +51,7 @@
private void updateQueryResults(){
try {
list = new ArrayList<Object>();
- queryResult = getConsoleConfiguration().getConsoleConfigurationExtension()
+ queryResult = getConsoleConfiguration().getHibernateExtension()
.executeCriteriaQuery(criteriaCode, model);
if (!queryResult.hasExceptions()){
Iterator<?> iter = queryResult.list().iterator(); // need to be
user-controllable to toggle between iterate, scroll etc.
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/workbench/LazyDatabaseSchemaWorkbenchAdapter.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -110,13 +110,13 @@
return getLazyDatabaseSchema(o).getConsoleConfiguration();
}
- protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor,
ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy strategy) {
+ protected DefaultDatabaseCollector readDatabaseSchema(final IProgressMonitor monitor,
final ConsoleConfiguration consoleConfiguration, final ReverseEngineeringStrategy
strategy) {
final Configuration configuration = consoleConfiguration.buildWith(null, false);
return (DefaultDatabaseCollector) consoleConfiguration.execute(new
ExecutionContext.Command() {
public Object execute() {
DefaultDatabaseCollector db = null;
- Settings settings = configuration.buildSettings();
+ Settings settings = consoleConfiguration.getSettings(configuration);
ConnectionProvider connectionProvider = null;
try {
connectionProvider = settings.getConnectionProvider();
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor2.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor2.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLCompletionProcessor2.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.hibernate.eclipse.hqleditor;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.ITypedRegion;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.ext.CompletionProposalsResult;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.QueryEditor;
+
+/**
+ * content assist processor for HQL code.
+ */
+public class HQLCompletionProcessor2 implements IContentAssistProcessor {
+
+ private char[] autoActivationChars = { '.' };
+ protected IContextInformationValidator validator = new
MinimalDiffContextInformationValidator(5);
+ private final Comparator<ICompletionProposal> completionComparator;
+ //private final HQLEditor editor;
+ private QueryEditor hqlEditor;
+ private String errorMessage;
+
+ public HQLCompletionProcessor2(QueryEditor editor) {
+ super();
+ this.hqlEditor = editor;
+ completionComparator = DisplayStringProposalComparator.INSTANCE;
+ }
+
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
documentOffset) {
+ IDocument doc = viewer.getDocument();
+ return computeCompletionProposals(doc, documentOffset);
+ }
+
+ public ICompletionProposal[] computeCompletionProposals(IDocument doc, int
documentOffset) {
+ ICompletionProposal[] result = new ICompletionProposal[0];
+
+ try {
+ ITypedRegion partition = null;
+
+ if (documentOffset > 0) {
+ partition = doc.getPartition( documentOffset - 1 );
+ }
+ else {
+ partition = doc.getPartition( documentOffset );
+ }
+
+ if(partition!=null) {
+ result = computeProposals( doc, partition.getOffset(), documentOffset,
hqlEditor.getConsoleConfiguration() );
+ }
+ }
+ catch (BadLocationException x) {
+ }
+ catch (RuntimeException re) {
+ HibernateConsolePlugin.getDefault().logErrorMessage(
HibernateConsoleMessages.HQLCompletionProcessor_error_while_performing_hql_completion, re
);
+ }
+
+ if (result != null)
+ result = sort( result );
+
+ return result;
+ }
+
+ ICompletionProposal[] computeProposals(IDocument doc, int lineStart, final int
currentOffset, final ConsoleConfiguration consoleConfiguration) {
+ ICompletionProposal[] result = null;
+ errorMessage = null;
+ if (doc != null && currentOffset >= 0) {
+
+ List<ICompletionProposal> proposalList = new
ArrayList<ICompletionProposal>();
+ String startWord = null;
+
+ int startOffset = findNearestWhiteSpace( doc, currentOffset, lineStart );
+
+ int wordLength = currentOffset - startOffset;
+ startWord = getWord( doc, startOffset, wordLength );
+
+ if(startWord!=null) {
+ try {
+ doc.get(0,doc.getLength()).toCharArray();
+ }
+ catch (BadLocationException e) {
+ errorMessage =
HibernateConsoleMessages.HQLCompletionProcessor_could_not_get_document_contents;
+ return result;
+ }
+
+ if(consoleConfiguration != null) {
+ //EclipseHQLCompletionRequestor eclipseHQLCompletionCollector = new
EclipseHQLCompletionRequestor();
+ CompletionProposalsResult codeCompletions =
consoleConfiguration.getHibernateExtension().hqlCodeComplete(doc.get(), currentOffset);
+
+ proposalList.addAll(codeCompletions.getCompletionProposals());
+ errorMessage =
codeCompletions.getErrorMessage();//eclipseHQLCompletionCollector.getLastErrorMessage();
+
+ result = proposalList.toArray(new ICompletionProposal[proposalList.size()]);
+ if(result.length==0 && errorMessage==null) {
+ errorMessage =
HibernateConsoleMessages.HQLCompletionProcessor_no_hql_completions_available;
+ }
+ }
+ } else {
+ errorMessage =
HibernateConsoleMessages.HQLCompletionProcessor_no_start_word_found;
+ }
+ }
+
+ return result;
+ }
+
+ private String getWord(IDocument doc, int startOffset, int wordLength) {
+ try {
+ return doc.get( startOffset, wordLength );
+ }
+ catch (BadLocationException e) {
+ return null; // no word found.
+ }
+ }
+
+
+ public IContextInformation[] computeContextInformation( ITextViewer viewer, int
documentOffset ) { return null; }
+
+ public char[] getCompletionProposalAutoActivationCharacters() { return
autoActivationChars; }
+
+ public char[] getContextInformationAutoActivationCharacters() { return null; }
+
+ public IContextInformationValidator getContextInformationValidator() { return
validator; }
+
+ public String getErrorMessage() {
+ return errorMessage;
+ }
+
+ private ICompletionProposal[] sort( ICompletionProposal[] proposals ) {
+ Arrays.sort( proposals, completionComparator );
+ return proposals;
+ }
+
+ public int findNearestWhiteSpace( IDocument doc, int documentOffset, int offset ) {
+ boolean loop = true;
+
+ int tmpOffset = documentOffset - 1;
+ try {
+ while (loop && offset <= tmpOffset) {
+ char c = doc.getChar(tmpOffset);
+ if(c=='"' || Character.isWhitespace(c)) {
+ loop = false;
+ } else {
+ tmpOffset--;
+ }
+ }
+ }
+ catch (BadLocationException x) {
+ }
+
+ offset = tmpOffset + 1;
+
+ return offset;
+ }
+
+ }
\ No newline at end of file
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLSourceViewerConfiguration.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLSourceViewerConfiguration.java 2011-11-03
12:52:16 UTC (rev 36159)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/hqleditor/HQLSourceViewerConfiguration.java 2011-11-03
12:52:28 UTC (rev 36160)
@@ -25,6 +25,7 @@
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.formatter.ContentFormatter;
import org.eclipse.jface.text.formatter.IContentFormatter;
@@ -42,7 +43,7 @@
public class HQLSourceViewerConfiguration extends SourceViewerConfiguration {
public final static String HQL_PARTITIONING= "__hql_partitioning";
//$NON-NLS-1$
- private HQLCompletionProcessor completionProcessor;
+ private IContentAssistProcessor completionProcessor;
//private HQLEditor hqlEditor;
private QueryEditor hqlEditor;
@@ -54,7 +55,7 @@
public HQLSourceViewerConfiguration(QueryEditor editor) {
this.hqlEditor = editor;
- completionProcessor = new HQLCompletionProcessor(editor);
+ completionProcessor = new HQLCompletionProcessor2(editor);
}
public String getConfiguredDocumentPartitioning( ISourceViewer sourceViewer ) {
@@ -66,7 +67,7 @@
assistant.setDocumentPartitioning( getConfiguredDocumentPartitioning(
sourceViewer ));
- completionProcessor = new HQLCompletionProcessor(hqlEditor);
+ completionProcessor = new HQLCompletionProcessor2(hqlEditor);
assistant.setContentAssistProcessor( completionProcessor,
IDocument.DEFAULT_CONTENT_TYPE);
assistant.enableAutoActivation( true );