Author: akazakov
Date: 2012-04-11 19:10:25 -0400 (Wed, 11 Apr 2012)
New Revision: 40147
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLFileWizardPage.java
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/META-INF/MANIFEST.MF
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLWizard.java
Log:
https://issues.jboss.org/browse/JBIDE-11472 Adding a XHTML targets
"target/m2e-wtp/web resources
Modified: trunk/jst/plugins/org.jboss.tools.jst.web.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.web.ui/META-INF/MANIFEST.MF 2012-04-11 21:45:29
UTC (rev 40146)
+++ trunk/jst/plugins/org.jboss.tools.jst.web.ui/META-INF/MANIFEST.MF 2012-04-11 23:10:25
UTC (rev 40147)
@@ -28,7 +28,7 @@
org.jboss.tools.jst.web,
org.eclipse.ui.navigator;bundle-version="3.5.0",
org.eclipse.jdt.ui;bundle-version="3.7.0",
-
org.eclipse.wst.common.frameworks;visibility:=reexport;bundle-version="1.2.0",
+
org.eclipse.wst.common.frameworks;bundle-version="1.2.0";visibility:=reexport,
org.eclipse.wst.server.core;bundle-version="1.1.302",
org.eclipse.wst.server.ui;bundle-version="1.1.305",
org.eclipse.jst.j2ee.web;bundle-version="1.1.500",
@@ -50,7 +50,8 @@
org.apache.ant;bundle-version="1.7.1",
org.eclipse.datatools.connectivity.ui.dse;bundle-version="1.1.4",
org.eclipse.datatools.connectivity.db.generic.ui;bundle-version="1.0.1",
- org.jboss.tools.common.el.ui
+ org.jboss.tools.common.el.ui,
+ org.eclipse.wst.html.core;bundle-version="1.1.502"
Bundle-Version: 3.3.0.qualifier
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ClassPath: .
Added:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLFileWizardPage.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLFileWizardPage.java
(rev 0)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLFileWizardPage.java 2012-04-11
23:10:25 UTC (rev 40147)
@@ -0,0 +1,283 @@
+/*******************************************************************************
+ * Copyright (c) 2012 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.jst.web.ui.wizards.newfile;
+
+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.util.FacetModuleCoreSupport;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
+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.ProjectFacetsManager;
+import org.eclipse.wst.html.ui.internal.HTMLUIMessages;
+import org.jboss.tools.common.web.WebUtils;
+import org.jboss.tools.jst.web.ui.WebUiPlugin;
+import org.eclipse.wst.html.core.internal.provisional.contenttype.ContentTypeIdForHTML;
+
+/**
+ * Copied from NewHTMLFileWizardPage because we can't extend it but we need to fix
https://issues.jboss.org/browse/JBIDE-11472
(
https://bugs.eclipse.org/bugs/show_bug.cgi?id=375605).
+ *
+ * @author Alexey Kazakov
+ */
+public class NewXHTMLFileWizardPage extends WizardNewFileCreationPage {
+
+ private static final String defaultName = "NewFile"; //$NON-NLS-1$
+ private IContentType fContentType;
+ private List fValidExtensions = null;
+
+ public NewXHTMLFileWizardPage(String pageName, IStructuredSelection selection) {
+ super(pageName, selection);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ // inherit default container and name specification widgets
+ super.createControl(parent);
+ setFileName(computeDefaultFileName());
+ setPageComplete(validatePage());
+ }
+
+ protected String computeDefaultFileName() {
+ int count = 0;
+ String fileName = addDefaultExtension(defaultName);
+ IPath containerFullPath = getContainerFullPath();
+ if (containerFullPath != null) {
+ while (true) {
+ IPath path = containerFullPath.append(fileName);
+ if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) {
+ count++;
+ fileName = addDefaultExtension(defaultName + count);
+ }
+ else {
+ break;
+ }
+ }
+ }
+ return fileName;
+ }
+
+ /**
+ * This method is overridden 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[] webContentPaths = WebUtils.getWebContentPaths(project);
+ boolean withinWebContent = false;
+ for (int i = 0; webContentPaths != null && i < webContentPaths.length; i++)
{
+ if (webContentPaths[i].isPrefixOf(fullPath)) {
+ withinWebContent = true;
+ break;
+ }
+ }
+ if(!withinWebContent && webContentPaths.length>0) {
+ setContainerFullPath(webContentPaths[0]);
+ }
+ }
+
+ /**
+ * This method is overridden 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);
+ // if inside web project, check if inside webContent folder
+ if (project != null && isWebProject(project)) {
+ // check that the path is inside the webContent folder
+ IPath[] webContentPaths = FacetModuleCoreSupport.getAcceptableRootPaths(project);
+ boolean isPrefix = false;
+ for (int i = 0; !isPrefix && i < webContentPaths.length; i++) {
+ isPrefix |= webContentPaths[i].isPrefixOf(fullPath);
+ }
+ if (!isPrefix) {
+ setMessage(HTMLUIMessages._WARNING_FOLDER_MUST_BE_INSIDE_WEB_CONTENT, WARNING);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Get content type associated with this new file wizard
+ *
+ * @return IContentType
+ */
+ private IContentType getContentType() {
+ if (fContentType == null)
+ fContentType =
Platform.getContentTypeManager().getContentType(ContentTypeIdForHTML.ContentTypeID_HTML);
+ return fContentType;
+ }
+
+ /**
+ * Get list of valid extensions for HTML Content type
+ *
+ * @return
+ */
+ private 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
+ */
+ private 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
+ */
+ String addDefaultExtension(String filename) {
+ StringBuffer newFileName = new StringBuffer(filename);
+
+// Preferences preference = HTMLCorePlugin.getDefault().getPluginPreferences();
+// String ext = preference.getString(HTMLCorePreferenceNames.DEFAULT_EXTENSION);
+ String ext = "xhtml";
+
+ 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>.
+ */
+ private 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
+ */
+ private boolean isWebProject(IProject project) {
+// return FacetModuleCoreSupport.isWebProject(project);
+ if (project == null) {
+ return false;
+ }
+ boolean is = false;
+ IFacetedProject faceted;
+ try {
+ faceted = ProjectFacetsManager.create(project);
+ } catch (CoreException e) {
+ WebUiPlugin.getDefault().logError(e);
+ return false;
+ }
+ if (ProjectFacetsManager.isProjectFacetDefined("jst.web")) {
+ IProjectFacet facet = ProjectFacetsManager.getProjectFacet("jst.web");
+ is = is || (faceted != null && faceted.hasProjectFacet(facet));
+ }
+ if (ProjectFacetsManager.isProjectFacetDefined("wst.web")) {
+ IProjectFacet facet = ProjectFacetsManager.getProjectFacet("wst.web");
+ is = is || (faceted != null && faceted.hasProjectFacet(facet));
+ }
+ return is;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLFileWizardPage.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLWizard.java
===================================================================
---
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLWizard.java 2012-04-11
21:45:29 UTC (rev 40146)
+++
trunk/jst/plugins/org.jboss.tools.jst.web.ui/src/org/jboss/tools/jst/web/ui/wizards/newfile/NewXHTMLWizard.java 2012-04-11
23:10:25 UTC (rev 40147)
@@ -22,6 +22,7 @@
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.IWizardPage;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
@@ -34,7 +35,6 @@
import org.eclipse.wst.sse.core.utils.StringUtils;
import org.jboss.tools.common.meta.action.impl.SpecialWizardSupport;
import org.jboss.tools.common.model.XModelException;
-import org.jboss.tools.common.model.files.handlers.CreateFileSupport;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.model.ui.wizard.newfile.NewFileContextEx;
import org.jboss.tools.common.model.ui.wizard.newfile.NewXHTMLFileWizard;
@@ -54,30 +54,33 @@
private WizardNewFileCreationPage fNewFilePage;
private NewXHTMLTemplatesWizardPage fNewFileTemplatesPage;
private NewXHTMLFileWizard newXHTMLFileWizard;
- private NewXHTMLWizardSelectTagLibrariesPage newXHTMLWizardSelectTagLibrariesPage;
-
-
-
+ private NewXHTMLWizardSelectTagLibrariesPage newXHTMLWizardSelectTagLibrariesPage;
+ private IStructuredSelection fSelection;
+
@Override
public void addPages() {
super.addPages();
- this.fNewFilePage = (WizardNewFileCreationPage)
getPage(NewXHTMLWizard.HTMLWizardNewFileCreationPage);
+// this.fNewFilePage = (WizardNewFileCreationPage)
getPage(NewXHTMLWizard.HTMLWizardNewFileCreationPage);
+ this.fNewFilePage = new
NewXHTMLFileWizardPage("XHTMLWizardNewFileCreationPage", new
StructuredSelection(IDE.computeSelectedResources(fSelection))); //$NON-NLS-1$
this.fNewFilePage.setTitle(Messages.UI_WIZARD_XHTML_NEW_TITLE);
this.fNewFilePage.setDescription(Messages.UI_WIZARD_XHTML_NEW_Description);
-
+ addPage(this.fNewFilePage);
+
NewFileContextEx newFileContext = newXHTMLFileWizard.getFileContext();
CreateJSPFileSupport jspFileSupport =
(CreateJSPFileSupport)newFileContext.getSupport();
this.fNewFileTemplatesPage = new NewXHTMLTemplatesWizardPage(jspFileSupport);
-
+
addPage(this.fNewFileTemplatesPage);
this.newXHTMLWizardSelectTagLibrariesPage = getURISelectionPage();
if(jspFileSupport.getTaglibs()!=null&&jspFileSupport.getTaglibs().getDescriptions().length>0)
addPage(this.newXHTMLWizardSelectTagLibrariesPage);
}
+
@Override
public void init(IWorkbench aWorkbench, IStructuredSelection aSelection) {
super.init(aWorkbench, aSelection);
+ fSelection = aSelection;
setWindowTitle(Messages.UI_WIZARD_XHTML_NEW_TITLE);
setNewXHTMLFileWizard(new NewXHTMLFileWizard());
getNewXHTMLFileWizard().init(aWorkbench, aSelection);
@@ -87,7 +90,7 @@
*/
@Override
public void addPage(IWizardPage page) {
- if(!NewXHTMLWizard.NewHTMLTemplatesWizardPage.equalsIgnoreCase(page.getName())){
+ if(!NewXHTMLWizard.NewHTMLTemplatesWizardPage.equalsIgnoreCase(page.getName())
&&
!NewXHTMLWizard.HTMLWizardNewFileCreationPage.equalsIgnoreCase(page.getName())){
super.addPage(page);
}
}