Commit 10cfaa23 authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien
Browse files

fix(bdm) fix ui glitch when editing BO name (#298)

fixes [BS-16240](https://bonitasoft.atlassian.net/browse/BS-16240)
parent 0806e9e8
......@@ -14,9 +14,15 @@
*/
package org.bonitasoft.studio.businessobject.ui.wizard;
import static org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory.neverUpdateValueStrategy;
import static org.bonitasoft.studio.common.jface.databinding.UpdateStrategyFactory.updateValueStrategy;
import java.util.HashSet;
import java.util.Set;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.studio.businessobject.BusinessObjectPlugin;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.businessobject.ui.wizard.control.AttributesTabItemControl;
......@@ -26,11 +32,13 @@ import org.bonitasoft.studio.businessobject.ui.wizard.control.UniqueConstraintTa
import org.bonitasoft.studio.businessobject.ui.wizard.editingsupport.BusinessObjectNameEditingSupport;
import org.bonitasoft.studio.common.NamingUtils;
import org.bonitasoft.studio.common.jface.TableColumnSorter;
import org.bonitasoft.studio.common.jface.databinding.observables.GroupTextProperty;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.beans.PojoObservables;
import org.eclipse.core.databinding.conversion.Converter;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
......@@ -51,11 +59,7 @@ import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent;
import org.eclipse.jface.viewers.ColumnViewerEditorActivationListener;
import org.eclipse.jface.viewers.ColumnViewerEditorDeactivationEvent;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableLayout;
import org.eclipse.jface.viewers.TableViewer;
......@@ -74,10 +78,6 @@ import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.Text;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.BusinessObjectModel;
import org.bonitasoft.engine.bdm.model.Query;
/**
* @author Romain Bioteau
*/
......@@ -95,10 +95,12 @@ public class BusinessDataModelWizardPage extends WizardPage {
private IObservableList fieldsList;
private Group businessObjectDescriptionGroup;
private Label helpLabel;
private TableViewerColumn businessObjectNameColumn;
private TableViewer boTableViewer;
protected BusinessDataModelWizardPage(final BusinessObjectModel businessObjectModel) {
super(BusinessDataModelWizardPage.class.getName());
this.businessObjectModel = businessObjectModel;
......@@ -139,23 +141,23 @@ public class BusinessDataModelWizardPage extends WizardPage {
protected void createBusinessObjectDescription(final Composite mainComposite, final DataBindingContext ctx,
final IViewerObservableValue viewerObservableValue) {
businessObjectDescriptionGroup = new Group(mainComposite, SWT.NONE);
final Group businessObjectDescriptionGroup = new Group(mainComposite, SWT.NONE);
businessObjectDescriptionGroup.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).span(1, 2).create());
businessObjectDescriptionGroup.setLayout(GridLayoutFactory.fillDefaults().numColumns(2).margins(10, 10).create());
businessObjectDescriptionGroup.setText(Messages.selectABusinessObjectToEdit);
viewerObservableValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(final ValueChangeEvent event) {
final Object newValue = event.diff.getNewValue();
if (newValue != null) {
businessObjectDescriptionGroup
.setText(NamingUtils.getSimpleName(((BusinessObject) newValue).getQualifiedName()));
} else {
businessObjectDescriptionGroup.setText(Messages.selectABusinessObjectToEdit);
}
}
});
final IObservableValue observeDetailValue = PojoObservables.observeDetailValue(viewerObservableValue,
"qualifiedName", String.class);
final ISWTObservableValue groupTextObservable = new GroupTextProperty().observe(businessObjectDescriptionGroup);
businessObjectNameColumn.setEditingSupport(new BusinessObjectNameEditingSupport(businessObjectModel,
viewerObservableValue, PojoObservables.observeValue(
this, "packageName"),
groupTextObservable,
boTableViewer, ctx));
ctx.bindValue(observeDetailValue,
groupTextObservable,
updateValueStrategy().withConverter(toPaneDescripitonlTitle()).create(),
neverUpdateValueStrategy().create());
createDescription(ctx, viewerObservableValue, businessObjectDescriptionGroup);
......@@ -273,7 +275,7 @@ public class BusinessDataModelWizardPage extends WizardPage {
deleteButton.setText(Messages.delete);
deleteButton.setEnabled(false);
final TableViewer boTableViewer = new TableViewer(group, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
boTableViewer = new TableViewer(group, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
boTableViewer.getControl()
.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).hint(200, SWT.DEFAULT).create());
boTableViewer.getTable().setLinesVisible(true);
......@@ -283,40 +285,10 @@ public class BusinessDataModelWizardPage extends WizardPage {
boTableViewer.getTable().setLayout(tableLayout);
boTableViewer.setContentProvider(new ObservableListContentProvider());
final IViewerObservableValue observeSingleSelection = ViewersObservables.observeSingleSelection(boTableViewer);
boTableViewer.getColumnViewerEditor().addEditorActivationListener(new ColumnViewerEditorActivationListener() {
@Override
public void beforeEditorDeactivated(final ColumnViewerEditorDeactivationEvent event) {
}
@Override
public void beforeEditorActivated(final ColumnViewerEditorActivationEvent event) {
}
@Override
public void afterEditorDeactivated(final ColumnViewerEditorDeactivationEvent event) {
final ISelection selection = boTableViewer.getSelection();
if (selection != null && ((IStructuredSelection) selection).getFirstElement() != null) {
businessObjectDescriptionGroup.setText(
NamingUtils.getSimpleName(((BusinessObject) ((IStructuredSelection) selection).getFirstElement())
.getQualifiedName()));
boTableViewer.refresh();
} else {
businessObjectDescriptionGroup.setText(Messages.selectABusinessObjectToEdit);
}
}
final IViewerObservableValue observeBusinessObjectSingleSelection = ViewersObservables
.observeSingleSelection(boTableViewer);
@Override
public void afterEditorActivated(final ColumnViewerEditorActivationEvent event) {
}
});
createBusinessObjectNameColumn(ctx, observeSingleSelection, boTableViewer);
businessObjectNameColumn = createBusinessObjectNameColumn(ctx, observeBusinessObjectSingleSelection, boTableViewer);
final UpdateValueStrategy enableStrategy = new UpdateValueStrategy();
enableStrategy.setConverter(new Converter(Object.class, Boolean.class) {
......@@ -327,7 +299,7 @@ public class BusinessDataModelWizardPage extends WizardPage {
}
});
ctx.bindValue(SWTObservables.observeEnabled(deleteButton), observeSingleSelection,
ctx.bindValue(SWTObservables.observeEnabled(deleteButton), observeBusinessObjectSingleSelection,
new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER),
enableStrategy);
......@@ -336,10 +308,6 @@ public class BusinessDataModelWizardPage extends WizardPage {
boTableViewer.setInput(businessObjectObserveList);
addButton.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(final SelectionEvent e) {
addBusinessObject(boTableViewer, businessObjectObserveList);
......@@ -349,17 +317,26 @@ public class BusinessDataModelWizardPage extends WizardPage {
deleteButton.addSelectionListener(new SelectionAdapter() {
/*
* (non-Javadoc)
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(final SelectionEvent e) {
deleteBusinessObject(boTableViewer, observeSingleSelection, businessObjectObserveList);
deleteBusinessObject(boTableViewer, observeBusinessObjectSingleSelection, businessObjectObserveList);
}
});
return observeSingleSelection;
return observeBusinessObjectSingleSelection;
}
private IConverter toPaneDescripitonlTitle() {
return new Converter(String.class, String.class) {
@Override
public Object convert(Object fromObject) {
if (fromObject != null) {
return NamingUtils.getSimpleName((String) fromObject);
}
return Messages.selectABusinessObjectToEdit;
}
};
}
protected void createPackageName(final DataBindingContext ctx, final Composite parent) {
......@@ -466,7 +443,7 @@ public class BusinessDataModelWizardPage extends WizardPage {
}
}
protected void createBusinessObjectNameColumn(final DataBindingContext ctx,
protected TableViewerColumn createBusinessObjectNameColumn(final DataBindingContext ctx,
final IViewerObservableValue businessObjectSingleSelection,
final TableViewer boTableViewer) {
final TableViewerColumn columnViewer = new TableViewerColumn(boTableViewer, SWT.FILL);
......@@ -486,17 +463,14 @@ public class BusinessDataModelWizardPage extends WizardPage {
return super.getText(element);
}
});
columnViewer.setEditingSupport(new BusinessObjectNameEditingSupport(businessObjectModel,
businessObjectSingleSelection, PojoObservables.observeValue(
this, "packageName"),
columnViewer.getViewer(), ctx));
final TableColumnSorter sorter = new TableColumnSorter(boTableViewer);
sorter.setColumn(column);
return columnViewer;
}
protected String generateObjectName() {
final Set<String> existingNames = new HashSet<String>();
final Set<String> existingNames = new HashSet<>();
for (final BusinessObject businessObject : businessObjectModel.getBusinessObjects()) {
existingNames.add(businessObject.getQualifiedName());
}
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -43,51 +41,64 @@ import org.eclipse.swt.widgets.Text;
/**
* @author Romain Bioteau
*
*/
public class BusinessObjectNameEditingSupport extends ObservableValueEditingSupport {
private DataBindingContext dbc;
private final DataBindingContext dbc;
private IObservableValue packageNameObservableValue;
private final IObservableValue packageNameObservableValue;
private BusinessObjectModel businessObjectModel;
private final BusinessObjectModel businessObjectModel;
private IViewerObservableValue businessObjectObservableValue;
private final IViewerObservableValue businessObjectObservableValue;
private final CellEditor cellEditor;
private final IObservableValue panelTextObservable;
/**
* @param viewer
* @param dbc
*/
public BusinessObjectNameEditingSupport(BusinessObjectModel businessObjectModel, IViewerObservableValue businessObjectObservableValue,
IObservableValue packageNameObservableValue, ColumnViewer viewer, DataBindingContext dbc) {
public BusinessObjectNameEditingSupport(BusinessObjectModel businessObjectModel,
IViewerObservableValue businessObjectObservableValue,
IObservableValue packageNameObservableValue,
IObservableValue panelTextObservable,
ColumnViewer viewer,
DataBindingContext dbc) {
super(viewer, dbc);
this.dbc = dbc;
this.packageNameObservableValue = packageNameObservableValue;
this.businessObjectModel = businessObjectModel;
this.panelTextObservable = panelTextObservable;
this.businessObjectObservableValue = businessObjectObservableValue;
this.cellEditor = createCellEditor();
}
@Override
protected CellEditor getCellEditor(Object element) {
TextCellEditor textCellEditor = new TextCellEditor((Composite) getViewer().getControl());
Text textControl = (Text) textCellEditor.getControl();
private CellEditor createCellEditor() {
final TextCellEditor textCellEditor = new TextCellEditor((Composite) getViewer().getControl());
final Text textControl = (Text) textCellEditor.getControl();
textControl.setTextLimit(BusinessObjectNameCellEditorValidator.MAX_TABLE_NAME_LENGTH + 5);
return textCellEditor;
}
@Override
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
@Override
protected IObservableValue doCreateElementObservable(final Object element, ViewerCell cell) {
IObservableValue observeValue = PojoObservables.observeValue(element, "qualifiedName");
final IObservableValue observeValue = PojoObservables.observeValue(element, "qualifiedName");
observeValue.addValueChangeListener(new ColumnViewerUpdateListener(getViewer(), element));
observeValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
BusinessObject businessObject = (BusinessObject) businessObjectObservableValue.getValue();
String oldName = (String) event.diff.getOldValue();
String newName = (String) event.diff.getNewValue();
for (Query q : businessObject.getQueries()) {
final BusinessObject businessObject = (BusinessObject) businessObjectObservableValue.getValue();
final String oldName = (String) event.diff.getOldValue();
final String newName = (String) event.diff.getNewValue();
for (final Query q : businessObject.getQueries()) {
if (q.getReturnType().equals(oldName)) {
q.setReturnType(newName);
}
......@@ -95,6 +106,13 @@ public class BusinessObjectNameEditingSupport extends ObservableValueEditingSupp
}
});
observeValue.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
panelTextObservable.setValue(NamingUtils.getSimpleName((String) event.diff.getNewValue()));
}
});
return observeValue;
}
......@@ -110,8 +128,8 @@ public class BusinessObjectNameEditingSupport extends ObservableValueEditingSupp
*/
@Override
protected Binding createBinding(IObservableValue target, IObservableValue model) {
UpdateValueStrategy targetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
BusinessObject value = (BusinessObject) businessObjectObservableValue.getValue();
final UpdateValueStrategy targetToModel = new UpdateValueStrategy(UpdateValueStrategy.POLICY_CONVERT);
final BusinessObject value = (BusinessObject) businessObjectObservableValue.getValue();
targetToModel.setAfterGetValidator(new BusinessObjectNameCellEditorValidator(businessObjectModel, value));
targetToModel.setConverter(new Converter(String.class, String.class) {
......@@ -120,7 +138,7 @@ public class BusinessObjectNameEditingSupport extends ObservableValueEditingSupp
return packageNameObservableValue.getValue() + "." + fromObject.toString();
}
});
UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
final UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
modelToTarget.setConverter(new Converter(String.class, String.class) {
@Override
......
......@@ -5,12 +5,10 @@
* 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/>.
*/
......@@ -22,13 +20,12 @@ import org.eclipse.jface.viewers.ColumnViewer;
/**
* @author Romain Bioteau
*
*/
public class ColumnViewerUpdateListener implements IValueChangeListener {
private ColumnViewer viewer;
private final ColumnViewer viewer;
private Object element;
private final Object element;
public ColumnViewerUpdateListener(ColumnViewer viewer, Object element) {
this.viewer = viewer;
......@@ -41,7 +38,14 @@ public class ColumnViewerUpdateListener implements IValueChangeListener {
*/
@Override
public void handleValueChange(ValueChangeEvent event) {
viewer.update(element, null);
viewer.getControl().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
viewer.update(element, null);
}
});
}
}
/**
* Copyright (C) 2016 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.observables;
import org.eclipse.jface.databinding.swt.WidgetValueProperty;
import org.eclipse.swt.widgets.Group;
public class GroupTextProperty extends WidgetValueProperty {
/*
* (non-Javadoc)
* @see org.eclipse.core.databinding.property.value.IValueProperty#getValueType()
*/
@Override
public Object getValueType() {
return String.class;
}
/*
* (non-Javadoc)
* @see org.eclipse.core.databinding.property.value.SimpleValueProperty#doGetValue(java.lang.Object)
*/
@Override
protected Object doGetValue(Object source) {
return ((Group) source).getText();
}
/*
* (non-Javadoc)
* @see org.eclipse.core.databinding.property.value.SimpleValueProperty#doSetValue(java.lang.Object, java.lang.Object)
*/
@Override
protected void doSetValue(Object source, Object value) {
((Group) source).setText((String) (value == null ? "" : value)); //$NON-NLS-1$
}
@Override
public String toString() {
return "Group.text <String>"; //$NON-NLS-1$
}
}
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