diff options
Diffstat (limited to 'bundles/org.eclipse.wst.xml.ui/src-wizards')
18 files changed, 0 insertions, 3486 deletions
diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java deleted file mode 100644 index cd809c778a..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationOperation.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.net.URL; -import java.util.zip.ZipFile; - -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.ui.dialogs.IOverwriteQuery; -import org.eclipse.ui.wizards.datatransfer.ImportOperation; -import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.osgi.framework.Bundle; - -public class ExampleProjectCreationOperation implements IRunnableWithProgress { - - private IResource elementToOpen; - - private IOverwriteQuery overwriteQuery; - - private ExampleProjectCreationWizardPage[] pages; - - /** - * Constructor for ExampleProjectCreationOperation - */ - public ExampleProjectCreationOperation(ExampleProjectCreationWizardPage[] myPages, IOverwriteQuery myOverwriteQuery) { - elementToOpen = null; - pages = myPages; - overwriteQuery = myOverwriteQuery; - } - - private IProject configNewProject(IWorkspaceRoot root, String name, String[] natureIds, IProject[] referencedProjects, IProgressMonitor monitor) throws InvocationTargetException { - try { - IProject project = root.getProject(name); - if (!project.exists()) { - project.create(null); - } - if (!project.isOpen()) { - project.open(null); - } - IProjectDescription desc = project.getDescription(); - desc.setLocation(null); - desc.setNatureIds(natureIds); - desc.setReferencedProjects(referencedProjects); - - project.setDescription(desc, new SubProgressMonitor(monitor, 1)); - - return project; - } - catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - private void createProject(IWorkspaceRoot root, ExampleProjectCreationWizardPage page, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - IConfigurationElement desc = page.getConfigurationElement(); - - IConfigurationElement[] imports = desc.getChildren("import"); //$NON-NLS-1$ - IConfigurationElement[] natures = desc.getChildren("nature"); //$NON-NLS-1$ - IConfigurationElement[] references = desc.getChildren("references"); //$NON-NLS-1$ - int nImports = (imports == null) ? 0 : imports.length; - int nNatures = (natures == null) ? 0 : natures.length; - int nReferences = (references == null) ? 0 : references.length; - - monitor.beginTask(XMLWizardsMessages.ExampleProjectCreationOperation_op_desc_proj, nImports + 1); - - String name = page.getProjectName(); - - String[] natureIds = new String[nNatures]; - for (int i = 0; i < nNatures; i++) { - natureIds[i] = natures[i].getAttribute("id"); //$NON-NLS-1$ - } - IProject[] referencedProjects = new IProject[nReferences]; - for (int i = 0; i < nReferences; i++) { - referencedProjects[i] = root.getProject(references[i].getAttribute("id")); //$NON-NLS-1$ - } - - IProject proj = configNewProject(root, name, natureIds, referencedProjects, monitor); - - for (int i = 0; i < nImports; i++) { - doImports(proj, imports[i], new SubProgressMonitor(monitor, 1)); - } - - String open = desc.getAttribute("open"); //$NON-NLS-1$ - if ((open != null) && (open.length() > 0)) { - IResource fileToOpen = proj.findMember(new Path(open)); - if (fileToOpen != null) { - elementToOpen = fileToOpen; - } - } - - } - - private void doImports(IProject project, IConfigurationElement curr, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - try { - IPath destPath; - String name = curr.getAttribute("dest"); //$NON-NLS-1$ - if ((name == null) || (name.length() == 0)) { - destPath = project.getFullPath(); - } - else { - IFolder folder = project.getFolder(name); - if (!folder.exists()) { - folder.create(true, true, null); - } - destPath = folder.getFullPath(); - } - String importPath = curr.getAttribute("src"); //$NON-NLS-1$ - if (importPath == null) { - importPath = ""; //$NON-NLS-1$ - Logger.log(Logger.ERROR, "projectsetup descriptor: import missing"); //$NON-NLS-1$ - return; - } - - ZipFile zipFile = getZipFileFromPluginDir(importPath, getContributingPlugin(curr)); - importFilesFromZip(zipFile, destPath, new SubProgressMonitor(monitor, 1)); - } - catch (CoreException e) { - throw new InvocationTargetException(e); - } - } - - private String getContributingPlugin(IConfigurationElement configurationElement) { - Object parent = configurationElement; - while (parent != null) { - if (parent instanceof IExtension) { - return ((IExtension) parent).getNamespace(); - } - parent = ((IConfigurationElement) parent).getParent(); - } - return null; - } - - public IResource getElementToOpen() { - return elementToOpen; - } - - private ZipFile getZipFileFromPluginDir(String pluginRelativePath, String symbolicName) throws CoreException { - try { - Bundle bundle = Platform.getBundle(symbolicName); - URL starterURL = new URL(bundle.getEntry("/"), pluginRelativePath); //$NON-NLS-1$ - return new ZipFile(Platform.asLocalURL(starterURL).getFile()); - } - catch (IOException e) { - String message = pluginRelativePath + ": " + e.getMessage(); //$NON-NLS-1$ - Status status = new Status(IStatus.ERROR, XMLUIPlugin.ID, IStatus.ERROR, message, e); - throw new CoreException(status); - } - } - - private void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile); - ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, overwriteQuery); - op.run(monitor); - } - - /* - * @see IRunnableWithProgress#run(IProgressMonitor) - */ - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - if (monitor == null) { - monitor = new NullProgressMonitor(); - } - try { - monitor.beginTask(XMLWizardsMessages.ExampleProjectCreationOperation_op_desc, pages.length); - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); - - for (int i = 0; i < pages.length; i++) { - createProject(root, pages[i], new SubProgressMonitor(monitor, 1)); - } - } - finally { - monitor.done(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java deleted file mode 100644 index d968c92071..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizard.java +++ /dev/null @@ -1,232 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.lang.reflect.InvocationTargetException; -import java.net.URL; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.IExtensionRegistry; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.operation.IRunnableWithProgress; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation; -import org.eclipse.ui.dialogs.IOverwriteQuery; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -public class ExampleProjectCreationWizard extends Wizard implements INewWizard, IExecutableExtension { - - private class ImportOverwriteQuery implements IOverwriteQuery { - - private int openDialog(final String file) { - final int[] result = {IDialogConstants.CANCEL_ID}; - getShell().getDisplay().syncExec(new Runnable() { - public void run() { - String title = XMLWizardsMessages.ExampleProjectCreationWizard_overwritequery_title; - String msg = NLS.bind(XMLWizardsMessages.ExampleProjectCreationWizard_overwritequery_message, file); - String[] options = {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.YES_TO_ALL_LABEL, IDialogConstants.CANCEL_LABEL}; - MessageDialog dialog = new MessageDialog(getShell(), title, null, msg, MessageDialog.QUESTION, options, 0); - result[0] = dialog.open(); - } - }); - return result[0]; - } - - public String queryOverwrite(String file) { - String[] returnCodes = {YES, NO, ALL, CANCEL}; - int returnVal = openDialog(file); - return returnVal < 0 ? CANCEL : returnCodes[returnVal]; - } - } - - private IConfigurationElement wizardConfigElement; - private IConfigurationElement exampleConfigElement; - - private String EXAMPLE_WIZARD_XP_ID = "org.eclipse.wst.common.ui.exampleProjectCreationWizard"; //$NON-NLS-1$ - - private ExampleProjectCreationWizardPage[] pages; - - private final String WEB_BROWSER_ID = "org.eclipse.ui.browser.editor"; //$NON-NLS-1$ - - public ExampleProjectCreationWizard() { - super(); - setDialogSettings(XMLUIPlugin.getDefault().getDialogSettings()); - setWindowTitle(XMLWizardsMessages.ExampleProjectCreationWizard_title); - setNeedsProgressMonitor(true); - } - - /* - * @see Wizard#addPages - */ - public void addPages() { - super.addPages(); - - if (exampleConfigElement == null) { - return; - } - IConfigurationElement[] children = exampleConfigElement.getChildren("projectsetup"); //$NON-NLS-1$ - if ((children == null) || (children.length == 0)) { - Logger.log(Logger.ERROR, "descriptor must contain one ore more projectsetup tags"); //$NON-NLS-1$ - return; - } - - pages = new ExampleProjectCreationWizardPage[children.length]; - - for (int i = 0; i < children.length; i++) { - pages[i] = new ExampleProjectCreationWizardPage(i, children[i]); - addPage(pages[i]); - } - } - - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - if (exampleConfigElement != null) { - String banner = exampleConfigElement.getAttribute("banner"); //$NON-NLS-1$ - if (banner != null) { - URL imageURL = Platform.find(Platform.getBundle(exampleConfigElement.getDeclaringExtension().getNamespace()), new Path(banner)); - ImageDescriptor desc = ImageDescriptor.createFromURL(imageURL); - setDefaultPageImageDescriptor(desc); - } - } - } - - protected IConfigurationElement[] getExtendedConfigurationElements() { - IExtensionRegistry registry = Platform.getExtensionRegistry(); - IExtensionPoint exampleWizardXP = registry.getExtensionPoint(EXAMPLE_WIZARD_XP_ID); - if (exampleWizardXP == null) { - return new IConfigurationElement[0]; - } - IExtension extension = exampleWizardXP.getExtension(getWizardExtensionId()); - if (extension != null) { - return extension.getConfigurationElements(); - } - IConfigurationElement[] exampleWizardCEs = exampleWizardXP.getConfigurationElements(); - return exampleWizardCEs; - } - - private void handleException(Throwable target) { - String title = XMLWizardsMessages.ExampleProjectCreationWizard_op_error_title; - String message = XMLWizardsMessages.ExampleProjectCreationWizard_op_error_message; - if (target instanceof CoreException) { - IStatus status = ((CoreException) target).getStatus(); - ErrorDialog.openError(getShell(), title, message, status); - Logger.logException(status.getMessage(), status.getException()); - } - else { - MessageDialog.openError(getShell(), title, target.getMessage()); - Logger.logException(target); - } - } - - private void openResource(final IResource resource) { - if (resource.getType() != IResource.FILE) { - return; - } - IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - if (window == null) { - return; - } - final IWorkbenchPage activePage = window.getActivePage(); - if (activePage != null) { - final Display display = getShell().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - try { - IDE.openEditor(activePage, (IFile) resource, WEB_BROWSER_ID, true); - } - catch (PartInitException e) { - Logger.logException(e); - } - } - }); - BasicNewResourceWizard.selectAndReveal(resource, activePage.getWorkbenchWindow()); - } - } - - /* - * @see Wizard#performFinish - */ - public boolean performFinish() { - ExampleProjectCreationOperation runnable = new ExampleProjectCreationOperation(pages, new ImportOverwriteQuery()); - - IRunnableWithProgress op = new WorkspaceModifyDelegatingOperation(runnable); - try { - getContainer().run(false, true, op); - } - catch (InvocationTargetException e) { - handleException(e.getTargetException()); - return false; - } - catch (InterruptedException e) { - return false; - } - BasicNewProjectResourceWizard.updatePerspective(wizardConfigElement); - IResource res = runnable.getElementToOpen(); - if (res != null) { - openResource(res); - } - return true; - } - - /** - * Stores the configuration element for the wizard. The config element - * will be used in <code>performFinish</code> to set the result - * perspective. - */ - public void setInitializationData(IConfigurationElement cfig, String propertyName, Object data) { - wizardConfigElement = cfig; - String title = wizardConfigElement.getAttribute("name"); //$NON-NLS-1$ - if (title != null) { - setWindowTitle(title); - } - String wizardId = getWizardExtensionId(); - IConfigurationElement[] exampleWizardCEs = getExtendedConfigurationElements(); - for (int i = 0; i < exampleWizardCEs.length; i++) { - IConfigurationElement element = exampleWizardCEs[i]; - String extWizardId = element.getAttribute("id"); //$NON-NLS-1$ - if ((wizardId != null) && (extWizardId != null) && wizardId.equals(extWizardId)) { - exampleConfigElement = element; - } - } - // initializeDefaultPageImageDescriptor(); - } - - public String getWizardExtensionId() { - return wizardConfigElement.getAttribute("id"); //$NON-NLS-1$ - } - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java deleted file mode 100644 index 3f13b33942..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExampleProjectCreationWizardPage.java +++ /dev/null @@ -1,111 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2002, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * Jens Lukowski/Innoopract - initial renaming/restructuring - * - *******************************************************************************/ - -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.jface.wizard.IWizard; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.ui.dialogs.WizardNewProjectCreationPage; - -public class ExampleProjectCreationWizardPage extends WizardNewProjectCreationPage { - - private IConfigurationElement configurationElement; - - public ExampleProjectCreationWizardPage(int pageNumber, IConfigurationElement elem) { - - super("page" + pageNumber); //$NON-NLS-1$ - configurationElement = elem; - - String name = getAttribute(elem, "name"); //$NON-NLS-1$ - setInitialProjectName(calculateInitialProjectName(name)); - - setDescription(getAttribute(configurationElement, "pagedescription")); //$NON-NLS-1$ - setTitle(getAttribute(configurationElement, "pagetitle")); //$NON-NLS-1$ - - } - - /* - * Set the default project name that is to appear on the initialPage page - * of this wizard. - */ - protected String calculateInitialProjectName(String projectName) { - IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); - if (!projectHandle.exists()) { - return projectName; - } - // Change the name until it doesn't exists. Try 9 times and then - // give up. - for (int i = 1; i < 10; i++) { - projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName + i); - if (!projectHandle.exists()) { - return projectName + i; - } - } - return projectName + "9"; //$NON-NLS-1$ - - } - - private String getAttribute(IConfigurationElement elem, String tag) { - String res = elem.getAttribute(tag); - if (res == null) { - return '!' + tag + '!'; - } - return res; - } - - - - /** - * Returns the configuration element of this page. - * - * @return Returns a IConfigurationElement - */ - public IConfigurationElement getConfigurationElement() { - return configurationElement; - } - - /** - * @see org.eclipse.ui.dialogs.WizardNewProjectCreationPage#validatePage() - */ - protected boolean validatePage() { - if (!super.validatePage()) { - return false; - } - - String projectName = getProjectName(); - if (projectName == null) { - return false; - } - - IWizard wizard = getWizard(); - if (wizard instanceof ExampleProjectCreationWizard) { - IWizardPage[] pages = wizard.getPages(); - for (int i = 0; i < pages.length; i++) { - if ((pages[i] != this) && (pages[i] instanceof ExampleProjectCreationWizardPage)) { - if (projectName.equals(((ExampleProjectCreationWizardPage) pages[i]).getProjectName())) { - setErrorMessage(XMLWizardsMessages.ExampleProjectCreationWizardPage_error_alreadyexists); - return false; - } - } - } - } - - return true; - } - - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java deleted file mode 100644 index a0796829cc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ExportXMLCatalogWizard.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Export Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.io.File; - -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IExportWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; - -public class ExportXMLCatalogWizard extends BasicNewFileResourceWizard implements IExportWizard { - - protected WizardNewFileCreationPage exportPage = null; - protected ICatalog workingUserCatalog = null; - protected ICatalog userCatalog = null; - - public ExportXMLCatalogWizard() { - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - userCatalog = referencedCatalog; - } - } - } - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - workingUserCatalog.addEntriesFromCatalog(userCatalog); - - } - - public boolean performFinish() { - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IWorkspaceRoot workspaceRoot = workspace.getRoot(); - String workspacePath = workspaceRoot.getLocation().toOSString(); - String fullPath = workspacePath + exportPage.getContainerFullPath().toOSString(); - String requiredString=fullPath + File.separator + exportPage.getFileName(); - try { - exportPage.createNewFile(); - workingUserCatalog.setLocation(requiredString); - workingUserCatalog.save(); - } catch (Exception ex) { - return false; - } - return true; - } - - public void addPages() { - exportPage = new WizardNewFileCreationPage("XML Catalog Export", getSelection()); - exportPage.setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - exportPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION); - addPage(exportPage); - } - - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - super.init(workbench, currentSelection); - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_EXPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java deleted file mode 100644 index e342efae4f..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/IXMLWizardHelpContextIds.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; - -/** - * Help context ids for the xml wizard. - * <p> - * This interface contains constants only; it is not intended to be - * implemented. - * </p> - */ -interface IXMLWizardHelpContextIds { - // org.eclipse.wst.xml.ui. - public static final String PREFIX = XMLUIPlugin.ID + "."; //$NON-NLS-1$ - // Create XML file from a DTD file radio - public static final String XML_NEWWIZARD_CREATEXML1_HELPID = PREFIX + "xmlc0101"; //$NON-NLS-1$ - // Create XML file from an XML schema file radio button - public static final String XML_NEWWIZARD_CREATEXML2_HELPID = PREFIX + "xmlc0102"; //$NON-NLS-1$ - // Create XML file from scratch radio button - public static final String XML_NEWWIZARD_CREATEXML3_HELPID = PREFIX + "xmlc0103"; //$NON-NLS-1$ - // Select Source file page - public static final String XML_NEWWIZARD_SELECTSOURCE_HELPID = PREFIX + "xmlc0500"; //$NON-NLS-1$ - // Root element for both DTD and XML schema - public static final String XML_NEWWIZARD_SELECTROOTELEMENT_HELPID = PREFIX + "xmlc0410"; //$NON-NLS-1$ - // Create Optional Attributes - public static final String XML_NEWWIZARD_SELECTROOTELEMENT1_HELPID = PREFIX + "xmlc0441"; //$NON-NLS-1$ - // Create Optional Elements - public static final String XML_NEWWIZARD_SELECTROOTELEMENT2_HELPID = PREFIX + "xmlc0442"; //$NON-NLS-1$ - // Create first choice of required choice - public static final String XML_NEWWIZARD_SELECTROOTELEMENT3_HELPID = PREFIX + "xmlc0443"; //$NON-NLS-1$ - // Fill elements and attribute with data - public static final String XML_NEWWIZARD_SELECTROOTELEMENT4_HELPID = PREFIX + "xmlc0444"; //$NON-NLS-1$ - // System ID for DTD - public static final String XML_NEWWIZARD_SELECTROOTELEMENT5_HELPID = PREFIX + "xmlc0210"; //$NON-NLS-1$ - // Public ID for DTD - public static final String XML_NEWWIZARD_SELECTROOTELEMENT6_HELPID = PREFIX + "xmlc0220"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java deleted file mode 100644 index 38e3447da2..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogPage.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Import Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.wst.common.ui.internal.viewers.SelectSingleFileView; - -public class ImportXMLCatalogPage extends WizardPage { - - protected SelectSingleFileView selectSingleFileView; - protected IStructuredSelection selection; - - - public ImportXMLCatalogPage() { - super(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - setTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - selection = new StructuredSelection(); - selectSingleFileView = new SelectSingleFileView(selection, false) { - public void createFilterControl(Composite composite) { - ImportXMLCatalogPage.this.createFilterControl(composite); - } - }; - - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NULL); - composite.setLayout(new GridLayout()); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = 350; - gd.heightHint = 350; - composite.setLayoutData(gd); - String[] extensions = { ".xmlcatalog", ".xml" }; //$NON-NLS-1$ //$NON-NLS-2$ - selectSingleFileView.addFilterExtensions(extensions); - selectSingleFileView.createControl(composite); - selectSingleFileView.setVisibleHelper(true); - selectSingleFileView.addSelectionChangedTreeListener(new ISelectionChangedListener(){ - public void selectionChanged(SelectionChangedEvent event) { - ImportXMLCatalogPage.this.setPageComplete(selectSingleFileView.getFile() != null); - } - }); - setControl(composite); - } - - public void createFilterControl(Composite composite) { - } - - public IFile getFile() { - return selectSingleFileView.getFile(); - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java deleted file mode 100644 index f1200a2478..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/ImportXMLCatalogWizard.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail (STAR) and - * others. All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Carver/STAR - dcarver@starstandard.org/d_a_carver@yahoo.com - bug 192568 - * Initial API - This implements the functionality of the - * old Import Dialog for the XML Catalog. - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.ui.IImportWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.CatalogSet; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog; -import org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog; -import org.eclipse.wst.xml.ui.internal.catalog.XMLCatalogMessages; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; - -public class ImportXMLCatalogWizard extends Wizard implements IImportWizard { - - protected ImportXMLCatalogPage importPage = null; - protected ICatalog workingUserCatalog = null; - protected ICatalog userCatalog = null; - - public ImportXMLCatalogWizard() { - setWindowTitle(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog(); - INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs(); - for (int i = 0; i < nextCatalogs.length; i++) { - INextCatalog catalog = nextCatalogs[i]; - ICatalog referencedCatalog = catalog.getReferencedCatalog(); - if (referencedCatalog != null) { - if (XMLCorePlugin.USER_CATALOG_ID.equals(referencedCatalog.getId())) { - userCatalog = referencedCatalog; - } - } - } - - CatalogSet tempCatalogSet = new CatalogSet(); - workingUserCatalog = tempCatalogSet.lookupOrCreateCatalog("working", ""); //$NON-NLS-1$ //$NON-NLS-2$ - workingUserCatalog.addEntriesFromCatalog(userCatalog); - } - - public boolean canFinish() { - return importPage.isPageComplete(); - } - - public boolean performFinish() { - IFile file = importPage.getFile(); - if (file != null) { - String fileName = file.getLocation().toFile().toURI().toString(); - try { - CatalogSet tempResourceSet = new CatalogSet(); - ICatalog newCatalog = tempResourceSet.lookupOrCreateCatalog("temp", fileName); //$NON-NLS-1$ - - workingUserCatalog.addEntriesFromCatalog(newCatalog); - userCatalog.clear(); - userCatalog.addEntriesFromCatalog(workingUserCatalog); - userCatalog.save(); - } - catch (Exception e) { - return false; - } - } - - return true; - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - // TODO Auto-generated method stub - - } - - public void addPages() { - importPage = new ImportXMLCatalogPage(); - importPage.setTitle(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_HEADING); - importPage.setDescription(XMLWizardsMessages._UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION); - importPage.setMessage(XMLCatalogMessages.UI_LABEL_IMPORT_DIALOG_MESSAGE); - addPage(importPage); - importPage.setPageComplete(false); - } -} - - diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java deleted file mode 100644 index 09eed81a69..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NamespaceInfoContentBuilder.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Hashtable; -import java.util.List; -import java.util.Vector; - -import org.eclipse.wst.xml.core.internal.contentmodel.CMAnyElement; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.util.ContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; - -public class NamespaceInfoContentBuilder extends ContentBuilder { - protected int count = 1; - public List list = new Vector(); - protected Hashtable table = new Hashtable(); - - public NamespaceInfoContentBuilder() { - super(); - } - - public void visitCMElementDeclaration(CMElementDeclaration ed) { - if (ed.getProperty("http://org.eclipse.wst/cm/properties/definitionInfo") != null) //$NON-NLS-1$ - { - super.visitCMElementDeclaration(ed); - } - } - - protected void createAnyElementNode(CMAnyElement anyElement) { - String uri = anyElement.getNamespaceURI(); - if ((uri != null) && !uri.startsWith("##")) //$NON-NLS-1$ - { - if (table.get(uri) == null) { - NamespaceInfo info = new NamespaceInfo(); - info.uri = uri; - info.prefix = "p" + count++; //$NON-NLS-1$ - table.put(uri, info); - list.add(info); - } - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java deleted file mode 100644 index 9cfcd23801..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewModelWizard.java +++ /dev/null @@ -1,325 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.Wizard; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.osgi.util.NLS; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.INewWizard; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.dialogs.WizardNewFileCreationPage; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; - -public class NewModelWizard extends Wizard implements INewWizard { - - protected IStructuredSelection fSelection; - protected IWorkbench fWorkbench; - protected String fCurrentDirectory; - - public NewModelWizard() { - super(); - } - - public void init(IWorkbench workbench, IStructuredSelection selection) { - this.fWorkbench = workbench; - this.fSelection = selection; - } - - public boolean performFinish() { - boolean result = true; - WizardPage currentPage = (WizardPage) getContainer().getCurrentPage(); - if (currentPage != null) { - result = currentPage.isPageComplete(); - } - return result; - } - - /** - * showFileDialog - */ - public FileDialog showFileDialog(Shell shell, String defaultDirectory, String defaultFile, String[] filterExtensions) { - FileDialog fileDialog = new FileDialog(shell, SWT.OPEN); - - // Get the last visit directory if we haven't defined a particular one - // here. - if ((defaultDirectory == null) || (defaultDirectory.length() == 0)) { - // defaultDirectory = - // Locate.instance(this).getLastSelectedDirectory(getResourcePath()); - } - - if ((defaultDirectory != null) && (defaultDirectory.length() != 0)) { - fileDialog.setFilterPath(defaultDirectory); - } - - fileDialog.setFileName(defaultFile); - fileDialog.setFilterExtensions(filterExtensions); - - fileDialog.open(); - - return fileDialog; - } - - - public void setCurrentDirectory(String currentDirectory1) { - this.fCurrentDirectory = currentDirectory1; - } - - - public void createWorkbenchResource(IContainer container, String fileName) { - IPath path = container.getFullPath(); - path = path.append(fileName); - IFile file = container.getWorkspace().getRoot().getFile(path); - if (!file.exists()) { - try { - file.create(null, true, null); - } - catch (CoreException e) { - // XMLBuilderPlugin.getPlugin().getMsgLogger().write("Encountered - // exception creating file: " + e.getMessage()); - } - } - } - - /** - * StartPage - */ - public class StartPage extends WizardPage implements Listener { - protected int selectedButton; - protected String[] radioButtonLabel; - protected Button[] radioButton; - - public StartPage(String pageName, String[] radioButtonLabel) { - super(pageName); - this.radioButtonLabel = radioButtonLabel; - radioButton = new Button[radioButtonLabel.length]; - } - - public Button getRadioButtonAtIndex(int i) { - Button result = null; - if ((i >= 0) && (i < radioButton.length)) { - result = radioButton[i]; - } - return result; - } - - public int getSelectedRadioButtonIndex() { - int result = -1; - for (int i = 0; i < radioButton.length; i++) { - if (radioButton[i].getSelection()) { - result = i; - } - } - return result; - } - - public void createControl(Composite parent) { - Composite base = new Composite(parent, SWT.NONE); - base.setLayout(new GridLayout()); - - // radio buttons' container - Composite radioButtonsGroup = new Composite(base, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.makeColumnsEqualWidth = true; - layout.marginWidth = 0; - - radioButtonsGroup.setLayout(layout); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.heightHint = 300; - gd.widthHint = 400; - radioButtonsGroup.setLayoutData(gd); - - for (int i = 0; i < radioButtonLabel.length; i++) { - radioButton[i] = new Button(radioButtonsGroup, SWT.RADIO); - radioButton[i].setText(radioButtonLabel[i]); - radioButton[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - // radioButton[i].addListener(SWT.Modify, this); - } - setControl(base); - setPageComplete(isPageComplete()); - Dialog.applyDialogFont(parent); - } - - public void handleEvent(Event event) { - if (event.type == SWT.Modify) { - setPageComplete(isPageComplete()); - } - } - } - - - /** - * NewFilePage - */ - public class NewFilePage extends WizardNewFileCreationPage { - public String defaultName = "NewFile"; //$NON-NLS-1$ - public String defaultFileExtension = ".txt"; //$NON-NLS-1$ - public String[] filterExtensions = {"*.txt"}; //$NON-NLS-1$ - private List fValidExtensions = null; - - public NewFilePage(IStructuredSelection selection) { - super("", selection); //$NON-NLS-1$ - } - - protected String computeDefaultFileName() { - int count = 0; - String fileName = defaultName + defaultFileExtension; - IPath containerFullPath = getContainerFullPath(); - if (containerFullPath != null) { - while (true) { - IPath path = containerFullPath.append(fileName); - if (ResourcesPlugin.getWorkspace().getRoot().exists(path)) { - count++; - fileName = defaultName + count + defaultFileExtension; - } - else { - break; - } - } - } - return fileName; - } - - // returns true if file of specified name exists in any case for - // selected container - protected String existsFileAnyCase(String fileName) { - if ((getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) && (fileName.compareTo("") != 0)) //$NON-NLS-1$ - { - // look through all resources at the specified container - - // compare in upper case - IResource parent = ResourcesPlugin.getWorkspace().getRoot().findMember(getContainerFullPath()); - if (parent instanceof IContainer) { - IContainer container = (IContainer) parent; - try { - IResource[] members = container.members(); - String enteredFileUpper = fileName.toUpperCase(); - for (int i = 0; i < members.length; i++) { - String resourceUpperName = members[i].getName().toUpperCase(); - if (resourceUpperName.equals(enteredFileUpper)) { - return members[i].getName(); - } - } - } - catch (CoreException e) { - } - } - } - return null; - } - - - protected boolean validatePage() { - String fullFileName = getFileName(); - if (!extensionValidForContentType(fullFileName)) { - setErrorMessage(NLS.bind(XMLWizardsMessages._ERROR_BAD_FILENAME_EXTENSION, getValidExtensions().toString())); - return false; - } - // no fileExtension, let's check for this file with default file - // extension - fullFileName += defaultFileExtension; - if ((getContainerFullPath() != null) && (getContainerFullPath().isEmpty() == false) && (getFileName().compareTo("") != 0)) //$NON-NLS-1$ - { - Path fullPath = new Path(getContainerFullPath().toString() + '/' + fullFileName); - IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(fullPath); - if (resource != null) { - setErrorMessage(XMLWizardsMessages._ERROR_FILE_ALREADY_EXISTS); - return false; - } - } - - // check for file should be case insensitive - String sameName = existsFileAnyCase(fullFileName); - if (sameName != null) { - // ISSUE: is qualitifedFileName not needed, or is it supposed - // to be used in error message? - // String qualifiedFileName = - // getContainerFullPath().toString() + '/' + fullFileName; - setErrorMessage(XMLWizardsMessages._ERROR_FILE_ALREADY_EXISTS + " " + sameName); //$NON-NLS-1$ - return false; - } - - return super.validatePage(); - } - - public void createControl(Composite parent) { - // inherit default container and name specification widgets - super.createControl(parent); - this.setFileName(computeDefaultFileName()); - setPageComplete(validatePage()); - } - - /** - * Get list of valid extensions for XML Content type - * - * @return List - */ - List getValidExtensions() { - if (fValidExtensions == null) { - IContentType type = Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - 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 = Platform.getContentTypeManager().getContentType(ContentTypeIdForXML.ContentTypeID_XML); - // 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; - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java deleted file mode 100644 index 406a4063d9..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLGenerator.java +++ /dev/null @@ -1,412 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import javax.xml.parsers.DocumentBuilderFactory; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.core.runtime.content.IContentType; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.core.runtime.preferences.InstanceScope; -import org.eclipse.jface.util.Assert; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver; -import org.eclipse.wst.common.uriresolver.internal.provisional.URIResolverPlugin; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.sse.core.internal.encoding.CommonEncodingPreferenceNames; -import org.eclipse.wst.sse.core.utils.StringUtils; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager; -import org.eclipse.wst.xml.core.internal.contentmodel.util.ContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilderImpl; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMWriter; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -public class NewXMLGenerator { - - protected String grammarURI; - protected CMDocument cmDocument; - protected int buildPolicy; - protected String rootElementName; - - protected ICatalogEntry xmlCatalogEntry; - - // info for dtd - protected String publicId; - protected String systemId; - protected String defaultSystemId; - - // info for xsd - public List namespaceInfoList; - - public NewXMLGenerator() { - super(); - } - - public NewXMLGenerator(String grammarURI, CMDocument cmDocument) { - this.grammarURI = grammarURI; - this.cmDocument = cmDocument; - } - - - public static CMDocument createCMDocument(String uri, String[] errorInfo) { - String title = null; - String message = null; - List errorList = new Vector(); - CMDocument cmDocument = null; - - if (URIHelper.isReadableURI(uri, true)) { - // (cs) assume the uri has been provided in a normalized form - cmDocument = ContentModelManager.getInstance().createCMDocument(uri, null); - - if (uri.endsWith(".dtd")) { //$NON-NLS-1$ - if (errorList.size() > 0) { - title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR; - message = XMLWizardsMessages._UI_LABEL_ERROR_DTD_INVALID_INFO; - } - } - else // ".xsd" - { - // To be consistent with the schema editor validation - XMLSchemaValidationChecker validator = new XMLSchemaValidationChecker(); - if (!validator.isValid(uri)) { - title = XMLWizardsMessages._UI_INVALID_GRAMMAR_ERROR; - message = XMLWizardsMessages._UI_LABEL_ERROR_SCHEMA_INVALID_INFO; - } - else if (cmDocument != null) { - int globalElementCount = cmDocument.getElements().getLength(); - if (globalElementCount == 0) { - title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - message = XMLWizardsMessages._UI_WARNING_MSG_NO_ROOT_ELEMENTS; - } - } - } - } - else { - title = XMLWizardsMessages._UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - message = XMLWizardsMessages._UI_WARNING_URI_NOT_FOUND_COLON + " " + uri; //$NON-NLS-1$ - } - errorInfo[0] = title; - errorInfo[1] = message; - - return cmDocument; - } - - private String applyLineDelimiter(IFile file, String text) { - String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, System.getProperty("line.separator"), new IScopeContext[] {new ProjectScope(file.getProject()), new InstanceScope() });//$NON-NLS-1$ - String convertedText = StringUtils.replace(text, "\r\n", "\n"); - convertedText = StringUtils.replace(convertedText, "\r", "\n"); - convertedText = StringUtils.replace(convertedText, "\n", lineDelimiter); - return convertedText; - } - - /** - * @deprecated use createTemplateXMLDocument(IFile, String) instead - */ - public void createEmptyXMLDocument(IFile newFile) throws Exception { - String charSet = getUserPreferredCharset(); - String contents = "<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>"; //$NON-NLS-1$ //$NON-NLS-2$ - createTemplateXMLDocument(newFile, contents); - } - - void createTemplateXMLDocument(IFile newFile, String contents) throws Exception { - if (contents != null) { - String charSet = getUserPreferredCharset(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - - PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet)); - contents = applyLineDelimiter(newFile, contents); - writer.println(contents); - writer.flush(); - outputStream.close(); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - } - - private String getUserPreferredCharset() { - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET); - return charSet; - } - - public void createXMLDocument(String xmlFileName) throws Exception { - IContentType contentType = Platform.getContentTypeManager().findContentTypeFor(xmlFileName); - String charset = null; - if (contentType != null) { - charset = contentType.getDefaultCharset(); - } - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset); - - File file = new File(xmlFileName); - FileOutputStream fos = new FileOutputStream(file); - outputStream.writeTo(fos); - fos.close(); - } - - - public void createXMLDocument(IFile newFile, String xmlFileName) throws Exception { - String charset = newFile.getCharset(); - ByteArrayOutputStream outputStream = createXMLDocument(xmlFileName, charset); - - String contents = outputStream.toString(charset); - contents = applyLineDelimiter(newFile, contents); - - ByteArrayInputStream inputStream = new ByteArrayInputStream(contents.getBytes(charset)); - newFile.setContents(inputStream, true, true, null); - inputStream.close(); - } - - - public ByteArrayOutputStream createXMLDocument(String xmlFileName, String charset) throws Exception { - if (charset == null) { - charset = getUserPreferredCharset(); - if (charset == null) { - charset = "UTF-8"; //$NON-NLS-1$ - } - } - CMDocument cmDocument = getCMDocument(); - - Assert.isNotNull(cmDocument); - Assert.isNotNull(getRootElementName()); - - // create the xml model - CMNamedNodeMap nameNodeMap = cmDocument.getElements(); - CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.getNamedItem(getRootElementName()); - - Document xmlDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); - DOMContentBuilderImpl contentBuilder = new DOMContentBuilderImpl(xmlDocument); - - // this 'uglyTempHack' flag is required in order to supress the - // creation a default encoding - // we'll handle this later in the domWriter.print() method used below - // - contentBuilder.supressCreationOfDoctypeAndXMLDeclaration = true; - contentBuilder.setBuildPolicy(buildPolicy); - contentBuilder.setExternalCMDocumentSupport(new MyExternalCMDocumentSupport(namespaceInfoList, xmlFileName)); - contentBuilder.createDefaultRootContent(cmDocument, cmElementDeclaration, namespaceInfoList); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset); - - DOMWriter domWriter = new DOMWriter(outputStreamWriter); - - // TODO... instead of relying on file extensions, we need to keep - // track of the grammar type - // better yet we should reate an SSE document so that we can format it - // nicely before saving - // then we won't need the DOMWriter at all - // - domWriter.print(xmlDocument, charset, cmDocument.getNodeName(), getNonWhitespaceString(getPublicId()), getNonWhitespaceString(getSystemId())); - outputStream.flush(); - outputStream.close(); - - return outputStream; - } - - - public void createNamespaceInfoList() { - List result = new Vector(); - if (cmDocument != null) { - result = (List) cmDocument.getProperty("http://org.eclipse.wst/cm/properties/completeNamespaceInfo"); //$NON-NLS-1$ - if (result != null) { - int size = result.size(); - for (int i = 0; i < size; i++) { - NamespaceInfo info = (NamespaceInfo) result.get(i); - if (i == 0) { - String locationInfo = null; - if (xmlCatalogEntry != null) { - if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) { - locationInfo = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL); - } - else { - locationInfo = xmlCatalogEntry.getKey(); - } - } - if (locationInfo == null) { - locationInfo = defaultSystemId; - } - info.locationHint = locationInfo; - info.setProperty("locationHint-readOnly", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - info.setProperty("uri-readOnly", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - info.setProperty("unremovable", "true"); //$NON-NLS-1$ //$NON-NLS-2$ - } else { - info.locationHint = null; - } - } - } - - NamespaceInfoContentBuilder builder = new NamespaceInfoContentBuilder(); - builder.setBuildPolicy(ContentBuilder.BUILD_ONLY_REQUIRED_CONTENT); - builder.visitCMNode(cmDocument); - result.addAll(builder.list); - } - namespaceInfoList = result; - } - - - public boolean isMissingNamespaceLocation() { - boolean result = false; - for (Iterator i = namespaceInfoList.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (info.locationHint == null) { - result = true; - break; - } - } - return result; - } - - - public String[] getNamespaceInfoErrors() { - String[] errorList = null; - -// No warnings should be given when namespaces entries have missing location hints -// See https://bugs.eclipse.org/bugs/show_bug.cgi?id=105128 -// if ((namespaceInfoList != null) && isMissingNamespaceLocation()) { -// String title = XMLWizardsMessages._UI_LABEL_NO_LOCATION_HINT; -// String message = XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_1 + " " + XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_2 + "\n\n" + XMLWizardsMessages._UI_WARNING_MSG_NO_LOCATION_HINT_3; //$NON-NLS-1$ //$NON-NLS-2$ -// -// errorList = new String[2]; -// errorList[0] = title; -// errorList[1] = message; -// } - return errorList; - } - - - public void setXMLCatalogEntry(ICatalogEntry catalogEntry) { - xmlCatalogEntry = catalogEntry; - } - - public ICatalogEntry getXMLCatalogEntry() { - return xmlCatalogEntry; - } - - - public void setBuildPolicy(int policy) { - buildPolicy = policy; - } - - - public void setDefaultSystemId(String sysId) { - defaultSystemId = sysId; - } - - public String getDefaultSystemId() { - return defaultSystemId; - } - - public void setSystemId(String sysId) { - systemId = sysId; - } - - public String getSystemId() { - return systemId; - } - - public void setPublicId(String pubId) { - publicId = pubId; - } - - public String getPublicId() { - return publicId; - } - - public void setGrammarURI(String gramURI) { - grammarURI = gramURI; - } - - public String getGrammarURI() { - return grammarURI; - } - - public void setCMDocument(CMDocument cmDoc) { - cmDocument = cmDoc; - } - - public CMDocument getCMDocument() { - return cmDocument; - } - - public void setRootElementName(String rootName) { - rootElementName = rootName; - } - - public String getRootElementName() { - return rootElementName; - } - - - protected class MyExternalCMDocumentSupport implements DOMContentBuilderImpl.ExternalCMDocumentSupport { - protected List namespaceInfoList1; - protected URIResolver idResolver; - protected String resourceLocation; - - protected MyExternalCMDocumentSupport(List namespaceInfoListParam, String resourceLocation) { - this.namespaceInfoList1 = namespaceInfoListParam; - this.resourceLocation = resourceLocation; - idResolver = URIResolverPlugin.createResolver(); - } - - public CMDocument getCMDocument(Element element, String namespaceURI) { - CMDocument result = null; - if ((namespaceURI != null) && (namespaceURI.trim().length() > 0)) { - String locationHint = null; - for (Iterator i = namespaceInfoList1.iterator(); i.hasNext();) { - NamespaceInfo info = (NamespaceInfo) i.next(); - if (namespaceURI.equals(info.uri)) { - locationHint = info.locationHint; - break; - } - } - if (locationHint != null) { - grammarURI = idResolver.resolve(resourceLocation, locationHint, locationHint); - result = ContentModelManager.getInstance().createCMDocument(getGrammarURI(), null); - } - } - else { - result = cmDocument; - } - return result; - } - } - - public static String getNonWhitespaceString(String string) { - String result = null; - if (string != null) { - if (string.trim().length() > 0) { - result = string; - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java deleted file mode 100644 index 38c2669350..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Standards for Technology in Automotive Retail and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * David Carver - initial API and implementation, bug 212330 - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Iterator; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.commands.IHandler; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.handlers.HandlerUtil; - -public class NewXMLHandler extends AbstractHandler implements IHandler { - - /** - * - */ - public NewXMLHandler() { - super(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent) - */ - public Object execute(ExecutionEvent event) throws ExecutionException { - IWorkbenchWindow workbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event); - ISelection selection = workbenchWindow.getSelectionService().getSelection(); - Object selectedObject = getSelection(selection); - - if ((selectedObject instanceof IFile) && (selection instanceof IStructuredSelection)) { - IFile file = (IFile) selectedObject; - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - try { - NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); - } - catch (Exception e) { - // XMLCorePlugin.getDefault().getLog().log(); - } - } - return null; - } - - public static Object getSelection(ISelection selection) { - if (selection == null) { - return null; - } - - Object result = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - Iterator i = es.iterator(); - if (i.hasNext()) { - result = i.next(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java deleted file mode 100644 index 929a01f762..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLTemplatesWizardPage.java +++ /dev/null @@ -1,508 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.preference.PreferenceDialog; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.text.source.SourceViewerConfiguration; -import org.eclipse.jface.text.templates.DocumentTemplateContext; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.TemplateBuffer; -import org.eclipse.jface.text.templates.TemplateContext; -import org.eclipse.jface.text.templates.TemplateContextType; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TableLayout; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerSorter; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlAdapter; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.eclipse.swt.widgets.Table; -import org.eclipse.swt.widgets.TableColumn; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.PreferencesUtil; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.internal.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.provisional.style.LineStyleProvider; -import org.eclipse.wst.xml.core.internal.provisional.contenttype.ContentTypeIdForXML; -import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.XMLUIPlugin; -import org.eclipse.wst.xml.ui.internal.editor.IHelpContextIds; -import org.eclipse.wst.xml.ui.internal.preferences.XMLUIPreferenceNames; -import org.eclipse.wst.xml.ui.internal.templates.TemplateContextTypeIdsXML; - -/** - * Templates page in new file wizard. Allows users to select a new file - * template to be applied in new file. - * - */ -public class NewXMLTemplatesWizardPage extends WizardPage { - - /** - * Content provider for templates - */ - private class TemplateContentProvider implements IStructuredContentProvider { - /** The template store. */ - private TemplateStore fStore; - - /* - * @see IContentProvider#dispose() - */ - public void dispose() { - fStore = null; - } - - /* - * @see IStructuredContentProvider#getElements(Object) - */ - public Object[] getElements(Object input) { - return fStore.getTemplates(TemplateContextTypeIdsXML.NEW); - } - - /* - * @see IContentProvider#inputChanged(Viewer, Object, Object) - */ - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - fStore = (TemplateStore) newInput; - } - } - - /** - * Label provider for templates. - */ - private class TemplateLabelProvider extends LabelProvider implements ITableLabelProvider { - - /* - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, - * int) - */ - public Image getColumnImage(Object element, int columnIndex) { - return null; - } - - /* - * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, - * int) - */ - public String getColumnText(Object element, int columnIndex) { - Template template = (Template) element; - - switch (columnIndex) { - case 0 : - return template.getName(); - case 1 : - return template.getDescription(); - default : - return ""; //$NON-NLS-1$ - } - } - } - - /** Last selected template name */ - private String fLastSelectedTemplateName; - /** The viewer displays the pattern of selected template. */ - private SourceViewer fPatternViewer; - /** The table presenting the templates. */ - private TableViewer fTableViewer; - /** Template store used by this wizard page */ - private TemplateStore fTemplateStore; - /** Checkbox for using templates. */ - private Button fUseTemplateButton; - - public NewXMLTemplatesWizardPage() { - super("NewXMLTemplatesWizardPage", XMLWizardsMessages.NewXMLTemplatesWizardPage_0, null); //$NON-NLS-1$ - setDescription(XMLWizardsMessages.NewXMLTemplatesWizardPage_1); - } - - /** - * Correctly resizes the table so no phantom columns appear - * - * @param parent - * the parent control - * @param buttons - * the buttons - * @param table - * the table - * @param column1 - * the first column - * @param column2 - * the second column - * @param column3 - * the third column - */ - private void configureTableResizing(final Composite parent, final Table table, final TableColumn column1, final TableColumn column2) { - parent.addControlListener(new ControlAdapter() { - public void controlResized(ControlEvent e) { - Rectangle area = parent.getClientArea(); - Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT); - int width = area.width - 2 * table.getBorderWidth(); - if (preferredSize.y > area.height) { - // Subtract the scrollbar width from the total column - // width - // if a vertical scrollbar will be required - Point vBarSize = table.getVerticalBar().getSize(); - width -= vBarSize.x; - } - - Point oldSize = table.getSize(); - if (oldSize.x > width) { - // table is getting smaller so make the columns - // smaller first and then resize the table to - // match the client area width - column1.setWidth(width / 2); - column2.setWidth(width / 2); - table.setSize(width, area.height); - } - else { - // table is getting bigger so make the table - // bigger first and then make the columns wider - // to match the client area width - table.setSize(width, area.height); - column1.setWidth(width / 2); - column2.setWidth(width / 2); - } - } - }); - } - - public void createControl(Composite ancestor) { - Composite parent = new Composite(ancestor, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - parent.setLayout(layout); - - // create checkbox for user to use XML Template - fUseTemplateButton = new Button(parent, SWT.CHECK); - fUseTemplateButton.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_4); - GridData data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); - fUseTemplateButton.setLayoutData(data); - fUseTemplateButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - enableTemplates(); - } - }); - - // create composite for Templates table - Composite innerParent = new Composite(parent, SWT.NONE); - GridLayout innerLayout = new GridLayout(); - innerLayout.numColumns = 2; - innerLayout.marginHeight = 0; - innerLayout.marginWidth = 0; - innerParent.setLayout(innerLayout); - GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1); - innerParent.setLayoutData(gd); - - // Create linked text to just to templates preference page - Link link = new Link(innerParent, SWT.NONE); - link.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_6); - data = new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1); - link.setLayoutData(data); - link.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - linkClicked(); - } - }); - - // create table that displays templates - Table table = new Table(innerParent, SWT.BORDER | SWT.FULL_SELECTION); - - data = new GridData(GridData.FILL_BOTH); - data.widthHint = convertWidthInCharsToPixels(2); - data.heightHint = convertHeightInCharsToPixels(10); - data.horizontalSpan = 2; - table.setLayoutData(data); - table.setHeaderVisible(true); - table.setLinesVisible(true); - TableLayout tableLayout = new TableLayout(); - table.setLayout(tableLayout); - - TableColumn column1 = new TableColumn(table, SWT.NONE); - column1.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_2); - - TableColumn column2 = new TableColumn(table, SWT.NONE); - column2.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_3); - - fTableViewer = new TableViewer(table); - fTableViewer.setLabelProvider(new TemplateLabelProvider()); - fTableViewer.setContentProvider(new TemplateContentProvider()); - - fTableViewer.setSorter(new ViewerSorter() { - public int compare(Viewer viewer, Object object1, Object object2) { - if ((object1 instanceof Template) && (object2 instanceof Template)) { - Template left = (Template) object1; - Template right = (Template) object2; - int result = left.getName().compareToIgnoreCase(right.getName()); - if (result != 0) { - return result; - } - return left.getDescription().compareToIgnoreCase(right.getDescription()); - } - return super.compare(viewer, object1, object2); - } - - public boolean isSorterProperty(Object element, String property) { - return true; - } - }); - - fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent e) { - updateViewerInput(); - } - }); - - // create viewer that displays currently selected template's contents - fPatternViewer = doCreateViewer(parent); - - fTemplateStore = XMLUIPlugin.getDefault().getTemplateStore(); - fTableViewer.setInput(fTemplateStore); - - configureTableResizing(innerParent, table, column1, column2); - loadLastSavedPreferences(); - - PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.XML_NEWWIZARD_TEMPLATE_HELPID); - Dialog.applyDialogFont(parent); - setControl(parent); - } - - /** - * Creates, configures and returns a source viewer to present the template - * pattern on the preference page. Clients may override to provide a - * custom source viewer featuring e.g. syntax coloring. - * - * @param parent - * the parent control - * @return a configured source viewer - */ - private SourceViewer createViewer(Composite parent) { - SourceViewerConfiguration sourceViewerConfiguration = new StructuredTextViewerConfiguration() { - StructuredTextViewerConfiguration baseConfiguration = new StructuredTextViewerConfigurationXML(); - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return baseConfiguration.getConfiguredContentTypes(sourceViewer); - } - - public LineStyleProvider[] getLineStyleProviders(ISourceViewer sourceViewer, String partitionType) { - return baseConfiguration.getLineStyleProviders(sourceViewer, partitionType); - } - }; - SourceViewer viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); - ((StructuredTextViewer) viewer).getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ - IStructuredModel scratchModel = StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML); - IDocument document = scratchModel.getStructuredDocument(); - viewer.configure(sourceViewerConfiguration); - viewer.setDocument(document); - return viewer; - } - - private SourceViewer doCreateViewer(Composite parent) { - Label label = new Label(parent, SWT.NONE); - label.setText(XMLWizardsMessages.NewXMLTemplatesWizardPage_5); - GridData data = new GridData(); - data.horizontalSpan = 2; - label.setLayoutData(data); - - SourceViewer viewer = createViewer(parent); - viewer.setEditable(false); - - Control control = viewer.getControl(); - data = new GridData(GridData.FILL_BOTH); - data.horizontalSpan = 2; - data.heightHint = convertHeightInCharsToPixels(5); - control.setLayoutData(data); - - return viewer; - } - - /** - * Enable/disable controls in page based on fUseTemplateButton's current - * state. - */ - void enableTemplates() { - boolean enabled = fUseTemplateButton.getSelection(); - - if (!enabled) { - // save last selected template - Template template = getSelectedTemplate(); - if (template != null) { - fLastSelectedTemplateName = template.getName(); - } - else { - fLastSelectedTemplateName = ""; //$NON-NLS-1$ - } - - fTableViewer.setSelection(null); - } - else { - setSelectedTemplate(fLastSelectedTemplateName); - } - - fTableViewer.getControl().setEnabled(enabled); - fPatternViewer.getControl().setEnabled(enabled); - } - - /** - * Return the template preference page id - * - * @return - */ - private String getPreferencePageId() { - return "org.eclipse.wst.sse.ui.preferences.xml.templates"; //$NON-NLS-1$ - } - - /** - * Get the currently selected template. - * - * @return - */ - private Template getSelectedTemplate() { - Template template = null; - IStructuredSelection selection = (IStructuredSelection) fTableViewer.getSelection(); - - if (selection.size() == 1) { - template = (Template) selection.getFirstElement(); - } - return template; - } - - /** - * Returns template string to insert. - * - * @return String to insert or null if none is to be inserted - */ - String getTemplateString() { - String templateString = null; - - Template template = getSelectedTemplate(); - if (template != null) { - TemplateContextType contextType = XMLUIPlugin.getDefault().getTemplateContextRegistry().getContextType(TemplateContextTypeIdsXML.NEW); - IDocument document = new Document(); - TemplateContext context = new DocumentTemplateContext(contextType, document, 0, 0); - try { - TemplateBuffer buffer = context.evaluate(template); - templateString = buffer.getString(); - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, "Could not create template for new xml", e); //$NON-NLS-1$ - } - } - - return templateString; - } - - void linkClicked() { - String pageId = getPreferencePageId(); - PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(getShell(), pageId, new String[]{pageId}, null); - dialog.open(); - fTableViewer.refresh(); - } - - /** - * Load the last template name used in New XML File wizard. - */ - private void loadLastSavedPreferences() { - String templateName = XMLUIPlugin.getDefault().getPreferenceStore().getString(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME); - if ((templateName == null) || (templateName.length() == 0)) { - fLastSelectedTemplateName = ""; //$NON-NLS-1$ - fUseTemplateButton.setSelection(false); - } - else { - fLastSelectedTemplateName = templateName; - fUseTemplateButton.setSelection(true); - } - enableTemplates(); - } - - /** - * Save template name used for next call to New XML File wizard. - */ - void saveLastSavedPreferences() { - String templateName = ""; //$NON-NLS-1$ - - Template template = getSelectedTemplate(); - if (template != null) { - templateName = template.getName(); - } - - XMLUIPlugin.getDefault().getPreferenceStore().setValue(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName); - XMLUIPlugin.getDefault().savePluginPreferences(); - } - - /** - * Select a template in the table viewer given the template name. If - * template name cannot be found or templateName is null, just select - * first item in table. If no items in table select nothing. - * - * @param templateName - */ - private void setSelectedTemplate(String templateName) { - Object template = null; - - if ((templateName != null) && (templateName.length() > 0)) { - // pick the last used template - template = fTemplateStore.findTemplate(templateName, TemplateContextTypeIdsXML.NEW); - } - - // no record of last used template so just pick first element - if (template == null) { - // just pick first element - template = fTableViewer.getElementAt(0); - } - - if (template != null) { - IStructuredSelection selection = new StructuredSelection(template); - fTableViewer.setSelection(selection, true); - } - } - - /** - * Updates the pattern viewer. - */ - void updateViewerInput() { - Template template = getSelectedTemplate(); - if (template != null) { - fPatternViewer.getDocument().set(template.getPattern()); - } - else { - fPatternViewer.getDocument().set(""); //$NON-NLS-1$ - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java deleted file mode 100644 index da1f814d3b..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/NewXMLWizard.java +++ /dev/null @@ -1,879 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2008 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * David Schneider, david.schneider@unisys.com - [142500] WTP properties pages fonts don't follow Eclipse preferences - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Arrays; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.Assert; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.wizard.IWizardPage; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ModifyEvent; -import org.eclipse.swt.events.ModifyListener; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.part.FileEditorInput; -import org.eclipse.ui.part.PageBook; -import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.eclipse.wst.xml.core.internal.XMLCorePlugin; -import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry; -import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument; -import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration; -import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.xml.core.internal.contentmodel.util.DOMContentBuilder; -import org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo; -import org.eclipse.wst.xml.core.internal.preferences.XMLCorePreferenceNames; -import org.eclipse.wst.xml.ui.internal.Logger; -import org.eclipse.wst.xml.ui.internal.dialogs.NamespaceInfoErrorHelper; -import org.eclipse.wst.xml.ui.internal.dialogs.SelectFileOrXMLCatalogIdPanel; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImageHelper; -import org.eclipse.wst.xml.ui.internal.editor.XMLEditorPluginImages; -import org.eclipse.wst.xml.ui.internal.nsedit.CommonEditNamespacesDialog; - -import com.ibm.icu.text.Collator; - -public class NewXMLWizard extends NewModelWizard { - protected static final int CREATE_FROM_DTD = 0; - protected static final int CREATE_FROM_XSD = 1; - protected static final int CREATE_FROM_SCRATCH = 2; - - protected static final String[] createFromRadioButtonLabel = {XMLWizardsMessages._UI_RADIO_XML_FROM_DTD, XMLWizardsMessages._UI_RADIO_XML_FROM_SCHEMA, XMLWizardsMessages._UI_RADIO_XML_FROM_SCRATCH}; - - protected static final String[] filePageFilterExtensions = {".xml"}; //$NON-NLS-1$ - protected static final String[] browseXSDFilterExtensions = {".xsd"}; //$NON-NLS-1$ - protected static final String[] browseDTDFilterExtensions = {".dtd"}; //$NON-NLS-1$ - - protected NewFilePage newFilePage; - /** - * @deprecated clients should not be allowed to change start page - */ - protected StartPage startPage; - private StartPage fCreateXMLFromWizardPage; - protected SelectGrammarFilePage selectGrammarFilePage; - protected SelectRootElementPage selectRootElementPage; - - protected String cmDocumentErrorMessage; - - protected NewXMLGenerator generator; - private NewXMLTemplatesWizardPage fNewXMLTemplatesWizardPage; - - - public NewXMLWizard() { - setWindowTitle(XMLWizardsMessages._UI_WIZARD_CREATE_NEW_TITLE); - ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML); - setDefaultPageImageDescriptor(descriptor); - generator = new NewXMLGenerator(); - } - - - public NewXMLWizard(IFile file, CMDocument cmDocument) { - this(); - - generator.setGrammarURI(URIHelper.getPlatformURI(file)); - generator.setCMDocument(cmDocument); - } - - - public static void showDialog(Shell shell, IFile file, IStructuredSelection structuredSelection) { - String[] errorInfo = new String[2]; - // (cs) the URI argument to createCMDocument needs to be a fully - // qualified URI - // - CMDocument cmDocument = NewXMLGenerator.createCMDocument(URIHelper.getPlatformURI(file), errorInfo); - if (errorInfo[0] == null) { - NewXMLWizard wizard = new NewXMLWizard(file, cmDocument); - wizard.init(PlatformUI.getWorkbench(), structuredSelection); - wizard.setNeedsProgressMonitor(true); - WizardDialog dialog = new WizardDialog(shell, wizard); - dialog.create(); - dialog.getShell().setText(XMLWizardsMessages._UI_DIALOG_NEW_TITLE); - dialog.setBlockOnOpen(true); - dialog.open(); - } - else { - MessageDialog.openInformation(shell, errorInfo[0], errorInfo[1]); - } - } - - public void addPages() { - String grammarURI = generator.getGrammarURI(); - - // new file page - newFilePage = new NewFilePage(fSelection); - newFilePage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_HEADING); - newFilePage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_EXPL); - newFilePage.defaultName = (grammarURI != null) ? URIHelper.removeFileExtension(URIHelper.getLastSegment(grammarURI)) : "NewFile"; //$NON-NLS-1$ - Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences(); - String ext = preference.getString(XMLCorePreferenceNames.DEFAULT_EXTENSION); - newFilePage.defaultFileExtension = "." + ext; //$NON-NLS-1$ - newFilePage.filterExtensions = filePageFilterExtensions; - addPage(newFilePage); - - if (grammarURI == null) { - // create xml from page - fCreateXMLFromWizardPage = new StartPage("StartPage", createFromRadioButtonLabel) //$NON-NLS-1$ - { - public void createControl(Composite parent) { - super.createControl(parent); - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - getRadioButtonAtIndex(getCreateMode()).setSelection(true); - getRadioButtonAtIndex(getCreateMode()).setFocus(); - - // Set the help context for each button - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(0), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML1_HELPID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(1), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML2_HELPID); - PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(2), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML3_HELPID); - } - }; - - - fCreateXMLFromWizardPage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING); - fCreateXMLFromWizardPage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_EXPL); - addPage(fCreateXMLFromWizardPage); - } - - // selectGrammarFilePage - selectGrammarFilePage = new SelectGrammarFilePage(); - addPage(selectGrammarFilePage); - - // select root element page - selectRootElementPage = new SelectRootElementPage(); - selectRootElementPage.setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_HEADING); - selectRootElementPage.setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_EXPL); - addPage(selectRootElementPage); - - // from "scratch" - fNewXMLTemplatesWizardPage = new NewXMLTemplatesWizardPage(); - addPage(fNewXMLTemplatesWizardPage); - } - - - public IWizardPage getStartingPage() { - WizardPage result = null; - if (startPage != null) { - result = startPage; - } - else { - result = newFilePage; - } - return result; - } - - - public int getCreateMode() { - String grammarURI = generator.getGrammarURI(); - - int result = CREATE_FROM_SCRATCH; - if (grammarURI != null) { - if (grammarURI.endsWith(".dtd")) //$NON-NLS-1$ - { - result = CREATE_FROM_DTD; - } - else if (grammarURI.endsWith(".xsd")) //$NON-NLS-1$ - { - result = CREATE_FROM_XSD; - } - } - else if (fCreateXMLFromWizardPage != null) { - int selectedIndex = fCreateXMLFromWizardPage.getSelectedRadioButtonIndex(); - if (selectedIndex != -1) { - result = selectedIndex; - } - } - return result; - } - - - public IWizardPage getNextPage(IWizardPage currentPage) { - WizardPage nextPage = null; - if (currentPage == startPage) { - nextPage = newFilePage; - } - else if (currentPage == newFilePage) { - if (generator.getGrammarURI() == null) - nextPage = fCreateXMLFromWizardPage; - else - nextPage = selectRootElementPage; - } - else if (currentPage == fCreateXMLFromWizardPage) { - if (getCreateMode() == CREATE_FROM_SCRATCH) { - nextPage = fNewXMLTemplatesWizardPage; - } - else if (generator.getGrammarURI() == null) { - nextPage = selectGrammarFilePage; - } - else { - nextPage = selectRootElementPage; - } - } - else if (currentPage == selectGrammarFilePage) { - nextPage = selectRootElementPage; - } - return nextPage; - } - - - public boolean canFinish() { - boolean result = false; - - IWizardPage currentPage = getContainer().getCurrentPage(); - // can finish on: new file page, create from & template page if creating from scratch, select root element page - if ((currentPage == newFilePage && generator.getGrammarURI() == null) || (fCreateXMLFromWizardPage != null && fCreateXMLFromWizardPage.getSelectedRadioButtonIndex() == CREATE_FROM_SCRATCH) || (currentPage == selectRootElementPage)) { - result = currentPage.isPageComplete(); - } - return result; - } - - - public boolean performFinish() { - boolean result = super.performFinish(); - // save user options for next use - fNewXMLTemplatesWizardPage.saveLastSavedPreferences(); - - String fileName = null; - try { - - String[] namespaceErrors = generator.getNamespaceInfoErrors(); - if (namespaceErrors != null) { - String title = namespaceErrors[0]; - String message = namespaceErrors[1]; - result = MessageDialog.openQuestion(getShell(), title, message); - } - - if (result) { - fileName = newFilePage.getFileName(); - if ((new Path(fileName)).getFileExtension() == null) { - newFilePage.setFileName(fileName.concat(newFilePage.defaultFileExtension)); - } - - IFile newFile = newFilePage.createNewFile(); - String xmlFileName = newFile.getLocation().toOSString(); - - if (getContainer().getCurrentPage() == selectRootElementPage) { - - generator.createXMLDocument(newFile, xmlFileName); - } - else { - // put template contents into file - String templateString = fNewXMLTemplatesWizardPage.getTemplateString(); - generator.createTemplateXMLDocument(newFile, templateString); - } - - newFile.refreshLocal(IResource.DEPTH_ONE, null); - - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - BasicNewResourceWizard.selectAndReveal(newFile, workbenchWindow); - openEditor(newFile); - } - } - catch (Exception e) { - Logger.logException("Exception completing New XML wizard " + fileName, e); //$NON-NLS-1$ - } - return result; - } - - public void openEditor(IFile file) { - // Open editor on new file. - String editorId = null; - try { - IEditorDescriptor editor = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getLocation().toOSString(), file.getContentDescription().getContentType()); - if (editor != null) { - editorId = editor.getId(); - } - } - catch (CoreException e1) { - // editor id could not be retrieved, so we can not open editor - return; - } - IWorkbenchWindow dw = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - try { - if (dw != null) { - IWorkbenchPage page = dw.getActivePage(); - if (page != null) { - page.openEditor(new FileEditorInput(file), editorId, true); - } - } - } - catch (PartInitException e) { - // editor can not open for some reason - return; - } - - } - - - protected String getDefaultSystemId() { - String relativePath = "platform:/resource/" + newFilePage.getContainerFullPath().toString() + "/dummy"; //$NON-NLS-1$ //$NON-NLS-2$ - return URIHelper.getRelativeURI(generator.getGrammarURI(), relativePath); - } - - - /** - * SelectGrammarFilePage - */ - class SelectGrammarFilePage extends WizardPage { - protected SelectFileOrXMLCatalogIdPanel panel; - - SelectGrammarFilePage() { - super("SelectGrammarFilePage"); //$NON-NLS-1$ - } - - public void createControl(Composite parent) { - Composite composite = new Composite(parent, SWT.NONE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTSOURCE_HELPID); - composite.setLayout(new GridLayout()); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - setControl(composite); - - panel = new SelectFileOrXMLCatalogIdPanel(composite); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - - SelectFileOrXMLCatalogIdPanel.Listener listener = new SelectFileOrXMLCatalogIdPanel.Listener() { - public void completionStateChanged() { - updateErrorMessage(); - } - }; - panel.setListener(listener); - Dialog.applyDialogFont(parent); - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - if (visible) { - if (getCreateMode() == CREATE_FROM_DTD) { - setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_DTD_FILE_TITLE); - setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_DTD_FILE_DESC); - panel.setFilterExtensions(browseDTDFilterExtensions); - } - else { - setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_XSD_FILE_TITLE); - setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_XSD_FILE_DESC); - panel.setFilterExtensions(browseXSDFilterExtensions); - } - generator.setGrammarURI(null); - generator.setCMDocument(null); - cmDocumentErrorMessage = null; - } - panel.setVisibleHelper(visible); - } - - public String getURI() { - String uri = panel.getXMLCatalogURI(); - if (uri == null) { - IFile file = panel.getFile(); - if (file != null) { - uri = URIHelper.getPlatformURI(file); - } - } - return uri; - } - - public boolean isPageComplete() { - return (getURI() != null) && (getErrorMessage() == null); - } - - public String getXMLCatalogId() { - return panel.getXMLCatalogId(); - } - - public ICatalogEntry getXMLCatalogEntry() { - return panel.getXMLCatalogEntry(); - } - - public String computeErrorMessage() { - String errorMessage = null; - String uri = getURI(); - if (uri != null) { - if (!URIHelper.isReadableURI(uri, false)) { - errorMessage = XMLWizardsMessages._UI_LABEL_ERROR_CATALOG_ENTRY_INVALID; - } - } - return errorMessage; - } - - - public void updateErrorMessage() { - String errorMessage = computeErrorMessage(); - setErrorMessage(errorMessage); - setPageComplete(isPageComplete()); - } - } - - - /** - * SelectRootElementPage - */ - class SelectRootElementPage extends WizardPage implements SelectionListener { - protected Combo combo; - protected Button[] radioButton; - protected PageBook pageBook; - protected XSDOptionsPanel xsdOptionsPanel; - protected DTDOptionsPanel dtdOptionsPanel; - - - SelectRootElementPage() { - super("SelectRootElementPage"); //$NON-NLS-1$ - } - - public void createControl(Composite parent) { - // container group - Composite containerGroup = new Composite(parent, SWT.NONE); - PlatformUI.getWorkbench().getHelpSystem().setHelp(containerGroup, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT_HELPID); - containerGroup.setLayout(new GridLayout()); - containerGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - setControl(containerGroup); - - // select root element - Label containerLabel = new Label(containerGroup, SWT.NONE); - containerLabel.setText(XMLWizardsMessages._UI_LABEL_ROOT_ELEMENT); - combo = new Combo(containerGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - combo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - combo.addSelectionListener(this); - - // Options - { - Group group = new Group(containerGroup, SWT.NONE); - group.setText(XMLWizardsMessages._UI_WIZARD_CONTENT_OPTIONS); - - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - layout.makeColumnsEqualWidth = true; - layout.marginWidth = 0; - group.setLayout(layout); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - radioButton = new Button[4]; - - radioButton[0] = new Button(group, SWT.CHECK); - radioButton[0].setText(XMLWizardsMessages._UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES); - radioButton[0].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[0].setSelection(false); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[0], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT1_HELPID); - - radioButton[1] = new Button(group, SWT.CHECK); - radioButton[1].setText(XMLWizardsMessages._UI_WIZARD_CREATE_OPTIONAL_ELEMENTS); - radioButton[1].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[1].setSelection(false); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[1], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT2_HELPID); - - radioButton[2] = new Button(group, SWT.CHECK); - radioButton[2].setText(XMLWizardsMessages._UI_WIZARD_CREATE_FIRST_CHOICE); - radioButton[2].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[2].setSelection(true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[2], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT3_HELPID); - - radioButton[3] = new Button(group, SWT.CHECK); - radioButton[3].setText(XMLWizardsMessages._UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES); - radioButton[3].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - radioButton[3].setSelection(true); - PlatformUI.getWorkbench().getHelpSystem().setHelp(radioButton[3], IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT4_HELPID); - /* - * radioButton = new Button[2]; - * - * radioButton[0] = new Button(group, SWT.RADIO); - * radioButton[0].setText(XMLWizardsMessages.getString("_UI_WIZARD_CREATE_REQUIRED")); - * radioButton[0].setLayoutData(new - * GridData(GridData.FILL_HORIZONTAL)); - * radioButton[0].setSelection(true); - * WorkbenchHelp.setHelp(radioButton[0], - * XMLBuilderContextIds.XMLC_CREATE_REQUIRED_ONLY); - * - * radioButton[1] = new Button(group, SWT.RADIO); - * radioButton[1].setText(XMLWizardsMessages.getString("_UI_WIZARD_CREATE_OPTIONAL")); - * radioButton[1].setLayoutData(new - * GridData(GridData.FILL_HORIZONTAL)); - * WorkbenchHelp.setHelp(radioButton[1], - * XMLBuilderContextIds.XMLC_CREATE_REQUIRED_AND_OPTION); - */ - } - - // add the grammar specific generation options - // - { - pageBook = new PageBook(containerGroup, SWT.NONE); - pageBook.setLayoutData(new GridData(GridData.FILL_BOTH)); - xsdOptionsPanel = new XSDOptionsPanel(this, pageBook); - dtdOptionsPanel = new DTDOptionsPanel(this, pageBook); - pageBook.showPage(xsdOptionsPanel); - } - } - - public void widgetSelected(SelectionEvent event) { - int index = combo.getSelectionIndex(); - String rootElementName = (index != -1) ? combo.getItem(index) : null; - generator.setRootElementName(rootElementName); - } - - public void widgetDefaultSelected(SelectionEvent event) { - // do nothing - } - - public void setVisible(boolean visible) { - super.setVisible(visible); - - if (visible) { - try { - if (generator.getGrammarURI() == null) { - generator.setGrammarURI(selectGrammarFilePage.getURI()); - generator.setXMLCatalogEntry(selectGrammarFilePage.getXMLCatalogEntry()); - } - Assert.isNotNull(generator.getGrammarURI()); - - if (generator.getCMDocument() == null) { - final String[] errorInfo = new String[2]; - final CMDocument[] cmdocs = new CMDocument[1]; - Runnable r = new Runnable() { - public void run() { - cmdocs[0] = NewXMLGenerator.createCMDocument(generator.getGrammarURI(), errorInfo); - } - }; - org.eclipse.swt.custom.BusyIndicator.showWhile(Display.getCurrent(), r); - - generator.setCMDocument(cmdocs[0]); - cmDocumentErrorMessage = errorInfo[1]; - } - - combo.removeAll(); - if ((generator.getCMDocument() != null) && (cmDocumentErrorMessage == null)) { - CMNamedNodeMap nameNodeMap = generator.getCMDocument().getElements(); - Vector nameNodeVector = new Vector(); - - for (int i = 0; i < nameNodeMap.getLength(); i++) { - CMElementDeclaration cmElementDeclaration = (CMElementDeclaration) nameNodeMap.item(i); - Object value = cmElementDeclaration.getProperty("Abstract"); //$NON-NLS-1$ - if (value != Boolean.TRUE) { - nameNodeVector.add(cmElementDeclaration.getElementName()); - } - } - - Object[] nameNodeArray = nameNodeVector.toArray(); - if (nameNodeArray.length > 0) { - Arrays.sort(nameNodeArray, Collator.getInstance()); - } - - String defaultRootName = (String) (generator.getCMDocument()).getProperty("http://org.eclipse.wst/cm/properties/defaultRootName"); //$NON-NLS-1$ - int defaultRootIndex = -1; - for (int i = 0; i < nameNodeArray.length; i++) { - String elementName = (String) nameNodeArray[i]; - - combo.add(elementName); - if ((defaultRootName != null) && defaultRootName.equals(elementName)) { - defaultRootIndex = i; - } - } - - if (nameNodeArray.length > 0) { - defaultRootIndex = defaultRootIndex != -1 ? defaultRootIndex : 0; - combo.select(defaultRootIndex); - generator.setRootElementName(combo.getItem(defaultRootIndex)); - } - } - - if (generator.getGrammarURI().endsWith("xsd")) //$NON-NLS-1$ - { - pageBook.showPage(xsdOptionsPanel); - generator.setDefaultSystemId(getDefaultSystemId()); - generator.createNamespaceInfoList(); - - // Provide default namespace prefix if none - for (int i = 0; i < generator.namespaceInfoList.size(); i++) { - NamespaceInfo nsinfo = (NamespaceInfo) generator.namespaceInfoList.get(i); - if (((nsinfo.prefix == null) || (nsinfo.prefix.trim().length() == 0)) && ((nsinfo.uri != null) && (nsinfo.uri.trim().length() != 0))) { - nsinfo.prefix = getDefaultPrefix(generator.namespaceInfoList); - } - } - xsdOptionsPanel.setNamespaceInfoList(generator.namespaceInfoList); - } - else if (generator.getGrammarURI().endsWith("dtd")) //$NON-NLS-1$ - { - pageBook.showPage(dtdOptionsPanel); - dtdOptionsPanel.update(); - } - } - catch (Exception e) { - // XMLBuilderPlugin.getPlugin().getMsgLogger().writeCurrentThread(); - } - - /* - * String errorMessage = computeErrorMessage(); if - * (errorMessage == null) super.setVisible(visible); - */ - - updateErrorMessage(); - } - } - - private String getDefaultPrefix(List nsInfoList) { - String defaultPrefix = "p"; //$NON-NLS-1$ - if (nsInfoList == null) { - return defaultPrefix; - } - - Vector v = new Vector(); - for (int i = 0; i < nsInfoList.size(); i++) { - NamespaceInfo nsinfo = (NamespaceInfo) nsInfoList.get(i); - if (nsinfo.prefix != null) { - v.addElement(nsinfo.prefix); - } - } - - if (v.contains(defaultPrefix)) { - String s = defaultPrefix; - for (int j = 0; v.contains(s); j++) { - s = defaultPrefix + Integer.toString(j); - } - return s; - } - return defaultPrefix; - } - - public boolean isPageComplete() { - boolean complete = ((generator.getRootElementName() != null) && (generator.getRootElementName().length() > 0)) && (getErrorMessage() == null); - - if (complete) { - /* - * int buildPolicy = radioButton[0].getSelection() ? - * DOMContentBuilder.BUILD_ONLY_REQUIRED_CONTENT : - * DOMContentBuilder.BUILD_ALL_CONTENT; - */ - int buildPolicy = 0; - if (radioButton[0].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_OPTIONAL_ATTRIBUTES; - } - if (radioButton[1].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_OPTIONAL_ELEMENTS; - } - if (radioButton[2].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_FIRST_CHOICE | DOMContentBuilder.BUILD_FIRST_SUBSTITUTION; - } - if (radioButton[3].getSelection()) { - buildPolicy = buildPolicy | DOMContentBuilder.BUILD_TEXT_NODES; - } - - generator.setBuildPolicy(buildPolicy); - } - - return complete; - } - - public String computeErrorMessage() { - String errorMessage = null; - - if (cmDocumentErrorMessage != null) { - errorMessage = cmDocumentErrorMessage; - } - else if ((generator.getRootElementName() == null) || (generator.getRootElementName().length() == 0)) { - errorMessage = XMLWizardsMessages._ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED; - } - - return errorMessage; - } - - - public void updateErrorMessage() { - String errorMessage = computeErrorMessage(); - if (errorMessage == null) { - if (xsdOptionsPanel.isVisible()) { - - errorMessage = xsdOptionsPanel.computeErrorMessage(); - } - else if (dtdOptionsPanel.isVisible()) { - errorMessage = dtdOptionsPanel.computeErrorMessage(); - } - } - setErrorMessage(errorMessage); - setPageComplete(isPageComplete()); - } - } - - // //////////////End SelectRootElementPage - - - - public static GridLayout createOptionsPanelLayout() { - GridLayout gridLayout = new GridLayout(); - gridLayout.marginWidth = 0; - gridLayout.horizontalSpacing = 0; - return gridLayout; - } - - - - /** - * - */ - class XSDOptionsPanel extends Composite { - protected String errorMessage = null; - protected SelectRootElementPage parentPage; - protected CommonEditNamespacesDialog editNamespaces; - private IPath currentPath = null; - - public XSDOptionsPanel(SelectRootElementPage parentPage, Composite parent) { - super(parent, SWT.NONE); - this.parentPage = parentPage; - - setLayout(createOptionsPanelLayout()); - setLayoutData(new GridData(GridData.FILL_BOTH)); - } - - private CommonEditNamespacesDialog getEditNamespaces() { - if (editNamespaces == null) { - Composite co = new Composite(this, SWT.NONE); - co.setLayout(new GridLayout()); - String tableTitle = XMLWizardsMessages._UI_LABEL_NAMESPACE_INFORMATION; - editNamespaces = new CommonEditNamespacesDialog(co, null, tableTitle, true, true); - this.layout(); - } - return editNamespaces; - } - - public void setNamespaceInfoList(List list) { - CommonEditNamespacesDialog editDialog = getEditNamespaces(); - - if (newFilePage != null) { - IPath newPath = newFilePage.getContainerFullPath(); - if (newPath != null) { - if (!newPath.equals(currentPath)) { - String resourceURI = "platform:/resource" + newPath.toString() + "/dummy"; //$NON-NLS-1$ //$NON-NLS-2$ - String resolvedPath = URIHelper.normalize(resourceURI, null, null); - resolvedPath = URIHelper.removeProtocol(resolvedPath); - - currentPath = new Path(resolvedPath); - editDialog.setResourcePath(currentPath); - } - } - } - editDialog.setNamespaceInfoList(list); - editDialog.updateErrorMessage(list); - } - - public void updateErrorMessage(List namespaceInfoList) { - NamespaceInfoErrorHelper helper = new NamespaceInfoErrorHelper(); - errorMessage = helper.computeErrorMessage(namespaceInfoList, null); - parentPage.updateErrorMessage(); - } - - - public String computeErrorMessage() { - return errorMessage; - } - } - - - /** - * - */ - public class DTDOptionsPanel extends Composite implements ModifyListener { - protected Group group; - protected Text systemIdField; - protected Text publicIdField; - protected SelectRootElementPage parentPage; - - public DTDOptionsPanel(SelectRootElementPage parentPage, Composite parent) { - super(parent, SWT.NONE); - this.parentPage = parentPage; - setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - setLayout(createOptionsPanelLayout()); - Group group = new Group(this, SWT.NONE); - group.setText(XMLWizardsMessages._UI_LABEL_DOCTYPE_INFORMATION); - - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - group.setLayout(layout); - group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Label publicIdLabel = new Label(group, SWT.NONE); - publicIdLabel.setText(XMLWizardsMessages._UI_LABEL_PUBLIC_ID); - publicIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - publicIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - publicIdField.addModifyListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(publicIdField, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT5_HELPID); - - Label systemIdLabel = new Label(group, SWT.NONE); - systemIdLabel.setText(XMLWizardsMessages._UI_LABEL_SYSTEM_ID); - systemIdField = new Text(group, SWT.SINGLE | SWT.BORDER); - systemIdField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - systemIdField.addModifyListener(this); - PlatformUI.getWorkbench().getHelpSystem().setHelp(systemIdField, IXMLWizardHelpContextIds.XML_NEWWIZARD_SELECTROOTELEMENT6_HELPID); - } - - public void update() { - String thePublicId = null; - String theSystemId = null; - ICatalogEntry xmlCatalogEntry = generator.getXMLCatalogEntry(); - - if (xmlCatalogEntry != null) { - if (xmlCatalogEntry.getEntryType() == ICatalogEntry.ENTRY_TYPE_PUBLIC) { - thePublicId = xmlCatalogEntry.getKey(); - theSystemId = xmlCatalogEntry.getAttributeValue(ICatalogEntry.ATTR_WEB_URL); - if (theSystemId == null) { - theSystemId = generator.getGrammarURI().startsWith("http:") ? generator.getGrammarURI() : URIHelper.getLastSegment(generator.getGrammarURI()); //$NON-NLS-1$ - } - } - else { - theSystemId = xmlCatalogEntry.getKey(); - } - } - else { - theSystemId = getDefaultSystemId(); - } - - publicIdField.setText(thePublicId != null ? thePublicId : ""); //$NON-NLS-1$ - systemIdField.setText(theSystemId != null ? theSystemId : ""); //$NON-NLS-1$ - } - - public void modifyText(ModifyEvent e) { - generator.setSystemId(systemIdField.getText()); - generator.setPublicId(publicIdField.getText()); - parentPage.updateErrorMessage(); - } - - public String computeErrorMessage() { - return null; - } - } - - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java deleted file mode 100644 index 4b923c48ff..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLImportActionDelegate.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.util.Iterator; -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IActionDelegate; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; - -// TODO cs... rename this class NewXMLActionDelegate -// we need to re-add pre-validation using the validation framework API's -// since we also need to add validation to the 'New XML' case, this -// prevalidation -// function should really go into the NewWizard somewhere -// -public class XMLImportActionDelegate implements IActionDelegate { - /** - * Checks the current selection and runs the separate browser to show the - * content of the Readme file. This code shows how to launch separate - * browsers that are not VA/Base desktop parts. - * - * @param action - * the action that was performed - */ - public void run(IAction action) { - IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); - ISelection selection = workbenchWindow.getSelectionService().getSelection(); - Object selectedObject = getSelection(selection); - - if ((selectedObject instanceof IFile) && (selection instanceof IStructuredSelection)) { - IFile file = (IFile) selectedObject; - IStructuredSelection structuredSelection = (IStructuredSelection) selection; - try { - NewXMLWizard.showDialog(workbenchWindow.getShell(), file, structuredSelection); - } - catch (Exception e) { - // XMLCorePlugin.getDefault().getLog().log(); - } - } - } - - /** - * unused - */ - public void selectionChanged(IAction action, ISelection selection) { - // unused - } - - // scammed from WindowUtility - // - public static Object getSelection(ISelection selection) { - if (selection == null) { - return null; - } // end of if () - - Object result = null; - if (selection instanceof IStructuredSelection) { - IStructuredSelection es = (IStructuredSelection) selection; - Iterator i = es.iterator(); - if (i.hasNext()) { - result = i.next(); - } - } - return result; - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java deleted file mode 100644 index e56a3d33ea..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLSchemaValidationChecker.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.core.resources.IFile; -import org.eclipse.wst.common.uriresolver.internal.util.URIHelper; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -public class XMLSchemaValidationChecker { - public boolean isValid(IFile ifile) { - String xsdFileName = ifile.getLocation().toString(); - return isValid(xsdFileName); - } - - /** - * Should this be implemented as a Validator and simply called as such - * with a reporter that only checks the results for severity = error? Or - * should the Xerces requirement be broken using a plug-in extension? - */ - - public boolean isValid(String xsdFileName) { - // DOMASBuilderImpl builder = new DOMASBuilderImpl(); - // DOMErrorHandler errorHandler = new DOMErrorHandler(); - // builder.setErrorHandler(errorHandler); - try { - // String uri = - URIHelper.getURIForFilePath(xsdFileName); - // ASModel model = builder.parseASURI(uri); - // if (errorHandler.hasError()) - // return false; - } - catch (Exception e) // invalid schema - { - return false; - } - - return true; - } - - // inner class - class DOMErrorHandler implements ErrorHandler { - private boolean hasError = false; - - public boolean hasError() { - return hasError; - } - - public void error(SAXParseException err) { - hasError = true; - } - - public void fatalError(SAXParseException exception) throws SAXException { - hasError = true; - } - - public void warning(SAXParseException exception) throws SAXException { - // not an error - } - } // end DOMErrorHandlerImpl - -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java deleted file mode 100644 index ffea5d4624..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizard.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; - -public class XMLWizard { - protected static XMLWizard instance = new XMLWizard(); - - public synchronized static XMLWizard getInstance() { - return instance; - } - - public XMLWizard() { - instance = this; - - } - - public ImageDescriptor getImageDescriptor(String name) { - try { - URL url = new URL(Platform.getBundle("org.eclipse.wst.xml.ui").getEntry("/"), name); //$NON-NLS-1$ //$NON-NLS-2$ - return ImageDescriptor.createFromURL(url); - } - catch (MalformedURLException e) { - return ImageDescriptor.getMissingImageDescriptor(); - } - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.java b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.java deleted file mode 100644 index a1e01bbfcc..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/XMLWizardsMessages.java +++ /dev/null @@ -1,97 +0,0 @@ -/********************************************************************** - * Copyright (c) 2005, 2007 IBM Corporation and others. All rights reserved. This - * program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0 which accompanies this distribution, and is - * available at http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM - Initial API and implementation - * David Carver/STAR Standard - d_a_carver@yahoo.com - bug 192568 - **********************************************************************/ -package org.eclipse.wst.xml.ui.internal.wizards; - -import org.eclipse.osgi.util.NLS; - -/** - * Strings used by XML Wizards - * - * @plannedfor 1.0 - */ -public class XMLWizardsMessages extends NLS { - private static final String BUNDLE_NAME = "org.eclipse.wst.xml.ui.internal.wizards.wizardResource";//$NON-NLS-1$ - - public static String _UI_DIALOG_NEW_TITLE; - public static String _UI_DIALOG_TITLE_INVALID_GRAMMAR; - public static String _UI_DIALOG_MESSAGE_INVALID_GRAMMAR; - public static String _UI_WIZARD_CREATE_NEW_TITLE; - public static String _UI_RADIO_XML_FROM_DTD; - public static String _UI_RADIO_XML_FROM_SCHEMA; - public static String _UI_RADIO_XML_FROM_SCRATCH; - public static String _UI_WIZARD_CREATE_XML_HEADING; - public static String _UI_WIZARD_CREATE_XML_EXPL; - public static String _UI_WIZARD_CREATE_XML_FILE_HEADING; - public static String _UI_WIZARD_CREATE_XML_FILE_EXPL; - public static String _UI_WIZARD_SELECT_DTD_FILE_DESC; - public static String _UI_WIZARD_SELECT_DTD_FILE_TITLE; - public static String _UI_WIZARD_SELECT_XSD_FILE_DESC; - public static String _UI_WIZARD_SELECT_XSD_FILE_TITLE; - public static String _UI_WIZARD_SELECT_ROOT_HEADING; - public static String _UI_WIZARD_SELECT_ROOT_EXPL; - public static String _UI_LABEL_ROOT_ELEMENT; - public static String _UI_WARNING_TITLE_NO_ROOT_ELEMENTS; - public static String _UI_WARNING_MSG_NO_ROOT_ELEMENTS; - public static String _UI_LABEL_NO_LOCATION_HINT; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_1; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_2; - public static String _UI_WARNING_MSG_NO_LOCATION_HINT_3; - public static String _UI_WIZARD_CONTENT_OPTIONS; - public static String _UI_WIZARD_CREATE_REQUIRED;// commented out - public static String _UI_WIZARD_CREATE_OPTIONAL;// commented out - public static String _UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES; - public static String _UI_WIZARD_CREATE_OPTIONAL_ELEMENTS; - public static String _UI_WIZARD_CREATE_FIRST_CHOICE; - public static String _UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES; - public static String _UI_LABEL_DOCTYPE_INFORMATION; - public static String _UI_LABEL_SYSTEM_ID; - public static String _UI_LABEL_PUBLIC_ID; - public static String _UI_WARNING_URI_NOT_FOUND_COLON; - public static String _UI_INVALID_GRAMMAR_ERROR; - public static String _ERROR_BAD_FILENAME_EXTENSION; - public static String _ERROR_FILE_ALREADY_EXISTS; - public static String _ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED; - public static String _UI_LABEL_ERROR_SCHEMA_INVALID_INFO; - public static String _UI_LABEL_ERROR_DTD_INVALID_INFO; - public static String _UI_LABEL_ERROR_CATALOG_ENTRY_INVALID; - public static String _UI_LABEL_NAMESPACE_INFORMATION; - public static String Validation_Plugins_Unavailable; - public static String Validation_cannot_be_performed; - public static String ExampleProjectCreationOperation_op_desc; - public static String ExampleProjectCreationOperation_op_desc_proj; - public static String ExampleProjectCreationWizard_title; - public static String ExampleProjectCreationWizard_op_error_title; - public static String ExampleProjectCreationWizard_op_error_message; - public static String ExampleProjectCreationWizard_overwritequery_title; - public static String ExampleProjectCreationWizard_overwritequery_message; - public static String ExampleProjectCreationWizardPage_error_alreadyexists; - - public static String NewXMLTemplatesWizardPage_0; - public static String NewXMLTemplatesWizardPage_1; - public static String NewXMLTemplatesWizardPage_2; - public static String NewXMLTemplatesWizardPage_3; - public static String NewXMLTemplatesWizardPage_4; - public static String NewXMLTemplatesWizardPage_5; - public static String NewXMLTemplatesWizardPage_6; - - public static String _UI_DIALOG_XMLCATALOG_IMPORT_TITLE; - public static String _UI_DIALOG_XMLCATALOG_EXPORT_TITLE; - public static String _UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION; - public static String _UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION; - static { - // load message values from bundle file - NLS.initializeMessages(BUNDLE_NAME, XMLWizardsMessages.class); - } - - private XMLWizardsMessages() { - // cannot create new instance - } -} diff --git a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties b/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties deleted file mode 100644 index 0bd7bacc11..0000000000 --- a/bundles/org.eclipse.wst.xml.ui/src-wizards/org/eclipse/wst/xml/ui/internal/wizards/wizardResource.properties +++ /dev/null @@ -1,99 +0,0 @@ -############################################################################### -# Copyright (c) 2001, 2007 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -# David Carver/STAR Standard - d_a_carver@yahoo.com - bug 192568 -############################################################################### -! Properties file for component: XML Tools - New XML Wizard -! Packaged for translation in: xml.zip - -!XMLImportActionDelegate -_UI_DIALOG_NEW_TITLE = New XML File -_UI_DIALOG_TITLE_INVALID_GRAMMAR = Invalid Grammar -_UI_DIALOG_MESSAGE_INVALID_GRAMMAR = The grammar file contains errors. If you proceed, an incorrect result file will be generated. Do you want to continue? - -!NewXMLBWizard -_UI_WIZARD_CREATE_NEW_TITLE = New XML File -_UI_RADIO_XML_FROM_DTD = Create XML file from a &DTD file -_UI_RADIO_XML_FROM_SCHEMA = Create XML file from an &XML schema file -_UI_RADIO_XML_FROM_SCRATCH = Create XML file from an XML &template -_UI_WIZARD_CREATE_XML_HEADING = Create XML File From -_UI_WIZARD_CREATE_XML_EXPL = Select how you would like to create your XML file. -_UI_WIZARD_CREATE_XML_FILE_HEADING = XML File -_UI_WIZARD_CREATE_XML_FILE_EXPL = Create a new XML file. -_UI_WIZARD_SELECT_DTD_FILE_DESC = Select the DTD file to create the XML file. -_UI_WIZARD_SELECT_DTD_FILE_TITLE = Select DTD File -_UI_WIZARD_SELECT_XSD_FILE_DESC = Select the schema file to create the XML file. -_UI_WIZARD_SELECT_XSD_FILE_TITLE = Select XML Schema File -_UI_WIZARD_SELECT_ROOT_HEADING = Select Root Element -_UI_WIZARD_SELECT_ROOT_EXPL = Select the root element of the XML file. -_UI_LABEL_ROOT_ELEMENT = Root element: -_UI_WARNING_TITLE_NO_ROOT_ELEMENTS = No Root Elements -_UI_WARNING_MSG_NO_ROOT_ELEMENTS = No root element exists since the schema provided has no global elements. -_UI_LABEL_NO_LOCATION_HINT = Unspecified Namespace Location -_UI_WARNING_MSG_NO_LOCATION_HINT_1 = You have not specified a location hint for one or more namespace entries. -_UI_WARNING_MSG_NO_LOCATION_HINT_2 = Elements from these namespaces will not be generated. This may lead to an invalid generated document. -_UI_WARNING_MSG_NO_LOCATION_HINT_3 = Click Yes to continue, Click No to go back and specify the location hints. -_UI_WIZARD_CONTENT_OPTIONS = Content options - -_UI_WIZARD_CREATE_REQUIRED = &Create required content only -_UI_WIZARD_CREATE_OPTIONAL = Create required and &optional content - -_UI_WIZARD_CREATE_OPTIONAL_ATTRIBUTES = Create optional &attributes -_UI_WIZARD_CREATE_OPTIONAL_ELEMENTS = Create optional e&lements -_UI_WIZARD_CREATE_FIRST_CHOICE = Create first choice of required &choice -_UI_WIZARD_FILL_ELEMENTS_AND_ATTRIBUTES = Fill elements and attributes with &data - -_UI_LABEL_DOCTYPE_INFORMATION = Document type information -_UI_LABEL_SYSTEM_ID = &System ID: -_UI_LABEL_PUBLIC_ID = &Public ID: - -_UI_WARNING_URI_NOT_FOUND_COLON = The specified resource cannot be located : - -!NewModelWizard -_UI_INVALID_GRAMMAR_ERROR = Invalid Grammar - -!NewModelWizard -_ERROR_BAD_FILENAME_EXTENSION = The file name must end in one of the following extensions {0}. -_ERROR_FILE_ALREADY_EXISTS = The same file already exists. -_ERROR_ROOT_ELEMENT_MUST_BE_SPECIFIED = A root element must be specified. -_UI_LABEL_ERROR_SCHEMA_INVALID_INFO = The schema file contains errors. Open it in the XML schema editor for details. -_UI_LABEL_ERROR_DTD_INVALID_INFO = The DTD file contains errors. Open it in the DTD editor for details. - -_UI_LABEL_ERROR_CATALOG_ENTRY_INVALID = The selected catalog entry specifies a URI that can not be located. - -_UI_LABEL_NAMESPACE_INFORMATION=Namespace Information - -Validation_Plugins_Unavailable=Validation Plugins Unavailable -Validation_cannot_be_performed=Validation cannot be performed because the validation plugins were disabled or not found. The generated file may be invalid. Do you wish to continue? - -!ImportXMLCatalogWizard -_UI_DIALOG_XMLCATALOG_IMPORT_TITLE = Import XML Catalog -_UI_DIALOG_XMLCATALOG_IMPORT_DESCRIPTION = Import all entries from an existing XML Catalog into the User Catalog. - -!ExportXMLCatalogWizard -_UI_DIALOG_XMLCATALOG_EXPORT_TITLE = Export Existing XML Catalog -_UI_DIALOG_XMLCATALOG_EXPORT_DESCRIPTION = Export all existing User Catalog entries. -# -# ExampleProject -ExampleProjectCreationOperation_op_desc=Creating example projects... -ExampleProjectCreationOperation_op_desc_proj=Configuring project... -ExampleProjectCreationWizard_title=New Example Project -ExampleProjectCreationWizard_op_error_title=Project Creation Failed -ExampleProjectCreationWizard_op_error_message=Project could not be created. -ExampleProjectCreationWizard_overwritequery_title=Overwrite -ExampleProjectCreationWizard_overwritequery_message=Do you want to overwrite {0}? -ExampleProjectCreationWizardPage_error_alreadyexists=Project already exists. - -NewXMLTemplatesWizardPage_0=Select XML Template -NewXMLTemplatesWizardPage_1=Select a template as initial content in the XML page. -NewXMLTemplatesWizardPage_2=Name -NewXMLTemplatesWizardPage_3=Description -NewXMLTemplatesWizardPage_4=Use XML Template -NewXMLTemplatesWizardPage_5=Preview: -NewXMLTemplatesWizardPage_6=Templates are 'New XML' templates found in the <a>XML Templates</a> preference page. |