Fix the issue on press of Enter key for querying the
filtered data but not on while selecting any suggestion by pressing enter. Also fixed the infinite looping of the progress spinner. Signed-off-by: Gaurav <gaurav.sahay@in.bosch.com>
This commit is contained in:
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.eclipse.hawkbit.repository.rsql.RsqlValidationOracle;
|
||||
import org.eclipse.hawkbit.ui.common.builder.TextFieldBuilder;
|
||||
@@ -24,8 +25,9 @@ import org.eclipse.hawkbit.ui.utils.SPUIStyleDefinitions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.vaadin.spring.events.EventBus;
|
||||
import org.vaadin.spring.events.EventScope;
|
||||
import org.vaadin.spring.events.annotation.EventBusListenerMethod;
|
||||
|
||||
import com.vaadin.event.ShortcutListener;
|
||||
import com.vaadin.server.FontAwesome;
|
||||
import com.vaadin.shared.ui.label.ContentMode;
|
||||
import com.vaadin.spring.annotation.SpringComponent;
|
||||
@@ -85,9 +87,27 @@ public class AutoCompleteTextFieldComponent extends HorizontalLayout {
|
||||
*/
|
||||
@PostConstruct
|
||||
public void postConstruct() {
|
||||
eventBus.subscribe(this);
|
||||
new TextFieldSuggestionBox(rsqlValidationOracle, this).extend(queryTextField);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
eventBus.unsubscribe(this);
|
||||
}
|
||||
|
||||
@EventBusListenerMethod(scope = EventScope.SESSION)
|
||||
void onEvent(final CustomFilterUIEvent custFUIEvent) {
|
||||
if (custFUIEvent == CustomFilterUIEvent.UPDATE_TARGET_FILTER_SEARCH_ICON) {
|
||||
validationIcon.setValue(FontAwesome.CHECK_CIRCLE.getHtml());
|
||||
if (!isValidationError()) {
|
||||
validationIcon.setStyleName(SPUIStyleDefinitions.SUCCESS_ICON);
|
||||
} else {
|
||||
validationIcon.setStyleName(SPUIStyleDefinitions.ERROR_ICON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the textfield and resets the validation icon.
|
||||
*/
|
||||
@@ -181,7 +201,6 @@ public class AutoCompleteTextFieldComponent extends HorizontalLayout {
|
||||
textField.setTextChangeEventMode(TextChangeEventMode.EAGER);
|
||||
textField.setImmediate(true);
|
||||
textField.setTextChangeTimeout(100);
|
||||
textField.addShortcutListener(new EnterShortCutListener());
|
||||
return textField;
|
||||
}
|
||||
|
||||
@@ -214,27 +233,17 @@ public class AutoCompleteTextFieldComponent extends HorizontalLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private final class EnterShortCutListener extends ShortcutListener {
|
||||
/**
|
||||
* Sets the spinner as progress indicator.
|
||||
*/
|
||||
public void showValidationInProgress() {
|
||||
validationIcon.setValue(null);
|
||||
validationIcon.addStyleName("show-status-label");
|
||||
validationIcon.setStyleName(SPUIStyleDefinitions.TARGET_FILTER_SEARCH_PROGRESS_INDICATOR_STYLE);
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public EnterShortCutListener() {
|
||||
super("Enter", KeyCode.ENTER, new int[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleAction(final Object sender, final Object target) {
|
||||
if (!isValidationError()) {
|
||||
showValidationInProgress();
|
||||
executor.execute(new StatusCircledAsync(UI.getCurrent()));
|
||||
}
|
||||
}
|
||||
|
||||
private void showValidationInProgress() {
|
||||
validationIcon.setValue(null);
|
||||
validationIcon.addStyleName("show-status-label");
|
||||
validationIcon.setStyleName(SPUIStyleDefinitions.TARGET_FILTER_SEARCH_PROGRESS_INDICATOR_STYLE);
|
||||
}
|
||||
public Executor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.eclipse.hawkbit.ui.filtermanagement.client.TextFieldSuggestionBoxServ
|
||||
|
||||
import com.vaadin.server.AbstractExtension;
|
||||
import com.vaadin.ui.TextField;
|
||||
import com.vaadin.ui.UI;
|
||||
|
||||
/**
|
||||
* Extension for the AutoCompleteTexfield.
|
||||
@@ -64,6 +65,15 @@ public class TextFieldSuggestionBox extends AbstractExtension implements TextFie
|
||||
getRpcProxy(TextFieldSuggestionBoxClientRpc.class).showSuggestions(mapToDto(suggest.getSuggestionContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeQuery(final String text, final int cursor) {
|
||||
if (!autoCompleteTextFieldComponent.isValidationError()) {
|
||||
autoCompleteTextFieldComponent.showValidationInProgress();
|
||||
autoCompleteTextFieldComponent.getExecutor()
|
||||
.execute(autoCompleteTextFieldComponent.new StatusCircledAsync(UI.getCurrent()));
|
||||
}
|
||||
}
|
||||
|
||||
private static SuggestionContextDto mapToDto(final SuggestionContext suggestionContext) {
|
||||
return new SuggestionContextDto(suggestionContext.getCursorPosition(),
|
||||
suggestionContext.getSuggestions().stream()
|
||||
|
||||
@@ -82,6 +82,8 @@ public class AutoCompleteTextFieldConnector extends AbstractExtensionConnector {
|
||||
public void onKeyUp(final KeyUpEvent event) {
|
||||
if (panel.isAttached()) {
|
||||
handlePanelEventDelegation(event);
|
||||
} else if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
|
||||
rpc.executeQuery(textFieldWidget.getValue(), textFieldWidget.getCursorPos());
|
||||
} else {
|
||||
doAskForSuggestion();
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.vaadin.shared.communication.ServerRpc;
|
||||
* make client to server calls in Vaadin. Only void methods are allowed in
|
||||
* ServerRpc calls.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TextFieldSuggestionBoxServerRpc extends ServerRpc {
|
||||
|
||||
/**
|
||||
@@ -31,4 +30,15 @@ public interface TextFieldSuggestionBoxServerRpc extends ServerRpc {
|
||||
* the current cursor position
|
||||
*/
|
||||
void suggest(final String text, final int cursor);
|
||||
|
||||
/**
|
||||
* Executes the query text to get the filtered data.
|
||||
*
|
||||
* @param text
|
||||
* the current entered text e.g. in a text field to retrieve
|
||||
* suggestion for
|
||||
* @param cursor
|
||||
* the current cursor position
|
||||
*/
|
||||
void executeQuery(final String text, final int cursor);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user