Search in sources :

Example 1 with BookmarkListModel

use of org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel in project ovirt-engine by oVirt.

the class SearchPanelPresenterWidget method onBind.

@Override
protected void onBind() {
    super.onBind();
    registerHandler(getView().getBookmarkButton().addClickHandler(event -> {
        BookmarkListModel bookmarkListModel = bookmarkModelProvider.getModel();
        bookmarkListModel.setSearchString(getView().getSearchString());
        bookmarkListModel.getNewCommand().execute();
    }));
    registerHandler(getView().getClearButton().addClickHandler(event -> {
        getView().setSearchString("");
        model.setSearchString("");
        updateViewSearchString();
        updateModelSearchString();
    }));
    registerHandler(getView().getSearchButton().addClickHandler(event -> updateModelSearchString()));
    registerHandler(getView().getSearchInputHandlers().addKeyDownHandler(event -> {
        if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
            updateModelSearchString();
        } else if (event.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
            getView().hideSuggestionBox();
        }
    }));
    BookmarkListModel bookmarkListModel = bookmarkModelProvider.getModel();
    bookmarkListModel.getItemsChangedEvent().addListener((ev, sender, args) -> bookmarkItemsChanged());
    if (bookmarkListModel.getItems() == null) {
        bookmarkListModel.search();
    }
    // Have to call this to initially populate the values.
    bookmarkItemsChanged();
}
Also used : TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) HasKeyDownHandlers(com.google.gwt.event.dom.client.HasKeyDownHandlers) BookmarkModelProvider(org.ovirt.engine.ui.webadmin.uicommon.model.BookmarkModelProvider) EventBus(com.google.gwt.event.shared.EventBus) View(com.gwtplatform.mvp.client.View) Inject(com.google.inject.Inject) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) Collectors(java.util.stream.Collectors) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ArrayList(java.util.ArrayList) MainModelProvider(org.ovirt.engine.ui.common.uicommon.model.MainModelProvider) HasClickHandlers(com.google.gwt.event.dom.client.HasClickHandlers) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) PresenterWidget(com.gwtplatform.mvp.client.PresenterWidget) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel)

Example 2 with BookmarkListModel

use of org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel in project ovirt-engine by oVirt.

the class BookmarkPresenterWidget method updateBookmarks.

private void updateBookmarks() {
    BookmarkListModel model = bookmarkModelProvider.getModel();
    Collection<Bookmark> items = model.getItems();
    AbstractMainWithDetailsPresenter<?, ?, ?, ?> presenter = null;
    if (getCurrentPlaceWidget() instanceof AbstractMainWithDetailsPresenter) {
        presenter = (AbstractMainWithDetailsPresenter<?, ?, ?, ?>) getCurrentPlaceWidget();
    }
    final AbstractMainWithDetailsPresenter<?, ?, ?, ?> mainPresenter = presenter;
    getView().clearBookmarks();
    if (items != null && !items.isEmpty()) {
        for (Bookmark bookmark : items) {
            if (mainPresenter != null && isBookmarkForCurrentPlace(bookmark, mainPresenter)) {
                registerHandler(getView().addBookmark(bookmark, model, event -> {
                    mainPresenter.applySearchString(bookmark.getValue());
                    // Close the overlay.
                    RevealOverlayContentEvent.fire(this, new RevealOverlayContentEvent(null));
                    event.preventDefault();
                }));
            } else {
                getView().addBookmark(bookmark, model, null);
            }
        }
    }
}
Also used : BookmarkModelProvider(org.ovirt.engine.ui.webadmin.uicommon.model.BookmarkModelProvider) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) AbstractOverlayPresenterWidget(org.ovirt.engine.ui.webadmin.section.main.presenter.AbstractOverlayPresenterWidget) SearchStringMapping(org.ovirt.engine.ui.uicommonweb.models.SearchStringMapping) Collection(java.util.Collection) Inject(com.google.inject.Inject) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) AbstractMainWithDetailsPresenter(org.ovirt.engine.ui.webadmin.section.main.presenter.AbstractMainWithDetailsPresenter) EventBus(com.google.web.bindery.event.shared.EventBus) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) RevealOverlayContentEvent(org.ovirt.engine.ui.webadmin.section.main.presenter.RevealOverlayContentEvent) RevealOverlayContentEvent(org.ovirt.engine.ui.webadmin.section.main.presenter.RevealOverlayContentEvent) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel) AbstractMainWithDetailsPresenter(org.ovirt.engine.ui.webadmin.section.main.presenter.AbstractMainWithDetailsPresenter)

