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

feat(profile & la) filtering auto complete (#553)

* auto complete widgets used in profile & application editors now work
with a start with filtering behavior

closes [BS-16760](https://bonitasoft.atlassian.net/browse/BS-16760)
parent 8ae46755
......@@ -16,6 +16,7 @@ package org.bonitasoft.studio.ui.viewer;
import java.util.stream.Stream;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposalProvider;
import org.eclipse.jface.fieldassist.TextContentAdapter;
......@@ -24,6 +25,7 @@ import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
public class AutoCompleteTextCellEditor extends TextCellEditor {
......@@ -35,12 +37,23 @@ public class AutoCompleteTextCellEditor extends TextCellEditor {
@Override
protected Control createControl(Composite parent) {
Control control = super.createControl(parent);
final Control control = super.createControl(parent);
Stream.of(control.getListeners(SWT.FocusIn)).forEach(l -> control.removeListener(SWT.FocusIn, l));
Stream.of(control.getListeners(SWT.FocusIn)).forEach(l -> control.removeListener(SWT.FocusOut, l));
control.addListener(SWT.Modify, e -> fireControlSpaceEvent());
return control;
}
private void fireControlSpaceEvent() {
if (proposalAdapter != null && !proposalAdapter.isProposalPopupOpen()
&& (getValue() == null || getValue().toString().isEmpty())) {
final Event ctrlSpaceEvent = new Event();
ctrlSpaceEvent.keyCode = SWT.SPACE;
ctrlSpaceEvent.stateMask = SWT.MOD1;
getControl().getDisplay().asyncExec(() -> getControl().notifyListeners(SWT.KeyDown, ctrlSpaceEvent));
}
}
@Override
protected void focusLost() {
if (proposalAdapter == null || !proposalAdapter.isProposalPopupOpen()) {
......@@ -51,7 +64,7 @@ public class AutoCompleteTextCellEditor extends TextCellEditor {
public void setProposalProvider(IContentProposalProvider proposalProvider) {
final TextContentAdapter controlContentAdapter = new TextContentAdapter();
proposalAdapter = new ContentProposalAdapter(getControl(), controlContentAdapter,
proposalProvider, null, null);
proposalProvider, KeyStroke.getInstance(SWT.MOD1, SWT.SPACE), null);
proposalAdapter.setPropagateKeys(true);
proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
proposalAdapter.setAutoActivationDelay(0);
......
......@@ -26,6 +26,7 @@ import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
import org.eclipse.jface.databinding.swt.SWTObservables;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
......@@ -45,6 +46,7 @@ import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.ToolBar;
......@@ -250,19 +252,29 @@ 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 KeyStroke keyStroke = KeyStroke.getInstance(SWT.MOD1, SWT.SPACE);
final ContentProposalAdapter proposalAdapter = new ContentProposalAdapter(text,
controlContentAdapter,
provider,
null,
keyStroke,
null);
proposalAdapter.setPropagateKeys(true);
proposalAdapter.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
proposalAdapter.setAutoActivationDelay(0);
text.addListener(SWT.FocusIn, e -> fireControlSpaceEvent(proposalAdapter));
text.addListener(SWT.Modify, e -> {
if (text.isFocusControl()) {
fireControlSpaceEvent(proposalAdapter);
}
});
});
text.addListener(SWT.FocusIn, event -> redraw(textContainer));
text.addListener(SWT.FocusIn, event ->
redraw(textContainer));
text.addListener(SWT.FocusOut, event -> redraw(textContainer));
text.addListener(SWT.Paint, event -> {
if (!text.isEnabled()) {
......@@ -310,6 +322,16 @@ public class TextWidget extends EditableControlWidget {
return textContainer;
}
private void fireControlSpaceEvent(ContentProposalAdapter proposalAdapter) {
if (proposalAdapter != null && !proposalAdapter.isProposalPopupOpen()
&& (text.getText() == null || text.getText().isEmpty())) {
final Event ctrlSpaceEvent = new Event();
ctrlSpaceEvent.keyCode = SWT.SPACE;
ctrlSpaceEvent.stateMask = SWT.MOD1;
text.getDisplay().asyncExec(() -> text.notifyListeners(SWT.KeyDown, ctrlSpaceEvent));
}
}
protected int verticalAlignment() {
return SWT.CENTER;
}
......
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