Commit 43b7c154 authored by Romain Bioteau's avatar Romain Bioteau

BS-12428

Fix length for organization validation
Create UpdateStrategyFactory and ValidatorFactory
parent ef60d8ba
......@@ -7,13 +7,15 @@ Bundle-ClassPath: .
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Export-Package: org.bonitasoft.studio.actors,org.bonitasoft.studio.act
ors.i18n; x-friends:="org.bonitasoft.studio.actors.tests, org.bonita
soft.studio.test.swtbot.util, org.bonitasoft.studio.tests",org.bonit
asoft.studio.actors.model.organization,org.bonitasoft.studio.actors.m
odel.organization.impl,org.bonitasoft.studio.actors.model.organizatio
n.util,org.bonitasoft.studio.actors.preference,org.bonitasoft.studio.
actors.repository,org.bonitasoft.studio.actors.ui.wizard.page
Export-Package: org.bonitasoft.studio.actors,
org.bonitasoft.studio.actors.i18n;x-friends:="org.bonitasoft.studio.actors.tests,org.bonitasoft.studio.test.swtbot.util,org.bonitasoft.studio.tests",
org.bonitasoft.studio.actors.model.organization,
org.bonitasoft.studio.actors.model.organization.impl,
org.bonitasoft.studio.actors.model.organization.util,
org.bonitasoft.studio.actors.preference,
org.bonitasoft.studio.actors.repository,
org.bonitasoft.studio.actors.ui.wizard.page,
org.bonitasoft.studio.actors.validator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
org.eclipse.emf.ecore;visibility:=reexport,
......
......@@ -117,7 +117,7 @@ synchronizeOrganizationDesc=Load the selected organization into the local {0}
synchronize=Publish
synchronizingOrganization=Publishing organization...
selectActor=Select an actor
illegalCharacter=The character '/' is not permitted
illegalCharacter=The character '/' is not allowed
filtersSourceRepositoryName=Actor filters sources
filterDefRepositoryName=Actor filter definitions
filterImplRepositoryName=Actor filter implementations
......
......@@ -25,7 +25,7 @@ import java.util.concurrent.CancellationException;
import org.bonitasoft.studio.actors.i18n.Messages;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.jface.BonitaErrorDialog;
import org.bonitasoft.studio.common.jface.FileActionDialog;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
......
......@@ -28,9 +28,9 @@ import org.bonitasoft.studio.actors.repository.OrganizationRepositoryStore;
import org.bonitasoft.studio.actors.ui.wizard.page.AbstractOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.GroupsWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.ManageOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.actors.ui.wizard.page.RolesWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.UsersWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.RepositoryManager;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
......
......@@ -24,8 +24,9 @@ import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.preference.ActorsPreferenceConstants;
import org.bonitasoft.studio.actors.repository.OrganizationFileStore;
import org.bonitasoft.studio.actors.ui.wizard.page.DefaultUserOrganizationWizardPage;
import org.bonitasoft.studio.actors.ui.wizard.page.OrganizationValidator;
import org.bonitasoft.studio.actors.ui.wizard.page.SynchronizeOrganizationWizardPage;
import org.bonitasoft.studio.actors.validator.OrganizationValidationException;
import org.bonitasoft.studio.actors.validator.OrganizationValidator;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.repository.model.IRepositoryFileStore;
import org.bonitasoft.studio.pics.Pics;
......
......@@ -16,6 +16,12 @@
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
import static org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory.updateValueStrategy;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.mandatoryValidator;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.maxLengthValidator;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.multiValidator;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.regExpValidator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
......@@ -26,10 +32,11 @@ import org.bonitasoft.studio.actors.model.organization.Membership;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.OrganizationFactory;
import org.bonitasoft.studio.actors.model.organization.OrganizationPackage;
import org.bonitasoft.studio.actors.validator.DisplayNameValidator;
import org.bonitasoft.studio.actors.validator.ValidatorConstants;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory;
import org.bonitasoft.studio.common.jface.databinding.validator.InputLengthValidator;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
......@@ -74,8 +81,41 @@ import org.eclipse.ui.dialogs.PatternFilter;
* @author Romain Bioteau
*
*/
public class GroupsWizardPage extends AbstractOrganizationWizardPage {
public class GroupsWizardPage extends AbstractOrganizationWizardPage implements ValidatorConstants {
final class GroupParentPathLengthValidator implements IValidator {
private final IObservableValue groupParentPathValue;
InputLengthValidator lengthValidator = new InputLengthValidator(Messages.groupPath, LONG_FIELD_MAX_LENGTH);
GroupParentPathLengthValidator(final IObservableValue groupParentPathValue) {
this.groupParentPathValue = groupParentPathValue;
}
@Override
public IStatus validate(final Object value) {
return lengthValidator.validate(groupParentPathValue.getValue());
}
}
final class UniqueGroupNameValidator implements IValidator {
@Override
public IStatus validate(final Object value) {
for (final org.bonitasoft.studio.actors.model.organization.Group g : groupList) {
final org.bonitasoft.studio.actors.model.organization.Group selectedGroup = (org.bonitasoft.studio.actors.model.organization.Group) groupSingleSelectionObservable
.getValue();
if (!g.equals(selectedGroup)) {
if (g.getName().equals(value)
&& (g.getParentPath() != null && g.getParentPath().equals(selectedGroup.getParentPath())
|| g.getParentPath() == null && selectedGroup.getParentPath() == null)) {
return ValidationStatus.error(Messages.groupNameAlreadyExistsForLevel);
}
}
}
return Status.OK_STATUS;
}
}
private final List<Membership> groupMemberShips = new ArrayList<Membership>();
private Button addSubGroupButton;
......@@ -298,11 +338,10 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
displayNamedText.setMessage(Messages.groupNameExample);
displayNamedText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()) ;
final UpdateValueStrategy displayNameStrategy = new UpdateValueStrategy();
displayNameStrategy.setAfterGetValidator(new DisplayNameValidator());
final IObservableValue displayNameValue = EMFObservables.observeDetailValue(Realm.getDefault(), groupSingleSelectionObservable, OrganizationPackage.Literals.GROUP__DISPLAY_NAME);
final Binding binding = context.bindValue(SWTObservables.observeText(displayNamedText,SWT.Modify), displayNameValue, displayNameStrategy, null) ;
final Binding binding = context.bindValue(SWTObservables.observeText(displayNamedText,SWT.Modify), displayNameValue, UpdateStrategyFactory.updateValueStrategy()
.withValidator(maxLengthValidator(Messages.displayName, LONG_FIELD_MAX_LENGTH)).create(), null);
ControlDecorationSupport.create(binding, SWT.LEFT);
displayNameValue.addValueChangeListener(new IValueChangeListener() {
......@@ -310,7 +349,6 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
@Override
public void handleValueChange(final ValueChangeEvent event) {
handleGroupDisplayName(event);
}
});
......@@ -326,7 +364,8 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
final Text pathText = new Text(group, SWT.BORDER | SWT.READ_ONLY) ;
pathText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()) ;
final IObservableValue groupParentPathValue = EMFObservables.observeDetailValue(Realm.getDefault(),groupSingleSelectionObservable, OrganizationPackage.Literals.GROUP__PARENT_PATH) ;
final IObservableValue groupParentPathValue = EMFObservables.observeDetailValue(Realm.getDefault(), groupSingleSelectionObservable,
OrganizationPackage.Literals.GROUP__PARENT_PATH);
groupParentPathValue.addValueChangeListener(new IValueChangeListener() {
@Override
......@@ -349,6 +388,8 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
groupNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(130, SWT.DEFAULT).create()) ;
final IObservableValue groupNameValue = EMFObservables.observeDetailValue(Realm.getDefault(), groupSingleSelectionObservable, OrganizationPackage.Literals.GROUP__NAME);
final IObservableValue groupParentPathValue = EMFObservables.observeDetailValue(Realm.getDefault(), groupSingleSelectionObservable,
OrganizationPackage.Literals.GROUP__PARENT_PATH);
groupPathObserveValue = PojoObservables.observeValue(this, "groupPath");
groupNameValue.addValueChangeListener(new IValueChangeListener() {
......@@ -358,35 +399,16 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
}
}) ;
final UpdateValueStrategy strategy = new UpdateValueStrategy() ;
strategy.setAfterGetValidator(new IValidator() {
@Override
public IStatus validate(final Object value) {
if(value.toString().isEmpty()){
return ValidationStatus.error(Messages.nameIsEmpty) ;
}
if(value.toString().length()>NAME_SIZE){
return ValidationStatus.error(Messages.nameLimitSize);
}
if(value.toString().contains("/")){
return ValidationStatus.error(Messages.illegalCharacter) ;
}
for(final org.bonitasoft.studio.actors.model.organization.Group g : groupList){
final org.bonitasoft.studio.actors.model.organization.Group selectedGroup = (org.bonitasoft.studio.actors.model.organization.Group) groupSingleSelectionObservable.getValue();
if(!g.equals(selectedGroup)){
if(g.getName().equals(value)
&& (g.getParentPath() != null && g.getParentPath().equals(selectedGroup.getParentPath())
|| g.getParentPath() == null && selectedGroup.getParentPath() == null)){
return ValidationStatus.error(Messages.groupNameAlreadyExistsForLevel) ;
}
}
}
return Status.OK_STATUS;
}
});
final Binding binding = context.bindValue(SWTObservables.observeText(groupNameText,SWT.Modify),groupNameValue,strategy,null);
final GroupParentPathLengthValidator groupParentPathLengthValidator = new GroupParentPathLengthValidator(groupParentPathValue);
final Binding binding = context.bindValue(SWTObservables.observeText(groupNameText, SWT.Modify), groupNameValue, updateValueStrategy().withValidator(
multiValidator()
.addValidator(mandatoryValidator(Messages.name))
.addValidator(maxLengthValidator(Messages.name, GROUP_NAME_MAX_LENGTH))
.addValidator(regExpValidator(Messages.illegalCharacter, "^[^/]*$"))
.addValidator(new UniqueGroupNameValidator())
.addValidator(groupParentPathLengthValidator).create())
.create(),
null);
ControlDecorationSupport.create(binding, SWT.LEFT,group,new ControlDecorationUpdater(){
@Override
protected void update(final ControlDecoration decoration, final IStatus status) {
......@@ -396,6 +418,7 @@ public class GroupsWizardPage extends AbstractOrganizationWizardPage {
}
});
}
@Override
......
......@@ -16,6 +16,11 @@
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
import static org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory.updateValueStrategy;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.mandatoryValidator;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.maxLengthValidator;
import static org.bonitasoft.studio.common.jface.databinding.ValidatorFactory.multiValidator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
......@@ -27,11 +32,10 @@ import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.OrganizationFactory;
import org.bonitasoft.studio.actors.model.organization.OrganizationPackage;
import org.bonitasoft.studio.actors.model.organization.Role;
import org.bonitasoft.studio.actors.validator.DisplayNameValidator;
import org.bonitasoft.studio.actors.validator.ValidatorConstants;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.jface.TableColumnSorter;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
......@@ -69,9 +73,23 @@ import org.eclipse.swt.widgets.Text;
* @author Romain Bioteau
*
*/
public class RolesWizardPage extends AbstractOrganizationWizardPage {
public class RolesWizardPage extends AbstractOrganizationWizardPage implements ValidatorConstants{
final class UniqueRoleNameValidator implements IValidator {
@Override
public IStatus validate(final Object value) {
for (final Role role : roleList) {
if (!role.equals(roleSingleSelectionObservable.getValue())) {
if (role.getName().equals(value)) {
return ValidationStatus.error(Messages.roleNameAlreadyExists);
}
}
}
return Status.OK_STATUS;
}
}
private final List<Membership> roleMemberShips = new ArrayList<Membership>();
private IViewerObservableValue roleSingleSelectionObservable;
......@@ -223,12 +241,9 @@ public class RolesWizardPage extends AbstractOrganizationWizardPage {
final Text displayNamedText = new Text(group, SWT.BORDER) ;
displayNamedText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()) ;
final UpdateValueStrategy roleDisplayNameStrategy = new UpdateValueStrategy();
roleDisplayNameStrategy.setAfterGetValidator(new DisplayNameValidator());
final IObservableValue roleDisplayNameValue = EMFObservables.observeDetailValue(Realm.getDefault(), roleSingleSelectionObservable, OrganizationPackage.Literals.ROLE__DISPLAY_NAME);
final Binding binding =context.bindValue(SWTObservables.observeText(displayNamedText, SWT.Modify), roleDisplayNameValue,roleDisplayNameStrategy,null);
final Binding binding =context.bindValue(SWTObservables.observeText(displayNamedText, SWT.Modify), roleDisplayNameValue,
updateValueStrategy().withValidator(maxLengthValidator(Messages.displayName, LONG_FIELD_MAX_LENGTH)).create(), null);
ControlDecorationSupport.create(binding, SWT.LEFT);
roleDisplayNameValue.addValueChangeListener(new IValueChangeListener() {
......@@ -249,31 +264,16 @@ public class RolesWizardPage extends AbstractOrganizationWizardPage {
final Text roleNameText = new Text(group, SWT.BORDER) ;
roleNameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).minSize(130, SWT.DEFAULT).create()) ;
final UpdateValueStrategy roleNameStrategy = new UpdateValueStrategy();
roleNameStrategy.setAfterGetValidator(new IValidator() {
@Override
public IStatus validate(final Object value) {
if(value.toString().isEmpty()){
return ValidationStatus.error(Messages.nameIsEmpty) ;
}
if(value.toString().length()>NAME_SIZE){
return ValidationStatus.error(Messages.nameLimitSize) ;
}
for(final Role role : roleList){
if(!role.equals(roleSingleSelectionObservable.getValue())){
if(role.getName().equals(value)){
return ValidationStatus.error(Messages.roleNameAlreadyExists) ;
}
}
}
return Status.OK_STATUS;
}
});
final IObservableValue roleNameValue = EMFObservables.observeDetailValue(Realm.getDefault(), roleSingleSelectionObservable, OrganizationPackage.Literals.ROLE__NAME);
final Binding binding = context.bindValue(SWTObservables.observeText(roleNameText, SWT.Modify), roleNameValue, roleNameStrategy,null);
final Binding binding = context.bindValue(SWTObservables.observeText(roleNameText, SWT.Modify),
roleNameValue,
updateValueStrategy().withValidator(multiValidator()
.addValidator(mandatoryValidator(Messages.name))
.addValidator(maxLengthValidator(Messages.name, LONG_FIELD_MAX_LENGTH))
.addValidator(new UniqueRoleNameValidator()).create()).create()
, null);
ControlDecorationSupport.create(binding, SWT.LEFT, group, new ControlDecorationUpdater(){
@Override
protected void update(final ControlDecoration decoration, final IStatus status) {
......
......@@ -34,14 +34,9 @@ import org.eclipse.jface.viewers.StructuredSelection;
*/
public class CustomerUserInformationDefinitionNameValidator implements IValidator {
Organization organization;
Set<String> exisingNames=new HashSet<String>();
private final Set<String> exisingNames = new HashSet<String>();
public CustomerUserInformationDefinitionNameValidator(final Organization organization, final ColumnViewer viewer) {
this.organization=organization;
final StructuredSelection structuredSelection = (StructuredSelection) viewer.getSelection();
final CustomUserInfoDefinition selectedCustomUserDef = (CustomUserInfoDefinition) structuredSelection.getFirstElement();
final String selectedDefinitionName = selectedCustomUserDef.getName();
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.ui.wizard;
package org.bonitasoft.studio.actors.validator;
import org.eclipse.core.runtime.IStatus;
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.ui.wizard.page;
package org.bonitasoft.studio.actors.validator;
import java.util.ArrayList;
import java.util.List;
......@@ -26,6 +26,7 @@ import org.bonitasoft.studio.actors.model.organization.Membership;
import org.bonitasoft.studio.actors.model.organization.Organization;
import org.bonitasoft.studio.actors.model.organization.Role;
import org.bonitasoft.studio.actors.model.organization.User;
import org.bonitasoft.studio.actors.ui.wizard.page.GroupContentProvider;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
......
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.actors.validator;
/**
* @author Romain Bioteau
*
*/
public interface ValidatorConstants {
static final int LONG_FIELD_MAX_LENGTH = 255;
static final int SHORT_FIELD_MAX_LENGTH = 50;
static final int GROUP_NAME_MAX_LENGTH = 125;
}
......@@ -42,20 +42,27 @@ Import-Package: org.bonitasoft.engine.bpm.bar,
org.bonitasoft.engine.session,
org.bonitasoft.engine.util,
org.bonitasoft.forms.client.model
Export-Package: org.bonitasoft.studio.common,org.bonitasoft.studio.com
mon.api,org.bonitasoft.studio.common.databinding,org.bonitasoft.studi
o.common.databinding.converter,org.bonitasoft.studio.common.dialog,or
g.bonitasoft.studio.common.editingdomain,org.bonitasoft.studio.common
.editor,org.bonitasoft.studio.common.emf.converter,org.bonitasoft.stu
dio.common.emf.tools,org.bonitasoft.studio.common.exporter,org.bonita
soft.studio.common.extension,org.bonitasoft.studio.common.gmfgraph,or
g.bonitasoft.studio.common.jface,org.bonitasoft.studio.common.jface.d
atabinding,org.bonitasoft.studio.common.jface.databinding.observables
,org.bonitasoft.studio.common.jface.databinding.validator,org.bonitas
oft.studio.common.jface.dialog,org.bonitasoft.studio.common.log,org.b
onitasoft.studio.common.palette,org.bonitasoft.studio.common.perspect
ives,org.bonitasoft.studio.common.platform.tools,org.bonitasoft.studi
o.common.properties,org.bonitasoft.studio.common.views,org.bonitasoft
.studio.common.widgets
Export-Package: org.bonitasoft.studio.common,
org.bonitasoft.studio.common.api,
org.bonitasoft.studio.common.dialog,
org.bonitasoft.studio.common.editingdomain,
org.bonitasoft.studio.common.editor,
org.bonitasoft.studio.common.emf.converter,
org.bonitasoft.studio.common.emf.tools,
org.bonitasoft.studio.common.exporter,
org.bonitasoft.studio.common.extension,
org.bonitasoft.studio.common.gmfgraph,
org.bonitasoft.studio.common.jface,
org.bonitasoft.studio.common.jface.databinding,
org.bonitasoft.studio.common.jface.databinding.observables,
org.bonitasoft.studio.common.jface.databinding.validator,
org.bonitasoft.studio.common.jface.dialog,
org.bonitasoft.studio.common.log,
org.bonitasoft.studio.common.palette,
org.bonitasoft.studio.common.perspectives,
org.bonitasoft.studio.common.platform.tools,
org.bonitasoft.studio.common.properties,
org.bonitasoft.studio.common.views,
org.bonitasoft.studio.common.widgets
Bundle-ClassPath: .,
lib/imgscalr-lib-3.2.jar
/**
* Copyright (C) 2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.jface.databinding.validator;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
* @author Romain Bioteau
*
*/
public class RegExpValidatorTest {
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
@Test
public void should_validate_not_accept_string_containing_slash() throws Exception {
final RegExpValidator regExpValidator = new RegExpValidator("error message", "^[^/]*$");
assertThat(regExpValidator.validate(null).isOK()).isTrue();
assertThat(regExpValidator.validate("").isOK()).isTrue();
assertThat(regExpValidator.validate("hello, my name is ****").isOK()).isTrue();
assertThat(regExpValidator.validate("hello, my n/ame").isOK()).isFalse();
assertThat(regExpValidator.validate("/hello").isOK()).isFalse();
assertThat(regExpValidator.validate("hello/").isOK()).isFalse();
}
}
package org.bonitasoft.studio.common.databinding;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
public class MultiValidator implements IValidator {
private List<IValidator> validators;
public MultiValidator(List<IValidator> validators){
this.validators = validators;
}
public MultiValidator() {
this.validators = new ArrayList<IValidator>();
}
public void addValidator(IValidator validator) {
if(!validators.contains(validator)){
this.validators.add(validator);
}
}
@Override
public IStatus validate(Object value) {
for (IValidator validator:validators){
IStatus status = validator.validate(value);
if (!status.isOK()){
return status;
}
}
return Status.OK_STATUS;
}
}
......@@ -15,7 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.databinding;
package org.bonitasoft.studio.common.jface.databinding;
import com.ibm.icu.text.DecimalFormat;
import com.ibm.icu.text.NumberFormat;
......
......@@ -2,7 +2,7 @@
* Copyright (C) 2010-2012 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
*/
package org.bonitasoft.studio.common.databinding;
package org.bonitasoft.studio.common.jface.databinding;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
......
......@@ -14,7 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.databinding;
package org.bonitasoft.studio.common.jface.databinding;
import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.Realm;
......
/**
* Copyright (C) 2015 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2.0 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.bonitasoft.studio.common.jface.databinding;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
/**
* @author Romain Bioteau
*/
public class MultiValidator implements IValidator {
private final List<IValidator> validators;
public MultiValidator(final List<IValidator> validators) {
this.validators = validators;