diff --git a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolViewImpl.java b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolViewImpl.java index 8c2f247..8cacd6d 100644 --- a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolViewImpl.java +++ b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolViewImpl.java @@ -34,10 +34,7 @@ package info.magnolia.ui.workbench.contenttool.search; import info.magnolia.i18nsystem.SimpleTranslator; -import info.magnolia.ui.vaadin.extension.ShortcutProtector; import info.magnolia.ui.vaadin.icon.Icon; - -import java.util.Arrays; import javax.inject.Inject; @@ -45,10 +42,12 @@ import com.vaadin.data.Property; import com.vaadin.event.FieldEvents; -import com.vaadin.event.ShortcutAction; +import com.vaadin.event.ShortcutAction.KeyCode; +import com.vaadin.event.ShortcutListener; import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; +import com.vaadin.ui.Panel; import com.vaadin.ui.TextField; /** @@ -58,14 +57,17 @@ private final SimpleTranslator i18n; - private TextField searchField; + private final TextField searchField; private SearchContentToolView.Listener listener; + + private int countEnter = 0; private final Property.ValueChangeListener searchFieldListener = new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { + listener.onSearch(searchField.getValue()); boolean hasSearchContent = !searchField.getValue().isEmpty(); @@ -77,6 +79,34 @@ searchField.focus(); } }; + + // private final ShortcutListener searchFieldShortCutListener = new ShortcutListener("", KeyCode.ENTER, null) { + // + // @Override + // public void handleAction(Object sender, Object target) { + // countEnter = countEnter + 1; + // TextField targetField = (TextField) target; + // // searchField = targetField; + // + // System.out.println("SearchField value: " + searchField.getValue()); + // System.out.println("TargetField value: " + targetField.getValue()); + // System.out.println("Counter: " + countEnter); + // System.out.println("searchField id: " + searchField.hashCode()); + // System.out.println("targetField id: " + targetField.hashCode()); + // System.out.println("searchFieldShortCutListener id: " + searchFieldShortCutListener.hashCode()); + // + // listener.onSearch(searchField.getValue()); + // + // boolean hasSearchContent = !searchField.getValue().isEmpty(); + // if (hasSearchContent) { + // addStyleName("has-content"); + // } else { + // removeStyleName("has-content"); + // } + // searchField.focus(); + // + // } + // }; @Inject public SearchContentToolViewImpl(SimpleTranslator i18n) { @@ -103,6 +133,15 @@ searchField = buildSearchField(); + Panel panel = new Panel(); + panel.setContent(searchField); + panel.focus(); + System.out.println("====================="); + System.out.println("Iinitialization start"); + System.out.println("view id init: " + this.hashCode()); + System.out.println("searchField id init: " + searchField.hashCode()); + System.out.println("====================="); + setVisible(true); addComponent(searchField); addComponent(clearSearchBoxButton); @@ -113,7 +152,7 @@ private TextField buildSearchField() { final TextField field = new TextField(); - ShortcutProtector.extend(field, Arrays.asList(ShortcutAction.KeyCode.ENTER)); + // ShortcutProtector.extend(field, Arrays.asList(ShortcutAction.KeyCode.ENTER)); final String inputPrompt = i18n.translate("toolbar.search.prompt"); field.setInputPrompt(inputPrompt); @@ -122,7 +161,35 @@ // TextField has to be immediate to fire value changes when pressing Enter, avoiding ShortcutListener overkill. field.setImmediate(true); - field.addValueChangeListener(searchFieldListener); + ShortcutListener searchFieldShortCutListener = new ShortcutListener("", KeyCode.ENTER, new int[] {}) { + + @Override + public void handleAction(Object sender, Object target) { + countEnter = countEnter + 1; + TextField targetField = (TextField) target; + + System.out.println("SearchField value: " + searchField.getValue()); + System.out.println("TargetField value: " + targetField.getValue()); + System.out.println("Counter: " + countEnter); + System.out.println("searchField id: " + searchField.hashCode()); + System.out.println("targetField id: " + targetField.hashCode()); + System.out.println("searchFieldShortCutListener id: " + this.hashCode()); + + listener.onSearch(searchField.getValue()); + + boolean hasSearchContent = !searchField.getValue().isEmpty(); + if (hasSearchContent) { + addStyleName("has-content"); + } else { + removeStyleName("has-content"); + } + searchField.focus(); + + } + }; + field.addShortcutListener(searchFieldShortCutListener); + // field.addValueChangeListener(searchFieldListener); + field.addFocusListener(new FieldEvents.FocusListener() { @Override @@ -148,7 +215,8 @@ return; } // turn off value change listener, so that presenter does not think there was user input and searches again - searchField.removeValueChangeListener(searchFieldListener); + // searchField.removeShortcutListener(searchFieldShortCutListener); + // searchField.removeValueChangeListener(searchFieldListener); if (StringUtils.isNotBlank(searchQuery)) { searchField.setValue(searchQuery); searchField.focus(); @@ -156,7 +224,8 @@ searchField.setValue(""); removeStyleName("has-content"); } - searchField.addValueChangeListener(searchFieldListener); + // searchField.addShortcutListener(searchFieldShortCutListener); + // searchField.addValueChangeListener(searchFieldListener); } @Override