Search in sources :

Example 1 with FinderSegment

use of org.jboss.hal.core.finder.FinderSegment in project console by hal.

the class ApplicationFinderPresenter method updateBreadcrumb.

@SuppressWarnings("unchecked")
private void updateBreadcrumb() {
    FinderPath applicationPath = finderPath();
    if (applicationPath != null) {
        // try to connect segments with existing columns from the finder
        for (FinderSegment segment : applicationPath) {
            FinderColumn column = finder.getColumn(segment.getColumnId());
            if (column != null) {
                segment.connect(column);
            } else {
                logger.warn("Unable to find column '{}' to connect breadcrumb segment '{}' for token '{}'", segment.getColumnId(), segment, getProxy().getNameToken());
            }
        }
        finder.getContext().reset(applicationPath);
    }
    // The breadcrumb is part of the header. Notify the header presenter to take care of updating the breadcrumb
    getEventBus().fireEvent(new FinderContextEvent(finder.getContext()));
}
Also used : FinderSegment(org.jboss.hal.core.finder.FinderSegment) FinderPath(org.jboss.hal.core.finder.FinderPath) FinderColumn(org.jboss.hal.core.finder.FinderColumn) FinderContextEvent(org.jboss.hal.core.finder.FinderContextEvent)

Example 2 with FinderSegment

use of org.jboss.hal.core.finder.FinderSegment in project console by hal.

the class HeaderView method updateBreadcrumb.

@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void updateBreadcrumb(FinderContext finderContext) {
    clearBreadcrumb();
    FinderPath currentPath = new FinderPath();
    for (HandlerRegistration handler : breadcrumbHandlers) {
        handler.removeHandler();
    }
    breadcrumbHandlers.clear();
    for (Iterator<FinderSegment> iterator = finderContext.getPath().iterator(); iterator.hasNext(); ) {
        FinderSegment<Object> segment = iterator.next();
        if (segment.getColumnId() == null || segment.getItemId() == null) {
            // we need to ignore half filled segments which occur when removing items from a column
            break;
        }
        boolean last = !iterator.hasNext();
        currentPath.append(segment.getColumnId(), segment.getItemId());
        HtmlContentBuilder<HTMLLIElement> builder = li();
        if (last) {
            builder.css(active);
        }
        HTMLElement key = span().css(CSS.key).element();
        if (finderContext.getToken() != null) {
            PlaceRequest keyRequest = new PlaceRequest.Builder().nameToken(finderContext.getToken()).with("path", currentPath.toString()).build();
            key.appendChild(a().css(clickable).on(click, event -> presenter.goTo(keyRequest)).textContent(segment.getColumnTitle()).element());
        } else {
            key.textContent = segment.getColumnTitle();
        }
        builder.add(key).add(span().css(arrow).innerHtml(SafeHtmlUtils.fromSafeConstant("&#8658;")));
        HTMLElement value = span().css(CSS.value).element();
        if (segment.supportsDropdown()) {
            value.classList.add(dropdown);
            HTMLElement a;
            String id = Ids.build(segment.getColumnId(), VALUE);
            value.appendChild(a = a().css(clickable).id(id).data(UIConstants.TOGGLE, UIConstants.DROPDOWN).aria(UIConstants.HAS_POPUP, UIConstants.TRUE).aria(UIConstants.EXPANDED, UIConstants.FALSE).attr(UIConstants.ROLE, UIConstants.BUTTON).element());
            breadcrumbHandlers.add(bind(a, click, event -> {
                Element ul = a.nextElementSibling;
                segment.dropdown(finderContext, items -> {
                    Elements.removeChildrenFrom(ul);
                    if (items.isEmpty()) {
                        HTMLElement empty = li().css(CSS.empty).textContent(HeaderView.this.resources.constants().noItems()).element();
                        ul.appendChild(empty);
                    } else {
                        for (DropdownItem<Object> dropdownItem : items) {
                            HTMLElement element = li().add(a().css(clickable).on(click, e -> dropdownItem.onSelect(finderContext)).textContent(dropdownItem.getTitle())).element();
                            ul.appendChild(element);
                        }
                    }
                });
            }));
            String breadcrumbValue = segment.getItemTitle();
            if (breadcrumbValue.length() > MAX_BREADCRUMB_VALUE_LENGTH) {
                a.appendChild(span().textContent(abbreviateMiddle(breadcrumbValue, MAX_BREADCRUMB_VALUE_LENGTH) + " ").title(breadcrumbValue).element());
            } else {
                a.appendChild(span().textContent(breadcrumbValue + " ").element());
            }
            a.appendChild(span().css(caret).element());
            value.appendChild(ul().css(dropdownMenu, valueDropdown).aria(UIConstants.LABELLED_BY, id).element());
        } else {
            String breadcrumbValue = segment.getItemTitle();
            if (breadcrumbValue.length() > MAX_BREADCRUMB_VALUE_LENGTH) {
                value.textContent = abbreviateMiddle(breadcrumbValue, MAX_BREADCRUMB_VALUE_LENGTH);
                value.title = breadcrumbValue;
            } else {
                value.textContent = segment.getItemTitle();
            }
        }
        builder.add(value);
        breadcrumb.insertBefore(builder.element(), breadcrumbToolsItem);
    }
}
Also used : HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) Environment(org.jboss.hal.config.Environment) Endpoints(org.jboss.hal.config.Endpoints) LoggerFactory(org.slf4j.LoggerFactory) Tooltip(org.jboss.hal.ballroom.Tooltip) FinderSegment(org.jboss.hal.core.finder.FinderSegment) HtmlContentBuilder(org.jboss.gwt.elemento.core.builder.HtmlContentBuilder) ResourceAddress(org.jboss.hal.dmr.ResourceAddress) VALUE(org.jboss.hal.dmr.ModelDescriptionConstants.VALUE) HTMLElement(elemental2.dom.HTMLElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Message(org.jboss.hal.spi.Message) HalViewImpl(org.jboss.hal.core.mvp.HalViewImpl) User(org.jboss.hal.config.User) Elements.i(org.jboss.gwt.elemento.core.Elements.i) Places(org.jboss.hal.core.mvp.Places) Names(org.jboss.hal.resources.Names) Settings(org.jboss.hal.config.Settings) Set(java.util.Set) CSS(org.jboss.hal.resources.CSS) EventType.click(org.jboss.gwt.elemento.core.EventType.click) FinderPath(org.jboss.hal.core.finder.FinderPath) MAX_BREADCRUMB_VALUE_LENGTH(org.jboss.hal.client.skeleton.HeaderPresenter.MAX_BREADCRUMB_VALUE_LENGTH) Collectors.joining(java.util.stream.Collectors.joining) Roles(org.jboss.hal.config.Roles) List(java.util.List) UIConstants(org.jboss.hal.resources.UIConstants) CSS.nav(org.jboss.hal.resources.CSS.nav) StreamSupport.stream(java.util.stream.StreamSupport.stream) Role(org.jboss.hal.config.Role) Segment(org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment) Element(elemental2.dom.Element) Strings.abbreviateMiddle(org.jboss.hal.resources.Strings.abbreviateMiddle) FontAwesomeSize.large(org.jboss.hal.resources.FontAwesomeSize.large) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) HandlerRegistration(com.google.web.bindery.event.shared.HandlerRegistration) ModelBrowser(org.jboss.hal.core.modelbrowser.ModelBrowser) SafeHtmlUtils(com.google.gwt.safehtml.shared.SafeHtmlUtils) AccessControl(org.jboss.hal.core.accesscontrol.AccessControl) Logger(org.slf4j.Logger) RBAC(org.jboss.hal.config.AccessControlProvider.RBAC) Iterator(java.util.Iterator) Ids(org.jboss.hal.resources.Ids) PlaceRequest(com.gwtplatform.mvp.shared.proxy.PlaceRequest) DropdownItem(org.jboss.hal.core.finder.FinderSegment.DropdownItem) ModelBrowserPath(org.jboss.hal.core.modelbrowser.ModelBrowserPath) FinderContext(org.jboss.hal.core.finder.FinderContext) HTMLLIElement(elemental2.dom.HTMLLIElement) Elements.nav(org.jboss.gwt.elemento.core.Elements.nav) NameTokens(org.jboss.hal.meta.token.NameTokens) Resources(org.jboss.hal.resources.Resources) EventType.bind(org.jboss.gwt.elemento.core.EventType.bind) RUN_AS(org.jboss.hal.config.Settings.Key.RUN_AS) Elements(org.jboss.gwt.elemento.core.Elements) HTMLElement(elemental2.dom.HTMLElement) FinderSegment(org.jboss.hal.core.finder.FinderSegment) HTMLElement(elemental2.dom.HTMLElement) Element(elemental2.dom.Element) HTMLLIElement(elemental2.dom.HTMLLIElement) HTMLLIElement(elemental2.dom.HTMLLIElement) FinderPath(org.jboss.hal.core.finder.FinderPath) DropdownItem(org.jboss.hal.core.finder.FinderSegment.DropdownItem)

