Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 42554 Details for
Bug 140752
wizards: create html/jsp/css/js files outside the webcontent dir
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
revised patch
patch2.txt (text/plain), 77.18 KB, created by
Kaloyan Raev
on 2006-05-25 06:39:05 EDT
(
hide
)
Description:
revised patch
Filename:
MIME Type:
Creator:
Kaloyan Raev
Created:
2006-05-25 06:39:05 EDT
Size:
77.18 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.wst.html.ui >Index: src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java,v >retrieving revision 1.8 >diff -u -r1.8 NewHTMLWizard.java >--- src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java 7 Mar 2006 21:01:21 -0000 1.8 >+++ src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLWizard.java 25 May 2006 10:35:04 -0000 >@@ -13,34 +13,20 @@ > import java.io.ByteArrayInputStream; > import java.io.ByteArrayOutputStream; > import java.io.OutputStreamWriter; >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.List; > > import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IWorkspace; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Preferences; >-import org.eclipse.core.runtime.content.IContentType; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.WizardNewFileCreationPage; > import org.eclipse.ui.ide.IDE; > import org.eclipse.wst.html.core.internal.HTMLCorePlugin; >-import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; >-import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML; > import org.eclipse.wst.html.ui.internal.HTMLUIMessages; > import org.eclipse.wst.html.ui.internal.Logger; > import org.eclipse.wst.html.ui.internal.editor.HTMLEditorPluginImageHelper; >@@ -48,119 +34,16 @@ > import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; > > public class NewHTMLWizard extends Wizard implements INewWizard { >- private WizardNewFileCreationPage fNewFilePage; >+ >+ private NewHTMLFileWizardPage fNewFilePage; > private NewHTMLTemplatesWizardPage fNewFileTemplatesPage; > private IStructuredSelection fSelection; >- private IContentType fContentType; >- private List fValidExtensions = null; >- >- /** >- * Adds default extension to the filename >- * >- * @param filename >- * @return >- */ >- String addDefaultExtension(String filename) { >- StringBuffer newFileName = new StringBuffer(filename); >- >- Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences(); >- String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION); >- >- newFileName.append("."); //$NON-NLS-1$ >- newFileName.append(ext); >- >- return newFileName.toString(); >- } >- >- /** >- * Get content type associated with this new file wizard >- * >- * @return IContentType >- */ >- IContentType getContentType() { >- if (fContentType == null) >- fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML); >- return fContentType; >- } >- >- /** >- * Get list of valid extensions for HTML Content type >- * >- * @return >- */ >- List getValidExtensions() { >- if (fValidExtensions == null) { >- IContentType type = getContentType(); >- fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >- } >- return fValidExtensions; >- } >- >- /** >- * Verifies if fileName is valid name for content type. Takes base content >- * type into consideration. >- * >- * @param fileName >- * @return true if extension is valid for this content type >- */ >- boolean extensionValidForContentType(String fileName) { >- boolean valid = false; >- >- IContentType type = getContentType(); >- // there is currently an extension >- if (fileName.lastIndexOf('.') != -1) { >- // check what content types are associated with current extension >- IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >- int i = 0; >- while (i < types.length && !valid) { >- valid = types[i].isKindOf(type); >- ++i; >- } >- } >- else >- valid = true; // no extension so valid >- return valid; >- } > > public void addPages() { >- fNewFilePage = new WizardNewFileCreationPage("HTMLWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$ >- protected boolean validatePage() { >- String fileName = getFileName(); >- IPath fullPath = getContainerFullPath(); >- if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >- // check that filename does not contain invalid extension >- if (!extensionValidForContentType(fileName)) { >- setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString())); >- return false; >- } >- // no file extension specified so check adding default >- // extension doesn't equal a file that already exists >- if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >- IPath resourcePath = fullPath.append(newFileName); >- >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >- if (!result.isOK()) { >- // path invalid >- setErrorMessage(result.getMessage()); >- return false; >- } >- >- if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >- setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists); >- return false; >- } >- } >- } >- >- setErrorMessage(null); >- return super.validatePage(); >- } >- }; >+ fNewFilePage = new NewHTMLFileWizardPage("NewHTMLTemplatesWizardPage", >+ new StructuredSelection(IDE.computeSelectedResources(fSelection))); > fNewFilePage.setTitle(HTMLUIMessages._UI_WIZARD_NEW_HEADING); > fNewFilePage.setDescription(HTMLUIMessages._UI_WIZARD_NEW_DESCRIPTION); >- > addPage(fNewFilePage); > > fNewFileTemplatesPage = new NewHTMLTemplatesWizardPage(); >@@ -199,7 +82,7 @@ > // no file extension specified so add default extension > String fileName = fNewFilePage.getFileName(); > if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >+ String newFileName = fNewFilePage.addDefaultExtension(fileName); > fNewFilePage.setFileName(newFileName); > } > >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/plugin.xml,v >retrieving revision 1.53 >diff -u -r1.53 plugin.xml >--- plugin.xml 16 May 2006 18:09:12 -0000 1.53 >+++ plugin.xml 25 May 2006 10:35:03 -0000 >@@ -322,20 +322,16 @@ > wizardId="org.eclipse.wst.html.ui.internal.wizard.NewHTMLWizard"> > <enablement> > <or> >- <adapt type="org.eclipse.core.resources.IProject"> >- <or> >- <test >- property="org.eclipse.wst.common.project.facet.core.projectFacet" >- value="wst.web"/> >- <test >- property="org.eclipse.wst.common.project.facet.core.projectFacet" >- value="jst.web"/> >- </or> >- </adapt> >- <instanceof >- value="org.eclipse.core.resources.IFolder" /> >- <instanceof >- value="org.eclipse.core.resources.IFile" /> >+ <adapt type="org.eclipse.core.resources.IResource"> >+ <or> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="wst.web"/> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="jst.web"/> >+ </or> >+ </adapt> > </or> > </enablement> > </commonWizard> >@@ -456,4 +452,4 @@ > id="org.eclipse.ui.texteditor.SelectRulerAction"/> > </editorContribution> > </extension> >-</plugin> >+</plugin> >\ No newline at end of file >Index: src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties,v >retrieving revision 1.8 >diff -u -r1.8 HTMLUIPluginResources.properties >--- src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties 23 Feb 2006 05:04:19 -0000 1.8 >+++ src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties 25 May 2006 10:35:03 -0000 >@@ -19,6 +19,8 @@ > _UI_WIZARD_NEW_HEADING = HTML Page > _UI_WIZARD_NEW_DESCRIPTION = Create a new HTML Page. > _ERROR_FILENAME_MUST_END_HTML = The file name must end in one of the following extensions {0}. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = The folder must be inside the Web Content folder. > ResourceGroup_nameExists = The same name already exists. > NewHTMLTemplatesWizardPage_0=Select HTML Template > NewHTMLTemplatesWizardPage_1=Select a template as initial content in the HTML page. >Index: src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java,v >retrieving revision 1.6 >diff -u -r1.6 HTMLUIMessages.java >--- src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java 23 Feb 2006 05:04:19 -0000 1.6 >+++ src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java 25 May 2006 10:35:03 -0000 >@@ -49,6 +49,8 @@ > public static String _UI_WIZARD_NEW_HEADING; > public static String _UI_WIZARD_NEW_DESCRIPTION; > public static String _ERROR_FILENAME_MUST_END_HTML; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT; > public static String ResourceGroup_nameExists; > public static String NewHTMLTemplatesWizardPage_0; > public static String NewHTMLTemplatesWizardPage_1; >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/wst/components/html/plugins/org.eclipse.wst.html.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.12 >diff -u -r1.12 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 May 2006 07:22:57 -0000 1.12 >+++ META-INF/MANIFEST.MF 25 May 2006 10:35:03 -0000 >@@ -46,5 +46,7 @@ > org.eclipse.wst.common.uriresolver, > org.eclipse.wst.validation, > org.eclipse.wst.javascript.ui, >+ org.eclipse.wst.common.project.facet.core, >+ org.eclipse.wst.common.modulecore, > com.ibm.icu > Eclipse-LazyStart: true >Index: src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java >=================================================================== >RCS file: src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java >diff -N src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/html/ui/internal/wizard/NewHTMLFileWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,243 @@ >+package org.eclipse.wst.html.ui.internal.wizard; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.content.IContentType; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.dialogs.WizardNewFileCreationPage; >+import org.eclipse.wst.common.componentcore.ComponentCore; >+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; >+import org.eclipse.wst.common.project.facet.core.IFacetedProject; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+import org.eclipse.wst.html.core.internal.HTMLCorePlugin; >+import org.eclipse.wst.html.core.internal.preferences.HTMLCorePreferenceNames; >+import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML; >+import org.eclipse.wst.html.ui.internal.HTMLUIMessages; >+ >+public class NewHTMLFileWizardPage extends WizardNewFileCreationPage { >+ >+ private IContentType fContentType; >+ private List fValidExtensions = null; >+ >+ public NewHTMLFileWizardPage(String pageName, IStructuredSelection selection) { >+ super(pageName, selection); >+ } >+ >+ /** >+ * This method is overriden to set the selected folder to web contents >+ * folder if the current selection is outside the web contents folder. >+ */ >+ protected void initialPopulateContainerNameField() { >+ super.initialPopulateContainerNameField(); >+ >+ IPath fullPath = getContainerFullPath(); >+ IProject project = getProjectFromPath(fullPath); >+ IPath webContentPath = getWebContentPath(project); >+ >+ if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) { >+ setContainerFullPath(webContentPath); >+ } >+ } >+ >+ /** >+ * This method is overriden to set additional validation specific to >+ * html files. >+ */ >+ protected boolean validatePage() { >+ setMessage(null); >+ setErrorMessage(null); >+ >+ if (!super.validatePage()) { >+ return false; >+ } >+ >+ String fileName = getFileName(); >+ IPath fullPath = getContainerFullPath(); >+ if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >+ // check that filename does not contain invalid extension >+ if (!extensionValidForContentType(fileName)) { >+ setErrorMessage(NLS.bind(HTMLUIMessages._ERROR_FILENAME_MUST_END_HTML, getValidExtensions().toString())); >+ return false; >+ } >+ // no file extension specified so check adding default >+ // extension doesn't equal a file that already exists >+ if (fileName.lastIndexOf('.') == -1) { >+ String newFileName = addDefaultExtension(fileName); >+ IPath resourcePath = fullPath.append(newFileName); >+ >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >+ if (!result.isOK()) { >+ // path invalid >+ setErrorMessage(result.getMessage()); >+ return false; >+ } >+ >+ if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >+ setErrorMessage(HTMLUIMessages.ResourceGroup_nameExists); >+ return false; >+ } >+ } >+ >+ // get the IProject for the selection path >+ IProject project = getProjectFromPath(fullPath); >+ >+ // check if the project has has web facet >+ if (!isWebProject(project)) { >+ setMessage(HTMLUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT, WARNING); >+ return false; >+ } >+ >+ // check that the path is inside the webContent folder >+ IPath webContentPath = getWebContentPath(project); >+ if (!webContentPath.isPrefixOf(fullPath)) { >+ setMessage(HTMLUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING); >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Get content type associated with this new file wizard >+ * >+ * @return IContentType >+ */ >+ protected IContentType getContentType() { >+ if (fContentType == null) >+ fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML); >+ return fContentType; >+ } >+ >+ /** >+ * Get list of valid extensions for HTML Content type >+ * >+ * @return >+ */ >+ protected List getValidExtensions() { >+ if (fValidExtensions == null) { >+ IContentType type = getContentType(); >+ fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >+ } >+ return fValidExtensions; >+ } >+ >+ /** >+ * Verifies if fileName is valid name for content type. Takes base content >+ * type into consideration. >+ * >+ * @param fileName >+ * @return true if extension is valid for this content type >+ */ >+ protected boolean extensionValidForContentType(String fileName) { >+ boolean valid = false; >+ >+ IContentType type = getContentType(); >+ // there is currently an extension >+ if (fileName.lastIndexOf('.') != -1) { >+ // check what content types are associated with current extension >+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >+ int i = 0; >+ while (i < types.length && !valid) { >+ valid = types[i].isKindOf(type); >+ ++i; >+ } >+ } >+ else >+ valid = true; // no extension so valid >+ return valid; >+ } >+ >+ /** >+ * Adds default extension to the filename >+ * >+ * @param filename >+ * @return >+ */ >+ protected String addDefaultExtension(String filename) { >+ StringBuffer newFileName = new StringBuffer(filename); >+ >+ Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences(); >+ String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION); >+ >+ newFileName.append("."); //$NON-NLS-1$ >+ newFileName.append(ext); >+ >+ return newFileName.toString(); >+ } >+ >+ /** >+ * Returns the project that contains the specified path >+ * >+ * @param path the path which project is needed >+ * @return IProject object. If path is <code>null</code> the return value >+ * is also <code>null</code>. >+ */ >+ protected IProject getProjectFromPath(IPath path) { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = null; >+ >+ if (path != null) { >+ if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) { >+ project = workspace.getRoot().getProject(path.toString()); >+ } else { >+ project = workspace.getRoot().getFile(path).getProject(); >+ } >+ } >+ >+ return project; >+ } >+ >+ /** >+ * Checks if the specified project is a web project. >+ * >+ * @param project project to be checked >+ * @return true if the project is web project, otherwise false >+ * @throws CoreException thrown when creating IFacetedProject from IProject >+ */ >+ protected boolean isWebProject(IProject project) { >+ IFacetedProject faceted; >+ try { >+ faceted = ProjectFacetsManager.create(project); >+ } catch (CoreException e) { >+ throw new RuntimeException(e); >+ } >+ >+ if (faceted != null && >+ (faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || >+ faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) { >+ return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * Returns the web contents folder of the specified project >+ * >+ * @param project the project which web contents path is needed >+ * @return IPath of the web contents folder >+ */ >+ protected IPath getWebContentPath(IProject project) { >+ IPath path = null; >+ >+ if (project != null && isWebProject(project)) { >+ IVirtualComponent component = ComponentCore.createComponent(project); >+ path = component.getRootFolder().getWorkspaceRelativePath(); >+ } >+ >+ return path; >+ } >+} >#P org.eclipse.wst.css.ui >Index: src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java,v >retrieving revision 1.7 >diff -u -r1.7 CSSUIMessages.java >--- src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java 23 Feb 2006 05:04:06 -0000 1.7 >+++ src/org/eclipse/wst/css/ui/internal/CSSUIMessages.java 25 May 2006 10:35:05 -0000 >@@ -69,6 +69,8 @@ > public static String _UI_WIZARD_NEW_HEADING; > public static String _UI_WIZARD_NEW_DESCRIPTION; > public static String _ERROR_FILENAME_MUST_END_CSS; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT; > public static String Title_InvalidValue; > public static String Message_InvalidValue; > public static String FormatMenu_label; >Index: src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties,v >retrieving revision 1.10 >diff -u -r1.10 CSSUIPluginResources.properties >--- src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties 23 Feb 2006 05:04:06 -0000 1.10 >+++ src/org/eclipse/wst/css/ui/internal/CSSUIPluginResources.properties 25 May 2006 10:35:06 -0000 >@@ -56,6 +56,8 @@ > _UI_WIZARD_NEW_HEADING = Cascading Style Sheet > _UI_WIZARD_NEW_DESCRIPTION = Create a new CSS file. > _ERROR_FILENAME_MUST_END_CSS = The file name must end in one of the following extensions {0}. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = The folder must be inside the Web Content folder. > # > Title_InvalidValue=Invalid Value > Message_InvalidValue=Invalid property value. >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/plugin.xml,v >retrieving revision 1.35 >diff -u -r1.35 plugin.xml >--- plugin.xml 17 Apr 2006 07:07:34 -0000 1.35 >+++ plugin.xml 25 May 2006 10:35:05 -0000 >@@ -126,6 +126,31 @@ > <selection class="org.eclipse.core.resources.IResource" /> > </wizard> > </extension> >+ >+ <!-- Add new CSS wizard to J2EE Project Navigator --> >+ <extension >+ id="org.eclipse.wst.css.commonWizard.newCSS" >+ point="org.eclipse.ui.navigator.navigatorContent"> >+ <commonWizard >+ menuGroupId="org.eclipse.wst.web.ui" >+ type="new" >+ wizardId="org.eclipse.wst.css.ui.internal.wizard.NewCSSWizard"> >+ <enablement> >+ <or> >+ <adapt type="org.eclipse.core.resources.IResource"> >+ <or> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="wst.web"/> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="jst.web"/> >+ </or> >+ </adapt> >+ </or> >+ </enablement> >+ </commonWizard> >+ </extension> > > <extension point="org.eclipse.ui.popupMenus"> > <viewerContribution >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.11 >diff -u -r1.11 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 May 2006 07:16:51 -0000 1.11 >+++ META-INF/MANIFEST.MF 25 May 2006 10:35:05 -0000 >@@ -43,5 +43,7 @@ > org.eclipse.core.resources, > org.eclipse.core.runtime, > org.eclipse.ui.ide, >+ org.eclipse.wst.common.project.facet.core, >+ org.eclipse.wst.common.modulecore, > com.ibm.icu > Eclipse-LazyStart: true >Index: src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/css/plugins/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java,v >retrieving revision 1.8 >diff -u -r1.8 NewCSSWizard.java >--- src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java 7 Mar 2006 21:00:48 -0000 1.8 >+++ src/org/eclipse/wst/css/ui/internal/wizard/NewCSSWizard.java 25 May 2006 10:35:06 -0000 >@@ -14,34 +14,20 @@ > import java.io.ByteArrayInputStream; > import java.io.ByteArrayOutputStream; > import java.io.OutputStreamWriter; >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.List; > > import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IWorkspace; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Preferences; >-import org.eclipse.core.runtime.content.IContentType; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.WizardNewFileCreationPage; > import org.eclipse.ui.ide.IDE; > import org.eclipse.wst.css.core.internal.CSSCorePlugin; >-import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames; >-import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; > import org.eclipse.wst.css.ui.internal.CSSUIMessages; > import org.eclipse.wst.css.ui.internal.Logger; > import org.eclipse.wst.css.ui.internal.editor.CSSEditorPluginImages; >@@ -49,118 +35,15 @@ > import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; > > public class NewCSSWizard extends Wizard implements INewWizard { >- private WizardNewFileCreationPage fNewFilePage; >+ private NewCSSFileWizardPage fNewFilePage; > private NewCSSTemplatesWizardPage fNewFileTemplatesPage; > private IStructuredSelection fSelection; >- private IContentType fContentType; >- private List fValidExtensions = null; >- >- /** >- * Adds default extension to the filename >- * >- * @param filename >- * @return >- */ >- String addDefaultExtension(String filename) { >- StringBuffer newFileName = new StringBuffer(filename); >- >- Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences(); >- String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION); >- >- newFileName.append("."); //$NON-NLS-1$ >- newFileName.append(ext); >- >- return newFileName.toString(); >- } >- >- /** >- * Get content type associated with this new file wizard >- * >- * @return IContentType >- */ >- IContentType getContentType() { >- if (fContentType == null) >- fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS); >- return fContentType; >- } >- >- /** >- * Get list of valid extensions for CSS Content type >- * >- * @return >- */ >- List getValidExtensions() { >- if (fValidExtensions == null) { >- IContentType type = getContentType(); >- fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >- } >- return fValidExtensions; >- } >- >- /** >- * Verifies if fileName is valid name for content type. Takes base content >- * type into consideration. >- * >- * @param fileName >- * @return true if extension is valid for this content type >- */ >- boolean extensionValidForContentType(String fileName) { >- boolean valid = false; >- >- IContentType type = getContentType(); >- // there is currently an extension >- if (fileName.lastIndexOf('.') != -1) { >- // check what content types are associated with current extension >- IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >- int i = 0; >- while (i < types.length && !valid) { >- valid = types[i].isKindOf(type); >- ++i; >- } >- } >- else >- valid = true; // no extension so valid >- return valid; >- } > > public void addPages() { >- fNewFilePage = new WizardNewFileCreationPage("CSSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$ >- protected boolean validatePage() { >- String fileName = getFileName(); >- IPath fullPath = getContainerFullPath(); >- if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >- // check that filename does not contain invalid extension >- if (!extensionValidForContentType(fileName)) { >- setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString())); >- return false; >- } >- // no file extension specified so check adding default >- // extension doesn't equal a file that already exists >- if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >- IPath resourcePath = fullPath.append(newFileName); >- >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >- if (!result.isOK()) { >- // path invalid >- setErrorMessage(result.getMessage()); >- return false; >- } >- >- if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >- setErrorMessage(CSSUIMessages.ResourceGroup_nameExists); >- return false; >- } >- } >- } >- setErrorMessage(null); >- return super.validatePage(); >- } >- }; >+ fNewFilePage = new NewCSSFileWizardPage("NewCSSTemplatesWizardPage", >+ new StructuredSelection(IDE.computeSelectedResources(fSelection))); > fNewFilePage.setTitle(CSSUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$ > fNewFilePage.setDescription(CSSUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$ >- > addPage(fNewFilePage); > > fNewFileTemplatesPage = new NewCSSTemplatesWizardPage(); >@@ -199,7 +82,7 @@ > // no file extension specified so add default extension > String fileName = fNewFilePage.getFileName(); > if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >+ String newFileName = fNewFilePage.addDefaultExtension(fileName); > fNewFilePage.setFileName(newFileName); > } > >Index: src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java >=================================================================== >RCS file: src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java >diff -N src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/css/ui/internal/wizard/NewCSSFileWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,244 @@ >+package org.eclipse.wst.css.ui.internal.wizard; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.content.IContentType; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.dialogs.WizardNewFileCreationPage; >+import org.eclipse.wst.common.componentcore.ComponentCore; >+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; >+import org.eclipse.wst.common.project.facet.core.IFacetedProject; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+import org.eclipse.wst.css.core.internal.CSSCorePlugin; >+import org.eclipse.wst.css.core.internal.preferences.CSSCorePreferenceNames; >+import org.eclipse.wst.css.core.internal.provisional.contenttype.ContentTypeIdForCSS; >+import org.eclipse.wst.css.ui.internal.CSSUIMessages; >+ >+public class NewCSSFileWizardPage extends WizardNewFileCreationPage { >+ >+ private IContentType fContentType; >+ private List fValidExtensions = null; >+ >+ public NewCSSFileWizardPage(String pageName, IStructuredSelection selection) { >+ super(pageName, selection); >+ } >+ >+ /** >+ * This method is overriden to set the selected folder to web contents >+ * folder if the current selection is outside the web contents folder. >+ */ >+ protected void initialPopulateContainerNameField() { >+ super.initialPopulateContainerNameField(); >+ >+ IPath fullPath = getContainerFullPath(); >+ IProject project = getProjectFromPath(fullPath); >+ IPath webContentPath = getWebContentPath(project); >+ >+ if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) { >+ setContainerFullPath(webContentPath); >+ } >+ } >+ >+ /** >+ * This method is overriden to set additional validation specific to >+ * css files. >+ */ >+ protected boolean validatePage() { >+ setMessage(null); >+ setErrorMessage(null); >+ >+ if (!super.validatePage()) { >+ return false; >+ } >+ >+ String fileName = getFileName(); >+ IPath fullPath = getContainerFullPath(); >+ if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >+ // check that filename does not contain invalid extension >+ if (!extensionValidForContentType(fileName)) { >+ setErrorMessage(NLS.bind(CSSUIMessages._ERROR_FILENAME_MUST_END_CSS, getValidExtensions().toString())); >+ return false; >+ } >+ // no file extension specified so check adding default >+ // extension doesn't equal a file that already exists >+ if (fileName.lastIndexOf('.') == -1) { >+ String newFileName = addDefaultExtension(fileName); >+ IPath resourcePath = fullPath.append(newFileName); >+ >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >+ if (!result.isOK()) { >+ // path invalid >+ setErrorMessage(result.getMessage()); >+ return false; >+ } >+ >+ if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >+ setErrorMessage(CSSUIMessages.ResourceGroup_nameExists); >+ return false; >+ } >+ } >+ >+ // get the IProject for the selection path >+ IProject project = getProjectFromPath(fullPath); >+ >+ // check if the project has has web facet >+ if (!isWebProject(project)) { >+ setMessage(CSSUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT, WARNING); >+ return false; >+ } >+ >+ // check that the path is inside the webContent folder >+ IPath webContentPath = getWebContentPath(project); >+ if (!webContentPath.isPrefixOf(fullPath)) { >+ setMessage(CSSUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING); >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Get content type associated with this new file wizard >+ * >+ * @return IContentType >+ */ >+ protected IContentType getContentType() { >+ if (fContentType == null) >+ fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForCSS.ContentTypeID_CSS); >+ return fContentType; >+ } >+ >+ /** >+ * Get list of valid extensions for CSS Content type >+ * >+ * @return >+ */ >+ protected List getValidExtensions() { >+ if (fValidExtensions == null) { >+ IContentType type = getContentType(); >+ fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >+ } >+ return fValidExtensions; >+ } >+ >+ /** >+ * Verifies if fileName is valid name for content type. Takes base content >+ * type into consideration. >+ * >+ * @param fileName >+ * @return true if extension is valid for this content type >+ */ >+ protected boolean extensionValidForContentType(String fileName) { >+ boolean valid = false; >+ >+ IContentType type = getContentType(); >+ // there is currently an extension >+ if (fileName.lastIndexOf('.') != -1) { >+ // check what content types are associated with current extension >+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >+ int i = 0; >+ while (i < types.length && !valid) { >+ valid = types[i].isKindOf(type); >+ ++i; >+ } >+ } >+ else >+ valid = true; // no extension so valid >+ return valid; >+ } >+ >+ /** >+ * Adds default extension to the filename >+ * >+ * @param filename >+ * @return >+ */ >+ protected String addDefaultExtension(String filename) { >+ StringBuffer newFileName = new StringBuffer(filename); >+ >+ Preferences preference = CSSCorePlugin.getDefault().getPluginPreferences(); >+ String ext = preference.getString(CSSCorePreferenceNames.DEFAULT_EXTENSION); >+ >+ newFileName.append("."); //$NON-NLS-1$ >+ newFileName.append(ext); >+ >+ return newFileName.toString(); >+ } >+ >+ /** >+ * Returns the project that contains the specified path >+ * >+ * @param path the path which project is needed >+ * @return IProject object. If path is <code>null</code> the return value >+ * is also <code>null</code>. >+ */ >+ protected IProject getProjectFromPath(IPath path) { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = null; >+ >+ if (path != null) { >+ if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) { >+ project = workspace.getRoot().getProject(path.toString()); >+ } else { >+ project = workspace.getRoot().getFile(path).getProject(); >+ } >+ } >+ >+ return project; >+ } >+ >+ /** >+ * Checks if the specified project is a web project. >+ * >+ * @param project project to be checked >+ * @return true if the project is web project, otherwise false >+ * @throws CoreException thrown when creating IFacetedProject from IProject >+ */ >+ protected boolean isWebProject(IProject project) { >+ IFacetedProject faceted; >+ try { >+ faceted = ProjectFacetsManager.create(project); >+ } catch (CoreException e) { >+ throw new RuntimeException(e); >+ } >+ >+ if (faceted != null && >+ (faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || >+ faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) { >+ return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * Returns the web contents folder of the specified project >+ * >+ * @param project the project which web contents path is needed >+ * @return IPath of the web contents folder >+ */ >+ protected IPath getWebContentPath(IProject project) { >+ IPath path = null; >+ >+ if (project != null && isWebProject(project)) { >+ IVirtualComponent component = ComponentCore.createComponent(project); >+ path = component.getRootFolder().getWorkspaceRelativePath(); >+ } >+ >+ return path; >+ } >+ >+} >#P org.eclipse.wst.javascript.ui >Index: src/org/eclipse/wst/javascript/ui/internal/editor/JavaScriptUIMessages.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/javascript/plugins/org.eclipse.wst.javascript.ui/src/org/eclipse/wst/javascript/ui/internal/editor/JavaScriptUIMessages.java,v >retrieving revision 1.4 >diff -u -r1.4 JavaScriptUIMessages.java >--- src/org/eclipse/wst/javascript/ui/internal/editor/JavaScriptUIMessages.java 25 Jan 2006 03:48:46 -0000 1.4 >+++ src/org/eclipse/wst/javascript/ui/internal/editor/JavaScriptUIMessages.java 25 May 2006 10:35:07 -0000 >@@ -41,6 +41,8 @@ > public static String _UI_WIZARD_NEW_HEADING; > public static String _UI_WIZARD_NEW_DESCRIPTION; > public static String _ERROR_FILENAME_MUST_END_JS; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT; > public static String ResourceGroup_nameExists; > public static String Editor_Cut_label; // Resource bundle > public static String Editor_Cut_tooltip; // Resource bundle >Index: src/org/eclipse/wst/javascript/ui/internal/editor/JSUIPluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/wst/components/javascript/plugins/org.eclipse.wst.javascript.ui/src/org/eclipse/wst/javascript/ui/internal/editor/JSUIPluginResources.properties,v >retrieving revision 1.6 >diff -u -r1.6 JSUIPluginResources.properties >--- src/org/eclipse/wst/javascript/ui/internal/editor/JSUIPluginResources.properties 25 Jan 2006 03:48:46 -0000 1.6 >+++ src/org/eclipse/wst/javascript/ui/internal/editor/JSUIPluginResources.properties 25 May 2006 10:35:07 -0000 >@@ -30,6 +30,8 @@ > _UI_WIZARD_NEW_HEADING = JavaScript > _UI_WIZARD_NEW_DESCRIPTION = Create a new JavaScript file. > _ERROR_FILENAME_MUST_END_JS = The file name must end in one of the following extensions {0}. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT = The folder must be inside Static or Dynamic Web Project. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = The folder must be inside the Web Content folder. > ResourceGroup_nameExists = The same name already exists. > # these are copied from sse ui > Editor_Cut_label=Cu&t@Ctrl+X >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/wst/components/javascript/plugins/org.eclipse.wst.javascript.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.9 >diff -u -r1.9 MANIFEST.MF >--- META-INF/MANIFEST.MF 29 Mar 2006 21:37:51 -0000 1.9 >+++ META-INF/MANIFEST.MF 25 May 2006 10:35:07 -0000 >@@ -34,5 +34,7 @@ > org.eclipse.core.runtime, > org.eclipse.ui.ide, > org.eclipse.wst.xml.core, >- com.ibm.icu >+ com.ibm.icu, >+ org.eclipse.wst.common.project.facet.core, >+ org.eclipse.wst.common.modulecore > Eclipse-LazyStart: true >Index: src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSWizard.java >=================================================================== >RCS file: /cvsroot/webtools/wst/components/javascript/plugins/org.eclipse.wst.javascript.ui/src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSWizard.java,v >retrieving revision 1.7 >diff -u -r1.7 NewJSWizard.java >--- src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSWizard.java 7 Mar 2006 21:01:42 -0000 1.7 >+++ src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSWizard.java 25 May 2006 10:35:07 -0000 >@@ -1,150 +1,30 @@ > package org.eclipse.wst.javascript.ui.internal.wizard; > >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.List; >- > import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IWorkspace; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Platform; >-import org.eclipse.core.runtime.Preferences; >-import org.eclipse.core.runtime.content.IContentType; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.WizardNewFileCreationPage; > import org.eclipse.ui.ide.IDE; >-import org.eclipse.wst.javascript.core.internal.JavaScriptCorePlugin; >-import org.eclipse.wst.javascript.core.internal.contenttype.ContentTypeIdForJavaScript; >-import org.eclipse.wst.javascript.core.internal.preferences.JavaScriptCorePreferenceNames; > import org.eclipse.wst.javascript.ui.internal.editor.JSEditorPlugin; > import org.eclipse.wst.javascript.ui.internal.editor.JavaScriptUIMessages; > import org.eclipse.wst.javascript.ui.internal.editor.Logger; > > public class NewJSWizard extends Wizard implements INewWizard { > static String PAGE_IMAGE = "/icons/full/wizban/newjscriptfile_wiz.gif"; //$NON-NLS-1$ >- private WizardNewFileCreationPage fNewFilePage; >+ private NewJSFileWizardPage fNewFilePage; > private IStructuredSelection fSelection; >- private IContentType fContentType; >- private List fValidExtensions = null; >- >- /** >- * Adds default extension to the filename >- * >- * @param filename >- * @return >- */ >- String addDefaultExtension(String filename) { >- StringBuffer newFileName = new StringBuffer(filename); >- >- Preferences preference = JavaScriptCorePlugin.getDefault().getPluginPreferences(); >- String ext = preference.getString(JavaScriptCorePreferenceNames.DEFAULT_EXTENSION); >- >- newFileName.append("."); //$NON-NLS-1$ >- newFileName.append(ext); >- >- return newFileName.toString(); >- } >- >- /** >- * Get content type associated with this new file wizard >- * >- * @return IContentType >- */ >- IContentType getContentType() { >- if (fContentType == null) >- fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJavaScript.ContentTypeID_JAVASCRIPT); >- return fContentType; >- } >- >- /** >- * Get list of valid extensions for JavaScript Content type >- * >- * @return >- */ >- List getValidExtensions() { >- if (fValidExtensions == null) { >- IContentType type = getContentType(); >- fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >- } >- return fValidExtensions; >- } >- >- /** >- * Verifies if fileName is valid name for content type. Takes base content >- * type into consideration. >- * >- * @param fileName >- * @return true if extension is valid for this content type >- */ >- boolean extensionValidForContentType(String fileName) { >- boolean valid = false; >- >- IContentType type = getContentType(); >- // there is currently an extension >- if (fileName.lastIndexOf('.') != -1) { >- // check what content types are associated with current extension >- IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >- int i = 0; >- while (i < types.length && !valid) { >- valid = types[i].isKindOf(type); >- ++i; >- } >- } >- else >- valid = true; // no extension so valid >- return valid; >- } > > public void addPages() { >- fNewFilePage = new WizardNewFileCreationPage("JSWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$ >- protected boolean validatePage() { >- String fileName = getFileName(); >- IPath fullPath = getContainerFullPath(); >- if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >- // check that filename does not contain invalid extension >- if (!extensionValidForContentType(fileName)) { >- setErrorMessage(NLS.bind(JavaScriptUIMessages._ERROR_FILENAME_MUST_END_JS, getValidExtensions().toString())); >- return false; >- } >- // no file extension specified so check adding default >- // extension doesn't equal a file that already exists >- if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >- IPath resourcePath = fullPath.append(newFileName); >- >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >- if (!result.isOK()) { >- // path invalid >- setErrorMessage(result.getMessage()); >- return false; >- } >- >- if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >- setErrorMessage(JavaScriptUIMessages.ResourceGroup_nameExists); >- return false; >- } >- } >- } >- setErrorMessage(null); >- return super.validatePage(); >- } >- }; >+ fNewFilePage = new NewJSFileWizardPage("NewJSTemplatesWizardPage", >+ new StructuredSelection(IDE.computeSelectedResources(fSelection))); > fNewFilePage.setTitle(JavaScriptUIMessages._UI_WIZARD_NEW_HEADING); //$NON-NLS-1$ > fNewFilePage.setDescription(JavaScriptUIMessages._UI_WIZARD_NEW_DESCRIPTION); //$NON-NLS-1$ >- > addPage(fNewFilePage); > } > >@@ -183,7 +63,7 @@ > // no file extension specified so add default extension > String fileName = fNewFilePage.getFileName(); > if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >+ String newFileName = fNewFilePage.addDefaultExtension(fileName); > fNewFilePage.setFileName(newFileName); > } > >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/wst/components/javascript/plugins/org.eclipse.wst.javascript.ui/plugin.xml,v >retrieving revision 1.27 >diff -u -r1.27 plugin.xml >--- plugin.xml 19 Apr 2006 16:28:19 -0000 1.27 >+++ plugin.xml 25 May 2006 10:35:07 -0000 >@@ -110,6 +110,32 @@ > <selection class="org.eclipse.core.resources.IResource" /> > </wizard> > </extension> >+ >+ <!-- Add new JavaScript wizard to J2EE Project Navigator --> >+ <extension >+ id="org.eclipse.wst.javascript.commonWizard.newJS" >+ point="org.eclipse.ui.navigator.navigatorContent"> >+ <commonWizard >+ menuGroupId="org.eclipse.wst.web.ui" >+ type="new" >+ wizardId="org.eclipse.wst.javascript.ui.internal.wizard.NewJSWizard"> >+ <enablement> >+ <or> >+ <adapt type="org.eclipse.core.resources.IResource"> >+ <or> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="wst.web"/> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="jst.web"/> >+ </or> >+ </adapt> >+ </or> >+ </enablement> >+ </commonWizard> >+ </extension> >+ > <extension point="org.eclipse.ui.preferencePages"> > <!-- JAVASCRIPT PREFERENCE PAGES --> > <page >Index: src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSFileWizardPage.java >=================================================================== >RCS file: src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSFileWizardPage.java >diff -N src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSFileWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/wst/javascript/ui/internal/wizard/NewJSFileWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,243 @@ >+package org.eclipse.wst.javascript.ui.internal.wizard; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.content.IContentType; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.dialogs.WizardNewFileCreationPage; >+import org.eclipse.wst.common.componentcore.ComponentCore; >+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; >+import org.eclipse.wst.common.project.facet.core.IFacetedProject; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+import org.eclipse.wst.javascript.core.internal.JavaScriptCorePlugin; >+import org.eclipse.wst.javascript.core.internal.contenttype.ContentTypeIdForJavaScript; >+import org.eclipse.wst.javascript.core.internal.preferences.JavaScriptCorePreferenceNames; >+import org.eclipse.wst.javascript.ui.internal.editor.JavaScriptUIMessages; >+ >+public class NewJSFileWizardPage extends WizardNewFileCreationPage { >+ >+ private IContentType fContentType; >+ private List fValidExtensions = null; >+ >+ public NewJSFileWizardPage(String pageName, IStructuredSelection selection) { >+ super(pageName, selection); >+ } >+ >+ /** >+ * This method is overriden to set the selected folder to web contents >+ * folder if the current selection is outside the web contents folder. >+ */ >+ protected void initialPopulateContainerNameField() { >+ super.initialPopulateContainerNameField(); >+ >+ IPath fullPath = getContainerFullPath(); >+ IProject project = getProjectFromPath(fullPath); >+ IPath webContentPath = getWebContentPath(project); >+ >+ if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) { >+ setContainerFullPath(webContentPath); >+ } >+ } >+ >+ /** >+ * This method is overriden to set additional validation specific to >+ * javascript files. >+ */ >+ protected boolean validatePage() { >+ setMessage(null); >+ setErrorMessage(null); >+ >+ if (!super.validatePage()) { >+ return false; >+ } >+ >+ String fileName = getFileName(); >+ IPath fullPath = getContainerFullPath(); >+ if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >+ // check that filename does not contain invalid extension >+ if (!extensionValidForContentType(fileName)) { >+ setErrorMessage(NLS.bind(JavaScriptUIMessages._ERROR_FILENAME_MUST_END_JS, getValidExtensions().toString())); >+ return false; >+ } >+ // no file extension specified so check adding default >+ // extension doesn't equal a file that already exists >+ if (fileName.lastIndexOf('.') == -1) { >+ String newFileName = addDefaultExtension(fileName); >+ IPath resourcePath = fullPath.append(newFileName); >+ >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >+ if (!result.isOK()) { >+ // path invalid >+ setErrorMessage(result.getMessage()); >+ return false; >+ } >+ >+ if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >+ setErrorMessage(JavaScriptUIMessages.ResourceGroup_nameExists); >+ return false; >+ } >+ } >+ >+ // get the IProject for the selection path >+ IProject project = getProjectFromPath(fullPath); >+ >+ // check if the project has has web facet >+ if (!isWebProject(project)) { >+ setMessage(JavaScriptUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_PROJECT, WARNING); >+ return false; >+ } >+ >+ // check that the path is inside the webContent folder >+ IPath webContentPath = getWebContentPath(project); >+ if (!webContentPath.isPrefixOf(fullPath)) { >+ setMessage(JavaScriptUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING); >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Get content type associated with this new file wizard >+ * >+ * @return IContentType >+ */ >+ protected IContentType getContentType() { >+ if (fContentType == null) >+ fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJavaScript.ContentTypeID_JAVASCRIPT); >+ return fContentType; >+ } >+ >+ /** >+ * Get list of valid extensions for JavaScript Content type >+ * >+ * @return >+ */ >+ protected List getValidExtensions() { >+ if (fValidExtensions == null) { >+ IContentType type = getContentType(); >+ fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >+ } >+ return fValidExtensions; >+ } >+ >+ /** >+ * Verifies if fileName is valid name for content type. Takes base content >+ * type into consideration. >+ * >+ * @param fileName >+ * @return true if extension is valid for this content type >+ */ >+ protected boolean extensionValidForContentType(String fileName) { >+ boolean valid = false; >+ >+ IContentType type = getContentType(); >+ // there is currently an extension >+ if (fileName.lastIndexOf('.') != -1) { >+ // check what content types are associated with current extension >+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >+ int i = 0; >+ while (i < types.length && !valid) { >+ valid = types[i].isKindOf(type); >+ ++i; >+ } >+ } >+ else >+ valid = true; // no extension so valid >+ return valid; >+ } >+ >+ /** >+ * Adds default extension to the filename >+ * >+ * @param filename >+ * @return >+ */ >+ protected String addDefaultExtension(String filename) { >+ StringBuffer newFileName = new StringBuffer(filename); >+ >+ Preferences preference = JavaScriptCorePlugin.getDefault().getPluginPreferences(); >+ String ext = preference.getString(JavaScriptCorePreferenceNames.DEFAULT_EXTENSION); >+ >+ newFileName.append("."); //$NON-NLS-1$ >+ newFileName.append(ext); >+ >+ return newFileName.toString(); >+ } >+ >+ /** >+ * Returns the project that contains the specified path >+ * >+ * @param path the path which project is needed >+ * @return IProject object. If path is <code>null</code> the return value >+ * is also <code>null</code>. >+ */ >+ protected IProject getProjectFromPath(IPath path) { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = null; >+ >+ if (path != null) { >+ if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) { >+ project = workspace.getRoot().getProject(path.toString()); >+ } else { >+ project = workspace.getRoot().getFile(path).getProject(); >+ } >+ } >+ >+ return project; >+ } >+ >+ /** >+ * Checks if the specified project is a web project. >+ * >+ * @param project project to be checked >+ * @return true if the project is web project, otherwise false >+ * @throws CoreException thrown when creating IFacetedProject from IProject >+ */ >+ protected boolean isWebProject(IProject project) { >+ IFacetedProject faceted; >+ try { >+ faceted = ProjectFacetsManager.create(project); >+ } catch (CoreException e) { >+ throw new RuntimeException(e); >+ } >+ >+ if (faceted != null && >+ (faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("wst.web")) || >+ faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web")))) { >+ return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * Returns the web contents folder of the specified project >+ * >+ * @param project the project which web contents path is needed >+ * @return IPath of the web contents folder >+ */ >+ protected IPath getWebContentPath(IProject project) { >+ IPath path = null; >+ >+ if (project != null && isWebProject(project)) { >+ IVirtualComponent component = ComponentCore.createComponent(project); >+ path = component.getRootFolder().getWorkspaceRelativePath(); >+ } >+ >+ return path; >+ } >+} >#P org.eclipse.jst.jsp.ui >Index: src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties,v >retrieving revision 1.14 >diff -u -r1.14 JSPUIPluginResources.properties >--- src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties 3 May 2006 07:41:50 -0000 1.14 >+++ src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties 25 May 2006 10:35:10 -0000 >@@ -37,6 +37,8 @@ > _UI_WIZARD_NEW_HEADING = JavaServer Page > _UI_WIZARD_NEW_DESCRIPTION = Create a new JavaServer Page. > _ERROR_FILENAME_MUST_END_JSP = The file name must end in one of the following extensions {0}. >+_WARNING_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT = The folder must be inside Dynamic Web Project. >+_WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT = The folder must be inside the Web Content folder. > ResourceGroup_nameExists = The same name already exists. > NewJSPTemplatesWizardPage_0=Select JSP Template > NewJSPTemplatesWizardPage_1=Select a template as initial content in the JSP page. >Index: src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java,v >retrieving revision 1.12 >diff -u -r1.12 JSPUIMessages.java >--- src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java 3 May 2006 07:41:50 -0000 1.12 >+++ src/org/eclipse/jst/jsp/ui/internal/JSPUIMessages.java 25 May 2006 10:35:10 -0000 >@@ -61,6 +61,8 @@ > public static String _UI_WIZARD_NEW_HEADING; > public static String _UI_WIZARD_NEW_DESCRIPTION; > public static String _ERROR_FILENAME_MUST_END_JSP; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT; >+ public static String _WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT; > public static String ResourceGroup_nameExists; > public static String NewJSPTemplatesWizardPage_0; > public static String NewJSPTemplatesWizardPage_1; >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/META-INF/MANIFEST.MF,v >retrieving revision 1.13 >diff -u -r1.13 MANIFEST.MF >--- META-INF/MANIFEST.MF 10 May 2006 07:19:03 -0000 1.13 >+++ META-INF/MANIFEST.MF 25 May 2006 10:35:10 -0000 >@@ -58,5 +58,7 @@ > org.eclipse.ui.ide, > org.eclipse.wst.javascript.ui, > org.eclipse.ui.views, >+ org.eclipse.wst.common.project.facet.core, >+ org.eclipse.wst.common.modulecore, > com.ibm.icu > Eclipse-LazyStart: true >Index: src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java,v >retrieving revision 1.8 >diff -u -r1.8 NewJSPWizard.java >--- src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java 7 Mar 2006 21:01:32 -0000 1.8 >+++ src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPWizard.java 25 May 2006 10:35:10 -0000 >@@ -13,153 +13,36 @@ > import java.io.ByteArrayInputStream; > import java.io.ByteArrayOutputStream; > import java.io.OutputStreamWriter; >-import java.util.ArrayList; >-import java.util.Arrays; >-import java.util.List; > > import org.eclipse.core.resources.IFile; >-import org.eclipse.core.resources.IResource; >-import org.eclipse.core.resources.IWorkspace; >-import org.eclipse.core.resources.ResourcesPlugin; >-import org.eclipse.core.runtime.IPath; >-import org.eclipse.core.runtime.IStatus; >-import org.eclipse.core.runtime.Platform; > import org.eclipse.core.runtime.Preferences; >-import org.eclipse.core.runtime.content.IContentType; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.wizard.Wizard; > import org.eclipse.jst.jsp.core.internal.JSPCorePlugin; >-import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames; >-import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP; > import org.eclipse.jst.jsp.ui.internal.JSPUIMessages; > import org.eclipse.jst.jsp.ui.internal.Logger; > import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; > import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; >-import org.eclipse.osgi.util.NLS; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.PlatformUI; >-import org.eclipse.ui.dialogs.WizardNewFileCreationPage; > import org.eclipse.ui.ide.IDE; > import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; > > public class NewJSPWizard extends Wizard implements INewWizard { >- private WizardNewFileCreationPage fNewFilePage; >+ private NewJSPFileWizardPage fNewFilePage; > private NewJSPTemplatesWizardPage fNewFileTemplatesPage; > private IStructuredSelection fSelection; >- private IContentType fContentType; >- private List fValidExtensions = null; >- >- /** >- * Adds default extension to the filename >- * >- * @param filename >- * @return >- */ >- String addDefaultExtension(String filename) { >- StringBuffer newFileName = new StringBuffer(filename); >- >- Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); >- String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION); >- >- newFileName.append("."); //$NON-NLS-1$ >- newFileName.append(ext); >- >- return newFileName.toString(); >- } >- >- /** >- * Get content type associated with this new file wizard >- * >- * @return IContentType >- */ >- IContentType getContentType() { >- if (fContentType == null) >- fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP); >- return fContentType; >- } >- >- /** >- * Get list of valid extensions for JSP Content type >- * >- * @return >- */ >- List getValidExtensions() { >- if (fValidExtensions == null) { >- IContentType type = getContentType(); >- fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >- } >- return fValidExtensions; >- } >- >- /** >- * Verifies if fileName is valid name for content type. Takes base content >- * type into consideration. >- * >- * @param fileName >- * @return true if extension is valid for this content type >- */ >- boolean extensionValidForContentType(String fileName) { >- boolean valid = false; >- >- IContentType type = getContentType(); >- // there is currently an extension >- if (fileName.lastIndexOf('.') != -1) { >- // check what content types are associated with current extension >- IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >- int i = 0; >- while (i < types.length && !valid) { >- valid = types[i].isKindOf(type); >- ++i; >- } >- } >- else >- valid = true; // no extension so valid >- return valid; >- } > > public void addPages() { >- fNewFilePage = new WizardNewFileCreationPage("JSPWizardNewFileCreationPage", new StructuredSelection(IDE.computeSelectedResources(fSelection))) { //$NON-NLS-1$ >- protected boolean validatePage() { >- String fileName = getFileName(); >- IPath fullPath = getContainerFullPath(); >- if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >- // check that filename does not contain invalid extension >- if (!extensionValidForContentType(fileName)) { >- setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString())); >- return false; >- } >- // no file extension specified so check adding default >- // extension doesn't equal a file that already exists >- if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >- IPath resourcePath = fullPath.append(newFileName); >- >- IWorkspace workspace = ResourcesPlugin.getWorkspace(); >- IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >- if (!result.isOK()) { >- // path invalid >- setErrorMessage(result.getMessage()); >- return false; >- } >- >- if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >- setErrorMessage(JSPUIMessages.ResourceGroup_nameExists); >- return false; >- } >- } >- } >- setErrorMessage(null); >- return super.validatePage(); >- } >- }; >+ fNewFilePage = new NewJSPFileWizardPage("NewJSPTemplatesWizardPage", >+ new StructuredSelection(IDE.computeSelectedResources(fSelection))); > fNewFilePage.setTitle(JSPUIMessages._UI_WIZARD_NEW_HEADING); > fNewFilePage.setDescription(JSPUIMessages._UI_WIZARD_NEW_DESCRIPTION); >- > addPage(fNewFilePage); > > fNewFileTemplatesPage = new NewJSPTemplatesWizardPage(); >@@ -199,7 +82,7 @@ > // no file extension specified so add default extension > String fileName = fNewFilePage.getFileName(); > if (fileName.lastIndexOf('.') == -1) { >- String newFileName = addDefaultExtension(fileName); >+ String newFileName = fNewFilePage.addDefaultExtension(fileName); > fNewFilePage.setFileName(newFileName); > } > >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/webtools/jst/components/jsp/plugins/org.eclipse.jst.jsp.ui/plugin.xml,v >retrieving revision 1.57 >diff -u -r1.57 plugin.xml >--- plugin.xml 16 May 2006 18:08:51 -0000 1.57 >+++ plugin.xml 25 May 2006 10:35:10 -0000 >@@ -420,24 +420,11 @@ > wizardId="org.eclipse.jst.jsp.ui.internal.wizard.NewJSPWizard"> > <enablement> > <or> >- >- <adapt type="org.eclipse.core.resources.IProject"> >- <or> >- <test >- property="org.eclipse.wst.common.project.facet.core.projectFacet" >- value="wst.web"/> >- <test >- property="org.eclipse.wst.common.project.facet.core.projectFacet" >- value="jst.web"/> >- </or> >- </adapt> >- >- <instanceof >- value="org.eclipse.core.resources.IFolder" /> >- >- <instanceof >- value="org.eclipse.core.resources.IFile" /> >- >+ <adapt type="org.eclipse.core.resources.IResource"> >+ <test >+ property="org.eclipse.wst.common.project.facet.core.projectFacet" >+ value="jst.web"/> >+ </adapt> > </or> > </enablement> > </commonWizard> >@@ -641,4 +628,4 @@ > <contentType id="org.eclipse.jst.jsp.core.cssjspsource" /> > </adapterFactoryDescription> > </extension> >-</plugin> >+</plugin> >\ No newline at end of file >Index: src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java >=================================================================== >RCS file: src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java >diff -N src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jst/jsp/ui/internal/wizard/NewJSPFileWizardPage.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,242 @@ >+package org.eclipse.jst.jsp.ui.internal.wizard; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.IWorkspace; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Preferences; >+import org.eclipse.core.runtime.content.IContentType; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jst.jsp.core.internal.JSPCorePlugin; >+import org.eclipse.jst.jsp.core.internal.preferences.JSPCorePreferenceNames; >+import org.eclipse.jst.jsp.core.internal.provisional.contenttype.ContentTypeIdForJSP; >+import org.eclipse.jst.jsp.ui.internal.JSPUIMessages; >+import org.eclipse.osgi.util.NLS; >+import org.eclipse.ui.dialogs.WizardNewFileCreationPage; >+import org.eclipse.wst.common.componentcore.ComponentCore; >+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; >+import org.eclipse.wst.common.project.facet.core.IFacetedProject; >+import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; >+ >+public class NewJSPFileWizardPage extends WizardNewFileCreationPage { >+ >+ private IContentType fContentType; >+ private List fValidExtensions = null; >+ >+ public NewJSPFileWizardPage(String pageName, IStructuredSelection selection) { >+ super(pageName, selection); >+ } >+ >+ /** >+ * This method is overriden to set the selected folder to web contents >+ * folder if the current selection is outside the web contents folder. >+ */ >+ protected void initialPopulateContainerNameField() { >+ super.initialPopulateContainerNameField(); >+ >+ IPath fullPath = getContainerFullPath(); >+ IProject project = getProjectFromPath(fullPath); >+ IPath webContentPath = getWebContentPath(project); >+ >+ if (webContentPath != null && !webContentPath.isPrefixOf(fullPath)) { >+ setContainerFullPath(webContentPath); >+ } >+ } >+ >+ /** >+ * This method is overriden to set additional validation specific to >+ * jsp files. >+ */ >+ protected boolean validatePage() { >+ setMessage(null); >+ setErrorMessage(null); >+ >+ if (!super.validatePage()) { >+ return false; >+ } >+ >+ String fileName = getFileName(); >+ IPath fullPath = getContainerFullPath(); >+ if ((fullPath != null) && (fullPath.isEmpty() == false) && (fileName != null)) { >+ // check that filename does not contain invalid extension >+ if (!extensionValidForContentType(fileName)) { >+ setErrorMessage(NLS.bind(JSPUIMessages._ERROR_FILENAME_MUST_END_JSP, getValidExtensions().toString())); >+ return false; >+ } >+ // no file extension specified so check adding default >+ // extension doesn't equal a file that already exists >+ if (fileName.lastIndexOf('.') == -1) { >+ String newFileName = addDefaultExtension(fileName); >+ IPath resourcePath = fullPath.append(newFileName); >+ >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IStatus result = workspace.validatePath(resourcePath.toString(), IResource.FOLDER); >+ if (!result.isOK()) { >+ // path invalid >+ setErrorMessage(result.getMessage()); >+ return false; >+ } >+ >+ if ((workspace.getRoot().getFolder(resourcePath).exists() || workspace.getRoot().getFile(resourcePath).exists())) { >+ setErrorMessage(JSPUIMessages.ResourceGroup_nameExists); >+ return false; >+ } >+ } >+ >+ // get the IProject for the selection path >+ IProject project = getProjectFromPath(fullPath); >+ >+ // check if the project has has web facet >+ if (!isDynamicWebProject(project)) { >+ setMessage(JSPUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_DYNAMIC_WEB_PROJECT, WARNING); >+ return false; >+ } >+ >+ // check that the path is inside the webContent folder >+ IPath webContentPath = getWebContentPath(project); >+ if (!webContentPath.isPrefixOf(fullPath)) { >+ setMessage(JSPUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING); >+ } >+ } >+ >+ return true; >+ } >+ >+ /** >+ * Adds default extension to the filename >+ * >+ * @param filename >+ * @return >+ */ >+ protected String addDefaultExtension(String filename) { >+ StringBuffer newFileName = new StringBuffer(filename); >+ >+ Preferences preference = JSPCorePlugin.getDefault().getPluginPreferences(); >+ String ext = preference.getString(JSPCorePreferenceNames.DEFAULT_EXTENSION); >+ >+ newFileName.append("."); //$NON-NLS-1$ >+ newFileName.append(ext); >+ >+ return newFileName.toString(); >+ } >+ >+ /** >+ * Get content type associated with this new file wizard >+ * >+ * @return IContentType >+ */ >+ protected IContentType getContentType() { >+ if (fContentType == null) >+ fContentType = Platform.getContentTypeManager().getContentType(ContentTypeIdForJSP.ContentTypeID_JSP); >+ return fContentType; >+ } >+ >+ /** >+ * Get list of valid extensions for JSP Content type >+ * >+ * @return >+ */ >+ protected List getValidExtensions() { >+ if (fValidExtensions == null) { >+ IContentType type = getContentType(); >+ fValidExtensions = new ArrayList(Arrays.asList(type.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); >+ } >+ return fValidExtensions; >+ } >+ >+ /** >+ * Verifies if fileName is valid name for content type. Takes base content >+ * type into consideration. >+ * >+ * @param fileName >+ * @return true if extension is valid for this content type >+ */ >+ protected boolean extensionValidForContentType(String fileName) { >+ boolean valid = false; >+ >+ IContentType type = getContentType(); >+ // there is currently an extension >+ if (fileName.lastIndexOf('.') != -1) { >+ // check what content types are associated with current extension >+ IContentType[] types = Platform.getContentTypeManager().findContentTypesFor(fileName); >+ int i = 0; >+ while (i < types.length && !valid) { >+ valid = types[i].isKindOf(type); >+ ++i; >+ } >+ } >+ else >+ valid = true; // no extension so valid >+ return valid; >+ } >+ >+ /** >+ * Returns the project that contains the specified path >+ * >+ * @param path the path which project is needed >+ * @return IProject object. If path is <code>null</code> the return value >+ * is also <code>null</code>. >+ */ >+ protected IProject getProjectFromPath(IPath path) { >+ IWorkspace workspace = ResourcesPlugin.getWorkspace(); >+ IProject project = null; >+ >+ if (path != null) { >+ if (workspace.validatePath(path.toString(), IResource.PROJECT).isOK()) { >+ project = workspace.getRoot().getProject(path.toString()); >+ } else { >+ project = workspace.getRoot().getFile(path).getProject(); >+ } >+ } >+ >+ return project; >+ } >+ >+ /** >+ * Checks if the specified project is a web project. >+ * >+ * @param project project to be checked >+ * @return true if the project is web project, otherwise false >+ * @throws CoreException thrown when creating IFacetedProject from IProject >+ */ >+ protected boolean isDynamicWebProject(IProject project) { >+ IFacetedProject faceted; >+ try { >+ faceted = ProjectFacetsManager.create(project); >+ } catch (CoreException e) { >+ throw new RuntimeException(e); >+ } >+ >+ if (faceted != null && >+ faceted.hasProjectFacet(ProjectFacetsManager.getProjectFacet("jst.web"))) { >+ return true; >+ } >+ >+ return false; >+ } >+ >+ /** >+ * Returns the web contents folder of the specified project >+ * >+ * @param project the project which web contents path is needed >+ * @return IPath of the web contents folder >+ */ >+ protected IPath getWebContentPath(IProject project) { >+ IPath path = null; >+ >+ if (project != null && isDynamicWebProject(project)) { >+ IVirtualComponent component = ComponentCore.createComponent(project); >+ path = component.getRootFolder().getWorkspaceRelativePath(); >+ } >+ >+ return path; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 140752
:
40689
|
42554
|
42795
|
43157