### Eclipse Workspace Patch 1.0 #P org.eclipse.jpt.ui Index: property_files/jpt_ui_persistence.properties =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/property_files/jpt_ui_persistence.properties,v retrieving revision 1.10 diff -u -r1.10 jpt_ui_persistence.properties --- property_files/jpt_ui_persistence.properties 22 Apr 2009 19:36:27 -0000 1.10 +++ property_files/jpt_ui_persistence.properties 16 May 2009 22:37:19 -0000 @@ -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 @@ PersistenceUnitJarFilesComposite_noFileName= 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 Index: src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java,v retrieving revision 1.2 diff -u -r1.2 GenericPersistenceUnitGeneralComposite.java --- src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java 22 Apr 2009 19:36:27 -0000 1.2 +++ src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitGeneralComposite.java 16 May 2009 22:37:19 -0000 @@ -100,5 +100,17 @@ new GenericPersistenceUnitMappingFilesComposite(this, container); } + + protected void initializeJarFilesPane(Composite container) { + container = addCollapsableSection( + container, + JptUiPersistenceMessages.PersistenceUnitGeneralComposite_jarFiles + ); + + updateGridData(container); + updateGridData(container.getParent()); + + new GenericPersistenceUnitJarFilesComposite(this, container); + } } Index: src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java,v retrieving revision 1.13 diff -u -r1.13 PersistenceUnitGeneralComposite.java --- src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java 8 May 2009 20:49:05 -0000 1.13 +++ src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitGeneralComposite.java 16 May 2009 22:37:19 -0000 @@ -232,19 +232,6 @@ 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(); Index: src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java,v retrieving revision 1.4 diff -u -r1.4 PersistenceUnitJarFilesComposite.java --- src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java 8 May 2009 20:49:05 -0000 1.4 +++ src/org/eclipse/jpt/ui/internal/persistence/details/PersistenceUnitJarFilesComposite.java 16 May 2009 22:37:19 -0000 @@ -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.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.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 @@ * @version 2.0 * @since 2.0 */ -public class PersistenceUnitJarFilesComposite extends Pane +public abstract class PersistenceUnitJarFilesComposite + extends Pane { /** * Creates a new PersistenceUnitJPAMappingDescriptorsComposite. @@ -77,8 +68,9 @@ * @param parentPane The parent pane of this one * @param parent The parent container */ - public PersistenceUnitJarFilesComposite(Pane parentPane, - Composite parent) { + public PersistenceUnitJarFilesComposite( + Pane parentPane, + Composite parent) { super(parentPane, parent, false); } @@ -188,42 +180,22 @@ 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 buildSelectionDialogPostExecution( @@ -235,15 +207,12 @@ } 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); } Index: src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java =================================================================== RCS file: src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java diff -N src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java --- src/org/eclipse/jpt/ui/internal/jface/JarFileViewerFilter.java 22 Apr 2009 19:36:27 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,61 +0,0 @@ -/******************************************************************************* - * 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.jface; - -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.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; - -/** - * 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 - extends ViewerFilter -{ - public JarFileViewerFilter() { - super(); - } - - - - @Override - public boolean select( - Viewer viewer, Object parentElement, Object element) { - if (element instanceof IFile) { - return isJarFile((IFile) element); - } - else if (element instanceof IFolder) { - IFolder folder = (IFolder) element; - try { - for (IResource each : folder.members()) { - if (select(viewer, folder, each)) { - return true; - } - } - } - catch (CoreException ce) { - // just skip this one, then - } - } - 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; - } -} Index: src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.ui/src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java,v retrieving revision 1.7 diff -u -r1.7 JptUiPersistenceMessages.java --- src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java 22 Apr 2009 19:36:27 -0000 1.7 +++ src/org/eclipse/jpt/ui/internal/persistence/JptUiPersistenceMessages.java 16 May 2009 22:37:19 -0000 @@ -21,6 +21,9 @@ 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; Index: src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java =================================================================== RCS file: src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java diff -N src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/ui/internal/persistence/details/ArchiveFileSelectionDialog.java 1 Jan 1970 00:00:00 -0000 @@ -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 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(); + } + + + @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(); + } + } +} Index: src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java =================================================================== RCS file: src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java diff -N src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/ui/internal/jface/ArchiveFileViewerFilter.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,71 @@ +/******************************************************************************* + * 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.jface; + +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 ArchiveFileViewerFilter + extends ViewerFilter +{ + 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 isArchivePath(((IFile)element).getFullPath()); + } + else if (element instanceof IFolder) { + IFolder folder = (IFolder) element; + try { + for (IResource each : folder.members()) { + if (select(viewer, folder, each)) { + return true; + } + } + } + catch (CoreException ce) { + // just skip this one, then + JptUiPlugin.log(ce); + } + } + return false; + } + + 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; + } +} Index: src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java =================================================================== RCS file: src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java diff -N src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/ui/internal/persistence/details/GenericPersistenceUnitJarFilesComposite.java 1 Jan 1970 00:00:00 -0000 @@ -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 parentPane, + Composite parent) { + + super(parentPane, parent); + } +} #P org.eclipse.jpt.core Index: src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java,v retrieving revision 1.5 diff -u -r1.5 GenericJarFileRef.java --- src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java 20 Apr 2009 21:48:32 -0000 1.5 +++ src/org/eclipse/jpt/core/internal/context/persistence/GenericJarFileRef.java 16 May 2009 22:37:21 -0000 @@ -1,215 +1,50 @@ /******************************************************************************* - * 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; - -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(); - } - - 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); + super(parent, xmlJarFileRef); } - // **************** JAR file *********************************************** + // **************** overrides ********************************************** - 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.getFileName()); - } - 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 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) + }; + } + else { + return new IPath[] { + 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; - } - - this.jarFile.validate(messages, reporter); - } - - - // **************** misc *************************************************** - - @Override - public void toString(StringBuilder sb) { - super.toString(sb); - sb.append(this.getFileName()); } } Index: src/org/eclipse/jpt/core/JptCorePlugin.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java,v retrieving revision 1.28 diff -u -r1.28 JptCorePlugin.java --- src/org/eclipse/jpt/core/JptCorePlugin.java 16 Mar 2009 19:33:22 -0000 1.28 +++ src/org/eclipse/jpt/core/JptCorePlugin.java 16 May 2009 22:37:21 -0000 @@ -267,6 +267,17 @@ 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 @@ super.stop(context); } } - } Index: src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java,v retrieving revision 1.1 diff -u -r1.1 AbstractJpaEObject.java --- src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java 9 Feb 2009 03:53:37 -0000 1.1 +++ src/org/eclipse/jpt/core/resource/xml/AbstractJpaEObject.java 16 May 2009 22:37:21 -0000 @@ -12,7 +12,6 @@ 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 @@ // ********** 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 Index: META-INF/MANIFEST.MF =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/META-INF/MANIFEST.MF,v retrieving revision 1.39 diff -u -r1.39 MANIFEST.MF --- META-INF/MANIFEST.MF 8 Apr 2009 21:36:32 -0000 1.39 +++ META-INF/MANIFEST.MF 16 May 2009 22:37:20 -0000 @@ -24,6 +24,7 @@ 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)", Index: src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java,v retrieving revision 1.24 diff -u -r1.24 JpaValidationMessages.java --- src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java 14 May 2009 18:02:04 -0000 1.24 +++ src/org/eclipse/jpt/core/internal/validation/JpaValidationMessages.java 16 May 2009 22:37:21 -0000 @@ -34,6 +34,7 @@ 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"; Index: plugin.xml =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/plugin.xml,v retrieving revision 1.37 diff -u -r1.37 plugin.xml --- plugin.xml 12 Mar 2009 04:15:57 -0000 1.37 +++ plugin.xml 16 May 2009 22:37:20 -0000 @@ -123,6 +123,7 @@ + Index: property_files/jpa_validation.properties =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/property_files/jpa_validation.properties,v retrieving revision 1.32 diff -u -r1.32 jpa_validation.properties --- property_files/jpa_validation.properties 14 May 2009 18:02:04 -0000 1.32 +++ property_files/jpa_validation.properties 16 May 2009 22:37:20 -0000 @@ -28,6 +28,7 @@ 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 Index: src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java,v retrieving revision 1.2 diff -u -r1.2 XmlJarFileRef.java --- src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java 22 Apr 2009 19:36:30 -0000 1.2 +++ src/org/eclipse/jpt/core/resource/persistence/XmlJarFileRef.java 16 May 2009 22:37:21 -0000 @@ -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 @@ result.append(')'); return result.toString(); } + + @Override + public TextRange getValidationTextRange() { + return (! StringTools.stringIsEmpty(this.fileName)) ? + getTextTextRange() : + super.getValidationTextRange(); + } // ********** translators ********** Index: src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java =================================================================== RCS file: src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java diff -N src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/core/internal/context/persistence/AbstractJarFileRef.java 1 Jan 1970 00:00:00 -0000 @@ -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 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()); + } +} #P org.eclipse.jpt.eclipselink.core Index: src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.eclipselink.core/src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java,v retrieving revision 1.31 diff -u -r1.31 EclipseLinkJpaFactory.java --- src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java 14 May 2009 18:02:06 -0000 1.31 +++ src/org/eclipse/jpt/eclipselink/core/internal/EclipseLinkJpaFactory.java 16 May 2009 22:37:23 -0000 @@ -43,6 +43,7 @@ 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.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.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 @@ return new EclipseLinkPersistenceUnit(parent, xmlPersistenceUnit); } + @Override + public JarFileRef buildJarFileRef(PersistenceUnit parent, XmlJarFileRef xmlJarFileRef) { + return new EclipseLinkJarFileRef(parent, xmlJarFileRef); + } + // ********** EclipseLink-specific ORM Virtual Resource Model ********** Index: src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java =================================================================== RCS file: src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java diff -N src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/eclipselink/core/internal/context/persistence/EclipseLinkJarFileRef.java 1 Jan 1970 00:00:00 -0000 @@ -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) + }; + } + } +} #P org.eclipse.jpt.eclipselink.ui Index: src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java,v retrieving revision 1.2 diff -u -r1.2 EclipseLinkPersistenceUnitGeneralComposite.java --- src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java 22 Apr 2009 19:36:24 -0000 1.2 +++ src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitGeneralComposite.java 16 May 2009 22:37:24 -0000 @@ -52,4 +52,17 @@ 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 Index: src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java =================================================================== RCS file: /cvsroot/webtools/org.eclipse.jpa/components/jpa/plugins/org.eclipse.jpt.eclipselink.ui/src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java,v retrieving revision 1.6 diff -u -r1.6 EclipseLinkNavigatorItemContentProviderFactory.java --- src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java 28 Jan 2009 06:18:24 -0000 1.6 +++ src/org/eclipse/jpt/eclipselink/ui/internal/persistencexml/details/EclipseLinkNavigatorItemContentProviderFactory.java 16 May 2009 22:37:24 -0000 @@ -11,7 +11,6 @@ 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 @@ list.add(buildImpliedMappingFileCvm()); list.add(buildImpliedEclipseLinkMappingFileCvm()); list.add(buildPersistentTypeCvm()); + list.add(buildJarFileCvm()); return new CompositeCollectionValueModel, JpaContextNode>(list); } Index: src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java =================================================================== RCS file: src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java diff -N src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/jpt/eclipselink/ui/internal/persistence/general/EclipseLinkPersistenceUnitJarFilesComposite.java 1 Jan 1970 00:00:00 -0000 @@ -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 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; + } + } + } +}