Commit dc645c9f authored by Romain Bioteau's avatar Romain Bioteau
Browse files

Fix TestDuplicate

parent cd3d459d
......@@ -30,7 +30,7 @@ import org.bonitasoft.studio.model.process.AbstractProcess;
import org.bonitasoft.studio.model.process.MainProcess;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.MultiValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
......@@ -59,7 +59,7 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
protected String newName;
protected String newVersion;
public ProcessesNameVersion(AbstractProcess pool) {
public ProcessesNameVersion(final AbstractProcess pool) {
abstractProcess = pool;
newName = pool.getName();
newVersion = pool.getVersion();
......@@ -73,7 +73,7 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
return newName;
}
public void setNewName(String newName) {
public void setNewName(final String newName) {
this.newName = newName;
}
......@@ -81,7 +81,7 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
return newVersion;
}
public void setNewVersion(String newVersion) {
public void setNewVersion(final String newVersion) {
this.newVersion = newVersion;
}
......@@ -91,30 +91,30 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
* @param name
* @param version
*/
public OpenNameAndVersionForDiagramDialog(Shell parentShell, MainProcess diagram,IRepositoryStore diagramStore) {
public OpenNameAndVersionForDiagramDialog(final Shell parentShell, final MainProcess diagram,final IRepositoryStore diagramStore) {
super(parentShell, diagram,diagramStore);
for(AbstractProcess pool : ModelHelper.getAllProcesses(diagram)){
for(final AbstractProcess pool : ModelHelper.getAllProcesses(diagram)){
pools.add(new ProcessesNameVersion(pool));
}
}
public OpenNameAndVersionForDiagramDialog(Shell parentShell, MainProcess diagram,IRepositoryStore diagramStore,boolean diagramNameOrVersionChangeMandatory) {
public OpenNameAndVersionForDiagramDialog(final Shell parentShell, final MainProcess diagram,final IRepositoryStore diagramStore,final boolean diagramNameOrVersionChangeMandatory) {
super(parentShell, diagram,diagramStore,diagramNameOrVersionChangeMandatory);
for(AbstractProcess pool : ModelHelper.getAllProcesses(diagram)){
for(final AbstractProcess pool : ModelHelper.getAllProcesses(diagram)){
pools.add(new ProcessesNameVersion(pool));
}
}
@Override
protected void configureShell(Shell newShell) {
protected void configureShell(final Shell newShell) {
super.configureShell(newShell);
}
@Override
protected Control createDialogArea(Composite parent) {
protected Control createDialogArea(final Composite parent) {
final DataBindingContext dbc = new DataBindingContext();
Composite res = new Composite(parent, SWT.FILL);
final Composite res = new Composite(parent, SWT.FILL);
res.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
res.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(15, 15).create());
......@@ -125,15 +125,15 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
return res;
}
private void createDiagramComposite(Composite res, final DataBindingContext dbc) {
Group diagramGroup = new Group(res, SWT.NONE);
private void createDiagramComposite(final Composite res, final DataBindingContext dbc) {
final Group diagramGroup = new Group(res, SWT.NONE);
diagramGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10,10).create());
diagramGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
diagramGroup.setText(Messages.diagram);
createDiagramNameAndVersion(diagramGroup, dbc);
}
void createPNVComposite(Composite parent, final ProcessesNameVersion pnv, DataBindingContext dbc) {
void createPNVComposite(final Composite parent, final ProcessesNameVersion pnv, final DataBindingContext dbc) {
final Composite pnvCompo = new Composite(parent, SWT.NONE);
pnvCompo.setLayout(GridLayoutFactory.fillDefaults().equalWidth(false).numColumns(4).create());
pnvCompo.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
......@@ -143,13 +143,14 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
final Text nameText = new Text(pnvCompo, SWT.BORDER);
nameText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(200, SWT.DEFAULT).create());
UpdateValueStrategy nameTargetToModel = new UpdateValueStrategy();
final UpdateValueStrategy nameTargetToModel = new UpdateValueStrategy();
final EmptyInputValidator emptyValidator = new EmptyInputValidator(Messages.name);
final InputLengthValidator lenghtValidator = new InputLengthValidator(Messages.name,50);
nameTargetToModel.setAfterGetValidator(new IValidator() {
public IStatus validate(Object value) {
@Override
public IStatus validate(final Object value) {
IStatus status = emptyValidator.validate(value);
if(status.isOK()){
status = lenghtValidator.validate(value);
......@@ -158,18 +159,20 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
}
});
nameTargetToModel.setBeforeSetValidator(new UTF8InputValidator(Messages.name));
ControlDecorationSupport.create(dbc.bindValue(SWTObservables.observeText(nameText, SWT.Modify), PojoProperties.value("newName").observe(pnv),nameTargetToModel,null), SWT.LEFT);
ControlDecorationSupport.create(dbc.bindValue(SWTObservables.observeText(nameText, SWT.Modify),
PojoObservables.observeValue(pnv, "newName"), nameTargetToModel, null), SWT.LEFT);
final Label poolVersion = new Label(pnvCompo, SWT.NONE);
poolVersion.setText(Messages.version);
final Text versionText = new Text(pnvCompo, SWT.BORDER);
versionText.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).hint(100, SWT.DEFAULT).create());
UpdateValueStrategy versionTargetToModel = new UpdateValueStrategy();
final UpdateValueStrategy versionTargetToModel = new UpdateValueStrategy();
final EmptyInputValidator verisonEmptyValidator = new EmptyInputValidator(Messages.version);
final InputLengthValidator versionLenghtValidator = new InputLengthValidator(Messages.version,50);
versionTargetToModel.setAfterGetValidator(new IValidator() {
public IStatus validate(Object value) {
@Override
public IStatus validate(final Object value) {
IStatus status = verisonEmptyValidator.validate(value);
if(status.isOK()){
status = versionLenghtValidator.validate(value);
......@@ -177,60 +180,62 @@ public class OpenNameAndVersionForDiagramDialog extends OpenNameAndVersionDialog
return status;
}
});
versionTargetToModel.setBeforeSetValidator(new UTF8InputValidator(Messages.version));
ControlDecorationSupport.create(dbc.bindValue(SWTObservables.observeText(versionText, SWT.Modify), PojoProperties.value("newVersion").observe(pnv),versionTargetToModel,null), SWT.LEFT);
ControlDecorationSupport
.create(dbc.bindValue(SWTObservables.observeText(versionText, SWT.Modify), PojoObservables.observeValue(pnv, "newVersion"),
versionTargetToModel, null), SWT.LEFT);
final ISWTObservableValue observeNameText = SWTObservables.observeText(nameText, SWT.Modify);
final ISWTObservableValue observeVersionText = SWTObservables.observeText(versionText, SWT.Modify);
final MultiValidator caseValidator = new MultiValidator() {
@Override
protected IStatus validate() {
final String name = observeNameText.getValue().toString();
final String version = observeVersionText.getValue().toString();
int countNewProcessWithSameName = 0;
for (ProcessesNameVersion pool : pools){
if (name.equals(pool.newName) && version.equals(pool.newVersion)) {
countNewProcessWithSameName ++;
}
}
if(countNewProcessWithSameName>1){
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
}
int countOldProcessWithSameName = 0;
for (ProcessesNameVersion pool : pools){
if (name.equals(pool.getAbstractProcess().getName()) && version.equals(pool.getAbstractProcess().getVersion())) {
countOldProcessWithSameName ++;
}
}
if(countOldProcessWithSameName==1){
if(diagramNameOrVersionChangeMandatory){
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
} else {
return ValidationStatus.ok();
}
}
for (AbstractProcess process : processes) {
if (name.equals(process.getName()) && version.equals(process.getVersion())) {
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
}
}
return ValidationStatus.ok();
}
};
dbc.addValidationStatusProvider(caseValidator);
ControlDecorationSupport.create(caseValidator, SWT.LEFT);
}
protected void createProcessesNameAndVersion(Composite res, final DataBindingContext dbc) {
Group parent = new Group(res, SWT.NONE);
final ISWTObservableValue observeVersionText = SWTObservables.observeText(versionText, SWT.Modify);
final MultiValidator caseValidator = new MultiValidator() {
@Override
protected IStatus validate() {
final String name = observeNameText.getValue().toString();
final String version = observeVersionText.getValue().toString();
int countNewProcessWithSameName = 0;
for (final ProcessesNameVersion pool : pools){
if (name.equals(pool.newName) && version.equals(pool.newVersion)) {
countNewProcessWithSameName ++;
}
}
if(countNewProcessWithSameName>1){
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
}
int countOldProcessWithSameName = 0;
for (final ProcessesNameVersion pool : pools){
if (name.equals(pool.getAbstractProcess().getName()) && version.equals(pool.getAbstractProcess().getVersion())) {
countOldProcessWithSameName ++;
}
}
if(countOldProcessWithSameName==1){
if(diagramNameOrVersionChangeMandatory){
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
} else {
return ValidationStatus.ok();
}
}
for (final AbstractProcess process : processes) {
if (name.equals(process.getName()) && version.equals(process.getVersion())) {
return ValidationStatus.error(Messages.bind(Messages.differentCaseSameNameError, typeLabel));
}
}
return ValidationStatus.ok();
}
};
dbc.addValidationStatusProvider(caseValidator);
ControlDecorationSupport.create(caseValidator, SWT.LEFT);
}
protected void createProcessesNameAndVersion(final Composite res, final DataBindingContext dbc) {
final Group parent = new Group(res, SWT.NONE);
parent.setLayoutData(GridDataFactory.fillDefaults().span(2, 1).grab(true, false).create());
parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).create());
parent.setText(Messages.pools);
for(ProcessesNameVersion pnv : pools){
for(final ProcessesNameVersion pnv : pools){
createPNVComposite(parent, pnv, dbc);
}
}
......
......@@ -105,9 +105,8 @@ public class DuplicateDiagramOperation implements IRunnableWithProgress {
final TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(newDiagram);
for (final ProcessesNameVersion pnv : pools) {
final AbstractProcess fromPool = pnv.getAbstractProcess();
final String fromPoolName = fromPool.getName();
final String fromPoolVersion = fromPool.getVersion();
final String fromPoolName = pnv.getNewName();
final String fromPoolVersion = pnv.getNewVersion();
/* Find corresponding element in the duplicated model */
for (final Element element : newDiagram.getElements()) {
if (element instanceof AbstractProcess) {
......@@ -204,7 +203,7 @@ public class DuplicateDiagramOperation implements IRunnableWithProgress {
/**
* All elements referenced via ResourceFolder or ResourceFile need to have path updated and artifact duplicated after a duplication of a process.
*
*
* @param oldProcess
* @param newProcess
* @param createEditingDomain
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment