Commit 694388e5 authored by Adrien's avatar Adrien Committed by GitHub

feat(BDM) apply cell editors values before add actions (#2143)

-> Sometimes the cell editor value is lost during the add operation,
because observable values are modified in asynch threads, something like
that. Manually apply the cell editor value before to do anything ensure
that it won't be lost.

[STUDIO-3420](https://bonitasoft.atlassian.net/browse/STUDIO-3420)
parent 0b93c88b
......@@ -47,9 +47,9 @@ import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.databinding.viewers.typed.ViewerProperties;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
......@@ -203,7 +203,7 @@ public class AttributeEditionControl extends Composite {
viewer.setContentProvider(new ObservableListContentProvider());
viewer.setInput(fieldsObservable);
selectedFieldObservable = ViewersObservables.observeSingleSelection(viewer);
selectedFieldObservable = ViewerProperties.singleSelection(Field.class).observe(viewer);
addDragAndDropSupport();
}
......@@ -430,6 +430,7 @@ public class AttributeEditionControl extends Composite {
}
private void addAttribute() {
viewer.applyEditorValue();
String fieldName = StringIncrementer.getNextIncrement(DEFAULT_FIELD_NAME,
selectedBoObservable.getValue().getFields().stream().map(Field::getName)
.collect(Collectors.toList()));
......
......@@ -64,8 +64,8 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.jface.databinding.viewers.typed.ViewerProperties;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
......@@ -219,7 +219,7 @@ public class BusinessObjectList {
viewer.setComparator(new BusinessObjectViewerComparator());
viewer.setInput(input);
addDNDSupport(formPage);
selectionObservable = ViewersObservables.observeSingleSelection(viewer);
selectionObservable = ViewerProperties.singleSelection(Object.class).observe(viewer);
}
protected void addDNDSupport(AbstractBdmFormPage formPage) {
......@@ -413,6 +413,7 @@ public class BusinessObjectList {
}
private void addPackage(AbstractBdmFormPage formPage) {
viewer.applyEditorValue();
List<String> existingPackages = input.getValue().getPackages().stream().map(Package::getName)
.collect(Collectors.toList());
String newPackageName = StringIncrementer.getNextIncrement(PackageHelper.DEFAULT_PACKAGE_NAME, existingPackages);
......@@ -423,6 +424,7 @@ public class BusinessObjectList {
}
private void addBusinessObject(AbstractBdmFormPage formPage) {
viewer.applyEditorValue();
Package pakage = selectionObservable.getValue() instanceof Package
? (Package) selectionObservable.getValue()
: (Package) ((BusinessObject) selectionObservable.getValue()).eContainer();
......
......@@ -371,6 +371,7 @@ public class ConstraintEditionControl {
}
private void addUniqueConstraint() {
constraintViewer.applyEditorValue();
String name = StringIncrementer.getNextIncrement(Messages.defaultConstraintName,
constraintsObservable.stream().map(UniqueConstraint::getName).collect(Collectors.toList()));
UniqueConstraint newConstraint = new UniqueConstraintBuilder()
......
......@@ -41,13 +41,13 @@ import org.bonitasoft.studio.ui.widget.SearchWidget;
import org.bonitasoft.studio.ui.widget.TextAreaWidget;
import org.bonitasoft.studio.ui.widget.TextWidget;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.beans.typed.PojoProperties;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.dialogs.MessageDialog;
......@@ -105,7 +105,7 @@ public class IndexControl {
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
mainComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
createIndexDefinitionSection(ctx);
createIndexDefinitionSection();
createIndexEditionComposite(ctx);
enableButtons(ctx);
......@@ -113,7 +113,7 @@ public class IndexControl {
BusinessDataModelPackage.Literals.INDEX__FIELD_NAMES).addChangeListener(e -> indexViewer.refresh());
}
private void createIndexDefinitionSection(DataBindingContext ctx) {
private void createIndexDefinitionSection() {
this.section = formPage.getToolkit().createSection(mainComposite, Section.EXPANDED);
section.setLayoutData(GridDataFactory.fillDefaults().grab(false, true).create());
section.setLayout(GridLayoutFactory.fillDefaults().create());
......@@ -316,6 +316,7 @@ public class IndexControl {
}
private void addIndex() {
indexViewer.applyEditorValue();
String newName = getNewName();
Index newIndex = new IndexBuilder()
.withName(newName)
......@@ -352,7 +353,7 @@ public class IndexControl {
}
public IObservableValue<String> observeSectionTitle() {
return PojoProperties.value("text").observe(section);
return PojoProperties.<Section, String> value("text").observe(section);
}
public IObservableValue<Boolean> observeSectionVisible() {
......
......@@ -39,14 +39,14 @@ import org.bonitasoft.studio.ui.viewer.LabelProviderBuilder;
import org.bonitasoft.studio.ui.widget.SearchWidget;
import org.bonitasoft.studio.ui.widget.TextWidget;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.beans.PojoProperties;
import org.eclipse.core.databinding.beans.typed.PojoProperties;
import org.eclipse.core.databinding.observable.Realm;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.emf.databinding.EMFObservables;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.databinding.swt.typed.WidgetProperties;
import org.eclipse.jface.databinding.viewers.typed.ViewerProperties;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
......@@ -209,7 +209,7 @@ public class QueryEditionControl {
viewer = createQueryViewer(customModeComposite);
viewer.setInput(boSelectedObservable);
querySelectedObservable = ViewersObservables.observeSingleSelection(viewer);
querySelectedObservable = ViewerProperties.singleSelection(Query.class).observe(viewer);
}
private void enableButtons() {
......@@ -233,6 +233,7 @@ public class QueryEditionControl {
}
private void addQuery() {
viewer.applyEditorValue();
String queryName = generateNewQueryName();
Query newQuery = new QueryBuilder().withName(queryName)
.withReturnType(boSelectedObservable.getValue().getQualifiedName()).create();
......@@ -332,7 +333,7 @@ public class QueryEditionControl {
}
public IObservableValue<String> observeSectionTitle() {
return PojoProperties.value("text").observe(section);
return PojoProperties.<Section, String> value("text").observe(section);
}
public IObservableValue<Boolean> observeSectionVisible() {
......
Markdown is supported
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