Author: dgeraskov
Date: 2011-11-11 07:44:47 -0500 (Fri, 11 Nov 2011)
New Revision: 36298
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CompletionProposal.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterAttributes.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterDefinition.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterFactory.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExtensionManager.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CompletionProposal.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EclipseHQLCompletionRequestor.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterAttributes.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterDefinition.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterFactory.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExtensionManager.java
Removed:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/CompletionProposal.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/ConsoleExtension3_5.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/EclipseHQLCompletionRequestor.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/CompletionProposal.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConsoleExtension4_0.java
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/EclipseHQLCompletionRequestor.java
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/plugin.xml
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/plugin.xml
Log:
Move exporters call to extenders plugins
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/META-INF/MANIFEST.MF 2011-11-11
12:44:47 UTC (rev 36298)
@@ -10,6 +10,10 @@
org.hibernate.eclipse;bundle-version="3.4.0",
org.hibernate.eclipse.libs;bundle-version="1.0.0",
org.eclipse.jface.text;bundle-version="3.7.0",
- org.hibernate.eclipse.console;bundle-version="3.4.0"
+ org.hibernate.eclipse.console;bundle-version="3.4.0",
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.core.variables;bundle-version="3.2.500",
+ org.eclipse.jdt.core;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.debug.core
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/plugin.xml
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/plugin.xml 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/plugin.xml 2011-11-11
12:44:47 UTC (rev 36298)
@@ -11,7 +11,7 @@
<extension
point="org.hibernate.eclipse.console.consoleextension">
<consoleextension
- classname="org.jboss.tools.hibernate3_5.ConsoleExtension3_5"
+
classname="org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5"
version="%hibernate.version">
</consoleextension>
</extension>
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/CompletionProposal.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/CompletionProposal.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/CompletionProposal.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,279 +0,0 @@
-/*
- * 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.jboss.tools.hibernate3_5;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
-
-/**
- * Generic completion proposal to be used as is, or as base for other completion
proposals.
- *
- * @author Max Rydahl Andersen
- *
- */
-public class CompletionProposal implements ICompletionProposal,
ICompletionProposalExtension {
-
- private String displayString;
- private String replacementString;
- private int replacementOffset;
- private int documentOffset = -1;
- private int replacementLength;
- private int cursorPosition;
- private Image image;
- private IContextInformation contextInformation;
- private int contextInformationPosition;
- private char[] triggerCharacters;
- private String additionalProposalInfo;
-
- /**
- * Creates a new completion proposal. All fields are initialized based on
- * the provided information.
- *
- * @param additionalInfo additional information about the completion proposal
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset offset of the text to be replaced
- * @param documentOffset offset of the document
- * @param replacementLength length of the text to be replaced
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal If set
- * to <code>null</code>, the replacement string will be taken
- * as display string.
- */
- public CompletionProposal( String additionalInfo, String replacementString, int
replacementOffset,
- int documentOffset, int replacementLength, Image image, String
displayString,
- IContextInformation contextInformation ) {
-
- this.replacementString = replacementString;
- this.replacementOffset = replacementOffset;
- this.documentOffset = documentOffset;
- this.replacementLength = replacementLength;
- this.image = image;
- this.displayString = displayString != null ? displayString : replacementString;
-
- this.cursorPosition = replacementString.length();
-
- this.contextInformation = contextInformation;
-
- this.triggerCharacters = null;
- this.additionalProposalInfo = additionalInfo;
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on
- * the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset the offset of the text to be replaced
- * @param replacementLength the length of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert
- * relative to replacementOffset
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param contentInformation the context information associated with this proposal
- * @param additionalProposalInfo the additional information associated with
- * this proposal
- */
- public CompletionProposal( String replacementString, int replacementOffset, int
replacementLength,
- int cursorPosition, Image image, String displayString, IContextInformation
contextInformation,
- String additionalProposalInfo ) {
-
- this.replacementString = replacementString;
- this.replacementOffset = replacementOffset;
- this.documentOffset = replacementOffset;
- this.replacementLength = replacementLength;
- this.cursorPosition = cursorPosition;
- this.image = image;
- this.displayString = displayString;
- this.contextInformation = contextInformation;
- this.additionalProposalInfo = additionalProposalInfo;
-
- }
-
- public void setContextInformation( IContextInformation contextInformation ) {
- this.contextInformation = contextInformation;
- contextInformationPosition = (contextInformation != null ? cursorPosition : -1);
- }
-
- /**
- * Sets the trigger characters.
- *
- * @param triggerCharacters The set of characters which can trigger the
- * application of this completion proposal
- */
- public void setTriggerCharacters( char[] triggerCharacters ) {
- this.triggerCharacters = triggerCharacters;
- }
-
- /**
- * Sets the cursor position relative to the insertion offset. By default
- * this is the length of the completion string (Cursor positioned after the
- * completion)
- *
- * @param cursorPosition The cursorPosition to set
- */
- public void setCursorPosition( int cursorPosition ) {
-
- if (cursorPosition >= 0) {
- this.cursorPosition = cursorPosition;
- this.contextInformationPosition = (contextInformation != null ?
cursorPosition : -1);
- }
- }
-
- public void apply( IDocument document, char trigger, int offset ) {
- try {
- // patch replacement length
-
- int delta = offset - (documentOffset + replacementLength);
- if (delta > 0)
- replacementLength += delta;
-
- if (trigger == (char) 0) {
- replace( document, documentOffset, replacementLength, replacementString
);
- }
- else {
- StringBuffer buffer = new StringBuffer( replacementString );
-
- if ((replacementLength < buffer.length() && buffer.charAt(
replacementLength ) != trigger)) {
- buffer.insert( cursorPosition, trigger );
- ++cursorPosition;
- }
-
- replace( document, documentOffset, replacementLength, buffer.toString()
);
- }
-
- int oldLen = document.getLength();
- documentOffset += document.getLength() - oldLen;
- }
- catch (BadLocationException e) {
- HibernateConsolePlugin.getDefault().log( e );
- }
- }
-
- /**
- * Replaces the document content at the specified offset and length with the
- * specified string.
- *
- * @param document the document opened in the editor
- * @param offset offset to the document content to be replaced
- * @param length length of text to be replaced
- * @param string replacement string
- * @throws BadLocationException
- */
- private void replace( IDocument document, int offset, int length, String string )
throws BadLocationException {
- if (document != null && string != null && offset >= 0
&& length >= 0) {
- if (!document.get( offset, length ).equals( string ))
- document.replace( offset, length, string );
- }
- }
-
- public void apply( IDocument document ) {
- apply( document, (char) 0, documentOffset + replacementLength );
- }
-
- public Point getSelection( IDocument document ) {
- return new Point( documentOffset + cursorPosition, 0 );
- }
-
- public IContextInformation getContextInformation() {
- return contextInformation;
- }
-
- public Image getImage() {
- return image;
- }
-
- public String getDisplayString() {
- return displayString;
- }
-
- public String getAdditionalProposalInfo() {
- return additionalProposalInfo;
- }
-
- public char[] getTriggerCharacters() {
- return triggerCharacters;
- }
-
- public int getContextInformationPosition() {
- return replacementOffset + contextInformationPosition;
- }
-
- public int getReplacementOffset() {
- return replacementOffset;
- }
-
- public void setReplacementOffset( int replacementOffset ) {
-
- if (replacementOffset >= 0) {
- this.replacementOffset = replacementOffset;
- }
- }
-
- public int getReplacementLength() {
- return replacementLength;
- }
-
- public void setReplacementLength( int replacementLength ) {
-
- if (replacementLength >= 0) {
- this.replacementLength = replacementLength;
- }
- }
-
- public String getReplacementString() {
- return replacementString;
- }
-
- public void setReplacementString( String replacementString ) {
- this.replacementString = replacementString;
- }
-
- public void setImage( Image image ) {
- this.image = image;
- }
-
- public boolean isValidFor( IDocument document, int offset ) {
- if (offset < replacementOffset)
- return false;
-
- int replacementLength = replacementString == null ? 0 :
replacementString.length();
- if (offset >= replacementOffset + replacementLength)
- return false;
-
- try {
- int length = offset - replacementOffset;
- String start = document.get( replacementOffset, length );
- return replacementString.substring( 0, length ).equalsIgnoreCase( start );
- }
- catch (BadLocationException x) {
- }
-
- return false;
- }
-
-}
\ No newline at end of file
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/ConsoleExtension3_5.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/ConsoleExtension3_5.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/ConsoleExtension3_5.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.jboss.tools.hibernate3_5;
-
-import org.hibernate.console.execution.ExecutionContext;
-import org.hibernate.console.ext.HibernateException;
-import org.hibernate.console.ext.HibernateExtension;
-import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
-import org.hibernate.eclipse.console.ext.ConsoleExtension;
-import org.hibernate.tool.ide.completion.HQLCodeAssist;
-import org.hibernate.tool.ide.completion.IHQLCodeAssist;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public class ConsoleExtension3_5 implements ConsoleExtension {
-
- private HibernateExtension3_5 hibernateExtension;
-
- public ConsoleExtension3_5(){}
-
- public void setHibernateException(HibernateExtension hibernateExtension){
- this.hibernateExtension = (HibernateExtension3_5) hibernateExtension;
- }
-
- @Override
- public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
- EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
- if (!hibernateExtension.hasConfiguration()){
- try {
- hibernateExtension.build();
- hibernateExtension.execute( new ExecutionContext.Command() {
- public Object execute() {
- if(hibernateExtension.hasConfiguration()) {
- hibernateExtension.getConfiguration().buildMappings();
- }
- return null;
- }
- });
- } catch (HibernateException e){
- //FIXME
- //String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
- //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
- }
- }
- IHQLCodeAssist hqlEval = new HQLCodeAssist(hibernateExtension.getConfiguration());
- query = query.replace('\t', ' ');
- hqlEval.codeComplete(query, currentOffset, requestor);
- return new CompletionProposalsResult(requestor.getCompletionProposals(),
requestor.getLastErrorMessage());
- }
-
-
-
-}
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/EclipseHQLCompletionRequestor.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/EclipseHQLCompletionRequestor.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/EclipseHQLCompletionRequestor.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,151 +0,0 @@
-/*
- * 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.jboss.tools.hibernate3_5;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.swt.graphics.Image;
-import org.hibernate.console.ImageConstants;
-import org.hibernate.eclipse.console.utils.EclipseImages;
-import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper;
-import org.hibernate.tool.ide.completion.HQLCompletionProposal;
-import org.hibernate.tool.ide.completion.IHQLCompletionRequestor;
-import org.hibernate.util.StringHelper;
-
-public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor {
-
- private final List<ICompletionProposal> result = new
ArrayList<ICompletionProposal>();
- private String lastErrorMessage;
- private final int virtualOffset;
-
- public EclipseHQLCompletionRequestor() {
- virtualOffset = 0;
- }
-
- public EclipseHQLCompletionRequestor(int virtualOffset) {
- this.virtualOffset = virtualOffset;
- }
-
- public List<ICompletionProposal> getCompletionProposals() {
- return result;
- }
-
- public boolean accept(HQLCompletionProposal proposal) {
- result.add(new CompletionProposal(proposal.getCompletion(), // replacementString
- proposal.getReplaceStart()+virtualOffset, // replacementOffset
- proposal.getReplaceEnd()-proposal.getReplaceStart(), // replacementLength
- proposal.getCompletion().length(), // cursorPosition (relativeTo
replacementStart)
- getImage(proposal),
- getDisplayString(proposal),
- null,
- null));
- return true;
- }
-
- private String getDisplayString(HQLCompletionProposal proposal) {
- StringBuffer buf = new StringBuffer(proposal.getSimpleName());
-
- switch(proposal.getCompletionKind()) {
- case HQLCompletionProposal.ENTITY_NAME:
- if(proposal.getEntityName()!=null &&
- !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
- buf.append(" - "); //$NON-NLS-1$
- buf.append(StringHelper.qualifier( proposal.getEntityName() ));
- } else if(proposal.getShortEntityName()!=null &&
- !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- }
- break;
- case HQLCompletionProposal.ALIAS_REF:
- if(proposal.getShortEntityName()!=null) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- } else if(proposal.getEntityName()!=null) {
- buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
- }
- break;
- case HQLCompletionProposal.PROPERTY:
- if(proposal.getShortEntityName()!=null) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- } else if(proposal.getEntityName()!=null) {
- if(proposal.getEntityName().indexOf( "." )>=0) { //$NON-NLS-1$
- buf.append( " - " + StringHelper.unqualify( proposal.getEntityName() ));
//$NON-NLS-1$
- } else {
- buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
- }
- }
- break;
- case HQLCompletionProposal.KEYWORD:
- break;
- case HQLCompletionProposal.FUNCTION:
- break;
- default:
-
- }
-
-
- return buf.toString();
- }
-
- private Image getImage(HQLCompletionProposal proposal) {
- String key = null;
-
- switch(proposal.getCompletionKind()) {
- case HQLCompletionProposal.ENTITY_NAME:
- case HQLCompletionProposal.ALIAS_REF:
- key = ImageConstants.MAPPEDCLASS;
- break;
- case HQLCompletionProposal.PROPERTY:
- if(proposal.getProperty()!=null) {
- return HibernateWorkbenchHelper.getImage( proposal.getProperty() );
- } else {
- key = ImageConstants.PROPERTY;
- }
- break;
- case HQLCompletionProposal.KEYWORD:
- key = null;
- break;
- case HQLCompletionProposal.FUNCTION:
- key = ImageConstants.FUNCTION;
- break;
- default:
- key = null;
- }
-
- return key==null?null:EclipseImages.getImage( key );
- }
-
- public void completionFailure(String errorMessage) {
- lastErrorMessage = errorMessage;
- }
-
- public String getLastErrorMessage() {
- return lastErrorMessage;
- }
-
- public void clear() {
- result.clear();
- lastErrorMessage = null;
- }
-
-}
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CompletionProposal.java
(from rev 36273,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/CompletionProposal.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CompletionProposal.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/CompletionProposal.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,279 @@
+/*
+ * 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.jboss.tools.hibernate3_5.console;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+
+/**
+ * Generic completion proposal to be used as is, or as base for other completion
proposals.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public class CompletionProposal implements ICompletionProposal,
ICompletionProposalExtension {
+
+ private String displayString;
+ private String replacementString;
+ private int replacementOffset;
+ private int documentOffset = -1;
+ private int replacementLength;
+ private int cursorPosition;
+ private Image image;
+ private IContextInformation contextInformation;
+ private int contextInformationPosition;
+ private char[] triggerCharacters;
+ private String additionalProposalInfo;
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param additionalInfo additional information about the completion proposal
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset offset of the text to be replaced
+ * @param documentOffset offset of the document
+ * @param replacementLength length of the text to be replaced
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal If set
+ * to <code>null</code>, the replacement string will be taken
+ * as display string.
+ */
+ public CompletionProposal( String additionalInfo, String replacementString, int
replacementOffset,
+ int documentOffset, int replacementLength, Image image, String
displayString,
+ IContextInformation contextInformation ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = documentOffset;
+ this.replacementLength = replacementLength;
+ this.image = image;
+ this.displayString = displayString != null ? displayString : replacementString;
+
+ this.cursorPosition = replacementString.length();
+
+ this.contextInformation = contextInformation;
+
+ this.triggerCharacters = null;
+ this.additionalProposalInfo = additionalInfo;
+ }
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset the offset of the text to be replaced
+ * @param replacementLength the length of the text to be replaced
+ * @param cursorPosition the position of the cursor following the insert
+ * relative to replacementOffset
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal
+ * @param contentInformation the context information associated with this proposal
+ * @param additionalProposalInfo the additional information associated with
+ * this proposal
+ */
+ public CompletionProposal( String replacementString, int replacementOffset, int
replacementLength,
+ int cursorPosition, Image image, String displayString, IContextInformation
contextInformation,
+ String additionalProposalInfo ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = replacementOffset;
+ this.replacementLength = replacementLength;
+ this.cursorPosition = cursorPosition;
+ this.image = image;
+ this.displayString = displayString;
+ this.contextInformation = contextInformation;
+ this.additionalProposalInfo = additionalProposalInfo;
+
+ }
+
+ public void setContextInformation( IContextInformation contextInformation ) {
+ this.contextInformation = contextInformation;
+ contextInformationPosition = (contextInformation != null ? cursorPosition : -1);
+ }
+
+ /**
+ * Sets the trigger characters.
+ *
+ * @param triggerCharacters The set of characters which can trigger the
+ * application of this completion proposal
+ */
+ public void setTriggerCharacters( char[] triggerCharacters ) {
+ this.triggerCharacters = triggerCharacters;
+ }
+
+ /**
+ * Sets the cursor position relative to the insertion offset. By default
+ * this is the length of the completion string (Cursor positioned after the
+ * completion)
+ *
+ * @param cursorPosition The cursorPosition to set
+ */
+ public void setCursorPosition( int cursorPosition ) {
+
+ if (cursorPosition >= 0) {
+ this.cursorPosition = cursorPosition;
+ this.contextInformationPosition = (contextInformation != null ?
cursorPosition : -1);
+ }
+ }
+
+ public void apply( IDocument document, char trigger, int offset ) {
+ try {
+ // patch replacement length
+
+ int delta = offset - (documentOffset + replacementLength);
+ if (delta > 0)
+ replacementLength += delta;
+
+ if (trigger == (char) 0) {
+ replace( document, documentOffset, replacementLength, replacementString
);
+ }
+ else {
+ StringBuffer buffer = new StringBuffer( replacementString );
+
+ if ((replacementLength < buffer.length() && buffer.charAt(
replacementLength ) != trigger)) {
+ buffer.insert( cursorPosition, trigger );
+ ++cursorPosition;
+ }
+
+ replace( document, documentOffset, replacementLength, buffer.toString()
);
+ }
+
+ int oldLen = document.getLength();
+ documentOffset += document.getLength() - oldLen;
+ }
+ catch (BadLocationException e) {
+ HibernateConsolePlugin.getDefault().log( e );
+ }
+ }
+
+ /**
+ * Replaces the document content at the specified offset and length with the
+ * specified string.
+ *
+ * @param document the document opened in the editor
+ * @param offset offset to the document content to be replaced
+ * @param length length of text to be replaced
+ * @param string replacement string
+ * @throws BadLocationException
+ */
+ private void replace( IDocument document, int offset, int length, String string )
throws BadLocationException {
+ if (document != null && string != null && offset >= 0
&& length >= 0) {
+ if (!document.get( offset, length ).equals( string ))
+ document.replace( offset, length, string );
+ }
+ }
+
+ public void apply( IDocument document ) {
+ apply( document, (char) 0, documentOffset + replacementLength );
+ }
+
+ public Point getSelection( IDocument document ) {
+ return new Point( documentOffset + cursorPosition, 0 );
+ }
+
+ public IContextInformation getContextInformation() {
+ return contextInformation;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public String getDisplayString() {
+ return displayString;
+ }
+
+ public String getAdditionalProposalInfo() {
+ return additionalProposalInfo;
+ }
+
+ public char[] getTriggerCharacters() {
+ return triggerCharacters;
+ }
+
+ public int getContextInformationPosition() {
+ return replacementOffset + contextInformationPosition;
+ }
+
+ public int getReplacementOffset() {
+ return replacementOffset;
+ }
+
+ public void setReplacementOffset( int replacementOffset ) {
+
+ if (replacementOffset >= 0) {
+ this.replacementOffset = replacementOffset;
+ }
+ }
+
+ public int getReplacementLength() {
+ return replacementLength;
+ }
+
+ public void setReplacementLength( int replacementLength ) {
+
+ if (replacementLength >= 0) {
+ this.replacementLength = replacementLength;
+ }
+ }
+
+ public String getReplacementString() {
+ return replacementString;
+ }
+
+ public void setReplacementString( String replacementString ) {
+ this.replacementString = replacementString;
+ }
+
+ public void setImage( Image image ) {
+ this.image = image;
+ }
+
+ public boolean isValidFor( IDocument document, int offset ) {
+ if (offset < replacementOffset)
+ return false;
+
+ int replacementLength = replacementString == null ? 0 :
replacementString.length();
+ if (offset >= replacementOffset + replacementLength)
+ return false;
+
+ try {
+ int length = offset - replacementOffset;
+ String start = document.get( replacementOffset, length );
+ return replacementString.substring( 0, length ).equalsIgnoreCase( start );
+ }
+ catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
(from rev 36275,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/ConsoleExtension3_5.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ConsoleExtension3_5.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,302 @@
+/*******************************************************************************
+ * 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.jboss.tools.hibernate3_5.console;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.OverrideRepository;
+import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
+import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.launch.CodeGenerationStrings;
+import org.hibernate.eclipse.launch.CodeGenerationUtils;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.ide.completion.HQLCodeAssist;
+import org.hibernate.tool.ide.completion.IHQLCodeAssist;
+import org.hibernate.util.ReflectHelper;
+import org.jboss.tools.hibernate3_5.HibernateExtension3_5;
+
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConsoleExtension3_5 implements ConsoleExtension {
+
+ private HibernateExtension3_5 hibernateExtension;
+
+ public ConsoleExtension3_5(){}
+
+ public void setHibernateException(HibernateExtension hibernateExtension){
+ this.hibernateExtension = (HibernateExtension3_5) hibernateExtension;
+ }
+
+ @Override
+ public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ if (!hibernateExtension.hasConfiguration()){
+ try {
+ hibernateExtension.build();
+ hibernateExtension.execute( new ExecutionContext.Command() {
+ public Object execute() {
+ if(hibernateExtension.hasConfiguration()) {
+ hibernateExtension.getConfiguration().buildMappings();
+ }
+ return null;
+ }
+ });
+ } catch (HibernateException e){
+ //FIXME
+ //String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
+ //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
+ }
+ }
+ IHQLCodeAssist hqlEval = new HQLCodeAssist(hibernateExtension.getConfiguration());
+ query = query.replace('\t', ' ');
+ hqlEval.codeComplete(query, currentOffset, requestor);
+ return new CompletionProposalsResult(requestor.getCompletionProposals(),
requestor.getLastErrorMessage());
+ }
+
+ /* (non-Javadoc)
+ * @see
org.hibernate.eclipse.console.ext.ConsoleExtension#launchExporters(org.hibernate.eclipse.console.ext.ILaunchConfiguration,
java.lang.String, org.hibernate.eclipse.console.ext.ILaunch,
org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void launchExporters(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ Assert.isNotNull(configuration);
+ Assert.isNotNull(monitor);
+ ExporterAttributes attributes = new ExporterAttributes(configuration);
+ List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
+ for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
+ ExporterFactory exFactory = iter.next();
+ if (!exFactory.isEnabled(configuration)) {
+ iter.remove();
+ }
+ }
+
+ try {
+ Set<String> outputDirectories = new HashSet<String>();
+ ExporterFactory[] exporters = exporterFactories.toArray( new
ExporterFactory[exporterFactories.size()] );
+ ArtifactCollector collector = runExporters(attributes, exporters,
outputDirectories, monitor);
+
+ for (String path : outputDirectories) {
+ CodeGenerationUtils.refreshOutputDir(path);
+ }
+
+ //RefreshTab.refreshResources(configuration, monitor);
+
+ // code formatting needs to happen *after* refresh to make sure eclipse will format
the uptodate files!
+ if(collector!=null) {
+ //formatGeneratedCode( monitor, collector );
+ }
+
+
+ } catch(Exception e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ } catch(NoClassDefFoundError e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e),
666));
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final
IProgressMonitor monitor)
+ throws CoreException
+ {
+
+
monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for
+ attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ ConsoleConfiguration cc =
KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
+ if (attributes.isReverseEngineer()) {
+ monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
+ }
+ final Configuration cfg = buildConfiguration(attributes, cc,
ResourcesPlugin.getWorkspace().getRoot());
+
+ monitor.worked(1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ return (ArtifactCollector) cc.execute(new Command() {
+
+ public Object execute() {
+ ArtifactCollector artifactCollector = new ArtifactCollector();
+
+ // Global properties
+ Properties props = new Properties();
+ props.put(CodeGenerationStrings.EJB3, "" +
attributes.isEJB3Enabled()); //$NON-NLS-1$
+ props.put(CodeGenerationStrings.JDK5, "" +
attributes.isJDK5Enabled()); //$NON-NLS-1$
+
+ for (int i = 0; i < exporterFactories.length; i++)
+ {
+
monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
+
+ Properties globalProperties = new Properties();
+ globalProperties.putAll(props);
+
+ Exporter exporter;
+ try {
+ exporter = exporterFactories[i].createConfiguredExporter(cfg,
attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties,
outputDirectories, artifactCollector);
+ } catch (CoreException e) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up
+ exporterFactories[i].getExporterDefinition(), e);
+ }
+
+ try {
+ exporter.start();
+ } catch(HibernateException he) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running
+ exporterFactories[i].getExporterDefinition().getDescription(), he);
+ }
+ monitor.worked(1);
+ }
+ return artifactCollector;
+ }
+
+ });
+
+
+ }
+
+
+ private Configuration buildConfiguration(final ExporterAttributes attributes,
ConsoleConfiguration cc, IWorkspaceRoot root) {
+ final boolean reveng = attributes.isReverseEngineer();
+ final String reverseEngineeringStrategy = attributes.getRevengStrategy();
+ final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
+ final IResource revengres = PathHelper.findMember( root,
attributes.getRevengSettings());
+
+ if(reveng) {
+ Configuration configuration = null;
+ if(cc.hasConfiguration()) {
+ configuration = cc.getConfiguration();
+ } else {
+ configuration = cc.buildWith( null, false );
+ }
+
+ final JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
+ Properties properties = configuration.getProperties();
+ cfg.setProperties( properties );
+ cc.buildWith(cfg,false);
+
+ cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
+
+ cc.execute(new Command() { // need to execute in the consoleconfiguration to let it
handle classpath stuff!
+
+ public Object execute() {
+ //todo: factor this setup of revengstrategy to core
+ ReverseEngineeringStrategy res = new DefaultReverseEngineeringStrategy();
+
+ OverrideRepository repository = null;
+
+ if(revengres!=null) {
+ File file = PathHelper.getLocation( revengres ).toFile();
+ repository = new OverrideRepository();
+ repository.addFile(file);
+ }
+
+ if (repository != null){
+ res = repository.getReverseEngineeringStrategy(res);
+ }
+
+ if(reverseEngineeringStrategy!=null &&
reverseEngineeringStrategy.trim().length()>0) {
+ res = loadreverseEngineeringStrategy(reverseEngineeringStrategy, res);
+ }
+
+ ReverseEngineeringSettings qqsettings = new ReverseEngineeringSettings(res)
+ .setDefaultPackageName(attributes.getPackageName())
+ .setDetectManyToMany( attributes.detectManyToMany() )
+ .setDetectOneToOne( attributes.detectOneToOne() )
+ .setDetectOptimisticLock( attributes.detectOptimisticLock() );
+
+ res.setSettings(qqsettings);
+
+ cfg.setReverseEngineeringStrategy( res );
+
+ cfg.readFromJDBC();
+ cfg.buildMappings();
+ return null;
+ }
+ });
+
+ return cfg;
+ } else {
+ cc.build();
+ final Configuration configuration = cc.getConfiguration();
+
+ cc.execute(new Command() {
+ public Object execute() {
+
+ configuration.buildMappings();
+ return configuration;
+ }
+ });
+ return configuration;
+ }
+ }
+
+ // TODO: merge with revstrategy load in JDBCConfigurationTask
+ @SuppressWarnings("unchecked")
+ private ReverseEngineeringStrategy loadreverseEngineeringStrategy(final String
className, ReverseEngineeringStrategy delegate) {
+ try {
+ Class<ReverseEngineeringStrategy> clazz =
ReflectHelper.classForName(className);
+ Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new
Class[] { ReverseEngineeringStrategy.class });
+ return constructor.newInstance(new Object[] { delegate });
+ }
+ catch (NoSuchMethodException e) {
+ try {
+ Class<?> clazz = ReflectHelper.classForName(className);
+ ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
+ return rev;
+ }
+ catch (Exception eq) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_default_noarg_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, eq);
+ }
+ }
+ catch (Exception e) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_one_argument_delegate_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, e);
+ }
+ }
+
+}
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java
(from rev 36273,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/EclipseHQLCompletionRequestor.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/EclipseHQLCompletionRequestor.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,151 @@
+/*
+ * 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.jboss.tools.hibernate3_5.console;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper;
+import org.hibernate.tool.ide.completion.HQLCompletionProposal;
+import org.hibernate.tool.ide.completion.IHQLCompletionRequestor;
+import org.hibernate.util.StringHelper;
+
+public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor {
+
+ private final List<ICompletionProposal> result = new
ArrayList<ICompletionProposal>();
+ private String lastErrorMessage;
+ private final int virtualOffset;
+
+ public EclipseHQLCompletionRequestor() {
+ virtualOffset = 0;
+ }
+
+ public EclipseHQLCompletionRequestor(int virtualOffset) {
+ this.virtualOffset = virtualOffset;
+ }
+
+ public List<ICompletionProposal> getCompletionProposals() {
+ return result;
+ }
+
+ public boolean accept(HQLCompletionProposal proposal) {
+ result.add(new CompletionProposal(proposal.getCompletion(), // replacementString
+ proposal.getReplaceStart()+virtualOffset, // replacementOffset
+ proposal.getReplaceEnd()-proposal.getReplaceStart(), // replacementLength
+ proposal.getCompletion().length(), // cursorPosition (relativeTo
replacementStart)
+ getImage(proposal),
+ getDisplayString(proposal),
+ null,
+ null));
+ return true;
+ }
+
+ private String getDisplayString(HQLCompletionProposal proposal) {
+ StringBuffer buf = new StringBuffer(proposal.getSimpleName());
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ if(proposal.getEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append(" - "); //$NON-NLS-1$
+ buf.append(StringHelper.qualifier( proposal.getEntityName() ));
+ } else if(proposal.getShortEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.ALIAS_REF:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ if(proposal.getEntityName().indexOf( "." )>=0) { //$NON-NLS-1$
+ buf.append( " - " + StringHelper.unqualify( proposal.getEntityName() ));
//$NON-NLS-1$
+ } else {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ break;
+ default:
+
+ }
+
+
+ return buf.toString();
+ }
+
+ private Image getImage(HQLCompletionProposal proposal) {
+ String key = null;
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ case HQLCompletionProposal.ALIAS_REF:
+ key = ImageConstants.MAPPEDCLASS;
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ if(proposal.getProperty()!=null) {
+ return HibernateWorkbenchHelper.getImage( proposal.getProperty() );
+ } else {
+ key = ImageConstants.PROPERTY;
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ key = null;
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ key = ImageConstants.FUNCTION;
+ break;
+ default:
+ key = null;
+ }
+
+ return key==null?null:EclipseImages.getImage( key );
+ }
+
+ public void completionFailure(String errorMessage) {
+ lastErrorMessage = errorMessage;
+ }
+
+ public String getLastErrorMessage() {
+ return lastErrorMessage;
+ }
+
+ public void clear() {
+ result.clear();
+ lastErrorMessage = null;
+ }
+
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterAttributes.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterAttributes.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterAttributes.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,406 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate3_5.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+
+// This class was created to centralize launch configuration attribute loading/saving
+// (and also to clean up CodeGenerationLaunchDelegate considerably)
+public class ExporterAttributes
+{
+ private boolean reverseEngineer, useOwnTemplates, enableJDK5, enableEJB3,
preferBasicCompositeIds;
+ private boolean useExternalProcess;
+ private String consoleConfigurationName;
+ private String revengSettings;
+ private String revengStrategy;
+ private String packageName;
+ private String outputPath;
+ private String templatePath;
+ private List<ExporterFactory> exporterFactories;
+
+ private boolean autoManyToManyDetection;
+ private boolean autoOneToOneDetection;
+ private boolean autoVersioning;
+
+ public ExporterAttributes () { }
+
+ public ExporterAttributes (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ initialize(configuration);
+ }
+
+ public void initialize (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ try {
+ consoleConfigurationName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,"");
//$NON-NLS-1$
+ outputPath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,"");
//$NON-NLS-1$
+ reverseEngineer =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, false);
+ revengSettings =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
""); //$NON-NLS-1$
+ revengStrategy =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
""); //$NON-NLS-1$
+ useOwnTemplates =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,false);
+ useExternalProcess =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_EXTERNAL_PROCESS, false);
+ enableJDK5 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5,false);
+ enableEJB3 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,false);
+ packageName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,"");
//$NON-NLS-1$
+ templatePath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,"");
//$NON-NLS-1$
+ preferBasicCompositeIds =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
true);
+ autoManyToManyDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY, true);
+ autoOneToOneDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE, true);
+ autoVersioning = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING, true);
+
+
+ if (!useOwnTemplates) {
+ templatePath = null;
+ }
+
+ exporterFactories = readExporterFactories(configuration);
+ } catch (CoreException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ }
+ }
+
+ public static String getLaunchAttributePrefix(String exporterId) {
+ return HibernateLaunchConstants.ATTR_EXPORTERS + "." + exporterId;
//$NON-NLS-1$
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<ExporterFactory> readExporterFactories(ILaunchConfiguration
configuration) throws CoreException {
+
+ List<String> exporterNames =
configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null);
+
+ if(exporterNames!=null) {
+ Map<String, ExporterDefinition> exDefinitions =
ExtensionManager.findExporterDefinitionsAsMap();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (String exporterId : exporterNames) {
+ String extensionId =
configuration.getAttribute(getLaunchAttributePrefix(exporterId) +
".extension_id", (String)null); //$NON-NLS-1$
+
+ ExporterDefinition expDef = exDefinitions.get(extensionId);
+ if(expDef==null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in,
extensionId, configuration.getName());
+ throw new HibernateConsoleRuntimeException(out);
+ } else {
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, exporterId );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+ }
+ return factories;
+
+ } else {
+ // fall back to old way of reading if list of exporters does not exist.
+ ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (int i = 0; i < exDefinitions.length; i++) {
+ ExporterDefinition expDef = exDefinitions[i];
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, expDef.getId() );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+
+ return factories;
+ }
+ }
+
+ public static void saveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, Set<ExporterFactory>
enabledExporters, Set<String> deletedExporterIds) {
+
+
+ List<String> names = new ArrayList<String>();
+ for (ExporterFactory ef : exporterFactories) {
+ configuration.setAttribute(getLaunchAttributePrefix(ef.getId()) +
".extension_id", ef.getExporterDefinition().getId()); //$NON-NLS-1$
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = getLaunchAttributePrefix(ef.getId()) + ".properties";
//$NON-NLS-1$
+ names.add(ef.getId());
+ ef.setEnabled( configuration, enabled, false );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+
+ deletedExporterIds.removeAll(names);
+
+ for (String deleted : deletedExporterIds) {
+ configuration.setAttribute( getLaunchAttributePrefix( deleted ), (String)null);
+ configuration.setAttribute(getLaunchAttributePrefix(deleted ) +
".extension_id", (String)null); //$NON-NLS-1$
+ configuration.setAttribute(getLaunchAttributePrefix(deleted) +
".properties", (String)null); //$NON-NLS-1$
+ }
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, names);
+ }
+
+ public static void oldSaveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, List<ExporterFactory>
enabledExporters) {
+
+ for (ExporterFactory ef : exporterFactories) {
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = ef.getId() + ".properties"; //$NON-NLS-1$
+
+ ef.setEnabled( configuration, enabled, true );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+ }
+
+
+ private Path pathOrNull(String p) {
+ if(p==null || p.trim().length()==0) {
+ return null;
+ } else {
+ return new Path(p);
+ }
+ }
+
+ public String getOutputPath()
+ {
+ return outputPath;
+ }
+
+ public void setOutputPath(String outputPath)
+ {
+ this.outputPath = outputPath;
+ }
+
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ public String getRevengSettings()
+ {
+ return revengSettings;
+ }
+
+ public void setRevengSettings(String revengSettings)
+ {
+ this.revengSettings = revengSettings;
+ }
+
+ public String getRevengStrategy()
+ {
+ return revengStrategy;
+ }
+
+ public void setRevengStrategy(String revengStrategy)
+ {
+ this.revengStrategy = revengStrategy;
+ }
+
+ public String getTemplatePath()
+ {
+ return templatePath;
+ }
+
+ public void setTemplatePath(String templatePath)
+ {
+ this.templatePath = templatePath;
+ }
+
+ public String getConsoleConfigurationName()
+ {
+ return consoleConfigurationName;
+ }
+
+ public void setConsoleConfigurationName(String consoleConfigurationName)
+ {
+ this.consoleConfigurationName = consoleConfigurationName;
+ }
+
+ public boolean isEJB3Enabled()
+ {
+ return enableEJB3;
+ }
+
+ public void setEnableEJB3(boolean enableEJB3)
+ {
+ this.enableEJB3 = enableEJB3;
+ }
+
+ public boolean isJDK5Enabled()
+ {
+ return enableJDK5;
+ }
+
+ public void setEnableJDK5(boolean enableJDK5)
+ {
+ this.enableJDK5 = enableJDK5;
+ }
+
+ public boolean isPreferBasicCompositeIds()
+ {
+ return preferBasicCompositeIds;
+ }
+
+ public void setPreferBasicCompositeIds(boolean preferBasicCompositeIds)
+ {
+ this.preferBasicCompositeIds = preferBasicCompositeIds;
+ }
+
+ public boolean isReverseEngineer()
+ {
+ return reverseEngineer;
+ }
+
+ public void setReverseEngineer(boolean reverseEngineer)
+ {
+ this.reverseEngineer = reverseEngineer;
+ }
+
+ public boolean isUseOwnTemplates()
+ {
+ return useOwnTemplates;
+ }
+
+ public void setUseOwnTemplates(boolean useOwnTemplates)
+ {
+ this.useOwnTemplates = useOwnTemplates;
+ }
+
+ public boolean isUseExternalProcess()
+ {
+ return useExternalProcess;
+ }
+
+ public void setUseExternalProcess(boolean useExternalProcess)
+ {
+ this.useExternalProcess = useExternalProcess;
+ }
+
+ public List<ExporterFactory> getExporterFactories() {
+ return exporterFactories;
+ }
+
+ public boolean detectManyToMany() {
+ return autoManyToManyDetection;
+ }
+
+ public boolean detectOptimisticLock() {
+ return autoVersioning;
+ }
+
+ public boolean detectOneToOne() {
+ return autoOneToOneDetection;
+ }
+
+ /**
+ * Check exporter attributes and return message with description what is wrong with
attributes.
+ *
+ * @return message
+ */
+ public String checkExporterAttributes() {
+ String msg = null;
+ boolean notSelected = consoleConfigurationName == null ||
consoleConfigurationName.length() <= 0;
+ if (notSelected) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_console_cfg_must_be_specified;
+ }
+ if (msg == null) {
+ msg = PathHelper.checkDirectory(outputPath,
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, true);
+ }
+ if (msg == null) {
+ if (reverseEngineer && packageName.length() > 0) {
+ IStatus val= JavaConventions.validatePackageName(packageName);
+ if (val.getSeverity() == IStatus.ERROR || val.getSeverity() ==
IStatus.WARNING) {
+ msg = val.getMessage();
+ }
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && revengSettings.trim().length() > 0) {
+ msg = PathHelper.checkFile(revengSettings,
HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_3, true);
+ }
+ }
+ if (msg == null) {
+ if (useOwnTemplates) {
+ msg = PathHelper.checkDirectory(templatePath,
HibernateConsoleMessages.CodeGenerationSettingsTab_template_dir, true);
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && !preferBasicCompositeIds) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_script_can_not_be_generated_correctly_without;
+ }
+ }
+ return msg;
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterDefinition.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterDefinition.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterDefinition.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,181 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate3_5.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.tool.hbm2x.Exporter;
+
+/**
+ * Represents what is specified in plugin.xml about possible exporters.
+ *
+ */
+public class ExporterDefinition {
+
+ private String classname;
+
+ private String description;
+
+ private String id;
+
+ private ImageDescriptor iconDescriptor;
+
+ private Map<String, ExporterProperty> properties;
+
+ private IConfigurationElement element;
+
+ public ExporterDefinition(IConfigurationElement element) {
+ init(element.getAttribute( "classname" ), //$NON-NLS-1$
+ element.getAttribute( "description" ), //$NON-NLS-1$
+ element.getAttribute( "id" ), //$NON-NLS-1$
+ createProperties( element ),
+ createIcon( element ));
+ this.element = element;
+ }
+
+ protected void init(String className, String description, String id, Map<String,
ExporterProperty> properties, ImageDescriptor icon) {
+ this.classname = className;
+ this.description = description;
+ this.id = id;
+ this.properties = properties;
+ this.iconDescriptor = icon;
+ }
+
+ static private ImageDescriptor createIcon(IConfigurationElement element) {
+ if ( element.getAttribute( "icon" ) != null ) { //$NON-NLS-1$
+ return AbstractUIPlugin.imageDescriptorFromPlugin(
+ element.getNamespace(), element.getAttribute( "icon" ) ); //$NON-NLS-1$
+ } else {
+ return null;
+ }
+ }
+
+ static private Map<String, ExporterProperty>
createProperties(IConfigurationElement element) {
+ Map<String, ExporterProperty> properties = new HashMap<String,
ExporterProperty>();
+
+ IConfigurationElement propertyElements[] = element
+ .getChildren( "property" ); //$NON-NLS-1$
+ for (int i = 0; i < propertyElements.length; i++) {
+ ExporterProperty property = new ExporterProperty(
+ propertyElements[i].getAttribute("name"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("description"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("value"), //$NON-NLS-1$
+ Boolean.valueOf(propertyElements[i].getAttribute("required")).booleanValue());
//$NON-NLS-1$
+ String type = propertyElements[i].getAttribute("type"); //$NON-NLS-1$
+ if (type != null){
+ property.setType(type);
+ }
+ properties.put(property.getName(),property);
+ }
+ return properties;
+ }
+
+
+ public Exporter createExporterInstance() {
+ Exporter exporter = null;
+
+ try {
+ exporter = (Exporter) ReflectHelper.classForName( classname ).newInstance();
+ }
+ catch (InstantiationException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+ catch (IllegalAccessException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname)); }
+ catch (ClassNotFoundException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+
+ return exporter;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public ImageDescriptor getIconDescriptor() {
+ return iconDescriptor;
+ }
+
+ public Map<String, ExporterProperty> getExporterProperties() {
+ return properties;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ // if we put this in some "namespace" we should have a way to either
+ // migrate an existing one...
+ enabled = configuration.getAttribute( id, false );
+ }
+ catch (CoreException e) {
+ // log and assume false
+ HibernateConsolePlugin.getDefault().log(e);
+ return false;
+ }
+
+ return enabled;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getExporterTag() {
+ return getId().substring(getId().lastIndexOf(".") + 1); //$NON-NLS-1$
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterFactory.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterFactory.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExporterFactory.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,363 @@
+package org.jboss.tools.hibernate3_5.console;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.model.impl.ExporterFactoryStrings;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.GenericExporter;
+import org.hibernate.tool.hbm2x.Hbm2DDLExporter;
+import org.hibernate.tool.hbm2x.QueryExporter;
+
+/**
+ * ExporterFactory is used in UI to hold additional configuration for Exporter
definitions
+ * @author max
+ *
+ */
+public class ExporterFactory {
+
+ private ExporterDefinition definition;
+
+ final Map<String, String> inputProperties;
+
+ private boolean enabled = true;
+
+ private final String exporterId;
+
+ public ExporterFactory(ExporterDefinition definition, String exporterId) {
+ this.definition = definition;
+ this.exporterId = exporterId;
+ inputProperties = new HashMap<String, String>();
+ }
+
+ public Map<String, ExporterProperty> getDefaultExporterProperties() {
+ return definition.getExporterProperties();
+ }
+
+ public String setProperty(String key, String value) {
+ return inputProperties.put( key, value );
+ }
+
+ public void removeProperty(String propertyName) {
+ inputProperties.remove( propertyName );
+ }
+
+ public String getPropertyValue(String key) {
+ if(inputProperties.containsKey( key )) {
+ return inputProperties.get( key );
+ } else {
+ ExporterProperty ep = definition.getExporterProperties().get( key );
+ if(ep!=null) {
+ return ep.getDefaultValue();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public boolean isEnabled() {
+ return enabled ;
+ }
+
+ public void setEnabled(boolean b) {
+ enabled = b;
+ }
+
+ public ExporterDefinition getExporterDefinition() {
+ return definition;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ enabled = configuration.getAttribute( getId(), false );
+ } else {
+ enabled =
configuration.getAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()), false);
+ }
+ } catch(CoreException ce) {
+ // ignore; assume false
+ enabled=false;
+ }
+
+ setEnabled( enabled );
+ return isEnabled();
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled,
boolean oldSettings) {
+ setEnabled( enabled );
+ if(oldSettings) {
+ configuration.setAttribute( getId(), isEnabled() );
+ } else {
+ configuration.setAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()),
isEnabled());
+ }
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled)
{
+
+ boolean oldSettings = true;
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ oldSettings = true;
+ } else {
+ oldSettings = false;
+ }
+ } catch(CoreException ce) {
+ // ignore and assume settings are old
+ }
+
+ setEnabled(configuration, enabled, oldSettings);
+ }
+
+ public Map<String, String> getProperties() {
+ return inputProperties;
+ }
+
+ public String getId() {
+ return exporterId;
+ }
+
+ public String getExporterTag() {
+ return definition.getExporterTag();
+ }
+
+ public String getExporterDefinitionId() {
+ return definition.getId();
+ }
+
+ public void setProperties(Map<String, String> props) {
+ inputProperties.clear();
+ inputProperties.putAll( props );
+ }
+
+ public ExporterProperty getExporterProperty(String key) {
+ return definition.getExporterProperties().get( key );
+ }
+
+ public boolean hasLocalValueFor(String string) {
+ return inputProperties.containsKey( string );
+ }
+
+ /** Method that resolves an expression through eclipses built-in variable manager.
+ * @throws CoreException if expression could not be evaluated. */
+ public static String resolve(String expression) throws CoreException {
+ if (expression == null) {
+ return null;
+ }
+ IStringVariableManager variableManager =
VariablesPlugin.getDefault().getStringVariableManager();
+ return variableManager.performStringSubstitution(expression, false);
+ }
+
+ /**
+ * ExporterFactory update a collection of output directories,
+ * true if new output directory was added into the set of outputDirs.
+ *
+ * @param defOutDir
+ * @param globalProps
+ * @param outputDirs
+ * @return true if new output directory added
+ * @throws CoreException
+ */
+ public boolean collectOutputDirectories(String defOutDir, final Properties globalProps,
+ Set<String> outputDirs) throws CoreException {
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProps);
+ props.putAll(getProperties());
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+ String outputPath = defOutDir;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ boolean res = false;
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ res = outputDirs.add(loc);
+ }
+ return res;
+ }
+
+ /**
+ * Creates exporter with the specified settings; also resolves any relevant properties
via Eclipse VariablesPlugin.
+ * @param collector
+ * @throws CoreException in case of resolve variables issues.
+ */
+ public Exporter createConfiguredExporter(Configuration cfg, String
defaultOutputDirectory,
+ String customTemplatePath, Properties globalProperties, Set<String>
outputDirectories, ArtifactCollector collector) throws CoreException {
+
+ Exporter exporter = getExporterDefinition().createExporterInstance();
+
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProperties);
+ props.putAll(getProperties());
+
+ exporter.setProperties(props);
+ exporter.setArtifactCollector(collector);
+
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+
+ String outputPath = defaultOutputDirectory;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ if (outputPath != null && loc == null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_output_dir_in_does_not_exist,
+ resolvedOutputDir, getExporterDefinition().getDescription());
+ throw new HibernateConsoleRuntimeException(out);
+ }
+
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ outputDirectories.add(loc);
+ exporter.setOutputDirectory(new File(loc));
+ }
+
+ exporter.setConfiguration(cfg);
+
+ List<String> templatePathList = new ArrayList<String>();
+ if (extract.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ String resolveTemplatePath =
resolve(extract.getProperty(ExporterFactoryStrings.TEMPLATE_PATH));
+ StringTokenizer st = new StringTokenizer(resolveTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath == null) {
+ out +=
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolveTemplatePath, getExporterDefinition().getDescription()) +
'\n';
+ } else {
+ templatePathList.add(locationAsStringPath);
+ }
+ }
+ if (out.length() > 0 ){
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+
+ if (StringHelper.isNotEmpty(customTemplatePath)) {
+ String resolvedCustomTemplatePath = resolve(customTemplatePath);
+ StringTokenizer st = new StringTokenizer(resolvedCustomTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath != null) {
+ templatePathList.add(locationAsStringPath);
+ } else {
+ out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolvedCustomTemplatePath, getExporterDefinition().getDescription());
+ }
+ }
+ if (!("".equals(out))) { //$NON-NLS-1$
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+ exporter.setTemplatePath(templatePathList.toArray(new
String[templatePathList.size()]));
+ // special handling for GenericExporter (TODO: be delegated via plugin.xml)
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbmtemplate")) {
//$NON-NLS-1$
+ GenericExporter ge = (GenericExporter) exporter;
+ ge.setFilePattern(extract.getProperty(ExporterFactoryStrings.FILE_PATTERN));
+ ge.setTemplateName(extract.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
+ ge.setForEach(extract.getProperty(ExporterFactoryStrings.FOR_EACH));
+ }
+ // special handling for Hbm2DDLExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbm2ddl")) {
//$NON-NLS-1$
+ Hbm2DDLExporter ddlExporter = (Hbm2DDLExporter) exporter;
+ //avoid users to delete their databases with a single click
+ ddlExporter.setExport(Boolean.parseBoolean(extract.getProperty(ExporterFactoryStrings.EXPORTTODATABASE)));
+ }
+ // special handling for QueryExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.query")) {
//$NON-NLS-1$
+ QueryExporter queryExporter = (QueryExporter) exporter;
+ List<String> queryStrings = new ArrayList<String>();
+ queryStrings.add(extract.getProperty(ExporterFactoryStrings.QUERY_STRING,
"")); //$NON-NLS-1$
+ queryExporter.setQueries(queryStrings);
+ queryExporter.setFilename(extract.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
+ }
+ return exporter;
+ }
+
+ /**
+ * Extract and update GUI specific exporter properties
+ *
+ * @param exporterId
+ * @param props - properties which values remain
+ * @param extract - separated updated properties
+ * @throws CoreException
+ */
+ public static void extractExporterProperties(
+ String exporterId, Properties props, Properties extract) throws CoreException {
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ extract.put(ExporterFactoryStrings.OUTPUTDIR,
resolve(props.getProperty(ExporterFactoryStrings.OUTPUTDIR)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ extract.put(ExporterFactoryStrings.TEMPLATE_PATH,
resolve(props.getProperty(ExporterFactoryStrings.TEMPLATE_PATH)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.TEMPLATE_PATH);
+ }
+ if (exporterId.equals("org.hibernate.tools.hbmtemplate")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.FILE_PATTERN)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FILE_PATTERN, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FILE_PATTERN, tmp);
+ props.remove(ExporterFactoryStrings.FILE_PATTERN);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_NAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.TEMPLATE_NAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.TEMPLATE_NAME, tmp);
+ props.remove(ExporterFactoryStrings.TEMPLATE_NAME);
+ }
+ if (props.containsKey(ExporterFactoryStrings.FOR_EACH)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FOR_EACH, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FOR_EACH, tmp);
+ props.remove(ExporterFactoryStrings.FOR_EACH);
+ }
+ }
+ // special handling for Hbm2DDLExporter
+ if (exporterId.equals("org.hibernate.tools.hbm2ddl")) { //$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.EXPORTTODATABASE,
props.getProperty(ExporterFactoryStrings.EXPORTTODATABASE, Boolean.toString(false)));
+ props.remove(ExporterFactoryStrings.EXPORTTODATABASE);
+ }
+ // special handling for QueryExporter
+ if (exporterId.equals("org.hibernate.tools.query")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.QUERY_STRING)) {
+ tmp = props.getProperty(ExporterFactoryStrings.QUERY_STRING, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.QUERY_STRING, tmp);
+ props.remove(ExporterFactoryStrings.QUERY_STRING);
+ }
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTFILENAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.OUTPUTFILENAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.OUTPUTFILENAME, tmp);
+ props.remove(ExporterFactoryStrings.OUTPUTFILENAME);
+ }
+ }
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExtensionManager.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExtensionManager.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate3_5/src/org/jboss/tools/hibernate3_5/console/ExtensionManager.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,97 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate3_5.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public class ExtensionManager
+{
+ public static final String EXPORTERS_EXTENSION_ID =
"org.hibernate.eclipse.console.exporters"; //$NON-NLS-1$
+
+ private static IExtension[] findExtensions (String extensionId)
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionId);
+ return extensionPoint.getExtensions();
+ }
+
+ public static ExporterDefinition[] findExporterDefinitions ()
+ {
+ List<ExporterDefinition> exporters = new
ArrayList<ExporterDefinition>();
+
+ IExtension[] extensions = findExtensions(EXPORTERS_EXTENSION_ID);
+ for (int i = 0; i < extensions.length; i++)
+ {
+ IConfigurationElement elements[] = extensions[i].getConfigurationElements();
+ for (int j = 0; j < elements.length; j++)
+ {
+ ExporterDefinition exporter = new ExporterDefinition(elements[j]);
+ exporters.add(exporter);
+ }
+ }
+
+ return exporters.toArray(new ExporterDefinition[exporters.size()]);
+ }
+
+ /**
+ * return map of ExporterDefinitions keyed by id
+ */
+ public static Map<String, ExporterDefinition> findExporterDefinitionsAsMap() {
+ Map<String, ExporterDefinition> result = new HashMap<String,
ExporterDefinition>();
+
+ ExporterDefinition[] findExporterDefinitions = findExporterDefinitions();
+ for (int i = 0; i < findExporterDefinitions.length; i++) {
+ ExporterDefinition exporterDefinition = findExporterDefinitions[i];
+ result.put(exporterDefinition.getId(), exporterDefinition);
+ }
+
+ return result;
+ }
+}
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/META-INF/MANIFEST.MF 2011-11-11
12:44:47 UTC (rev 36298)
@@ -10,7 +10,10 @@
org.hibernate.eclipse;bundle-version="3.4.0",
org.eclipse.datatools.connectivity;bundle-version="1.2.2",
org.hibernate.eclipse.console;bundle-version="3.4.0",
- org.eclipse.jface.text;bundle-version="3.7.0"
+ org.eclipse.jface.text;bundle-version="3.7.0",
+ org.eclipse.debug.core;bundle-version="3.7.0",
+ org.eclipse.core.variables;bundle-version="3.2.500",
+ org.eclipse.jdt.core;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: lib/required/jboss-logging-3.0.0.GA.jar,
Modified:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/plugin.xml
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/plugin.xml 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/plugin.xml 2011-11-11
12:44:47 UTC (rev 36298)
@@ -11,7 +11,7 @@
<extension
point="org.hibernate.eclipse.console.consoleextension">
<consoleextension
- classname="org.jboss.tools.hibernate4_0.ConsoleExtension4_0"
+
classname="org.jboss.tools.hibernate4_0.console.ConsoleExtension4_0"
version="%hibernate.version">
</consoleextension>
</extension>
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/CompletionProposal.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/CompletionProposal.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/CompletionProposal.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,279 +0,0 @@
-/*
- * 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.jboss.tools.hibernate4_0;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.hibernate.eclipse.console.HibernateConsolePlugin;
-
-/**
- * Generic completion proposal to be used as is, or as base for other completion
proposals.
- *
- * @author Max Rydahl Andersen
- *
- */
-public class CompletionProposal implements ICompletionProposal,
ICompletionProposalExtension {
-
- private String displayString;
- private String replacementString;
- private int replacementOffset;
- private int documentOffset = -1;
- private int replacementLength;
- private int cursorPosition;
- private Image image;
- private IContextInformation contextInformation;
- private int contextInformationPosition;
- private char[] triggerCharacters;
- private String additionalProposalInfo;
-
- /**
- * Creates a new completion proposal. All fields are initialized based on
- * the provided information.
- *
- * @param additionalInfo additional information about the completion proposal
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset offset of the text to be replaced
- * @param documentOffset offset of the document
- * @param replacementLength length of the text to be replaced
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal If set
- * to <code>null</code>, the replacement string will be taken
- * as display string.
- */
- public CompletionProposal( String additionalInfo, String replacementString, int
replacementOffset,
- int documentOffset, int replacementLength, Image image, String
displayString,
- IContextInformation contextInformation ) {
-
- this.replacementString = replacementString;
- this.replacementOffset = replacementOffset;
- this.documentOffset = documentOffset;
- this.replacementLength = replacementLength;
- this.image = image;
- this.displayString = displayString != null ? displayString : replacementString;
-
- this.cursorPosition = replacementString.length();
-
- this.contextInformation = contextInformation;
-
- this.triggerCharacters = null;
- this.additionalProposalInfo = additionalInfo;
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on
- * the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset the offset of the text to be replaced
- * @param replacementLength the length of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert
- * relative to replacementOffset
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param contentInformation the context information associated with this proposal
- * @param additionalProposalInfo the additional information associated with
- * this proposal
- */
- public CompletionProposal( String replacementString, int replacementOffset, int
replacementLength,
- int cursorPosition, Image image, String displayString, IContextInformation
contextInformation,
- String additionalProposalInfo ) {
-
- this.replacementString = replacementString;
- this.replacementOffset = replacementOffset;
- this.documentOffset = replacementOffset;
- this.replacementLength = replacementLength;
- this.cursorPosition = cursorPosition;
- this.image = image;
- this.displayString = displayString;
- this.contextInformation = contextInformation;
- this.additionalProposalInfo = additionalProposalInfo;
-
- }
-
- public void setContextInformation( IContextInformation contextInformation ) {
- this.contextInformation = contextInformation;
- contextInformationPosition = (contextInformation != null ? cursorPosition : -1);
- }
-
- /**
- * Sets the trigger characters.
- *
- * @param triggerCharacters The set of characters which can trigger the
- * application of this completion proposal
- */
- public void setTriggerCharacters( char[] triggerCharacters ) {
- this.triggerCharacters = triggerCharacters;
- }
-
- /**
- * Sets the cursor position relative to the insertion offset. By default
- * this is the length of the completion string (Cursor positioned after the
- * completion)
- *
- * @param cursorPosition The cursorPosition to set
- */
- public void setCursorPosition( int cursorPosition ) {
-
- if (cursorPosition >= 0) {
- this.cursorPosition = cursorPosition;
- this.contextInformationPosition = (contextInformation != null ?
cursorPosition : -1);
- }
- }
-
- public void apply( IDocument document, char trigger, int offset ) {
- try {
- // patch replacement length
-
- int delta = offset - (documentOffset + replacementLength);
- if (delta > 0)
- replacementLength += delta;
-
- if (trigger == (char) 0) {
- replace( document, documentOffset, replacementLength, replacementString
);
- }
- else {
- StringBuffer buffer = new StringBuffer( replacementString );
-
- if ((replacementLength < buffer.length() && buffer.charAt(
replacementLength ) != trigger)) {
- buffer.insert( cursorPosition, trigger );
- ++cursorPosition;
- }
-
- replace( document, documentOffset, replacementLength, buffer.toString()
);
- }
-
- int oldLen = document.getLength();
- documentOffset += document.getLength() - oldLen;
- }
- catch (BadLocationException e) {
- HibernateConsolePlugin.getDefault().log( e );
- }
- }
-
- /**
- * Replaces the document content at the specified offset and length with the
- * specified string.
- *
- * @param document the document opened in the editor
- * @param offset offset to the document content to be replaced
- * @param length length of text to be replaced
- * @param string replacement string
- * @throws BadLocationException
- */
- private void replace( IDocument document, int offset, int length, String string )
throws BadLocationException {
- if (document != null && string != null && offset >= 0
&& length >= 0) {
- if (!document.get( offset, length ).equals( string ))
- document.replace( offset, length, string );
- }
- }
-
- public void apply( IDocument document ) {
- apply( document, (char) 0, documentOffset + replacementLength );
- }
-
- public Point getSelection( IDocument document ) {
- return new Point( documentOffset + cursorPosition, 0 );
- }
-
- public IContextInformation getContextInformation() {
- return contextInformation;
- }
-
- public Image getImage() {
- return image;
- }
-
- public String getDisplayString() {
- return displayString;
- }
-
- public String getAdditionalProposalInfo() {
- return additionalProposalInfo;
- }
-
- public char[] getTriggerCharacters() {
- return triggerCharacters;
- }
-
- public int getContextInformationPosition() {
- return replacementOffset + contextInformationPosition;
- }
-
- public int getReplacementOffset() {
- return replacementOffset;
- }
-
- public void setReplacementOffset( int replacementOffset ) {
-
- if (replacementOffset >= 0) {
- this.replacementOffset = replacementOffset;
- }
- }
-
- public int getReplacementLength() {
- return replacementLength;
- }
-
- public void setReplacementLength( int replacementLength ) {
-
- if (replacementLength >= 0) {
- this.replacementLength = replacementLength;
- }
- }
-
- public String getReplacementString() {
- return replacementString;
- }
-
- public void setReplacementString( String replacementString ) {
- this.replacementString = replacementString;
- }
-
- public void setImage( Image image ) {
- this.image = image;
- }
-
- public boolean isValidFor( IDocument document, int offset ) {
- if (offset < replacementOffset)
- return false;
-
- int replacementLength = replacementString == null ? 0 :
replacementString.length();
- if (offset >= replacementOffset + replacementLength)
- return false;
-
- try {
- int length = offset - replacementOffset;
- String start = document.get( replacementOffset, length );
- return replacementString.substring( 0, length ).equalsIgnoreCase( start );
- }
- catch (BadLocationException x) {
- }
-
- return false;
- }
-
-}
\ No newline at end of file
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConsoleExtension4_0.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConsoleExtension4_0.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConsoleExtension4_0.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * 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.jboss.tools.hibernate4_0;
-
-import org.hibernate.console.execution.ExecutionContext;
-import org.hibernate.console.ext.HibernateException;
-import org.hibernate.console.ext.HibernateExtension;
-import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
-import org.hibernate.eclipse.console.ext.ConsoleExtension;
-import org.hibernate.tool.ide.completion.HQLCodeAssist;
-import org.hibernate.tool.ide.completion.IHQLCodeAssist;
-
-/**
- * @author Dmitry Geraskov
- *
- */
-public class ConsoleExtension4_0 implements ConsoleExtension {
-
- private HibernateExtension4_0 hibernateExtension;
-
- public ConsoleExtension4_0(){}
-
- public void setHibernateException(HibernateExtension hibernateExtension){
- this.hibernateExtension = (HibernateExtension4_0) hibernateExtension;
- }
-
- @Override
- public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
- EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
- if (!hibernateExtension.hasConfiguration()){
- try {
- hibernateExtension.build();
- hibernateExtension.execute( new ExecutionContext.Command() {
- public Object execute() {
- if(hibernateExtension.hasConfiguration()) {
- hibernateExtension.getConfiguration().buildMappings();
- }
- return null;
- }
- });
- } catch (HibernateException e){
- //FIXME
- //String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
- //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
- }
- }
- IHQLCodeAssist hqlEval = new HQLCodeAssist(hibernateExtension.getConfiguration());
- query = query.replace('\t', ' ');
- hqlEval.codeComplete(query, currentOffset, requestor);
- return new CompletionProposalsResult(requestor.getCompletionProposals(),
requestor.getLastErrorMessage());
- }
-
-
-
-}
Deleted:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/EclipseHQLCompletionRequestor.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/EclipseHQLCompletionRequestor.java 2011-11-11
12:13:18 UTC (rev 36297)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/EclipseHQLCompletionRequestor.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -1,151 +0,0 @@
-/*
- * 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.jboss.tools.hibernate4_0;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.swt.graphics.Image;
-import org.hibernate.console.ImageConstants;
-import org.hibernate.eclipse.console.utils.EclipseImages;
-import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper;
-import org.hibernate.internal.util.StringHelper;
-import org.hibernate.tool.ide.completion.HQLCompletionProposal;
-import org.hibernate.tool.ide.completion.IHQLCompletionRequestor;
-
-public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor {
-
- private final List<ICompletionProposal> result = new
ArrayList<ICompletionProposal>();
- private String lastErrorMessage;
- private final int virtualOffset;
-
- public EclipseHQLCompletionRequestor() {
- virtualOffset = 0;
- }
-
- public EclipseHQLCompletionRequestor(int virtualOffset) {
- this.virtualOffset = virtualOffset;
- }
-
- public List<ICompletionProposal> getCompletionProposals() {
- return result;
- }
-
- public boolean accept(HQLCompletionProposal proposal) {
- result.add(new CompletionProposal(proposal.getCompletion(), // replacementString
- proposal.getReplaceStart()+virtualOffset, // replacementOffset
- proposal.getReplaceEnd()-proposal.getReplaceStart(), // replacementLength
- proposal.getCompletion().length(), // cursorPosition (relativeTo
replacementStart)
- getImage(proposal),
- getDisplayString(proposal),
- null,
- null));
- return true;
- }
-
- private String getDisplayString(HQLCompletionProposal proposal) {
- StringBuffer buf = new StringBuffer(proposal.getSimpleName());
-
- switch(proposal.getCompletionKind()) {
- case HQLCompletionProposal.ENTITY_NAME:
- if(proposal.getEntityName()!=null &&
- !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
- buf.append(" - "); //$NON-NLS-1$
- buf.append(StringHelper.qualifier( proposal.getEntityName() ));
- } else if(proposal.getShortEntityName()!=null &&
- !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- }
- break;
- case HQLCompletionProposal.ALIAS_REF:
- if(proposal.getShortEntityName()!=null) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- } else if(proposal.getEntityName()!=null) {
- buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
- }
- break;
- case HQLCompletionProposal.PROPERTY:
- if(proposal.getShortEntityName()!=null) {
- buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
- } else if(proposal.getEntityName()!=null) {
- if(proposal.getEntityName().indexOf( "." )>=0) { //$NON-NLS-1$
- buf.append( " - " + StringHelper.unqualify( proposal.getEntityName() ));
//$NON-NLS-1$
- } else {
- buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
- }
- }
- break;
- case HQLCompletionProposal.KEYWORD:
- break;
- case HQLCompletionProposal.FUNCTION:
- break;
- default:
-
- }
-
-
- return buf.toString();
- }
-
- private Image getImage(HQLCompletionProposal proposal) {
- String key = null;
-
- switch(proposal.getCompletionKind()) {
- case HQLCompletionProposal.ENTITY_NAME:
- case HQLCompletionProposal.ALIAS_REF:
- key = ImageConstants.MAPPEDCLASS;
- break;
- case HQLCompletionProposal.PROPERTY:
- if(proposal.getProperty()!=null) {
- return HibernateWorkbenchHelper.getImage( proposal.getProperty() );
- } else {
- key = ImageConstants.PROPERTY;
- }
- break;
- case HQLCompletionProposal.KEYWORD:
- key = null;
- break;
- case HQLCompletionProposal.FUNCTION:
- key = ImageConstants.FUNCTION;
- break;
- default:
- key = null;
- }
-
- return key==null?null:EclipseImages.getImage( key );
- }
-
- public void completionFailure(String errorMessage) {
- lastErrorMessage = errorMessage;
- }
-
- public String getLastErrorMessage() {
- return lastErrorMessage;
- }
-
- public void clear() {
- result.clear();
- lastErrorMessage = null;
- }
-
-}
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CompletionProposal.java
(from rev 36159,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/CompletionProposal.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CompletionProposal.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/CompletionProposal.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,279 @@
+/*
+ * 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.jboss.tools.hibernate4_0.console;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+
+/**
+ * Generic completion proposal to be used as is, or as base for other completion
proposals.
+ *
+ * @author Max Rydahl Andersen
+ *
+ */
+public class CompletionProposal implements ICompletionProposal,
ICompletionProposalExtension {
+
+ private String displayString;
+ private String replacementString;
+ private int replacementOffset;
+ private int documentOffset = -1;
+ private int replacementLength;
+ private int cursorPosition;
+ private Image image;
+ private IContextInformation contextInformation;
+ private int contextInformationPosition;
+ private char[] triggerCharacters;
+ private String additionalProposalInfo;
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param additionalInfo additional information about the completion proposal
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset offset of the text to be replaced
+ * @param documentOffset offset of the document
+ * @param replacementLength length of the text to be replaced
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal If set
+ * to <code>null</code>, the replacement string will be taken
+ * as display string.
+ */
+ public CompletionProposal( String additionalInfo, String replacementString, int
replacementOffset,
+ int documentOffset, int replacementLength, Image image, String
displayString,
+ IContextInformation contextInformation ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = documentOffset;
+ this.replacementLength = replacementLength;
+ this.image = image;
+ this.displayString = displayString != null ? displayString : replacementString;
+
+ this.cursorPosition = replacementString.length();
+
+ this.contextInformation = contextInformation;
+
+ this.triggerCharacters = null;
+ this.additionalProposalInfo = additionalInfo;
+ }
+
+ /**
+ * Creates a new completion proposal. All fields are initialized based on
+ * the provided information.
+ *
+ * @param replacementString the actual string to be inserted into the document
+ * @param replacementOffset the offset of the text to be replaced
+ * @param replacementLength the length of the text to be replaced
+ * @param cursorPosition the position of the cursor following the insert
+ * relative to replacementOffset
+ * @param image the image to display for this proposal
+ * @param displayString the string to be displayed for the proposal
+ * @param contentInformation the context information associated with this proposal
+ * @param additionalProposalInfo the additional information associated with
+ * this proposal
+ */
+ public CompletionProposal( String replacementString, int replacementOffset, int
replacementLength,
+ int cursorPosition, Image image, String displayString, IContextInformation
contextInformation,
+ String additionalProposalInfo ) {
+
+ this.replacementString = replacementString;
+ this.replacementOffset = replacementOffset;
+ this.documentOffset = replacementOffset;
+ this.replacementLength = replacementLength;
+ this.cursorPosition = cursorPosition;
+ this.image = image;
+ this.displayString = displayString;
+ this.contextInformation = contextInformation;
+ this.additionalProposalInfo = additionalProposalInfo;
+
+ }
+
+ public void setContextInformation( IContextInformation contextInformation ) {
+ this.contextInformation = contextInformation;
+ contextInformationPosition = (contextInformation != null ? cursorPosition : -1);
+ }
+
+ /**
+ * Sets the trigger characters.
+ *
+ * @param triggerCharacters The set of characters which can trigger the
+ * application of this completion proposal
+ */
+ public void setTriggerCharacters( char[] triggerCharacters ) {
+ this.triggerCharacters = triggerCharacters;
+ }
+
+ /**
+ * Sets the cursor position relative to the insertion offset. By default
+ * this is the length of the completion string (Cursor positioned after the
+ * completion)
+ *
+ * @param cursorPosition The cursorPosition to set
+ */
+ public void setCursorPosition( int cursorPosition ) {
+
+ if (cursorPosition >= 0) {
+ this.cursorPosition = cursorPosition;
+ this.contextInformationPosition = (contextInformation != null ?
cursorPosition : -1);
+ }
+ }
+
+ public void apply( IDocument document, char trigger, int offset ) {
+ try {
+ // patch replacement length
+
+ int delta = offset - (documentOffset + replacementLength);
+ if (delta > 0)
+ replacementLength += delta;
+
+ if (trigger == (char) 0) {
+ replace( document, documentOffset, replacementLength, replacementString
);
+ }
+ else {
+ StringBuffer buffer = new StringBuffer( replacementString );
+
+ if ((replacementLength < buffer.length() && buffer.charAt(
replacementLength ) != trigger)) {
+ buffer.insert( cursorPosition, trigger );
+ ++cursorPosition;
+ }
+
+ replace( document, documentOffset, replacementLength, buffer.toString()
);
+ }
+
+ int oldLen = document.getLength();
+ documentOffset += document.getLength() - oldLen;
+ }
+ catch (BadLocationException e) {
+ HibernateConsolePlugin.getDefault().log( e );
+ }
+ }
+
+ /**
+ * Replaces the document content at the specified offset and length with the
+ * specified string.
+ *
+ * @param document the document opened in the editor
+ * @param offset offset to the document content to be replaced
+ * @param length length of text to be replaced
+ * @param string replacement string
+ * @throws BadLocationException
+ */
+ private void replace( IDocument document, int offset, int length, String string )
throws BadLocationException {
+ if (document != null && string != null && offset >= 0
&& length >= 0) {
+ if (!document.get( offset, length ).equals( string ))
+ document.replace( offset, length, string );
+ }
+ }
+
+ public void apply( IDocument document ) {
+ apply( document, (char) 0, documentOffset + replacementLength );
+ }
+
+ public Point getSelection( IDocument document ) {
+ return new Point( documentOffset + cursorPosition, 0 );
+ }
+
+ public IContextInformation getContextInformation() {
+ return contextInformation;
+ }
+
+ public Image getImage() {
+ return image;
+ }
+
+ public String getDisplayString() {
+ return displayString;
+ }
+
+ public String getAdditionalProposalInfo() {
+ return additionalProposalInfo;
+ }
+
+ public char[] getTriggerCharacters() {
+ return triggerCharacters;
+ }
+
+ public int getContextInformationPosition() {
+ return replacementOffset + contextInformationPosition;
+ }
+
+ public int getReplacementOffset() {
+ return replacementOffset;
+ }
+
+ public void setReplacementOffset( int replacementOffset ) {
+
+ if (replacementOffset >= 0) {
+ this.replacementOffset = replacementOffset;
+ }
+ }
+
+ public int getReplacementLength() {
+ return replacementLength;
+ }
+
+ public void setReplacementLength( int replacementLength ) {
+
+ if (replacementLength >= 0) {
+ this.replacementLength = replacementLength;
+ }
+ }
+
+ public String getReplacementString() {
+ return replacementString;
+ }
+
+ public void setReplacementString( String replacementString ) {
+ this.replacementString = replacementString;
+ }
+
+ public void setImage( Image image ) {
+ this.image = image;
+ }
+
+ public boolean isValidFor( IDocument document, int offset ) {
+ if (offset < replacementOffset)
+ return false;
+
+ int replacementLength = replacementString == null ? 0 :
replacementString.length();
+ if (offset >= replacementOffset + replacementLength)
+ return false;
+
+ try {
+ int length = offset - replacementOffset;
+ String start = document.get( replacementOffset, length );
+ return replacementString.substring( 0, length ).equalsIgnoreCase( start );
+ }
+ catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+}
\ No newline at end of file
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
(from rev 36275,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/ConsoleExtension4_0.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ConsoleExtension4_0.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,303 @@
+/*******************************************************************************
+ * 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.jboss.tools.hibernate4_0.console;
+
+import java.io.File;
+import java.lang.reflect.Constructor;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.JDBCMetaDataConfiguration;
+import org.hibernate.cfg.reveng.DefaultReverseEngineeringStrategy;
+import org.hibernate.cfg.reveng.OverrideRepository;
+import org.hibernate.cfg.reveng.ReverseEngineeringSettings;
+import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
+import org.hibernate.console.ConsoleConfiguration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.console.KnownConfigurations;
+import org.hibernate.console.execution.ExecutionContext;
+import org.hibernate.console.execution.ExecutionContext.Command;
+import org.hibernate.console.ext.HibernateException;
+import org.hibernate.console.ext.HibernateExtension;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.ext.CompletionProposalsResult;
+import org.hibernate.eclipse.console.ext.ConsoleExtension;
+import org.hibernate.eclipse.launch.CodeGenerationStrings;
+import org.hibernate.eclipse.launch.CodeGenerationUtils;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.ide.completion.HQLCodeAssist;
+import org.hibernate.tool.ide.completion.IHQLCodeAssist;
+import org.jboss.tools.hibernate4_0.HibernateExtension4_0;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class ConsoleExtension4_0 implements ConsoleExtension {
+
+ private HibernateExtension4_0 hibernateExtension;
+
+ public ConsoleExtension4_0(){}
+
+ public void setHibernateException(HibernateExtension hibernateExtension){
+ this.hibernateExtension = (HibernateExtension4_0) hibernateExtension;
+ }
+
+ @Override
+ public CompletionProposalsResult hqlCodeComplete(String query, int currentOffset) {
+ EclipseHQLCompletionRequestor requestor = new EclipseHQLCompletionRequestor();
+ if (!hibernateExtension.hasConfiguration()){
+ try {
+ hibernateExtension.build();
+ hibernateExtension.execute( new ExecutionContext.Command() {
+ public Object execute() {
+ if(hibernateExtension.hasConfiguration()) {
+ hibernateExtension.getConfiguration().buildMappings();
+ }
+ return null;
+ }
+ });
+ } catch (HibernateException e){
+ //FIXME
+ //String mess =
NLS.bind(HibernateConsoleMessages.CompletionHelper_error_could_not_build_cc,
consoleConfiguration.getName());
+ //HibernateConsolePlugin.getDefault().logErrorMessage(mess, e);
+ }
+ }
+ IHQLCodeAssist hqlEval = new HQLCodeAssist(hibernateExtension.getConfiguration());
+ query = query.replace('\t', ' ');
+ hqlEval.codeComplete(query, currentOffset, requestor);
+ return new CompletionProposalsResult(requestor.getCompletionProposals(),
requestor.getLastErrorMessage());
+ }
+
+ /* (non-Javadoc)
+ * @see
org.hibernate.eclipse.console.ext.ConsoleExtension#launchExporters(org.hibernate.eclipse.console.ext.ILaunchConfiguration,
java.lang.String, org.hibernate.eclipse.console.ext.ILaunch,
org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public void launchExporters(ILaunchConfiguration configuration,
+ String mode, ILaunch launch, IProgressMonitor monitor)
+ throws CoreException {
+ Assert.isNotNull(configuration);
+ Assert.isNotNull(monitor);
+ ExporterAttributes attributes = new ExporterAttributes(configuration);
+ List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
+ for (Iterator<ExporterFactory> iter = exporterFactories.iterator();
iter.hasNext();) {
+ ExporterFactory exFactory = iter.next();
+ if (!exFactory.isEnabled(configuration)) {
+ iter.remove();
+ }
+ }
+
+ try {
+ Set<String> outputDirectories = new HashSet<String>();
+ ExporterFactory[] exporters = exporterFactories.toArray( new
ExporterFactory[exporterFactories.size()] );
+ ArtifactCollector collector = runExporters(attributes, exporters,
outputDirectories, monitor);
+
+ for (String path : outputDirectories) {
+ CodeGenerationUtils.refreshOutputDir(path);
+ }
+
+ //RefreshTab.refreshResources(configuration, monitor);
+
+ // code formatting needs to happen *after* refresh to make sure eclipse will format
the uptodate files!
+ if(collector!=null) {
+ //formatGeneratedCode( monitor, collector );
+ }
+
+
+ } catch(Exception e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ } catch(NoClassDefFoundError e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e),
666));
+ } finally {
+ monitor.done();
+ }
+ }
+
+ private ArtifactCollector runExporters (final ExporterAttributes attributes, final
ExporterFactory[] exporterFactories, final Set<String> outputDirectories, final
IProgressMonitor monitor)
+ throws CoreException
+ {
+
+
monitor.beginTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_generating_code_for
+ attributes.getConsoleConfigurationName(), exporterFactories.length + 1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ ConsoleConfiguration cc =
KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
+ if (attributes.isReverseEngineer()) {
+ monitor.subTask(HibernateConsoleMessages.CodeGenerationLaunchDelegate_reading_jdbc_metadata);
+ }
+ final Configuration cfg = buildConfiguration(attributes, cc,
ResourcesPlugin.getWorkspace().getRoot());
+
+ monitor.worked(1);
+
+ if (monitor.isCanceled())
+ return null;
+
+ return (ArtifactCollector) cc.execute(new Command() {
+
+ public Object execute() {
+ ArtifactCollector artifactCollector = new ArtifactCollector();
+
+ // Global properties
+ Properties props = new Properties();
+ props.put(CodeGenerationStrings.EJB3, "" +
attributes.isEJB3Enabled()); //$NON-NLS-1$
+ props.put(CodeGenerationStrings.JDK5, "" +
attributes.isJDK5Enabled()); //$NON-NLS-1$
+
+ for (int i = 0; i < exporterFactories.length; i++)
+ {
+
monitor.subTask(exporterFactories[i].getExporterDefinition().getDescription());
+
+ Properties globalProperties = new Properties();
+ globalProperties.putAll(props);
+
+ Exporter exporter;
+ try {
+ //FIXME - the exporters are not the same here!
+ //may be need to create it using the data from exporter definition???
+ exporter = exporterFactories[i].createConfiguredExporter(cfg,
attributes.getOutputPath(), attributes.getTemplatePath(), globalProperties,
outputDirectories, artifactCollector);
+ } catch (CoreException e) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_setting_up
+ exporterFactories[i].getExporterDefinition(), e);
+ }
+
+ try {
+ exporter.start();
+ } catch(HibernateException he) {
+ throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_error_while_running
+ exporterFactories[i].getExporterDefinition().getDescription(), he);
+ }
+ monitor.worked(1);
+ }
+ return artifactCollector;
+ }
+
+ });
+
+
+ }
+
+
+ private Configuration buildConfiguration(final ExporterAttributes attributes,
ConsoleConfiguration cc, IWorkspaceRoot root) {
+ final boolean reveng = attributes.isReverseEngineer();
+ final String reverseEngineeringStrategy = attributes.getRevengStrategy();
+ final boolean preferBasicCompositeids = attributes.isPreferBasicCompositeIds();
+ final IResource revengres = PathHelper.findMember( root,
attributes.getRevengSettings());
+
+ if(reveng) {
+ Configuration configuration = null;
+ if(cc.hasConfiguration()) {
+ configuration = cc.getConfiguration();
+ } else {
+ configuration = cc.buildWith( null, false );
+ }
+
+ final JDBCMetaDataConfiguration cfg = new JDBCMetaDataConfiguration();
+ Properties properties = configuration.getProperties();
+ cfg.setProperties( properties );
+ cc.buildWith(cfg,false);
+
+ cfg.setPreferBasicCompositeIds(preferBasicCompositeids);
+
+ cc.execute(new Command() { // need to execute in the consoleconfiguration to let it
handle classpath stuff!
+
+ public Object execute() {
+ //todo: factor this setup of revengstrategy to core
+ ReverseEngineeringStrategy res = new DefaultReverseEngineeringStrategy();
+
+ OverrideRepository repository = null;
+
+ if(revengres!=null) {
+ File file = PathHelper.getLocation( revengres ).toFile();
+ repository = new OverrideRepository();
+ repository.addFile(file);
+ }
+
+ if (repository != null){
+ res = repository.getReverseEngineeringStrategy(res);
+ }
+
+ if(reverseEngineeringStrategy!=null &&
reverseEngineeringStrategy.trim().length()>0) {
+ res = loadreverseEngineeringStrategy(reverseEngineeringStrategy, res);
+ }
+
+ ReverseEngineeringSettings qqsettings = new ReverseEngineeringSettings(res)
+ .setDefaultPackageName(attributes.getPackageName())
+ .setDetectManyToMany( attributes.detectManyToMany() )
+ .setDetectOneToOne( attributes.detectOneToOne() )
+ .setDetectOptimisticLock( attributes.detectOptimisticLock() );
+
+ res.setSettings(qqsettings);
+
+ cfg.setReverseEngineeringStrategy( res );
+
+ cfg.readFromJDBC();
+ cfg.buildMappings();
+ return null;
+ }
+ });
+
+ return cfg;
+ } else {
+ cc.build();
+ final Configuration configuration =
((HibernateExtension4_0)cc.getHibernateExtension()).getConfiguration();
+
+ cc.execute(new Command() {
+ public Object execute() {
+
+ configuration.buildMappings();
+ return configuration;
+ }
+ });
+ return configuration;
+ }
+ }
+
+ // TODO: merge with revstrategy load in JDBCConfigurationTask
+ @SuppressWarnings("unchecked")
+ private ReverseEngineeringStrategy loadreverseEngineeringStrategy(final String
className, ReverseEngineeringStrategy delegate) {
+ try {
+ Class<ReverseEngineeringStrategy> clazz =
ReflectHelper.classForName(className);
+ Constructor<ReverseEngineeringStrategy> constructor = clazz.getConstructor(new
Class[] { ReverseEngineeringStrategy.class });
+ return constructor.newInstance(new Object[] { delegate });
+ }
+ catch (NoSuchMethodException e) {
+ try {
+ Class<?> clazz = ReflectHelper.classForName(className);
+ ReverseEngineeringStrategy rev = (ReverseEngineeringStrategy) clazz.newInstance();
+ return rev;
+ }
+ catch (Exception eq) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_default_noarg_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, eq);
+ }
+ }
+ catch (Exception e) {
+ String out =
NLS.bind(HibernateConsoleMessages.CodeGenerationLaunchDelegate_could_not_create_or_find_with_one_argument_delegate_constructor,
className);
+ throw new HibernateConsoleRuntimeException(out, e);
+ }
+ }
+
+}
Copied:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EclipseHQLCompletionRequestor.java
(from rev 36159,
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/EclipseHQLCompletionRequestor.java)
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EclipseHQLCompletionRequestor.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/EclipseHQLCompletionRequestor.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,151 @@
+/*
+ * 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.jboss.tools.hibernate4_0.console;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.swt.graphics.Image;
+import org.hibernate.console.ImageConstants;
+import org.hibernate.eclipse.console.utils.EclipseImages;
+import org.hibernate.eclipse.console.workbench.HibernateWorkbenchHelper;
+import org.hibernate.internal.util.StringHelper;
+import org.hibernate.tool.ide.completion.HQLCompletionProposal;
+import org.hibernate.tool.ide.completion.IHQLCompletionRequestor;
+
+public class EclipseHQLCompletionRequestor implements IHQLCompletionRequestor {
+
+ private final List<ICompletionProposal> result = new
ArrayList<ICompletionProposal>();
+ private String lastErrorMessage;
+ private final int virtualOffset;
+
+ public EclipseHQLCompletionRequestor() {
+ virtualOffset = 0;
+ }
+
+ public EclipseHQLCompletionRequestor(int virtualOffset) {
+ this.virtualOffset = virtualOffset;
+ }
+
+ public List<ICompletionProposal> getCompletionProposals() {
+ return result;
+ }
+
+ public boolean accept(HQLCompletionProposal proposal) {
+ result.add(new CompletionProposal(proposal.getCompletion(), // replacementString
+ proposal.getReplaceStart()+virtualOffset, // replacementOffset
+ proposal.getReplaceEnd()-proposal.getReplaceStart(), // replacementLength
+ proposal.getCompletion().length(), // cursorPosition (relativeTo
replacementStart)
+ getImage(proposal),
+ getDisplayString(proposal),
+ null,
+ null));
+ return true;
+ }
+
+ private String getDisplayString(HQLCompletionProposal proposal) {
+ StringBuffer buf = new StringBuffer(proposal.getSimpleName());
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ if(proposal.getEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append(" - "); //$NON-NLS-1$
+ buf.append(StringHelper.qualifier( proposal.getEntityName() ));
+ } else if(proposal.getShortEntityName()!=null &&
+ !(proposal.getSimpleName().equals( proposal.getEntityName()))) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.ALIAS_REF:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ if(proposal.getShortEntityName()!=null) {
+ buf.append( " - " + proposal.getShortEntityName() ); //$NON-NLS-1$
+ } else if(proposal.getEntityName()!=null) {
+ if(proposal.getEntityName().indexOf( "." )>=0) { //$NON-NLS-1$
+ buf.append( " - " + StringHelper.unqualify( proposal.getEntityName() ));
//$NON-NLS-1$
+ } else {
+ buf.append( " - " + proposal.getEntityName() ); //$NON-NLS-1$
+ }
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ break;
+ default:
+
+ }
+
+
+ return buf.toString();
+ }
+
+ private Image getImage(HQLCompletionProposal proposal) {
+ String key = null;
+
+ switch(proposal.getCompletionKind()) {
+ case HQLCompletionProposal.ENTITY_NAME:
+ case HQLCompletionProposal.ALIAS_REF:
+ key = ImageConstants.MAPPEDCLASS;
+ break;
+ case HQLCompletionProposal.PROPERTY:
+ if(proposal.getProperty()!=null) {
+ return HibernateWorkbenchHelper.getImage( proposal.getProperty() );
+ } else {
+ key = ImageConstants.PROPERTY;
+ }
+ break;
+ case HQLCompletionProposal.KEYWORD:
+ key = null;
+ break;
+ case HQLCompletionProposal.FUNCTION:
+ key = ImageConstants.FUNCTION;
+ break;
+ default:
+ key = null;
+ }
+
+ return key==null?null:EclipseImages.getImage( key );
+ }
+
+ public void completionFailure(String errorMessage) {
+ lastErrorMessage = errorMessage;
+ }
+
+ public String getLastErrorMessage() {
+ return lastErrorMessage;
+ }
+
+ public void clear() {
+ result.clear();
+ lastErrorMessage = null;
+ }
+
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterAttributes.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterAttributes.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterAttributes.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,406 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate4_0.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.jdt.core.JavaConventions;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+
+// This class was created to centralize launch configuration attribute loading/saving
+// (and also to clean up CodeGenerationLaunchDelegate considerably)
+public class ExporterAttributes
+{
+ private boolean reverseEngineer, useOwnTemplates, enableJDK5, enableEJB3,
preferBasicCompositeIds;
+ private boolean useExternalProcess;
+ private String consoleConfigurationName;
+ private String revengSettings;
+ private String revengStrategy;
+ private String packageName;
+ private String outputPath;
+ private String templatePath;
+ private List<ExporterFactory> exporterFactories;
+
+ private boolean autoManyToManyDetection;
+ private boolean autoOneToOneDetection;
+ private boolean autoVersioning;
+
+ public ExporterAttributes () { }
+
+ public ExporterAttributes (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ initialize(configuration);
+ }
+
+ public void initialize (ILaunchConfiguration configuration)
+ throws CoreException
+ {
+ try {
+ consoleConfigurationName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_CONSOLE_CONFIGURATION_NAME,"");
//$NON-NLS-1$
+ outputPath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR,"");
//$NON-NLS-1$
+ reverseEngineer =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER, false);
+ revengSettings =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
""); //$NON-NLS-1$
+ revengStrategy =
configuration.getAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_STRATEGY,
""); //$NON-NLS-1$
+ useOwnTemplates =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_OWN_TEMPLATES,false);
+ useExternalProcess =
configuration.getAttribute(HibernateLaunchConstants.ATTR_USE_EXTERNAL_PROCESS, false);
+ enableJDK5 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_JDK5,false);
+ enableEJB3 =
configuration.getAttribute(HibernateLaunchConstants.ATTR_ENABLE_EJB3_ANNOTATIONS,false);
+ packageName =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PACKAGE_NAME,"");
//$NON-NLS-1$
+ templatePath =
configuration.getAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,"");
//$NON-NLS-1$
+ preferBasicCompositeIds =
configuration.getAttribute(HibernateLaunchConstants.ATTR_PREFER_BASIC_COMPOSITE_IDS,
true);
+ autoManyToManyDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_MANY_TO_MANY, true);
+ autoOneToOneDetection = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_ONE_TO_ONE, true);
+ autoVersioning = configuration.getAttribute(
HibernateLaunchConstants.ATTR_AUTOMATIC_VERSIONING, true);
+
+
+ if (!useOwnTemplates) {
+ templatePath = null;
+ }
+
+ exporterFactories = readExporterFactories(configuration);
+ } catch (CoreException e) {
+ throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
+ }
+ }
+
+ public static String getLaunchAttributePrefix(String exporterId) {
+ return HibernateLaunchConstants.ATTR_EXPORTERS + "." + exporterId;
//$NON-NLS-1$
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<ExporterFactory> readExporterFactories(ILaunchConfiguration
configuration) throws CoreException {
+
+ List<String> exporterNames =
configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null);
+
+ if(exporterNames!=null) {
+ Map<String, ExporterDefinition> exDefinitions =
ExtensionManager.findExporterDefinitionsAsMap();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (String exporterId : exporterNames) {
+ String extensionId =
configuration.getAttribute(getLaunchAttributePrefix(exporterId) +
".extension_id", (String)null); //$NON-NLS-1$
+
+ ExporterDefinition expDef = exDefinitions.get(extensionId);
+ if(expDef==null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterAttributes_could_not_locate_exporter_for_in,
extensionId, configuration.getName());
+ throw new HibernateConsoleRuntimeException(out);
+ } else {
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, exporterId );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+ }
+ return factories;
+
+ } else {
+ // fall back to old way of reading if list of exporters does not exist.
+ ExporterDefinition[] exDefinitions = ExtensionManager.findExporterDefinitions();
+ List<ExporterFactory> factories = new ArrayList<ExporterFactory>();
+
+ for (int i = 0; i < exDefinitions.length; i++) {
+ ExporterDefinition expDef = exDefinitions[i];
+ ExporterFactory exporterFactory = new ExporterFactory( expDef, expDef.getId() );
+ exporterFactory.isEnabled( configuration );
+ factories.add( exporterFactory );
+ Map<String, String> props = configuration.getAttribute(
getLaunchAttributePrefix(exporterFactory.getId())
+ + ".properties", new HashMap<String, String>() ); //$NON-NLS-1$
+ exporterFactory.setProperties( props );
+ }
+
+ return factories;
+ }
+ }
+
+ public static void saveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, Set<ExporterFactory>
enabledExporters, Set<String> deletedExporterIds) {
+
+
+ List<String> names = new ArrayList<String>();
+ for (ExporterFactory ef : exporterFactories) {
+ configuration.setAttribute(getLaunchAttributePrefix(ef.getId()) +
".extension_id", ef.getExporterDefinition().getId()); //$NON-NLS-1$
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = getLaunchAttributePrefix(ef.getId()) + ".properties";
//$NON-NLS-1$
+ names.add(ef.getId());
+ ef.setEnabled( configuration, enabled, false );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+
+ deletedExporterIds.removeAll(names);
+
+ for (String deleted : deletedExporterIds) {
+ configuration.setAttribute( getLaunchAttributePrefix( deleted ), (String)null);
+ configuration.setAttribute(getLaunchAttributePrefix(deleted ) +
".extension_id", (String)null); //$NON-NLS-1$
+ configuration.setAttribute(getLaunchAttributePrefix(deleted) +
".properties", (String)null); //$NON-NLS-1$
+ }
+
+ configuration.setAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, names);
+ }
+
+ public static void oldSaveExporterFactories(
+ ILaunchConfigurationWorkingCopy configuration,
+ List<ExporterFactory> exporterFactories, List<ExporterFactory>
enabledExporters) {
+
+ for (ExporterFactory ef : exporterFactories) {
+ boolean enabled = enabledExporters.contains( ef );
+ String propertiesId = ef.getId() + ".properties"; //$NON-NLS-1$
+
+ ef.setEnabled( configuration, enabled, true );
+
+ HashMap<String, String> map = new HashMap<String,
String>(ef.getProperties());
+
+ if(map.isEmpty()) {
+ configuration.setAttribute( propertiesId, (Map<String, String>)null );
+ } else {
+ configuration.setAttribute( propertiesId, map );
+ }
+ }
+ }
+
+
+ private Path pathOrNull(String p) {
+ if(p==null || p.trim().length()==0) {
+ return null;
+ } else {
+ return new Path(p);
+ }
+ }
+
+ public String getOutputPath()
+ {
+ return outputPath;
+ }
+
+ public void setOutputPath(String outputPath)
+ {
+ this.outputPath = outputPath;
+ }
+
+ public String getPackageName()
+ {
+ return packageName;
+ }
+
+ public void setPackageName(String packageName)
+ {
+ this.packageName = packageName;
+ }
+
+ public String getRevengSettings()
+ {
+ return revengSettings;
+ }
+
+ public void setRevengSettings(String revengSettings)
+ {
+ this.revengSettings = revengSettings;
+ }
+
+ public String getRevengStrategy()
+ {
+ return revengStrategy;
+ }
+
+ public void setRevengStrategy(String revengStrategy)
+ {
+ this.revengStrategy = revengStrategy;
+ }
+
+ public String getTemplatePath()
+ {
+ return templatePath;
+ }
+
+ public void setTemplatePath(String templatePath)
+ {
+ this.templatePath = templatePath;
+ }
+
+ public String getConsoleConfigurationName()
+ {
+ return consoleConfigurationName;
+ }
+
+ public void setConsoleConfigurationName(String consoleConfigurationName)
+ {
+ this.consoleConfigurationName = consoleConfigurationName;
+ }
+
+ public boolean isEJB3Enabled()
+ {
+ return enableEJB3;
+ }
+
+ public void setEnableEJB3(boolean enableEJB3)
+ {
+ this.enableEJB3 = enableEJB3;
+ }
+
+ public boolean isJDK5Enabled()
+ {
+ return enableJDK5;
+ }
+
+ public void setEnableJDK5(boolean enableJDK5)
+ {
+ this.enableJDK5 = enableJDK5;
+ }
+
+ public boolean isPreferBasicCompositeIds()
+ {
+ return preferBasicCompositeIds;
+ }
+
+ public void setPreferBasicCompositeIds(boolean preferBasicCompositeIds)
+ {
+ this.preferBasicCompositeIds = preferBasicCompositeIds;
+ }
+
+ public boolean isReverseEngineer()
+ {
+ return reverseEngineer;
+ }
+
+ public void setReverseEngineer(boolean reverseEngineer)
+ {
+ this.reverseEngineer = reverseEngineer;
+ }
+
+ public boolean isUseOwnTemplates()
+ {
+ return useOwnTemplates;
+ }
+
+ public void setUseOwnTemplates(boolean useOwnTemplates)
+ {
+ this.useOwnTemplates = useOwnTemplates;
+ }
+
+ public boolean isUseExternalProcess()
+ {
+ return useExternalProcess;
+ }
+
+ public void setUseExternalProcess(boolean useExternalProcess)
+ {
+ this.useExternalProcess = useExternalProcess;
+ }
+
+ public List<ExporterFactory> getExporterFactories() {
+ return exporterFactories;
+ }
+
+ public boolean detectManyToMany() {
+ return autoManyToManyDetection;
+ }
+
+ public boolean detectOptimisticLock() {
+ return autoVersioning;
+ }
+
+ public boolean detectOneToOne() {
+ return autoOneToOneDetection;
+ }
+
+ /**
+ * Check exporter attributes and return message with description what is wrong with
attributes.
+ *
+ * @return message
+ */
+ public String checkExporterAttributes() {
+ String msg = null;
+ boolean notSelected = consoleConfigurationName == null ||
consoleConfigurationName.length() <= 0;
+ if (notSelected) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_console_cfg_must_be_specified;
+ }
+ if (msg == null) {
+ msg = PathHelper.checkDirectory(outputPath,
HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, true);
+ }
+ if (msg == null) {
+ if (reverseEngineer && packageName.length() > 0) {
+ IStatus val= JavaConventions.validatePackageName(packageName);
+ if (val.getSeverity() == IStatus.ERROR || val.getSeverity() ==
IStatus.WARNING) {
+ msg = val.getMessage();
+ }
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && revengSettings.trim().length() > 0) {
+ msg = PathHelper.checkFile(revengSettings,
HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_3, true);
+ }
+ }
+ if (msg == null) {
+ if (useOwnTemplates) {
+ msg = PathHelper.checkDirectory(templatePath,
HibernateConsoleMessages.CodeGenerationSettingsTab_template_dir, true);
+ }
+ }
+ if (msg == null) {
+ if (reverseEngineer && !preferBasicCompositeIds) {
+ msg =
HibernateConsoleMessages.CodeGenerationSettingsTab_script_can_not_be_generated_correctly_without;
+ }
+ }
+ return msg;
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterDefinition.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterDefinition.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterDefinition.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,181 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate4_0.console;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.HibernateConsolePlugin;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.tool.hbm2x.Exporter;
+
+/**
+ * Represents what is specified in plugin.xml about possible exporters.
+ *
+ */
+public class ExporterDefinition {
+
+ private String classname;
+
+ private String description;
+
+ private String id;
+
+ private ImageDescriptor iconDescriptor;
+
+ private Map<String, ExporterProperty> properties;
+
+ private IConfigurationElement element;
+
+ public ExporterDefinition(IConfigurationElement element) {
+ init(element.getAttribute( "classname" ), //$NON-NLS-1$
+ element.getAttribute( "description" ), //$NON-NLS-1$
+ element.getAttribute( "id" ), //$NON-NLS-1$
+ createProperties( element ),
+ createIcon( element ));
+ this.element = element;
+ }
+
+ protected void init(String className, String description, String id, Map<String,
ExporterProperty> properties, ImageDescriptor icon) {
+ this.classname = className;
+ this.description = description;
+ this.id = id;
+ this.properties = properties;
+ this.iconDescriptor = icon;
+ }
+
+ static private ImageDescriptor createIcon(IConfigurationElement element) {
+ if ( element.getAttribute( "icon" ) != null ) { //$NON-NLS-1$
+ return AbstractUIPlugin.imageDescriptorFromPlugin(
+ element.getNamespace(), element.getAttribute( "icon" ) ); //$NON-NLS-1$
+ } else {
+ return null;
+ }
+ }
+
+ static private Map<String, ExporterProperty>
createProperties(IConfigurationElement element) {
+ Map<String, ExporterProperty> properties = new HashMap<String,
ExporterProperty>();
+
+ IConfigurationElement propertyElements[] = element
+ .getChildren( "property" ); //$NON-NLS-1$
+ for (int i = 0; i < propertyElements.length; i++) {
+ ExporterProperty property = new ExporterProperty(
+ propertyElements[i].getAttribute("name"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("description"), //$NON-NLS-1$
+ propertyElements[i].getAttribute("value"), //$NON-NLS-1$
+ Boolean.valueOf(propertyElements[i].getAttribute("required")).booleanValue());
//$NON-NLS-1$
+ String type = propertyElements[i].getAttribute("type"); //$NON-NLS-1$
+ if (type != null){
+ property.setType(type);
+ }
+ properties.put(property.getName(),property);
+ }
+ return properties;
+ }
+
+
+ public Exporter createExporterInstance() {
+ Exporter exporter = null;
+
+ try {
+ exporter = (Exporter) ReflectHelper.classForName( classname ).newInstance();
+ }
+ catch (InstantiationException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+ catch (IllegalAccessException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname)); }
+ catch (ClassNotFoundException e) {
+ throw new HibernateConsoleRuntimeException(NLS.bind(
+ HibernateConsoleMessages.ExporterDefinition_problem_creating_exporter_class,
classname));
+ }
+
+ return exporter;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public ImageDescriptor getIconDescriptor() {
+ return iconDescriptor;
+ }
+
+ public Map<String, ExporterProperty> getExporterProperties() {
+ return properties;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ // if we put this in some "namespace" we should have a way to either
+ // migrate an existing one...
+ enabled = configuration.getAttribute( id, false );
+ }
+ catch (CoreException e) {
+ // log and assume false
+ HibernateConsolePlugin.getDefault().log(e);
+ return false;
+ }
+
+ return enabled;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getExporterTag() {
+ return getId().substring(getId().lastIndexOf(".") + 1); //$NON-NLS-1$
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterFactory.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterFactory.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExporterFactory.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,364 @@
+package org.jboss.tools.hibernate4_0.console;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.variables.IStringVariableManager;
+import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.annotations.common.util.StringHelper;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.console.HibernateConsoleRuntimeException;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+import org.hibernate.eclipse.console.model.impl.ExporterFactoryStrings;
+import org.hibernate.eclipse.console.model.impl.ExporterProperty;
+import org.hibernate.eclipse.launch.ExporterAttributes;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
+import org.hibernate.eclipse.launch.PathHelper;
+import org.hibernate.tool.hbm2x.ArtifactCollector;
+import org.hibernate.tool.hbm2x.Exporter;
+import org.hibernate.tool.hbm2x.GenericExporter;
+import org.hibernate.tool.hbm2x.Hbm2DDLExporter;
+import org.hibernate.tool.hbm2x.QueryExporter;
+
+/**
+ * ExporterFactory is used in UI to hold additional configuration for Exporter
definitions
+ * @author max
+ *
+ */
+public class ExporterFactory {
+
+ private ExporterDefinition definition;
+
+ final Map<String, String> inputProperties;
+
+ private boolean enabled = true;
+
+ private final String exporterId;
+
+ public ExporterFactory(ExporterDefinition definition, String exporterId) {
+ this.definition = definition;
+ this.exporterId = exporterId;
+ inputProperties = new HashMap<String, String>();
+ }
+
+ public Map<String, ExporterProperty> getDefaultExporterProperties() {
+ return definition.getExporterProperties();
+ }
+
+ public String setProperty(String key, String value) {
+ return inputProperties.put( key, value );
+ }
+
+ public void removeProperty(String propertyName) {
+ inputProperties.remove( propertyName );
+ }
+
+ public String getPropertyValue(String key) {
+ if(inputProperties.containsKey( key )) {
+ return inputProperties.get( key );
+ } else {
+ ExporterProperty ep = definition.getExporterProperties().get( key );
+ if(ep!=null) {
+ return ep.getDefaultValue();
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public boolean isEnabled() {
+ return enabled ;
+ }
+
+ public void setEnabled(boolean b) {
+ enabled = b;
+ }
+
+ public ExporterDefinition getExporterDefinition() {
+ return definition;
+ }
+
+ public boolean isEnabled(ILaunchConfiguration configuration) {
+ boolean enabled = false;
+
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ enabled = configuration.getAttribute( getId(), false );
+ } else {
+ enabled =
configuration.getAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()), false);
+ }
+ } catch(CoreException ce) {
+ // ignore; assume false
+ enabled=false;
+ }
+
+ setEnabled( enabled );
+ return isEnabled();
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled,
boolean oldSettings) {
+ setEnabled( enabled );
+ if(oldSettings) {
+ configuration.setAttribute( getId(), isEnabled() );
+ } else {
+ configuration.setAttribute(ExporterAttributes.getLaunchAttributePrefix(getId()),
isEnabled());
+ }
+ }
+
+ public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled)
{
+
+ boolean oldSettings = true;
+ try {
+ if(configuration.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS,
(List<String>)null)==null) {
+ oldSettings = true;
+ } else {
+ oldSettings = false;
+ }
+ } catch(CoreException ce) {
+ // ignore and assume settings are old
+ }
+
+ setEnabled(configuration, enabled, oldSettings);
+ }
+
+ public Map<String, String> getProperties() {
+ return inputProperties;
+ }
+
+ public String getId() {
+ return exporterId;
+ }
+
+ public String getExporterTag() {
+ return definition.getExporterTag();
+ }
+
+ public String getExporterDefinitionId() {
+ return definition.getId();
+ }
+
+ public void setProperties(Map<String, String> props) {
+ inputProperties.clear();
+ inputProperties.putAll( props );
+ }
+
+ public ExporterProperty getExporterProperty(String key) {
+ return definition.getExporterProperties().get( key );
+ }
+
+ public boolean hasLocalValueFor(String string) {
+ return inputProperties.containsKey( string );
+ }
+
+ /** Method that resolves an expression through eclipses built-in variable manager.
+ * @throws CoreException if expression could not be evaluated. */
+ public static String resolve(String expression) throws CoreException {
+ if (expression == null) {
+ return null;
+ }
+ IStringVariableManager variableManager =
VariablesPlugin.getDefault().getStringVariableManager();
+ return variableManager.performStringSubstitution(expression, false);
+ }
+
+ /**
+ * ExporterFactory update a collection of output directories,
+ * true if new output directory was added into the set of outputDirs.
+ *
+ * @param defOutDir
+ * @param globalProps
+ * @param outputDirs
+ * @return true if new output directory added
+ * @throws CoreException
+ */
+ public boolean collectOutputDirectories(String defOutDir, final Properties globalProps,
+ Set<String> outputDirs) throws CoreException {
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProps);
+ props.putAll(getProperties());
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+ String outputPath = defOutDir;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ boolean res = false;
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ res = outputDirs.add(loc);
+ }
+ return res;
+ }
+
+ /**
+ * Creates exporter with the specified settings; also resolves any relevant properties
via Eclipse VariablesPlugin.
+ * @param collector
+ * @throws CoreException in case of resolve variables issues.
+ */
+ public Exporter createConfiguredExporter(Configuration cfg, String
defaultOutputDirectory,
+ String customTemplatePath, Properties globalProperties, Set<String>
outputDirectories, ArtifactCollector collector) throws CoreException {
+
+ Exporter exporter = getExporterDefinition().createExporterInstance();
+
+ Properties extract = new Properties();
+ Properties props = new Properties();
+ props.putAll(globalProperties);
+ props.putAll(getProperties());
+
+ exporter.setProperties(props);
+ exporter.setArtifactCollector(collector);
+
+ extractExporterProperties(getExporterDefinitionId(), props, extract);
+
+ String outputPath = defaultOutputDirectory;
+ if (extract.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ outputPath = extract.getProperty(ExporterFactoryStrings.OUTPUTDIR);
+ }
+
+ String resolvedOutputDir = resolve(outputPath);
+ String loc = PathHelper.getLocationAsStringPath(resolvedOutputDir);
+ if (outputPath != null && loc == null) {
+ String out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_output_dir_in_does_not_exist,
+ resolvedOutputDir, getExporterDefinition().getDescription());
+ throw new HibernateConsoleRuntimeException(out);
+ }
+
+ if (StringHelper.isNotEmpty(loc)) { // only set if something valid found
+ outputDirectories.add(loc);
+ exporter.setOutputDirectory(new File(loc));
+ }
+
+ exporter.setConfiguration(cfg);
+
+ List<String> templatePathList = new ArrayList<String>();
+ if (extract.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ String resolveTemplatePath =
resolve(extract.getProperty(ExporterFactoryStrings.TEMPLATE_PATH));
+ StringTokenizer st = new StringTokenizer(resolveTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath == null) {
+ out +=
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolveTemplatePath, getExporterDefinition().getDescription()) +
'\n';
+ } else {
+ templatePathList.add(locationAsStringPath);
+ }
+ }
+ if (out.length() > 0 ){
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+
+ if (StringHelper.isNotEmpty(customTemplatePath)) {
+ String resolvedCustomTemplatePath = resolve(customTemplatePath);
+ StringTokenizer st = new StringTokenizer(resolvedCustomTemplatePath, ";");
//$NON-NLS-1$
+ String out = ""; //$NON-NLS-1$
+ while (st.hasMoreTokens()) {
+ String locationAsStringPath = PathHelper.getLocationAsStringPath(st.nextToken());
+ if (locationAsStringPath != null) {
+ templatePathList.add(locationAsStringPath);
+ } else {
+ out =
NLS.bind(HibernateConsoleMessages.ExporterFactory_template_dir_in_does_not_exist,
+ resolvedCustomTemplatePath, getExporterDefinition().getDescription());
+ }
+ }
+ if (!("".equals(out))) { //$NON-NLS-1$
+ out = out.substring(0, out.length() - 1);
+ throw new HibernateConsoleRuntimeException(out);
+ }
+ }
+ exporter.setTemplatePath(templatePathList.toArray(new
String[templatePathList.size()]));
+ // special handling for GenericExporter (TODO: be delegated via plugin.xml)
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbmtemplate")) {
//$NON-NLS-1$
+ GenericExporter ge = (GenericExporter) exporter;
+ ge.setFilePattern(extract.getProperty(ExporterFactoryStrings.FILE_PATTERN));
+ ge.setTemplateName(extract.getProperty(ExporterFactoryStrings.TEMPLATE_NAME));
+ ge.setForEach(extract.getProperty(ExporterFactoryStrings.FOR_EACH));
+ }
+ // special handling for Hbm2DDLExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.hbm2ddl")) {
//$NON-NLS-1$
+ Hbm2DDLExporter ddlExporter = (Hbm2DDLExporter) exporter;
+ //avoid users to delete their databases with a single click
+ ddlExporter.setExport(Boolean.parseBoolean(extract.getProperty(ExporterFactoryStrings.EXPORTTODATABASE)));
+ }
+ // special handling for QueryExporter
+ if (getExporterDefinitionId().equals("org.hibernate.tools.query")) {
//$NON-NLS-1$
+ QueryExporter queryExporter = (QueryExporter) exporter;
+ List<String> queryStrings = new ArrayList<String>();
+ queryStrings.add(extract.getProperty(ExporterFactoryStrings.QUERY_STRING,
"")); //$NON-NLS-1$
+ queryExporter.setQueries(queryStrings);
+ queryExporter.setFilename(extract.getProperty(ExporterFactoryStrings.OUTPUTFILENAME));
+ }
+ return exporter;
+ }
+
+ /**
+ * Extract and update GUI specific exporter properties
+ *
+ * @param exporterId
+ * @param props - properties which values remain
+ * @param extract - separated updated properties
+ * @throws CoreException
+ */
+ public static void extractExporterProperties(
+ String exporterId, Properties props, Properties extract) throws CoreException {
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTDIR)) {
+ extract.put(ExporterFactoryStrings.OUTPUTDIR,
resolve(props.getProperty(ExporterFactoryStrings.OUTPUTDIR)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.OUTPUTDIR);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_PATH)) {
+ extract.put(ExporterFactoryStrings.TEMPLATE_PATH,
resolve(props.getProperty(ExporterFactoryStrings.TEMPLATE_PATH)));
+ // done to avoid validation check in hibernate tools templates
+ props.remove(ExporterFactoryStrings.TEMPLATE_PATH);
+ }
+ if (exporterId.equals("org.hibernate.tools.hbmtemplate")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.FILE_PATTERN)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FILE_PATTERN, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FILE_PATTERN, tmp);
+ props.remove(ExporterFactoryStrings.FILE_PATTERN);
+ }
+ if (props.containsKey(ExporterFactoryStrings.TEMPLATE_NAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.TEMPLATE_NAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.TEMPLATE_NAME, tmp);
+ props.remove(ExporterFactoryStrings.TEMPLATE_NAME);
+ }
+ if (props.containsKey(ExporterFactoryStrings.FOR_EACH)) {
+ tmp = props.getProperty(ExporterFactoryStrings.FOR_EACH, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.FOR_EACH, tmp);
+ props.remove(ExporterFactoryStrings.FOR_EACH);
+ }
+ }
+ // special handling for Hbm2DDLExporter
+ if (exporterId.equals("org.hibernate.tools.hbm2ddl")) { //$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.EXPORTTODATABASE,
props.getProperty(ExporterFactoryStrings.EXPORTTODATABASE, Boolean.toString(false)));
+ props.remove(ExporterFactoryStrings.EXPORTTODATABASE);
+ }
+ // special handling for QueryExporter
+ if (exporterId.equals("org.hibernate.tools.query")) { //$NON-NLS-1$
+ String tmp;
+ if (props.containsKey(ExporterFactoryStrings.QUERY_STRING)) {
+ tmp = props.getProperty(ExporterFactoryStrings.QUERY_STRING, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.QUERY_STRING, tmp);
+ props.remove(ExporterFactoryStrings.QUERY_STRING);
+ }
+ if (props.containsKey(ExporterFactoryStrings.OUTPUTFILENAME)) {
+ tmp = props.getProperty(ExporterFactoryStrings.OUTPUTFILENAME, "");
//$NON-NLS-1$
+ extract.put(ExporterFactoryStrings.OUTPUTFILENAME, tmp);
+ props.remove(ExporterFactoryStrings.OUTPUTFILENAME);
+ }
+ }
+ }
+}
Added:
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExtensionManager.java
===================================================================
---
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExtensionManager.java
(rev 0)
+++
branches/dead/hibernatetools-multiversion2/plugins/org.jboss.tools.hibernate4_0/src/org/jboss/tools/hibernate4_0/console/ExtensionManager.java 2011-11-11
12:44:47 UTC (rev 36298)
@@ -0,0 +1,97 @@
+/*
+ * 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:/*
+ * 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.jboss.tools.hibernate4_0.console;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
+
+public class ExtensionManager
+{
+ public static final String EXPORTERS_EXTENSION_ID =
"org.hibernate.eclipse.console.exporters"; //$NON-NLS-1$
+
+ private static IExtension[] findExtensions (String extensionId)
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IExtensionPoint extensionPoint = registry.getExtensionPoint(extensionId);
+ return extensionPoint.getExtensions();
+ }
+
+ public static ExporterDefinition[] findExporterDefinitions ()
+ {
+ List<ExporterDefinition> exporters = new
ArrayList<ExporterDefinition>();
+
+ IExtension[] extensions = findExtensions(EXPORTERS_EXTENSION_ID);
+ for (int i = 0; i < extensions.length; i++)
+ {
+ IConfigurationElement elements[] = extensions[i].getConfigurationElements();
+ for (int j = 0; j < elements.length; j++)
+ {
+ ExporterDefinition exporter = new ExporterDefinition(elements[j]);
+ exporters.add(exporter);
+ }
+ }
+
+ return exporters.toArray(new ExporterDefinition[exporters.size()]);
+ }
+
+ /**
+ * return map of ExporterDefinitions keyed by id
+ */
+ public static Map<String, ExporterDefinition> findExporterDefinitionsAsMap() {
+ Map<String, ExporterDefinition> result = new HashMap<String,
ExporterDefinition>();
+
+ ExporterDefinition[] findExporterDefinitions = findExporterDefinitions();
+ for (int i = 0; i < findExporterDefinitions.length; i++) {
+ ExporterDefinition exporterDefinition = findExporterDefinitions[i];
+ result.put(exporterDefinition.getId(), exporterDefinition);
+ }
+
+ return result;
+ }
+}