Example 3 with BookmarkListModel

use of org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel in project ovirt-engine by oVirt.

the class SearchPanelPresenterWidget method bookmarkItemsChanged.

private void bookmarkItemsChanged() {
    BookmarkListModel bookmarkListModel = bookmarkModelProvider.getModel();
    if (bookmarkListModel.getItems() != null) {
        getView().clearBookmarks();
        List<Bookmark> items = new ArrayList<>(bookmarkListModel.getItems());
        final String filterString = model.getDefaultSearchString();
        List<Bookmark> result = items.stream().filter(bookmark -> bookmark.getValue().startsWith(filterString)).collect(Collectors.toList());
        result.forEach(bookmark -> {
            registerHandler(getView().addAvailableBookmarks(bookmark, e -> {
                model.setSearchString(bookmark.getValue());
                model.search();
            }));
        });
    }
}
Also used : TagModel(org.ovirt.engine.ui.uicommonweb.models.tags.TagModel) HasKeyDownHandlers(com.google.gwt.event.dom.client.HasKeyDownHandlers) BookmarkModelProvider(org.ovirt.engine.ui.webadmin.uicommon.model.BookmarkModelProvider) EventBus(com.google.gwt.event.shared.EventBus) View(com.gwtplatform.mvp.client.View) Inject(com.google.inject.Inject) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) Collectors(java.util.stream.Collectors) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ArrayList(java.util.ArrayList) MainModelProvider(org.ovirt.engine.ui.common.uicommon.model.MainModelProvider) HasClickHandlers(com.google.gwt.event.dom.client.HasClickHandlers) Scheduler(com.google.gwt.core.client.Scheduler) List(java.util.List) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) KeyCodes(com.google.gwt.event.dom.client.KeyCodes) PresenterWidget(com.gwtplatform.mvp.client.PresenterWidget) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel) Bookmark(org.ovirt.engine.core.common.businessentities.Bookmark) BookmarkListModel(org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel) ArrayList(java.util.ArrayList)

Aggregations

ClickHandler (com.google.gwt.event.dom.client.ClickHandler)3 Inject (com.google.inject.Inject)3 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)3 Bookmark (org.ovirt.engine.core.common.businessentities.Bookmark)3 BookmarkListModel (org.ovirt.engine.ui.uicommonweb.models.bookmarks.BookmarkListModel)3 BookmarkModelProvider (org.ovirt.engine.ui.webadmin.uicommon.model.BookmarkModelProvider)3 Scheduler (com.google.gwt.core.client.Scheduler)2 HasClickHandlers (com.google.gwt.event.dom.client.HasClickHandlers)2 HasKeyDownHandlers (com.google.gwt.event.dom.client.HasKeyDownHandlers)2 KeyCodes (com.google.gwt.event.dom.client.KeyCodes)2 EventBus (com.google.gwt.event.shared.EventBus)2 PresenterWidget (com.gwtplatform.mvp.client.PresenterWidget)2 View (com.gwtplatform.mvp.client.View)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 MainModelProvider (org.ovirt.engine.ui.common.uicommon.model.MainModelProvider)2 SearchableListModel (org.ovirt.engine.ui.uicommonweb.models.SearchableListModel)2 TagModel (org.ovirt.engine.ui.uicommonweb.models.tags.TagModel)2 EventBus (com.google.web.bindery.event.shared.EventBus)1