Commit 83fa2273 authored by Romain Bioteau's avatar Romain Bioteau Committed by Adrien
Browse files

feat(app) use auto complete text instead of combo (#387)

Closes [BS-16402](https://bonitasoft.atlassian.net/browse/BS-16402)
parent 33e77d14
......@@ -15,7 +15,6 @@ errorWhileImporting_title=Error during import
ImportProcessButtonLabel=Import
importResultTitle=Import status
importSucessfulMessage=Import successfully completed.
openDiagram=Open diagrams
seeDetails=See details
skipValidation=Skip validation >>
importStatusMsg=Problems has been detected in imported content.
......
......@@ -20,6 +20,7 @@ import org.bonitasoft.studio.ui.databinding.UpdateValueStrategyFactory;
import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridData;
......@@ -45,6 +46,7 @@ public abstract class ControlWidgetBuilder<T, W extends ControlWidget> {
protected DataBindingContext ctx;
protected String id;
protected Optional<FormToolkit> toolkit = Optional.empty();
protected Optional<IValidator> validator = Optional.empty();
/**
* Adds a text label next to the control.
......@@ -276,6 +278,11 @@ public abstract class ControlWidgetBuilder<T, W extends ControlWidget> {
return (T) this;
}
public T withValidator(IValidator validator) {
this.validator = Optional.ofNullable(validator);
return (T) this;
}
/**
* Sets the {@link DataBindingContext} to use when binding this control
*/
......
......@@ -18,12 +18,15 @@ import java.util.Optional;
import org.bonitasoft.studio.ui.ColorConstants;
import org.bonitasoft.studio.ui.databinding.ControlMessageSupport;
import org.bonitasoft.studio.ui.databinding.UpdateStrategyFactory;
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.IObservableValue;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.resource.LocalResourceManager;
......@@ -157,6 +160,21 @@ public abstract class EditableControlWidget extends ControlWidget {
};
}
protected ControlMessageSupport bindValidator(DataBindingContext ctx, ISWTObservableValue controlObservable,
IObservableValue modelObservable, IValidator validator) {
final UpdateValueStrategy validateOnlyStrategy = UpdateStrategyFactory.convertUpdateValueStrategy()
.withValidator(validator).create();
return new ControlMessageSupport(ctx.bindValue(controlObservable, modelObservable,
validateOnlyStrategy, validateOnlyStrategy)) {
@Override
protected void statusChanged(IStatus status) {
EditableControlWidget.this.statusChanged(status);
}
};
}
protected void statusChanged(IStatus status) {
EditableControlWidget.this.status = status;
messageDecorator.setStatus(status);
......
......@@ -57,10 +57,14 @@ public class TextAreaWidget extends TextWidget {
protected TextAreaWidget(Composite container, String id, boolean topLabel, int horizontalLabelAlignment,
int verticalLabelAlignment,
int labelWidth, boolean readOnly, String label, String message, Optional<String> labelButton,
int labelWidth,
boolean readOnly,
String label,
String message,
Optional<String> labelButton,
Optional<FormToolkit> toolkit) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message, labelButton, false, null, toolkit);
message, labelButton, false, null, toolkit, Optional.empty());
}
/*
......
......@@ -27,6 +27,9 @@ import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
......@@ -57,6 +60,7 @@ public class TextWidget extends EditableControlWidget {
protected Optional<Integer> delay = Optional.empty();
protected boolean transactionalEdit = false;
private BiConsumer<String, String> onEdit;
private Optional<IContentProposalProvider> proposalProvider = Optional.empty();
/**
* Adds a placeholder to the resulting {@link Text}
......@@ -98,6 +102,11 @@ public class TextWidget extends EditableControlWidget {
return this;
}
public Builder withProposalProvider(IContentProposalProvider proposalProvider) {
this.proposalProvider = Optional.of(proposalProvider);
return this;
}
@Override
public TextWidget createIn(Composite container) {
if (transactionalEdit && targetToModelStrategy == null) {
......@@ -108,9 +117,20 @@ public class TextWidget extends EditableControlWidget {
throw new IllegalStateException(
"Target to model strategy must have a POLICY_CONVERT strategy with transactionalEdit");
}
final TextWidget control = new TextWidget(container, id, labelAbove, horizontalLabelAlignment,
verticalLabelAlignment, labelWidth, readOnly, label,
message, labelButton, transactionalEdit, onEdit, toolkit);
final TextWidget control = new TextWidget(container,
id,
labelAbove,
horizontalLabelAlignment,
verticalLabelAlignment,
labelWidth,
readOnly,
label,
message,
labelButton,
transactionalEdit,
onEdit,
toolkit,
proposalProvider);
control.init();
control.setLayoutData(layoutData != null ? layoutData : gridData);
buttonListner.ifPresent(control::onCLickButton);
......@@ -123,6 +143,10 @@ public class TextWidget extends EditableControlWidget {
modelObservable,
targetToModelStrategy,
modelToTargetStrategy);
validator.ifPresent(v -> control.bindValidator(ctx, delay.map(time -> control.observeText(time, SWT.Modify))
.orElse(control.observeText(SWT.Modify)),
modelObservable,
v));
}
return control;
}
......@@ -136,18 +160,21 @@ public class TextWidget extends EditableControlWidget {
private boolean editing = false;
private final Color editingColor;
private ToolItem okButton;
private final Optional<IContentProposalProvider> proposalProvider;
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) {
boolean transactionalEdit, BiConsumer<String, String> onEdit, Optional<FormToolkit> toolkit,
Optional<IContentProposalProvider> proposalProvider) {
super(container, id, topLabel, horizontalLabelAlignment, verticalLabelAlignment, labelWidth, readOnly, label,
message,
labelButton,
toolkit);
this.transactionalEdit = transactionalEdit;
this.onEdit = Optional.ofNullable(onEdit);
editingColor = resourceManager.createColor(ColorConstants.EDITING_RGB);
this.proposalProvider = proposalProvider;
this.editingColor = resourceManager.createColor(ColorConstants.EDITING_RGB);
}
@Override
......@@ -222,6 +249,17 @@ public class TextWidget extends EditableControlWidget {
text = newText(textContainer);
text.setData(SWTBOT_WIDGET_ID_KEY, id);
configureBackground(text);
proposalProvider.ifPresent(provider -> {
final TextContentAdapter controlContentAdapter = new TextContentAdapter();
final ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(text,
controlContentAdapter,
provider,
null,
null);
proposalAdapter.setPropagateKeys(true);
proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
proposalAdapter.setAutoActivationDelay(0);
});
text.addListener(SWT.FocusIn, event -> redraw(textContainer));
text.addListener(SWT.FocusOut, event -> redraw(textContainer));
......
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