diff options
author | gkessler | 2007-04-02 17:08:05 +0000 |
---|---|---|
committer | gkessler | 2007-04-02 17:08:05 +0000 |
commit | 13c13235fa8ad5de0e46e8305e161134edb74580 (patch) | |
tree | 600d75ceaded130b0340e3f6873f1b336fe7bdf6 | |
parent | be679ac4e8eb1453a2b399cdf1604a1deb0ddec6 (diff) | |
download | webtools.jsf-13c13235fa8ad5de0e46e8305e161134edb74580.tar.gz webtools.jsf-13c13235fa8ad5de0e46e8305e161134edb74580.tar.xz webtools.jsf-13c13235fa8ad5de0e46e8305e161134edb74580.zip |
[142056] JSF library referenced in a web project does not act as true reference
[156784] JSF Library References are not stored in the project .settings folder
[164165] Exception logged on deploy flag change in JSF library
[178291] JSF Library jars not copied when project location is not default
[154573] The FacesServlet class name is hardcoded to javax.faces.webapp.FacesServlet
Facet install page UI Cleanup
Removed JSF Library Reference Page - must now Java Build Path + j2ee Module dependencies
New Wizard: New JSF Library --> JSF Library
49 files changed, 2702 insertions, 1848 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/model/jsflibraryregistry.ecore b/jsf/plugins/org.eclipse.jst.jsf.core/model/jsflibraryregistry.ecore index c4ed2681d..e2900d29b 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/model/jsflibraryregistry.ecore +++ b/jsf/plugins/org.eclipse.jst.jsf.core/model/jsflibraryregistry.ecore @@ -41,8 +41,8 @@ <eOperations name="copyTo" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"> <eParameters name="baseDestLocation" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> </eOperations> - <eStructuralFeatures xsi:type="ecore:EAttribute" name="ID" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString" - defaultValueLiteral="" iD="true"/> + <eStructuralFeatures xsi:type="ecore:EAttribute" name="ID" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString" + changeable="false" transient="true" defaultValueLiteral="" derived="true"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="Name" lowerBound="1" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/> <eStructuralFeatures xsi:type="ecore:EAttribute" name="JSFVersion" lowerBound="1" eType="#//JSFVersion" defaultValueLiteral="UNKNOWN"/> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml b/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml index a1470abbb..f1f880dca 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.core/plugin.xml @@ -244,4 +244,10 @@ type="org.eclipse.wst.validation.problemmarker"> </super> </extension> + + <extension point="org.eclipse.jdt.core.classpathContainerInitializer"> + <classpathContainerInitializer + class="org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer" + id="org.eclipse.jst.jsf.core.internal.jsflibrarycontainer"/> + </extension> </plugin> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFCorePlugin.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFCorePlugin.java index 70efe5411..445506c15 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFCorePlugin.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFCorePlugin.java @@ -161,6 +161,8 @@ public class JSFCorePlugin extends WTPPlugin { // log(IStatus.INFO, Messages.JSFLibraryRegistry_NoLoadCreatingNew); jsfLibraryRegistry = JSFLibraryRegistryFactory.eINSTANCE.createJSFLibraryRegistry(); + //next line ensures that old registry does not get written out on exit when save occurs + jsfLibraryRegistryResource = (JSFLibraryRegistryResourceImpl)resourceFactory.createResource(jsfLibRegURI); jsfLibraryRegistryResource.getContents().add(jsfLibraryRegistry); loadJSFLibraryExtensions(); } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibrariesContainerInitializer.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibrariesContainerInitializer.java new file mode 100644 index 000000000..f343137ab --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibrariesContainerInitializer.java @@ -0,0 +1,85 @@ +package org.eclipse.jst.jsf.core.internal; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.ClasspathContainerInitializer; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.internal.core.UserLibrary; +import org.eclipse.jdt.internal.core.UserLibraryManager; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; + +/** + * Initialize JSF Libraries as classpath containers + */ +public class JSFLibrariesContainerInitializer extends + ClasspathContainerInitializer { + + /** + * container id + */ + public static final String JSF_LIBRARY_CP_CONTAINER_ID="org.eclipse.jst.jsf.core.internal.jsflibrarycontainer"; + + /** + * Constructor + */ + public JSFLibrariesContainerInitializer() { + super(); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#initialize(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject) + */ + public void initialize(IPath containerPath, IJavaProject project) throws CoreException { + if (isJSFLibraryContainer(containerPath)) { + String libId= containerPath.lastSegment(); + + JSFLibrary ref= JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(libId); +// JSFLibraryReference ref= JSFLibraryRegistryUtil.getInstance().getJSFLibryReferencebyID(libId); + if (ref != null) { + JSFLibraryClasspathContainer container= new JSFLibraryClasspathContainer(ref); + JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project }, new IClasspathContainer[] { container }, null); + } + } + } + + private boolean isJSFLibraryContainer(IPath path) { + return path != null && path.segmentCount() == 2 && JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID.equals(path.segment(0)); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#canUpdateClasspathContainer(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject) + */ + public boolean canUpdateClasspathContainer(IPath containerPath, IJavaProject project) { + return isJSFLibraryContainer(containerPath); + } + + /** + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#getDescription(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject) + */ + public String getDescription(IPath containerPath, IJavaProject project) { + if (isJSFLibraryContainer(containerPath)) { + String id = containerPath.lastSegment(); + JSFLibrary libref = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(id); + String displayText = id; + + if (libref == null){ + displayText = displayText + " (missing JSF Library)"; + } + + return displayText; + } + return super.getDescription(containerPath, project); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.ClasspathContainerInitializer#getComparisonID(org.eclipse.core.runtime.IPath, org.eclipse.jdt.core.IJavaProject) + */ + public Object getComparisonID(IPath containerPath, IJavaProject project) { + return containerPath; + } + +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibraryClasspathContainer.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibraryClasspathContainer.java new file mode 100644 index 000000000..8616f86f4 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/JSFLibraryClasspathContainer.java @@ -0,0 +1,53 @@ +package org.eclipse.jst.jsf.core.internal; + +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; + +/** + * JSF Library classpath container + */ +public class JSFLibraryClasspathContainer implements IClasspathContainer { + + private JSFLibrary lib; + + /** + * @param JSFLibrary + */ + public JSFLibraryClasspathContainer(JSFLibrary lib) { + this.lib = lib; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.IClasspathContainer#getClasspathEntries() + */ + public IClasspathEntry[] getClasspathEntries() { + return JSFLibraryRegistryUtil.getInstance().getClasspathEntries(lib); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.IClasspathContainer#getDescription() + */ + public String getDescription() { + return lib.getName() + " (JSF Library"+ (lib.isImplementation() ? " - implementation)" : ")"); + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.IClasspathContainer#getKind() + */ + public int getKind() { + return IClasspathContainer.K_APPLICATION; + } + + /* (non-Javadoc) + * @see org.eclipse.jdt.core.IClasspathContainer#getPath() + */ + public IPath getPath() { + return new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID).append(this.lib.getID()); + } + +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/J2EEModuleDependencyDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/J2EEModuleDependencyDelegate.java deleted file mode 100644 index 79da9d001..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/J2EEModuleDependencyDelegate.java +++ /dev/null @@ -1,442 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Justin Chen - development check in - * Ian Trimble - run reference-changing code in WorkspaceJob (bug# 144006) - *******************************************************************************/ -package org.eclipse.jst.jsf.core.internal.jsflibraryconfig; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.jar.Manifest; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.emf.common.util.URI; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jem.workbench.utility.JemProjectUtilities; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jst.j2ee.application.internal.operations.ClassPathSelection; -import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.common.ClasspathModel; -import org.eclipse.jst.j2ee.internal.common.operations.UpdateJavaBuildPathOperation; -import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; -import org.eclipse.jst.jsf.core.internal.Messages; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; -import org.eclipse.jst.jsf.core.internal.project.facet.JSFUtils; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.frameworks.internal.ui.WTPUIPlugin; - -/** - * <b>J2EEModuleDependencyDelegate</b> provides a service to update project dependencies. - * It includes updating web library dependencies and java build path for web modules. - * - * @author Justin Chen - Oracle - */ -public class J2EEModuleDependencyDelegate { - final private IProject project; - final private ClasspathModel model; - - /** - * Constructor - * @param project IProject instance on which to update dependencies. - */ - public J2EEModuleDependencyDelegate(IProject project) { - this.project = project; - this.model = newClasspathModel(project); - } - - /** - * To update project dependencies including Java buildpath and - * web library dependencies from JSFLibraryConfigModel. - * - * @param model_ JSFLibraryConfigModel instance with information to update project dependencies - * @param monitor IProgressMonitor progress monitor passed. New instance is creatsed if a null is given - */ - public void updateProjectDependencies(final JSFLibraryConfigModel model_, - IProgressMonitor monitor) { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - // update implementation library - JSFProjectLibraryReference newImplLib = model_.getCurrentJSFImplementationLibrarySelection(); - JSFProjectLibraryReference savedImplLib = model_.getSavedJSFImplementationLibrary(); - if (savedImplLib != null) { - this.removeProjectDependency(savedImplLib.getLibrary(), monitor); - this.addProjectDependency(newImplLib.getLibrary(), newImplLib.isCheckedToBeDeployed(), monitor); - } else { - this.addProjectDependency(newImplLib.getLibrary(), newImplLib.isCheckedToBeDeployed(), monitor); - } - - // update component libraries - // Remove first and then add dependencies from selected libraries currently. - JSFProjectLibraryReference compLibDctr = null; - List savedCompLibs = model_.getSavedJSFComponentLibraries(); - Iterator it = savedCompLibs.iterator(); - while (it.hasNext()) { - compLibDctr = (JSFProjectLibraryReference) it.next(); - this.removeProjectDependency(compLibDctr.getLibrary(), monitor); - } - - List selComponentLibs = model_.getCurrentJSFComponentLibrarySelection(); - it = selComponentLibs.iterator(); - while (it.hasNext()) { - compLibDctr = (JSFProjectLibraryReference) it.next(); - if (compLibDctr.isSelected()) { - this.addProjectDependency(compLibDctr.getLibrary(), - compLibDctr.isCheckedToBeDeployed(), - monitor); - } - } - } - - /** - * Add the given jsfLibrary instance as project dependency. - * If toDeploy is true, the JARs from JSF library is added as web library dependencies. - * Otherwise, JARs are added in project build path only. - * - * @param jsfLibrary JSFLibrary instance to be added as project dependencies. - * @param toDeploy boolean add as web library project for a web module if true. Otheriwse, add to build path only - * @param monitor IProgressMOnitor - */ - private void addProjectDependency(final JSFLibrary jsfLibrary, - final boolean toDeploy, - final IProgressMonitor monitor) { - IPath[] jarPaths = JSFUtils.getJARPathforJSFLibwFilterMissingJars(jsfLibrary, true); - updateProjectDependency(jarPaths, toDeploy, monitor); - } - - /** - * Remove given <b>jsfLibrary</b> from project dependency, - * including web library dependencies and project build path. - * - * @param jsfLibrary JSFLibrary instance to be removed from project dependencies. - * @param monitor - */ - private void removeProjectDependency(final JSFLibrary jsfLibrary, final IProgressMonitor monitor) { - IPath[] elements = JSFUtils.getJARPathforJSFLib(jsfLibrary, false); - removeProjectDependency_(elements, monitor); - } - - /** - * To update project dependencies by the path collection of JARs. - * - * All JARs are added into project build path. - * However, JARs are added as web library dependencies only if deployme is true. - * - * @param elems IPath[] - * @param deployme boolean - * @param monitor IProgressMonitor - */ - private void updateProjectDependency(final IPath[] elems, - final boolean deployme, - final IProgressMonitor monitor) { - - ClassPathSelection selection = null; - /** - * For each JAR defined in a JSF Library, it is added as J2EE Module Dependency if - * the JSF Library is checked for deployment. However, JARs are added into project build path - * regardless if a JSF Library is checked for deployment or not. - * - */ - String type = VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR; - for (int i= 0; i < elems.length; i++) { - IVirtualComponent archive = ComponentCore.createArchiveComponent( model.getComponent().getProject(), type + elems[i].toString()); - - // Added as J2EE Module Dependency if need to be deployed - if (deployme) { - // fix for bug# 144006 - wrap in WorkspaceJob - SetReferencesJob setRefsJob = new SetReferencesJob(project, model.getComponent(), archive, true); - setRefsJob.schedule(); - } else { - // added into the path selection to update build path later. - ClasspathElement element = createClassPathElement(archive, archive.getName(), true); - if (selection == null) { - selection = createClassPathSelectionForExternalJar(element); - } else { - selection.getClasspathElements().add(element); - } - model.getClassPathSelectionForWLPs().getClasspathElements().add(element); - } - } // end For - - // Add JARs into build path for selected JSF libs checked for not deploy. - if (selection != null) { - IRunnableWithProgress buildPathOP = createBuildPathOperationForExternalJar(selection); - try { - buildPathOP.run(monitor); - } catch (InvocationTargetException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); - } catch (InterruptedException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); - } - } - } - - /** - * To remove project dependencies from the path collection of JARs. - * - * @param elems IPath[] elems - * @param monitor IProgressMonitor - */ - private void removeProjectDependency_(final IPath[] elems, final IProgressMonitor monitor) { - - ClassPathSelection selection = null; - for (int i= 0; i < elems.length; i++) { - String type = VirtualArchiveComponent.LIBARCHIVETYPE + IPath.SEPARATOR; - IVirtualComponent archive = ComponentCore.createArchiveComponent( model.getComponent().getProject(), type + elems[i].toString()); - // fix for bug# 144006 - wrap in WorkspaceJob - SetReferencesJob setRefsJob = new SetReferencesJob(project, model.getComponent(), archive, false); - setRefsJob.schedule(); - - // Update project classpath - ClasspathElement element = createClassPathElement(archive, archive.getName(), false); - if (selection == null) { - selection = createClassPathSelectionForExternalJar(element); - } else { - selection.getClasspathElements().add(element); - } - selection.getClasspathElements().add(element); - model.getClassPathSelectionForWLPs().getClasspathElements().remove(element); - } // end for - - IRunnableWithProgress buildPathOP = createBuildPathOperationForExternalJar(selection); - try { - buildPathOP.run(monitor); - } catch (InvocationTargetException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); - } catch (InterruptedException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); - } - } - - private void removeReference(ArrayList vList, IVirtualReference ref) { - IVirtualReference elem = null; - for (int i = 0; i < vList.size(); i++) { - elem = (IVirtualReference)vList.get(i); - if (elem.getReferencedComponent().getName().equalsIgnoreCase(ref.getReferencedComponent().getName())) { - vList.remove(elem); - } - } - } - - /** - * To Do: check if archive component already exists - * - * @param vlist ArrayList - * @param ref IVirtualReference - */ - private void addReferences(ArrayList vlist, IVirtualReference ref) { - IVirtualReference elem = null; - boolean exist = false; - for (int i = 0; i < vlist.size(); i++) { - elem = (IVirtualReference)vlist.get(i); - if (elem.getReferencedComponent().getName().equalsIgnoreCase(ref.getReferencedComponent().getName())) { - exist = true; - break; - } - } - if ( !exist) { - vlist.add(ref); - } - } - - private ClasspathModel newClasspathModel(IProject project_) { - ClasspathModel model_ = new ClasspathModel(null); - model_.setProject(project_); - if( model_.getComponent() != null ){ - updateModelManifest(model_); - } - return model_; - } - - private ClasspathElement createClassPathElement( - IVirtualComponent archiveComp, - String unresolvedName, - boolean addedToPath) { - - URI uri = URI.createURI(ModuleURIUtil.getHandleString(archiveComp)); - ClasspathElement element = new ClasspathElement(uri); - element.setValid(false); - element.setSelected(addedToPath); - element.setRelativeText(unresolvedName); - element.setText(unresolvedName); - element.setEarProject(null); - return element; - } - - private ClassPathSelection createClassPathSelectionForExternalJar(ClasspathElement element){ - ClassPathSelection selection = new ClassPathSelection(); - selection.getClasspathElements().add(element); - return selection; - } - - private IRunnableWithProgress createBuildPathOperationForExternalJar(ClassPathSelection selection) { - IJavaProject javaProject = JemProjectUtilities.getJavaProject(project); - return WTPUIPlugin.getRunnableWithProgress(new UpdateJavaBuildPathOperation(javaProject, selection)); - } - - private void updateModelManifest(ClasspathModel model_) { - if (JemProjectUtilities.isBinaryProject(project) || model_.getAvailableEARComponents().length == 0) { - return; - } - - IContainer root = null; - IFile manifestFile = null; - if (project != null) { - root = project; - } else { - root = JemProjectUtilities.getSourceFolderOrFirst(project, null); - } - if (root != null) { - manifestFile = root.getFile(new Path(J2EEConstants.MANIFEST_URI)); - } - if (manifestFile == null || !manifestFile.exists()) { - return; - } - - InputStream in = null; - try { - in = manifestFile.getContents(); - ArchiveManifest mf = new ArchiveManifestImpl(new Manifest(in)); - model_.primSetManifest(mf); - } catch (CoreException e) { - model_.primSetManifest(new ArchiveManifestImpl()); - } catch (IOException iox) { - model_.primSetManifest(new ArchiveManifestImpl()); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - //Ignore - } - } - } - } - - /** - * SetReferencesJob is responsible for adding or removing IVirtualReference - * instances on a specified IVirtualComponent and runs as a WorkspaceJob. - * - * @author Ian Trimble - Oracle - */ - class SetReferencesJob extends WorkspaceJob { - - /** - * IProject instance. - */ - protected IProject project = null; - /** - * IVirtualComponent instance on which to set references. - */ - protected IVirtualComponent parentComponent = null; - /** - * IVirtualComponent instance to be added or removed as a reference on parentComponent. - */ - protected IVirtualComponent referencedComponent = null; - /** - * If true, referencedComponent is added; if false, it is removed. - */ - protected boolean addReferencedComponent = true; - - /** - * Instantiates and configures a SetReferencesJob. - * - * @param project IProject instance on which to set rule. - * @param parentComponent IVirtualComponent instance on which to set references. - * @param referencedComponent IVirtualComponent instance to be added or removed as a reference on parentComponent. - * @param addReferencedComponent If true, referencedComponent is added; if false, it is removed. - */ - public SetReferencesJob( - IProject project, - IVirtualComponent parentComponent, - IVirtualComponent referencedComponent, - boolean addReferencedComponent) { - super(Messages.J2EEModuleDependencyDelegate_UpdatingJ2EEModuleDependencies); - this.project = project; - this.parentComponent = parentComponent; - this.referencedComponent = referencedComponent; - this.addReferencedComponent = addReferencedComponent; - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - setRule(workspace.getRuleFactory().createRule(workspace.getRoot())); - setUser(true); - } - - /* - * (non-Javadoc) - * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - try { - String projectName = project != null ? project.getName() : "null"; - monitor.beginTask( - NLS.bind(Messages.J2EEModuleDependencyDelegate_UpdatingJ2EEModuleDependenciesForProject, projectName), - 5); - if (parentComponent != null) { - //copy from array to list - ArrayList refList = new ArrayList(); - IVirtualReference[] refArray = parentComponent.getReferences(); - for (int i = 0; i < refArray.length; i++) { - refList.add(refArray[i]); - } - monitor.worked(1); - //create new reference - IVirtualReference reference = ComponentCore.createReference( - parentComponent, - referencedComponent, - new Path("/WEB-INF/lib")); //$NON-NLS-1$ - monitor.worked(1); - //add or remove reference - if (addReferencedComponent) { - addReferences(refList, reference); - } else { - removeReference(refList, reference); - } - monitor.worked(1); - //copy from list to array - IVirtualReference[] newRefArray = new IVirtualReference[refList.size()]; - newRefArray = (IVirtualReference[])refList.toArray(newRefArray); - monitor.worked(1); - //set references - parentComponent.setReferences(newRefArray); - monitor.worked(1); - } else { - monitor.worked(5); - } - } finally { - monitor.done(); - } - return Status.OK_STATUS; - } - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigDialogSettingData.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigDialogSettingData.java index 6d7e994c8..e51105c55 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigDialogSettingData.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigDialogSettingData.java @@ -32,7 +32,7 @@ public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModel final private JSFLibraryRegistryUtil jsfLibReg; final private boolean dftImplLibDeployFlag; final private String[] savedCompLibs; - private JSFProjectLibraryReference selJSFLibImpl; // lazy initialized + private JSFLibraryReference selJSFLibImpl; // lazy initialized private List selJSFLibComp; // lazy initialized /** @@ -66,14 +66,14 @@ public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModel * A null is returned when there is no default * implementation library in registry. * - * @return selJSFLibImpl JSFProjectLibraryReference return default implementation library with updated deployment flag + * @return selJSFLibImpl JSFLibraryReference return default implementation library with updated deployment flag */ - public JSFProjectLibraryReference getJSFImplementationLibrary() { + public JSFLibraryReference getJSFImplementationLibrary() { if (selJSFLibImpl == null) { - // To instanciate a JSFProjectLibraryReference object from default impl lib as the saved library. - JSFProjectLibraryReference dftImplLib = jsfLibReg.getDefaultJSFImplementationLibrary(); + // To instanciate a JSFLibraryReference object from default impl lib as the saved library. + JSFLibraryReference dftImplLib = jsfLibReg.getDefaultJSFImplementationLibrary(); if (dftImplLib != null) { - selJSFLibImpl = new JSFProjectLibraryReference(dftImplLib.getLibrary(), + selJSFLibImpl = new JSFLibraryReference(dftImplLib.getLibrary(), true, // selected dftImplLibDeployFlag); } @@ -91,7 +91,7 @@ public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModel selJSFLibComp = new ArrayList(); if (savedCompLibs != null && savedCompLibs.length > 0) { - JSFProjectLibraryReference lib = null; + JSFLibraryReference lib = null; String item; String[] attributes; String id; @@ -104,9 +104,9 @@ public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModel id = attributes[0]; deploy = Boolean.valueOf(attributes[1]).booleanValue(); - lib = jsfLibReg.getJSFLibryReferencebyID(id); + lib = jsfLibReg.getJSFLibraryReferencebyID(id); if (lib != null) { - selJSFLibComp.add(new JSFProjectLibraryReference(lib.getLibrary(), true, deploy)); + selJSFLibComp.add(new JSFLibraryReference(lib.getLibrary(), true, deploy)); } /*else { // already logged if a saved component library is no longer available. }*/ @@ -128,7 +128,7 @@ public class JSFLibraryConfigDialogSettingData implements JSFLibraryConfiglModel item = savedCompLibs[i]; attributes = item.split(SEPARATOR); - if (jsfLibReg.getJSFLibryReferencebyID(attributes[0]) == null) { + if (jsfLibReg.getJSFLibraryReferencebyID(attributes[0]) == null) { JSFCorePlugin.log(IStatus.INFO, Messages.JSFLibCfgDialogSettingData_Sticky_Component_Lib_Not_Exist); } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigModel.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigModel.java index d1ca4a168..005d21d85 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigModel.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigModel.java @@ -52,13 +52,13 @@ public class JSFLibraryConfigModel { * and then update the list with saved implementation library. */ colJSFImplLib = jsfLibReg.getJSFImplementationLibraries(); - JSFProjectLibraryReference targetLib = data.getJSFImplementationLibrary(); + JSFLibraryReference targetLib = data.getJSFImplementationLibrary(); if (targetLib == null) { // no saved implementation, get default implementation library targetLib = jsfLibReg.getDefaultJSFImplementationLibrary(); } if (targetLib != null) { - JSFProjectLibraryReference srcLib = jsfLibReg.getJSFLibryReferencebyID(targetLib.getID()); + JSFLibraryReference srcLib = jsfLibReg.getJSFLibraryReferencebyID(targetLib.getID()); if (srcLib != null) { srcLib.setSelected(true); srcLib.setToBeDeployed(targetLib.isCheckedToBeDeployed()); @@ -84,11 +84,11 @@ public class JSFLibraryConfigModel { */ colJSFCompLib = jsfLibReg.getJSFComponentLibraries(); Iterator it = data.getJSFComponentLibraries().iterator(); - JSFProjectLibraryReference targetItem = null; - JSFProjectLibraryReference srcItem = null; + JSFLibraryReference targetItem = null; + JSFLibraryReference srcItem = null; while (it.hasNext()) { - targetItem = (JSFProjectLibraryReference) it.next(); - srcItem = jsfLibReg.getJSFLibryReferencebyID(targetItem.getID()); + targetItem = (JSFLibraryReference) it.next(); + srcItem = jsfLibReg.getJSFLibraryReferencebyID(targetItem.getID()); if (srcItem != null) { srcItem.setSelected(true); srcItem.setToBeDeployed(targetItem.isCheckedToBeDeployed()); @@ -102,13 +102,13 @@ public class JSFLibraryConfigModel { * Return the selected JSF implementation library currently. * A null is returned if none is selected. * - * @return JSFProjectLibraryReference + * @return JSFLibraryReference */ - public JSFProjectLibraryReference getCurrentJSFImplementationLibrarySelection() { + public JSFLibraryReference getCurrentJSFImplementationLibrarySelection() { Iterator it = getJSFImplementationLibraries().iterator(); - JSFProjectLibraryReference crtItem = null; + JSFLibraryReference crtItem = null; while (it.hasNext()) { - crtItem = (JSFProjectLibraryReference) it.next(); + crtItem = (JSFLibraryReference) it.next(); if (crtItem.isSelected()) { return crtItem; } @@ -126,9 +126,9 @@ public class JSFLibraryConfigModel { List list = new ArrayList(); Iterator it = getJSFComponentLibraries().iterator(); - JSFProjectLibraryReference crtItem = null; + JSFLibraryReference crtItem = null; while (it.hasNext()) { - crtItem = (JSFProjectLibraryReference) it.next(); + crtItem = (JSFLibraryReference) it.next(); if (crtItem.isSelected()) { list.add(crtItem); } @@ -140,9 +140,9 @@ public class JSFLibraryConfigModel { * Returned a saved implementation library which was persisted as * DialogSettings or as project properties. * - * @return JSFProjectLibraryReference + * @return JSFLibraryReference */ - public JSFProjectLibraryReference getSavedJSFImplementationLibrary() { + public JSFLibraryReference getSavedJSFImplementationLibrary() { return data.getJSFImplementationLibrary(); } @@ -162,14 +162,14 @@ public class JSFLibraryConfigModel { * Note: The library parameter won't be not added into the collection * if it does not exist already. * - * @param library JSFProjectLibraryReference + * @param library JSFLibraryReference */ - public void setCurrentJSFImplementationLibrarySelection(final JSFProjectLibraryReference library) { + public void setCurrentJSFImplementationLibrarySelection(final JSFLibraryReference library) { if (library != null) { Iterator it = getJSFImplementationLibraries().iterator(); - JSFProjectLibraryReference crtjsflib = null; + JSFLibraryReference crtjsflib = null; while (it.hasNext()) { - crtjsflib = (JSFProjectLibraryReference) it.next(); + crtjsflib = (JSFLibraryReference) it.next(); if (crtjsflib.getID().equals(library.getID())) { crtjsflib.setSelected(true); crtjsflib.setToBeDeployed(library.isCheckedToBeDeployed()); @@ -193,11 +193,11 @@ public class JSFLibraryConfigModel { setJSFLibrariesSelection(getJSFComponentLibraries(), false); Iterator it = libraries.iterator(); - JSFProjectLibraryReference crtItem; - JSFProjectLibraryReference srcItem = null; + JSFLibraryReference crtItem; + JSFLibraryReference srcItem = null; while (it.hasNext()) { - crtItem = (JSFProjectLibraryReference) it.next(); - srcItem = jsfLibReg.getJSFLibryReferencebyID(crtItem.getID()); + crtItem = (JSFLibraryReference) it.next(); + srcItem = jsfLibReg.getJSFLibraryReferencebyID(crtItem.getID()); if (srcItem != null) { srcItem.setSelected(true); @@ -229,9 +229,9 @@ public class JSFLibraryConfigModel { */ private void setJSFLibrariesSelection(final List libs, final boolean state) { Iterator it = libs.iterator(); - JSFProjectLibraryReference crtjsflib; + JSFLibraryReference crtjsflib; while (it.hasNext()) { - crtjsflib = (JSFProjectLibraryReference) it.next(); + crtjsflib = (JSFLibraryReference) it.next(); crtjsflib.setSelected(state); } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigProjectData.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigProjectData.java index ca3816f01..b7ac0d46d 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigProjectData.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfigProjectData.java @@ -42,7 +42,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource final private IProject project; final private JSFLibraryRegistryUtil jsfLibReg; - private JSFProjectLibraryReference selJSFLibImpl = null; + private JSFLibraryReference selJSFLibImpl = null; private List selJSFLibComp = null; /** @@ -67,7 +67,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource * * @return selJSFLibImpl JSFLibraryDecorator */ - public JSFProjectLibraryReference getJSFImplementationLibrary() { + public JSFLibraryReference getJSFImplementationLibrary() { try { if (!isProjectFirstCreated() && selJSFLibImpl == null ) { @@ -76,7 +76,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource selJSFLibImpl = getJSFImplLibfromPersistentProperties(getTuples(strImplLibs)); } } catch (CoreException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); + JSFCorePlugin.log(e, "Exception occured while returning reference to the JSF implementation library"); } return selJSFLibImpl; } @@ -99,13 +99,13 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource Iterator it = savedList.iterator(); Tuple crtTuple = null; - JSFProjectLibraryReference srcItem = null; + JSFLibraryReference srcItem = null; while (it.hasNext()) { crtTuple = (Tuple) it.next(); - srcItem = jsfLibReg.getJSFLibryReferencebyID(crtTuple.getID()); + srcItem = jsfLibReg.getJSFLibraryReferencebyID(crtTuple.getID()); if (srcItem != null) { - selJSFLibComp.add( new JSFProjectLibraryReference(srcItem.getLibrary(), + selJSFLibComp.add( new JSFLibraryReference(srcItem.getLibrary(), true, crtTuple.needDeploy()) ); } /*else { @@ -117,7 +117,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource selJSFLibComp = new ArrayList(0); } } catch (CoreException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); + JSFCorePlugin.log(e, "Exception occured while returning references to the JSF component libraries."); } return selJSFLibComp; } @@ -141,7 +141,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource selJSFLibComp = null; } catch (CoreException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); + JSFCorePlugin.log(e, "Exception occured while persisting the JSF Library preferences"); } } @@ -169,7 +169,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource logMissingLib(getTuples(strCompLibs), false); } catch (CoreException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); + JSFCorePlugin.log(e, "Exception occured while verifying saved JSF Library preferences"); } } @@ -178,7 +178,7 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource Iterator itTuple = jsfLibTuples.iterator(); while(itTuple.hasNext()) { Tuple tuple = (Tuple)itTuple.next(); - JSFProjectLibraryReference jsfLib = jsfLibReg.getJSFLibryReferencebyID(tuple.getID()); + JSFLibraryReference jsfLib = jsfLibReg.getJSFLibraryReferencebyID(tuple.getID()); /* Information logged when saved JSF lib is removed from registry. * One log entry is created for each missing library. */ @@ -193,16 +193,16 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource } } - private JSFProjectLibraryReference getJSFImplLibfromPersistentProperties(final List jsfLibTuples) { + private JSFLibraryReference getJSFImplLibfromPersistentProperties(final List jsfLibTuples) { if (jsfLibReg != null) { Tuple tuple = null; - JSFProjectLibraryReference lib = null; + JSFLibraryReference lib = null; Iterator itTuple = jsfLibTuples.iterator(); while(itTuple.hasNext()) { tuple = (Tuple) itTuple.next(); - lib = jsfLibReg.getJSFLibryReferencebyID(tuple.id); + lib = jsfLibReg.getJSFLibraryReferencebyID(tuple.id); if (lib != null) { - return new JSFProjectLibraryReference(lib.getLibrary(), + return new JSFLibraryReference(lib.getLibrary(), tuple.selected, tuple.deploy); } /*else { @@ -214,10 +214,10 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource } private String generatePersistString(List list) { - JSFProjectLibraryReference jsfLibItem; + JSFLibraryReference jsfLibItem; StringBuffer sb = new StringBuffer(); for (int i = 0; i < list.size(); i++) { - jsfLibItem = (JSFProjectLibraryReference)list.get(i); + jsfLibItem = (JSFLibraryReference)list.get(i); sb = sb.append(jsfLibItem.generatePersistString()); sb.append(JSFLibraryConfigProjectData.EO_TUPLE); } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfiglModelSource.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfiglModelSource.java index 1413571d3..7a6c0736c 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfiglModelSource.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryConfiglModelSource.java @@ -25,9 +25,9 @@ public interface JSFLibraryConfiglModelSource { * * A null could be returned when creating first web project in a new workspace. * - * @return JSFProjectLibraryReference + * @return JSFLibraryReference */ - public JSFProjectLibraryReference getJSFImplementationLibrary(); + public JSFLibraryReference getJSFImplementationLibrary(); /** * Return a list of saved JSF component libraries. diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFProjectLibraryReference.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryReference.java index 9d4b481ca..4033d3a0a 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFProjectLibraryReference.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryReference.java @@ -18,7 +18,7 @@ import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; * * @author Justin Chen - Oracle */ -public class JSFProjectLibraryReference { +public class JSFLibraryReference { final private JSFLibrary jsfLib; private boolean check4Deploy; // Initialized from default in workspace private boolean selected; // selected for project @@ -29,7 +29,7 @@ public class JSFProjectLibraryReference { * @param selected boolean true if selected, otherwise, not selected. * @param deploy boolean true if needs to be deployed, otherwise, won't be deployed. */ - public JSFProjectLibraryReference(JSFLibrary jsfLib, boolean selected, boolean deploy) { + public JSFLibraryReference(JSFLibrary jsfLib, boolean selected, boolean deploy) { this.jsfLib = jsfLib; this.selected = selected; this.check4Deploy = deploy; diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryRegistryUtil.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryRegistryUtil.java index 850d947c4..067cee553 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryRegistryUtil.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryconfig/JSFLibraryRegistryUtil.java @@ -13,8 +13,20 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.util.EList; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; +import org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer; +import org.eclipse.jst.jsf.core.internal.JSFLibraryClasspathContainer; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; @@ -28,11 +40,11 @@ import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; * * The lists are updated when there are changes in JSF library registry. * - * @author Justin Chen - Oracle + * @author Justin Chen, etc. - Oracle + * TODO: consider making all methods static */ public class JSFLibraryRegistryUtil { private static JSFLibraryRegistryUtil instance = null; - final private JSFLibraryRegistry jsfLibReg; private List implLibs = null; private List compLibs = null; @@ -40,7 +52,6 @@ public class JSFLibraryRegistryUtil { * Private constructor */ private JSFLibraryRegistryUtil() { - jsfLibReg = JSFCorePlugin.getDefault().getJSFLibraryRegistry(); } /** @@ -48,7 +59,7 @@ public class JSFLibraryRegistryUtil { * * @return JSFLibraryRegistryUtil */ - public static JSFLibraryRegistryUtil getInstance() { + public synchronized static JSFLibraryRegistryUtil getInstance() { if ( instance == null ) { instance = new JSFLibraryRegistryUtil(); } @@ -56,12 +67,12 @@ public class JSFLibraryRegistryUtil { } /** - * Return the JSFLibraryRegistry instance. + * Convenience method to return the JSFLibraryRegistry instance. * * @return jsfLibReg JSFLibraryRegistry */ public JSFLibraryRegistry getJSFLibraryRegistry() { - return jsfLibReg; + return JSFCorePlugin.getDefault().getJSFLibraryRegistry(); } /** @@ -70,11 +81,11 @@ public class JSFLibraryRegistryUtil { * * @return JSFLibraryDecorator */ - public JSFProjectLibraryReference getDefaultJSFImplementationLibrary() { - JSFLibrary dftImplLib = jsfLibReg.getDefaultImplementation(); + public JSFLibraryReference getDefaultJSFImplementationLibrary() { + JSFLibrary dftImplLib = getJSFLibraryRegistry().getDefaultImplementation(); return ((dftImplLib != null) ? - getJSFLibryReferencebyID(dftImplLib.getID()) : + getJSFLibraryReferencebyID(dftImplLib.getID()) : null); } @@ -86,12 +97,12 @@ public class JSFLibraryRegistryUtil { */ List getJSFImplementationLibraries() { if (implLibs == null) { - implLibs = wrapJSFLibraries(jsfLibReg.getImplJSFLibraries()); + implLibs = wrapJSFLibraries(getJSFLibraryRegistry().getImplJSFLibraries()); } else { - if (implLibs.size() != jsfLibReg.getImplJSFLibraries().size() || + if (implLibs.size() != getJSFLibraryRegistry().getImplJSFLibraries().size() || isAnyLibraryChanged(implLibs)) { implLibs.clear(); - implLibs = wrapJSFLibraries(jsfLibReg.getImplJSFLibraries()); + implLibs = wrapJSFLibraries(getJSFLibraryRegistry().getImplJSFLibraries()); } } return implLibs; @@ -105,12 +116,12 @@ public class JSFLibraryRegistryUtil { */ List getJSFComponentLibraries() { if (compLibs == null) { - compLibs = wrapJSFLibraries(jsfLibReg.getNonImplJSFLibraries()); + compLibs = wrapJSFLibraries(getJSFLibraryRegistry().getNonImplJSFLibraries()); } else { - if (compLibs.size() != jsfLibReg.getNonImplJSFLibraries().size() || + if (compLibs.size() != getJSFLibraryRegistry().getNonImplJSFLibraries().size() || isAnyLibraryChanged(compLibs)) { compLibs.clear(); - compLibs = wrapJSFLibraries(jsfLibReg.getNonImplJSFLibraries()); + compLibs = wrapJSFLibraries(getJSFLibraryRegistry().getNonImplJSFLibraries()); } } return compLibs; @@ -123,13 +134,13 @@ public class JSFLibraryRegistryUtil { * @param id String * @return JSFLibraryDecorator */ - public JSFProjectLibraryReference getJSFLibryReferencebyID(final String id) { + public JSFLibraryReference getJSFLibraryReferencebyID(final String id) { Iterator it = getJSFImplementationLibraries().iterator(); - JSFProjectLibraryReference crtItem = null; + JSFLibraryReference crtItem = null; // search implementation libraries while(it.hasNext()) { - crtItem = (JSFProjectLibraryReference)it.next(); + crtItem = (JSFLibraryReference)it.next(); if (id.equals(crtItem.getID())) { return crtItem; } @@ -137,7 +148,7 @@ public class JSFLibraryRegistryUtil { // search component libraries it = getJSFComponentLibraries().iterator(); while(it.hasNext()) { - crtItem = (JSFProjectLibraryReference)it.next(); + crtItem = (JSFLibraryReference)it.next(); if (id.equals(crtItem.getID())) { return crtItem; } @@ -150,14 +161,14 @@ public class JSFLibraryRegistryUtil { * JSF implementation libraries or component libraries. * The decision is based on if a JSF library is an implementation. * - * @param library JSFProjectLibraryReference + * @param library JSFLibraryReference */ - public void addJSFLibrary(final JSFProjectLibraryReference library) { + public void addJSFLibrary(final JSFLibraryReference library) { // Library is added only if it does not exist in registry - if (library != null && jsfLibReg.getJSFLibraryByID(library.getID()) == null) { + if (library != null && getJSFLibraryRegistry().getJSFLibraryByID(library.getID()) == null) { // Add the library working copy into workspace registry. JSFLibrary jsfLib = library.getLibrary(); - jsfLibReg.addJSFLibrary(jsfLib.getWorkingCopy()); + getJSFLibraryRegistry().addJSFLibrary(jsfLib.getWorkingCopy()); // Add library into the collection depends on its type. List list = (library.isImplementation() ? @@ -171,13 +182,13 @@ public class JSFLibraryRegistryUtil { List list = new ArrayList(); if (libs != null) { JSFLibrary jsfLib; - JSFProjectLibraryReference jsfLibDctr; + JSFLibraryReference jsfLibDctr; Iterator it = libs.iterator(); while (it.hasNext()) { jsfLib = (JSFLibrary) it.next(); // Set unselected and undeployed initially. - jsfLibDctr = new JSFProjectLibraryReference(jsfLib.getWorkingCopy(), + jsfLibDctr = new JSFLibraryReference(jsfLib, //.getWorkingCopy(), false, false); list.add(jsfLibDctr); @@ -188,11 +199,11 @@ public class JSFLibraryRegistryUtil { private boolean isAnyLibraryChanged(final List list) { Iterator it = list.iterator(); - JSFProjectLibraryReference wclib = null; // working copy library + JSFLibraryReference wclib = null; // working copy library JSFLibrary lib = null; while(it.hasNext()) { - wclib = (JSFProjectLibraryReference)it.next(); + wclib = (JSFLibraryReference)it.next(); lib = getJSFLibraryRegistry().getJSFLibraryByID(wclib.getID()); if (lib == null) { // removed. Hence, changed. return true; @@ -232,5 +243,128 @@ public class JSFLibraryRegistryUtil { } return false; } + + /** + * Get the classpath entries for a JSF Library + * @param lib + * @return IClasspathEntry[] + */ + public IClasspathEntry[] getClasspathEntries(JSFLibrary lib){ + //TODO: cache to optimize. probably belongs inside JSFLibrary model. + ArrayList res= new ArrayList(lib.getArchiveFiles().size()); + for (Iterator it=lib.getArchiveFiles().iterator();it.hasNext();) { + ArchiveFile jar= (ArchiveFile)it.next(); + if (jar != null && jar.exists()) { + IClasspathEntry entry = getClasspathEntry(jar); + if (entry != null) + res.add(entry); + } + } + IClasspathEntry[] entries= (IClasspathEntry[]) res.toArray(new IClasspathEntry[res.size()]); + return entries; + } + + /** + * Create IClasspathEntry for ArchiveFile + * @param jar + * @return IClasspathEntry + */ + public IClasspathEntry getClasspathEntry(ArchiveFile jar){ + IClasspathEntry entry = null; + if (jar !=null && jar.exists()){ + entry = JavaCore.newLibraryEntry(new Path(jar.getResolvedSourceLocation()), null, null);//, nu, sourceAttachRoot, accessRules, extraAttributes, false/*not exported*/); + } + return entry; + } + + /** + * Binds JSF Libraries to classpath containers when the library changes. + * + * This method will deal with library/cp container renames by removing the old classpath container and then adding. + * + * @param oldId + * @param newId + * @param removeAndAddBecauseOfRename + * @param monitor + * @throws JavaModelException + */ + public static void rebindClasspathContainerEntries(String oldId, String newId, boolean removeAndAddBecauseOfRename, IProgressMonitor monitor) throws JavaModelException { + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); + IJavaProject[] projects= JavaCore.create(root).getJavaProjects(); + IPath containerPath= new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID).append(newId); + IPath oldContainerPath = new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID).append(oldId); + + JSFLibrary lib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(newId); + List affectedProjects= new ArrayList(); + removeAndAddBecauseOfRename = (!oldId.equals(newId)); + // find all projects using the old container name... + for (int i= 0; i < projects.length; i++) { + IJavaProject project= projects[i]; + IClasspathEntry[] entries= project.getRawClasspath(); + for (int k= 0; k < entries.length; k++) { + IClasspathEntry curr= entries[k]; + if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { + if (oldContainerPath.equals(curr.getPath())) { + affectedProjects.add(project); + break; + } + } + } + } + + if (!affectedProjects.isEmpty()) { + IJavaProject[] affected= (IJavaProject[]) affectedProjects.toArray(new IJavaProject[affectedProjects.size()]); + IClasspathContainer[] containers= new IClasspathContainer[affected.length]; + removeAndAddBecauseOfRename = (!oldId.equals(newId)); + if (removeAndAddBecauseOfRename){//not very pretty... remove and add new container + IClasspathEntry newEntry = JavaCore.newContainerEntry(containerPath); + for (int i= 0; i < affected.length; i++) { + IJavaProject project= affected[i]; + IClasspathEntry[] entries= project.getRawClasspath(); + List keptEntries = new ArrayList(); + //keep all entries except the old one + for (int k= 0; k < entries.length; k++) { + IClasspathEntry curr= entries[k]; + if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER){ + if( ! oldContainerPath.equals(curr.getPath())) + keptEntries.add(curr); + } + else { + keptEntries.add(curr); + } + } + // add new container entry + keptEntries.add(newEntry); + setRawClasspath(project, keptEntries, monitor); + } + + } + else {//rebind + + JSFLibraryClasspathContainer container= new JSFLibraryClasspathContainer(lib); + containers[0] = container; + JavaCore.setClasspathContainer(containerPath, affected, containers, monitor); + } + } else { + if (monitor != null) { + monitor.done(); + } + } + } + + /** + * Sets the raw classpath on a project and logs an error if it when a JavaModelException occurs + * @param project + * @param cpEntries + * @param monitor + */ + public static void setRawClasspath(IJavaProject project, List cpEntries, IProgressMonitor monitor) { + IClasspathEntry[] entries = (IClasspathEntry[])cpEntries.toArray(new IClasspathEntry[0]); + try { + project.setRawClasspath(entries, monitor); + } catch (JavaModelException e) { + JSFCorePlugin.log(e, "Unable to set classpath for: "+project.getProject().getName()); + } + } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibrary.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibrary.java index f42a414d5..7eebd7906 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibrary.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibrary.java @@ -11,7 +11,6 @@ package org.eclipse.jst.jsf.core.internal.jsflibraryregistry; import org.eclipse.emf.common.util.EList; - import org.eclipse.emf.ecore.EObject; /** @@ -53,24 +52,13 @@ public interface JSFLibrary extends EObject{ * </p> * <!-- end-user-doc --> * @return the value of the '<em>ID</em>' attribute. - * @see #setID(String) * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryPackage#getJSFLibrary_ID() - * @model default="" id="true" required="true" + * @model default="" transient="true" changeable="false" derived="true" * @generated */ String getID(); /** - * Sets the value of the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary#getID <em>ID</em>}' attribute. - * <!-- begin-user-doc --> - * <!-- end-user-doc --> - * @param value the new value of the '<em>ID</em>' attribute. - * @see #getID() - * @generated - */ - void setID(String value); - - /** * Returns the value of the '<em><b>Name</b></em>' attribute. * <!-- begin-user-doc --> * <p> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistry.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistry.java index 34a85903d..bdcec5be6 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistry.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistry.java @@ -119,12 +119,12 @@ public interface JSFLibraryRegistry extends EObject{ /** * <!-- begin-user-doc --> - * @param value * <!-- end-user-doc --> + * @param implementation library * @model implementationRequired="true" * @generated */ - void setDefaultImplementation(JSFLibrary value); + void setDefaultImplementation(JSFLibrary implementation); /** * <!-- begin-user-doc --> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryFactory.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryFactory.java index 0953c0e99..77560bd6e 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryFactory.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryFactory.java @@ -34,7 +34,7 @@ public interface JSFLibraryRegistryFactory extends EFactory{ * <!-- end-user-doc --> * @generated */ - JSFLibraryRegistryFactory eINSTANCE = new org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryFactoryImpl(); + JSFLibraryRegistryFactory eINSTANCE = org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryFactoryImpl.init(); /** * Returns a new object of class '<em>JSF Library Registry</em>'. diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryPackage.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryPackage.java index 3e00cb703..4789bad95 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryPackage.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFLibraryRegistryPackage.java @@ -109,7 +109,7 @@ public interface JSFLibraryRegistryPackage extends EPackage{ int JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES = 2; /** - * The number of structural features of the the '<em>JSF Library Registry</em>' class. + * The number of structural features of the '<em>JSF Library Registry</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -182,7 +182,7 @@ public interface JSFLibraryRegistryPackage extends EPackage{ int JSF_LIBRARY__ARCHIVE_FILES = 5; /** - * The number of structural features of the the '<em>JSF Library</em>' class. + * The number of structural features of the '<em>JSF Library</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -237,7 +237,7 @@ public interface JSFLibraryRegistryPackage extends EPackage{ int ARCHIVE_FILE__JSF_LIBRARY = 3; /** - * The number of structural features of the the '<em>Archive File</em>' class. + * The number of structural features of the '<em>Archive File</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -319,7 +319,7 @@ public interface JSFLibraryRegistryPackage extends EPackage{ int PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID = JSF_LIBRARY_FEATURE_COUNT + 0; /** - * The number of structural features of the the '<em>Plugin Provided JSF Library</em>' class. + * The number of structural features of the '<em>Plugin Provided JSF Library</em>' class. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated @@ -551,4 +551,181 @@ public interface JSFLibraryRegistryPackage extends EPackage{ */ JSFLibraryRegistryFactory getJSFLibraryRegistryFactory(); + /** + * <!-- begin-user-doc --> + * Defines literals for the meta objects that represent + * <ul> + * <li>each class,</li> + * <li>each feature of each class,</li> + * <li>each enum,</li> + * <li>and each data type</li> + * </ul> + * <!-- end-user-doc --> + * @generated + */ + interface Literals { + /** + * The meta object literal for the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryImpl <em>JSF Library Registry</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryImpl + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryPackageImpl#getJSFLibraryRegistry() + * @generated + */ + EClass JSF_LIBRARY_REGISTRY = eINSTANCE.getJSFLibraryRegistry(); + + /** + * The meta object literal for the '<em><b>Default Implementation ID</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID = eINSTANCE.getJSFLibraryRegistry_DefaultImplementationID(); + + /** + * The meta object literal for the '<em><b>JSF Libraries</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EReference JSF_LIBRARY_REGISTRY__JSF_LIBRARIES = eINSTANCE.getJSFLibraryRegistry_JSFLibraries(); + + /** + * The meta object literal for the '<em><b>Plugin Provided JSF Libraries</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EReference JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES = eINSTANCE.getJSFLibraryRegistry_PluginProvidedJSFLibraries(); + + /** + * The meta object literal for the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryImpl <em>JSF Library</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryImpl + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryPackageImpl#getJSFLibrary() + * @generated + */ + EClass JSF_LIBRARY = eINSTANCE.getJSFLibrary(); + + /** + * The meta object literal for the '<em><b>ID</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY__ID = eINSTANCE.getJSFLibrary_ID(); + + /** + * The meta object literal for the '<em><b>Name</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY__NAME = eINSTANCE.getJSFLibrary_Name(); + + /** + * The meta object literal for the '<em><b>JSF Version</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY__JSF_VERSION = eINSTANCE.getJSFLibrary_JSFVersion(); + + /** + * The meta object literal for the '<em><b>Deployed</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY__DEPLOYED = eINSTANCE.getJSFLibrary_Deployed(); + + /** + * The meta object literal for the '<em><b>Implementation</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute JSF_LIBRARY__IMPLEMENTATION = eINSTANCE.getJSFLibrary_Implementation(); + + /** + * The meta object literal for the '<em><b>Archive Files</b></em>' containment reference list feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EReference JSF_LIBRARY__ARCHIVE_FILES = eINSTANCE.getJSFLibrary_ArchiveFiles(); + + /** + * The meta object literal for the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.ArchiveFileImpl <em>Archive File</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.ArchiveFileImpl + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryPackageImpl#getArchiveFile() + * @generated + */ + EClass ARCHIVE_FILE = eINSTANCE.getArchiveFile(); + + /** + * The meta object literal for the '<em><b>Relative To Workspace</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute ARCHIVE_FILE__RELATIVE_TO_WORKSPACE = eINSTANCE.getArchiveFile_RelativeToWorkspace(); + + /** + * The meta object literal for the '<em><b>Source Location</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute ARCHIVE_FILE__SOURCE_LOCATION = eINSTANCE.getArchiveFile_SourceLocation(); + + /** + * The meta object literal for the '<em><b>Relative Dest Location</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute ARCHIVE_FILE__RELATIVE_DEST_LOCATION = eINSTANCE.getArchiveFile_RelativeDestLocation(); + + /** + * The meta object literal for the '<em><b>JSF Library</b></em>' container reference feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EReference ARCHIVE_FILE__JSF_LIBRARY = eINSTANCE.getArchiveFile_JSFLibrary(); + + /** + * The meta object literal for the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.PluginProvidedJSFLibraryImpl <em>Plugin Provided JSF Library</em>}' class. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.PluginProvidedJSFLibraryImpl + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryPackageImpl#getPluginProvidedJSFLibrary() + * @generated + */ + EClass PLUGIN_PROVIDED_JSF_LIBRARY = eINSTANCE.getPluginProvidedJSFLibrary(); + + /** + * The meta object literal for the '<em><b>Plugin ID</b></em>' attribute feature. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + EAttribute PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID = eINSTANCE.getPluginProvidedJSFLibrary_PluginID(); + + /** + * The meta object literal for the '{@link org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion <em>JSF Version</em>}' enum. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion + * @see org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl.JSFLibraryRegistryPackageImpl#getJSFVersion() + * @generated + */ + EEnum JSF_VERSION = eINSTANCE.getJSFVersion(); + + } + } //JSFLibraryRegistryPackage diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFVersion.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFVersion.java index 4fdf1bd6b..7beb1a9d5 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFVersion.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/JSFVersion.java @@ -86,7 +86,7 @@ public final class JSFVersion extends AbstractEnumerator { * @generated * @ordered */ - public static final JSFVersion V1_1_LITERAL = new JSFVersion(V1_1, "v1_1"); + public static final JSFVersion V1_1_LITERAL = new JSFVersion(V1_1, "v1_1", "v1_1"); /** * The '<em><b>V1 2</b></em>' literal object. @@ -96,7 +96,7 @@ public final class JSFVersion extends AbstractEnumerator { * @generated * @ordered */ - public static final JSFVersion V1_2_LITERAL = new JSFVersion(V1_2, "v1_2"); + public static final JSFVersion V1_2_LITERAL = new JSFVersion(V1_2, "v1_2", "v1_2"); /** * The '<em><b>UNKNOWN</b></em>' literal object. @@ -106,7 +106,7 @@ public final class JSFVersion extends AbstractEnumerator { * @generated * @ordered */ - public static final JSFVersion UNKNOWN_LITERAL = new JSFVersion(UNKNOWN, "UNKNOWN"); + public static final JSFVersion UNKNOWN_LITERAL = new JSFVersion(UNKNOWN, "UNKNOWN", "UNKNOWN"); /** * An array of all the '<em><b>JSF Version</b></em>' enumerators. @@ -130,17 +130,35 @@ public final class JSFVersion extends AbstractEnumerator { public static final List VALUES = Collections.unmodifiableList(Arrays.asList(VALUES_ARRAY)); /** + * Returns the '<em><b>JSF Version</b></em>' literal with the specified literal value. + * <!-- begin-user-doc --> + * @param literal value + * @return the JSF version for name value + * <!-- end-user-doc --> + * @generated + */ + public static JSFVersion get(String literal) { + for (int i = 0; i < VALUES_ARRAY.length; ++i) { + JSFVersion result = VALUES_ARRAY[i]; + if (result.toString().equals(literal)) { + return result; + } + } + return null; + } + + /** * Returns the '<em><b>JSF Version</b></em>' literal with the specified name. * <!-- begin-user-doc --> * @param name - * @return the JSF version for name value + * @return JSFVersion * <!-- end-user-doc --> * @generated */ - public static JSFVersion get(String name) { + public static JSFVersion getByName(String name) { for (int i = 0; i < VALUES_ARRAY.length; ++i) { JSFVersion result = VALUES_ARRAY[i]; - if (result.toString().equals(name)) { + if (result.getName().equals(name)) { return result; } } @@ -148,7 +166,7 @@ public final class JSFVersion extends AbstractEnumerator { } /** - * Returns the '<em><b>JSF Version</b></em>' literal with the specified value. + * Returns the '<em><b>JSF Version</b></em>' literal with the specified integer value. * <!-- begin-user-doc --> * @param value * @return the JSFVersion for the integer 'value' @@ -161,7 +179,7 @@ public final class JSFVersion extends AbstractEnumerator { case V1_2: return V1_2_LITERAL; case UNKNOWN: return UNKNOWN_LITERAL; } - return null; + return null; } /** @@ -170,8 +188,8 @@ public final class JSFVersion extends AbstractEnumerator { * <!-- end-user-doc --> * @generated */ - private JSFVersion(int value, String name) { - super(value, name); + private JSFVersion(int value, String name, String literal) { + super(value, name, literal); } /** diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/PluginProvidedJSFLibrary.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/PluginProvidedJSFLibrary.java index 5474d9d1b..36d15ac15 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/PluginProvidedJSFLibrary.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/PluginProvidedJSFLibrary.java @@ -29,6 +29,10 @@ package org.eclipse.jst.jsf.core.internal.jsflibraryregistry; */ public interface PluginProvidedJSFLibrary extends JSFLibrary{ /** + * Separator between plugin id and JSF Library name + */ + public static final String ID_SEPARATOR = "$$"; + /** * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/ArchiveFileImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/ArchiveFileImpl.java index dcb10a8af..0f769d436 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/ArchiveFileImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/ArchiveFileImpl.java @@ -144,7 +144,7 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { * @generated */ protected EClass eStaticClass() { - return JSFLibraryRegistryPackage.eINSTANCE.getArchiveFile(); + return JSFLibraryRegistryPackage.Literals.ARCHIVE_FILE; } /** @@ -252,7 +252,17 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { */ public JSFLibrary getJSFLibrary() { if (eContainerFeatureID != JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY) return null; - return (JSFLibrary)eContainer; + return (JSFLibrary)eContainer(); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public NotificationChain basicSetJSFLibrary(JSFLibrary newJSFLibrary, NotificationChain msgs) { + msgs = eBasicSetContainer((InternalEObject)newJSFLibrary, JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY, msgs); + return msgs; } /** @@ -262,15 +272,15 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { * @generated */ public void setJSFLibrary(JSFLibrary newJSFLibrary) { - if (newJSFLibrary != eContainer || (eContainerFeatureID != JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY && newJSFLibrary != null)) { + if (newJSFLibrary != eInternalContainer() || (eContainerFeatureID != JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY && newJSFLibrary != null)) { if (EcoreUtil.isAncestor(this, newJSFLibrary)) throw new IllegalArgumentException("Recursive containment not allowed for " + toString()); NotificationChain msgs = null; - if (eContainer != null) + if (eInternalContainer() != null) msgs = eBasicRemoveFromContainer(msgs); if (newJSFLibrary != null) msgs = ((InternalEObject)newJSFLibrary).eInverseAdd(this, JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES, JSFLibrary.class, msgs); - msgs = eBasicSetContainer((InternalEObject)newJSFLibrary, JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY, msgs); + msgs = basicSetJSFLibrary(newJSFLibrary, msgs); if (msgs != null) msgs.dispatch(); } else if (eNotificationRequired()) @@ -490,126 +500,53 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { } /** - * Gets the Bundle instance by parent PluginProvidedJSFLibrary instance's - * pluginID property, if and only if the parent JSFLibrary instance IS a - * PluginProvidedJSFLibrary, else returns null. - * @return Bundle instance, or null if not located or applicable - */ - protected Bundle getBundle() { - Bundle bundle = null; - if (getJSFLibrary() instanceof PluginProvidedJSFLibrary) { - String pluginID = ((PluginProvidedJSFLibrary)getJSFLibrary()).getPluginID(); - if (pluginID != null) { - bundle = Platform.getBundle(pluginID); - } - } - return bundle; - } - - /** - * Gets the IWorkspaceRoot instance. - * @return IWorkspaceRoot instance - */ - protected IWorkspaceRoot getWorkspaceRoot() { - IWorkspaceRoot workspaceRoot = null; - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - if (workspace != null) { - workspaceRoot = workspace.getRoot(); - } - return workspaceRoot; - } - - /** - * @param path - * @return the the path string with invalid path separators correctly fixed - */ - protected String appendSeparator(String path) { - String newPath = null; - if (!path.endsWith("\\") && !path.endsWith("/")) { //$NON-NLS-1$ //$NON-NLS-2$ - newPath = path + System.getProperty("file.separator"); //$NON-NLS-1$ - } else { - newPath = path; - } - return newPath; - } - - /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the inverse notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: - if (eContainer != null) - msgs = eBasicRemoveFromContainer(msgs); - return eBasicSetContainer(otherEnd, JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY, msgs); - default: - return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); - } + public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: + if (eInternalContainer() != null) + msgs = eBasicRemoveFromContainer(msgs); + return basicSetJSFLibrary((JSFLibrary)otherEnd, msgs); } - if (eContainer != null) - msgs = eBasicRemoveFromContainer(msgs); - return eBasicSetContainer(otherEnd, featureID, msgs); + return super.eInverseAdd(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: - return eBasicSetContainer(null, JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY, msgs); - default: - return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); - } + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: + return basicSetJSFLibrary(null, msgs); } - return eBasicSetContainer(null, featureID, msgs); + return super.eInverseRemove(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eBasicRemoveFromContainer(NotificationChain msgs) { - if (eContainerFeatureID >= 0) { - switch (eContainerFeatureID) { - case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: - return eContainer.eInverseRemove(this, JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES, JSFLibrary.class, msgs); - default: - return eDynamicBasicRemoveFromContainer(msgs); - } + public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) { + switch (eContainerFeatureID) { + case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: + return eInternalContainer().eInverseRemove(this, JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES, JSFLibrary.class, msgs); } - return eContainer.eInverseRemove(this, EOPPOSITE_FEATURE_BASE - eContainerFeatureID, null, msgs); + return super.eBasicRemoveFromContainerFeature(msgs); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param resolve - * @return the request feature value * <!-- end-user-doc --> * @generated */ - public Object eGet(EStructuralFeature eFeature, boolean resolve) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { case JSFLibraryRegistryPackage.ARCHIVE_FILE__RELATIVE_TO_WORKSPACE: return isRelativeToWorkspace() ? Boolean.TRUE : Boolean.FALSE; case JSFLibraryRegistryPackage.ARCHIVE_FILE__SOURCE_LOCATION: @@ -619,18 +556,16 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: return getJSFLibrary(); } - return eDynamicGet(eFeature, resolve); + return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param newValue * <!-- end-user-doc --> * @generated */ - public void eSet(EStructuralFeature eFeature, Object newValue) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public void eSet(int featureID, Object newValue) { + switch (featureID) { case JSFLibraryRegistryPackage.ARCHIVE_FILE__RELATIVE_TO_WORKSPACE: setRelativeToWorkspace(((Boolean)newValue).booleanValue()); return; @@ -644,17 +579,16 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { setJSFLibrary((JSFLibrary)newValue); return; } - eDynamicSet(eFeature, newValue); + super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> - * @param eFeature * <!-- end-user-doc --> * @generated */ - public void eUnset(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public void eUnset(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.ARCHIVE_FILE__RELATIVE_TO_WORKSPACE: setRelativeToWorkspace(RELATIVE_TO_WORKSPACE_EDEFAULT); return; @@ -668,18 +602,16 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { setJSFLibrary((JSFLibrary)null); return; } - eDynamicUnset(eFeature); + super.eUnset(featureID); } /** * <!-- begin-user-doc --> - * @param eFeature - * @return true if the feature is set * <!-- end-user-doc --> * @generated */ - public boolean eIsSet(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public boolean eIsSet(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.ARCHIVE_FILE__RELATIVE_TO_WORKSPACE: return relativeToWorkspace != RELATIVE_TO_WORKSPACE_EDEFAULT; case JSFLibraryRegistryPackage.ARCHIVE_FILE__SOURCE_LOCATION: @@ -689,7 +621,51 @@ public class ArchiveFileImpl extends EObjectImpl implements ArchiveFile { case JSFLibraryRegistryPackage.ARCHIVE_FILE__JSF_LIBRARY: return getJSFLibrary() != null; } - return eDynamicIsSet(eFeature); + return super.eIsSet(featureID); + } + + /** + * Gets the Bundle instance by parent PluginProvidedJSFLibrary instance's + * pluginID property, if and only if the parent JSFLibrary instance IS a + * PluginProvidedJSFLibrary, else returns null. + * @return Bundle instance, or null if not located or applicable + */ + protected Bundle getBundle() { + Bundle bundle = null; + if (getJSFLibrary() instanceof PluginProvidedJSFLibrary) { + String pluginID = ((PluginProvidedJSFLibrary)getJSFLibrary()).getPluginID(); + if (pluginID != null) { + bundle = Platform.getBundle(pluginID); + } + } + return bundle; + } + + /** + * Gets the IWorkspaceRoot instance. + * @return IWorkspaceRoot instance + */ + protected IWorkspaceRoot getWorkspaceRoot() { + IWorkspaceRoot workspaceRoot = null; + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + if (workspace != null) { + workspaceRoot = workspace.getRoot(); + } + return workspaceRoot; + } + + /** + * @param path + * @return the the path string with invalid path separators correctly fixed + */ + protected String appendSeparator(String path) { + String newPath = null; + if (!path.endsWith("\\") && !path.endsWith("/")) { //$NON-NLS-1$ //$NON-NLS-2$ + newPath = path + System.getProperty("file.separator"); //$NON-NLS-1$ + } else { + newPath = path; + } + return newPath; } /** diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryImpl.java index b5dd73066..7f60be63c 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryImpl.java @@ -10,9 +10,12 @@ *******************************************************************************/ package org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.common.util.EList; @@ -23,12 +26,21 @@ import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.emf.ecore.impl.EObjectImpl; import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList; import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.jdt.core.IAccessRule; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.ClasspathEntry; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryFactory; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryPackage; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.adapter.MaintainDefaultImplementationAdapter; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /** * <!-- begin-user-doc --> @@ -176,8 +188,8 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { */ protected JSFLibraryImpl() { super(); - //set initial ID; will be overwritten from XML if already persisted - setID(String.valueOf(System.currentTimeMillis())); +// //set initial ID; will be overwritten from XML if already persisted +// setID(String.valueOf(System.currentTimeMillis())); //add adapter to maintain a default implementation eAdapters().add(MaintainDefaultImplementationAdapter.getInstance()); } @@ -189,30 +201,16 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { * @generated */ protected EClass eStaticClass() { - return JSFLibraryRegistryPackage.eINSTANCE.getJSFLibrary(); + return JSFLibraryRegistryPackage.Literals.JSF_LIBRARY; } /** * <!-- begin-user-doc --> - * @return the id * <!-- end-user-doc --> - * @generated + * @generated NOT */ public String getID() { - return id; - } - - /** - * <!-- begin-user-doc --> - * @param newID - * <!-- end-user-doc --> - * @generated - */ - public void setID(String newID) { - String oldID = id; - id = newID; - if (eNotificationRequired()) - eNotify(new ENotificationImpl(this, Notification.SET, JSFLibraryRegistryPackage.JSF_LIBRARY__ID, oldID, id)); + return getName(); } /** @@ -351,7 +349,7 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { */ public JSFLibrary getWorkingCopy() { JSFLibrary workingCopyLib = JSFLibraryRegistryFactory.eINSTANCE.createJSFLibrary(); - workingCopyLib.setID(getID()); +// workingCopyLib.setID(getID()); workingCopyLib.setName(getName()); workingCopyLib.setJSFVersion(getJSFVersion()); workingCopyLib.setDeployed(isDeployed()); @@ -376,7 +374,7 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { */ public void updateValues(JSFLibrary otherLibrary) { if (otherLibrary != null) { - setID(otherLibrary.getID()); +// setID(otherLibrary.getID()); setName(otherLibrary.getName()); setJSFVersion(otherLibrary.getJSFVersion()); setDeployed(otherLibrary.isDeployed()); @@ -414,60 +412,37 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: - return ((InternalEList)getArchiveFiles()).basicAdd(otherEnd, msgs); - default: - return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); - } + public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: + return ((InternalEList)getArchiveFiles()).basicAdd(otherEnd, msgs); } - if (eContainer != null) - msgs = eBasicRemoveFromContainer(msgs); - return eBasicSetContainer(otherEnd, featureID, msgs); + return super.eInverseAdd(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: - return ((InternalEList)getArchiveFiles()).basicRemove(otherEnd, msgs); - default: - return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); - } + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: + return ((InternalEList)getArchiveFiles()).basicRemove(otherEnd, msgs); } - return eBasicSetContainer(null, featureID, msgs); + return super.eInverseRemove(otherEnd, featureID, msgs); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param resolve - * @return the value of the indicated feature * <!-- end-user-doc --> * @generated */ - public Object eGet(EStructuralFeature eFeature, boolean resolve) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { case JSFLibraryRegistryPackage.JSF_LIBRARY__ID: return getID(); case JSFLibraryRegistryPackage.JSF_LIBRARY__NAME: @@ -481,21 +456,16 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: return getArchiveFiles(); } - return eDynamicGet(eFeature, resolve); + return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param newValue * <!-- end-user-doc --> * @generated */ - public void eSet(EStructuralFeature eFeature, Object newValue) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY__ID: - setID((String)newValue); - return; + public void eSet(int featureID, Object newValue) { + switch (featureID) { case JSFLibraryRegistryPackage.JSF_LIBRARY__NAME: setName((String)newValue); return; @@ -513,20 +483,16 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { getArchiveFiles().addAll((Collection)newValue); return; } - eDynamicSet(eFeature, newValue); + super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> - * @param eFeature * <!-- end-user-doc --> * @generated */ - public void eUnset(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY__ID: - setID(ID_EDEFAULT); - return; + public void eUnset(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.JSF_LIBRARY__NAME: setName(NAME_EDEFAULT); return; @@ -543,18 +509,16 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { getArchiveFiles().clear(); return; } - eDynamicUnset(eFeature); + super.eUnset(featureID); } /** * <!-- begin-user-doc --> - * @param eFeature - * @return true if the feature's value is set * <!-- end-user-doc --> * @generated */ - public boolean eIsSet(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { + public boolean eIsSet(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.JSF_LIBRARY__ID: return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id); case JSFLibraryRegistryPackage.JSF_LIBRARY__NAME: @@ -568,7 +532,7 @@ public class JSFLibraryImpl extends EObjectImpl implements JSFLibrary { case JSFLibraryRegistryPackage.JSF_LIBRARY__ARCHIVE_FILES: return archiveFiles != null && !archiveFiles.isEmpty(); } - return eDynamicIsSet(eFeature); + return super.eIsSet(featureID); } /** diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryFactoryImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryFactoryImpl.java index ea914b530..40538ed67 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryFactoryImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryFactoryImpl.java @@ -13,7 +13,10 @@ package org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.impl.EFactoryImpl; +import org.eclipse.emf.ecore.plugin.EcorePlugin; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.*; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; @@ -37,6 +40,25 @@ public class JSFLibraryRegistryFactoryImpl extends EFactoryImpl implements JSFLi public static final String copyright = "Copyright (c) 2005 Oracle Corporation"; /** + * Creates the default factory implementation. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static JSFLibraryRegistryFactory init() { + try { + JSFLibraryRegistryFactory theJSFLibraryRegistryFactory = (JSFLibraryRegistryFactory)EPackage.Registry.INSTANCE.getEFactory("http://www.eclipse.org/webtools/jsf/schema/jsflibraryregistry.xsd"); + if (theJSFLibraryRegistryFactory != null) { + return theJSFLibraryRegistryFactory; + } + } + catch (Exception exception) { + EcorePlugin.INSTANCE.log(exception); + } + return new JSFLibraryRegistryFactoryImpl(); + } + + /** * Creates an instance of the factory. * <!-- begin-user-doc --> * <!-- end-user-doc --> @@ -74,11 +96,8 @@ public class JSFLibraryRegistryFactoryImpl extends EFactoryImpl implements JSFLi */ public Object createFromString(EDataType eDataType, String initialValue) { switch (eDataType.getClassifierID()) { - case JSFLibraryRegistryPackage.JSF_VERSION: { - JSFVersion result = JSFVersion.get(initialValue); - if (result == null) throw new IllegalArgumentException("The value '" + initialValue + "' is not a valid enumerator of '" + eDataType.getName() + "'"); - return result; - } + case JSFLibraryRegistryPackage.JSF_VERSION: + return createJSFVersionFromString(eDataType, initialValue); default: throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier"); } @@ -95,7 +114,7 @@ public class JSFLibraryRegistryFactoryImpl extends EFactoryImpl implements JSFLi public String convertToString(EDataType eDataType, Object instanceValue) { switch (eDataType.getClassifierID()) { case JSFLibraryRegistryPackage.JSF_VERSION: - return instanceValue == null ? null : instanceValue.toString(); + return convertJSFVersionToString(eDataType, instanceValue); default: throw new IllegalArgumentException("The datatype '" + eDataType.getName() + "' is not a valid classifier"); } @@ -147,6 +166,26 @@ public class JSFLibraryRegistryFactoryImpl extends EFactoryImpl implements JSFLi /** * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public JSFVersion createJSFVersionFromString(EDataType eDataType, String initialValue) { + JSFVersion result = JSFVersion.get(initialValue); + if (result == null) throw new IllegalArgumentException("The value '" + initialValue + "' is not a valid enumerator of '" + eDataType.getName() + "'"); + return result; + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public String convertJSFVersionToString(EDataType eDataType, Object instanceValue) { + return instanceValue == null ? null : instanceValue.toString(); + } + + /** + * <!-- begin-user-doc --> * @return the registry package * <!-- end-user-doc --> * @generated diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryImpl.java index a3951361f..c5aa393b8 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryImpl.java @@ -10,9 +10,15 @@ *******************************************************************************/ package org.eclipse.jst.jsf.core.internal.jsflibraryregistry.impl; +import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.Path; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.NotificationChain; import org.eclipse.emf.common.util.BasicEList; @@ -24,6 +30,14 @@ import org.eclipse.emf.ecore.impl.ENotificationImpl; import org.eclipse.emf.ecore.impl.EObjectImpl; import org.eclipse.emf.ecore.util.EObjectContainmentEList; import org.eclipse.emf.ecore.util.InternalEList; +import org.eclipse.jdt.core.IClasspathContainer; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.UserLibraryClasspathContainer; +import org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer; +import org.eclipse.jst.jsf.core.internal.JSFLibraryClasspathContainer; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryPackage; @@ -109,7 +123,7 @@ public class JSFLibraryRegistryImpl extends EObjectImpl implements JSFLibraryReg * @generated */ protected EClass eStaticClass() { - return JSFLibraryRegistryPackage.eINSTANCE.getJSFLibraryRegistry(); + return JSFLibraryRegistryPackage.Literals.JSF_LIBRARY_REGISTRY; } /** @@ -187,6 +201,97 @@ public class JSFLibraryRegistryImpl extends EObjectImpl implements JSFLibraryReg /** * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: + return ((InternalEList)getJSFLibraries()).basicRemove(otherEnd, msgs); + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: + return ((InternalEList)getPluginProvidedJSFLibraries()).basicRemove(otherEnd, msgs); + } + return super.eInverseRemove(otherEnd, featureID, msgs); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: + return getDefaultImplementationID(); + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: + return getJSFLibraries(); + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: + return getPluginProvidedJSFLibraries(); + } + return super.eGet(featureID, resolve, coreType); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: + setDefaultImplementationID((String)newValue); + return; + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: + getJSFLibraries().clear(); + getJSFLibraries().addAll((Collection)newValue); + return; + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: + getPluginProvidedJSFLibraries().clear(); + getPluginProvidedJSFLibraries().addAll((Collection)newValue); + return; + } + super.eSet(featureID, newValue); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public void eUnset(int featureID) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: + setDefaultImplementationID(DEFAULT_IMPLEMENTATION_ID_EDEFAULT); + return; + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: + getJSFLibraries().clear(); + return; + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: + getPluginProvidedJSFLibraries().clear(); + return; + } + super.eUnset(featureID); + } + + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public boolean eIsSet(int featureID) { + switch (featureID) { + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: + return DEFAULT_IMPLEMENTATION_ID_EDEFAULT == null ? defaultImplementationID != null : !DEFAULT_IMPLEMENTATION_ID_EDEFAULT.equals(defaultImplementationID); + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: + return jsfLibraries != null && !jsfLibraries.isEmpty(); + case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: + return pluginProvidedJSFLibraries != null && !pluginProvidedJSFLibraries.isEmpty(); + } + return super.eIsSet(featureID); + } + + /** + * <!-- begin-user-doc --> * @param ID * @return the jsf library of ID or null if none * <!-- end-user-doc --> @@ -326,114 +431,6 @@ public class JSFLibraryRegistryImpl extends EObjectImpl implements JSFLibraryReg /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain - * <!-- end-user-doc --> - * @generated - */ - public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: - return ((InternalEList)getJSFLibraries()).basicRemove(otherEnd, msgs); - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: - return ((InternalEList)getPluginProvidedJSFLibraries()).basicRemove(otherEnd, msgs); - default: - return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); - } - } - return eBasicSetContainer(null, featureID, msgs); - } - - /** - * <!-- begin-user-doc --> - * @param eFeature - * @param resolve - * @return the value of the feature - * <!-- end-user-doc --> - * @generated - */ - public Object eGet(EStructuralFeature eFeature, boolean resolve) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: - return getDefaultImplementationID(); - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: - return getJSFLibraries(); - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: - return getPluginProvidedJSFLibraries(); - } - return eDynamicGet(eFeature, resolve); - } - - /** - * <!-- begin-user-doc --> - * @param eFeature - * @param newValue - * <!-- end-user-doc --> - * @generated - */ - public void eSet(EStructuralFeature eFeature, Object newValue) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: - setDefaultImplementationID((String)newValue); - return; - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: - getJSFLibraries().clear(); - getJSFLibraries().addAll((Collection)newValue); - return; - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: - getPluginProvidedJSFLibraries().clear(); - getPluginProvidedJSFLibraries().addAll((Collection)newValue); - return; - } - eDynamicSet(eFeature, newValue); - } - - /** - * <!-- begin-user-doc --> - * @param eFeature - * <!-- end-user-doc --> - * @generated - */ - public void eUnset(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: - setDefaultImplementationID(DEFAULT_IMPLEMENTATION_ID_EDEFAULT); - return; - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: - getJSFLibraries().clear(); - return; - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: - getPluginProvidedJSFLibraries().clear(); - return; - } - eDynamicUnset(eFeature); - } - - /** - * <!-- begin-user-doc --> - * @param eFeature - * @return true if the feature value is set - * <!-- end-user-doc --> - * @generated - */ - public boolean eIsSet(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__DEFAULT_IMPLEMENTATION_ID: - return DEFAULT_IMPLEMENTATION_ID_EDEFAULT == null ? defaultImplementationID != null : !DEFAULT_IMPLEMENTATION_ID_EDEFAULT.equals(defaultImplementationID); - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__JSF_LIBRARIES: - return jsfLibraries != null && !jsfLibraries.isEmpty(); - case JSFLibraryRegistryPackage.JSF_LIBRARY_REGISTRY__PLUGIN_PROVIDED_JSF_LIBRARIES: - return pluginProvidedJSFLibraries != null && !pluginProvidedJSFLibraries.isEmpty(); - } - return eDynamicIsSet(eFeature); - } - - /** - * <!-- begin-user-doc --> * @return the string representation * <!-- end-user-doc --> * @generated @@ -447,5 +444,56 @@ public class JSFLibraryRegistryImpl extends EObjectImpl implements JSFLibraryReg result.append(')'); return result.toString(); } - + + /** + * Copied from JDT UserLibraryManager + * @generated NOT + * @param name + * @param remove + * @param monitor + * @throws JavaModelException + */ + private void rebindClasspathEntries(String name, boolean remove, IProgressMonitor monitor) throws JavaModelException { + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); + IJavaProject[] projects= JavaCore.create(root).getJavaProjects(); + IPath containerPath= new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID).append(name); + + ArrayList affectedProjects= new ArrayList(); + + for (int i= 0; i < projects.length; i++) { + IJavaProject project= projects[i]; + IClasspathEntry[] entries= project.getRawClasspath(); + for (int k= 0; k < entries.length; k++) { + IClasspathEntry curr= entries[k]; + if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { + if (containerPath.equals(curr.getPath())) { + affectedProjects.add(project); + break; + } + } + } + } + if (!affectedProjects.isEmpty()) { + IJavaProject[] affected= (IJavaProject[]) affectedProjects.toArray(new IJavaProject[affectedProjects.size()]); + IClasspathContainer[] containers= new IClasspathContainer[affected.length]; + if (!remove) { + // Previously, containers array only contained a null value. Then, user library classpath entry was first removed + // and then added a while after when post change delta event on .classpath file was fired... + // Unfortunately, in some cases, this event was fired a little bit too late and missed the refresh of Package Explorer + // (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=61872) + // So now, instanciate a new user library classpath container instead which allow to refresh its content immediately + // as there's no classpath entry removal... + // Note that it works because equals(Object) method is not overridden for UserLibraryClasspathContainer. + // If it was, the update wouldn't happen while setting classpath container + // @see javaCore.setClasspathContainer(IPath, IJavaProject[], IClasspathContainer[], IProgressMonitor) + JSFLibraryClasspathContainer container= new JSFLibraryClasspathContainer(null); + containers[0] = container; + } + JavaCore.setClasspathContainer(containerPath, affected, containers, monitor); + } else { + if (monitor != null) { + monitor.done(); + } + } + } } //JSFLibraryRegistryImpl diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryPackageImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryPackageImpl.java index 14de3cccd..846fa47f2 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryPackageImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/JSFLibraryRegistryPackageImpl.java @@ -421,47 +421,47 @@ public class JSFLibraryRegistryPackageImpl extends EPackageImpl implements JSFLi initEReference(getJSFLibraryRegistry_JSFLibraries(), this.getJSFLibrary(), null, "JSFLibraries", null, 0, -1, JSFLibraryRegistry.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getJSFLibraryRegistry_PluginProvidedJSFLibraries(), this.getPluginProvidedJSFLibrary(), null, "PluginProvidedJSFLibraries", null, 0, -1, JSFLibraryRegistry.class, IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getImplJSFLibraries"); + EOperation op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getImplJSFLibraries", 1, 1); - addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getNonImplJSFLibraries"); + op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getNonImplJSFLibraries", 1, 1); - EOperation op = addEOperation(jsfLibraryRegistryEClass, this.getJSFLibrary(), "getJSFLibraryByID"); - addEParameter(op, ecorePackage.getEString(), "ID"); + op = addEOperation(jsfLibraryRegistryEClass, this.getJSFLibrary(), "getJSFLibraryByID", 1, 1); + addEParameter(op, ecorePackage.getEString(), "ID", 1, 1); - op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getJSFLibrariesByName"); - addEParameter(op, ecorePackage.getEString(), "name"); + op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getJSFLibrariesByName", 1, 1); + addEParameter(op, ecorePackage.getEString(), "name", 1, 1); - addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getAllJSFLibraries"); + op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEEList(), "getAllJSFLibraries", 1, 1); - op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEBoolean(), "addJSFLibrary"); - addEParameter(op, this.getJSFLibrary(), "library"); + op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEBoolean(), "addJSFLibrary", 1, 1); + addEParameter(op, this.getJSFLibrary(), "library", 1, 1); - op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEBoolean(), "removeJSFLibrary"); - addEParameter(op, this.getJSFLibrary(), "library"); + op = addEOperation(jsfLibraryRegistryEClass, ecorePackage.getEBoolean(), "removeJSFLibrary", 1, 1); + addEParameter(op, this.getJSFLibrary(), "library", 1, 1); - addEOperation(jsfLibraryRegistryEClass, this.getJSFLibrary(), "getDefaultImplementation"); + op = addEOperation(jsfLibraryRegistryEClass, this.getJSFLibrary(), "getDefaultImplementation", 1, 1); op = addEOperation(jsfLibraryRegistryEClass, null, "setDefaultImplementation"); - addEParameter(op, this.getJSFLibrary(), "implementation"); + addEParameter(op, this.getJSFLibrary(), "implementation", 1, 1); initEClass(jsfLibraryEClass, JSFLibrary.class, "JSFLibrary", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); - initEAttribute(getJSFLibrary_ID(), ecorePackage.getEString(), "ID", "", 1, 1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); + initEAttribute(getJSFLibrary_ID(), ecorePackage.getEString(), "ID", "", 0, 1, JSFLibrary.class, IS_TRANSIENT, !IS_VOLATILE, !IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, IS_DERIVED, IS_ORDERED); initEAttribute(getJSFLibrary_Name(), ecorePackage.getEString(), "Name", null, 1, 1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getJSFLibrary_JSFVersion(), this.getJSFVersion(), "JSFVersion", "UNKNOWN", 1, 1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getJSFLibrary_Deployed(), ecorePackage.getEBoolean(), "Deployed", "true", 1, 1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEAttribute(getJSFLibrary_Implementation(), ecorePackage.getEBoolean(), "Implementation", "false", 1, 1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getJSFLibrary_ArchiveFiles(), this.getArchiveFile(), this.getArchiveFile_JSFLibrary(), "ArchiveFiles", null, 0, -1, JSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - op = addEOperation(jsfLibraryEClass, ecorePackage.getEBoolean(), "containsArchiveFile"); - addEParameter(op, ecorePackage.getEString(), "fullPath"); + op = addEOperation(jsfLibraryEClass, ecorePackage.getEBoolean(), "containsArchiveFile", 1, 1); + addEParameter(op, ecorePackage.getEString(), "fullPath", 1, 1); - addEOperation(jsfLibraryEClass, this.getJSFLibrary(), "getWorkingCopy"); + op = addEOperation(jsfLibraryEClass, this.getJSFLibrary(), "getWorkingCopy", 1, 1); op = addEOperation(jsfLibraryEClass, null, "updateValues"); - addEParameter(op, this.getJSFLibrary(), "otherLibrary"); + addEParameter(op, this.getJSFLibrary(), "otherLibrary", 1, 1); - op = addEOperation(jsfLibraryEClass, ecorePackage.getEBoolean(), "copyTo"); - addEParameter(op, ecorePackage.getEString(), "baseDestLocation"); + op = addEOperation(jsfLibraryEClass, ecorePackage.getEBoolean(), "copyTo", 1, 1); + addEParameter(op, ecorePackage.getEString(), "baseDestLocation", 1, 1); initEClass(archiveFileEClass, ArchiveFile.class, "ArchiveFile", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEAttribute(getArchiveFile_RelativeToWorkspace(), ecorePackage.getEBoolean(), "RelativeToWorkspace", "true", 1, 1, ArchiveFile.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); @@ -469,21 +469,21 @@ public class JSFLibraryRegistryPackageImpl extends EPackageImpl implements JSFLi initEAttribute(getArchiveFile_RelativeDestLocation(), ecorePackage.getEString(), "RelativeDestLocation", null, 1, 1, ArchiveFile.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); initEReference(getArchiveFile_JSFLibrary(), this.getJSFLibrary(), this.getJSFLibrary_ArchiveFiles(), "JSFLibrary", null, 1, 1, ArchiveFile.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_COMPOSITE, !IS_RESOLVE_PROXIES, !IS_UNSETTABLE, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); - addEOperation(archiveFileEClass, ecorePackage.getEString(), "getName"); + op = addEOperation(archiveFileEClass, ecorePackage.getEString(), "getName", 1, 1); - addEOperation(archiveFileEClass, ecorePackage.getEString(), "getPath"); + op = addEOperation(archiveFileEClass, ecorePackage.getEString(), "getPath", 1, 1); - addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "exists"); + op = addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "exists", 1, 1); - op = addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "equals"); - addEParameter(op, ecorePackage.getEJavaObject(), "object"); + op = addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "equals", 1, 1); + addEParameter(op, ecorePackage.getEJavaObject(), "object", 1, 1); - addEOperation(archiveFileEClass, ecorePackage.getEInt(), "hashCode"); + op = addEOperation(archiveFileEClass, ecorePackage.getEInt(), "hashCode", 1, 1); - op = addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "copyTo"); - addEParameter(op, ecorePackage.getEString(), "baseDestLocation"); + op = addEOperation(archiveFileEClass, ecorePackage.getEBoolean(), "copyTo", 1, 1); + addEParameter(op, ecorePackage.getEString(), "baseDestLocation", 1, 1); - addEOperation(archiveFileEClass, ecorePackage.getEString(), "getResolvedSourceLocation"); + op = addEOperation(archiveFileEClass, ecorePackage.getEString(), "getResolvedSourceLocation", 1, 1); initEClass(pluginProvidedJSFLibraryEClass, PluginProvidedJSFLibrary.class, "PluginProvidedJSFLibrary", !IS_ABSTRACT, !IS_INTERFACE, IS_GENERATED_INSTANCE_CLASS); initEAttribute(getPluginProvidedJSFLibrary_PluginID(), ecorePackage.getEString(), "pluginID", null, 1, 1, PluginProvidedJSFLibrary.class, !IS_TRANSIENT, !IS_VOLATILE, IS_CHANGEABLE, !IS_UNSETTABLE, !IS_ID, IS_UNIQUE, !IS_DERIVED, IS_ORDERED); diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/PluginProvidedJSFLibraryImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/PluginProvidedJSFLibraryImpl.java index 7a6db77a9..e5bf90def 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/PluginProvidedJSFLibraryImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/impl/PluginProvidedJSFLibraryImpl.java @@ -88,7 +88,7 @@ public class PluginProvidedJSFLibraryImpl extends JSFLibraryImpl implements Plug * @generated */ protected EClass eStaticClass() { - return JSFLibraryRegistryPackage.eINSTANCE.getPluginProvidedJSFLibrary(); + return JSFLibraryRegistryPackage.Literals.PLUGIN_PROVIDED_JSF_LIBRARY; } /** @@ -116,197 +116,91 @@ public class PluginProvidedJSFLibraryImpl extends JSFLibraryImpl implements Plug /** * <!-- begin-user-doc --> - * @return the working copy - * <!-- end-user-doc --> - * @generated NOT - */ - public JSFLibrary getWorkingCopy() { - PluginProvidedJSFLibrary workingCopyLib = JSFLibraryRegistryFactory.eINSTANCE.createPluginProvidedJSFLibrary(); - workingCopyLib.setID(getID()); - workingCopyLib.setName(getName()); - workingCopyLib.setJSFVersion(getJSFVersion()); - workingCopyLib.setDeployed(isDeployed()); - workingCopyLib.setImplementation(isImplementation()); - workingCopyLib.setPluginID(getPluginID()); - Iterator itArchiveFiles = getArchiveFiles().iterator(); - while (itArchiveFiles.hasNext()) { - ArchiveFile srcArchiveFile = (ArchiveFile)itArchiveFiles.next(); - ArchiveFile destArchiveFile = JSFLibraryRegistryFactory.eINSTANCE.createArchiveFile(); - destArchiveFile.setRelativeToWorkspace(srcArchiveFile.isRelativeToWorkspace()); - destArchiveFile.setSourceLocation(srcArchiveFile.getSourceLocation()); - destArchiveFile.setRelativeDestLocation(srcArchiveFile.getRelativeDestLocation()); - workingCopyLib.getArchiveFiles().add(destArchiveFile); - } - return workingCopyLib; - } - - /** - * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - return ((InternalEList)getArchiveFiles()).basicAdd(otherEnd, msgs); - default: - return eDynamicInverseAdd(otherEnd, featureID, baseClass, msgs); - } + public Object eGet(int featureID, boolean resolve, boolean coreType) { + switch (featureID) { + case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: + return getPluginID(); } - if (eContainer != null) - msgs = eBasicRemoveFromContainer(msgs); - return eBasicSetContainer(otherEnd, featureID, msgs); + return super.eGet(featureID, resolve, coreType); } /** * <!-- begin-user-doc --> - * @param otherEnd - * @param featureID - * @param baseClass - * @param msgs - * @return the notification chain * <!-- end-user-doc --> * @generated */ - public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, Class baseClass, NotificationChain msgs) { - if (featureID >= 0) { - switch (eDerivedStructuralFeatureID(featureID, baseClass)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - return ((InternalEList)getArchiveFiles()).basicRemove(otherEnd, msgs); - default: - return eDynamicInverseRemove(otherEnd, featureID, baseClass, msgs); - } + public void eSet(int featureID, Object newValue) { + switch (featureID) { + case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: + setPluginID((String)newValue); + return; } - return eBasicSetContainer(null, featureID, msgs); + super.eSet(featureID, newValue); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param resolve - * @return the value of the feature * <!-- end-user-doc --> * @generated */ - public Object eGet(EStructuralFeature eFeature, boolean resolve) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ID: - return getID(); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__NAME: - return getName(); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__JSF_VERSION: - return getJSFVersion(); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__DEPLOYED: - return isDeployed() ? Boolean.TRUE : Boolean.FALSE; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__IMPLEMENTATION: - return isImplementation() ? Boolean.TRUE : Boolean.FALSE; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - return getArchiveFiles(); + public void eUnset(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: - return getPluginID(); + setPluginID(PLUGIN_ID_EDEFAULT); + return; } - return eDynamicGet(eFeature, resolve); + super.eUnset(featureID); } /** * <!-- begin-user-doc --> - * @param eFeature - * @param newValue * <!-- end-user-doc --> * @generated */ - public void eSet(EStructuralFeature eFeature, Object newValue) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ID: - setID((String)newValue); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__NAME: - setName((String)newValue); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__JSF_VERSION: - setJSFVersion((JSFVersion)newValue); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__DEPLOYED: - setDeployed(((Boolean)newValue).booleanValue()); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__IMPLEMENTATION: - setImplementation(((Boolean)newValue).booleanValue()); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - getArchiveFiles().clear(); - getArchiveFiles().addAll((Collection)newValue); - return; + public boolean eIsSet(int featureID) { + switch (featureID) { case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: - setPluginID((String)newValue); - return; + return PLUGIN_ID_EDEFAULT == null ? pluginID != null : !PLUGIN_ID_EDEFAULT.equals(pluginID); } - eDynamicSet(eFeature, newValue); + return super.eIsSet(featureID); } - + /** * <!-- begin-user-doc --> - * @param eFeature * <!-- end-user-doc --> - * @generated + * @generated NOT */ - public void eUnset(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ID: - setID(ID_EDEFAULT); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__NAME: - setName(NAME_EDEFAULT); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__JSF_VERSION: - setJSFVersion(JSF_VERSION_EDEFAULT); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__DEPLOYED: - setDeployed(DEPLOYED_EDEFAULT); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__IMPLEMENTATION: - setImplementation(IMPLEMENTATION_EDEFAULT); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - getArchiveFiles().clear(); - return; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: - setPluginID(PLUGIN_ID_EDEFAULT); - return; - } - eDynamicUnset(eFeature); + public String getID() { + return getPluginID() + ID_SEPARATOR + getName(); } /** * <!-- begin-user-doc --> - * @param eFeature - * @return true if the value of eFeature is set + * @return the working copy * <!-- end-user-doc --> - * @generated + * @generated NOT */ - public boolean eIsSet(EStructuralFeature eFeature) { - switch (eDerivedStructuralFeatureID(eFeature)) { - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ID: - return ID_EDEFAULT == null ? id != null : !ID_EDEFAULT.equals(id); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__NAME: - return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__JSF_VERSION: - return jsfVersion != JSF_VERSION_EDEFAULT; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__DEPLOYED: - return deployed != DEPLOYED_EDEFAULT; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__IMPLEMENTATION: - return implementation != IMPLEMENTATION_EDEFAULT; - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__ARCHIVE_FILES: - return archiveFiles != null && !archiveFiles.isEmpty(); - case JSFLibraryRegistryPackage.PLUGIN_PROVIDED_JSF_LIBRARY__PLUGIN_ID: - return PLUGIN_ID_EDEFAULT == null ? pluginID != null : !PLUGIN_ID_EDEFAULT.equals(pluginID); + public JSFLibrary getWorkingCopy() { + PluginProvidedJSFLibrary workingCopyLib = JSFLibraryRegistryFactory.eINSTANCE.createPluginProvidedJSFLibrary(); +// workingCopyLib.setID(getID()); + workingCopyLib.setName(getName()); + workingCopyLib.setJSFVersion(getJSFVersion()); + workingCopyLib.setDeployed(isDeployed()); + workingCopyLib.setImplementation(isImplementation()); + workingCopyLib.setPluginID(getPluginID()); + Iterator itArchiveFiles = getArchiveFiles().iterator(); + while (itArchiveFiles.hasNext()) { + ArchiveFile srcArchiveFile = (ArchiveFile)itArchiveFiles.next(); + ArchiveFile destArchiveFile = JSFLibraryRegistryFactory.eINSTANCE.createArchiveFile(); + destArchiveFile.setRelativeToWorkspace(srcArchiveFile.isRelativeToWorkspace()); + destArchiveFile.setSourceLocation(srcArchiveFile.getSourceLocation()); + destArchiveFile.setRelativeDestLocation(srcArchiveFile.getRelativeDestLocation()); + workingCopyLib.getArchiveFiles().add(destArchiveFile); } - return eDynamicIsSet(eFeature); + return workingCopyLib; } /** diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryResourceFactoryImpl.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryResourceFactoryImpl.java index 10d995511..31305c798 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryResourceFactoryImpl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryResourceFactoryImpl.java @@ -15,6 +15,7 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl; +import org.eclipse.emf.ecore.xmi.XMLResource; /** * <!-- begin-user-doc --> diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistrySwitch.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistrySwitch.java index f1ad73ce3..91e7277c5 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistrySwitch.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistrySwitch.java @@ -64,6 +64,7 @@ public class JSFLibraryRegistrySwitch { * @param theEObject * @return the first non-null result returned by a <code>caseXXX</code> call. * <!-- end-user-doc --> + * @return the first non-null result returned by a <code>caseXXX</code> call. * @generated */ public Object doSwitch(EObject theEObject) { @@ -77,17 +78,20 @@ public class JSFLibraryRegistrySwitch { * @param theEObject * @return the first non-null result returned by a <code>caseXXX</code> call. * <!-- end-user-doc --> + * @return the first non-null result returned by a <code>caseXXX</code> call. * @generated */ protected Object doSwitch(EClass theEClass, EObject theEObject) { if (theEClass.eContainer() == modelPackage) { return doSwitch(theEClass.getClassifierID(), theEObject); } - List eSuperTypes = theEClass.getESuperTypes(); - return - eSuperTypes.isEmpty() ? - defaultCase(theEObject) : - doSwitch((EClass)eSuperTypes.get(0), theEObject); + else { + List eSuperTypes = theEClass.getESuperTypes(); + return + eSuperTypes.isEmpty() ? + defaultCase(theEObject) : + doSwitch((EClass)eSuperTypes.get(0), theEObject); + } } /** @@ -97,6 +101,7 @@ public class JSFLibraryRegistrySwitch { * @param theEObject * @return the first non-null result returned by a <code>caseXXX</code> call. * <!-- end-user-doc --> + * @return the first non-null result returned by a <code>caseXXX</code> call. * @generated */ protected Object doSwitch(int classifierID, EObject theEObject) { diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryXMLProcessor.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryXMLProcessor.java new file mode 100644 index 000000000..e151c36c1 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/jsflibraryregistry/util/JSFLibraryRegistryXMLProcessor.java @@ -0,0 +1,58 @@ +/** + * <copyright> + * </copyright> + * + * $Id: JSFLibraryRegistryXMLProcessor.java,v 1.1 2007/04/02 17:07:34 gkessler Exp $ + */ +package org.eclipse.jst.jsf.core.internal.jsflibraryregistry.util; + +import java.util.Map; + +import org.eclipse.emf.ecore.EPackage; + +import org.eclipse.emf.ecore.xmi.util.XMLProcessor; + +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryPackage; + +/** + * This class contains helper methods to serialize and deserialize XML documents + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ +public class JSFLibraryRegistryXMLProcessor extends XMLProcessor { + /** + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public static final String copyright = "Copyright (c) 2005 Oracle Corporation"; + + + /** + * Public constructor to instantiate the helper. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + public JSFLibraryRegistryXMLProcessor() { + super((EPackage.Registry.INSTANCE)); + JSFLibraryRegistryPackage.eINSTANCE.eClass(); + } + + /** + * Register for "*" and "xml" file extensions the JSFLibraryRegistryResourceFactoryImpl factory. + * <!-- begin-user-doc --> + * <!-- end-user-doc --> + * @generated + */ + protected Map getRegistrations() { + if (registrations == null) { + super.getRegistrations(); + registrations.put(XML_EXTENSION, new JSFLibraryRegistryResourceFactoryImpl()); + registrations.put(STAR_EXTENSION, new JSFLibraryRegistryResourceFactoryImpl()); + } + return registrations; + } + +} //JSFLibraryRegistryXMLProcessor diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java index 337aa6e83..9d891d2b2 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/IJSFFacetInstallDataModelProperties.java @@ -42,6 +42,11 @@ public interface IJSFFacetInstallDataModelProperties extends /** * TODO: */ + public static final String SERVLET_CLASSNAME = "IJSFFacetInstallDataModelProperties.SERVLET_CLASSNAME"; //$NON-NLS-1$ + + /** + * TODO: + */ public static final String SERVLET_URL_PATTERNS = "IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS"; //$NON-NLS-1$ /** diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDataModelProvider.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDataModelProvider.java index 4cdae49fd..efc040ed7 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDataModelProvider.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDataModelProvider.java @@ -11,6 +11,8 @@ package org.eclipse.jst.jsf.core.internal.project.facet; import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; @@ -19,17 +21,24 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.jst.jsf.core.internal.Messages; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFProjectLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; import org.eclipse.osgi.util.NLS; import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider; import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetDataModelProperties; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; import org.eclipse.wst.common.frameworks.internal.operations.IProjectCreationPropertiesNew; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; /** * Provides a data model used by the JSF facet install. @@ -49,6 +58,7 @@ public class JSFFacetInstallDataModelProvider extends names.add(DEPLOY_IMPLEMENTATION); names.add(CONFIG_PATH); names.add(SERVLET_NAME); + names.add(SERVLET_CLASSNAME); names.add(SERVLET_URL_PATTERNS); names.add(WEBCONTENT_DIR); @@ -69,7 +79,9 @@ public class JSFFacetInstallDataModelProvider extends } else if (propertyName.equals(CONFIG_PATH)) { return JSFUtils.JSF_DEFAULT_CONFIG_PATH; //$NON-NLS-1$; } else if (propertyName.equals(SERVLET_NAME)) { - return "Faces Servlet"; //$NON-NLS-1$ + return JSFUtils.JSF_DEFAULT_SERVLET_NAME; //$NON-NLS-1$ + } else if (propertyName.equals(SERVLET_CLASSNAME)) { + return JSFUtils.JSF_SERVLET_CLASS; } else if (propertyName.equals(SERVLET_URL_PATTERNS)) { return new String[] { "*.faces" }; //$NON-NLS-1$ } else if (propertyName.equals(FACET_ID)) { @@ -77,7 +89,7 @@ public class JSFFacetInstallDataModelProvider extends } else if (propertyName.equals(WEBCONTENT_DIR)){ return "WebContent"; //not sure I need this } else if (propertyName.equals(COMPONENT_LIBRARIES)) { - return new ArrayList(0); + return new Object[0]; } else if (propertyName.equals(IMPLEMENTATION_LIBRARIES)) { return getDefaultJSFImplementationLibraries(); } else if (propertyName.equals(DEFAULT_IMPLEMENTATION_LIBRARY)) { @@ -87,20 +99,42 @@ public class JSFFacetInstallDataModelProvider extends } public IStatus validate(String name) { errorMessage = null; - if (name.equals(IMPLEMENTATION) && getBooleanProperty(DEPLOY_IMPLEMENTATION)) { - return validateImpl((JSFLibrary)getProperty(IMPLEMENTATION)); + if (name.equals(IMPLEMENTATION_LIBRARIES) && getBooleanProperty(DEPLOY_IMPLEMENTATION)) { + List libs = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibrariesByName(getStringPropertyWithDefaultStripped(IMPLEMENTATION_LIBRARIES)); + JSFLibrary lib = ! libs.isEmpty() ? (JSFLibrary)libs.get(0) : null; + IStatus status = validateImpl(lib); + if (!OK_STATUS.equals(status)) + return status; + else + return validateClasspath(); } else if (name.equals(CONFIG_PATH)) { return validateConfigLocation(getStringProperty(CONFIG_PATH)); } else if (name.equals(SERVLET_NAME)) { return validateServletName(getStringProperty(SERVLET_NAME)); } + else if (name.equals(COMPONENT_LIBRARIES)) { + return validateClasspath(); + } return super.validate(name); } + private IStatus createErrorStatus(String msg) { + return new Status(IStatus.ERROR, JSFCorePlugin.PLUGIN_ID, msg); + } + + private String getStringPropertyWithDefaultStripped(String propertyName) { + String val = getStringProperty(propertyName); + if (val.endsWith(JSFLibraryRegistry.DEFAULT_IMPL_LABEL)){ + val = val.substring(0, val.indexOf(JSFLibraryRegistry.DEFAULT_IMPL_LABEL)).trim(); + setProperty(propertyName, val); + } + return val; + } + private IStatus validateServletName(String servletName) { if (servletName == null || servletName.trim().length() == 0) { errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateServletName; - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } return OK_STATUS; @@ -111,7 +145,7 @@ public class JSFFacetInstallDataModelProvider extends errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateJSFImpl; } if (errorMessage != null) { - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } return OK_STATUS; } @@ -119,7 +153,7 @@ public class JSFFacetInstallDataModelProvider extends private IStatus validateConfigLocation(String text) { if (text == null || text.trim().equals("")) { //$NON-NLS-1$ errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateConfigFileEmpty; - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } text = text.trim(); @@ -130,18 +164,18 @@ public class JSFFacetInstallDataModelProvider extends IPath passedPath = new Path(text); if (!fullPath.isValidPath(text)){ errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateConfigFilePath; - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } //FIXME: check for valid file path also [passedPath.toFile().isFile()] if (text.toLowerCase().lastIndexOf(".xml") != text.length() - 4) { //$NON-NLS-1$ errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateConfigFileXML; - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } if (text.lastIndexOf("\\") >= 0){ //$NON-NLS-1$ errorMessage = Messages.JSFFacetInstallDataModelProvider_ValidateConfigFileSlashes; - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } // if (1 == 1){ // //FIXME!!!! @@ -153,7 +187,7 @@ public class JSFFacetInstallDataModelProvider extends errorMessage = NLS.bind( Messages.JSFFacetInstallDataModelProvider_ValidateConfigFileRelative1, getWebContentFolder().removeFirstSegments(getWebContentFolder().segmentCount() - 1).toString()); - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } IPath setPath = getWebContentFolder().append(passedPath); @@ -161,12 +195,87 @@ public class JSFFacetInstallDataModelProvider extends errorMessage = NLS.bind( Messages.JSFFacetInstallDataModelProvider_ValidateConfigFileRelative2, getWebContentFolder().removeFirstSegments(getWebContentFolder().segmentCount() - 1).toString()); - return WTPCommonPlugin.createErrorStatus(errorMessage); + return createErrorStatus(errorMessage); } return OK_STATUS; } + private IStatus validateClasspath(){ + Set jars = new HashSet(); + if (doesProjectExist()){ + //validate actual classpath by loading jars from cp + try { + IClasspathEntry[] entries = getJavaProject().getResolvedClasspath(true); + for (int i=0;i<entries.length;i++){ + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY){ + jars.add(entry.getPath().makeAbsolute().toString()); + } +// else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER){ +// IClasspathContainer cont = (IClasspathContainer)entry; +// for (int j=0;j<cont.getClasspathEntries().length;j++){ +// jars.add(cont.getClasspathEntries()[j].getPath().makeAbsolute().toString()); +// } +// } + } + } catch (JavaModelException e) { + } + } + else {//as we do not have a javaProject yet, all we can do is validate that there is no duplicate jars (absolute path) + + } + + IStatus status = checkForDupeArchiveFiles(jars, ((JSFLibraryReference)getProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION)).getLibrary()); + if (!OK_STATUS.equals(status)){ + return status; + } + + JSFLibraryReference[] compLibs = (JSFLibraryReference[])getProperty(IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES); + for (int i=0;i<compLibs.length;i++){ + JSFLibrary lib = compLibs[i].getLibrary(); + status = checkForDupeArchiveFiles(jars, lib); + if (!OK_STATUS.equals(status)){ + return status; + } + } + return OK_STATUS; + } + + private IJavaProject getJavaProject() { + IProject proj = getProject(); + if (proj != null) + return JavaCore.create(proj); + return null; + } + + private IProject getProject(){ + String projName = (String)getProperty(FACET_PROJECT_NAME); + IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName); + return project; + } + private boolean doesProjectExist() { + IProject project = getProject(); + return (project != null) && project.exists(); + } + + private IStatus checkForDupeArchiveFiles(Set jars, + JSFLibrary selectedJSFLibImplementation) { + if (selectedJSFLibImplementation == null) + return OK_STATUS; + + for (Iterator it=selectedJSFLibImplementation.getArchiveFiles().iterator();it.hasNext();){ + ArchiveFile jar = (ArchiveFile)it.next(); + if (jars.contains(jar.getResolvedSourceLocation())){ + return createErrorStatus("Duplicated jar on classpath: "+jar.getResolvedSourceLocation()); + } + else { + jars.add(jar.getSourceLocation()); + } + } + return OK_STATUS; + } + private IPath getProjectPath() { String projName = (String)getProperty(FACET_PROJECT_NAME); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projName); @@ -214,16 +323,16 @@ public class JSFFacetInstallDataModelProvider extends List list = new ArrayList(); if (JSFCorePlugin.getDefault().getJSFLibraryRegistry() != null) { JSFLibrary jsfLib = JSFCorePlugin.getDefault().getJSFLibraryRegistry().getDefaultImplementation(); - JSFProjectLibraryReference prjJSFLib = new JSFProjectLibraryReference(jsfLib, true, true); + JSFLibraryReference prjJSFLib = new JSFLibraryReference(jsfLib, true, true); list.add(prjJSFLib); } return list; } - private JSFProjectLibraryReference getDefaultImplementationLibrary() { + private JSFLibraryReference getDefaultImplementationLibrary() { if (JSFCorePlugin.getDefault().getJSFLibraryRegistry() != null) { JSFLibrary jsfLib = JSFCorePlugin.getDefault().getJSFLibraryRegistry().getDefaultImplementation(); - return new JSFProjectLibraryReference(jsfLib, true, true); + return new JSFLibraryReference(jsfLib, true, true); } return null; } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java index c428334c6..31d89eaa7 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetInstallDelegate.java @@ -21,16 +21,21 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil; +import org.eclipse.jst.j2ee.classpathdep.IClasspathDependencyConstants; import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; import org.eclipse.jst.j2ee.webapplication.Servlet; import org.eclipse.jst.j2ee.webapplication.WebApp; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.J2EEModuleDependencyDelegate; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfiglModelSource; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigProjectData; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigModel; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFProjectLibraryReference; +import org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; import org.eclipse.wst.common.project.facet.core.IDelegate; import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; @@ -39,7 +44,6 @@ import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; * JSF Facet Install Delegate for WTP faceted web projects. * * Uses <code>com.eclispe.jst.jsf.core.internal.project.facet.JSFFacetInstallDataModelProvider<code> for model - * <li> TODO: creates JSF Application Model * <li> creates JSF configuration file if not present * <li> updates web.xml for: servlet, servlet-mapping and context-param * <li> adds implementation jars to WEB-INF/lib if user requests @@ -72,21 +76,9 @@ public class JSFFacetInstallDelegate implements IDelegate { // config = new JSFFacetInstallConfig(); // config.setJsfImplID(jsfImplID); } - // Create JSF App Model - // tbd - // Update project dependencies and save configiuration data - java.util.List implLibs = (List) config.getProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION_LIBRARIES); - java.util.List compLibs = (List) config.getProperty(IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES); - - JSFLibraryConfiglModelSource source = new JSFLibraryConfigProjectData(project); - JSFLibraryConfigModel model = JSFLibraryConfigModel.JSFLibraryConfigModelFactory.createInstance(source); - model.setCurrentJSFImplementationLibrarySelection((JSFProjectLibraryReference) implLibs.get(0)); - model.setCurrentJSFComponentLibrarySelection(compLibs); - - J2EEModuleDependencyDelegate updateDependecnies = new J2EEModuleDependencyDelegate(project); - updateDependecnies.updateProjectDependencies(model, monitor); - model.saveData(project); + // Create JSF Libs as classpath containers and set WTP dependencies as required + createClasspathEntries(project, config, monitor); // Create config file createConfigFile(project, fv, config, monitor); @@ -105,19 +97,61 @@ public class JSFFacetInstallDelegate implements IDelegate { } } - /** Obsoleted M1 approach - private void deployJSFLibraries(IProject project, - final IDataModel config, IProgressMonitor monitor) { - - if (config.getBooleanProperty(IJSFFacetInstallDataModelProperties.DEPLOY_IMPLEMENTATION)){ - JSFLibrary impl = (JSFLibrary)config.getProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION); - if (impl != null){ - IPath destPath = project.getLocation().append(getWebContentPath(project)); - impl.copyTo(destPath.toOSString()); + private void createClasspathEntries(IProject project, IDataModel config, IProgressMonitor monitor) { + IJavaProject javaProject = JavaCore.create(project); + List cpEntries = new ArrayList(); + try { + for (int i=0;i<javaProject.getRawClasspath().length;i++){ + cpEntries.add(javaProject.getRawClasspath()[i]); } + } catch (JavaModelException e) { + JSFCorePlugin.log(e, "Unable to read classpath"); + } + + //Implementation + IPath cp = new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID); + JSFLibraryReference libref = (JSFLibraryReference)config.getProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION); + IPath path = cp.append(new Path(libref.getID())); + IClasspathEntry entry = getNewCPEntry(path, libref); + cpEntries.add(entry); + + JSFLibraryReference[] compLibs = (JSFLibraryReference[])config.getProperty(IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES); + for (int i=0;i<compLibs.length;i++){ + libref = (JSFLibraryReference)compLibs[i]; + cp = new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID); + path = cp.append(new Path(libref.getID())); + entry = getNewCPEntry(path, libref); + if (entry != null) + cpEntries.add(entry); + } + + JSFLibraryRegistryUtil.setRawClasspath(javaProject, cpEntries, monitor); + } + + //creates new IClasspathEntry with WTP dependency attribute set, if required + private IClasspathEntry getNewCPEntry(IPath path, JSFLibraryReference lib) { + + IClasspathEntry entry = null; + if (lib.isCheckedToBeDeployed()){ + IClasspathAttribute depAttrib = JavaCore.newClasspathAttribute(IClasspathDependencyConstants.CLASSPATH_COMPONENT_DEPENDENCY, + ClasspathDependencyUtil.getDefaultRuntimePath(true).toString()); + entry = JavaCore.newContainerEntry(path,null, new IClasspathAttribute[]{depAttrib}, true); } + else { + entry = JavaCore.newContainerEntry(path); + } + + return entry; } - */ + + //revisit when can set attr on new cp container. curren +// private void addWTPDependencyAttribute(IProject project, IClasspathEntry entry) { +// try { +// UpdateClasspathAttributeUtil.addDependencyAttribute(null, project.getProject().getName(), entry); +// } catch (ExecutionException e) { +// JSFCorePlugin.log(e, "Unable to set WTP J2EE Module Dependency for: "+entry.getPath().lastSegment()); +// } +// } private void createConfigFile(final IProject project, final IProjectFacetVersion fv, final IDataModel config, @@ -140,8 +174,7 @@ public class JSFFacetInstallDelegate implements IDelegate { op.run(monitor); } } catch (CoreException e) { - JSFCorePlugin.getDefault().getMsgLogger().log(e); - e.printStackTrace(); + JSFCorePlugin.log(e, "Exception occured while creating faces-config.xml"); } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetUninstallDelegate.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetUninstallDelegate.java index e8371cad9..d45ee6da5 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetUninstallDelegate.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFFacetUninstallDelegate.java @@ -10,17 +10,25 @@ *******************************************************************************/ package org.eclipse.jst.jsf.core.internal.project.facet; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.IClasspathEntry; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jst.j2ee.common.ParamValue; import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; import org.eclipse.jst.j2ee.web.componentcore.util.WebArtifactEdit; import org.eclipse.jst.j2ee.webapplication.ContextParam; import org.eclipse.jst.j2ee.webapplication.Servlet; import org.eclipse.jst.j2ee.webapplication.WebApp; +import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; +import org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer; import org.eclipse.wst.common.project.facet.core.IDelegate; import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; @@ -46,14 +54,8 @@ public class JSFFacetUninstallDelegate implements IDelegate { try { - // Remove JSF App Model - - // Rempoe JSF Impl Class Container - // Add JSF Impl Class Container - // final IJavaProject jproj = JavaCore.create(project); - // final IPath cont = new - // Path(JSFImplContainer.CONTAINER_ID).append(project.getName()); - // removeClasspathContainer(jproj, cont); + // Remove JSF Libraries + removeJSFLibaries(project, monitor); // remove servlet stuff from web.xml uninstallJSFReferencesFromWebApp(project, monitor); @@ -69,6 +71,34 @@ public class JSFFacetUninstallDelegate implements IDelegate { } } + private void removeJSFLibaries(IProject project, IProgressMonitor monitor) { + final IJavaProject jproj = JavaCore.create(project); + List keptEntries = new ArrayList(); + try { + IClasspathEntry[] entries = jproj.getRawClasspath(); + keptEntries = new ArrayList(); + for (int i=0;i<entries.length;i++){ + IClasspathEntry entry = entries[i]; + if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && + ! entry.getPath().segment(0) + .equals(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID)) + keptEntries.add(entry); + } + } catch (JavaModelException e) { + JSFCorePlugin.log(e, "Cannot get classpath entries to remove JSF Libraries for: "+project.getName()); + } + + if (keptEntries.size() > 0){ + try { + jproj.setRawClasspath((IClasspathEntry[])keptEntries.toArray(new IClasspathEntry[0]), monitor); + } catch (JavaModelException e) { + JSFCorePlugin.log(e, "Exception occured while removing JSF Libraries during JSF Facet uninstall"); + } + } + + + } + private void uninstallJSFReferencesFromWebApp(IProject project, IProgressMonitor monitor) { WebArtifactEdit artifactEdit = JSFUtils diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java index ec4774ceb..49df01c51 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/project/facet/JSFUtils.java @@ -49,7 +49,11 @@ import org.eclipse.wst.common.frameworks.datamodel.IDataModel; */ public class JSFUtils { /** - * The name of the Faces servlet class + * The default name for the Faces servlet + */ + public static final String JSF_DEFAULT_SERVLET_NAME = "Faces Servlet"; //$NON-NLS-1$ + /** + * The default name of the Faces servlet class */ public static final String JSF_SERVLET_CLASS = "javax.faces.webapp.FacesServlet"; //$NON-NLS-1$ /** @@ -205,8 +209,15 @@ public class JSFUtils { */ public static Servlet createOrUpdateServletRef(WebApp webApp, IDataModel config, Servlet servlet) { + String displayName = config.getStringProperty(IJSFFacetInstallDataModelProperties.SERVLET_NAME); - + if (displayName.equals("")) + displayName = JSF_DEFAULT_SERVLET_NAME; + + String className = config.getStringProperty(IJSFFacetInstallDataModelProperties.SERVLET_CLASSNAME); + if (className.equals("")) + className = JSF_SERVLET_CLASS; + if (servlet == null) { // Create the servlet instance and set up the parameters from data // model @@ -215,7 +226,7 @@ public class JSFUtils { ServletType servletType = WebapplicationFactory.eINSTANCE .createServletType(); - servletType.setClassName(JSF_SERVLET_CLASS); + servletType.setClassName(className); servlet.setWebType(servletType); servlet.setLoadOnStartup(new Integer(1)); // Add the servlet to the web application model diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/provisional/jsflibraryregistry/PluginProvidedJSFLibraryCreationHelper.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/provisional/jsflibraryregistry/PluginProvidedJSFLibraryCreationHelper.java index f3f0c7bdf..959941ddf 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/provisional/jsflibraryregistry/PluginProvidedJSFLibraryCreationHelper.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/provisional/jsflibraryregistry/PluginProvidedJSFLibraryCreationHelper.java @@ -68,7 +68,7 @@ public final class PluginProvidedJSFLibraryCreationHelper { */ public JSFLibrary create(){ PluginProvidedJSFLibrary newLib = JSFLibraryRegistryFactory.eINSTANCE.createPluginProvidedJSFLibrary(); - newLib.setID(getLibID()); +// newLib.setID(getLibID()); newLib.setPluginID(getPluginID()); newLib.setName(config_element.getAttribute(NAME)); newLib.setImplementation(config_element.getAttribute(IS_IMPL).equals("true") ? true : false); //$NON-NLS-1$ @@ -124,18 +124,7 @@ public final class PluginProvidedJSFLibraryCreationHelper { } } } - - /** - * Returns the JSFLibrary instance's ID as specified in the plugin. - * - * @return The JSFLibrary instance's ID - */ - private String getLibID(){ - StringBuffer buf = new StringBuffer(config_element.getDeclaringExtension().getUniqueIdentifier()); - buf.append("/").append(config_element.getAttribute(NAME)); //$NON-NLS-1$ - return buf.toString(); - } - + /** * Returns the plugin's ID. * diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml b/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml index b1fbca373..338f0c166 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/plugin.xml @@ -27,32 +27,10 @@ hasPages="true" icon="icons/obj16/library_obj.gif" id="org.eclipse.jst.jsf.ui.jsfLibraryWizard" - name="%jsf.library.wizard.name" + name="JSF Library" preferredPerspectives="org.eclipse.jst.j2ee.J2EEPerspective"/> </extension> <extension - point="org.eclipse.ui.propertyPages"> - <page - adaptable="true" - class="org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryPropertyPage" - id="org.eclipse.jst.jsf.ui.properties.jsfLibraryPropertyPage" - name="%jsf.library.reference" - objectClass="org.eclipse.core.resources.IProject"> - <enabledWhen> - <and> - <adapt type="org.eclipse.core.resources.IProject"> - <or> - <test - forcePluginActivation="true" - property="org.eclipse.wst.common.project.facet.core.projectFacet" - value="jst.jsf"/> - </or> - </adapt> - </and> - </enabledWhen> - </page> - </extension> - <extension point="org.eclipse.wst.common.project.facet.ui.wizardPages"> <wizard-pages action="jst.jsf.v11.install"> <page class="org.eclipse.jst.jsf.ui.internal.project.facet.JSFFacetInstallPage"/> @@ -93,5 +71,13 @@ </contentTypeIdentifier> </validator> </extension> + <extension + point="org.eclipse.jdt.ui.classpathContainerPage"> + <classpathContainerPage + class="org.eclipse.jst.jsf.ui.internal.classpath.JSFLibraryContainerWizardPage" + id="org.eclipse.jst.jsf.core.internal.jsflibrarycontainer" + name="JSF Libraries"> + </classpathContainerPage> + </extension> </plugin> diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/Messages.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/Messages.java index f658fc916..a3bc764a6 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/Messages.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/Messages.java @@ -31,6 +31,7 @@ public class Messages extends NLS { public static String JSFFacetInstallPage_DeployJarsLabel; public static String JSFFacetInstallPage_JSFConfigLabel; public static String JSFFacetInstallPage_JSFServletNameLabel; + public static String JSFFacetInstallPage_JSFServletClassNameLabel; public static String JSFFacetInstallPage_JSFURLMappingLabel; public static String JSFFacetInstallPage_PatternDialogTitle; public static String JSFFacetInstallPage_PatternDialogDesc; @@ -80,7 +81,10 @@ public class Messages extends NLS { public static String JSFLibraryContainerWizardPage_WarningNoJSFFacet; public static String JSFLibraryContainerWizardPage_JSFLibraries; public static String JSFLibraryContainerWizardPage_Add; + public static String JSFLibraryContainerWizardPage_Edit; public static String JSFLibraryContainerWizardPage_ErrorInitializing; + public static String JSFLibraryContainerWizardPage_ImplAlreadyPresent; + public static String JSFLibraryContainerWizardPage_SelectOneImpl; public static String JSFLibraryPropertyPage_No_JSF_Facet_Installed; diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java index dd3a974c9..9724380b0 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibrariesPreferencePage.java @@ -27,6 +27,7 @@ import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; @@ -87,6 +88,7 @@ public class JSFLibrariesPreferencePage extends PreferencePage implements IWorkb tv.setLabelProvider(tvLabelProvider); tv.addSelectionChangedListener(tvAdapter); tv.addDoubleClickListener(tvAdapter); + tv.setComparator(tvAdapter); tv.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tv.setInput(getJSFLibraries()); @@ -198,7 +200,7 @@ public class JSFLibrariesPreferencePage extends PreferencePage implements IWorkb return tv; } - private class TreeViewerAdapter implements ITreeContentProvider, ISelectionChangedListener, IDoubleClickListener { + private class TreeViewerAdapter extends ViewerComparator implements ITreeContentProvider, ISelectionChangedListener, IDoubleClickListener { private final Object[] NO_ELEMENTS= new Object[0]; // ------- ITreeContentProvider Interface ------------ @@ -252,6 +254,18 @@ public class JSFLibrariesPreferencePage extends PreferencePage implements IWorkb public void doubleClick(DoubleClickEvent event) { doDoubleClick(event); } + + public int compare(Viewer viewer, Object e1, Object e2) { + if (e1 instanceof JSFLibrary && e2 instanceof JSFLibrary){ + JSFLibrary lib1 = (JSFLibrary)e1; + JSFLibrary lib2 = (JSFLibrary)e2; + + return getComparator().compare(lib1.getName(), lib2.getName()); + } + return super.compare(viewer, e1, e2); + } + + } protected void doListSelected(SelectionChangedEvent event) { diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java index c1aea6bcd..7dd6eebe8 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryContainerWizardPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005 Oracle Corporation. + * Copyright (c) 2005 2007 Oracle Corporation. * 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 @@ -11,14 +11,22 @@ package org.eclipse.jst.jsf.ui.internal.classpath; import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; +import java.util.List; +import java.util.Map; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.ui.wizards.IClasspathContainerPage; import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension; +import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension2; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -27,17 +35,22 @@ import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.jface.viewers.IDoubleClickListener; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionChangedListener; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; +import org.eclipse.jst.jsf.core.internal.JSFLibrariesContainerInitializer; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.PluginProvidedJSFLibrary; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.jst.jsf.ui.internal.Messages; import org.eclipse.swt.SWT; @@ -65,14 +78,21 @@ import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature; * @author Gerry Kessler - Oracle */ public class JSFLibraryContainerWizardPage extends WizardPage implements - IClasspathContainerPage, IClasspathContainerPageExtension{ + IClasspathContainerPage, IClasspathContainerPageExtension, IClasspathContainerPageExtension2{ - private TableViewer lv; + private CheckboxTableViewer lv; private JSFLibrariesTableViewerAdapter lvAdapter; private JSFLibrariesListLabelProvider lvLabelProvider; - private ArrayList elements; - private boolean isJSFProject = false; - + + private boolean isJSFProject = false; + private IClasspathEntry containerEntry; + private IClasspathEntry[] currentEntries; + private Map _currentLibs; + private JSFLibrary currentLib; + + /** + * Zero arg constructor + */ public JSFLibraryContainerWizardPage(){ super(Messages.JSFLibraryContainerWizardPage_PageName); setTitle(Messages.JSFLibraryContainerWizardPage_Title); @@ -81,8 +101,12 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements setImageDescriptor( JSFUiPlugin.getImageDescriptor("full/wizban/addlibrary_wiz.gif")); //$NON-NLS-1$ } + /* (non-Javadoc) + * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry[]) + */ public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) { isJSFProject = false; + this.currentEntries = currentEntries; try { //check for faceted nature //NOTE: use of following constant produces warnings; this was known @@ -108,37 +132,101 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements } } + /* (non-Javadoc) + * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#finish() + */ public boolean finish() { - // TODO Create lib containers and verify single implementation selected return true; } + /* (non-Javadoc) + * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension2#getNewContainers() + */ + public IClasspathEntry[] getNewContainers() { + IPath cp = new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID); + List res = new ArrayList(); + Object[] items = lv.getCheckedElements(); + for (int i=0;i<items.length;i++){ + JSFLibrary jsfLib = (JSFLibrary)items[i]; + if (getSelectedJSFLibariesForProject().get(jsfLib.getID()) == null){ + IPath path = cp.append(new Path(jsfLib.getID())); + IClasspathEntry entry = JavaCore.newContainerEntry(path); + // need to update wtp dependency in j2ee mod dependency ui + res.add(entry); + } + } + return (IClasspathEntry[])res.toArray(new IClasspathEntry[]{}); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() + */ public boolean isPageComplete() { if (!isJSFProject) { return false; } + if (isEditReference() && ! selectionHasChanged()) + return false; + return isValid(); } - private boolean isValid() { - return false; + private boolean isValid() { + return isCheckedItems() && getErrorMessage() == null; + } + + //to be used to know whether the selected library has changed when in "edit" mode + private boolean selectionHasChanged() { + JSFLibrary lib = getCurrentLibrarySelection(); + if (lib == null) + return false; + + return (getJSFLibraryForEdit(containerEntry) != lib) ; + + } + + private JSFLibrary getCurrentLibrarySelection() { + JSFLibrary lib = null; + StructuredSelection ssel = (StructuredSelection)lv.getSelection(); + if (ssel != null && !ssel.isEmpty()){ + lib = (JSFLibrary)ssel.getFirstElement(); + } + return lib; + } + + private boolean isCheckedItems() { + return lv.getCheckedElements().length > 0; } /* (non-Javadoc) * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#getSelection() */ public IClasspathEntry getSelection() { - // TODO: dead code? - // if (lv.getSelection()!= null){ -// } - return null; + IClasspathEntry entry = null; + if (isEditReference()){ + if (lv.getCheckedElements().length == 0) + return containerEntry; + + JSFLibrary lib = (JSFLibrary)lv.getCheckedElements()[0]; + if (lib != null){ + if (lib == getJSFLibraryForEdit(containerEntry)) + return containerEntry; + else { + IPath path = new Path(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID).append(new Path(lib.getID())); + entry = JavaCore.newContainerEntry(path, containerEntry.getAccessRules(), containerEntry.getExtraAttributes(),containerEntry.isExported()); + } + } + } + return entry; + } /* (non-Javadoc) * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#setSelection(org.eclipse.jdt.core.IClasspathEntry) */ public void setSelection(IClasspathEntry containerEntry) { - // getSelection always returns null + //this is signalling that this is an "edit" + this.containerEntry = containerEntry; } public void createControl(Composite parent) { @@ -170,68 +258,205 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements lv.setLabelProvider(lvLabelProvider); lv.addSelectionChangedListener(lvAdapter); lv.addDoubleClickListener(lvAdapter); - - lv.setInput(getJSFLibraries()); - -// Composite btnBar = new Composite(c, SWT.NONE); -// GridLayout gl = new GridLayout(1, false); -// gl.marginHeight = 0; -// gl.marginWidth = 0; - - Button addButton = new Button(c, SWT.NONE); + lv.setComparator(lvAdapter); + + Composite buttons = new Composite(c, SWT.NONE); + buttons.setLayout(new GridLayout(1, false)); + buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL)); + + final Button addButton = new Button(buttons, SWT.NONE); addButton.setText(Messages.JSFLibraryContainerWizardPage_Add); addButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); addButton.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent e){ - openJSFLibraryWizard(null); + openJSFLibraryWizard(null); + } + }); + + final Button editButton = new Button(buttons, SWT.NONE); + editButton.setText(Messages.JSFLibraryContainerWizardPage_Edit); + editButton.setLayoutData(new GridData(GridData.END | GridData.VERTICAL_ALIGN_BEGINNING)); + editButton.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e){ + StructuredSelection sel = (StructuredSelection)lv.getSelection(); + if ((sel == null || sel.isEmpty()) && containerEntry != null){ + JSFLibrary jsfLib = getJSFLibraryForEdit(containerEntry); + sel = new StructuredSelection(jsfLib); + } + openJSFLibraryWizard(sel); } + }); + editButton.setVisible(false); + lv.addSelectionChangedListener(new ISelectionChangedListener(){ + public void selectionChanged(SelectionChangedEvent event) { + setEditButton(event.getSelection()); + } + private void setEditButton(final ISelection selection) { + IStructuredSelection sel = (IStructuredSelection)selection; + editButton.setVisible(sel.size()==1); + if (sel.size() == 1){ + JSFLibrary lib = (JSFLibrary)sel.getFirstElement(); + boolean pp = lib instanceof PluginProvidedJSFLibrary; + editButton.setEnabled(! pp); + if (isEditReference()){ + lv.setAllChecked(false); + lv.setChecked(lib, true); + } + } + + } + }); setControl(c); + + if (isEditReference()){ + JSFLibrary lib = getJSFLibraryForEdit(containerEntry); + lv.setInput(getAllUnselectedJSFLibrariesExceptReferencedLib(lib)); + selectAndCheckCurrentLib(lib); + setDescription("Select JSF Libary for this reference to use. Choose 'Edit...' to modify contents of the selected libarary."); + } + else { + lv.setInput(getAllJSFLibraries()); + lv.setCheckedElements(getSelectedJSFLibariesForProject().values().toArray(new Object[0])); + } + } + + private void selectAndCheckCurrentLib(final JSFLibrary lib) { + if (lib != null){ + StructuredSelection ssel = new StructuredSelection(lib); + lv.setSelection(ssel); + lv.setChecked(lib, true); + } } - private void openJSFLibraryWizard(Object element){ + private Object getAllUnselectedJSFLibrariesExceptReferencedLib(JSFLibrary referenceLib) { + List allLibs = getAllJSFLibraries(); + Collection selLibs = getSelectedJSFLibariesForProject().values(); + for (Iterator it=selLibs.iterator();it.hasNext();){ + JSFLibrary aLib = (JSFLibrary)it.next(); + int i= allLibs.indexOf(aLib); + //remove from allLibs unless it is the selected reference + if (i >= 0 && ((referenceLib == null) || (aLib != null && ! aLib.getID().equals(referenceLib.getID())))){ + allLibs.remove(i); + } + } + return allLibs; + } + + private List getJSFLibraryEntries(IClasspathEntry[] entries) { + List jsfLibs = new ArrayList(); + for (int i=0;i<entries.length;i++){ + IClasspathEntry entry = entries[i]; + if (isJSFLibrary(entry)){ + JSFLibrary lib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry(). getJSFLibraryByID(entry.getPath().segment(1)); + if (lib != null){ + jsfLibs.add(lib); + } + } + } + + return jsfLibs; + } + + private boolean isJSFLibrary(IClasspathEntry entry) { + return entry.getPath().segment(0).equals(JSFLibrariesContainerInitializer.JSF_LIBRARY_CP_CONTAINER_ID); + } + + private void openJSFLibraryWizard(IStructuredSelection element){ IWorkbenchWizard wizard = new JSFLibraryWizard(); IWorkbench wb = PlatformUI.getWorkbench(); - wizard.init(wb, getStructuredElement(element)); + wizard.init(wb, element); WizardDialog dialog = new WizardDialog(wb.getActiveWorkbenchWindow().getShell(), wizard); int ret = dialog.open(); if (ret == Window.OK){ //FIXME: select returned object + if (containerEntry == null){ + lv.setInput(getAllJSFLibraries()); + } + else { + lv.setInput(getAllUnselectedJSFLibrariesExceptReferencedLib(getJSFLibraryForEdit(containerEntry))); + lv.refresh(true); + } lv.refresh(); } } - private IStructuredSelection getStructuredElement(Object element) { - if (element != null && element instanceof IStructuredSelection){ - //FIXME: -// IStructuredSelection firstelement = (IStructuredSelection)((IStructuredSelection)element).getFirstElement(); -// return new StructuredSelection(firstelement); - } - return null; - } - - private TableViewer createTableViewer(Composite parent) { + private CheckboxTableViewer createTableViewer(Composite parent) { Table table= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); table.setFont(parent.getFont()); CheckboxTableViewer tableViewer= new CheckboxTableViewer(table); tableViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent e) { - validate(); + if (! isEditReference()){ + //ensure that existing CP entries cannot be unchecked + if (getSelectedJSFLibariesForProject().get(((JSFLibrary)e.getElement()).getID()) != null){ + if (containerEntry == null) + e.getCheckable().setChecked(e.getElement(), true); + else + lv.setAllChecked(true); + } + } + else { + //select only one + lv.setAllChecked(false); + lv.setChecked(e.getElement(), true); + if (isEditReference()) + lv.setSelection(new StructuredSelection(e.getElement())); + } + validate(); } }); return tableViewer; } - private Object getJSFLibraries() { - elements = new ArrayList(10); - elements.addAll(JSFCorePlugin.getDefault().getJSFLibraryRegistry().getAllJSFLibraries()); - return elements; + private Map getSelectedJSFLibariesForProject(){ + if (_currentLibs == null){ + List allLibs = getAllJSFLibraries(); + List curLibs = getJSFLibraryEntries(currentEntries); + _currentLibs = new HashMap(curLibs.size()); + for (Iterator it=curLibs.iterator();it.hasNext();){ + JSFLibrary lib = (JSFLibrary)it.next(); + int index = getIndex(allLibs, lib); + if (index >=0) + _currentLibs.put(lib.getID(), allLibs.get(index)); + } + + } + return _currentLibs; } + + private List getAllJSFLibraries() { + List allLibs = JSFCorePlugin.getDefault().getJSFLibraryRegistry().getAllJSFLibraries(); + + return allLibs; + } + + + private JSFLibrary getJSFLibraryForEdit( + IClasspathEntry containerEntry) { + if (currentLib == null){ + String id = containerEntry.getPath().segment(1); + currentLib = JSFLibraryRegistryUtil.getInstance().getJSFLibraryRegistry().getJSFLibraryByID(id); + } + return currentLib; + + } + + private int getIndex(List libs, JSFLibrary lib) { + for (int i=0;i<libs.size();i++){ + if (lib.getID().equals(((JSFLibrary)libs.get(i)).getID())) + return i; + } + return -1; + } + + private class JSFLibrariesTableViewerAdapter extends ViewerComparator implements IStructuredContentProvider, ISelectionChangedListener, IDoubleClickListener { + + private Object input; - private class JSFLibrariesTableViewerAdapter implements IStructuredContentProvider, ISelectionChangedListener, IDoubleClickListener { public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - //should never happen + input = newInput; } /* (non-Javadoc) @@ -244,15 +469,18 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements /* (non-Javadoc) * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) */ - public Object[] getElements(Object inputElement) { - return elements.toArray(); + public Object[] getElements(Object inputElement) { + return ((List)input).toArray(); } /* (non-Javadoc) * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) */ public void selectionChanged(SelectionChangedEvent event) { - doListSelected(event); + if (isEditReference()){ + setPageComplete(isPageComplete()); + } + } /* (non-Javadoc) @@ -261,6 +489,23 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements public void doubleClick(DoubleClickEvent event) { doDoubleClick(event); } + + public int compare(Viewer viewer, Object e1, Object e2) { + JSFLibrary lib1 = (JSFLibrary)e1; + JSFLibrary lib2 = (JSFLibrary)e2; + + //sort first by in selection already and then by name + boolean lib1Sel = getSelectedJSFLibariesForProject().get(lib1.getID())!=null; + boolean lib2Sel = getSelectedJSFLibariesForProject().get(lib2.getID())!= null; + + if ((lib1Sel && lib2Sel) || (!lib1Sel && !lib2Sel) ){ + return getComparator().compare(lib1.getName(), lib2.getName()); + } + else if (lib1Sel) + return -1; + else + return 1; + } } private class JSFLibrariesListLabelProvider implements ILabelProvider{ @@ -303,15 +548,35 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements } private void validate() { - // TODO: what's this for? seems dead + setErrorMessage(null); + int implChosenCount = implSelectedCount(); + if (implChosenCount>1){ + setErrorMessage(Messages.JSFLibraryContainerWizardPage_ImplAlreadyPresent); + } + setPageComplete(isPageComplete()); } - private void doListSelected(SelectionChangedEvent event) { - // what's this for? seems dead. + + private boolean isEditReference() { + return (containerEntry != null); + } + + private int implSelectedCount() { + int count = 0; + for (int i=0;i<lv.getCheckedElements().length;i++){ + JSFLibrary lib = (JSFLibrary)lv.getCheckedElements()[i]; + if (lib.isImplementation()) + count++; + } + return count; } private void doDoubleClick(DoubleClickEvent event) { - openJSFLibraryWizard(lv.getSelection()); + StructuredSelection ssel = (StructuredSelection)event.getSelection(); + if (ssel != null && + (! ((JSFLibrary)ssel.getFirstElement() instanceof PluginProvidedJSFLibrary))) + openJSFLibraryWizard((IStructuredSelection)event.getSelection()); } + } diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java new file mode 100644 index 000000000..59c6f2b4d --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryEditControl.java @@ -0,0 +1,446 @@ +package org.eclipse.jst.jsf.ui.internal.classpath; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryFactory; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion; +import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; +import org.eclipse.jst.jsf.ui.internal.Messages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.CCombo; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; + +public class JSFLibraryEditControl extends Composite implements ModifyListener, SelectionListener { + private Text txtName; + private Label lblName; + private CCombo cboVersions; + private Label lblVersions; + private Button chkDeploy; + private Button chkImpl; + private Composite btnBar; + private Button btnAdd; + private Button btnRemove; + private TableViewer jars; + + private boolean initing = false; + + private JSFLibrary workingCopyLibrary; + + private String validationMsg; + private Set _listeners; + private int _isNew = -1;//use isNew() method.. not this variable directly + + public JSFLibraryEditControl(JSFLibrary workingCopyLibrary, Composite parent){ + super(parent, SWT.NONE); + this.workingCopyLibrary = workingCopyLibrary; + _listeners = new HashSet(1); + createControl(parent); + } + + public void addValidationListener(JSFLibraryValidationListener listener){ + removeValidationListener(listener); + _listeners.add(listener); + } + + public void removeValidationListener(JSFLibraryValidationListener listener){ + _listeners.remove(listener); + } + + public void createControl(Composite parent) { + initing = true; + +// this = new Composite(parent, SWT.NONE); + this.setLayout(new GridLayout(2, false)); + this.setLayoutData(new GridData(GridData.FILL_BOTH)); + + lblName = new Label(this, SWT.NONE); + lblName.setText(Messages.JSFLibraryWizard_LibraryName); + lblName.setLayoutData(new GridData(GridData.BEGINNING)); + + txtName = new Text(this, SWT.BORDER); + txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + txtName.addModifyListener(this); + + lblVersions = new Label(this, SWT.NONE); + lblVersions.setText(Messages.JSFLibraryWizard_VersionSupported); + + cboVersions = new CCombo(this, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER); + cboVersions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + cboVersions.addModifyListener(this); + + Group jarsComp = new Group(this, SWT.NONE); + jarsComp.setText(Messages.JSFLibraryWizard_LibraryJars); + GridLayout gl1 = new GridLayout(2, false); + jarsComp.setLayout(gl1); + GridData gd2 = new GridData(GridData.FILL_HORIZONTAL + | GridData.FILL_VERTICAL); + gd2.horizontalSpan = 2; + jarsComp.setLayoutData(gd2); + + createJarsViewer(jarsComp); + + createButtons(jarsComp); + + chkImpl = new Button(this, SWT.CHECK); + chkImpl.setText(Messages.JSFLibraryWizard_IsJSFImplementation); + GridData gd3 = new GridData(); + gd3.horizontalSpan = 2; + chkImpl.setLayoutData(gd3); + chkImpl.addSelectionListener(this); + + chkDeploy = new Button(this, SWT.CHECK); + chkDeploy.setText(Messages.JSFLibraryWizard_DeployJars); + GridData gd4 = new GridData(); + gd4.horizontalSpan = 2; + chkDeploy.setLayoutData(gd4); +// chkDeploy.addSelectionListener(this); + chkDeploy.setVisible(false); + + loadVersions(); + + if (!isNew()) { + txtName.setText(workingCopyLibrary.getName()); + cboVersions.setText(workingCopyLibrary.getJSFVersion().getName()); + chkDeploy.setSelection(workingCopyLibrary.isDeployed()); + chkImpl.setSelection(workingCopyLibrary.isImplementation()); + } + jars.setInput(workingCopyLibrary); + + initing = false; + + txtName.setFocus(); + } + + private void createJarsViewer(Group jarsComp) { + jars = new TableViewer(jarsComp, SWT.BORDER | SWT.MULTI); + jars.setContentProvider(new IStructuredContentProvider() { + public Object[] getElements(Object inputElement) { + if (inputElement instanceof JSFLibrary) + return ((JSFLibrary) inputElement).getArchiveFiles() + .toArray(); + return new Object[0]; + } + + public void dispose() { + // do nothing + } + + public void inputChanged(Viewer viewer, Object oldInput, + Object newInput) { + // won't happen + } + }); + jars.setLabelProvider(new ILabelProvider() { + private Image jarImg = null; + public Image getImage(Object element) { + if (jarImg == null){ + ImageDescriptor desc = JSFUiPlugin.getImageDescriptor("obj16/jar_obj.gif"); //$NON-NLS-1$ + jarImg = desc.createImage(); + } + return jarImg; + } + + public String getText(Object element) { + StringBuffer labelBuf = new StringBuffer(); + if (element instanceof ArchiveFile) { + ArchiveFile archive = (ArchiveFile) element; + labelBuf.append(archive.getName()); + if (!archive.exists()) + labelBuf.append("[missing]"); //$NON-NLS-1$ + labelBuf.append(" - ").append(archive.getPath()); //$NON-NLS-1$ + } + return labelBuf.toString(); + } + + public void addListener(ILabelProviderListener listener) { + // no listeners supported + } + + public void dispose() { + if (jarImg != null) + jarImg.dispose(); + } + + public boolean isLabelProperty(Object element, String property) { + return false; + } + + public void removeListener(ILabelProviderListener listener) { + // no listeners supported + } + }); + + jars.addSelectionChangedListener(new ISelectionChangedListener(){ + public void selectionChanged(SelectionChangedEvent event){ + updateButtons(); + } + }); + + GridData gd = new GridData(GridData.FILL_BOTH); +// gd.widthHint = convertWidthInCharsToPixels(30); +// gd.heightHint = convertHeightInCharsToPixels(10); + jars.getControl().setLayoutData(gd); + } + + private void updateButtons() { + btnRemove.setEnabled(!((StructuredSelection)jars.getSelection()).isEmpty()); + // getButton(IDialogConstants.OK_ID).setEnabled(modified); + } + + private void createButtons(Composite c) { + btnBar = new Composite(c, SWT.NONE); + GridLayout gl = new GridLayout(1, false); + gl.marginHeight = 0; + gl.marginTop = 0; + gl.marginWidth = 0; + btnBar.setLayout(gl); + btnBar.setLayoutData(new GridData(GridData.END)); + + btnAdd = new Button(btnBar, SWT.NONE); + btnAdd.setText(Messages.JSFLibraryWizard_Add); + btnAdd.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_BEGINNING)); + btnAdd.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + String cur = null; + String[] chosenJars = openExtJarFileDialog(cur); + if (chosenJars != null) { + for (int i = 0; i < chosenJars.length; i++) { + String jar = chosenJars[i]; + if (!workingCopyLibrary.containsArchiveFile(jar)) { + ArchiveFile archive = JSFLibraryRegistryFactory.eINSTANCE + .createArchiveFile(); + archive.setSourceLocation(jar); + archive.setRelativeDestLocation("WEB-INF/lib"); //$NON-NLS-1$ + workingCopyLibrary.getArchiveFiles().add(archive); + } + } + jars.refresh(); + validate(); + } + } + }); + + btnRemove = new Button(btnBar, SWT.NONE); + btnRemove.setEnabled(false); + btnRemove.setText(Messages.JSFLibraryWizard_Remove); + btnRemove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.VERTICAL_ALIGN_BEGINNING)); + btnRemove.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (jars.getSelection() instanceof StructuredSelection){ + StructuredSelection objs = (StructuredSelection)jars.getSelection(); + if (objs != null){ + Iterator it = objs.iterator(); + while (it.hasNext()){ + Object obj = it.next(); + ArchiveFile jar = (ArchiveFile)obj; + workingCopyLibrary.getArchiveFiles().remove(jar); + } + } + jars.refresh(); + validate(); + } + } + }); + } + + private void loadVersions() { + cboVersions.removeAll(); + Iterator it = JSFVersion.VALUES.iterator(); + while (it.hasNext()) { + JSFVersion ver = (JSFVersion) it.next(); + cboVersions.add(ver.getName()); + } + } + + private String[] openExtJarFileDialog(String existing) { + String title = Messages.JSFLibraryWizard_ExtJarFileDialogTitle; + + FileDialog dialog = new FileDialog(getShell(), + existing == null ? SWT.MULTI : SWT.SINGLE); + dialog.setText(title); + dialog.setFilterExtensions(new String[] { "*.jar;*.zip" }); //$NON-NLS-1$ + // FIXME: remember and use last path chosen?? + String filterPath = ResourcesPlugin.getWorkspace().getRoot() + .getFullPath().toString(); + dialog.setFilterPath(filterPath); + // if (existing != null) { + // dialog.setFileName(existing.getPath().lastSegment()); + // } + + String res = dialog.open(); + if (res == null) { + return null; + } + String[] fileNames = dialog.getFileNames(); + String[] elems = new String[fileNames.length]; + IPath file = new Path(res); + IPath apath = file.removeLastSegments(1); + for (int i = 0; i < fileNames.length; i++) { + elems[i] = apath.append(fileNames[i]).toString(); + } + return elems; + } + + public void modifyText(ModifyEvent e) { + validate(); + updateButtons(); + } + + private void fireValidateEvent(final JSFLibraryValidationEvent jSFLibraryValidationEvent) { + new Runnable(){ + public void run() { + for (Iterator it=_listeners.iterator();it.hasNext();){ + JSFLibraryValidationListener listener = (JSFLibraryValidationListener)it.next(); + listener.notifyValidation(jSFLibraryValidationEvent); + } + } + }.run(); + } + + + public void widgetSelected(SelectionEvent e) { + validate(); + updateButtons(); + } + + public void widgetDefaultSelected(SelectionEvent e) { + // no handling for default selection + } + + private void validate() { + if (initing) + return; + validationMsg = null; +// setPageComplete(true); + if (!validateName() || !validateJars() || !validateVersion()) { +// setPageComplete(false); + } + fireValidateEvent(new JSFLibraryValidationEvent(validationMsg)); + } + + private boolean validateJars() { + if (workingCopyLibrary.getArchiveFiles().isEmpty()) { + validationMsg = Messages.JSFLibraryWizard_ValidateNoJars; + return false; + } + return true; + } + + private boolean validateVersion() { + //FIXME: why isn't selection indesx correct??? + // if (cboVersions.getSelectionIndex() < 0) { + // setErrorMessage("Choose the maximum JSF version supported if known."); + // return false; + // } + return true; + } + + private boolean validateName() { + if (txtName.getText() == null + || txtName.getText().trim().equals("")) { //$NON-NLS-1$ + validationMsg = Messages.JSFLibraryWizard_ValidateNoLibraryName; + return false; + } + String aName = txtName.getText().trim(); + if (isNew() || (!isNew() && !getCurrentLibraryName().equals(aName))) { + if (isNameInRegistry(JSFCorePlugin.getDefault() + .getJSFLibraryRegistry().getAllJSFLibraries(), aName)) { + validationMsg = Messages.JSFLibraryWizard_ValidateExistingLibraryName; + return false; + } + } + return true; + } + + private boolean isNew() { + if (_isNew == -1){ + _isNew = workingCopyLibrary.getName() == null ? 1 : 0; + } + return _isNew == 1; + } + + private String getCurrentLibraryName() { + return workingCopyLibrary.getName(); + } + + private boolean isNameInRegistry(Collection c, String name) { + Iterator it = c.iterator(); + while (it.hasNext()) { + JSFLibrary lib = (JSFLibrary) it.next(); + if (lib.getName().equals(name)) { + return true; + } + } + return false; + } + + public String getJSFLibraryName() { + return txtName.getText().trim(); + } + + + public boolean getIsDeployed() { + return chkDeploy.getSelection(); + } + + + public boolean getIsImplementation() { + return chkImpl.getSelection(); + } + + public JSFVersion getJSFVersion() { + if (cboVersions.getSelectionIndex() >= 0) { + JSFVersion ver = (JSFVersion) JSFVersion.VALUES.get(cboVersions + .getSelectionIndex()); + return ver; + } + return JSFVersion.UNKNOWN_LITERAL; + } + + public void setImplOnly(boolean implsOnly) { + if (implsOnly){ + chkImpl.setSelection(true); + chkImpl.setEnabled(false); + } + } + + public void setNonImplOnly(boolean nonImplsOnly) { + if (nonImplsOnly){ + chkImpl.setSelection(false); + chkImpl.setEnabled(false); + } + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java new file mode 100644 index 000000000..104dc5e46 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationEvent.java @@ -0,0 +1,44 @@ +package org.eclipse.jst.jsf.ui.internal.classpath; + +import org.eclipse.core.runtime.IStatus; + +/** + * Validation event used by JSFLibraryControl to notify containers of updates + * + */ +public class JSFLibraryValidationEvent { + private String msg; + private int severity; + + /** + * Constructor + * @param msg + * @param severity - IStatus int value + */ + public JSFLibraryValidationEvent(String msg, int severity) { + this.msg = msg; + this.severity = severity; + } + + /** + * Constructs event with severity of IStatus.ERROR + * @param msg + */ + public JSFLibraryValidationEvent(String msg) { + this(msg, IStatus.ERROR); + } + + /** + * @return validation message + */ + public String getMessage(){ + return msg; + } + + /** + * @return IStatus int value + */ + public int getSeverity(){ + return severity; + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java new file mode 100644 index 000000000..ffb05255d --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryValidationListener.java @@ -0,0 +1,13 @@ +package org.eclipse.jst.jsf.ui.internal.classpath; + +/** + * Listeners of {@link JSFLibraryValidationEvent}s should implement + * + */ +public interface JSFLibraryValidationListener { + /** + * Callback + * @param JSFLibraryValidationEvent + */ + public void notifyValidation(JSFLibraryValidationEvent e); +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java index d1c6ede76..6baaa3447 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizard.java @@ -10,45 +10,21 @@ *******************************************************************************/ package org.eclipse.jst.jsf.ui.internal.classpath; -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ILabelProviderListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; -import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistryFactory; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFVersion; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.CCombo; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; @@ -60,20 +36,20 @@ import org.eclipse.ui.IWorkbench; * @author Gerry Kessler - Oracle */ public class JSFLibraryWizard extends Wizard implements INewWizard { - private Text txtName; - private Label lblName; - private CCombo cboVersions; - private Label lblVersions; - private Button chkDeploy; - private Button chkImpl; - private Composite btnBar; - private Button btnAdd; - private Button btnRemove; - private TableViewer jars; + /** + * Implementation libaries to be included + */ + public static int IMPLS = 1; + /** + * Non-Implementation libaries to be included + */ + public static int NONIMPLS = 2; + + private JSFLibraryEditControl c; + private boolean isNew = false; private boolean modified = false; - private boolean implsOnly = false; private JSFLibrary curLibrary; private JSFLibrary workingCopyLibrary; @@ -83,17 +59,49 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { private static final String DESCRIPTION = Messages.JSFLibraryWizard_DESCRIPTION; private static final String IMPLS_ONLY_DESC = Messages.JSFLibraryWizard_IMPLS_ONLY_DESC; - private boolean nonimplOnly = false; + private boolean _impls; + private boolean _nonimpls; - public JSFLibraryWizard(boolean b) { + /** + * Constructor + * @see IMPLS + * @see NONIMPLS + * @param libTypes + */ + public JSFLibraryWizard(int libTypes) { super(); - implsOnly = b; + if ((libTypes & IMPLS) == IMPLS) + _impls = true; + + if ((libTypes & NONIMPLS) == NONIMPLS) + _nonimpls = true; } + + /** + * Constructor. List will include all JSF Libraries. + */ public JSFLibraryWizard() { super(); + _impls = true; + _nonimpls = true; } + private boolean isImplsOnly(){ + if (_impls && ! _nonimpls) + return true; + return false; + } + + private boolean isNonImplsOnly(){ + if (_nonimpls && ! _impls) + return true; + return false; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ public void init(IWorkbench workbench, IStructuredSelection selection) { if (selection != null && selection.getFirstElement() instanceof JSFLibrary) { @@ -103,60 +111,79 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { isNew = true; workingCopyLibrary = JSFLibraryRegistryFactory.eINSTANCE.createJSFLibrary(); } - if (implsOnly) { + if (isImplsOnly()) { setWindowTitle(Messages.JSFLibraryWizard_CreateImplementation); } else { setWindowTitle(isNew ? Messages.JSFLibraryWizard_CreateJSFLibrary : Messages.JSFLibraryWizard_EditJSFLibrary); } } - public void init(IWorkbench workbench, IStructuredSelection selection, boolean nonimplonly) { - init(workbench, selection); - this.nonimplOnly = nonimplonly; - } - public boolean performFinish() { - final String name = txtName.getText().trim(); - final boolean isDeployed = chkDeploy.getSelection(); - final boolean isImplementation = chkImpl.getSelection(); + /** + * Updates the JSF Library instance with the values from the working copy and + * persists the registry. + * + * If editing a library reference, referencing java models will be updated. + * + * @see org.eclipse.jface.wizard.Wizard#performFinish() + */ + public boolean performFinish() { + final String name = c.getJSFLibraryName(); + final boolean isDeployed = c.getIsDeployed(); + final boolean isImplementation = c.getIsImplementation(); + final JSFVersion version = c.getJSFVersion(); + workingCopyLibrary.setName(name); - if (cboVersions.getSelectionIndex() >= 0) { - JSFVersion ver = (JSFVersion) JSFVersion.VALUES.get(cboVersions - .getSelectionIndex()); - workingCopyLibrary.setJSFVersion(ver); - } workingCopyLibrary.setDeployed(isDeployed); workingCopyLibrary.setImplementation(isImplementation); + workingCopyLibrary.setJSFVersion(version); + + final String originalID = curLibrary != null ? curLibrary.getID() :workingCopyLibrary.getID(); + if (isNew){ JSFCorePlugin.getDefault().getJSFLibraryRegistry().addJSFLibrary(workingCopyLibrary); } else { curLibrary.updateValues(workingCopyLibrary); + try { + JSFLibraryRegistryUtil.rebindClasspathContainerEntries(originalID, workingCopyLibrary.getID(), false, null); + } catch (JavaModelException e) { + JSFUiPlugin.log(IStatus.ERROR, "Exception while updating JSF Library containers", e); + } } JSFCorePlugin.getDefault().saveJSFLibraryRegistry(); return true; } + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.Wizard#addPages() + */ public void addPages() { page = new JSFLibraryWizardPage(Messages.JSFLibraryWizard_JSFLibrary); super.addPage(page); page.setWizard(this); } + /** + * @return the JSFLibrary being modified by this wizard + */ public JSFLibrary getJSFLibrary() { return workingCopyLibrary; } - private class JSFLibraryWizardPage extends WizardPage implements - ModifyListener, SelectionListener { - - private boolean initing; + private class JSFLibraryWizardPage extends WizardPage { + /** + * @param pageName + */ protected JSFLibraryWizardPage(String pageName) { super(pageName); - setDescription(implsOnly ? IMPLS_ONLY_DESC : DESCRIPTION); + setDescription(isImplsOnly() ? IMPLS_ONLY_DESC : DESCRIPTION); setTitle(Messages.JSFLibraryWizard_JSFLibrary); } + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() + */ public boolean isPageComplete() { if (modified == false) { return false; @@ -164,321 +191,30 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { return super.isPageComplete(); } + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ public void createControl(Composite parent) { - initing = true; initializeDialogUnits(parent); - Composite c = new Composite(parent, SWT.NONE); + c = new JSFLibraryEditControl(workingCopyLibrary, parent); + c.setImplOnly(isImplsOnly()); + c.setNonImplOnly(isNonImplsOnly()); c.setLayout(new GridLayout(2, false)); c.setLayoutData(new GridData(GridData.FILL_BOTH)); - lblName = new Label(c, SWT.NONE); - lblName.setText(Messages.JSFLibraryWizard_LibraryName); - lblName.setLayoutData(new GridData(GridData.BEGINNING)); - - txtName = new Text(c, SWT.BORDER); - txtName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - txtName.addModifyListener(this); - - lblVersions = new Label(c, SWT.NONE); - lblVersions.setText(Messages.JSFLibraryWizard_VersionSupported); - - cboVersions = new CCombo(c, SWT.SINGLE | SWT.READ_ONLY | SWT.BORDER); - cboVersions.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - cboVersions.addModifyListener(this); - - Group jarsComp = new Group(c, SWT.NONE); - jarsComp.setText(Messages.JSFLibraryWizard_LibraryJars); - GridLayout gl1 = new GridLayout(2, false); - jarsComp.setLayout(gl1); - GridData gd2 = new GridData(GridData.FILL_HORIZONTAL - | GridData.FILL_VERTICAL); - gd2.horizontalSpan = 2; - jarsComp.setLayoutData(gd2); - - createJarsViewer(jarsComp); - - createButtons(jarsComp); - - chkImpl = new Button(c, SWT.CHECK); - chkImpl.setText(Messages.JSFLibraryWizard_IsJSFImplementation); - GridData gd3 = new GridData(); - gd3.horizontalSpan = 2; - chkImpl.setLayoutData(gd3); - chkImpl.addSelectionListener(this); - - chkDeploy = new Button(c, SWT.CHECK); - chkDeploy.setText(Messages.JSFLibraryWizard_DeployJars); - GridData gd4 = new GridData(); - gd4.horizontalSpan = 2; - chkDeploy.setLayoutData(gd4); - chkDeploy.addSelectionListener(this); - chkDeploy.setVisible(false); - - loadVersions(); - - if (!isNew) { - txtName.setText(workingCopyLibrary.getName()); - cboVersions.setText(workingCopyLibrary.getJSFVersion().getName()); - chkDeploy.setSelection(workingCopyLibrary.isDeployed()); - chkImpl.setSelection(workingCopyLibrary.isImplementation()); - } - - if (implsOnly) { - chkImpl.setSelection(true); - chkImpl.setEnabled(false); - } - - if (nonimplOnly) { - chkImpl.setSelection(false); - chkImpl.setEnabled(false); - } - jars.setInput(workingCopyLibrary); + c.addValidationListener(new JSFLibraryValidationListener(){ + public void notifyValidation(JSFLibraryValidationEvent e) { + setErrorMessage(e.getMessage()); + modified = true; + setPageComplete(getErrorMessage()==null); + } + }); - initing = false; setControl(c); - - txtName.setFocus(); setPageComplete(false); } - private void createJarsViewer(Group jarsComp) { - jars = new TableViewer(jarsComp, SWT.BORDER | SWT.MULTI); - jars.setContentProvider(new IStructuredContentProvider() { - public Object[] getElements(Object inputElement) { - if (inputElement instanceof JSFLibrary) - return ((JSFLibrary) inputElement).getArchiveFiles() - .toArray(); - return new Object[0]; - } - - public void dispose() { - // do nothing - } - - public void inputChanged(Viewer viewer, Object oldInput, - Object newInput) { - // won't happen - } - }); - jars.setLabelProvider(new ILabelProvider() { - private Image jarImg = null; - public Image getImage(Object element) { - if (jarImg == null){ - ImageDescriptor desc = JSFUiPlugin.getImageDescriptor("obj16/jar_obj.gif"); //$NON-NLS-1$ - jarImg = desc.createImage(); - } - return jarImg; - } - - public String getText(Object element) { - StringBuffer labelBuf = new StringBuffer(); - if (element instanceof ArchiveFile) { - ArchiveFile archive = (ArchiveFile) element; - labelBuf.append(archive.getName()); - if (!archive.exists()) - labelBuf.append("[missing]"); //$NON-NLS-1$ - labelBuf.append(" - ").append(archive.getPath()); //$NON-NLS-1$ - } - return labelBuf.toString(); - } - - public void addListener(ILabelProviderListener listener) { - // no listeners supported - } - - public void dispose() { - if (jarImg != null) - jarImg.dispose(); - } - - public boolean isLabelProperty(Object element, String property) { - return false; - } - - public void removeListener(ILabelProviderListener listener) { - // no listeners supported - } - }); - - GridData gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = convertWidthInCharsToPixels(30); - gd.heightHint = convertHeightInCharsToPixels(10); - jars.getControl().setLayoutData(gd); - } - - private void updateButtons() { - btnRemove.setEnabled(jars.getSelection() != null); - // getButton(IDialogConstants.OK_ID).setEnabled(modified); - } - - private void createButtons(Composite c) { - btnBar = new Composite(c, SWT.NONE); - GridLayout gl = new GridLayout(1, false); - gl.marginHeight = 0; - gl.marginTop = 0; - gl.marginWidth = 0; - btnBar.setLayout(gl); - btnBar.setLayoutData(new GridData(GridData.END)); - - btnAdd = new Button(btnBar, SWT.NONE); - btnAdd.setText(Messages.JSFLibraryWizard_Add); - btnAdd.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); - btnAdd.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - String cur = null; - String[] chosenJars = openExtJarFileDialog(cur); - if (chosenJars != null) { - for (int i = 0; i < chosenJars.length; i++) { - String jar = chosenJars[i]; - if (!workingCopyLibrary.containsArchiveFile(jar)) { - ArchiveFile archive = JSFLibraryRegistryFactory.eINSTANCE - .createArchiveFile(); - archive.setSourceLocation(jar); - archive.setRelativeDestLocation("WEB-INF/lib"); //$NON-NLS-1$ - workingCopyLibrary.getArchiveFiles().add(archive); - modified = true; - } - } - jars.refresh(); - validate(); - } - } - }); - - btnRemove = new Button(btnBar, SWT.NONE); - btnRemove.setText(Messages.JSFLibraryWizard_Remove); - btnRemove.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL - | GridData.VERTICAL_ALIGN_BEGINNING)); - btnRemove.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (jars.getSelection() instanceof StructuredSelection){ - StructuredSelection objs = (StructuredSelection)jars.getSelection(); - if (objs != null){ - Iterator it = objs.iterator(); - while (it.hasNext()){ - Object obj = it.next(); - ArchiveFile jar = (ArchiveFile)obj; - workingCopyLibrary.getArchiveFiles().remove(jar); - modified = true; - } - } - jars.refresh(); - validate(); - } - } - }); - } - - private void loadVersions() { - cboVersions.removeAll(); - Iterator it = JSFVersion.VALUES.iterator(); - while (it.hasNext()) { - JSFVersion ver = (JSFVersion) it.next(); - cboVersions.add(ver.getName()); - } - } - - private String[] openExtJarFileDialog(String existing) { - String title = Messages.JSFLibraryWizard_ExtJarFileDialogTitle; - - FileDialog dialog = new FileDialog(getShell(), - existing == null ? SWT.MULTI : SWT.SINGLE); - dialog.setText(title); - dialog.setFilterExtensions(new String[] { "*.jar;*.zip" }); //$NON-NLS-1$ - // FIXME: remember and use last path chosen?? - String filterPath = ResourcesPlugin.getWorkspace().getRoot() - .getFullPath().toString(); - dialog.setFilterPath(filterPath); - // if (existing != null) { - // dialog.setFileName(existing.getPath().lastSegment()); - // } - - String res = dialog.open(); - if (res == null) { - return null; - } - String[] fileNames = dialog.getFileNames(); - String[] elems = new String[fileNames.length]; - IPath file = new Path(res); - IPath apath = file.removeLastSegments(1); - for (int i = 0; i < fileNames.length; i++) { - elems[i] = apath.append(fileNames[i]).toString(); - } - return elems; - } - - public void modifyText(ModifyEvent e) { - modified = true; - validate(); - updateButtons(); - } - - public void widgetSelected(SelectionEvent e) { - modified = true; - validate(); - updateButtons(); - } - - public void widgetDefaultSelected(SelectionEvent e) { - // no handling for default selection - } - - private void validate() { - if (initing) - return; - setErrorMessage(null); - setPageComplete(true); - if (!validateName() || !validateJars() || !validateVersion()) { - setPageComplete(false); - } - } - - private boolean validateJars() { - if (getJSFLibrary().getArchiveFiles().isEmpty()) { - setErrorMessage(Messages.JSFLibraryWizard_ValidateNoJars); - return false; - } - return true; - } - - private boolean validateVersion() { - //FIXME: why isn't selection indesx correct??? -// if (cboVersions.getSelectionIndex() < 0) { -// setErrorMessage("Choose the maximum JSF version supported if known."); -// return false; -// } - return true; - } - - private boolean validateName() { - if (txtName.getText() == null - || txtName.getText().trim().equals("")) { //$NON-NLS-1$ - setErrorMessage(Messages.JSFLibraryWizard_ValidateNoLibraryName); - return false; - } - String aName = txtName.getText().trim(); - if (isNew || (!isNew && !curLibrary.getName().equals(aName))) { - if (isNameInRegistry(JSFCorePlugin.getDefault() - .getJSFLibraryRegistry().getAllJSFLibraries(), aName)) { - setErrorMessage(Messages.JSFLibraryWizard_ValidateExistingLibraryName); - return false; - } - } - return true; - } - - private boolean isNameInRegistry(Collection c, String name) { - Iterator it = c.iterator(); - while (it.hasNext()) { - JSFLibrary lib = (JSFLibrary) it.next(); - if (lib.getName().equals(name)) { - return true; - } - } - return false; - } } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizardPage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizardPage.java new file mode 100644 index 000000000..019d67f4e --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/JSFLibraryWizardPage.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2005 Oracle Corporation. + * 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: + * Gerry Kessler - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.jsf.ui.internal.classpath; + +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; +import org.eclipse.jst.jsf.ui.internal.Messages; +import org.eclipse.swt.widgets.Composite; + +/** + * Dialog for creating or editing a JSF Library or Implementation. + * <br> + * If the selection passed in init is not null then the item will be edit mode. + * + * @author Gerry Kessler - Oracle + */ +public class JSFLibraryWizardPage extends WizardPage { + + private boolean modified = false; + private JSFLibrary workingCopyLibrary; + + private static final String DESCRIPTION = Messages.JSFLibraryWizard_DESCRIPTION; + + /** + * Constructor + */ + public JSFLibraryWizardPage(){ + super("JSFLibrary"); + } + + /** + * @return JSF Library working copy + */ + public JSFLibrary getJSFLibrary() { + return workingCopyLibrary; + } + + /** + * Constructor + * @param pageName + */ + public JSFLibraryWizardPage(String pageName) { + super(pageName); + setDescription(DESCRIPTION);//implsOnly ? IMPLS_ONLY_DESC : + setTitle(Messages.JSFLibraryWizard_JSFLibrary); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.wizard.WizardPage#isPageComplete() + */ + public boolean isPageComplete() { + if (modified == false) { + return false; + } + return super.isPageComplete(); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + JSFLibraryEditControl editControl = new JSFLibraryEditControl(workingCopyLibrary, parent); + editControl.addValidationListener(new JSFLibraryValidationListener(){ + public void notifyValidation(JSFLibraryValidationEvent e) { + setErrorMessage(e.getMessage()); + modified = true; + setPageComplete(getErrorMessage()==null); + } + }); + setControl(editControl); + setPageComplete(false); + } + + + /* (non-Javadoc) + * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#finish() + */ + public boolean finish() { + return true; + } + + +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/contentassist/JSFContentAssistProcessor.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/contentassist/JSFContentAssistProcessor.java index 97f1e1c68..eb14e08d5 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/contentassist/JSFContentAssistProcessor.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/contentassist/JSFContentAssistProcessor.java @@ -21,7 +21,6 @@ import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControl.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControl.java index bc20ec649..af2b2c2f8 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControl.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. + * Copyright (c) 2006, 2007 Oracle Corporation. * 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 @@ -12,12 +12,17 @@ package org.eclipse.jst.jsf.ui.internal.jsflibraryconfig; import java.util.ArrayList; import java.util.Collections; +import java.util.EventObject; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.Vector; +import org.eclipse.core.runtime.ISafeRunnable; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.util.SafeRunnable; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; import org.eclipse.jface.viewers.ComboViewer; @@ -42,17 +47,16 @@ import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigModel; import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfiglModelSource; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryRegistryUtil; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFProjectLibraryReference; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.ArchiveFile; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibrary; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.JSFLibraryRegistry; +import org.eclipse.jst.jsf.core.internal.project.facet.IJSFFacetInstallDataModelProperties; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.jst.jsf.ui.internal.Messages; import org.eclipse.jst.jsf.ui.internal.classpath.JSFLibraryWizard; import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; @@ -64,8 +68,11 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.PlatformUI; +import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelSynchHelper; /** * A custom control used in wizard and property pages. @@ -77,7 +84,6 @@ public class JSFLibraryConfigControl extends Composite { final private int COLUMN_LIB_NAME = 1; private JSFLibraryConfigModel workingCopyModel = null; - // TODO: never read private JSFLibraryConfiglModelSource persistentModel = null; private ComboViewer cvImplLib; private CheckboxTableViewer ctvSelCompLib; @@ -86,24 +92,70 @@ public class JSFLibraryConfigControl extends Composite { private TreeViewerAdapter tvAdapter; private TreeLabelProvider tvLabelProvider; private Combo comboImplLib; - - private Vector newJSFLibCreatedListeners = new Vector(); + private Button btnAddAll; + private Button btnRemoveAll; + + private Vector newJSFLibCreatedListeners = new Vector(); + private Set _changeListeners; + private boolean _initing; + private IDataModel model; + /** + * @param listener + */ public void addOkClickedListener(IJSFImplLibraryCreationListener listener) { newJSFLibCreatedListeners.addElement(listener); } + /** + * @param listener + */ public void removeOkClickedListener(IJSFImplLibraryCreationListener listener) { newJSFLibCreatedListeners.removeElement(listener); } /** + * @param listener + */ + public void addChangeListener(JSFLibraryConfigControlChangeListener listener){ + getChangeListeners().add(listener); + } + + /** + * @param listener + */ + public void removeChangeListener(JSFLibraryConfigControlChangeListener listener){ + if (getChangeListeners().contains(listener)) + getChangeListeners().remove(listener); + } + + private Set getChangeListeners() { + if (_changeListeners == null){ + _changeListeners = new HashSet(); + } + return _changeListeners; + } + + private void fireChangedEvent(final EventObject e){ + if (_initing) return; + SafeRunnable.run(new ISafeRunnable(){ + public void handleException(Throwable exception) { + } + public void run() throws Exception { + for (Iterator it=getChangeListeners().iterator();it.hasNext();){ + ((JSFLibraryConfigControlChangeListener)it.next()).changed(new JSFLibraryConfigControlChangeEvent(e)); + } + } + }); + } + + /** * Create the composite * @param parent * @param style */ public JSFLibraryConfigControl(Composite parent, int style) { super(parent, style); - + _initing = true; createControls(); } @@ -117,9 +169,11 @@ public class JSFLibraryConfigControl extends Composite { // never read persistentModel = source; workingCopyModel = JSFLibraryConfigModel.JSFLibraryConfigModelFactory.createInstance(source); initializeControlValues(); + _initing = false; } else { JSFUiPlugin.log(IStatus.ERROR, Messages.JSFLibraryConfigControl_NullProject); } + } /* (non-Javadoc) @@ -128,13 +182,6 @@ public class JSFLibraryConfigControl extends Composite { public void dispose() { super.dispose(); } - - /* (non-Javadoc) - * @see org.eclipse.swt.widgets.Composite#checkSubclass() - */ - protected void checkSubclass() { - // TODO: overriding sub-class checking? why? - } /** * Return current selected JSF Implementation Library. @@ -142,7 +189,7 @@ public class JSFLibraryConfigControl extends Composite { * * @return JSFLibraryDecorator */ - public JSFProjectLibraryReference getSelectedJSFLibImplementation() { + public JSFLibraryReference getSelectedJSFLibImplementation() { return workingCopyModel.getCurrentJSFImplementationLibrarySelection(); } @@ -169,18 +216,18 @@ public class JSFLibraryConfigControl extends Composite { btnDeployJars.setSelection(false); //JSFLibraryDecorator savedImplLib = persistentModel.getJSFImplementationLibrary(); - JSFProjectLibraryReference savedImplLib = workingCopyModel.getSavedJSFImplementationLibrary(); + JSFLibraryReference savedImplLib = workingCopyModel.getSavedJSFImplementationLibrary(); if ( savedImplLib != null ) { /* * Get the input for the control to set selection. */ - JSFProjectLibraryReference selected = JSFLibraryRegistryUtil.getInstance().getJSFLibryReferencebyID(savedImplLib.getID()); + JSFLibraryReference selected = JSFLibraryRegistryUtil.getInstance().getJSFLibraryReferencebyID(savedImplLib.getID()); if (selected != null) { btnDeployJars.setSelection(selected.isCheckedToBeDeployed()); cvImplLib.setSelection(new StructuredSelection(selected), true); } } else { - JSFProjectLibraryReference dftJSFImplLib = JSFLibraryRegistryUtil.getInstance().getDefaultJSFImplementationLibrary(); + JSFLibraryReference dftJSFImplLib = JSFLibraryRegistryUtil.getInstance().getDefaultJSFImplementationLibrary(); if (dftJSFImplLib != null) { btnDeployJars.setSelection(dftJSFImplLib.isCheckedToBeDeployed()); cvImplLib.setSelection(new StructuredSelection(dftJSFImplLib), true); @@ -189,18 +236,19 @@ public class JSFLibraryConfigControl extends Composite { loadJSFCompList(); - JSFProjectLibraryReference savedCompLib = null; - JSFProjectLibraryReference selected = null; + JSFLibraryReference savedCompLib = null; + JSFLibraryReference selected = null; //Iterator it = persistentModel.getJSFComponentLibraries().iterator(); Iterator it = workingCopyModel.getJSFComponentLibraries().iterator(); while (it.hasNext()) { - savedCompLib = (JSFProjectLibraryReference) it.next(); - selected = JSFLibraryRegistryUtil.getInstance().getJSFLibryReferencebyID(savedCompLib.getID()); + savedCompLib = (JSFLibraryReference) it.next(); + selected = JSFLibraryRegistryUtil.getInstance().getJSFLibraryReferencebyID(savedCompLib.getID()); if (selected != null) { ctvSelCompLib.setChecked(selected, selected.isCheckedToBeDeployed()); } } - + + setCompListModelProperty(); redraw(); } @@ -213,12 +261,12 @@ public class JSFLibraryConfigControl extends Composite { ctvSelCompLib.setInput(workingCopyModel.getJSFComponentLibraries()); } - private JSFProjectLibraryReference getCurrentSelectedJSFImplLib() { - JSFProjectLibraryReference selJSFImpl = null; + private JSFLibraryReference getCurrentSelectedJSFImplLib() { + JSFLibraryReference selJSFImpl = null; StructuredSelection objs = (StructuredSelection)cvImplLib.getSelection(); if (objs != null){ - if (objs.getFirstElement() instanceof JSFProjectLibraryReference){ - selJSFImpl = (JSFProjectLibraryReference)objs.getFirstElement(); + if (objs.getFirstElement() instanceof JSFLibraryReference){ + selJSFImpl = (JSFLibraryReference)objs.getFirstElement(); } } return selJSFImpl; @@ -243,9 +291,13 @@ public class JSFLibraryConfigControl extends Composite { btnDeployJars.setText(Messages.JSFLibraryConfigControl_DeployJAR); btnDeployJars.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - JSFProjectLibraryReference jsflib = getCurrentSelectedJSFImplLib(); - jsflib.setToBeDeployed(btnDeployJars.getSelection()); - workingCopyModel.setCurrentJSFImplementationLibrarySelection(jsflib); + if (! _initing){ + JSFLibraryReference jsflib = getCurrentSelectedJSFImplLib(); + jsflib.setToBeDeployed(btnDeployJars.getSelection()); + workingCopyModel.setCurrentJSFImplementationLibrarySelection(jsflib);//why r we doing this here??? + // model.setProperty(IJSFFacetInstallDataModelProperties.DEPLOY_IMPLEMENTATION, btnDeployJars.getSelection()); + fireChangedEvent(e); + } } } ); @@ -271,9 +323,11 @@ public class JSFLibraryConfigControl extends Composite { new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { StructuredSelection ss = (StructuredSelection) event.getSelection(); - JSFProjectLibraryReference crtSelImplLib = (JSFProjectLibraryReference) ss.getFirstElement(); + JSFLibraryReference crtSelImplLib = (JSFLibraryReference) ss.getFirstElement(); crtSelImplLib.setToBeDeployed(btnDeployJars.getSelection()); workingCopyModel.setCurrentJSFImplementationLibrarySelection(crtSelImplLib); + model.setProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION, crtSelImplLib); + fireChangedEvent(event); } } ); @@ -283,14 +337,14 @@ public class JSFLibraryConfigControl extends Composite { btnNewImpl.setText(Messages.JSFLibraryConfigControl_NewImplementationLibrary); btnNewImpl.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - JSFLibraryWizard wizard = new JSFLibraryWizard(true); + JSFLibraryWizard wizard = new JSFLibraryWizard(JSFLibraryWizard.IMPLS); IWorkbench wb = PlatformUI.getWorkbench(); wizard.init(wb, null); WizardDialog dialog = new WizardDialog(wb .getActiveWorkbenchWindow().getShell(), wizard); int ret = dialog.open(); if (ret == Window.OK) { - JSFProjectLibraryReference lib = new JSFProjectLibraryReference(wizard.getJSFLibrary(), true, true); + JSFLibraryReference lib = new JSFLibraryReference(wizard.getJSFLibrary(), true, true); JSFLibraryRegistryUtil.getInstance().addJSFLibrary(lib); workingCopyModel.getJSFImplementationLibraries().add(lib); workingCopyModel.setCurrentJSFImplementationLibrarySelection(lib); @@ -325,8 +379,15 @@ public class JSFLibraryConfigControl extends Composite { tvLabelProvider = new TreeLabelProvider(); tvCompLib.setContentProvider(tvAdapter); tvCompLib.setLabelProvider(tvLabelProvider); - tvCompLib.addSelectionChangedListener(tvAdapter); - tvCompLib.addDoubleClickListener(tvAdapter); + tvCompLib.addDoubleClickListener(new IDoubleClickListener(){ + public void doubleClick(DoubleClickEvent event) { + resetComponentLibSelection((StructuredSelection)event.getSelection(), + tvCompLib, + ctvSelCompLib, + true); + fireChangedEvent(event); + } + }); tvCompLib.getTree().setLayoutData(new GridData(GridData.FILL_BOTH)); tvCompLib.addFilter(new TreeViewerFilter()); @@ -343,22 +404,24 @@ public class JSFLibraryConfigControl extends Composite { final Button btnAdd = new Button(composite_Single, SWT.NONE); btnAdd.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnAdd.setText(Messages.JSFLibraryConfigControl_Add); + btnAdd.setEnabled(false); final Button btnRemove = new Button(composite_Single, SWT.NONE); btnRemove.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnRemove.setText(Messages.JSFLibraryConfigControl_Remove); - + btnRemove.setEnabled(false); + final Composite composite_All = new Composite(composite_buttons, SWT.None); composite_All.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); final GridLayout gl_All = new GridLayout(); gl_Single.marginHeight = 4; composite_All.setLayout(gl_All); - final Button btnAddAll = new Button(composite_All, SWT.NONE); + btnAddAll = new Button(composite_All, SWT.NONE); btnAddAll.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnAddAll.setText(Messages.JSFLibraryConfigControl_AddAll); - final Button btnRemoveAll = new Button(composite_All, SWT.NONE); + btnRemoveAll = new Button(composite_All, SWT.NONE); btnRemoveAll.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); btnRemoveAll.setText(Messages.JSFLibraryConfigControl_RemoveAll); @@ -373,14 +436,14 @@ public class JSFLibraryConfigControl extends Composite { btnNewCompLib.setText(Messages.JSFLibraryConfigControl_NewComponentLibrary); btnNewCompLib.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { - JSFLibraryWizard wizard = new JSFLibraryWizard(false); + JSFLibraryWizard wizard = new JSFLibraryWizard(JSFLibraryWizard.NONIMPLS); IWorkbench wb = PlatformUI.getWorkbench(); - wizard.init(wb, null, true); + wizard.init(wb, null); WizardDialog dialog = new WizardDialog(wb .getActiveWorkbenchWindow().getShell(), wizard); int ret = dialog.open(); if (ret == Window.OK) { - JSFProjectLibraryReference lib = new JSFProjectLibraryReference( + JSFLibraryReference lib = new JSFLibraryReference( wizard.getJSFLibrary(), true, true); @@ -388,6 +451,7 @@ public class JSFLibraryConfigControl extends Composite { workingCopyModel.getJSFComponentLibraries().add(lib); loadJSFCompList(); + setCompListModelProperty(); ctvSelCompLib.setChecked(lib, true); } } @@ -409,51 +473,82 @@ public class JSFLibraryConfigControl extends Composite { ctvSelCompLib.setSorter(new SelectedCompLibCTVSorter()); ctvSelCompLib.setLabelProvider(new SelectedCompLibCTVLabelProvider()); ctvSelCompLib.setContentProvider(new CompLibCTVContentProvider()); + ctvSelCompLib.addDoubleClickListener(new IDoubleClickListener(){ + public void doubleClick(DoubleClickEvent event) { + resetComponentLibSelection((StructuredSelection)event.getSelection(), + tvCompLib, + ctvSelCompLib, + false); + fireChangedEvent(event); + } + }); ctvSelCompLib.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { - JSFProjectLibraryReference changedItem = (JSFProjectLibraryReference) event.getElement(); + JSFLibraryReference changedItem = (JSFLibraryReference) event.getElement(); boolean isChecked4Deploy = event.getChecked(); List list = workingCopyModel.getJSFComponentLibraries(); Iterator it = list.iterator(); - JSFProjectLibraryReference crtjsflib = null; + JSFLibraryReference crtjsflib = null; while (it.hasNext()) { - crtjsflib = (JSFProjectLibraryReference) it.next(); + crtjsflib = (JSFLibraryReference) it.next(); if (crtjsflib.getID().equals(changedItem.getID())) { crtjsflib.setToBeDeployed(isChecked4Deploy); + fireChangedEvent(event); break; } } } }); - btnAdd.addMouseListener(new MouseAdapter() { - public void mouseDown(MouseEvent e) { + btnAdd.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { resetComponentLibSelection((StructuredSelection)tvCompLib.getSelection(), tvCompLib, ctvSelCompLib, true); + fireChangedEvent(e); } }); - btnAddAll.addMouseListener(new MouseAdapter() { - public void mouseDown(MouseEvent e) { + + btnAddAll.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { resetCompontLibSelectionAll(tvCompLib, ctvSelCompLib, true); + fireChangedEvent(e); } }); - btnRemove.addMouseListener(new MouseAdapter() { - public void mouseDown(MouseEvent e) { + btnRemove.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { resetComponentLibSelection((StructuredSelection)ctvSelCompLib.getSelection(), tvCompLib, ctvSelCompLib, false); + fireChangedEvent(e); } }); - btnRemoveAll.addMouseListener(new MouseAdapter() { - public void mouseDown(MouseEvent e) { + + btnRemoveAll.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { resetCompontLibSelectionAll(tvCompLib, ctvSelCompLib, false); + fireChangedEvent(e); } }); - + + tvCompLib.addSelectionChangedListener(new ISelectionChangedListener(){ + public void selectionChanged(SelectionChangedEvent event) { + StructuredSelection sel= (StructuredSelection)event.getSelection(); + btnAdd.setEnabled(!sel.isEmpty() && sel.getFirstElement() instanceof JSFLibraryReference); + btnAddAll.setEnabled(tvCompLib.getTree().getItemCount() > 0); + } + }); + + ctvSelCompLib.addSelectionChangedListener(new ISelectionChangedListener(){ + public void selectionChanged(SelectionChangedEvent event) { + StructuredSelection sel= (StructuredSelection)event.getSelection(); + btnRemove.setEnabled(!sel.isEmpty()); + btnRemoveAll.setEnabled(ctvSelCompLib.getTable().getItemCount() > 0); + } + }); } /* @@ -465,24 +560,32 @@ public class JSFLibraryConfigControl extends Composite { TreeViewer srcViewer, CheckboxTableViewer destViewer, boolean state) { - if (item != null && item.getFirstElement() != null) { - JSFProjectLibraryReference jsfLibDctr = (JSFProjectLibraryReference)item.getFirstElement(); - List list = workingCopyModel.getJSFComponentLibraries(); - Iterator it = list.iterator(); - JSFProjectLibraryReference crtjsfLibDctr = null; - while(it.hasNext()) { - crtjsfLibDctr = (JSFProjectLibraryReference)it.next(); - if (crtjsfLibDctr.getID().equals(jsfLibDctr.getID())) { - crtjsfLibDctr.setToBeDeployed(state); - crtjsfLibDctr.setSelected(state); - } - } + if (item != null && !item.isEmpty()) { + List selected = new ArrayList(item.size()); + for (Iterator sel=item.iterator();sel.hasNext();){ + JSFLibraryReference jsfLibDctr = (JSFLibraryReference)sel.next(); + selected.add(jsfLibDctr); + List list = workingCopyModel.getJSFComponentLibraries(); + Iterator it = list.iterator(); + JSFLibraryReference crtjsfLibDctr = null; + while(it.hasNext()) { + crtjsfLibDctr = (JSFLibraryReference)it.next(); + if (crtjsfLibDctr.getID().equals(jsfLibDctr.getID())) { + crtjsfLibDctr.setToBeDeployed(state); + crtjsfLibDctr.setSelected(state); + } + } + } loadJSFCompList(); srcViewer.refresh(); destViewer.refresh(); - destViewer.setChecked(jsfLibDctr, state); + for (Iterator it=selected.iterator();it.hasNext();){ + destViewer.setChecked(it.next(), state); + } + + setCompListModelProperty(); } } @@ -493,28 +596,56 @@ public class JSFLibraryConfigControl extends Composite { List list = workingCopyModel.getJSFComponentLibraries(); Iterator it = list.iterator(); - JSFProjectLibraryReference jsfLibDctr; + JSFLibraryReference jsfLibDctr; while(it.hasNext()) { - jsfLibDctr = (JSFProjectLibraryReference)it.next(); + jsfLibDctr = (JSFLibraryReference)it.next(); jsfLibDctr.setSelected(state); jsfLibDctr.setToBeDeployed(state); } loadJSFCompList(); - + srcViewer.refresh(); destViewer.refresh(); - destViewer.setAllChecked(state); + destViewer.setAllChecked(state); + + btnAddAll.setEnabled(! state); + btnRemoveAll.setEnabled(state); + + setCompListModelProperty(); + } + + //synchHelper is not able to track changes to data elements in tableviewer... manual set of property + private void setCompListModelProperty() { + TableItem[] tableItems = ctvSelCompLib.getTable().getItems(); + List compLibs = new ArrayList(tableItems.length); + for (int i=0;i<tableItems.length;i++){ + compLibs.add(tableItems[i].getData()); + } + JSFLibraryReference[] libs = (JSFLibraryReference[])compLibs.toArray(new JSFLibraryReference[0]); + model.setProperty(IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES, libs); } + + /** + * Configure the JSFLibraryConfigControl elements to used the containers synchHelper + * @param synchHelper + */ + public void setSynchHelper(DataModelSynchHelper synchHelper) { + model = synchHelper.getDataModel(); + synchHelper.synchCombo(cvImplLib.getCombo(), IJSFFacetInstallDataModelProperties.IMPLEMENTATION_LIBRARIES, null); + synchHelper.synchCheckbox(btnDeployJars, IJSFFacetInstallDataModelProperties.DEPLOY_IMPLEMENTATION, null); +// synchHelper.synchCheckBoxTableViewer(ctvSelCompLib, IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES, new Control[]{hiddenList}); + } + /** * Inner Classes for filtering. * */ class CheckedTableViewerFilter extends ViewerFilter { public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof JSFProjectLibraryReference) { - return ((JSFProjectLibraryReference)element).isSelected(); + if (element instanceof JSFLibraryReference) { + return ((JSFLibraryReference)element).isSelected(); } return false; } @@ -522,8 +653,8 @@ public class JSFLibraryConfigControl extends Composite { class TreeViewerFilter extends ViewerFilter { public boolean select(Viewer viewer, Object parentElement, Object element) { - if (element instanceof JSFProjectLibraryReference) { - return !((JSFProjectLibraryReference)element).isSelected(); + if (element instanceof JSFLibraryReference) { + return !((JSFLibraryReference)element).isSelected(); } return true; } @@ -532,7 +663,7 @@ public class JSFLibraryConfigControl extends Composite { class CompLibCTVContentProvider implements IStructuredContentProvider { private List jsfComplLibs = new ArrayList(0); - public Object[] getElements(Object inputElement) { + public Object[] getElements(Object inputElement) { return jsfComplLibs.toArray(); } public void dispose() { @@ -567,13 +698,13 @@ public class JSFLibraryConfigControl extends Composite { // Label Provider class SelectedCompLibCTVLabelProvider extends LabelProvider implements ITableLabelProvider { public String getColumnText(Object element, int columnIndex) { - if (element instanceof JSFProjectLibraryReference){ + if (element instanceof JSFLibraryReference){ switch(columnIndex) { case COLUMN_DEPLOY: return " "; //$NON-NLS-1$ case COLUMN_LIB_NAME: - return ((JSFProjectLibraryReference)element).getName(); + return ((JSFLibraryReference)element).getName(); } } return ""; //$NON-NLS-1$ @@ -587,9 +718,9 @@ public class JSFLibraryConfigControl extends Composite { private JSFLibrary defaultImpl = null; public String getText(Object element) { - if (element instanceof JSFProjectLibraryReference){ - StringBuffer nameBuf = new StringBuffer(((JSFProjectLibraryReference)element).getName()); - if ((((JSFProjectLibraryReference)element).getLibrary()).getID().equals(getDefaultImpl().getID())) + if (element instanceof JSFLibraryReference){ + StringBuffer nameBuf = new StringBuffer(((JSFLibraryReference)element).getName()); + if ((((JSFLibraryReference)element).getLibrary()).getID().equals(getDefaultImpl().getID())) nameBuf.append(" ").append(JSFLibraryRegistry.DEFAULT_IMPL_LABEL); //$NON-NLS-1$ return nameBuf.toString() ; } @@ -610,10 +741,10 @@ public class JSFLibraryConfigControl extends Composite { // Sorter class SelectedCompLibCTVSorter extends ViewerSorter { public int compare(Viewer viewer, Object e1, Object e2) { - if (e1 instanceof JSFProjectLibraryReference && - e2 instanceof JSFProjectLibraryReference) { - JSFProjectLibraryReference item1 = (JSFProjectLibraryReference)e1; - JSFProjectLibraryReference item2 = (JSFProjectLibraryReference)e2; + if (e1 instanceof JSFLibraryReference && + e2 instanceof JSFLibraryReference) { + JSFLibraryReference item1 = (JSFLibraryReference)e1; + JSFLibraryReference item2 = (JSFLibraryReference)e2; return item1.getName().compareToIgnoreCase(item2.getName()); } return 0; @@ -623,7 +754,7 @@ public class JSFLibraryConfigControl extends Composite { /* * Content provider Adapter for TreeViewer */ - private class TreeViewerAdapter implements ITreeContentProvider, ISelectionChangedListener, IDoubleClickListener { + private class TreeViewerAdapter implements ITreeContentProvider { private final Object[] NO_ELEMENTS= new Object[0]; // ------- ITreeContentProvider Interface ------------ @@ -645,8 +776,8 @@ public class JSFLibraryConfigControl extends Composite { } public Object[] getChildren(Object element) { - if (element instanceof JSFProjectLibraryReference) { - return ((JSFProjectLibraryReference)element).getArchiveFiles().toArray(); + if (element instanceof JSFLibraryReference) { + return ((JSFLibraryReference)element).getArchiveFiles().toArray(); } return NO_ELEMENTS; } @@ -656,24 +787,12 @@ public class JSFLibraryConfigControl extends Composite { } public boolean hasChildren(Object element) { - if (element instanceof JSFProjectLibraryReference) { + if (element instanceof JSFLibraryReference) { return true; } return false; } - - // ------- ISelectionChangedListener Interface ------------ - - public void selectionChanged(SelectionChangedEvent event) { - // do nothing; TODO: what's the point then? - } - /* (non-Javadoc) - * @see org.eclipse.jface.viewers.IDoubleClickListener#doubleClick(org.eclipse.jface.viewers.DoubleClickEvent) - */ - public void doubleClick(DoubleClickEvent event) { - // do nothing; TODO: what's the point then? - } } private class TreeLabelProvider implements ILabelProvider { @@ -692,7 +811,7 @@ public class JSFLibraryConfigControl extends Composite { } public Image getImage(Object element) { - if (element instanceof JSFProjectLibraryReference) + if (element instanceof JSFLibraryReference) { return libImg; } @@ -701,8 +820,8 @@ public class JSFLibraryConfigControl extends Composite { public String getText(Object element) { StringBuffer labelBuf = new StringBuffer(); - if (element instanceof JSFProjectLibraryReference) { - JSFProjectLibraryReference libWrapper = (JSFProjectLibraryReference)element; + if (element instanceof JSFLibraryReference) { + JSFLibraryReference libWrapper = (JSFLibraryReference)element; JSFLibrary lib = libWrapper.getLibrary(); labelBuf.append(lib.getName()); if (lib.isImplementation()) { diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeEvent.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeEvent.java new file mode 100644 index 000000000..58bd7b1ee --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeEvent.java @@ -0,0 +1,26 @@ +package org.eclipse.jst.jsf.ui.internal.jsflibraryconfig; + +import java.util.EventObject; + +/** + * Event that something has changed in the JSFLibraryConfigControl + * + */ +public class JSFLibraryConfigControlChangeEvent { + private EventObject event; + + /** + * Constructor + * @param java.util.EventObject + */ + public JSFLibraryConfigControlChangeEvent(EventObject ev){ + this.event = ev; + } + + /** + * @return java.util.EventObject + */ + public EventObject getEvent(){ + return event; + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeListener.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeListener.java new file mode 100644 index 000000000..5aa451474 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryConfigControlChangeListener.java @@ -0,0 +1,14 @@ +package org.eclipse.jst.jsf.ui.internal.jsflibraryconfig; + + +/** + * Interface to be implemented to listen to changes in the JSFLibraryConfigControl object + * + */ +public interface JSFLibraryConfigControlChangeListener { + /** + * Callback method + * @param JSFLibraryConfigControlChangeEvent + */ + public void changed(JSFLibraryConfigControlChangeEvent e); +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryPropertyPage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryPropertyPage.java deleted file mode 100644 index 13afc404a..000000000 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/jsflibraryconfig/JSFLibraryPropertyPage.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 Oracle Corporation. - * 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: - * Justin Chen - development check in - *******************************************************************************/ -package org.eclipse.jst.jsf.ui.internal.jsflibraryconfig; - -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.J2EEModuleDependencyDelegate; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigModel; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigProjectData; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfiglModelSource; -import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; -import org.eclipse.jst.jsf.ui.internal.Messages; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.dialogs.PropertyPage; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -/** - * @author Justin Chen - */ -public class JSFLibraryPropertyPage extends PropertyPage { - private static String JSF_FACET_ID = "jst.jsf"; //$NON-NLS-1$ - private JSFLibraryConfigControl jsfLibCfgControl; - private IProject project; - - /** - * Constructor for SamplePropertyPage. - */ - public JSFLibraryPropertyPage() { - super(); - super.noDefaultAndApplyButton(); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.PropertyPage#setElement(org.eclipse.core.runtime.IAdaptable) - */ - public void setElement(IAdaptable element) { - super.setElement(element); - project = (IProject) element.getAdapter(IResource.class); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#performOk() - */ - public boolean performOk() { - // Do nothing because of invalid settings. - if (!validatePage()) { - return true; - } - - JSFLibraryConfigModel model = jsfLibCfgControl.getWorkingModel(); - if (model != null) { - J2EEModuleDependencyDelegate dependencyUpdate = new J2EEModuleDependencyDelegate(project); - dependencyUpdate.updateProjectDependencies(model, new NullProgressMonitor()); - model.saveData(project); - } else { - // log an error message - } - - return true; - } - - /* - * (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite parent) { - //if (isJSFFacetInstalled()) { - return createForJSFProject(parent); - //} else { - // return createForNonJSFProject(parent); - //} - } - - private Control createForJSFProject(Composite parent) { - JSFLibraryConfiglModelSource model = new JSFLibraryConfigProjectData(project); - jsfLibCfgControl = new JSFLibraryConfigControl(parent, SWT.NULL); - jsfLibCfgControl.loadControlValuesFromModel(model); - - jsfLibCfgControl.addOkClickedListener(new IJSFImplLibraryCreationListener() { - public void okClicked(JSFImplLibraryCreationEvent event) { - validatePage(); - /*setValid(jsfLibCfgControl.getSelectedJSFLibImplementation() != null && - isJSFFacetInstalled()); - */ - } - }); - - validatePage(); - - return jsfLibCfgControl; - } - - protected boolean validatePage() { - if (!isJSFFacetInstalled() || jsfLibCfgControl.getSelectedJSFLibImplementation() == null) { - if (!isJSFFacetInstalled()) { - JSFLibraryPropertyPage.this.setErrorMessage(Messages.JSFLibraryPropertyPage_No_JSF_Facet_Installed); - } - if (jsfLibCfgControl.getSelectedJSFLibImplementation() == null) { - JSFLibraryPropertyPage.this.setErrorMessage(Messages.JSFLibraryPropertyPage_No_JSF_Implementation_Lib_Selected); - } - return false; - }/* else { - this.setMessage("Configurations are valid.", IMessageProvider.INFORMATION); - }*/ - return true; - } - - private boolean isJSFFacetInstalled() { - if (project == null) { - return false; - } - - try { - IFacetedProject fProject = ProjectFacetsManager.create(project); - - Iterator it = fProject.getProjectFacets().iterator(); - IProjectFacetVersion fv = null; - String facetId = null; - while (it.hasNext()) { - fv = ((IProjectFacetVersion)it.next()); - facetId = fv.getProjectFacet().getId(); - if (facetId.equals(JSF_FACET_ID)) { - return true; - } - } - - } catch (CoreException e) { - JSFUiPlugin.log(IStatus.ERROR, "Error creating faceted project", e); - } - return false; - - } - -} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/messages.properties b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/messages.properties index ccf57e9ef..5b9233d3b 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/messages.properties +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/messages.properties @@ -17,6 +17,7 @@ JSFFacetInstallPage_Add2=&Add... JSFFacetInstallPage_DeployJarsLabel=&Deploy jars to WEB-INF/lib JSFFacetInstallPage_JSFConfigLabel=JSF &Configuration File: JSFFacetInstallPage_JSFServletNameLabel=JSF &Servlet Name: +JSFFacetInstallPage_JSFServletClassNameLabel=JSF Servlet C&lassname: JSFFacetInstallPage_JSFURLMappingLabel=&URL Mapping Patterns: JSFFacetInstallPage_JSFLibraryLabel0=JSF Libraries: JSFFacetInstallPage_PatternDialogTitle=Specify URL Pattern @@ -33,18 +34,21 @@ JSFLibrariesPreferencePage_Remove=Remove JSFLibrariesPreferencePage_CannotRemovePluginProvidedTitle=Cannot Remove JSFLibrariesPreferencePage_CannotRemovePluginProvidedMessage=Plugin provided libraries cannot be removed from the registry JSFLibrariesPreferencePage_MakeDefault=Make Default -JSFLibrariesPreferencePage_Description=JSF Libraries contain jars with JSF components and tag libraries. Some JSF Libaries can be specially marked as implementations so that the WebApp can be executed. +JSFLibrariesPreferencePage_Description=JSF Libraries contain jars with JSF components and tag libraries. Some JSF Libraries can be specially marked as implementations so that the WebApp can be executed. JSFLibrariesPreferencePage_CannotModifyPluginProvidedTitle=Cannot Modify JSFLibraryPropertyPage_No_JSF_Implementation_Lib_Selected=No JSF implementation library selected. JSFLibrariesPreferencePage_CannotModifyPluginProvidedMessage=Plugin provided libraries cannot be edited JSFLibraryContainerWizardPage_PageName=Add JSF Library JSFLibraryContainerWizardPage_Title=JSF Library -JSFLibraryContainerWizardPage_Description=Select JavaServer Face Library to add to the classpath +JSFLibraryContainerWizardPage_Description=Select JavaServer Face Libraries to add to the classpath JSFLibraryContainerWizardPage_WarningNoJSFFacet=JavaServer Face Libraries can only be configured for Dynamic Web projects with the JSF facet installed. -JSFLibraryContainerWizardPage_JSFLibraries=JSF Libaries: +JSFLibraryContainerWizardPage_JSFLibraries=JSF Libraries: JSFLibraryContainerWizardPage_Add=Add... +JSFLibraryContainerWizardPage_Edit=Edit... +JSFLibraryContainerWizardPage_ImplAlreadyPresent=An implementation has already been chosen. Please remove before adding different one JSFLibraryContainerWizardPage_ErrorInitializing=Error during initialization +JSFLibraryContainerWizardPage_SelectOneImpl=Choose only one implementation JSFLibraryWizard_DESCRIPTION=Create a library of jars that make up a JSF component library. JSFLibraryWizard_IMPLS_ONLY_DESC=Create a library of jars that make up a JSF implementation library. diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/project/facet/JSFFacetInstallPage.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/project/facet/JSFFacetInstallPage.java index adf679b32..7ee88213e 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/project/facet/JSFFacetInstallPage.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/project/facet/JSFFacetInstallPage.java @@ -21,13 +21,14 @@ import org.eclipse.jface.dialogs.IInputValidator; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.window.Window; import org.eclipse.jst.j2ee.project.facet.IJ2EEModuleFacetInstallDataModelProperties; -import org.eclipse.jst.jsf.core.internal.JSFCorePlugin; import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigDialogSettingData; import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfiglModelSource; -import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFProjectLibraryReference; +import org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryReference; import org.eclipse.jst.jsf.core.internal.project.facet.IJSFFacetInstallDataModelProperties; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.jst.jsf.ui.internal.Messages; +import org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControlChangeEvent; +import org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControlChangeListener; import org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.IJSFImplLibraryCreationListener; import org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFImplLibraryCreationEvent; import org.eclipse.jst.jsf.ui.internal.jsflibraryconfig.JSFLibraryConfigControl; @@ -64,6 +65,8 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements private Text txtJSFConfig; private Label lblJSFServletName; private Text txtJSFServletName; + private Label lblJSFServletClassName; + private Text txtJSFServletClassName; private Label lblJSFServletURLPatterns; private List lstJSFServletURLPatterns; private Button btnAddPattern; @@ -75,6 +78,7 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements + ".jsfFacetInstall"; //$NON-NLS-1$ private static final String SETTINGS_CONFIG = "configPath"; //$NON-NLS-1$ private static final String SETTINGS_SERVLET = "servletName"; //$NON-NLS-1$ + private static final String SETTINGS_SERVLET_CLASSNAME = "servletClassname"; //$NON-NLS-1$ private static final String SETTINGS_URL_MAPPINGS = "urlMappings"; //$NON-NLS-1$ private static final String SETTINGS_URL_PATTERN = "pattern"; //$NON-NLS-1$ private static final String SETTINGS_DEPLOY_IMPL = "deployImplementation"; //$NON-NLS-1$ @@ -133,6 +137,13 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements } }); + jsfLibCfgComp.addChangeListener( new JSFLibraryConfigControlChangeListener(){ + + public void changed(JSFLibraryConfigControlChangeEvent e) { + validatePage(); + } + + }); GridData gd_comp = new GridData(GridData.FILL, GridData.FILL, true, true); gd_comp.horizontalSpan = 2; @@ -158,6 +169,16 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements gd2.horizontalSpan = 2; txtJSFServletName.setLayoutData(gd2); + lblJSFServletClassName = new Label(composite, SWT.NONE); + lblJSFServletClassName + .setText(Messages.JSFFacetInstallPage_JSFServletClassNameLabel); + lblJSFServletClassName.setLayoutData(new GridData(GridData.BEGINNING)); + + txtJSFServletClassName = new Text(composite, SWT.BORDER); + GridData gd2c = new GridData(GridData.FILL_HORIZONTAL); + gd2c.horizontalSpan = 2; + txtJSFServletClassName.setLayoutData(gd2c); + lblJSFServletURLPatterns = new Label(composite, SWT.NULL); lblJSFServletURLPatterns .setText(Messages.JSFFacetInstallPage_JSFURLMappingLabel); @@ -249,6 +270,15 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements } txtJSFServletName.setText(servletName); + String servletClassname = null; + if (root != null) + servletClassname = root.get(SETTINGS_SERVLET_CLASSNAME); + if (servletClassname == null || servletClassname.equals("")) { //$NON-NLS-1$ + servletClassname = (String) model + .getDefaultProperty(IJSFFacetInstallDataModelProperties.SERVLET_CLASSNAME); + } + txtJSFServletClassName.setText(servletClassname); + loadURLMappingPatterns(root); } @@ -278,6 +308,7 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements jsfLibCfgComp.loadControlValuesFromModel(source); } + private void saveSettings() { DialogSettings root = new DialogSettings(SETTINGS_ROOT); dialogSettings.addSection(root); @@ -285,6 +316,7 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements root.put(SETTINGS_DEPLOY_IMPL, String.valueOf(getDeployJSFImpl())); root.put(SETTINGS_CONFIG, getJSFConfig()); root.put(SETTINGS_SERVLET, getJSFServletName()); + root.put(SETTINGS_SERVLET_CLASSNAME, getJSFServletClassname()); DialogSettings mappings = new DialogSettings(SETTINGS_URL_MAPPINGS); root.addSection(mappings); mappings.put(SETTINGS_URL_PATTERN, getJSFPatterns()); @@ -310,6 +342,10 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements return txtJSFServletName.getText().trim(); } + private String getJSFServletClassname() { + return txtJSFServletClassName.getText().trim(); + } + private String[] getJSFPatterns() { return lstJSFServletURLPatterns.getItems(); } @@ -319,14 +355,14 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements * Iterate thru the selected component libraries and return selected * component libraries and their deployment flags in a string array. */ - JSFProjectLibraryReference complib = null; + JSFLibraryReference complib = null; String str = null; ArrayList al = new ArrayList(); java.util.List list = jsfLibCfgComp.getSelectedJSFLibComponents(); Iterator it = list.iterator(); while (it.hasNext()) { - complib = (JSFProjectLibraryReference) it.next(); + complib = (JSFLibraryReference) it.next(); str = complib.getID() + SEPARATOR + complib.isCheckedToBeDeployed(); al.add(str); } @@ -359,41 +395,36 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements // do nothing else now. being handled by synchHelper // config.setProperty(IJSFFacetInstallDataModelProperties.IMPLEMENTATION, // getJSFImpl()); - model - .setStringProperty( - IJSFFacetInstallDataModelProperties.CONFIG_PATH, - getJSFConfig()); - model.setStringProperty( - IJSFFacetInstallDataModelProperties.SERVLET_NAME, - getJSFServletName()); +// model +// .setStringProperty( +// IJSFFacetInstallDataModelProperties.CONFIG_PATH, +// getJSFConfig()); +// model.setStringProperty( +// IJSFFacetInstallDataModelProperties.SERVLET_NAME, +// getJSFServletName()); // config.setProperty(IJSFFacetInstallDataModelProperties.SERVLET_URL_PATTERNS, // getJSFPatterns()); - java.util.List implLibs = new ArrayList(); - implLibs.add(jsfLibCfgComp.getSelectedJSFLibImplementation()); - java.util.List compLibs = jsfLibCfgComp.getSelectedJSFLibComponents(); - model.setProperty( - IJSFFacetInstallDataModelProperties.IMPLEMENTATION_LIBRARIES, - implLibs); - model.setProperty( - IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES, - compLibs); +// java.util.List implLibs = new ArrayList(); +// implLibs.add(jsfLibCfgComp.getSelectedJSFLibImplementation()); +// java.util.List compLibs = jsfLibCfgComp.getSelectedJSFLibComponents(); +// model.setProperty( +// IJSFFacetInstallDataModelProperties.IMPLEMENTATION_LIBRARIES, +// implLibs); +// model.setProperty( +// IJSFFacetInstallDataModelProperties.COMPONENT_LIBRARIES, +// compLibs); } private void addModificationListeners() { - // 119330 - enhancement request for ComboViewer support. Manually update - // model for now - // addJSFImplComboListeners(); - // synchHelper.synchComboViewer(cboJSFImplViewer, IMPLEMENTATION, null); - // synchHelper.synchText(txtJSFConfig, CONFIG_PATH, null); - // synchHelper.synchText(txtJSFServletName, SERVLET_NAME, null); + jsfLibCfgComp.setSynchHelper(synchHelper); + synchHelper.synchText(txtJSFConfig, CONFIG_PATH, null); + synchHelper.synchText(txtJSFServletName, SERVLET_NAME, null); + synchHelper.synchText(txtJSFServletClassName, SERVLET_CLASSNAME, null); + synchHelper.synchList(lstJSFServletURLPatterns, SERVLET_URL_PATTERNS, null); + // synchHelper.synchCheckbox(chkDeployImpl, DEPLOY_IMPLEMENTATION, // null); - // Until 119321 is fixed, need to comment out below and handle model - // updates 'manually'. - // This is being done on Add and Remove, currently - // synchHelper.synchList(lstJSFServletURLPatterns, SERVLET_URL_PATTERNS, - // null); } private String isValidPattern(String value) { @@ -447,11 +478,17 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements lstJSFServletURLPatterns.getItems()); } + /* (non-Javadoc) + * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#getValidationPropertyNames() + */ protected String[] getValidationPropertyNames() { return new String[] { IMPLEMENTATION, DEPLOY_IMPLEMENTATION, - CONFIG_PATH, SERVLET_NAME }; + CONFIG_PATH, SERVLET_NAME, SERVLET_CLASSNAME, COMPONENT_LIBRARIES }; } + /* (non-Javadoc) + * @see org.eclipse.wst.common.project.facet.ui.IFacetWizardPage#setWizardContext(org.eclipse.wst.common.project.facet.ui.IWizardContext) + */ public void setWizardContext(IWizardContext context) { // hook into web datamodel if new project wizard. Iterator it = context.getSelectedProjectFacets().iterator(); @@ -479,6 +516,9 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements } } + /* (non-Javadoc) + * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#propertyChanged(org.eclipse.wst.common.frameworks.datamodel.DataModelEvent) + */ public void propertyChanged(DataModelEvent event) { if (webAppDataModel != null) { String propertyName = event.getPropertyName(); @@ -491,12 +531,20 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements super.propertyChanged(event); } + /* (non-Javadoc) + * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#dispose() + */ public void dispose() { if (webAppDataModel != null) webAppDataModel.removeListener(this); + + jsfLibCfgComp.dispose(); super.dispose(); } + /* (non-Javadoc) + * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#restoreDefaultSettings() + */ protected void restoreDefaultSettings() { initializeValues(); @@ -515,4 +563,12 @@ public class JSFFacetInstallPage extends DataModelWizardPage implements setPageComplete(enableFinish); } + /* (non-Javadoc) + * @see org.eclipse.wst.common.frameworks.internal.datamodel.ui.DataModelWizardPage#showValidationErrorsOnEnter() + */ + protected boolean showValidationErrorsOnEnter() { + return true; + } + + } |