diff options
22 files changed, 778 insertions, 270 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF index c9f72938a4..8b76fce7c2 100644 --- a/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF +++ b/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF @@ -24,6 +24,7 @@ Require-Bundle: org.eclipse.core.commands;bundle-version="[3.4.0,4.0.0)", org.eclipse.jst.common.project.facet.core;bundle-version="1.3.100", org.eclipse.jst.j2ee;bundle-version="[1.1.200,1.2.0)", org.eclipse.jst.j2ee.core;bundle-version="[1.1.200,1.2.0)", + org.eclipse.jst.j2ee.web;bundle-version="[1.1.300,1.2.0)", org.eclipse.jst.jee.ejb;bundle-version="[1.0.100,1.1.0)", org.eclipse.text;bundle-version="[3.4.0,4.0.0)", org.eclipse.wst.common.emf;bundle-version="[1.1.200,2.0.0)", diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.core/plugin.xml index 7880b79990..d8231ba279 100644 --- a/jpa/plugins/org.eclipse.jpt.core/plugin.xml +++ b/jpa/plugins/org.eclipse.jpt.core/plugin.xml @@ -123,6 +123,7 @@ <parameter name="signature" value="50 4B 03 04"/> </describer> </content-type> + </extension> diff --git a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties index d1926bd334..de7abb6351 100644 --- a/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties +++ b/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties @@ -28,6 +28,7 @@ PERSISTENCE_UNIT_DUPLICATE_CLASS=Duplicate class \"{0}\" PERSISTENCE_UNIT_REDUNDANT_CLASS=Class \"{0}\" is already specified in mapping file \"{1}\" PERSISTENCE_UNIT_DUPLICATE_JAR_FILE=Duplicate JAR file \"{0}\" PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE=Unspecified JAR file +PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING=The path to the JAR file will vary on your deployment environment. Please make sure the specified path fits your particular environment. PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE=JAR file \"{0}\" cannot be resolved GENERATOR_DUPLICATE_NAME=Duplicate generator named \"{0}\" defined in this persistence unit QUERY_DUPLICATE_NAME=Duplicate query named \"{0}\" defined in this persistence unit diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java index 0f6fc09d30..7ed1104b51 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java @@ -267,6 +267,17 @@ public class JptCorePlugin extends Plugin { defaultURI; } + /** + * Return the deployment path to which jars are relatively specified for + * the given project + * (Web projects have a different deployment structure than non-web projects) + */ + public static IPath getJarDeploymentRootPath(IProject project) { + return projectHasWebFacet(project) ? + new Path("/" + J2EEConstants.WEB_INF) : + new Path("/"); + } + public static IFile getPlatformFile(IProject project, String defaultURI) { IPath deploymentPath = new Path(getDeploymentURI(project, defaultURI)); IVirtualFile vFile = ComponentCore.createFile(project, deploymentPath); @@ -509,5 +520,4 @@ public class JptCorePlugin extends Plugin { super.stop(context); } } - } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java new file mode 100644 index 0000000000..c1c72a641a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java @@ -0,0 +1,274 @@ +/******************************************************************************* + * Copyright (c) 2009 Oracle. All rights reserved. + * This program and the accompanying materials are 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. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.core.internal.context.persistence; + +import java.util.List; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.jpt.core.JpaFile; +import org.eclipse.jpt.core.JpaStructureNode; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.context.PersistentType; +import org.eclipse.jpt.core.context.java.JarFile; +import org.eclipse.jpt.core.context.persistence.JarFileRef; +import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; +import org.eclipse.jpt.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; +import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; +import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; +import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; +import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.utility.internal.CollectionTools; +import org.eclipse.jpt.utility.internal.StringTools; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.resources.IVirtualFile; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + + +public abstract class AbstractJarFileRef + extends AbstractXmlContextNode + implements JarFileRef +{ + protected XmlJarFileRef xmlJarFileRef; + + protected String fileName; + + protected JarFile jarFile; + + + // **************** construction/initialization **************************** + + public AbstractJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { + super(parent); + this.xmlJarFileRef = xmlJarFileRef; + this.fileName = xmlJarFileRef.getFileName(); + this.jarFile = this.buildJarFile(); + } + + protected JarFile buildJarFile() { + if (StringTools.stringIsEmpty(this.fileName)) { + return null; + } + JavaResourcePackageFragmentRoot jrpfr = this.getJpaProject().getJavaResourcePackageFragmentRoot(this.getFileName()); + return (jrpfr == null) ? null : this.buildJarFile(jrpfr); + } + + @Override + public PersistenceUnit getParent() { + return (PersistenceUnit) super.getParent(); + } + + + // **************** file name ********************************************** + + public String getFileName() { + return this.fileName; + } + + public void setFileName(String newFileName) { + String old = this.fileName; + this.fileName = newFileName; + this.xmlJarFileRef.setFileName(newFileName); + this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); + } + + protected void setFileName_(String newFileName) { + String old = this.fileName; + this.fileName = newFileName; + this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); + } + + + // **************** JAR file *********************************************** + + public JarFile getJarFile() { + return this.jarFile; + } + + protected void setJarFile(JarFile jarFile) { + JarFile old = this.jarFile; + this.jarFile = jarFile; + this.firePropertyChanged(JAR_FILE_PROPERTY, old, jarFile); + } + + + // **************** JarFileRef impl **************************************** + + public PersistentType getPersistentType(String typeName) { + return (this.jarFile == null) ? null : this.jarFile.getPersistentType(typeName); + } + + public boolean containsOffset(int textOffset) { + return (this.xmlJarFileRef != null) && this.xmlJarFileRef.containsOffset(textOffset); + } + + + // **************** JpaStructureNode impl ********************************** + + public String getId() { + return PersistenceStructureNodes.JAR_FILE_REF_ID; + } + + public IContentType getContentType() { + return getParent().getContentType(); + } + + public JpaStructureNode getStructureNode(int textOffset) { + return this; + } + + public TextRange getSelectionTextRange() { + return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getSelectionTextRange(); + } + + public void dispose() { + if (this.jarFile != null) { + this.jarFile.dispose(); + } + } + + + // **************** XmlContextNode impl ************************************ + + public TextRange getValidationTextRange() { + return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getValidationTextRange(); + } + + + // **************** updating *********************************************** + + public void update(XmlJarFileRef xjfr) { + this.xmlJarFileRef = xjfr; + this.setFileName_(xjfr.getFileName()); + this.updateJarFile(); + } + + protected void updateJarFile() { + JavaResourcePackageFragmentRoot jrpfr = null; + + if (! StringTools.stringIsEmpty(this.fileName)) { + + // first, attempt to resolve location specifically + jrpfr = javaPackageRoot_specifically(); + + // then ... guess, basically + if (jrpfr == null) { + jrpfr = javaPackageRoot_guess(); + } + } + + if (jrpfr == null) { + if (this.jarFile != null) { + this.jarFile.dispose(); + this.setJarFile(null); + } + } else { + if (this.jarFile == null) { + this.setJarFile(this.buildJarFile(jrpfr)); + } else { + this.jarFile.update(jrpfr); + } + } + } + + private JavaResourcePackageFragmentRoot javaPackageRoot_specifically() { + IProject project = getJpaProject().getProject(); + + for (IPath deploymentPath : resolveDeploymentJarFilePath(new Path(this.fileName))) { + IVirtualFile virtualJar = ComponentCore.createFile(project, deploymentPath); + IFile realJar = virtualJar.getUnderlyingFile(); + if (realJar.exists() && realJar.getProject().equals(project)) { + return getJpaProject().getJavaResourcePackageFragmentRoot(realJar.getProjectRelativePath().toString()); + } + } + + return null; + } + + private JavaResourcePackageFragmentRoot javaPackageRoot_guess() { + String jarFileName = new Path(this.fileName).lastSegment(); + for (JpaFile jpaFile : CollectionTools.iterable(getJpaProject().jpaFiles())) { + if (jpaFile.getFile().getName().equals(jarFileName) + && JptCorePlugin.JAR_CONTENT_TYPE.equals(jpaFile.getContentType())) { + return (JavaResourcePackageFragmentRoot) jpaFile.getResourceModel(); + } + } + + return null; + } + + /** + * Return an array of deployment paths that may correspond + * to the given persistence.xml jar file entry + */ + protected abstract IPath[] resolveDeploymentJarFilePath(IPath jarFilePath); + + protected JarFile buildJarFile(JavaResourcePackageFragmentRoot jrpfr) { + return this.getJpaFactory().buildJarFile(this, jrpfr); + } + + + // **************** validation ********************************************* + + @Override + public void validate(List<IMessage> messages, IReporter reporter) { + super.validate(messages, reporter); + + if (StringTools.stringIsEmpty(this.xmlJarFileRef.getFileName())) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE, + this, + this.getValidationTextRange() + ) + ); + return; + } + + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.NORMAL_SEVERITY, + JpaValidationMessages.PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING, + this, + this.getValidationTextRange() + ) + ); + + if (this.jarFile == null) { + messages.add( + DefaultJpaValidationMessages.buildMessage( + IMessage.HIGH_SEVERITY, + JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE, + new String[] {this.xmlJarFileRef.getFileName()}, + this, + this.getValidationTextRange() + ) + ); + return; + } + + this.jarFile.validate(messages, reporter); + } + + + // **************** misc *************************************************** + + @Override + public void toString(StringBuilder sb) { + super.toString(sb); + sb.append(this.getFileName()); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java index 48cac3897b..131586a743 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java @@ -1,217 +1,53 @@ /******************************************************************************* - * Copyright (c) 2009 Oracle. All rights reserved. - * This program and the accompanying materials are 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ + * Copyright (c) 2009 Oracle. + * All rights reserved. This program and the accompanying materials are + * 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 + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ package org.eclipse.jpt.core.internal.context.persistence; -import java.util.List; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jpt.core.JpaStructureNode; -import org.eclipse.jpt.core.context.PersistentType; -import org.eclipse.jpt.core.context.java.JarFile; -import org.eclipse.jpt.core.context.persistence.JarFileRef; -import org.eclipse.jpt.core.context.persistence.PersistenceStructureNodes; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jpt.core.JptCorePlugin; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; -import org.eclipse.jpt.core.internal.context.AbstractXmlContextNode; -import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages; -import org.eclipse.jpt.core.internal.validation.JpaValidationMessages; -import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot; import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; -import org.eclipse.jpt.core.utility.TextRange; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.wst.validation.internal.provisional.core.IMessage; -import org.eclipse.wst.validation.internal.provisional.core.IReporter; /** * Context JAR file reference (from the persistence unit) */ -public class GenericJarFileRef - extends AbstractXmlContextNode - implements JarFileRef +public class GenericJarFileRef + extends AbstractJarFileRef { - protected XmlJarFileRef xmlJarFileRef; - - protected String fileName; - - protected JarFile jarFile; - - // **************** construction/initialization **************************** public GenericJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { - super(parent); - this.xmlJarFileRef = xmlJarFileRef; - this.fileName = xmlJarFileRef.getFileName(); - this.jarFile = this.buildJarFile(); + super(parent, xmlJarFileRef); } - protected JarFile buildJarFile() { - if (StringTools.stringIsEmpty(this.fileName)) { - return null; - } - JavaResourcePackageFragmentRoot jrpfr = this.getJpaProject().getJavaResourcePackageFragmentRoot(this.getFileName()); - return (jrpfr == null) ? null : this.buildJarFile(jrpfr); - } - - @Override - public PersistenceUnit getParent() { - return (PersistenceUnit) super.getParent(); - } - - - // **************** file name ********************************************** - - public String getFileName() { - return this.fileName; - } - - public void setFileName(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.xmlJarFileRef.setFileName(newFileName); - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } - - protected void setFileName_(String newFileName) { - String old = this.fileName; - this.fileName = newFileName; - this.firePropertyChanged(FILE_NAME_PROPERTY, old, newFileName); - } + // **************** overrides ********************************************** - // **************** JAR file *********************************************** - - public JarFile getJarFile() { - return this.jarFile; - } - - protected void setJarFile(JarFile jarFile) { - JarFile old = this.jarFile; - this.jarFile = jarFile; - this.firePropertyChanged(JAR_FILE_PROPERTY, old, jarFile); - } - - - // **************** JarFileRef impl **************************************** - - public PersistentType getPersistentType(String typeName) { - return (this.jarFile == null) ? null : this.jarFile.getPersistentType(typeName); - } - - public boolean containsOffset(int textOffset) { - return (this.xmlJarFileRef != null) && this.xmlJarFileRef.containsOffset(textOffset); - } - - - // **************** JpaStructureNode impl ********************************** - - public String getId() { - return PersistenceStructureNodes.JAR_FILE_REF_ID; - } - - public IContentType getContentType() { - return getParent().getContentType(); - } - - public JpaStructureNode getStructureNode(int textOffset) { - return this; - } - - public TextRange getSelectionTextRange() { - return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getSelectionTextRange(); - } - - public void dispose() { - if (this.jarFile != null) { - this.jarFile.dispose(); - } - } - - - // **************** XmlContextNode impl ************************************ - - public TextRange getValidationTextRange() { - return (this.xmlJarFileRef == null) ? null : this.xmlJarFileRef.getValidationTextRange(); - } - - - // **************** updating *********************************************** - - public void update(XmlJarFileRef xjfr) { - this.xmlJarFileRef = xjfr; - this.setFileName_(xjfr.getFileName()); - this.updateJarFile(); - } - - protected void updateJarFile() { - JavaResourcePackageFragmentRoot jrpfr = null; - if (! StringTools.stringIsEmpty(this.fileName)) { - jrpfr = this.getJpaProject().getJavaResourcePackageFragmentRoot(this.fileName); - } - if (jrpfr == null) { - if (this.jarFile != null) { - this.jarFile.dispose(); - this.setJarFile(null); - } - } else { - if (this.jarFile == null) { - this.setJarFile(this.buildJarFile(jrpfr)); - } else { - this.jarFile.update(jrpfr); - } - } - } - - protected JarFile buildJarFile(JavaResourcePackageFragmentRoot jrpfr) { - return this.getJpaFactory().buildJarFile(this, jrpfr); - } - - - // **************** validation ********************************************* - @Override - public void validate(List<IMessage> messages, IReporter reporter) { - super.validate(messages, reporter); - - if (StringTools.stringIsEmpty(this.xmlJarFileRef.getFileName())) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE, - this, - this.getValidationTextRange() - ) - ); - return; + protected IPath[] resolveDeploymentJarFilePath(IPath jarFilePath) { + IProject project = getJpaProject().getProject(); + IPath rootPath = JptCorePlugin.getJarDeploymentRootPath(project); + + if (JptCorePlugin.projectHasWebFacet(project)) { + return new IPath[] { + // first path assumes form "../lib/other.jar" + rootPath.append(jarFilePath.removeFirstSegments(1)), + // second path assumes form of first, without ".." ("lib/other.jar") + rootPath.append(jarFilePath) + }; } - - if (this.jarFile == null) { - messages.add( - DefaultJpaValidationMessages.buildMessage( - IMessage.HIGH_SEVERITY, - JpaValidationMessages.PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE, - new String[] {this.xmlJarFileRef.getFileName()}, - this, - this.getValidationTextRange() - ) - ); - return; + else { + return new IPath[] { + rootPath.append(jarFilePath) + }; } - - this.jarFile.validate(messages, reporter); - } - - - // **************** misc *************************************************** - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getFileName()); } } diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java index ec5a2e0b3d..95c8b53ef4 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java @@ -34,6 +34,7 @@ public interface JpaValidationMessages { public static final String PERSISTENCE_UNIT_REDUNDANT_CLASS = "PERSISTENCE_UNIT_REDUNDANT_CLASS"; public static final String PERSISTENCE_UNIT_DUPLICATE_JAR_FILE = "PERSISTENCE_UNIT_DUPLICATE_JAR_FILE"; public static final String PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE = "PERSISTENCE_UNIT_UNSPECIFIED_JAR_FILE"; + public static final String PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING = "PERSISTENCE_UNIT_JAR_FILE_DEPLOYMENT_PATH_WARNING"; public static final String PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE = "PERSISTENCE_UNIT_NONEXISTENT_JAR_FILE"; public static final String GENERATOR_DUPLICATE_NAME = "GENERATOR_DUPLICATE_NAME"; public static final String QUERY_DUPLICATE_NAME = "QUERY_DUPLICATE_NAME"; diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java index d79564568e..57b9200318 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java @@ -10,15 +10,14 @@ package org.eclipse.jpt.core.resource.persistence; import org.eclipse.emf.common.notify.Notification; - import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EStructuralFeature; - import org.eclipse.emf.ecore.impl.ENotificationImpl; - import org.eclipse.jpt.core.internal.resource.xml.translators.SimpleTranslator; import org.eclipse.jpt.core.resource.xml.AbstractJpaEObject; import org.eclipse.jpt.core.resource.xml.JpaEObject; +import org.eclipse.jpt.core.utility.TextRange; +import org.eclipse.jpt.utility.internal.StringTools; import org.eclipse.wst.common.internal.emf.resource.Translator; /** @@ -199,6 +198,13 @@ public class XmlJarFileRef extends AbstractJpaEObject implements JpaEObject result.append(')'); return result.toString(); } + + @Override + public TextRange getValidationTextRange() { + return (! StringTools.stringIsEmpty(this.fileName)) ? + getTextTextRange() : + super.getValidationTextRange(); + } // ********** translators ********** diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java index 62659ea55d..7b42fbf6be 100644 --- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java +++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java @@ -12,7 +12,6 @@ package org.eclipse.jpt.core.resource.xml; import java.util.HashSet; import java.util.Hashtable; import java.util.Set; - import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.Notifier; @@ -160,6 +159,26 @@ public abstract class AbstractJpaEObject // ********** text ranges ********** /** + * Return a text range for the "text" node. + * If the text node does not exist, return a text range for this object's node + */ + protected TextRange getTextTextRange() { + IDOMNode textNode = this.getTextNode(); + return (textNode != null) ? buildTextRange(textNode) : this.getValidationTextRange(); + } + + protected IDOMNode getTextNode() { + NodeList children = this.node.getChildNodes(); + for (int i = 0; i < children.getLength(); i ++) { + IDOMNode child = (IDOMNode) children.item(i); + if (child.getNodeType() == Node.TEXT_NODE) { + return child; + } + } + return null; + } + + /** * Return a text range for the specified attribute node. * If the attribute node does not exist, return a text range for this object's * node diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java index 663d892668..d855d3912e 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java @@ -43,6 +43,7 @@ import org.eclipse.jpt.core.context.orm.OrmTypeMapping; import org.eclipse.jpt.core.context.orm.OrmVersionMapping; import org.eclipse.jpt.core.context.orm.OrmXml; import org.eclipse.jpt.core.context.orm.PersistenceUnitMetadata; +import org.eclipse.jpt.core.context.persistence.JarFileRef; import org.eclipse.jpt.core.context.persistence.MappingFileRef; import org.eclipse.jpt.core.context.persistence.Persistence; import org.eclipse.jpt.core.context.persistence.PersistenceUnit; @@ -50,6 +51,7 @@ import org.eclipse.jpt.core.internal.platform.GenericJpaFactory; import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute; import org.eclipse.jpt.core.resource.orm.XmlAttributeMapping; import org.eclipse.jpt.core.resource.orm.XmlTypeMapping; +import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; import org.eclipse.jpt.core.resource.persistence.XmlPersistenceUnit; import org.eclipse.jpt.core.resource.xml.JpaXmlResource; import org.eclipse.jpt.eclipselink.core.EclipseLinkJpaProject; @@ -103,6 +105,7 @@ import org.eclipse.jpt.eclipselink.core.internal.context.orm.VirtualXmlBasicColl import org.eclipse.jpt.eclipselink.core.internal.context.orm.VirtualXmlBasicMap; import org.eclipse.jpt.eclipselink.core.internal.context.orm.VirtualXmlTransformation; import org.eclipse.jpt.eclipselink.core.internal.context.orm.VirtualXmlVariableOneToOne; +import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkJarFileRef; import org.eclipse.jpt.eclipselink.core.internal.context.persistence.EclipseLinkPersistenceUnit; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasic; import org.eclipse.jpt.eclipselink.core.resource.orm.XmlBasicCollection; @@ -155,6 +158,11 @@ public class EclipseLinkJpaFactory return new EclipseLinkPersistenceUnit(parent, xmlPersistenceUnit); } + @Override + public JarFileRef buildJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { + return new EclipseLinkJarFileRef(parent, xmlJarFileRef); + } + // ********** EclipseLink-specific ORM Virtual Resource Model ********** diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java new file mode 100644 index 0000000000..84987e1c7a --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2009 Oracle. + * All rights reserved. This program and the accompanying materials are + * 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 + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.core.internal.context.persistence; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.core.internal.context.persistence.AbstractJarFileRef; +import org.eclipse.jpt.core.resource.persistence.XmlJarFileRef; + +public class EclipseLinkJarFileRef + extends AbstractJarFileRef +{ + // **************** construction/initialization **************************** + + public EclipseLinkJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { + super(parent, xmlJarFileRef); + } + + + // **************** overrides ********************************************** + + @Override + protected IPath[] resolveDeploymentJarFilePath(IPath jarFilePath) { + IProject project = getJpaProject().getProject(); + IPath rootPath = JptCorePlugin.getJarDeploymentRootPath(project); + + if (JptCorePlugin.projectHasWebFacet(project)) { + return new IPath[] { + // assumes form "../lib/other.jar" + rootPath.append(jarFilePath.removeFirstSegments(1)) + }; + } + else { + return new IPath[] { + rootPath.append(jarFilePath) + }; + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java index 0655539201..0aea92cde3 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java @@ -52,4 +52,17 @@ public class EclipseLinkPersistenceUnitGeneralComposite new EclipseLinkPersistenceUnitMappingFilesComposite(this, container); } + + protected void initializeJarFilesPane(Composite container) { + + container = addCollapsableSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jarFiles + ); + + updateGridData(container); + updateGridData(container.getParent()); + + new EclipseLinkPersistenceUnitJarFilesComposite(this, container); + } }
\ No newline at end of file diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java new file mode 100644 index 0000000000..2449678ffc --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2009 Oracle. + * All rights reserved. This program and the accompanying materials are + * 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 + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.eclipselink.ui.internal.persistence.general; + +import org.eclipse.core.resources.IFile; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.ui.internal.persistence.details.ArchiveFileSelectionDialog; +import org.eclipse.jpt.ui.internal.persistence.details.PersistenceUnitJarFilesComposite; +import org.eclipse.jpt.ui.internal.persistence.details.ArchiveFileSelectionDialog.DeploymentPathCalculator; +import org.eclipse.jpt.ui.internal.widgets.Pane; +import org.eclipse.swt.widgets.Composite; + +public class EclipseLinkPersistenceUnitJarFilesComposite + extends PersistenceUnitJarFilesComposite +{ + public EclipseLinkPersistenceUnitJarFilesComposite( + Pane<? extends PersistenceUnit> parentPane, + Composite parent) { + + super(parentPane, parent); + } + + + @Override + protected DeploymentPathCalculator buildJarFileDeploymentPathCalculator() { + return new EclipseLinkDeploymentPathCalculator(); + } + + + private static class EclipseLinkDeploymentPathCalculator + extends ArchiveFileSelectionDialog.ModuleDeploymentPathCalculator + { + @Override + public String calculateDeploymentPath(IFile file) { + String baseDeploymentPath = super.calculateDeploymentPath(file); + if (JptCorePlugin.projectHasWebFacet(file.getProject())) { + return "../" + baseDeploymentPath; + } + else { + return baseDeploymentPath; + } + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java index de7abf7f4c..f921d3bc40 100644 --- a/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java +++ b/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java @@ -11,7 +11,6 @@ package org.eclipse.jpt.eclipselink.ui.internal.persistencexml.details; import java.util.ArrayList; import java.util.List; - import org.eclipse.jpt.core.context.JpaContextNode; import org.eclipse.jpt.core.context.MappingFile; import org.eclipse.jpt.core.context.persistence.MappingFileRef; @@ -68,6 +67,7 @@ public class EclipseLinkNavigatorItemContentProviderFactory list.add(buildImpliedMappingFileCvm()); list.add(buildImpliedEclipseLinkMappingFileCvm()); list.add(buildPersistentTypeCvm()); + list.add(buildJarFileCvm()); return new CompositeCollectionValueModel<CollectionValueModel<? extends JpaContextNode>, JpaContextNode>(list); } diff --git a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties index b90f7cf01d..a54ab6f4d9 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties +++ b/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties @@ -11,6 +11,9 @@ Boolean_False=False Boolean_True=True +ArchiveFileSelectionDialog_jarPathHelpLabel=The correct path to the JAR file selected will vary on your deployment environment. You may alter it here to correctly reflect your particular environment. +ArchiveFileSelectionDialog_jarPathLabel=JAR file path: + PersistenceEditor_page_help=Help PersistenceEditor_sourceTab=Source @@ -44,7 +47,7 @@ PersistenceUnitGeneralComposite_description=Description: PersistenceUnitJarFilesComposite_noFileName=<File name not set> PersistenceUnitMappingFilesComposite_jarFileDialog_title=JAR File Selection -PersistenceUnitMappingFilesComposite_jarFileDialog_message=Choose the JAR files to be added to the persistence unit. +PersistenceUnitMappingFilesComposite_jarFileDialog_message=Choose a JAR file to be added to the persistence unit. PersistenceUnitMappingFilesComposite_mappingFileDialog_message=Choose the XML mapping files to be added to the persistence unit. PersistenceUnitMappingFilesComposite_mappingFileDialog_title=JPA XML Mapping File Selection diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java index e6b2bc014d..3f66b67618 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java @@ -14,27 +14,31 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; +import org.eclipse.jpt.ui.JptUiPlugin; /** * This filter will deny showing any file that are not JAR files or folders * that don't contain any JAR files in its sub-hierarchy. */ -public class JarFileViewerFilter +public class ArchiveFileViewerFilter extends ViewerFilter { - public JarFileViewerFilter() { + private static final String[] archiveExtensions= { "jar", "zip" }; //$NON-NLS-1$ + + + public ArchiveFileViewerFilter() { super(); } - @Override public boolean select( Viewer viewer, Object parentElement, Object element) { if (element instanceof IFile) { - return isJarFile((IFile) element); + return isArchivePath(((IFile)element).getFullPath()); } else if (element instanceof IFolder) { IFolder folder = (IFolder) element; @@ -47,15 +51,21 @@ public class JarFileViewerFilter } catch (CoreException ce) { // just skip this one, then + JptUiPlugin.log(ce); } } return false; } - /* there doesn't seem to be a very good way of determining if a file is an - * actual jar file, so for now, if it's a file => true. - */ - protected boolean isJarFile(IFile file) { - return true; - } + public static boolean isArchivePath(IPath path) { + String ext= path.getFileExtension(); + if (ext != null && ext.length() != 0) { + for (int i= 0; i < archiveExtensions.length; i++) { + if (ext.equalsIgnoreCase(archiveExtensions[i])) { + return true; + } + } + } + return false; + } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java index f0a120274a..8675b04527 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java @@ -21,6 +21,9 @@ public class JptUiPersistenceMessages { public static String Boolean_False; public static String Boolean_True; + + public static String ArchiveFileSelectionDialog_jarPathHelpLabel; + public static String ArchiveFileSelectionDialog_jarPathLabel; public static String PersistenceEditor_page_help; public static String PersistenceEditor_sourceTab; diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java new file mode 100644 index 0000000000..6be91cd9c9 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java @@ -0,0 +1,226 @@ +/******************************************************************************* + * Copyright (c) 2009 Oracle. + * All rights reserved. This program and the accompanying materials are + * 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 + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.persistence.details; + +import java.util.Collections; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.draw2d.graph.Path; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jpt.core.JptCorePlugin; +import org.eclipse.jpt.ui.JptUiPlugin; +import org.eclipse.jpt.ui.internal.jface.ArchiveFileViewerFilter; +import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; +import org.eclipse.jpt.ui.internal.swt.TextFieldModelAdapter; +import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; +import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; +import org.eclipse.ui.dialogs.ISelectionStatusValidator; +import org.eclipse.ui.model.WorkbenchContentProvider; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.views.navigator.ResourceComparator; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualContainer; +import org.eclipse.wst.common.componentcore.resources.IVirtualFile; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.eclipse.wst.common.componentcore.resources.IVirtualResource; + +public class ArchiveFileSelectionDialog + extends ElementTreeSelectionDialog +{ + private final WritablePropertyValueModel<String> jarPathModel; + + private DeploymentPathCalculator pathCalculator; + + + public ArchiveFileSelectionDialog(Shell parent) { + this(parent, new SimpleDeploymentPathCalculator()); + } + + public ArchiveFileSelectionDialog(Shell parent, DeploymentPathCalculator pathCalculator) { + super(parent, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); + this.pathCalculator = pathCalculator; + setComparator(new ResourceComparator(ResourceComparator.NAME)); + addFilter(new ArchiveFileViewerFilter()); + setValidator(new ArchiveFileSelectionValidator()); + this.jarPathModel = new SimplePropertyValueModel<String>(); + } + + + @Override + protected Control createDialogArea(Composite parent) { + Composite composite = (Composite) super.createDialogArea(parent); + + Label helpLabel = new Label(composite, SWT.WRAP); + helpLabel.setText(JptUiPersistenceMessages.ArchiveFileSelectionDialog_jarPathHelpLabel); + GridData gd = new GridData(GridData.FILL_HORIZONTAL); + gd.widthHint = 400; + helpLabel.setLayoutData(gd); + + Composite subComposite = new Composite(composite, SWT.NONE); + subComposite.setLayout(new GridLayout(2, false)); + subComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Label jarPathLabel = new Label(subComposite, SWT.NONE); + jarPathLabel.setFont(composite.getFont()); + jarPathLabel.setText(JptUiPersistenceMessages.ArchiveFileSelectionDialog_jarPathLabel); + + Text jarPathText = new Text(subComposite, SWT.BORDER); + jarPathText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + TextFieldModelAdapter.adapt(jarPathModel, jarPathText); + + return composite; + } + + @Override + protected TreeViewer doCreateTreeViewer(Composite parent, int style) { + TreeViewer treeViewer = super.doCreateTreeViewer(parent, style); + + treeViewer.addSelectionChangedListener( + new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + updateJarPathModel(event.getSelection()); + } + }); + + return treeViewer; + } + + protected void updateJarPathModel(ISelection selection) { + Object selectedObj = ((IStructuredSelection) selection).getFirstElement(); + if (selectedObj instanceof IFile) { + this.jarPathModel.setValue(calculateDeployPath((IFile) selectedObj)); + } + else { + this.jarPathModel.setValue(""); + } + } + + protected String calculateDeployPath(IFile archiveFile) { + return this.pathCalculator.calculateDeploymentPath(archiveFile); + } + + @Override + protected void computeResult() { + setResult(Collections.singletonList(this.jarPathModel.getValue())); + } + + + private static class ArchiveFileSelectionValidator + implements ISelectionStatusValidator + { + public ArchiveFileSelectionValidator() { + super(); + } + + + public IStatus validate(Object[] selection) { + int nSelected= selection.length; + if (nSelected == 0 || (nSelected > 1)) { + return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + } + for (int i= 0; i < selection.length; i++) { + Object curr= selection[i]; + if (curr instanceof IFile) { + return new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + } + } + return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); //$NON-NLS-1$ + } + } + + + public static interface DeploymentPathCalculator + { + String calculateDeploymentPath(IFile file); + } + + + public static class SimpleDeploymentPathCalculator + implements DeploymentPathCalculator + { + public String calculateDeploymentPath(IFile file) { + return file.getName(); + } + } + + + public static class ModuleDeploymentPathCalculator + extends SimpleDeploymentPathCalculator + { + @Override + public String calculateDeploymentPath(IFile file) { + // first look for virtual component that matches this file, returning + // the path to that virtual component + IVirtualComponent vComponent = ComponentCore.createComponent(file.getProject()); + if (vComponent != null) { + IVirtualFolder vFolder = vComponent.getRootFolder(); + IVirtualFile vFile = findVirtualFile(vFolder, file); + if (vFile != null) { + return calculatePersistenceRootRelativePath(vFile); + } + } + + // then default to simple behavior + return super.calculateDeploymentPath(file); + } + + protected IVirtualFile findVirtualFile(IVirtualContainer vContainer, IFile realFile) { + try { + for (IVirtualResource vResource : vContainer.members()) { + if (vResource.getType() == IVirtualResource.FILE) { + IVirtualFile vFile = (IVirtualFile) vResource; + if (realFile.equals(vFile.getUnderlyingFile())) { + return vFile; + } + } + else { + IVirtualFile vFile = findVirtualFile((IVirtualContainer) vResource, realFile); + if (vFile != null) { + return vFile; + } + } + } + } + catch (CoreException ce) { + JptUiPlugin.log(ce); + } + + return null; + } + + protected String calculatePersistenceRootRelativePath(IVirtualFile vFile) { + IProject project = vFile.getProject(); + IPath puRootPath = JptCorePlugin.getJarDeploymentRootPath(project); + + IPath path = vFile.getRuntimePath().makeRelativeTo(puRootPath); + + return path.toString(); + } + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java index 5f18aa2439..661fcb016f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java @@ -100,5 +100,17 @@ public class GenericPersistenceUnitGeneralComposite extends PersistenceUnitGener new GenericPersistenceUnitMappingFilesComposite(this, container); } + + protected void initializeJarFilesPane(Composite container) { + container = addCollapsableSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jarFiles + ); + + updateGridData(container); + updateGridData(container.getParent()); + + new GenericPersistenceUnitJarFilesComposite(this, container); + } } diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java new file mode 100644 index 0000000000..f695596c98 --- /dev/null +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2009 Oracle. + * All rights reserved. This program and the accompanying materials are + * 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 + * + * Contributors: + * Oracle - initial API and implementation + *******************************************************************************/ +package org.eclipse.jpt.ui.internal.persistence.details; + +import org.eclipse.jpt.core.context.persistence.PersistenceUnit; +import org.eclipse.jpt.ui.internal.widgets.Pane; +import org.eclipse.swt.widgets.Composite; + +public class GenericPersistenceUnitJarFilesComposite + extends PersistenceUnitJarFilesComposite +{ + public GenericPersistenceUnitJarFilesComposite( + Pane<? extends PersistenceUnit> parentPane, + Composite parent) { + + super(parentPane, parent); + } +} diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java index 0c63df1137..1bd355472f 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java @@ -232,19 +232,6 @@ public abstract class PersistenceUnitGeneralComposite extends FormPane<Persisten new PersistenceUnitClassesComposite(this, container); } - protected void initializeJarFilesPane(Composite container) { - - container = addCollapsableSection( - container, - JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jarFiles - ); - - updateGridData(container); - updateGridData(container.getParent()); - - new PersistenceUnitJarFilesComposite(this, container); - } - protected void updateGridData(Composite container) { GridData gridData = new GridData(); diff --git a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java index 0f979b4bf4..05c0c9ae15 100644 --- a/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java +++ b/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java @@ -10,12 +10,7 @@ package org.eclipse.jpt.ui.internal.persistence.details; import java.util.ListIterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; @@ -24,7 +19,6 @@ import org.eclipse.jpt.core.context.persistence.PersistenceUnit; import org.eclipse.jpt.ui.JptUiPlugin; import org.eclipse.jpt.ui.internal.JpaHelpContextIds; import org.eclipse.jpt.ui.internal.JptUiIcons; -import org.eclipse.jpt.ui.internal.jface.JarFileViewerFilter; import org.eclipse.jpt.ui.internal.persistence.JptUiPersistenceMessages; import org.eclipse.jpt.ui.internal.util.SWTUtil; import org.eclipse.jpt.ui.internal.widgets.AddRemoveListPane; @@ -43,10 +37,6 @@ import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.dialogs.ElementTreeSelectionDialog; -import org.eclipse.ui.dialogs.ISelectionStatusValidator; -import org.eclipse.ui.model.WorkbenchContentProvider; -import org.eclipse.ui.model.WorkbenchLabelProvider; -import org.eclipse.ui.views.navigator.ResourceComparator; /** * Here the layout of this pane: @@ -69,7 +59,8 @@ import org.eclipse.ui.views.navigator.ResourceComparator; * @version 2.0 * @since 2.0 */ -public class PersistenceUnitJarFilesComposite extends Pane<PersistenceUnit> +public abstract class PersistenceUnitJarFilesComposite + extends Pane<PersistenceUnit> { /** * Creates a new <code>PersistenceUnitJPAMappingDescriptorsComposite</code>. @@ -77,8 +68,9 @@ public class PersistenceUnitJarFilesComposite extends Pane<PersistenceUnit> * @param parentPane The parent pane of this one * @param parent The parent container */ - public PersistenceUnitJarFilesComposite(Pane<? extends PersistenceUnit> parentPane, - Composite parent) { + public PersistenceUnitJarFilesComposite( + Pane<? extends PersistenceUnit> parentPane, + Composite parent) { super(parentPane, parent, false); } @@ -188,42 +180,22 @@ public class PersistenceUnitJarFilesComposite extends Pane<PersistenceUnit> private void addJarFileRef(ObjectListSelectionModel listSelectionModel) { IProject project = getSubject().getJpaProject().getProject(); - ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog( - getShell(), - new WorkbenchLabelProvider(), - new WorkbenchContentProvider() - ); - + ElementTreeSelectionDialog dialog = new ArchiveFileSelectionDialog( + getShell(), buildJarFileDeploymentPathCalculator()); + dialog.setHelpAvailable(false); - dialog.setValidator(buildValidator()); dialog.setTitle(JptUiPersistenceMessages.PersistenceUnitMappingFilesComposite_jarFileDialog_title); dialog.setMessage(JptUiPersistenceMessages.PersistenceUnitMappingFilesComposite_jarFileDialog_message); - dialog.addFilter(new JarFileViewerFilter()); dialog.setInput(project); - dialog.setComparator(new ResourceComparator(ResourceComparator.NAME)); - + SWTUtil.show( dialog, buildSelectionDialogPostExecution(listSelectionModel) ); } - private ISelectionStatusValidator buildValidator() { - return new ISelectionStatusValidator() { - public IStatus validate(Object[] selection) { - if (selection.length == 0) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); - } - - for (Object item : selection) { - if (item instanceof IFolder) { - return new Status(IStatus.ERROR, JptUiPlugin.PLUGIN_ID, ""); - } - } - - return new Status(IStatus.OK, JptUiPlugin.PLUGIN_ID, ""); - } - }; + protected ArchiveFileSelectionDialog.DeploymentPathCalculator buildJarFileDeploymentPathCalculator() { + return new ArchiveFileSelectionDialog.ModuleDeploymentPathCalculator(); } private PostExecution<ElementTreeSelectionDialog> buildSelectionDialogPostExecution( @@ -235,15 +207,12 @@ public class PersistenceUnitJarFilesComposite extends Pane<PersistenceUnit> } for (Object result : dialog.getResult()) { - IFile file = (IFile) result; - // TODO - move to deploy path location - IPath filePath = file.getProjectRelativePath(); - String fileName = filePath.toPortableString(); - if (jarFileRefExists(fileName)) { + String filePath = (String) result; + if (jarFileRefExists(filePath)) { continue; } JarFileRef jarFileRef = getSubject().addJarFileRef(); - jarFileRef.setFileName(fileName); + jarFileRef.setFileName(filePath); listSelectionModel.addSelectedValue(jarFileRef); } |