diff --git a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolPresenter.java b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolPresenter.java index 6832e3a..26b6194 100644 --- a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolPresenter.java +++ b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolPresenter.java @@ -34,6 +34,8 @@ package info.magnolia.ui.workbench.contenttool.search; import info.magnolia.event.EventBus; +import info.magnolia.ui.api.app.AppContext; +import info.magnolia.ui.api.app.SubAppContext; import info.magnolia.ui.api.view.View; import info.magnolia.ui.workbench.WorkbenchPresenter; import info.magnolia.ui.workbench.contenttool.ContentToolPresenter; @@ -58,20 +60,30 @@ private EventBus eventBus; private SearchContentToolView view; private WorkbenchPresenter workbenchPresenter; + private SubAppContext subAppContext; @Inject public SearchContentToolPresenter( WorkbenchPresenter workbenchPresenter, SearchContentToolView view, - EventBus eventBus) { + EventBus eventBus, SubAppContext subAppContext) { this.view = view; this.eventBus = eventBus; this.workbenchPresenter = workbenchPresenter; + this.subAppContext = subAppContext; } @Override public View start() { view.setListener(this); + + System.out.println("====================="); + System.out.println("Initialization PRESENTER start of APP: " + subAppContext.getAppContext().getName()); + System.out.println("Presenter id init: " + this.hashCode()); + System.out.println("In Pres: View id init: " + view.hashCode()); + System.out.println("In Pres: searchField id init: " + view.getSearchField().hashCode()); + System.out.println("In Pres: searchFieldShortCutListener id init: " + view.getSearchFieldShortCutListener().hashCode()); + System.out.println("====================="); eventBus.addHandler(QueryStatementChangedEvent.class, new QueryStatementChangedEvent.Handler() { @Override @@ -85,6 +97,14 @@ @Override public void onSearch(String searchQuery) { + System.out.println("====================="); + System.out.println("ON-SEACRH of APP: " + subAppContext.getAppContext().getName()); + System.out.println("Presenter id init: " + this.hashCode()); + System.out.println("In Pres: View id init: " + view.hashCode()); + System.out.println("In Pres: searchField id init: " + view.getSearchField().hashCode()); + System.out.println("In Pres: searchFieldShortCutListener id init: " + view.getSearchFieldShortCutListener().hashCode()); + System.out.println("In Pres: searchQuery: " + searchQuery); + System.out.println("====================="); if (workbenchPresenter.hasViewType(SearchPresenterDefinition.VIEW_TYPE)) { if (StringUtils.isNotBlank(searchQuery)) { eventBus.fireEvent(new SearchEvent(searchQuery)); diff --git a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolView.java b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolView.java index 9b7efe2..ed749a2 100644 --- a/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolView.java +++ b/magnolia-ui-workbench/src/main/java/info/magnolia/ui/workbench/contenttool/search/SearchContentToolView.java @@ -35,6 +35,9 @@ import info.magnolia.ui.api.view.View; +import com.vaadin.event.ShortcutListener; +import com.vaadin.ui.TextField; + /** * Search content tool view. */ @@ -44,6 +47,12 @@ void setSearchQuery(String searchQuery); + public TextField getSearchField(); + + public SearchContentToolView.Listener getListener(); + + public ShortcutListener getSearchFieldShortCutListener(); + /** * Listener interface. */ 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..285c115 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,8 @@ package info.magnolia.ui.workbench.contenttool.search; import info.magnolia.i18nsystem.SimpleTranslator; -import info.magnolia.ui.vaadin.extension.ShortcutProtector; +import info.magnolia.ui.api.app.SubAppContext; import info.magnolia.ui.vaadin.icon.Icon; - -import java.util.Arrays; import javax.inject.Inject; @@ -45,10 +43,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 +58,19 @@ private final SimpleTranslator i18n; - private TextField searchField; + private final TextField searchField; private SearchContentToolView.Listener listener; + + private int countEnter = 0; + + private SubAppContext subAppContext; private final Property.ValueChangeListener searchFieldListener = new Property.ValueChangeListener() { @Override public void valueChange(Property.ValueChangeEvent event) { + listener.onSearch(searchField.getValue()); boolean hasSearchContent = !searchField.getValue().isEmpty(); @@ -78,9 +83,42 @@ } }; + 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("====================="); + System.out.println("Calling searchFieldShortCutListener in VIEW of APP: " + subAppContext.getAppContext().getName()); + 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()); + System.out.println("listener id: " + listener.hashCode()); + System.out.println("====================="); + + 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) { + public SearchContentToolViewImpl(SimpleTranslator i18n, SubAppContext subAppContext) { this.i18n = i18n; + this.subAppContext = subAppContext; Button clearSearchBoxButton = new Button(); clearSearchBoxButton.setStyleName("m-closebutton"); clearSearchBoxButton.addStyleName("icon-delete-search"); @@ -103,6 +141,16 @@ searchField = buildSearchField(); + Panel panel = new Panel(); + panel.setContent(searchField); + panel.focus(); + System.out.println("====================="); + System.out.println("Initialization VIEW start of APP: " + subAppContext.getAppContext().getName()); + System.out.println("view id init: " + this.hashCode()); + System.out.println("searchField id init: " + searchField.hashCode()); + System.out.println("searchFieldShortCutListener id init: " + searchFieldShortCutListener.hashCode()); + System.out.println("====================="); + setVisible(true); addComponent(searchField); addComponent(clearSearchBoxButton); @@ -113,7 +161,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 +170,8 @@ // TextField has to be immediate to fire value changes when pressing Enter, avoiding ShortcutListener overkill. field.setImmediate(true); - field.addValueChangeListener(searchFieldListener); + field.addShortcutListener(searchFieldShortCutListener); + // field.addValueChangeListener(searchFieldListener); field.addFocusListener(new FieldEvents.FocusListener() { @Override @@ -148,7 +197,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,11 +206,28 @@ searchField.setValue(""); removeStyleName("has-content"); } - searchField.addValueChangeListener(searchFieldListener); + // searchField.addShortcutListener(searchFieldShortCutListener); + // searchField.addValueChangeListener(searchFieldListener); } @Override public Component asVaadinComponent() { return this; } + + @Override + public TextField getSearchField() { + return searchField; + } + + @Override + public SearchContentToolView.Listener getListener() { + return listener; + } + + @Override + public ShortcutListener getSearchFieldShortCutListener() { + return searchFieldShortCutListener; + } + }