Commit e0f6f87b authored by Adrien's avatar Adrien Committed by GitHub

feat(BDM) add error label for constraints & indexes (#2140)

* Same behavior when creating a unique constraint / an index: content is
empty
* New error label above the viewers to help users

[STUDIO-3418](https://bonitasoft.atlassian.net/browse/STUDIO-3418)
parent 694388e5
......@@ -32,6 +32,7 @@ import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.businessobject.validator.UniqueConstraintFieldsValidator;
import org.bonitasoft.studio.businessobject.validator.UniqueConstraintNameValidator;
import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.ui.ColorConstants;
import org.bonitasoft.studio.ui.util.StringIncrementer;
import org.bonitasoft.studio.ui.viewer.EditingSupportBuilder;
import org.bonitasoft.studio.ui.viewer.LabelProviderBuilder;
......@@ -53,6 +54,8 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
......@@ -63,8 +66,11 @@ import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.forms.widgets.Section;
......@@ -89,6 +95,7 @@ public class ConstraintEditionControl {
private Composite mainComposite;
private ToolItem deleteConstraintItem;
private List<UniqueConstraint> constraintsToFilter = new ArrayList<>();
private Color errorColor;
public ConstraintEditionControl(Composite parent,
AbstractBdmFormPage formPage,
......@@ -101,6 +108,8 @@ public class ConstraintEditionControl {
this.actualsFieldsObservable = EMFObservables.observeDetailList(Realm.getDefault(),
formPage.observeBusinessObjectSelected(),
BusinessDataModelPackage.Literals.BUSINESS_OBJECT__FIELDS);
this.errorColor = new LocalResourceManager(JFaceResources.getResources(),
parent).createColor(ColorConstants.ERROR_RGB);
this.mainComposite = formPage.getToolkit().createComposite(parent);
mainComposite.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).create());
......@@ -214,11 +223,34 @@ public class ConstraintEditionControl {
.createLabel(client, Messages.warningTextConstraint, SWT.WRAP)
.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
createValidationLabel(client);
createConstraintEditionViewer(client);
section.setClient(client);
}
private void createValidationLabel(Composite client) {
Label validationLabel = formPage.getToolkit().createLabel(client, "", SWT.WRAP);
validationLabel.setLayoutData(GridDataFactory.fillDefaults().create());
validationLabel.setForeground(errorColor);
attributesSetObservable.addChangeListener(e -> {
if (selectedConstraintObservable.getValue() != null) {
if (!attributesSetObservable.isEmpty()) {
validationLabel.setVisible(false);
((GridData) validationLabel.getLayoutData()).exclude = true;
} else {
validationLabel.setVisible(true);
((GridData) validationLabel.getLayoutData()).exclude = false;
validationLabel.setText(
String.format(Messages.constraintFieldEmptiness,
selectedConstraintObservable.getValue().getName()));
}
client.layout();
}
});
}
private void createConstraintEditionViewer(Composite parent) {
constraintEditionViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER);
constraintEditionViewer.getTable()
......
......@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
import org.bonitasoft.studio.businessobject.editor.editor.filter.IndexableFieldFilter;
......@@ -49,7 +48,7 @@ import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.emf.databinding.EMFObservables;
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;
......@@ -267,7 +266,7 @@ public class IndexControl {
indexViewer.setContentProvider(new ObservableListContentProvider());
indexViewer.setInput(indexObservable);
selectedIndexObservable = ViewersObservables.observeSingleSelection(indexViewer);
selectedIndexObservable = ViewerProperties.singleSelection(Index.class).observe(indexViewer);
}
private void enableButtons(DataBindingContext ctx) {
......@@ -320,19 +319,11 @@ public class IndexControl {
String newName = getNewName();
Index newIndex = new IndexBuilder()
.withName(newName)
.withFieldNames(getIndexableFields().toArray(new String[0]))
.create();
indexObservable.add(newIndex);
Display.getDefault().asyncExec(() -> indexViewer.editElement(newIndex, 0));
}
private List<String> getIndexableFields() {
return selectedBoObservable.getValue().getFields().stream()
.filter(indexableFieldFilter::isIndexableField)
.map(Field::getName)
.collect(Collectors.toList());
}
private String getNewName() {
List<String> existingNames = new ArrayList<>();
existingNames.add(DEFAULT_INDEX_NAME);
......
......@@ -27,6 +27,7 @@ import org.bonitasoft.studio.businessobject.editor.model.Field;
import org.bonitasoft.studio.businessobject.editor.model.Index;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.ui.ColorConstants;
import org.bonitasoft.studio.ui.converter.ConverterBuilder;
import org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory;
import org.bonitasoft.studio.ui.viewer.LabelProviderBuilder;
......@@ -40,6 +41,8 @@ import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableLayout;
......@@ -55,9 +58,12 @@ import org.eclipse.swt.dnd.DropTargetAdapter;
import org.eclipse.swt.dnd.DropTargetEvent;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.ui.forms.widgets.Section;
......@@ -68,6 +74,7 @@ public class IndexEditionControl extends Composite {
public static final String AVAILABLE_FIELDS_VIEWER_ID = "availableFieldsViewerId";
private AbstractBdmFormPage formPage;
private IObservableValue<Index> selectedIndexObservable;
private IObservableList<Field> actualsFieldsObservable;
private IndexableFieldFilter indexableFieldFilter;
private FieldStyleStringProvider fieldStyleStringProvider;
......@@ -79,6 +86,7 @@ public class IndexEditionControl extends Composite {
private IObservableList<Field> selectedIndexedAttributeObservable;
private Cursor cursorHand;
private Cursor cursorArrow;
private Color errorColor;
public IndexEditionControl(Section parent, AbstractBdmFormPage formPage, DataBindingContext ctx,
IObservableValue<Index> selectedIndexObservable, IObservableList<Field> actualsFieldsObservable) {
......@@ -88,11 +96,14 @@ public class IndexEditionControl extends Composite {
setLayout(GridLayoutFactory.fillDefaults().margins(15, 10).create());
this.formPage = formPage;
this.selectedIndexObservable = selectedIndexObservable;
this.actualsFieldsObservable = actualsFieldsObservable;
this.indexableFieldFilter = new IndexableFieldFilter();
this.fieldStyleStringProvider = new FieldStyleStringProvider();
this.cursorHand = new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
this.cursorArrow = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW);
this.errorColor = new LocalResourceManager(JFaceResources.getResources(),
parent).createColor(ColorConstants.ERROR_RGB);
indexedFieldNameObservable = EMFObservables.observeDetailList(Realm.getDefault(), selectedIndexObservable,
BusinessDataModelPackage.Literals.INDEX__FIELD_NAMES);
......@@ -313,6 +324,25 @@ public class IndexEditionControl extends Composite {
formPage.getToolkit()
.createLabel(this, Messages.warningTextIndex, SWT.WRAP)
.setLayoutData(GridDataFactory.fillDefaults().create());
Label validationLabel = formPage.getToolkit().createLabel(this, "", SWT.WRAP);
validationLabel.setLayoutData(GridDataFactory.fillDefaults().create());
validationLabel.setForeground(errorColor);
indexedFieldNameObservable.addChangeListener(e -> {
if (selectedIndexObservable.getValue() != null) {
if (!selectedIndexObservable.getValue().getFieldNames().isEmpty()) {
validationLabel.setVisible(false);
((GridData) validationLabel.getLayoutData()).exclude = true;
} else {
validationLabel.setVisible(true);
((GridData) validationLabel.getLayoutData()).exclude = false;
validationLabel.setText(
String.format(Messages.indexFieldEmptiness, selectedIndexObservable.getValue().getName()));
}
layout();
}
});
}
public void refreshIndexEditionViewers() {
......
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