# HG changeset patch # User Eugene Ostroukhov # Date 1278984586 25200 # Node ID 57fff6202b74e7f4a97a15fa22bb79856910ae86 # Parent 99afbaa8a4bcc13d5e91eb948953d8ff09d85c90 Bug 3184 - Reorganize new project wizard diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools.product/launch/WRT IDE Product (Mac OS X).launch --- a/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Mac OS X).launch Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools.product/launch/WRT IDE Product (Mac OS X).launch Mon Jul 12 18:29:46 2010 -0700 @@ -21,8 +21,8 @@ - - + + diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/schema/projectTemplates.exsd --- a/org.symbian.tools.wrttools/schema/projectTemplates.exsd Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/schema/projectTemplates.exsd Mon Jul 12 18:29:46 2010 -0700 @@ -1,184 +1,177 @@ - - - - - - - - - [Enter description of this extension point.] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - [Enter the first release in which this extension point appears.] - - - - - - - - - [Enter extension point usage example here.] - - - - - - - - - [Enter API information here.] - - - - - - - - - [Enter information about supplied implementation of this extension point.] - - - - - + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/core/ProjectTemplate.java Mon Jul 12 18:29:46 2010 -0700 @@ -35,117 +35,117 @@ import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.core.libraries.JSLibrary; import org.symbian.tools.wrttools.wizards.IWizardPageFactory; -import org.symbian.tools.wrttools.wizards.WRTProjectDetailsWizardPage; +import org.symbian.tools.wrttools.wizards.WRTProjectFilesWizardPage; import org.symbian.tools.wrttools.wizards.WizardContext; public class ProjectTemplate { - private static ProjectTemplate[] templates; + private static ProjectTemplate[] templates; + + private final IConfigurationElement element; - private final IConfigurationElement element; + private Image icon; + + public ProjectTemplate(IConfigurationElement element) { + this.element = element; + } - private Image icon; - - public ProjectTemplate(IConfigurationElement element) { - this.element = element; - } - - public Image getIcon() { - if (icon == null) { - String path = element.getAttribute("icon"); - final ImageDescriptor imageDescriptor; - if (path != null) { - imageDescriptor = Activator.imageDescriptorFromPlugin(element.getNamespaceIdentifier(), path); - } else { - imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); - } - icon = imageDescriptor.createImage(true); - } - return icon; - } + public Image getIcon() { + if (icon == null) { + String path = element.getAttribute("icon"); + final ImageDescriptor imageDescriptor; + if (path != null) { + imageDescriptor = Activator.imageDescriptorFromPlugin( + element.getNamespaceIdentifier(), path); + } else { + imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); + } + icon = imageDescriptor.createImage(true); + } + return icon; + } - public String getName() { - return element.getAttribute("name"); - } - - public String getDescription() { - IConfigurationElement[] children = element.getChildren("description"); - if (children.length == 1) { - return children[0].getValue(); - } else { - return ""; - } - } - + public String getName() { + return element.getAttribute("name"); + } + + public String getDescription() { + IConfigurationElement[] children = element.getChildren("description"); + if (children.length == 1) { + return children[0].getValue(); + } else { + return ""; + } + } + private String[] getLibraryIds() { - IConfigurationElement[] elements = element.getChildren("requires-library"); - String[] ids = new String[elements.length]; - for (int i = 0; i < elements.length; i++) { - IConfigurationElement element = elements[i]; - ids[i] = element.getValue(); - } - return ids; - } - - public static ProjectTemplate[] getAllTemplates() { - if (templates == null) { - IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "projectTemplates"); - IConfigurationElement[] elements = point.getConfigurationElements(); - templates = new ProjectTemplate[elements.length]; - for (int i = 0; i < elements.length; i++) { - IConfigurationElement element = elements[i]; - templates[i] = new ProjectTemplate(element); - } - } - return templates; - } + IConfigurationElement[] elements = element + .getChildren("requires-library"); + String[] ids = new String[elements.length]; + for (int i = 0; i < elements.length; i++) { + IConfigurationElement element = elements[i]; + ids[i] = element.getValue(); + } + return ids; + } - public String getDefaultCssFile() { - String file = element.getAttribute("default-css-name"); - return file != null ? file : "main"; - } + public static ProjectTemplate[] getAllTemplates() { + if (templates == null) { + IExtensionPoint point = Platform.getExtensionRegistry() + .getExtensionPoint(Activator.PLUGIN_ID, "projectTemplates"); + IConfigurationElement[] elements = point.getConfigurationElements(); + templates = new ProjectTemplate[elements.length]; + for (int i = 0; i < elements.length; i++) { + IConfigurationElement element = elements[i]; + templates[i] = new ProjectTemplate(element); + } + } + return templates; + } - public String getDefaultJsFile() { - String file = element.getAttribute("default-js-name"); - return file != null ? file : "main"; - } + public String getDefaultCssFile() { + String file = element.getAttribute("default-css-name"); + return file != null ? file : "main"; + } + + public String getDefaultJsFile() { + String file = element.getAttribute("default-js-name"); + return file != null ? file : "main"; + } - public String getDefaultHtmlFile() { - String file = element.getAttribute("default-html-name"); - return file != null ? file : "index"; - } - - public String getIdFormat() { - String pattern = element.getAttribute("id-pattern"); - return pattern != null ? pattern : "com.{0}.widget"; - } + public String getDefaultHtmlFile() { + String file = element.getAttribute("default-html-name"); + return file != null ? file : "index"; + } - public WRTProjectDetailsWizardPage createWizardPage(WizardContext context, - DataBindingContext bindingContext) { - try { - if (element.getAttribute("wizard-page-factory") != null) { - IWizardPageFactory factory = (IWizardPageFactory) element.createExecutableExtension("wizard-page-factory"); - return factory.createPage(context, bindingContext); - } - }catch (CoreException e) { - Activator.log("Problem with template " + getName(), e); - } - return new WRTProjectDetailsWizardPage(context, bindingContext); - } - - @Override - public String toString() { - return getName(); - } + public WRTProjectFilesWizardPage createWizardPage(WizardContext context, + DataBindingContext bindingContext) { + try { + if (element.getAttribute("wizard-page-factory") != null) { + IWizardPageFactory factory = (IWizardPageFactory) element + .createExecutableExtension("wizard-page-factory"); + return factory.createPage(context, bindingContext); + } + } catch (CoreException e) { + Activator.log("Problem with template " + getName(), e); + } + return new WRTProjectFilesWizardPage(context, bindingContext); + } - public URL getProjectContents() { - String uri = element.getAttribute("archive"); - if (uri != null) { - Bundle bundle = Platform.getBundle(element.getContributor().getName()); - URL resource = bundle.getResource(uri); - return resource; - } - return null; - } + @Override + public String toString() { + return getName(); + } + + public URL getProjectContents() { + String uri = element.getAttribute("archive"); + if (uri != null) { + Bundle bundle = Platform.getBundle(element.getContributor() + .getName()); + URL resource = bundle.getResource(uri); + return resource; + } + return null; + } public boolean requires(JSLibrary library) { for (String id : getLibraryIds()) { diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CompoundValidator.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CompoundValidator.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CompoundValidator.java Mon Jul 12 18:29:46 2010 -0700 @@ -21,7 +21,7 @@ import org.eclipse.core.databinding.validation.IValidator; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.symbian.tools.wrttools.wizards.AbstractDataBindingPage.NonEmptyStringValidator; +import org.symbian.tools.wrttools.wizards.NonEmptyStringValidator; public class CompoundValidator implements IValidator { diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/Util.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/Util.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/Util.java Mon Jul 12 18:29:46 2010 -0700 @@ -24,146 +24,163 @@ public class Util { - public static String removeSpaces(String widgetName) { - return widgetName != null ? widgetName.replace(" ", "") : null; - } + public static String removeSpaces(String widgetName) { + return widgetName != null ? widgetName.replace(" ", "") : ""; + } + + public static String removeNonAlphaNum(String projectName) { + return projectName != null ? projectName + .replaceAll("[^a-zA-Z0-9 ]", "") : null; + } + + public static void logEvent(Logger log, Level level, Throwable throwable) { + if (level == Level.SEVERE) { + log.severe(throwable.getLocalizedMessage()); + if (throwable.getCause() != null) { + log.severe(throwable.getCause().toString()); + } + log.severe(throwable.getStackTrace().toString()); + } + if (level == Level.WARNING) { + log.warning(throwable.getLocalizedMessage()); + if (throwable.getCause() != null) { + log.warning(throwable.getCause().toString()); + } + log.warning(throwable.getStackTrace().toString()); + } + if (level == Level.INFO) { + log.info(throwable.getLocalizedMessage()); + if (throwable.getCause() != null) { + log.info(throwable.getCause().toString()); + } + log.info(throwable.getStackTrace().toString()); + } + + } - public static String removeNonAlphaNum(String projectName) { - return projectName != null ? projectName.replaceAll("[^a-zA-Z0-9 ]", "") : null; - } -public static void logEvent(Logger log, Level level, Throwable throwable) - { - if (level==Level.SEVERE) - { - log.severe(throwable.getLocalizedMessage()); - if(throwable.getCause()!=null) - log.severe(throwable.getCause().toString()); - log.severe(throwable.getStackTrace().toString()); - } - if (level==Level.WARNING) - { - log.warning(throwable.getLocalizedMessage()); - if(throwable.getCause()!=null) - log.warning(throwable.getCause().toString()); - log.warning(throwable.getStackTrace().toString()); - } - if (level==Level.INFO) - { - log.info(throwable.getLocalizedMessage()); - if(throwable.getCause()!=null) - log.info(throwable.getCause().toString()); - log.info(throwable.getStackTrace().toString()); - } - - } - - public static String replaceChar(String input, char asciiOutChar, char asciiInChar){ - char x; - int ascii ; - String outString=""; - int outCharAscii= (asciiOutChar > 127) ? '?' : (char)(asciiOutChar & 0x7F); - int inCharAscii= (asciiInChar > 127) ? '?' : (char)(asciiInChar & 0x7F); - - for (int i = 0; i < input.length(); i++) { - x = input.charAt(i); - ascii = (x > 127) ? '?' : (char)(x & 0x7F); - - if(ascii==outCharAscii){ - outString=outString+asciiInChar; - }else{ - outString=outString+x; - } - - } - return outString; - } - - public static void showData(String s) { - System.out.println(s); - } - - public static void showData(List listString, String header) { - - if(listString!=null&&listString.size()>0) { - System.out.println("--------"+header+"------"); - for(String s:listString){ - System.out.println(s); - } - }else { - System.out.println("--------Empty/Null "+header+"------"); - } - } + public static String replaceChar(String input, char asciiOutChar, + char asciiInChar) { + char x; + int ascii; + String outString = ""; + int outCharAscii = (asciiOutChar > 127) ? '?' + : (char) (asciiOutChar & 0x7F); + + for (int i = 0; i < input.length(); i++) { + x = input.charAt(i); + ascii = (x > 127) ? '?' : (char) (x & 0x7F); + + if (ascii == outCharAscii) { + outString = outString + asciiInChar; + } else { + outString = outString + x; + } + + } + return outString; + } + public static void showData(String s) { + System.out.println(s); + } + + public static void showData(List listString, String header) { + + if (listString != null && listString.size() > 0) { + System.out.println("--------" + header + "------"); + for (String s : listString) { + System.out.println(s); + } + } else { + System.out.println("--------Empty/Null " + header + "------"); + } + } + + /* Validation tests for both Windows & Mac OS */ + private static String commonValidate(String argName) { + if (argName.length() == 0) { + return ("Can not be empty"); + } - @SuppressWarnings("restriction") - /* Validation tests for both Windows & Mac OS */ - private static String commonValidate(String argName) - { - if (argName.length() == 0 ) { - return ("Can not be empty"); - } - - // filenames starting with dot are not valid for both Widget name & UID - if ( argName.charAt(0) == '.' ) { - return("Can not begin with a dot"); - } + // filenames starting with dot are not valid for both Widget name & UID + if (argName.charAt(0) == '.') { + return ("Can not begin with a dot"); + } + + final char lastChar = argName.charAt(argName.length() - 1); + // filenames ending in dot are not valid for both Widget name & UID + if (lastChar == '.') { + return ("Can not end with dot"); + } + + return null; + } - final char lastChar = argName.charAt(argName.length()-1); - // filenames ending in dot are not valid for both Widget name & UID - if (lastChar == '.') { - return("Can not end with dot"); - } - - return null; - } - + public static String validateWidgetName(String widgetName) { + String strError = null; + if ((strError = commonValidate(widgetName)) != null) { + return "Invalid Widget name. " + strError; + } + if (widgetName.indexOf("<") > -1 || widgetName.indexOf(">") > -1) { + return ("Invalid Widget name. Angle brackets are not allowed"); + } + final char lastChar = widgetName.charAt(widgetName.length() - 1); + // trailing or beginning space is not valid in filenames for Widget name + if ((Character.isWhitespace(widgetName.charAt(0)) || Character + .isWhitespace(lastChar))) { + return ("Invalid Widget name. Beginning or trailing spaces are not allowed"); + } - public static String validateWidgetName(String widgetName){ - String strError = null; - if ((strError = commonValidate(widgetName)) != null) - return "Invalid Widget name. " + strError; - if (widgetName.indexOf("<") > -1 || widgetName.indexOf(">") > -1){ - return("Invalid Widget name. Angle brackets are not allowed"); - } - final char lastChar = widgetName.charAt(widgetName.length()-1); - // trailing or beginning space is not valid in filenames for Widget name - if ((Character.isWhitespace(widgetName.charAt(0)) || Character.isWhitespace(lastChar))) { - return("Invalid Widget name. Beginning or trailing spaces are not allowed"); - } + if (widgetName.indexOf('\n') != -1 || widgetName.indexOf('\t') != -1) { + return ("Invalid Widget name. newline character is not allowed"); + } + + return null; + } - if (widgetName.indexOf('\n') != -1 || widgetName.indexOf('\t') != -1 ) { - return("Invalid Widget name. newline character is not allowed"); - } - - return null; - } + public static String validateWidgetID(String widgetID) { + String strError = null; + if ((strError = commonValidate(widgetID)) != null) { + return "Invalid Widget identifier. " + strError; + } - public static String validateWidgetID(String widgetID) - { - String strError = null; - if ((strError = commonValidate(widgetID)) != null) - return "Invalid Widget identifier. " + strError; + // file names with white spaces are not allowed for Widget Identifier + // (UID) + if (widgetID.indexOf(" ") > -1) { + return ("Invalid Widget identifier. Whitespaces are not allowed"); + } + + if (widgetID.length() > 78) { + return ("Invalid Widget identifier. Maximum string length exceeded"); + } - // file names with white spaces are not allowed for Widget Identifier (UID) - if (widgetID.indexOf(" ") > -1 ){ - return("Invalid Widget identifier. Whitespaces are not allowed"); - } - - if (widgetID.length() > 78 ) { - return("Invalid Widget identifier. Maximum string length exceeded"); - } - - /* test invalid characters, allows only alphanumeric and '.' for UID*/ - String alphnum = ".0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; - for (int i = 0; i < widgetID.length(); i++) - if (alphnum.indexOf(widgetID.charAt(i),0) == -1) { - return("Invalid Widget identifier. Only alphanumeric or '.' is allowed"); - } + /* test invalid characters, allows only alphanumeric and '.' for UID */ + String alphnum = ".0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + for (int i = 0; i < widgetID.length(); i++) { + if (alphnum.indexOf(widgetID.charAt(i), 0) == -1) { + return ("Invalid Widget identifier. Only alphanumeric or '.' is allowed"); + } + } + + if (widgetID.matches(".*[.]{2,}.*")) { + return ("Invalid Widget identifier. Consecutive dots are not allowed"); + } + + return null; + } - if (widgetID.matches(".*[.]{2,}.*")) { - return("Invalid Widget identifier. Consecutive dots are not allowed"); - } - - return null; - } + public static String toProjectName(String widgetId) { + if (widgetId == null || widgetId.trim().length() == 0) { + return ""; + } + StringBuilder builder = new StringBuilder(); + for (char c : widgetId.trim().toCharArray()) { + if (Character.isJavaIdentifierPart(c)) { + builder.append(c); + } else { + builder.append("_"); + } + } + return builder.toString(); + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -18,96 +18,20 @@ */ package org.symbian.tools.wrttools.wizards; -import java.text.MessageFormat; import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.UpdateValueStrategy; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.Observables; -import org.eclipse.core.databinding.observable.map.IObservableMap; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.core.databinding.validation.IValidator; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.databinding.swt.ISWTObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.wizard.WizardPage; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.symbian.tools.wrttools.Activator; -import org.symbian.tools.wrttools.util.CompoundValidator; public abstract class AbstractDataBindingPage extends WizardPage { - public class NonEmptyStringValidator implements IValidator { - private final String propertyName; - - public NonEmptyStringValidator(String propertyName) { - this.propertyName = propertyName; - } - - public IStatus validate(Object value) { - if (isActive()) { - if (value == null || value.toString().trim().length() == 0) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, - MessageFormat.format("Field {0} is empty", - propertyName)); - } - } - return Status.OK_STATUS; - } - } - - protected final WizardContext context; - protected final DataBindingContext bindingContext; - - public AbstractDataBindingPage(WizardContext context, - DataBindingContext bindingContext, String name, String title, - ImageDescriptor image, String description) { - super(name, title, image); - this.context = context; - this.bindingContext = bindingContext; - setDescription(description); - } - - protected boolean isActive() { - return true; - } + public AbstractDataBindingPage(WizardContext context, + DataBindingContext bindingContext, String name, String title, + ImageDescriptor image, String description) { + super(name, title, image); + setDescription(description); + } - protected Text createText(Composite root, String property, - String propertyName, IValidator... validators) { - return createText(root, BeansObservables - .observeValue(context, property), propertyName, validators); - } - - protected Text createTextForExt(Composite root, String property, - String propertyName) { - IObservableMap map = BeansObservables.observeMap(context, "extensions"); - IObservableValue entry = Observables.observeMapEntry(map, property, - String.class); - return createText(root, entry, propertyName); - } - - private Text createText(Composite root, IObservableValue model, - String propertyName, IValidator... validators) { - Text text = new Text(root, SWT.BORDER); - text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify); - UpdateValueStrategy strategy = new UpdateValueStrategy( - UpdateValueStrategy.POLICY_UPDATE); - NonEmptyStringValidator validator = new NonEmptyStringValidator( - propertyName); - strategy.setBeforeSetValidator(validators.length == 0 ? validator - : new CompoundValidator(validator, validators)); - bindingContext.bindValue(view, model, strategy, null); - return text; - } - - protected static void createLabel(Composite root, String text) { - Label label = new Label(root, SWT.NONE); - label.setText(text); - } + protected boolean isActive() { + return true; + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/FlickrProjectDetailsWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -21,27 +21,29 @@ import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.swt.widgets.Composite; -public class FlickrProjectDetailsWizardPage extends WRTProjectDetailsWizardPage { +public class FlickrProjectDetailsWizardPage extends WRTProjectFilesWizardPage { + + public FlickrProjectDetailsWizardPage(WizardContext context, + DataBindingContext bindingContext) { + super(context, bindingContext); + } - public FlickrProjectDetailsWizardPage(WizardContext context, - DataBindingContext bindingContext) { - super(context, bindingContext); - } - - @Override - protected void addTemplateControls(Composite root) { - context.getExtensions().put("flickrUrl", "http://flickr.com/photos/symbianfoundation"); - createLabel(root, "Flickr URL:"); - createTextForExt(root, "flickrUrl", "Flickr URL"); - createLabel(root, ""); - createLabel(root, ""); - - } + @Override + protected void addTemplateControls(Composite root) { + context.getExtensions().put("flickrUrl", + "http://flickr.com/photos/symbianfoundation"); + context.createLabel(root, "Flickr URL:"); + context.createTextForExt(root, "flickrUrl", "Flickr URL", + bindingContext, this); + context.createLabel(root, ""); + context.createLabel(root, ""); - public static final class Factory implements IWizardPageFactory { - public WRTProjectDetailsWizardPage createPage(WizardContext context, - DataBindingContext bindingContext) { - return new FlickrProjectDetailsWizardPage(context, bindingContext); - } - } + } + + public static final class Factory implements IWizardPageFactory { + public WRTProjectFilesWizardPage createPage(WizardContext context, + DataBindingContext bindingContext) { + return new FlickrProjectDetailsWizardPage(context, bindingContext); + } + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/HelloWithWRTKitProjectDetailsWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/HelloWithWRTKitProjectDetailsWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/HelloWithWRTKitProjectDetailsWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -21,21 +21,23 @@ import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.swt.widgets.Composite; -public class HelloWithWRTKitProjectDetailsWizardPage extends WRTProjectDetailsWizardPage { +public class HelloWithWRTKitProjectDetailsWizardPage extends + WRTProjectFilesWizardPage { + + public HelloWithWRTKitProjectDetailsWizardPage(WizardContext context, + DataBindingContext bindingContext) { + super(context, bindingContext); + } - public HelloWithWRTKitProjectDetailsWizardPage(WizardContext context, - DataBindingContext bindingContext) { - super(context, bindingContext); - } - - @Override - protected void addTemplateControls(Composite root) { - } + @Override + protected void addTemplateControls(Composite root) { + } - public static final class Factory implements IWizardPageFactory { - public WRTProjectDetailsWizardPage createPage(WizardContext context, - DataBindingContext bindingContext) { - return new HelloWithWRTKitProjectDetailsWizardPage(context, bindingContext); - } - } + public static final class Factory implements IWizardPageFactory { + public WRTProjectFilesWizardPage createPage(WizardContext context, + DataBindingContext bindingContext) { + return new HelloWithWRTKitProjectDetailsWizardPage(context, + bindingContext); + } + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/IWizardPageFactory.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/IWizardPageFactory.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/IWizardPageFactory.java Mon Jul 12 18:29:46 2010 -0700 @@ -21,5 +21,6 @@ import org.eclipse.core.databinding.DataBindingContext; public interface IWizardPageFactory { - WRTProjectDetailsWizardPage createPage(WizardContext context, DataBindingContext bindingContext); + WRTProjectFilesWizardPage createPage(WizardContext context, + DataBindingContext bindingContext); } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/RssReaderProjectDetailsWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/RssReaderProjectDetailsWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/RssReaderProjectDetailsWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -24,33 +24,35 @@ import org.eclipse.swt.widgets.Composite; public class RssReaderProjectDetailsWizardPage extends - WRTProjectDetailsWizardPage { + WRTProjectFilesWizardPage { public RssReaderProjectDetailsWizardPage(WizardContext context, DataBindingContext bindingContext) { super(context, bindingContext); } - + @Override protected void addTemplateControls(Composite root) { Map extensions = context.getExtensions(); extensions.put("feedUrl", "http://twitter.com/statuses/user_timeline/21138778.rss"); extensions.put("feedName", "Symbian Twitter"); - - createLabel(root, "Feed URL:"); - createTextForExt(root, "feedUrl", "feed URL"); - createLabel(root, "Feed Name:"); - createTextForExt(root, "feedName", "feed name"); - createLabel(root, ""); - createLabel(root, ""); + + context.createLabel(root, "Feed URL:"); + context.createTextForExt(root, "feedUrl", "feed URL", bindingContext, + this); + context.createLabel(root, "Feed Name:"); + context.createTextForExt(root, "feedName", "feed name", bindingContext, + this); + context.createLabel(root, ""); + context.createLabel(root, ""); } - + public static final class Factory implements IWizardPageFactory { - public WRTProjectDetailsWizardPage createPage(WizardContext context, + public WRTProjectFilesWizardPage createPage(WizardContext context, DataBindingContext bindingContext) { return new RssReaderProjectDetailsWizardPage(context, bindingContext); } - + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -18,67 +18,272 @@ */ package org.symbian.tools.wrttools.wizards; +import java.net.URI; + import org.eclipse.core.databinding.DataBindingContext; -import org.eclipse.core.databinding.beans.BeansObservables; -import org.eclipse.core.databinding.observable.value.IObservableValue; -import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; import org.eclipse.jface.databinding.wizard.WizardPageSupport; +import org.eclipse.jface.dialogs.Dialog; +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.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.internal.ide.IIDEHelpContextIds; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea; +import org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea.IErrorMessageReporter; +import org.symbian.tools.wrttools.Activator; import org.symbian.tools.wrttools.util.RegexpValidator; -public class WRTProjectDetailsWizardPage extends AbstractDataBindingPage { - private boolean isActive; +@SuppressWarnings("restriction") +public final class WRTProjectDetailsWizardPage extends WizardPage { + public static final class ProjectNameValidator implements IValidator { + + public IStatus validate(Object value) { + IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); + + String projectFieldContents = (String) value; + IStatus nameStatus = workspace.validateName(projectFieldContents, + IResource.PROJECT); + if (!nameStatus.isOK()) { + return nameStatus; + } + + IProject handle = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectFieldContents); + if (handle.exists()) { + return new Status( + IStatus.ERROR, + Activator.PLUGIN_ID, + IDEWorkbenchMessages.WizardNewProjectCreationPage_projectExistsMessage); + } + return Status.OK_STATUS; + } + + } + + private ProjectContentsLocationArea locationArea; + private final DataBindingContext bindingContext; + private final WizardContext context; + + public WRTProjectDetailsWizardPage(WizardContext context, + DataBindingContext bindingContext) { + super("WRTApp"); + setImageDescriptor(null); + setTitle("Application Details"); + setDescription("Specify application details"); + this.context = context; + this.bindingContext = bindingContext; + } + + public void createControl(Composite parent) { + Composite root = new Composite(parent, SWT.NONE); + + initializeDialogUnits(parent); + + PlatformUI.getWorkbench().getHelpSystem() + .setHelp(root, IIDEHelpContextIds.NEW_PROJECT_WIZARD_PAGE); + + WizardPageSupport.create(this, bindingContext); + root.setLayout(new GridLayout(2, false)); + context.createLabel(root, "Application name:"); + + context.createText(root, WizardContext.WIDGET_NAME, "application name", + bindingContext, null, new RegexpValidator("[^\\w\\. ]", + "Application name cannot contain {0} character", false)); - public WRTProjectDetailsWizardPage(WizardContext context, DataBindingContext bindingContext) { - super(context, bindingContext, "WRTApp", "Application Details", null, "Specify application details"); - } - - protected void addTemplateControls(Composite root) { - // Subclasses will override - } - - public void createControl(Composite parent) { - Composite root = new Composite(parent, SWT.NONE); - WizardPageSupport.create(this, bindingContext); - root.setLayout(new GridLayout(2, false)); - createLabel(root, "Application name:"); - - createText(root, WizardContext.WIDGET_NAME, "application name", new RegexpValidator("[^\\w\\. ]", "Application name cannot contain {0} character", false)); - - createLabel(root, ""); - createLabel(root, "This will be the application display name on the device"); - createLabel(root, ""); - createLabel(root, ""); - createLabel(root, "Widget identifier:"); + context.createLabel(root, ""); + context.createLabel(root, + "This will be the application display name on the device"); + context.createLabel(root, ""); + context.createLabel(root, ""); + context.createLabel(root, "Widget identifier:"); + + context.createText(root, WizardContext.WIDGET_ID, + "applicatoin identifier", bindingContext, null, + new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*", + "{0} is not a valid applicatoin ID", true)); + context.createLabel(root, ""); + context.createLabel( + root, + "This id should be unique for succesful installation of application on the device"); + context.createLabel(root, ""); + context.createLabel(root, ""); + + createProjectNameGroup(root); + + Composite composite = new Composite(root, SWT.NONE); + GridLayout gridLayout = new GridLayout(1, false); + gridLayout.marginWidth = 0; + composite.setLayout(gridLayout); + composite.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, + true, true, 2, 1)); + + locationArea = new ProjectContentsLocationArea(getErrorReporter(), + composite); + if (context.getProjectName() != null + && context.getProjectName().trim().length() > 0) { + locationArea.updateProjectName(context.getProjectName()); + } + + // Scale the button based on the rest of the dialog + setButtonLayoutData(locationArea.getBrowseButton()); + + setPageComplete(validatePage()); + // Show description on opening + setErrorMessage(null); + setMessage(null); + setControl(root); + Dialog.applyDialogFont(root); + } + + /** + * Creates the project name specification controls. + * + * @param parent + * the parent composite + */ + private final void createProjectNameGroup(Composite parent) { + // new project label + Label projectLabel = new Label(parent, SWT.NONE); + projectLabel + .setText(IDEWorkbenchMessages.WizardNewProjectCreationPage_nameLabel); + projectLabel.setFont(parent.getFont()); + + Text projectNameField = context.createText(parent, + WizardContext.PROJECT_NAME, "project name", bindingContext, + null, new ProjectNameValidator()); - createText(root, WizardContext.WIDGET_ID, "applicatoin identifier", new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*", "{0} is not a valid applicatoin ID", true)); - createLabel(root, ""); - createLabel(root, "This id should be unique for succesful installation of application on the device"); - createLabel(root, ""); - createLabel(root, ""); - - addTemplateControls(root); - - createLabel(root, ""); - Button homeScreen = new Button(root, SWT.CHECK); - homeScreen.setText("Enable HomeScreen"); - - IObservableValue view = SWTObservables.observeSelection(homeScreen); - IObservableValue model = BeansObservables.observeValue(context, WizardContext.HOME_SCREEN); - bindingContext.bindValue(view, model); - - setControl(root); - } + projectNameField.setFont(parent.getFont()); + + projectNameField.addListener(SWT.Modify, nameModifyListener); + } + + /** + * Returns the current project location path as entered by the user, or its + * anticipated initial value. Note that if the default has been returned the + * path in a project description used to create a project should not be set. + * + * @return the project location path or its anticipated initial value. + */ + public IPath getLocationPath() { + return new Path(locationArea.getProjectLocation()); + } + + /** + * /** Returns the current project location URI as entered by the user, or + * null if a valid project location has not been entered. + * + * @return the project location URI, or null + * @since 3.2 + */ + public URI getLocationURI() { + return locationArea.getProjectLocationURI(); + } + + private final Listener nameModifyListener = new Listener() { + public void handleEvent(Event e) { + if (isPageComplete()) { + setLocationForSelection(); + boolean valid = validatePage(); + setPageComplete(valid); + } + } + }; - @Override - protected boolean isActive() { - return isActive; - } + /** + * Get an error reporter for the receiver. + * + * @return IErrorMessageReporter + */ + private IErrorMessageReporter getErrorReporter() { + return new IErrorMessageReporter() { + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.internal.ide.dialogs.ProjectContentsLocationArea + * .IErrorMessageReporter#reportError(java.lang.String) + */ + public void reportError(String errorMessage, boolean infoOnly) { + if (infoOnly) { + setMessage(errorMessage, IStatus.INFO); + setErrorMessage(null); + } else { + setErrorMessage(errorMessage); + } + boolean valid = errorMessage == null; + if (valid) { + valid = validatePage(); + } + + setPageComplete(valid); + } + }; + } + + /** + * Set the location to the default location if we are set to useDefaults. + */ + void setLocationForSelection() { + locationArea.updateProjectName(context.getProjectName()); + } - public void setActive(boolean isActive) { - this.isActive = isActive; - } + /** + * Returns whether this page's controls currently all contain valid values. + * + * @return true if all controls are valid, and + * false if at least one is invalid + */ + protected boolean validatePage() { + if (isPageComplete() || context.getProjectName().trim().length() == 0) { + return false; + } + String projectName = context.getProjectName(); + IProject project = ResourcesPlugin.getWorkspace().getRoot() + .getProject(projectName); + locationArea.setExistingProject(project); + + String validLocationMessage = locationArea.checkValidLocation(); + if (validLocationMessage != null) { // there is no destination location + // given + setErrorMessage(validLocationMessage); + return false; + } + + setErrorMessage(null); + setMessage(null); + return true; + } + + /** + * Returns the useDefaults. + * + * @return boolean + */ + public boolean useDefaults() { + return locationArea.isDefault(); + } + + @Override + public void setVisible(boolean visible) { + // TODO Auto-generated method stub + super.setVisible(visible); + setErrorMessage(null); + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectFilesWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectFilesWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectFilesWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -19,30 +19,74 @@ package org.symbian.tools.wrttools.wizards; import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; import org.eclipse.jface.databinding.wizard.WizardPageSupport; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; public class WRTProjectFilesWizardPage extends AbstractDataBindingPage { - - public WRTProjectFilesWizardPage(WizardContext context, DataBindingContext bindingContext) { - super(context, bindingContext, "WRTApplicationFiles", "Application Files", null, "Specify application file names"); - } + private boolean isActive; + protected final DataBindingContext bindingContext; + protected final WizardContext context; - public void createControl(Composite parent) { - Composite root = new Composite(parent, SWT.NONE); - WizardPageSupport.create(this, bindingContext); - root.setLayout(new GridLayout(2, false)); + public WRTProjectFilesWizardPage(WizardContext context, + DataBindingContext bindingContext) { + super(context, bindingContext, "WRTApplicationFiles", + "Application Files", null, "Specify application file names"); + this.context = context; + this.bindingContext = bindingContext; + } + + protected void addTemplateControls(Composite root) { + // Subclasses will override + } + + public void createControl(Composite parent) { + Composite root = new Composite(parent, SWT.NONE); + WizardPageSupport.create(this, bindingContext); + root.setLayout(new GridLayout(2, false)); - createLabel(root, "Name of main HTML:"); - createText(root, WizardContext.HTML_FILE, "HTML file name"); - createLabel(root, "Name of CSS file:"); - createText(root, WizardContext.CSS_FILE, "CSS file name"); - createLabel(root, "Name of JavaScript file:"); - createText(root, WizardContext.JS_FILE, "JavaScript file name"); - - setControl(root); - } + context.createLabel(root, "Name of main HTML:"); + context.createText(root, WizardContext.HTML_FILE, "HTML file name", + bindingContext, this); + context.createLabel(root, ""); + context.createLabel(root, ""); + context.createLabel(root, "Name of CSS file:"); + context.createText(root, WizardContext.CSS_FILE, "CSS file name", + bindingContext, this); + context.createLabel(root, ""); + context.createLabel(root, ""); + context.createLabel(root, "Name of JavaScript file:"); + context.createText(root, WizardContext.JS_FILE, "JavaScript file name", + bindingContext, this); + + context.createLabel(root, ""); + Button homeScreen = new Button(root, SWT.CHECK); + homeScreen.setText("Enable HomeScreen"); + context.createLabel(root, ""); + context.createLabel(root, ""); + + IObservableValue view = SWTObservables.observeSelection(homeScreen); + IObservableValue model = BeansObservables.observeValue(context, + WizardContext.HOME_SCREEN); + bindingContext.bindValue(view, model); + + addTemplateControls(root); + + setControl(root); + } + + @Override + protected boolean isActive() { + return isActive; + } + + public void setActive(boolean isActive) { + this.isActive = isActive; + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectTemplateWizardPage.java Mon Jul 12 18:29:46 2010 -0700 @@ -33,6 +33,7 @@ import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.ViewerSorter; import org.eclipse.jface.wizard.IWizardPage; +import org.eclipse.jface.wizard.WizardPage; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FormAttachment; @@ -42,162 +43,146 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.symbian.tools.wrttools.core.ProjectTemplate; -@SuppressWarnings("restriction") -public class WRTProjectTemplateWizardPage extends WizardNewProjectCreationPage { - - public class ProjectTemplateLabelProvider extends LabelProvider { +public class WRTProjectTemplateWizardPage extends WizardPage { + public class ProjectTemplateLabelProvider extends LabelProvider { - @Override - public Image getImage(Object element) { - return ((ProjectTemplate) element).getIcon(); - } + @Override + public Image getImage(Object element) { + return ((ProjectTemplate) element).getIcon(); + } - @Override - public String getText(Object element) { - return ((ProjectTemplate) element).getName(); - } - } + @Override + public String getText(Object element) { + return ((ProjectTemplate) element).getName(); + } + } - private TableViewer templates; - private Text description; - private final WizardContext context; - private final DataBindingContext bindingContext; + private TableViewer templates; + private Text description; + private final WizardContext context; + private final DataBindingContext bindingContext; - public WRTProjectTemplateWizardPage(WizardContext context, DataBindingContext bindingContext) { + public WRTProjectTemplateWizardPage(WizardContext context, + DataBindingContext bindingContext) { super("Create a New Mobile Web Application"); setTitle("Create a New Mobile Web Application"); - this.context = context; - this.bindingContext = bindingContext; + this.context = context; + this.bindingContext = bindingContext; setDescription("Select project name and template that will be used to populate"); - } - - @Override - protected void createChildControls(Composite c) { - ProjectTemplate[] allTemplates = ProjectTemplate.getAllTemplates(); + } + + public void createControl(Composite parent) { + ProjectTemplate[] allTemplates = ProjectTemplate.getAllTemplates(); - context.setTemplate(getFirstTemplate(allTemplates)); - Composite composite = new Composite(c, SWT.NONE); - composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); - FormLayout layout = new FormLayout(); - layout.marginWidth = 5; - composite.setLayout(layout); + Composite composite = new Composite(parent, SWT.NONE); + composite.setLayoutData(new GridData(GridData.FILL, GridData.FILL, + true, true)); + FormLayout layout = new FormLayout(); + layout.marginWidth = 5; + composite.setLayout(layout); - templates = new TableViewer(composite, SWT.BORDER | SWT.SINGLE); - FormData templatesData = new FormData(); + templates = new TableViewer(composite, SWT.BORDER | SWT.SINGLE); + FormData templatesData = new FormData(); templatesData.top = new FormAttachment(0, 0); - templatesData.left = new FormAttachment(0, 0); + templatesData.left = new FormAttachment(0, 0); templatesData.right = new FormAttachment(40, -2); templatesData.bottom = new FormAttachment(100, -8); - templates.getControl().setLayoutData(templatesData); - templates.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - IStructuredSelection selection = (IStructuredSelection)event.getSelection(); - final ProjectTemplate - template = (ProjectTemplate) selection.getFirstElement(); - refreshSelection(template); - } - }); - templates.addDoubleClickListener(new IDoubleClickListener() { - public void doubleClick(DoubleClickEvent arg0) { - switchWizardPage(); - } - }); - - description = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT .READ_ONLY); - FormData descriptionData = new FormData(); + templates.getControl().setLayoutData(templatesData); + templates.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + IStructuredSelection selection = (IStructuredSelection) event + .getSelection(); + final ProjectTemplate template = (ProjectTemplate) selection + .getFirstElement(); + refreshSelection(template); + } + }); + templates.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent arg0) { + switchWizardPage(); + } + }); + + description = new Text(composite, SWT.BORDER | SWT.MULTI | SWT.WRAP + | SWT.READ_ONLY); + FormData descriptionData = new FormData(); descriptionData.top = new FormAttachment(0, 0); descriptionData.bottom = new FormAttachment(100, -8); descriptionData.left = new FormAttachment(templates.getControl(), 5); - descriptionData.right = new FormAttachment(100, 0); + descriptionData.right = new FormAttachment(100, 0); descriptionData.width = 50; - description.setLayoutData(descriptionData); - - templates.setContentProvider(new ArrayContentProvider()); - templates.setLabelProvider(new ProjectTemplateLabelProvider()); + description.setLayoutData(descriptionData); + + templates.setContentProvider(new ArrayContentProvider()); + templates.setLabelProvider(new ProjectTemplateLabelProvider()); templates.setSorter(new ViewerSorter() { @Override public int category(Object element) { return Integer.valueOf(((ProjectTemplate) element).getOrder()); } }); - templates.setInput(allTemplates); - - setPageComplete(false); + templates.setInput(allTemplates); + + setPageComplete(false); - IViewerObservableValue selection = ViewersObservables.observeSingleSelection(templates); - IObservableValue property = BeansObservables.observeValue(context, WizardContext.TEMPLATE); - - bindingContext.bindValue(selection, property); - if (context.getTemplate() != null) { - refreshSelection(context.getTemplate()); - } - setErrorMessage(null); - } + IViewerObservableValue selection = ViewersObservables + .observeSingleSelection(templates); + IObservableValue property = BeansObservables.observeValue(context, + WizardContext.TEMPLATE); - private ProjectTemplate getFirstTemplate(ProjectTemplate[] allTemplates) { - ProjectTemplate template = null; - for (ProjectTemplate projectTemplate : allTemplates) { - if (template == null || template.getOrder() > projectTemplate.getOrder()) { - template = projectTemplate; - } + bindingContext.bindValue(selection, property); + if (context.getTemplate() != null) { + refreshSelection(context.getTemplate()); } - return template; + setErrorMessage(null); + setControl(composite); } protected void switchWizardPage() { - Display display = getShell().getDisplay(); - display.asyncExec(new Runnable() { - public void run() { - if (isPageComplete()) { - IWizardPage nextPage = getWizard().getNextPage(WRTProjectTemplateWizardPage.this); - getContainer().showPage(nextPage); - } - } - }); - } - - protected void refreshSelection(ProjectTemplate template) { - if (template != null) { - description.setText(template.getDescription()); - } else { - description.setText(""); - } - validatePage(); - } + Display display = getShell().getDisplay(); + display.asyncExec(new Runnable() { + public void run() { + if (isPageComplete()) { + IWizardPage nextPage = getWizard().getNextPage( + WRTProjectTemplateWizardPage.this); + getContainer().showPage(nextPage); + } + } + }); + } - @Override + protected void refreshSelection(ProjectTemplate template) { + if (template != null) { + description.setText(template.getDescription()); + } else { + description.setText(""); + } + validatePage(); + } + protected boolean validatePage() { - boolean parentValidation = super.validatePage(); - if (!parentValidation && getProjectName().trim().length() == 0) { - setMessage(null); - setErrorMessage(IDEWorkbenchMessages.WizardNewProjectCreationPage_projectNameEmpty); + if (templates.getSelection().isEmpty()) { + setErrorMessage("Project template is not selected"); + setPageComplete(false); return false; - } else if (parentValidation) { - if (templates.getSelection().isEmpty()) { - setErrorMessage("Project template is not selected"); - setPageComplete(false); - return false; - } else { - setErrorMessage(null); - setPageComplete(true); - return true; - } } else { - return false; + setErrorMessage(null); + setPageComplete(true); + return true; } } - public ProjectTemplate getSelectedProjectTemplate() { - IStructuredSelection selection = (IStructuredSelection) templates.getSelection(); - return (ProjectTemplate) selection.getFirstElement(); - } - - @Override - public void setVisible(boolean visible) { - super.setVisible(visible); - templates.getControl().setFocus(); - } + public ProjectTemplate getSelectedProjectTemplate() { + IStructuredSelection selection = (IStructuredSelection) templates + .getSelection(); + return (ProjectTemplate) selection.getFirstElement(); + } + + @Override + public void setVisible(boolean visible) { + super.setVisible(visible); + templates.getControl().setFocus(); + } } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java Mon Jul 12 18:29:46 2010 -0700 @@ -20,7 +20,6 @@ import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; -import java.net.URI; import java.text.MessageFormat; import java.util.Arrays; import java.util.Collections; @@ -29,262 +28,277 @@ import java.util.Set; import java.util.TreeMap; +import org.eclipse.core.databinding.DataBindingContext; +import org.eclipse.core.databinding.UpdateValueStrategy; +import org.eclipse.core.databinding.beans.BeansObservables; +import org.eclipse.core.databinding.observable.Observables; +import org.eclipse.core.databinding.observable.map.IObservableMap; +import org.eclipse.core.databinding.observable.value.IObservableValue; +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.jface.databinding.swt.ISWTObservableValue; +import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; import org.symbian.tools.wrttools.core.ProjectTemplate; import org.symbian.tools.wrttools.core.libraries.JSLibrary; +import org.symbian.tools.wrttools.util.CompoundValidator; import org.symbian.tools.wrttools.util.Util; public class WizardContext { - public static final String PROJECT_URI = "projectUri"; - public static final String CSS_FILE = "cssFile"; - public static final String HTML_FILE = "htmlFile"; - public static final String JS_FILE = "jsFile"; - public static final String PROJECT_NAME = "projectName"; - public static final String TEMPLATE = "template"; - public static final String WIDGET_ID = "widgetId"; - public static final String WIDGET_NAME = "widgetName"; - public static final String HOME_SCREEN = "homeScreen"; + public static final String CSS_FILE = "cssFile"; + public static final String HTML_FILE = "htmlFile"; + public static final String JS_FILE = "jsFile"; + public static final String TEMPLATE = "template"; + public static final String WIDGET_ID = "widgetId"; + public static final String WIDGET_NAME = "widgetName"; + public static final String HOME_SCREEN = "homeScreen"; public static final String LIBRARIES = "libraries"; + public static final String PROJECT_NAME = "projectName"; - private String cssFile; - private String htmlFile; - private String jsFile; - private String projectName; - private final PropertyChangeSupport propertySupport = new PropertyChangeSupport(this); - private ProjectTemplate template; - private String widgetId; - private String widgetName; - private Map extensions = new TreeMap(); - private URI projectUri; - private boolean homeScreen; + private String cssFile; + private String projectName; + private String htmlFile; + private String jsFile; + private final PropertyChangeSupport propertySupport = new PropertyChangeSupport( + this); + private ProjectTemplate template; + private String widgetId; + private String widgetName; + private Map extensions = new TreeMap(); + private boolean homeScreen; private Set libraries = new HashSet(); - public void addPropertyChangeListener(PropertyChangeListener arg0) { - propertySupport.addPropertyChangeListener(arg0); - } - - public void addPropertyChangeListener(String arg0, - PropertyChangeListener arg1) { - propertySupport.addPropertyChangeListener(arg0, arg1); - } + public WizardContext() { + setTemplate(getFirstTemplate(ProjectTemplate.getAllTemplates())); + } - public String getCssFile() { - if (cssFile == null) { - if (template != null) { - return template.getDefaultCssFile(); - } - } - return cssFile; - } + private ProjectTemplate getFirstTemplate(ProjectTemplate[] allTemplates) { + ProjectTemplate template = null; + for (ProjectTemplate projectTemplate : allTemplates) { + if (template == null + || template.getOrder() > projectTemplate.getOrder()) { + template = projectTemplate; + } + } + return template; + } + + + public void addPropertyChangeListener(PropertyChangeListener arg0) { + propertySupport.addPropertyChangeListener(arg0); + } + + public void addPropertyChangeListener(String arg0, + PropertyChangeListener arg1) { + propertySupport.addPropertyChangeListener(arg0, arg1); + } - private String getDefaultWidgetId() { - if (template != null) { - return MessageFormat - .format(template.getIdFormat(), Util.removeSpaces(getWidgetName())); - } else { - return null; - } - } + public String getProjectName() { + return (projectName == null ? getDefaultProjectName() : projectName); + } + + private String getDefaultProjectName() { + return Util.toProjectName(getWidgetName()); + } - public String getHtmlFile() { - if (htmlFile == null) { - if (template != null) { - return template.getDefaultHtmlFile(); - } - } - return htmlFile; - } + public void setProjectName(String projectName) { + String prev = getProjectName(); + if (projectName.equals(getDefaultProjectName())) { + this.projectName = null; + } else { + this.projectName = projectName; + } + propertySupport.firePropertyChange(PROJECT_NAME, projectName, prev); + } - public String getJsFile() { - if (jsFile == null) { - if (template != null) { - return template.getDefaultJsFile(); - } - } - return jsFile; - } - - public String getProjectName() { - return projectName; - } + public String getCssFile() { + if (cssFile == null) { + if (template != null) { + return template.getDefaultCssFile(); + } + } + return cssFile; + } - public ProjectTemplate getTemplate() { - return template; - } - - public String getWidgetId() { - if (widgetId == null) { - return getDefaultWidgetId(); - } - return widgetId; - } + private String getDefaultWidgetId() { + String name = Util.removeSpaces(getWidgetName()); + return MessageFormat.format("com.company.{0}", name.length() > 0 ? name + : "ApplicationName"); + } - public String getWidgetName() { - return widgetName != null ? widgetName : Util.removeNonAlphaNum(getProjectName()); - } + public String getHtmlFile() { + if (htmlFile == null) { + if (template != null) { + return template.getDefaultHtmlFile(); + } + } + return htmlFile; + } - public void removePropertyChangeListener(PropertyChangeListener arg0) { - propertySupport.removePropertyChangeListener(arg0); - } + public String getJsFile() { + if (jsFile == null) { + if (template != null) { + return template.getDefaultJsFile(); + } + } + return jsFile; + } - public void removePropertyChangeListener(String arg0, - PropertyChangeListener arg1) { - propertySupport.removePropertyChangeListener(arg0, arg1); - } + public ProjectTemplate getTemplate() { + return template; + } - public void setCssFile(String cssFile) { - if (template != null && template.getDefaultCssFile().equals(cssFile)) { - cssFile = null; - } - String prev = this.cssFile; - this.cssFile = cssFile; - propertySupport.firePropertyChange(CSS_FILE, cssFile, prev); - } + public String getWidgetId() { + if (widgetId == null) { + return getDefaultWidgetId(); + } + return widgetId; + } + + public String getWidgetName() { + return widgetName; + } - public void setHtmlFile(String htmlFile) { - if (template != null && template.getDefaultHtmlFile().equals(htmlFile)) { - htmlFile = null; - } - String prev = this.htmlFile; - this.htmlFile = htmlFile; - propertySupport.firePropertyChange(HTML_FILE, htmlFile, prev); - } + public void removePropertyChangeListener(PropertyChangeListener arg0) { + propertySupport.removePropertyChangeListener(arg0); + } + + public void removePropertyChangeListener(String arg0, + PropertyChangeListener arg1) { + propertySupport.removePropertyChangeListener(arg0, arg1); + } - public void setJsFile(String jsFile) { - if (template != null && template.getDefaultJsFile().equals(jsFile)) { - jsFile = null; - } - String prev = this.jsFile; - this.jsFile = jsFile; - propertySupport.firePropertyChange(JS_FILE, jsFile, prev); - } + public void setCssFile(String cssFile) { + if (template != null && template.getDefaultCssFile().equals(cssFile)) { + cssFile = null; + } + String prev = this.cssFile; + this.cssFile = cssFile; + propertySupport.firePropertyChange(CSS_FILE, cssFile, prev); + } - public void setProjectName(String projectName) { - String prevName = getWidgetName(); - String prevId = getWidgetId(); - String prev = this.projectName; - this.projectName = projectName; - propertySupport.firePropertyChange(PROJECT_NAME, projectName, prev); - if (widgetName == null) { - propertySupport.firePropertyChange(WIDGET_NAME, getWidgetName(), - prevName); - if (widgetId == null) { - propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), - prevId); - } - } - } + public void setHtmlFile(String htmlFile) { + if (template != null && template.getDefaultHtmlFile().equals(htmlFile)) { + htmlFile = null; + } + String prev = this.htmlFile; + this.htmlFile = htmlFile; + propertySupport.firePropertyChange(HTML_FILE, htmlFile, prev); + } + + public void setJsFile(String jsFile) { + if (template != null && template.getDefaultJsFile().equals(jsFile)) { + jsFile = null; + } + String prev = this.jsFile; + this.jsFile = jsFile; + propertySupport.firePropertyChange(JS_FILE, jsFile, prev); + } - public void setTemplate(ProjectTemplate template) { - String id = getWidgetId(); - String html = getHtmlFile(); - String js = getJsFile(); - String css = getCssFile(); - ProjectTemplate prev = this.template; - this.template = template; - propertySupport.firePropertyChange(TEMPLATE, template, prev); - if (widgetId == null) { - propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), id); - } - if (htmlFile == null) { - propertySupport.firePropertyChange(HTML_FILE, getHtmlFile(), html); - } - if (jsFile == null) { - propertySupport.firePropertyChange(JS_FILE, getJsFile(), js); - } - if (cssFile == null) { - propertySupport.firePropertyChange(CSS_FILE, getCssFile(), css); - } - if (cssFile == null) { - propertySupport.firePropertyChange(LIBRARIES, getLibraries(), libraries); + public void setTemplate(ProjectTemplate template) { + String html = getHtmlFile(); + String js = getJsFile(); + String css = getCssFile(); + ProjectTemplate prev = this.template; + this.template = template; + propertySupport.firePropertyChange(TEMPLATE, template, prev); + if (htmlFile == null) { + propertySupport.firePropertyChange(HTML_FILE, getHtmlFile(), html); + } + if (jsFile == null) { + propertySupport.firePropertyChange(JS_FILE, getJsFile(), js); } - } - - public void setWidgetId(String widgetId) { - String prev = getWidgetId(); - if (getDefaultWidgetId().equals(widgetId)) { - widgetId = null; - } - this.widgetId = widgetId; - propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prev); - } + if (cssFile == null) { + propertySupport.firePropertyChange(CSS_FILE, getCssFile(), css); + } + if (cssFile == null) { + propertySupport.firePropertyChange(LIBRARIES, getLibraries(), + libraries); + } + } - public void setWidgetName(String widgetName) { - String prevId = getWidgetId(); - String prev = getWidgetName(); - if (projectName.equals(widgetName)) { - widgetName = null; - } - this.widgetName = widgetName; - propertySupport.firePropertyChange(WIDGET_NAME, widgetName, prev); - if (widgetId == null) { - propertySupport - .firePropertyChange(WIDGET_ID, getWidgetId(), prevId); - } - } + public void setWidgetId(String widgetId) { + String prev = getWidgetId(); + if (getDefaultWidgetId().equals(widgetId)) { + widgetId = null; + } + this.widgetId = widgetId; + propertySupport.firePropertyChange(WIDGET_ID, getWidgetId(), prev); + } - public void setExtensions(Map extensions) { - this.extensions = extensions; - } - - public Map getExtensions() { - return extensions; - } + public void setWidgetName(String widgetName) { + String prevPn = getProjectName(); + String prevId = getWidgetId(); + String prev = getWidgetName(); + this.widgetName = widgetName; + propertySupport.firePropertyChange(WIDGET_NAME, widgetName, prev); + if (widgetId == null) { + propertySupport + .firePropertyChange(WIDGET_ID, getWidgetId(), prevId); + } + if (projectName == null) { + propertySupport.firePropertyChange(PROJECT_NAME, getProjectName(), + prevPn); + } + } - public void setProjectUri(URI uri) { - URI orig = projectUri; - this.projectUri = uri; - propertySupport.firePropertyChange(PROJECT_URI, projectUri, orig); - } - - public URI getProjectUri() { - return projectUri; - } - - public Map getTemplateVars() { - Map vars = new TreeMap(); - - vars.put("widgetName", getWidgetName()); - vars.put("widgetId", getWidgetId()); - vars.put("mainHtml", getHtmlFileName()); - vars.put("mainCss", getCssFileName()); - vars.put("mainJs", getJsFileName()); - vars.put("homeScreen", String.valueOf(isHomeScreen())); - vars.putAll(extensions); - - return vars ; - } + public void setExtensions(Map extensions) { + this.extensions = extensions; + } + + public Map getExtensions() { + return extensions; + } + + public Map getTemplateVars() { + Map vars = new TreeMap(); + + vars.put("widgetName", getWidgetName()); + vars.put("widgetId", getWidgetId()); + vars.put("mainHtml", getHtmlFileName()); + vars.put("mainCss", getCssFileName()); + vars.put("mainJs", getJsFileName()); + vars.put("homeScreen", String.valueOf(isHomeScreen())); + vars.putAll(extensions); - public boolean isHomeScreen() { - return homeScreen; - } - - public void setHomeScreen(boolean homeScreen) { - boolean old = homeScreen; - this.homeScreen = homeScreen; - propertySupport.firePropertyChange(HOME_SCREEN, old, homeScreen); - } - - public String getHtmlFileName() { - return stripExtension(getHtmlFile(), "htm", "html"); - } - - public String getJsFileName() { - return stripExtension(getJsFile(), "js"); - } + return vars; + } + + public boolean isHomeScreen() { + return homeScreen; + } + + public void setHomeScreen(boolean homeScreen) { + boolean old = homeScreen; + this.homeScreen = homeScreen; + propertySupport.firePropertyChange(HOME_SCREEN, old, homeScreen); + } + + public String getHtmlFileName() { + return stripExtension(getHtmlFile(), "htm", "html"); + } - public String getCssFileName() { - return stripExtension(getCssFile(), "css"); - } - - private String stripExtension(String fileName, String... extensions) { - for (String extension : extensions) { - String extensionAndDot = "." + extension; - if (fileName.endsWith(extensionAndDot)) { - return fileName.substring(0, fileName.length() - extensionAndDot.length()); - } - } - return fileName; - } + public String getJsFileName() { + return stripExtension(getJsFile(), "js"); + } + + public String getCssFileName() { + return stripExtension(getCssFile(), "css"); + } + + private String stripExtension(String fileName, String... extensions) { + for (String extension : extensions) { + String extensionAndDot = "." + extension; + if (fileName.endsWith(extensionAndDot)) { + return fileName.substring(0, fileName.length() + - extensionAndDot.length()); + } + } + return fileName; + } public boolean isRequiredLibrary(JSLibrary element) { return template != null && template.requires(element); @@ -307,4 +321,42 @@ public Map getLibraryParameters(JSLibrary library) { return Collections.emptyMap(); } + + protected Text createText(Composite root, String property, + String propertyName, DataBindingContext bindingContext, + AbstractDataBindingPage page, IValidator... validators) { + return createText(root, BeansObservables.observeValue(this, property), + propertyName, bindingContext, page, validators); + } + + protected Text createTextForExt(Composite root, String property, + String propertyName, DataBindingContext bindingContext, + AbstractDataBindingPage page) { + IObservableMap map = BeansObservables.observeMap(this, "extensions"); + IObservableValue entry = Observables.observeMapEntry(map, property, + String.class); + return createText(root, entry, propertyName, bindingContext, page); + } + + private Text createText(Composite root, IObservableValue model, + String propertyName, DataBindingContext bindingContext, + AbstractDataBindingPage page, IValidator... validators) { + Text text = new Text(root, SWT.BORDER); + text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + ISWTObservableValue view = SWTObservables.observeText(text, SWT.Modify); + UpdateValueStrategy strategy = new UpdateValueStrategy( + UpdateValueStrategy.POLICY_UPDATE); + NonEmptyStringValidator validator = new NonEmptyStringValidator( + propertyName, page); + strategy.setBeforeSetValidator(validators.length == 0 ? validator + : new CompoundValidator(validator, validators)); + bindingContext.bindValue(view, model, strategy, null); + return text; + } + + protected void createLabel(Composite root, String text) { + Label label = new Label(root, SWT.NONE); + label.setText(text); + } + } diff -r 99afbaa8a4bc -r 57fff6202b74 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java --- a/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Fri Jul 09 17:49:55 2010 -0700 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Mon Jul 12 18:29:46 2010 -0700 @@ -26,6 +26,7 @@ import java.io.Reader; import java.io.Writer; import java.lang.reflect.InvocationTargetException; +import java.net.URI; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -63,13 +64,15 @@ import org.symbian.tools.wrttools.util.ProjectUtils; import org.symbian.tools.wrttools.wizards.libraries.WRTProjectLibraryWizardPage; -public class WrtWidgetWizard extends Wizard implements INewWizard, IExecutableExtension { +public class WrtWidgetWizard extends Wizard implements INewWizard, + IExecutableExtension { private WizardContext context; private DataBindingContext bindingContext; - private final Map templateDetails = new HashMap(); + private final Map templateDetails = new HashMap(); private WRTProjectTemplateWizardPage templatesPage; - private WRTProjectFilesWizardPage filesPage; + private WRTProjectDetailsWizardPage detailsPage; private IConfigurationElement config; + private WRTProjectLibraryWizardPage librariesPage; public WrtWidgetWizard() { setDefaultPageImageDescriptor(WRTImages.newWizardBanner()); @@ -79,10 +82,12 @@ public boolean performFinish() { final IProject[] holder = new IProject[1]; + final URI locationURI = detailsPage.getLocationURI(); try { getContainer().run(true, true, new IRunnableWithProgress() { - public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - holder[0] = action(monitor); + public void run(IProgressMonitor monitor) + throws InvocationTargetException, InterruptedException { + holder[0] = action(locationURI, monitor); } }); } catch (InvocationTargetException e) { @@ -97,12 +102,12 @@ return true; } - protected IProject action(IProgressMonitor monitor) { + protected IProject action(final URI locationURI, IProgressMonitor monitor) { final IProject[] holder = new IProject[1]; try { ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { - holder[0] = createAndInitProject(monitor); + holder[0] = createAndInitProject(locationURI, monitor); } }, monitor); } catch (CoreException e) { @@ -111,36 +116,41 @@ return holder[0]; } - protected IProject createAndInitProject(IProgressMonitor monitor) throws CoreException { + protected IProject createAndInitProject(URI locationURI, + IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating project", 100); - IProject project = ProjectUtils.createWrtProject(context.getProjectName(), context.getProjectUri(), - new SubProgressMonitor(monitor, 30)); + final IProject project = ProjectUtils.createWrtProject(context + .getProjectName(), locationURI, new SubProgressMonitor(monitor, + 30)); populateProject(project, new SubProgressMonitor(monitor, 30)); try { - initLibraries(project, context.getLibraries(), new SubProgressMonitor(monitor, 40)); + initLibraries(project, context.getLibraries(), + new SubProgressMonitor(monitor, 40)); } catch (IOException e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed to setup libraries", e)); + throw new CoreException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, "Failed to setup libraries", e)); } monitor.done(); return project; } - private void initLibraries(IProject project, Set set, IProgressMonitor progressMonitor) - throws IOException, CoreException { + private void initLibraries(IProject project, Set set, + IProgressMonitor progressMonitor) throws IOException, CoreException { if (set.isEmpty()) { progressMonitor.done(); return; } progressMonitor.beginTask("Installing JS libraries", 100); int perContainer = 90 / set.size(); - for (JSLibrary library: set) { - library.install(project, context.getLibraryParameters(library), new SubProgressMonitor(progressMonitor, - perContainer)); + for (JSLibrary library : set) { + library.install(project, context.getLibraryParameters(library), + new SubProgressMonitor(progressMonitor, perContainer)); } progressMonitor.done(); } - private void populateProject(IProject project, IProgressMonitor monitor) throws CoreException { + private void populateProject(IProject project, IProgressMonitor monitor) + throws CoreException { URL projectContents = context.getTemplate().getProjectContents(); Map vars = context.getTemplateVars(); @@ -149,34 +159,44 @@ Velocity.init(); VelocityContext ctx = new VelocityContext(vars); stream = new ZipInputStream(projectContents.openStream()); - monitor.beginTask("Generating project contents", IProgressMonitor.UNKNOWN); + monitor.beginTask("Generating project contents", + IProgressMonitor.UNKNOWN); ZipEntry entry; - while ((entry = stream.getNextEntry()) != null && !monitor.isCanceled()) { + while ((entry = stream.getNextEntry()) != null + && !monitor.isCanceled()) { String name = entry.getName(); boolean isVelocity = name.endsWith(".velocitytemplate"); if (isVelocity) { - name = name.substring(0, name.length() - ".velocitytemplate".length()); + name = name.substring(0, name.length() + - ".velocitytemplate".length()); } if (name.startsWith("$")) { int dotLocation = name.indexOf("."); - String template = name.substring(1, dotLocation > 1 ? dotLocation : name.length()); + String template = name.substring(1, + dotLocation > 1 ? dotLocation : name.length()); if (vars.containsKey(template)) { - name = vars.get(template) + name.substring(dotLocation > 1 ? dotLocation : name.length()); + name = vars.get(template) + + name.substring(dotLocation > 1 ? dotLocation + : name.length()); } } if (entry.isDirectory()) { IFolder folder = project.getFolder(entry.getName()); - folder.create(false, true, new SubProgressMonitor(monitor, 1)); + folder.create(false, true, new SubProgressMonitor(monitor, + 1)); } else if (isVelocity) { - copyTemplate(project, name, stream, (int) entry.getSize(), ctx, monitor); + copyTemplate(project, name, stream, (int) entry.getSize(), + ctx, monitor); } else { - ProjectUtils.copyFile(project, name, stream, entry.getSize(), monitor); + ProjectUtils.copyFile(project, name, stream, + entry.getSize(), monitor); } stream.closeEntry(); } monitor.done(); } catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Project creation failed", e)); + throw new CoreException(new Status(IStatus.ERROR, + Activator.PLUGIN_ID, "Project creation failed", e)); } finally { if (stream != null) { try { @@ -188,7 +208,8 @@ } } - private void copyTemplate(IProject project, String name, ZipInputStream stream, int size, VelocityContext ctx, + private void copyTemplate(IProject project, String name, + ZipInputStream stream, int size, VelocityContext ctx, IProgressMonitor monitor) throws IOException, CoreException { // Templates will not be more then a few megs - we can afford the memory ByteArrayOutputStream file = new ByteArrayOutputStream(); @@ -201,7 +222,8 @@ reader.close(); writer.close(); - ByteArrayInputStream contents = new ByteArrayInputStream(file.toByteArray()); + ByteArrayInputStream contents = new ByteArrayInputStream( + file.toByteArray()); IFile f = project.getFile(name); f.create(contents, true, new SubProgressMonitor(monitor, 1)); } @@ -213,50 +235,54 @@ @Override public void addPages() { - templatesPage = new WRTProjectTemplateWizardPage(context, bindingContext); + detailsPage = new WRTProjectDetailsWizardPage(context, bindingContext); + addPage(detailsPage); + + templatesPage = new WRTProjectTemplateWizardPage(context, + bindingContext); addPage(templatesPage); ProjectTemplate[] templates = ProjectTemplate.getAllTemplates(); for (ProjectTemplate projectTemplate : templates) { - WRTProjectDetailsWizardPage page = projectTemplate.createWizardPage(context, bindingContext); + final WRTProjectFilesWizardPage page = projectTemplate + .createWizardPage(context, bindingContext); addPage(page); templateDetails.put(projectTemplate, page); } - filesPage = new WRTProjectFilesWizardPage(context, bindingContext); - addPage(filesPage); - - addPage(new WRTProjectLibraryWizardPage(context, bindingContext)); + librariesPage = new WRTProjectLibraryWizardPage(context, bindingContext); + addPage(librariesPage); } @Override public boolean canFinish() { - return super.canFinish() && getContainer().getCurrentPage() == getPages()[getPageCount() - 1]; + return super.canFinish() + && getContainer().getCurrentPage() == getPages()[getPageCount() - 1]; } @Override public IWizardPage getNextPage(IWizardPage page) { if (page == templatesPage) { - context.setProjectName(templatesPage.getProjectName()); - context.setProjectUri(templatesPage.getLocationURI()); ProjectTemplate template = context.getTemplate(); if (template != null) { - WRTProjectDetailsWizardPage activePage = templateDetails.get(template); - for (WRTProjectDetailsWizardPage wizardPage : templateDetails.values()) { + WRTProjectFilesWizardPage activePage = templateDetails + .get(template); + for (WRTProjectFilesWizardPage wizardPage : templateDetails + .values()) { wizardPage.setActive(wizardPage == activePage); } bindingContext.updateModels(); return activePage; } } - if (page instanceof WRTProjectDetailsWizardPage) { - return filesPage; + if (page instanceof WRTProjectFilesWizardPage) { + return librariesPage; } return super.getNextPage(page); } - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) - throws CoreException { + public void setInitializationData(IConfigurationElement config, + String propertyName, Object data) throws CoreException { this.config = config; } }