Example 3 with FinderSegment

use of org.jboss.hal.core.finder.FinderSegment in project console by hal.

the class Tracker method onFinderContext.

@Override
public void onFinderContext(FinderContextEvent event) {
    FinderContext context = event.getFinderContext();
    StringBuilder page = new StringBuilder();
    page.append("/" + context.getToken());
    for (FinderSegment segment : context.getPath()) {
        append(page, segment.getColumnId(), segment.getItemId());
    }
    logger.debug("Track finder selection {}", page);
    ga.trackPageView(page.toString());
}
Also used : FinderContext(org.jboss.hal.core.finder.FinderContext) FinderSegment(org.jboss.hal.core.finder.FinderSegment)

Aggregations

FinderSegment (org.jboss.hal.core.finder.FinderSegment)3 FinderContext (org.jboss.hal.core.finder.FinderContext)2 FinderPath (org.jboss.hal.core.finder.FinderPath)2 Strings (com.google.common.base.Strings)1 SafeHtmlUtils (com.google.gwt.safehtml.shared.SafeHtmlUtils)1 HandlerRegistration (com.google.web.bindery.event.shared.HandlerRegistration)1 PlaceRequest (com.gwtplatform.mvp.shared.proxy.PlaceRequest)1 Element (elemental2.dom.Element)1 HTMLElement (elemental2.dom.HTMLElement)1 HTMLLIElement (elemental2.dom.HTMLLIElement)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 StreamSupport.stream (java.util.stream.StreamSupport.stream)1 Inject (javax.inject.Inject)1