Commit 5b7b6533 authored by Adrien's avatar Adrien Committed by GitHub
Browse files

* change the enable binding with an editable binding to avoid the (#1176)

strange behavior on windows
parent fcd6a9dc
......@@ -43,6 +43,7 @@ import org.eclipse.core.databinding.beans.PojoProperties;
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.ComputedValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
......@@ -53,7 +54,6 @@ import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.jface.databinding.viewers.IViewerObservableValue;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ViewersObservables;
......@@ -77,7 +77,6 @@ import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
......@@ -231,27 +230,24 @@ public class BusinessDataModelWizardPage extends WizardPage {
final Group descriptionGroup) {
IObservableValue<String> descriptionObservable = PojoProperties.value("description")
.observeDetail(viewerObservableValue);
ComputedValue<Boolean> enableStrategy = new ComputedValue<Boolean>() {
Control descriptionText = new TextAreaWidget.Builder()
@Override
protected Boolean calculate() {
return viewerObservableValue != null && viewerObservableValue.getValue() != null;
}
};
new TextAreaWidget.Builder()
.withLabel(Messages.description)
.labelAbove()
.heightHint(75)
.grabHorizontalSpace()
.fill()
.bindTo(descriptionObservable)
.withEditableStrategy(enableStrategy)
.inContext(ctx)
.createIn(descriptionGroup)
.getControl();
final UpdateValueStrategy enableStrategy = new UpdateValueStrategy();
enableStrategy.setConverter(new Converter(Object.class, Boolean.class) {
@Override
public Object convert(final Object fromObject) {
return fromObject != null;
}
});
ctx.bindValue(WidgetProperties.enabled().observe(descriptionText), viewerObservableValue, null, enableStrategy);
.createIn(descriptionGroup);
}
protected void createSeparator(final Composite mainComposite) {
......
......@@ -17,6 +17,8 @@ package org.bonitasoft.studio.ui.widget;
import java.util.Optional;
import java.util.function.BiConsumer;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
......@@ -31,21 +33,24 @@ public class NativeTextWidget extends TextWidget {
protected NativeTextWidget(Composite container, String id, boolean topLabel, int horizontalLabelAlignment,
int verticalLabelAlignment, int labelWidth, boolean readOnly, String label, String message,
Optional<String> labelButton, boolean transactionalEdit, BiConsumer<String, String> onEdit,
Optional<FormToolkit> toolkit, Optional<IContentProposalProvider> proposalProvider) {
Optional<FormToolkit> toolkit, Optional<IContentProposalProvider> proposalProvider,
Optional<ComputedValue<Boolean>> editableStrategy,
Optional<DataBindingContext> ctx) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message,
labelButton, transactionalEdit, onEdit, toolkit, proposalProvider);
message, labelButton, transactionalEdit, onEdit, toolkit, proposalProvider, editableStrategy, ctx);
}
/*
* (non-Javadoc)
* @see org.bonitasoft.studio.ui.widget.EditableControlWidget#drawBorder(org.eclipse.swt.widgets.Composite, org.eclipse.swt.widgets.Event)
* @see org.bonitasoft.studio.ui.widget.EditableControlWidget#drawBorder(org.eclipse.swt.widgets.Composite,
* org.eclipse.swt.widgets.Event)
*/
@Override
protected void drawBorder(Composite container, Event e) {
}
@Override
protected Text newText(final Composite textContainer) {
final Text newText = new Text(textContainer, SWT.SINGLE | SWT.BORDER);
newText.setLayoutData(
......
......@@ -16,6 +16,8 @@ package org.bonitasoft.studio.ui.widget;
import java.util.Optional;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
......@@ -31,7 +33,8 @@ public class SearchWidget extends TextWidget {
@Override
public SearchWidget createIn(Composite container) {
final SearchWidget control = new SearchWidget(container, id, labelAbove, horizontalLabelAlignment,
verticalLabelAlignment, labelWidth, readOnly, label, message, labelButton, toolkit);
verticalLabelAlignment, labelWidth, readOnly, label, message, labelButton, toolkit, editableStrategy,
Optional.ofNullable(ctx));
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
placeholder.ifPresent(control::setPlaceholder);
......@@ -55,9 +58,11 @@ public class SearchWidget extends TextWidget {
String label,
String message,
Optional<String> labelButton,
Optional<FormToolkit> toolkit) {
Optional<FormToolkit> toolkit,
Optional<ComputedValue<Boolean>> editableStrategy,
Optional<DataBindingContext> ctx) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message, labelButton, false, null, toolkit, Optional.empty());
message, labelButton, false, null, toolkit, Optional.empty(), editableStrategy, ctx);
}
@Override
......
......@@ -16,6 +16,8 @@ package org.bonitasoft.studio.ui.widget;
import java.util.Optional;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
......@@ -32,7 +34,8 @@ public class TextAreaWidget extends TextWidget {
@Override
public TextAreaWidget createIn(Composite container) {
final TextAreaWidget control = new TextAreaWidget(container, id, labelAbove, horizontalLabelAlignment,
verticalLabelAlignment, labelWidth, readOnly, label, message, labelButton, toolkit);
verticalLabelAlignment, labelWidth, readOnly, label, message, labelButton, toolkit, editableStrategy,
Optional.ofNullable(ctx));
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
if (ctx != null && modelObservable != null) {
......@@ -54,9 +57,11 @@ public class TextAreaWidget extends TextWidget {
String label,
String message,
Optional<String> labelButton,
Optional<FormToolkit> toolkit) {
Optional<FormToolkit> toolkit,
Optional<ComputedValue<Boolean>> editableStrategy,
Optional<DataBindingContext> ctx) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message, labelButton, false, null, toolkit, Optional.empty());
message, labelButton, false, null, toolkit, Optional.empty(), editableStrategy, ctx);
}
/*
......
......@@ -23,7 +23,9 @@ import org.bonitasoft.studio.common.jface.SWTBotConstants;
import org.bonitasoft.studio.ui.ColorConstants;
import org.bonitasoft.studio.ui.i18n.Messages;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.ComputedValue;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.bindings.keys.KeyStroke;
......@@ -67,6 +69,12 @@ public class TextWidget extends EditableControlWidget {
private BiConsumer<String, String> onEdit;
private Optional<IContentProposalProvider> proposalProvider = Optional.empty();
private Optional<String> tooltip = Optional.empty();
protected Optional<ComputedValue<Boolean>> editableStrategy = Optional.empty();
public Builder withEditableStrategy(ComputedValue<Boolean> viewerObservableValue) {
this.editableStrategy = Optional.ofNullable(viewerObservableValue);
return this;
}
/**
* Adds a placeholder to the resulting {@link Text}
......@@ -141,7 +149,9 @@ public class TextWidget extends EditableControlWidget {
transactionalEdit,
onEdit,
toolkit,
proposalProvider)
proposalProvider,
editableStrategy,
Optional.ofNullable(ctx))
: new TextWidget(container,
id,
labelAbove,
......@@ -155,7 +165,9 @@ public class TextWidget extends EditableControlWidget {
transactionalEdit,
onEdit,
toolkit,
proposalProvider);
proposalProvider,
editableStrategy,
Optional.ofNullable(ctx));
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
buttonListner.ifPresent(control::onCLickButton);
......@@ -187,12 +199,15 @@ public class TextWidget extends EditableControlWidget {
private final Color editingColor;
private ToolItem okButton;
private final Optional<IContentProposalProvider> proposalProvider;
private Optional<ComputedValue<Boolean>> enableStrategy;
private Optional<DataBindingContext> ctx;
protected TextWidget(Composite container, String id, boolean topLabel, int horizontalLabelAlignment,
int verticalLabelAlignment,
int labelWidth, boolean readOnly, String label, String message, Optional<String> labelButton,
boolean transactionalEdit, BiConsumer<String, String> onEdit, Optional<FormToolkit> toolkit,
Optional<IContentProposalProvider> proposalProvider) {
Optional<IContentProposalProvider> proposalProvider, Optional<ComputedValue<Boolean>> enableStrategy,
Optional<DataBindingContext> ctx) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message,
labelButton,
......@@ -201,6 +216,8 @@ public class TextWidget extends EditableControlWidget {
this.onEdit = Optional.ofNullable(onEdit);
this.proposalProvider = proposalProvider;
this.editingColor = resourceManager.createColor(ColorConstants.EDITING_RGB);
this.enableStrategy = enableStrategy;
this.ctx = ctx;
}
@Override
......@@ -290,6 +307,9 @@ public class TextWidget extends EditableControlWidget {
text.setData(SWTBOT_WIDGET_ID_KEY, id);
configureBackground(text);
enableStrategy.ifPresent(strategy -> ctx.orElse(new DataBindingContext())
.bindValue(WidgetProperties.editable().observe(text), strategy));
proposalProvider.ifPresent(provider -> {
final TextContentAdapter controlContentAdapter = new TextContentAdapter();
final KeyStroke keyStroke = KeyStroke.getInstance(SWT.MOD1, SWT.SPACE);
......
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