Search in sources :

Example 1 with SearchResult

use of io.jmix.search.searching.SearchResult in project jmix by jmix-framework.

the class SearchFieldImpl method performSearch.

public void performSearch() {
    Screen frameOwner = ComponentsHelper.getWindowNN(this).getFrameOwner();
    String searchText = getValue();
    ScreenContext screenContext = getScreenContext(frameOwner);
    if (StringUtils.isBlank(searchText)) {
        Notifications notifications = screenContext.getNotifications();
        notifications.create(HUMANIZED).withCaption(messages.getMessage("io.jmix.searchui.noSearchText")).show();
    } else {
        String preparedSearchText = searchText.trim();
        SearchContext searchContext = new SearchContext(preparedSearchText).setSize(searchProperties.getSearchResultPageSize()).setEntities(getEntities());
        SearchResult searchResult = entitySearcher.search(searchContext, searchStrategy);
        if (searchCompletedHandler != null) {
            searchCompletedHandler.accept(new SearchCompletedEvent(this, searchResult));
        }
    }
}
Also used : ScreenContext(io.jmix.ui.screen.ScreenContext) UiControllerUtils.getScreenContext(io.jmix.ui.screen.UiControllerUtils.getScreenContext) SearchResultsScreen(io.jmix.searchui.screen.result.SearchResultsScreen) Screen(io.jmix.ui.screen.Screen) SearchContext(io.jmix.search.searching.SearchContext) SearchResult(io.jmix.search.searching.SearchResult) Notifications(io.jmix.ui.Notifications)

Example 2 with SearchResult

use of io.jmix.search.searching.SearchResult in project jmix by jmix-framework.

the class SearchResultsScreen method renderNavigationControls.

protected void renderNavigationControls(Queue<Page> pages) {
    navigationBox.removeAll();
    boolean showNextPage = true;
    Page lastPage = getLastPage();
    if (lastPage != null) {
        SearchResult lastSearchResult = lastPage.getSearchResult();
        showNextPage = lastSearchResult.isMoreDataAvailable();
    }
    if (pages.size() > 1 || showNextPage) {
        for (Page page : pages) {
            LinkButton pageButton = uiComponents.create(LinkButton.class);
            BaseAction action = new BaseAction("page_" + page.getPageNumber()).withCaption(page.getDisplayedPageNumber()).withHandler(e -> openPage(page));
            pageButton.setAction(action);
            if (page == currentPage) {
                pageButton.setStyleName("jmix-fts-current-page");
            } else {
                pageButton.setStyleName("jmix-fts-page");
            }
            navigationBox.add(pageButton);
        }
    }
    if (showNextPage) {
        LinkButton nextPageButton = uiComponents.create(LinkButton.class);
        BaseAction action = new BaseAction("nextPage").withCaption(messages.getMessage(SearchResultsScreen.class, "nextPage")).withHandler(e -> openNextPage());
        nextPageButton.setAction(action);
        nextPageButton.setStyleName("jmix-fts-page");
        navigationBox.add(nextPageButton);
    }
}
Also used : BaseAction(io.jmix.ui.action.BaseAction) SearchResult(io.jmix.search.searching.SearchResult)

Example 3 with SearchResult

use of io.jmix.search.searching.SearchResult in project jmix by jmix-framework.

the class SearchResultsScreen method renderResult.

protected void renderResult(SearchResultsScreen.Page page) {
    contentBox.removeAll();
    SearchResult searchResult = page.getSearchResult();
    if (searchResult.isEmpty()) {
        contentBox.add(createNotFoundLabel());
    } else {
        List<Pair<String, String>> entityGroups = new ArrayList<>();
        for (String entityName : searchResult.getEntityNames()) {
            entityGroups.add(new Pair<>(entityName, messageTools.getEntityCaption(metadata.getClass(entityName))));
        }
        entityGroups.sort(Comparator.comparing(Pair::getSecond));
        for (Pair<String, String> entityPair : entityGroups) {
            String entityName = entityPair.getFirst();
            String entityCaption = entityPair.getSecond();
            CssLayout container = createCssLayout();
            container.setStyleName("jmix-fts-entities-container");
            container.setWidth("100%");
            CssLayout entityLabelLayout = createCssLayout();
            entityLabelLayout.setStyleName("jmix-fts-entities-type");
            entityLabelLayout.add(createEntityLabel(entityCaption));
            container.add(entityLabelLayout);
            CssLayout instancesLayout = createCssLayout();
            instancesLayout.setWidth("100%");
            displayInstances(searchResult, entityName, instancesLayout);
            container.add(instancesLayout);
            contentBox.add(container);
        }
    }
}
Also used : SearchResult(io.jmix.search.searching.SearchResult) Pair(io.jmix.core.common.datastruct.Pair)

Example 4 with SearchResult

use of io.jmix.search.searching.SearchResult in project jmix-docs by Haulmont.

the class SearchScreenHandler2 method mySearchFieldSearchCompletedHandler.

// end::screen-builders[]
// tag::handler[]
@Install(to = "mySearchField", subject = "searchCompletedHandler")
public void mySearchFieldSearchCompletedHandler(SearchField.SearchCompletedEvent event) {
    SearchResult searchResult = event.getSearchResult();
    screenBuilders.screen(this).withScreenClass(SearchResultsScreen.class).withOpenMode(OpenMode.DIALOG).build().setSearchResult(searchResult).show();
}
Also used : SearchResult(io.jmix.search.searching.SearchResult)

Example 5 with SearchResult

use of io.jmix.search.searching.SearchResult in project jmix-docs by Haulmont.

the class SearchScreenHandler1 method onInit.

// end::screen-builders[]
// tag::init[]
@Subscribe
public void onInit(InitEvent initEvent) {
    mySearchField.setSearchCompletedHandler(event -> {
        SearchResult searchResult = event.getSearchResult();
        screenBuilders.screen(this).withScreenClass(SearchResultsScreen.class).withOpenMode(OpenMode.DIALOG).build().setSearchResult(searchResult).show();
    });
}
Also used : SearchResult(io.jmix.search.searching.SearchResult)

Aggregations

SearchResult (io.jmix.search.searching.SearchResult)7 SearchContext (io.jmix.search.searching.SearchContext)2 Pair (io.jmix.core.common.datastruct.Pair)1 SearchResultsScreen (io.jmix.searchui.screen.result.SearchResultsScreen)1 Notifications (io.jmix.ui.Notifications)1 BaseAction (io.jmix.ui.action.BaseAction)1 Screen (io.jmix.ui.screen.Screen)1 ScreenContext (io.jmix.ui.screen.ScreenContext)1 Subscribe (io.jmix.ui.screen.Subscribe)1 UiControllerUtils.getScreenContext (io.jmix.ui.screen.UiControllerUtils.getScreenContext)1