[116315] New XML Wizard should look like other new file wizards
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
index c4bbb88..9b70131 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
+ * 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
@@ -114,19 +114,29 @@
return cmDocument;
}
-
+ /**
+ * @deprecated use createTemplateXMLDocument(IFile, String) instead
+ */
public void createEmptyXMLDocument(IFile newFile) throws Exception {
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
String charSet = getUserPreferredCharset();
-
- PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream, charSet));
- writer.println("<?xml version=\"1.0\" encoding=\"" + charSet + "\"?>"); //$NON-NLS-1$ //$NON-NLS-2$
- writer.flush();
- outputStream.close();
-
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
- newFile.setContents(inputStream, true, true, null);
- inputStream.close();
+ 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));
+ writer.println(contents);
+ writer.flush();
+ outputStream.close();
+
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ newFile.setContents(inputStream, true, true, null);
+ inputStream.close();
+ }
}
private String getUserPreferredCharset() {
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
index 0fa3940..929a01f 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006 IBM Corporation and others.
+ * 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
@@ -209,7 +209,7 @@
layout.numColumns = 2;
parent.setLayout(layout);
- // create checkbox for user to use DTD Template
+ // 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);
@@ -421,7 +421,7 @@
templateString = buffer.getString();
}
catch (Exception e) {
- Logger.log(Logger.WARNING_DEBUG, "Could not create template for new dtd", e); //$NON-NLS-1$
+ Logger.log(Logger.WARNING_DEBUG, "Could not create template for new xml", e); //$NON-NLS-1$
}
}
@@ -436,7 +436,7 @@
}
/**
- * Load the last template name used in New DTD File wizard.
+ * 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);
@@ -452,7 +452,7 @@
}
/**
- * Save template name used for next call to New DTD File wizard.
+ * Save template name used for next call to New XML File wizard.
*/
void saveLastSavedPreferences() {
String templateName = ""; //$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
index 94d9171..83e0813 100644
--- 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2006 IBM Corporation and others.
+ * 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
@@ -80,7 +80,11 @@
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;
@@ -91,7 +95,7 @@
public NewXMLWizard() {
- setWindowTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING);
+ setWindowTitle(XMLWizardsMessages._UI_WIZARD_CREATE_NEW_TITLE);
ImageDescriptor descriptor = XMLEditorPluginImageHelper.getInstance().getImageDescriptor(XMLEditorPluginImages.IMG_WIZBAN_GENERATEXML);
setDefaultPageImageDescriptor(descriptor);
generator = new NewXMLGenerator();
@@ -127,13 +131,23 @@
}
}
-
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) {
- // start page
- startPage = new StartPage("StartPage", createFromRadioButtonLabel) //$NON-NLS-1$
+ // create xml from page
+ fCreateXMLFromWizardPage = new StartPage("StartPage", createFromRadioButtonLabel) //$NON-NLS-1$
{
public void createControl(Composite parent) {
super.createControl(parent);
@@ -145,29 +159,18 @@
getRadioButtonAtIndex(getCreateMode()).setFocus();
// Set the help context for each button
- PlatformUI.getWorkbench().getHelpSystem().setHelp(startPage.getRadioButtonAtIndex(0), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML1_HELPID);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(startPage.getRadioButtonAtIndex(1), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML2_HELPID);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(startPage.getRadioButtonAtIndex(2), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML3_HELPID);
+ 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);
}
};
- startPage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING);
- startPage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_EXPL);
- addPage(startPage);
+ fCreateXMLFromWizardPage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING);
+ fCreateXMLFromWizardPage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_EXPL);
+ addPage(fCreateXMLFromWizardPage);
}
- // 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);
-
// selectGrammarFilePage
selectGrammarFilePage = new SelectGrammarFilePage();
addPage(selectGrammarFilePage);
@@ -210,8 +213,8 @@
result = CREATE_FROM_XSD;
}
}
- else if (startPage != null) {
- int selectedIndex = startPage.getSelectedRadioButtonIndex();
+ else if (fCreateXMLFromWizardPage != null) {
+ int selectedIndex = fCreateXMLFromWizardPage.getSelectedRadioButtonIndex();
if (selectedIndex != -1) {
result = selectedIndex;
}
@@ -226,6 +229,12 @@
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;
}
@@ -247,8 +256,8 @@
boolean result = false;
IWizardPage currentPage = getContainer().getCurrentPage();
-
- if (((startPage != null) && (startPage.getSelectedRadioButtonIndex() == CREATE_FROM_SCRATCH) && (currentPage == fNewXMLTemplatesWizardPage)) || (currentPage == selectRootElementPage)) {
+ // 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;
@@ -256,8 +265,10 @@
public boolean performFinish() {
- boolean result = true;
- super.performFinish();
+ boolean result = super.performFinish();
+ // save user options for next use
+ fNewXMLTemplatesWizardPage.saveLastSavedPreferences();
+
String fileName = null;
try {
@@ -282,7 +293,9 @@
generator.createXMLDocument(newFile, xmlFileName);
}
else {
- generator.createEmptyXMLDocument(newFile);
+ // put template contents into file
+ String templateString = fNewXMLTemplatesWizardPage.getTemplateString();
+ generator.createTemplateXMLDocument(newFile, templateString);
}
newFile.refreshLocal(1, null);
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
index 41e9648..eb29971 100644
--- 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
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2005 IBM Corporation and others. All rights reserved. This
+ * 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
@@ -22,6 +22,7 @@
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;
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
index fb8135c..7fc323b 100644
--- 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
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2001, 2006 IBM Corporation and others.
+# 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
@@ -12,18 +12,19 @@
! Packaged for translation in: xml.zip
!XMLImportActionDelegate
-_UI_DIALOG_NEW_TITLE = New
+_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
+_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 Name
-_UI_WIZARD_CREATE_XML_FILE_EXPL = Specify a name for the new 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.
diff --git a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
index 4a84520..476f40a 100644
--- a/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
+++ b/bundles/org.eclipse.wst.xml.ui/src/org/eclipse/wst/xml/ui/internal/preferences/XMLUIPreferenceInitializer.java
@@ -14,6 +14,7 @@
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.templates.Template;
import org.eclipse.wst.sse.ui.internal.preferences.ui.ColorHelper;
import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
import org.eclipse.wst.xml.ui.internal.style.IStyleConstantsXML;
@@ -109,6 +110,17 @@
styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD;
store.setDefault(IStyleConstantsXML.ENTITY_REFERENCE, styleValue);
+
+ // set default new xml file template to use in new file wizard
+ /*
+ * Need to find template name that goes with default template id (name
+ * may change for differnt language)
+ */
+ String templateName = ""; //$NON-NLS-1$
+ Template template = XMLUIPlugin.getDefault().getTemplateStore().findTemplateById("org.eclipse.wst.xml.ui.internal.templates.xmldeclaration"); //$NON-NLS-1$
+ if (template != null)
+ templateName = template.getName();
+ store.setDefault(XMLUIPreferenceNames.NEW_FILE_TEMPLATE_NAME, templateName);
}
}