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));
}
}
}
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);
}
}
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);
}
}
}
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();
}
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();
});
}
Aggregations