# HG changeset patch # User Eugene Ostroukhov # Date 1263244516 28800 # Node ID f1b0259bb4102039b8ace289dc27dbf0be7b59e1 # Parent 718b6c524eba76bb5588f10242938cfe664c6837 Validation was added to new project creation wizard diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/CompoundValidator.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/CompoundValidator.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/RegexpValidator.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/RegexpValidator.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/Util.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/util/Util.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage$NonEmptyStringValidator.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage$NonEmptyStringValidator.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectFilesWizardPage.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WRTProjectFilesWizardPage.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WizardContext.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WizardContext.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.class Binary file org.symbian.tools.wrttools/bin/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.class has changed diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/plugin.xml --- a/org.symbian.tools.wrttools/plugin.xml Fri Jan 08 17:41:28 2010 -0800 +++ b/org.symbian.tools.wrttools/plugin.xml Mon Jan 11 13:15:16 2010 -0800 @@ -70,6 +70,16 @@ Creates a new Symbian WRT widget project using one of the provided templates + + diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CompoundValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/CompoundValidator.java Mon Jan 11 13:15:16 2010 -0800 @@ -0,0 +1,57 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools.util; + +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; + + +public class CompoundValidator implements IValidator { + private final IValidator[] validators; + + public CompoundValidator(IValidator ... validators) { + this.validators = validators; + } + + public CompoundValidator(NonEmptyStringValidator validator, + IValidator[] validators) { + this.validators = new IValidator[validators.length + 1]; + this.validators[0] = validator; + System.arraycopy(validators, 0, this.validators, 1, validators.length); + } + + @Override + public IStatus validate(Object value) { + IStatus status = Status.OK_STATUS; + + for (IValidator validator : validators) { + IStatus s = validator.validate(value); + switch (s.getSeverity()) { + case IStatus.ERROR: + return s; + case IStatus.WARNING: + status = s; + } + } + return status; + } + +} diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/RegexpValidator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/RegexpValidator.java Mon Jan 11 13:15:16 2010 -0800 @@ -0,0 +1,54 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools.util; + +import java.text.MessageFormat; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.core.databinding.validation.IValidator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.symbian.tools.wrttools.Activator; + +public class RegexpValidator implements IValidator { + private final String errorMessage; + private Pattern pattern; + private final boolean match; + + public RegexpValidator(String pattern, String errorMessage, boolean match) { + this.errorMessage = errorMessage; + this.match = match; + this.pattern = Pattern.compile(pattern); + } + + @Override + public IStatus validate(Object value) { + String string = value.toString(); + Matcher matcher = pattern.matcher(string); + if (match && !matcher.matches()) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(errorMessage, string)); + } else if (!match && matcher.find()) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(errorMessage, string.substring(matcher.start(), matcher.end()))); + } else { + return Status.OK_STATUS; + } + } + +} diff -r 718b6c524eba -r f1b0259bb410 org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/util/Util.java Mon Jan 11 13:15:16 2010 -0800 @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies). + * All rights reserved. + * This component and the accompanying materials are made available + * under the terms of the License "Eclipse Public License v1.0" + * which accompanies this distribution, and is available + * at the URL "http://www.eclipse.org/legal/epl-v10.html". + * + * Initial Contributors: + * Symbian Foundation - initial contribution. + * Contributors: + * Description: + * Overview: + * Details: + * Platforms/Drives/Compatibility: + * Assumptions/Requirement/Pre-requisites: + * Failures and causes: + */ +package org.symbian.tools.wrttools.util; + +public class Util { + + public static String removeSpaces(String widgetName) { + return widgetName != null ? widgetName.replace(" ", "") : null; + } + + public static String removeNonAlphaNum(String projectName) { + return projectName != null ? projectName.replaceAll("[^a-zA-Z0-9 ]", "") : null; + } + +} diff -r 718b6c524eba -r f1b0259bb410 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 Jan 08 17:41:28 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/AbstractDataBindingPage.java Mon Jan 11 13:15:16 2010 -0800 @@ -39,6 +39,7 @@ 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 { @@ -78,9 +79,9 @@ } protected Text createText(Composite root, String property, - String propertyName) { + String propertyName, IValidator... validators) { return createText(root, BeansObservables - .observeValue(context, property), propertyName); + .observeValue(context, property), propertyName, validators); } protected Text createTextForExt(Composite root, String property, @@ -92,14 +93,16 @@ } private Text createText(Composite root, IObservableValue model, - String propertyName) { + 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); - strategy - .setBeforeSetValidator(new NonEmptyStringValidator(propertyName)); + NonEmptyStringValidator validator = new NonEmptyStringValidator( + propertyName); + strategy.setBeforeSetValidator(validators.length == 0 ? validator + : new CompoundValidator(validator, validators)); bindingContext.bindValue(view, model, strategy, null); return text; } diff -r 718b6c524eba -r f1b0259bb410 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 Jan 08 17:41:28 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WRTProjectDetailsWizardPage.java Mon Jan 11 13:15:16 2010 -0800 @@ -27,6 +27,7 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.symbian.tools.wrttools.util.RegexpValidator; public class WRTProjectDetailsWizardPage extends AbstractDataBindingPage { private boolean isActive; @@ -46,7 +47,7 @@ root.setLayout(new GridLayout(2, false)); createLabel(root, "Widget name:"); - createText(root, WizardContext.WIDGET_NAME, "widget name"); + createText(root, WizardContext.WIDGET_NAME, "widget name", new RegexpValidator("[^\\w\\. ]", "Widget name cannot contain {0} character", false)); createLabel(root, ""); createLabel(root, "This will be the widget's display name on the device"); @@ -54,7 +55,7 @@ createLabel(root, ""); createLabel(root, "Widget identifier:"); - createText(root, WizardContext.WIDGET_ID, "widget identifier"); + createText(root, WizardContext.WIDGET_ID, "widget identifier", new RegexpValidator("[\\w]*(\\.\\w[\\w]*)*", "{0} is not a valid widget ID", true)); createLabel(root, ""); createLabel(root, "This id should be unique for succesful installation of widget on the device"); createLabel(root, ""); @@ -70,7 +71,6 @@ IObservableValue model = BeansObservables.observeValue(context, WizardContext.HOME_SCREEN); bindingContext.bindValue(view, model); - setControl(root); } diff -r 718b6c524eba -r f1b0259bb410 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 Jan 08 17:41:28 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WizardContext.java Mon Jan 11 13:15:16 2010 -0800 @@ -26,6 +26,7 @@ import java.util.TreeMap; import org.symbian.tools.wrttools.core.ProjectTemplate; +import org.symbian.tools.wrttools.util.Util; public class WizardContext { public static final String PROJECT_URI = "projectUri"; @@ -71,7 +72,7 @@ private String getDefaultWidgetId() { if (template != null) { return MessageFormat - .format(template.getIdFormat(), getWidgetName()); + .format(template.getIdFormat(), Util.removeSpaces(getWidgetName())); } else { return null; } @@ -111,7 +112,7 @@ } public String getWidgetName() { - return widgetName != null ? widgetName : getProjectName(); + return widgetName != null ? widgetName : Util.removeNonAlphaNum(getProjectName()); } public void removePropertyChangeListener(PropertyChangeListener arg0) { @@ -234,9 +235,9 @@ vars.put("widgetName", getWidgetName()); vars.put("widgetId", getWidgetId()); - vars.put("mainHtml", getHtmlFile()); - vars.put("mainCss", getCssFile()); - vars.put("mainJs", getJsFile()); + vars.put("mainHtml", getHtmlFileName()); + vars.put("mainCss", getCssFileName()); + vars.put("mainJs", getJsFileName()); vars.put("homeScreen", String.valueOf(isHomeScreen())); vars.putAll(extensions); @@ -252,4 +253,26 @@ this.homeScreen = homeScreen; propertySupport.firePropertyChange(HOME_SCREEN, old, homeScreen); } + + public String getHtmlFileName() { + return stripExtension(getHtmlFile(), "htm", "html"); + } + + 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; + } } diff -r 718b6c524eba -r f1b0259bb410 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 Jan 08 17:41:28 2010 -0800 +++ b/org.symbian.tools.wrttools/src/org/symbian/tools/wrttools/wizards/WrtWidgetWizard.java Mon Jan 11 13:15:16 2010 -0800 @@ -166,7 +166,7 @@ } } } - ProjectUtils.addPreviewer(project, new Path(context.getHtmlFile())); + ProjectUtils.addPreviewer(project, new Path(context.getHtmlFileName())); } private void copyTemplate(IProject project, String name,