diff options
author | cbateman | 2007-04-17 23:59:31 +0000 |
---|---|---|
committer | cbateman | 2007-04-17 23:59:31 +0000 |
commit | 9b4ce3f7c3e42e43bd77fea30a2233d0f8547490 (patch) | |
tree | 4ab20b67e1716344b81b46040670e605e3b5315b | |
parent | 7ca3d7a542f10247024711bec2797d2311cfc19b (diff) | |
download | webtools.jsf-9b4ce3f7c3e42e43bd77fea30a2233d0f8547490.tar.gz webtools.jsf-9b4ce3f7c3e42e43bd77fea30a2233d0f8547490.tar.xz webtools.jsf-9b4ce3f7c3e42e43bd77fea30a2233d0f8547490.zip |
Final fix for JSF Library Registry migration issue. Instead of a blanket startup dialog, the user is only prompted when affecting the backward compatibility of individual projects.
11 files changed, 739 insertions, 162 deletions
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 aa5c5b1a3..e4d3a9cd4 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 @@ -58,11 +58,6 @@ public class JSFCorePlugin extends WTPPlugin { */ public static final String PLUGIN_ID = "org.eclipse.jst.jsf.core";//org.eclipse.jst.jsf.core.internal.JSFCorePlugin"; //$NON-NLS-1$ - /** - * The JSF facet identifier - */ - public static final String FACET_ID = "jst.jsf"; //$NON-NLS-1$ - // The shared instance. private static JSFCorePlugin plugin; diff --git a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/RegistryMigrationStartupHandler.java b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/RegistryMigrationStartupHandler.java index 1c37d071b..db22b2603 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/RegistryMigrationStartupHandler.java +++ b/jsf/plugins/org.eclipse.jst.jsf.core/src/org/eclipse/jst/jsf/core/internal/RegistryMigrationStartupHandler.java @@ -5,11 +5,8 @@ import java.net.URL; import org.eclipse.core.runtime.IStatus; import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.util.JSFLibraryRegistryUpgradeUtil; import org.eclipse.jst.jsf.core.internal.jsflibraryregistry.util.UpgradeStatus; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IStartup; import org.eclipse.ui.PartInitException; @@ -74,21 +71,8 @@ public class RegistryMigrationStartupHandler implements IStartup public void run() { - final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - MessageDialogWithToggle dialog = - new ConfirmDialog(shell, Messages.JSFRegistryMigration05_to_10_title, Messages.JSFRegistryMigration05_to_10_customMessage); - int result = dialog.open(); - - switch(result) - { - case ConfirmDialog.CONFIRMED: - doConfirmed(dialog.getToggleState()); - break; - - default: - // all other cases than explicit proceed, abort and exit - doAbortAndExit(); - } + // no prompting necessary. just commit. + doConfirmed(false); } private void doConfirmed(boolean userWantsMigrationDocLaunch) { @@ -115,62 +99,62 @@ public class RegistryMigrationStartupHandler implements IStartup } } - private void doAbortAndExit() - { - // rollback - IStatus result = _status.rollback(); - - if (result.getSeverity() != IStatus.OK) - { - final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - MessageDialog.openError(shell, Messages.RegistryMigrationStartupHandler_Error_Rolling_Back_Migration, result.getMessage()); - } - // close workbench - PlatformUI.getWorkbench().close(); - } - } - - private static class ConfirmDialog extends MessageDialogWithToggle - { - final static int CONFIRMED = 0; - final static int ABORT_AND_EXIT = 1; - - /** - * @param parentShell - * @param dialogTitle - * @param dialogMessage - */ - public ConfirmDialog(Shell parentShell, String dialogTitle, - String dialogMessage) { - super(parentShell - , dialogTitle - , null - , dialogMessage - , WARNING - , new String[] { Messages.RegistryMigrationStartupHandler_Dialog_Confirm_Migration, Messages.RegistryMigrationStartupHandler_Dialog_Abort_And_Exit_Migration } - , ABORT_AND_EXIT - , Messages.RegistryMigrationStartupHandler_Launch_Migration_Doc_On_Confirm, true); - } - - /** - * Override so that the button ids line up with the constants - * expected - * @param parent - */ - protected void createButtonsForButtonBar(Composite parent) { - final String[] buttonLabels = getButtonLabels(); - final Button[] buttons = new Button[buttonLabels.length]; - final int defaultButtonIndex = getDefaultButtonIndex(); - - for (int i = 0; i < buttonLabels.length; i++) { - String label = buttonLabels[i]; - Button button = createButton(parent, i, label, - defaultButtonIndex == i); - buttons[i] = button; - - } - setButtons(buttons); - } - +// private void doAbortAndExit() +// { +// // rollback +// IStatus result = _status.rollback(); +// +// if (result.getSeverity() != IStatus.OK) +// { +// final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); +// MessageDialog.openError(shell, Messages.RegistryMigrationStartupHandler_Error_Rolling_Back_Migration, result.getMessage()); +// } +// // close workbench +// PlatformUI.getWorkbench().close(); +// } +// } +// +// private static class ConfirmDialog extends MessageDialogWithToggle +// { +// final static int CONFIRMED = 0; +// final static int ABORT_AND_EXIT = 1; +// +// /** +// * @param parentShell +// * @param dialogTitle +// * @param dialogMessage +// */ +// public ConfirmDialog(Shell parentShell, String dialogTitle, +// String dialogMessage) { +// super(parentShell +// , dialogTitle +// , null +// , dialogMessage +// , WARNING +// , new String[] { Messages.RegistryMigrationStartupHandler_Dialog_Confirm_Migration, Messages.RegistryMigrationStartupHandler_Dialog_Abort_And_Exit_Migration } +// , ABORT_AND_EXIT +// , Messages.RegistryMigrationStartupHandler_Launch_Migration_Doc_On_Confirm, true); +// } +// +// /** +// * Override so that the button ids line up with the constants +// * expected +// * @param parent +// */ +// protected void createButtonsForButtonBar(Composite parent) { +// final String[] buttonLabels = getButtonLabels(); +// final Button[] buttons = new Button[buttonLabels.length]; +// final int defaultButtonIndex = getDefaultButtonIndex(); +// +// for (int i = 0; i < buttonLabels.length; i++) { +// String label = buttonLabels[i]; +// Button button = createButton(parent, i, label, +// defaultButtonIndex == i); +// buttons[i] = button; +// +// } +// setButtons(buttons); +// } +// } } 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 b7ac0d46d..cee3cff2d 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 @@ -30,7 +30,7 @@ import org.eclipse.osgi.util.NLS; * @author Justin Chen - Oracle */ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource { - final static private String QUALIFIEDNAME = "org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigProjectData"; + final static String QUALIFIEDNAME = "org.eclipse.jst.jsf.core.internal.jsflibraryconfig.JSFLibraryConfigProjectData"; /** * Parsing delimnitor for elements in a tuple. */ @@ -247,8 +247,11 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource * To Do: Take out selected attribute since it is not needed. * Add the library name as an attribute. * Provide code path to migrate earlier project. + * + * NOTE: this class should no longer be used except to support + * legacy (pre-2.0M6 library registries) */ - private static class Tuple { + static class Tuple { final private String id; final private boolean selected; final private boolean deploy; @@ -261,9 +264,17 @@ public class JSFLibraryConfigProjectData implements JSFLibraryConfiglModelSource // parse tuple = ID:selected:deploy Tuple(String tuple) { String[] fields = tuple.split(JSFLibraryConfigProjectData.SPTR_TUPLE); - this.id = fields[0]; - this.selected = Boolean.valueOf(fields[1]).booleanValue(); - this.deploy = Boolean.valueOf(fields[2]).booleanValue(); + + if (fields.length >= 3) + { + this.id = fields[0]; + this.selected = Boolean.valueOf(fields[1]).booleanValue(); + this.deploy = Boolean.valueOf(fields[2]).booleanValue(); + } + else + { + throw new IllegalStateException("Library registry is corrupt"); + } } String getID() { 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 f5e271293..f57c46ebc 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,11 +13,14 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +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.core.runtime.QualifiedName; import org.eclipse.emf.common.util.EList; import org.eclipse.jdt.core.IClasspathContainer; import org.eclipse.jdt.core.IClasspathEntry; @@ -30,6 +33,7 @@ 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; +import org.eclipse.jst.jsf.core.internal.project.facet.JSFUtils; /** * A singleton maintains lists of implementation and component libraries @@ -368,4 +372,48 @@ public class JSFLibraryRegistryUtil { JSFCorePlugin.log(e, "Unable to set classpath for: "+project.getProject().getName()); } } + + /** + * @param iproject + * @return true if iproject has persistent properties indicating that it may still + * be using V1 JSF Library references + */ + public static boolean doesProjectHaveV1JSFLibraries(IProject iproject) + { + try + { + Object compLib = iproject.getPersistentProperty(new QualifiedName(JSFLibraryConfigProjectData.QUALIFIEDNAME, JSFUtils.PP_JSF_COMPONENT_LIBRARIES)); + Object implLib = iproject.getPersistentProperty(new QualifiedName(JSFLibraryConfigProjectData.QUALIFIEDNAME, JSFUtils.PP_JSF_IMPLEMENTATION_LIBRARIES)); + + if (compLib != null || implLib != null) + { + return true; + } + return false; + } + catch(CoreException ce) + { + JSFCorePlugin.log(ce, "Error checking age of project"); + return false; + } + } + + /** + * Removes the persistent property from JSF projects tagged with + * V1 JSF libraries. + * @param projects + */ + public static void removeV1JSFLibraryProperty(List<IProject> projects) + { + for (final Iterator<IProject> it = projects.iterator(); it.hasNext();) + { + IProject project = it.next(); + try { + project.setPersistentProperty(new QualifiedName(JSFLibraryConfigProjectData.QUALIFIEDNAME, JSFUtils.PP_JSF_COMPONENT_LIBRARIES), null); + project.setPersistentProperty(new QualifiedName(JSFLibraryConfigProjectData.QUALIFIEDNAME, JSFUtils.PP_JSF_IMPLEMENTATION_LIBRARIES), null); + } catch (CoreException e) { + JSFCorePlugin.log(e, "Error removing JSF library persistent property"); + } + } + } } 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 a3bc764a6..830979cef 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 @@ -21,91 +21,304 @@ import org.eclipse.osgi.util.NLS; public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.jst.jsf.ui.internal.messages"; //$NON-NLS-1$ + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFLibraryLabel0; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_title; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_description; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFImplLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_Add1; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_Add2; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_DeployJarsLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFConfigLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFServletNameLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFServletClassNameLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_JSFURLMappingLabel; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_PatternDialogTitle; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_PatternDialogDesc; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_Remove; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_PatternEmptyMsg; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_PatternSpecifiedMsg; + /** + * see messages.properties + */ public static String JSFFacetInstallPage_ErrorNoWebAppDataModel; - + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_DefinedJSFLibraries; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_New; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_Edit; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_Remove; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_CannotRemovePluginProvidedTitle; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_CannotRemovePluginProvidedMessage; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_MakeDefault; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_Description; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_CannotModifyPluginProvidedTitle; + /** + * see messages.properties + */ public static String JSFLibrariesPreferencePage_CannotModifyPluginProvidedMessage; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_Add; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_AddAll; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_ComponentLibrary; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_DeployJAR; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_ImplementationLibrary; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_NewComponentLibrary; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_NewImplementationLibrary; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_NullProject; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_Remove; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_RemoveAll; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_TH_Deploy; - + /** + * see messages.properties + */ public static String JSFLibraryConfigControl_TH_LibraryName; + + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_PageName; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_Title; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_Description; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_WarningNoJSFFacet; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_JSFLibraries; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_Add; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_Edit; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_ErrorInitializing; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_ImplAlreadyPresent; + /** + * see messages.properties + */ public static String JSFLibraryContainerWizardPage_SelectOneImpl; - + /** + * see messages.properties + */ + public static String JSFLibraryContainerWizardPage_V1Registry_Warning_DialogTitle; + /** + * see messages.properties + */ + public static String JSFLibraryContainerWizardPage_V1Registry_Warning_DialogText; + /** + * see messages.properties + */ + public static String JSFLibraryContainerWizardPage_EditLibrary_DescriptionText; + /** + * see messages.properties + */ public static String JSFLibraryPropertyPage_No_JSF_Facet_Installed; - + /** + * see messages.properties + */ public static String JSFLibraryPropertyPage_No_JSF_Implementation_Lib_Selected; - + /** + * see messages.properties + */ public static String JSFLibraryWizard_DESCRIPTION; + /** + * see messages.properties + */ public static String JSFLibraryWizard_IMPLS_ONLY_DESC; + /** + * see messages.properties + */ public static String JSFLibraryWizard_CreateImplementation; + /** + * see messages.properties + */ public static String JSFLibraryWizard_CreateJSFLibrary; + /** + * see messages.properties + */ public static String JSFLibraryWizard_EditJSFLibrary; + /** + * see messages.properties + */ public static String JSFLibraryWizard_JSFLibrary; + /** + * see messages.properties + */ + public static String JSFLibraryWizard_JSFLibraryWizard_DontShowThisAgain_CheckBoxLabel; + /** + * see messages.properties + */ public static String JSFLibraryWizard_LibraryName; + /** + * see messages.properties + */ + public static String JSFLibraryWizard_V1JSFLibrary_DialogMessage; + /** + * see messages.properties + */ + public static String JSFLibraryWizard_V1JSFLibrary_DialogTitle; + /** + * see messages.properties + */ public static String JSFLibraryWizard_VersionSupported; + /** + * see messages.properties + */ public static String JSFLibraryWizard_LibraryJars; + /** + * see messages.properties + */ public static String JSFLibraryWizard_IsJSFImplementation; + /** + * see messages.properties + */ public static String JSFLibraryWizard_DeployJars; + /** + * see messages.properties + */ public static String JSFLibraryWizard_Add; + /** + * see messages.properties + */ public static String JSFLibraryWizard_Remove; + /** + * see messages.properties + */ public static String JSFLibraryWizard_ExtJarFileDialogTitle; + /** + * see messages.properties + */ public static String JSFLibraryWizard_ValidateNoJars; + /** + * see messages.properties + */ public static String JSFLibraryWizard_ValidateNoLibraryName; + /** + * see messages.properties + */ public static String JSFLibraryWizard_ValidateExistingLibraryName; /** 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 0bb83ae75..512e8e65a 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 @@ -12,14 +12,14 @@ package org.eclipse.jst.jsf.ui.internal.classpath; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; 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.resources.IProject; 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; @@ -51,6 +51,7 @@ 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.core.jsfappconfig.JSFAppConfigUtils; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.jst.jsf.ui.internal.Messages; import org.eclipse.swt.SWT; @@ -66,11 +67,6 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchWizard; import org.eclipse.ui.PlatformUI; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.internal.FacetedProjectNature; /** * Provides a classpath container wizard page for JSF Libraries. @@ -88,7 +84,10 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements private IClasspathEntry containerEntry; private IClasspathEntry[] currentEntries; private Map _currentLibs; - private JSFLibrary currentLib; + private JSFLibrary currentLib; + + private boolean _projectHaveV1JSFLibraries; // = false; + private IProject _iproject; /** * Zero arg constructor @@ -104,31 +103,15 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements /* (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; + public void initialize(IJavaProject project, IClasspathEntry[] currentEntries_) { this.currentEntries = currentEntries_; - try { - //check for faceted nature - //NOTE: use of following constant produces warnings; this was known - //but at time of writing no public API was available - if (project.getProject().hasNature(FacetedProjectNature.NATURE_ID)){ - //check for jsf facet - IFacetedProject fproj = ProjectFacetsManager.create(project.getProject()); - Iterator it = fproj.getProjectFacets().iterator(); - while (it.hasNext()){ - IProjectFacetVersion facetVersion = (IProjectFacetVersion)it.next(); - IProjectFacet facet = facetVersion.getProjectFacet(); - if (facet.getId().equals(JSFCorePlugin.FACET_ID)){ - isJSFProject = true; - return; - } - } - } - } catch (CoreException e) { - JSFUiPlugin.log( - IStatus.ERROR, - Messages.JSFLibraryContainerWizardPage_ErrorInitializing, - e); + + _iproject = project.getProject(); + this.isJSFProject = JSFAppConfigUtils.isValidJSFProject(_iproject); + if (this.isJSFProject) + { + _projectHaveV1JSFLibraries = + JSFLibraryRegistryUtil.doesProjectHaveV1JSFLibraries(_iproject); } } @@ -136,7 +119,22 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPage#finish() */ public boolean finish() { - return true; + boolean finish = true; + if (_projectHaveV1JSFLibraries) + { + // if the user doesn't want to confirm, back off on the change + // and let them decide if they want to hit cancel + finish = WarningMessageDialog. + openConfirm(getShell() + , Messages.JSFLibraryContainerWizardPage_V1Registry_Warning_DialogTitle + , Messages.JSFLibraryContainerWizardPage_V1Registry_Warning_DialogText); + + if (finish) + { + JSFLibraryRegistryUtil.removeV1JSFLibraryProperty(Collections.singletonList(_iproject)); + } + } + return finish; } /* (non-Javadoc) @@ -314,7 +312,7 @@ public class JSFLibraryContainerWizardPage extends WizardPage implements 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."); + setDescription(Messages.JSFLibraryContainerWizardPage_EditLibrary_DescriptionText); } else { lv.setInput(getAllJSFLibraries()); 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 20c5e356a..90033b154 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,8 +10,17 @@ *******************************************************************************/ package org.eclipse.jst.jsf.ui.internal.classpath; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IStatus; import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.Wizard; import org.eclipse.jface.wizard.WizardPage; @@ -46,7 +55,7 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { */ public static int NONIMPLS = 2; - private JSFLibraryEditControl c; + private JSFLibraryEditControl jsfLibraryEditControl; private boolean isNew = false; private boolean modified = false; @@ -62,6 +71,8 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { private boolean _impls; private boolean _nonimpls; + private List<IProject> _projectsWithV1JSFLibraries = new ArrayList<IProject>(); + /** * Constructor * see IMPLS @@ -102,7 +113,10 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { /* (non-Javadoc) * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) */ - public void init(IWorkbench workbench, IStructuredSelection selection) { + public void init(IWorkbench workbench, IStructuredSelection selection) + { + initV1LibrariesList(); + if (selection != null && selection.getFirstElement() instanceof JSFLibrary) { curLibrary = (JSFLibrary) selection.getFirstElement(); @@ -118,6 +132,22 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { } } + private void initV1LibrariesList() + { + final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); + + // loop through the workspace and look for projects that are still using the V1 way + // of doing JSF libraries + for (int i = 0; i < projects.length; i++) + { + final IProject project = projects[i]; + if (JSFLibraryRegistryUtil.doesProjectHaveV1JSFLibraries(project)) + { + _projectsWithV1JSFLibraries.add(project); + } + } + } + /** * Updates the JSF Library instance with the values from the working copy and * persists the registry. @@ -126,11 +156,48 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { * * @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(); + public boolean performFinish() + { + // on init, if we detected any projects with old library + // refs, we need to warn the user + if (!isNew && // can ignore new libraries, since old projects can't possibly have dependencies on them + _projectsWithV1JSFLibraries.size() > 0) + { + String projectNames = ""; //$NON-NLS-1$ + for (Iterator<IProject> it = _projectsWithV1JSFLibraries.iterator(); it.hasNext();) + { + IProject project = it.next(); + projectNames += project.getName() + ","; //$NON-NLS-1$ + } + // trim trailing comma + if (projectNames.length() > 0) + { + projectNames = projectNames.substring(0, projectNames.length()-1); + } + + final String messageText = MessageFormat.format(Messages.JSFLibraryWizard_V1JSFLibrary_DialogMessage, + new Object[] {projectNames}); + MessageDialogWithToggle dialog = + WarningMessageDialogWithToggle.openOkCancelConfirm + (getShell(), Messages.JSFLibraryWizard_V1JSFLibrary_DialogTitle, messageText, Messages.JSFLibraryWizard_JSFLibraryWizard_DontShowThisAgain_CheckBoxLabel, false, null, null); + if (dialog.getReturnCode() != IDialogConstants.OK_ID) + { + // abort if the user doesn't really want to commit this change + return false; + } + + // if user accepted and asked not be warned again, clear the + // the project properties. + if (dialog.getToggleState()) + { + JSFLibraryRegistryUtil.removeV1JSFLibraryProperty(_projectsWithV1JSFLibraries); + } + } + + final String name = jsfLibraryEditControl.getJSFLibraryName(); + final boolean isDeployed = jsfLibraryEditControl.getIsDeployed(); + final boolean isImplementation = jsfLibraryEditControl.getIsImplementation(); + final JSFVersion version = jsfLibraryEditControl.getJSFVersion(); workingCopyLibrary.setName(name); workingCopyLibrary.setDeployed(isDeployed); @@ -147,7 +214,7 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { try { JSFLibraryRegistryUtil.rebindClasspathContainerEntries(originalID, workingCopyLibrary.getID(), false, null); } catch (JavaModelException e) { - JSFUiPlugin.log(IStatus.ERROR, "Exception while updating JSF Library containers", e); + JSFUiPlugin.log(IStatus.ERROR, "Exception while updating JSF Library containers", e); //$NON-NLS-1$ } } JSFCorePlugin.getDefault().saveJSFLibraryRegistry(); @@ -197,13 +264,13 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { public void createControl(Composite parent) { initializeDialogUnits(parent); - c = new JSFLibraryEditControl(workingCopyLibrary, parent); - c.setImplOnly(isImplsOnly()); - c.setNonImplOnly(isNonImplsOnly()); - c.setLayout(new GridLayout(2, false)); - c.setLayoutData(new GridData(GridData.FILL_BOTH)); + jsfLibraryEditControl = new JSFLibraryEditControl(workingCopyLibrary, parent); + jsfLibraryEditControl.setImplOnly(isImplsOnly()); + jsfLibraryEditControl.setNonImplOnly(isNonImplsOnly()); + jsfLibraryEditControl.setLayout(new GridLayout(2, false)); + jsfLibraryEditControl.setLayoutData(new GridData(GridData.FILL_BOTH)); - c.addValidationListener(new JSFLibraryValidationListener(){ + jsfLibraryEditControl.addValidationListener(new JSFLibraryValidationListener(){ public void notifyValidation(JSFLibraryValidationEvent e) { setErrorMessage(e.getMessage()); modified = true; @@ -211,7 +278,7 @@ public class JSFLibraryWizard extends Wizard implements INewWizard { } }); - setControl(c); + setControl(jsfLibraryEditControl); setPageComplete(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 index c84f07581..ca26df812 100644 --- 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 @@ -33,7 +33,7 @@ public class JSFLibraryWizardPage extends WizardPage { * Constructor */ public JSFLibraryWizardPage(){ - super("JSFLibrary"); + super("JSFLibrary"); } /** @@ -80,15 +80,4 @@ public class JSFLibraryWizardPage extends WizardPage { setControl(editControl); setPageComplete(false); } - - - /** - * @return true if can finish - */ - public boolean finish() { - // TODO: dead? - return true; - } - - } diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java new file mode 100644 index 000000000..d7a4157f5 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialog.java @@ -0,0 +1,127 @@ +package org.eclipse.jst.jsf.ui.internal.classpath; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * Customized warning dialog for JSF Library Upgrade warnings. + * + * @author cbateman + * + */ +class WarningMessageDialog extends MessageDialog +{ + private Text _messageLabel; + + /** + * @param parent + * @param title + * @param message + * @return true if the user hit OK + * + * Overriden to set the default button to CANCEL and use this dialog. + */ + public static boolean openConfirm(Shell parent, String title, String message) { + MessageDialog dialog = new WarningMessageDialog(parent, title, null, // accept + // the + // default + // window + // icon + message, QUESTION, new String[] { IDialogConstants.OK_LABEL, + IDialogConstants.CANCEL_LABEL }, 1); // CANCEL is the + // default + return dialog.open() == 0; + } + + WarningMessageDialog(Shell parentShell, String dialogTitle, + Image dialogTitleImage, String dialogMessage, int dialogImageType, + String[] dialogButtonLabels, int defaultIndex) { + super(parentShell, dialogTitle, dialogTitleImage, dialogMessage, + dialogImageType, dialogButtonLabels, defaultIndex); + } + + @Override + protected Control createMessageArea(Composite composite) + { + // create composite + // create image + Image image = getImage(); + if (image != null) { + imageLabel = new Label(composite, SWT.NULL); + image.setBackground(imageLabel.getBackground()); + imageLabel.setImage(image); + addAccessibleListeners(imageLabel, image); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING) + .applyTo(imageLabel); + } + // create message + if (message != null) { + _messageLabel = new Text(composite, getMessageLabelStyle()|SWT.READ_ONLY); + _messageLabel.setText(message); + GridDataFactory + .fillDefaults() + .align(SWT.FILL, SWT.BEGINNING) + .grab(true, false) + .hint( + convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), + SWT.DEFAULT).applyTo(_messageLabel); + } + return composite; + } + + /** + * NOTE: copied from IconAndMessageDialog + * Add an accessible listener to the label if it can be inferred from the + * image. + * + * @param label + * @param image + */ + private void addAccessibleListeners(Label label, final Image image) { + label.getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getName(AccessibleEvent event) { + final String accessibleMessage = getAccessibleMessageFor(image); + if (accessibleMessage == null) { + return; + } + event.result = accessibleMessage; + } + }); + } + + /** + * NOTE: copied from IconAndMessageDialog + * @param image + * @return an accesible string + */ + private String getAccessibleMessageFor(Image image) { + if (image.equals(getErrorImage())) { + return JFaceResources.getString("error");//$NON-NLS-1$ + } + + if (image.equals(getWarningImage())) { + return JFaceResources.getString("warning");//$NON-NLS-1$ + } + + if (image.equals(getInfoImage())) { + return JFaceResources.getString("info");//$NON-NLS-1$ + } + + if (image.equals(getQuestionImage())) { + return JFaceResources.getString("question"); //$NON-NLS-1$ + } + + return null; + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java new file mode 100644 index 000000000..6bc94b62f --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/classpath/WarningMessageDialogWithToggle.java @@ -0,0 +1,134 @@ +package org.eclipse.jst.jsf.ui.internal.classpath; + +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.SWT; +import org.eclipse.swt.accessibility.AccessibleAdapter; +import org.eclipse.swt.accessibility.AccessibleEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * Customized warning dialog for JSF Library Upgrade warnings. + * + * @author cbateman + * + */ +class WarningMessageDialogWithToggle extends MessageDialogWithToggle +{ + private Text _messageLabel; + + /** + * @param parent + * @param title + * @param message + * @param toggleMessage + * @param toggleState + * @param store + * @param key + * @return the dialog. + * + * Overriden to make default button CANCEL and use this dialog + */ + public static MessageDialogWithToggle openOkCancelConfirm(Shell parent, + String title, String message, String toggleMessage, + boolean toggleState, IPreferenceStore store, String key) { + MessageDialogWithToggle dialog = new WarningMessageDialogWithToggle(parent, + title, null, // accept the default window icon + message, QUESTION, new String[] { IDialogConstants.OK_LABEL, + IDialogConstants.CANCEL_LABEL }, 1, // CANCEL is the default + toggleMessage, toggleState); + dialog.open(); + return dialog; + } + + WarningMessageDialogWithToggle(Shell parentShell, String dialogTitle, + Image image, String message, int dialogImageType, + String[] dialogButtonLabels, int defaultIndex, + String toggleMessage, boolean toggleState) { + super(parentShell, dialogTitle, image, message, dialogImageType, + dialogButtonLabels, defaultIndex, toggleMessage, toggleState); + } + + @Override + protected Control createMessageArea(Composite composite) + { + // create composite + // create image + Image image = getImage(); + if (image != null) { + imageLabel = new Label(composite, SWT.NULL); + image.setBackground(imageLabel.getBackground()); + imageLabel.setImage(image); + addAccessibleListeners(imageLabel, image); + GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.BEGINNING) + .applyTo(imageLabel); + } + // create message + if (message != null) { + _messageLabel = new Text(composite, getMessageLabelStyle()|SWT.READ_ONLY); + _messageLabel.setText(message); + GridDataFactory + .fillDefaults() + .align(SWT.FILL, SWT.BEGINNING) + .grab(true, false) + .hint( + convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH), + SWT.DEFAULT).applyTo(_messageLabel); + } + return composite; + } + + /** + * NOTE: copied from IconAndMessageDialog + * Add an accessible listener to the label if it can be inferred from the + * image. + * + * @param label + * @param image + */ + private void addAccessibleListeners(Label label, final Image image) { + label.getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getName(AccessibleEvent event) { + final String accessibleMessage = getAccessibleMessageFor(image); + if (accessibleMessage == null) { + return; + } + event.result = accessibleMessage; + } + }); + } + + /** + * NOTE: copied from IconAndMessageDialog + * @param image + * @return an accesible string + */ + private String getAccessibleMessageFor(Image image) { + if (image.equals(getErrorImage())) { + return JFaceResources.getString("error");//$NON-NLS-1$ + } + + if (image.equals(getWarningImage())) { + return JFaceResources.getString("warning");//$NON-NLS-1$ + } + + if (image.equals(getInfoImage())) { + return JFaceResources.getString("info");//$NON-NLS-1$ + } + + if (image.equals(getQuestionImage())) { + return JFaceResources.getString("question"); //$NON-NLS-1$ + } + + return null; + } + +} 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 5b9233d3b..3f7c97b1b 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 @@ -45,6 +45,12 @@ JSFLibraryContainerWizardPage_Description=Select JavaServer Face Libraries to ad JSFLibraryContainerWizardPage_WarningNoJSFFacet=JavaServer Face Libraries can only be configured for Dynamic Web projects with the JSF facet installed. JSFLibraryContainerWizardPage_JSFLibraries=JSF Libraries: JSFLibraryContainerWizardPage_Add=Add... +JSFLibraryContainerWizardPage_V1Registry_Warning_DialogTitle=Backward compatibility issue +JSFLibraryWizard_JSFLibraryWizard_DontShowThisAgain_CheckBoxLabel=Do not show this message again (affects all listed projects) +JSFLibraryContainerWizardPage_V1Registry_Warning_DialogText=This project is currently configured for use with an obsolete version of JSF libraries. \ +Changing JSF library settings on this project may break backward compatibility with older versions of JSF tools.\ +\n\nSee http://wiki.eclipse.org/index.php/JSF_Library_Migration for more information. +JSFLibraryContainerWizardPage_EditLibrary_DescriptionText=Select JSF Library for this reference to use. Choose 'Edit...' to modify contents of the selected library. JSFLibraryContainerWizardPage_Edit=Edit... JSFLibraryContainerWizardPage_ImplAlreadyPresent=An implementation has already been chosen. Please remove before adding different one JSFLibraryContainerWizardPage_ErrorInitializing=Error during initialization @@ -67,6 +73,11 @@ JSFLibraryWizard_ExtJarFileDialogTitle=Browse for Jars/Zips JSFLibraryWizard_ValidateNoJars=The library must contain at least one jar. JSFLibraryWizard_ValidateNoLibraryName=A library name must be supplied. JSFLibraryWizard_ValidateExistingLibraryName=A library or implementation by this name already exists. +JSFLibraryWizard_V1JSFLibrary_DialogMessage=The projects listed below contain JSF library references that are\ +obsolete and may not be automatically updated by this change. To fix this issue, you need to update these\ +these projects.\ +\n\nSee http://wiki.eclipse.org/index.php/JSF_Library_Migration for more information. \n\nProjects: {0} +JSFLibraryWizard_V1JSFLibrary_DialogTitle=Backward compatibility issue JSFLibraryConfigControl_ImplementationLibrary=Implementation Library JSFLibraryPropertyPage_No_JSF_Facet_Installed=JSF Facet not installed. |