Search in sources :

Example 1 with Segment

use of org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment in project console by hal.

the class HeaderView method updateBreadcrumb.

@Override
public void updateBreadcrumb(ModelBrowserPath path) {
    clearBreadcrumb();
    if (path == null || path.isEmpty()) {
        // deselection
        breadcrumb.insertBefore(li().textContent(resources.constants().nothingSelected()).element(), breadcrumbToolsItem);
    } else {
        ModelBrowser modelBrowser = path.getModelBrowser();
        for (Iterator<Segment[]> iterator = path.iterator(); iterator.hasNext(); ) {
            Segment[] segments = iterator.next();
            Segment key = segments[0];
            Segment value = segments[1];
            boolean link = value != ModelBrowserPath.WILDCARD && iterator.hasNext();
            HTMLElement valueContainer;
            HTMLElement li = li().add(span().css(CSS.key).add(a().css(clickable).on(click, event -> modelBrowser.select(key.id, true)).textContent(key.text))).add(span().css(arrow).innerHtml(SafeHtmlUtils.fromSafeConstant("&#8658;"))).add(valueContainer = span().css(CSS.value).element()).element();
            if (link) {
                valueContainer.appendChild(valueContainer = a().css(clickable).on(click, event -> modelBrowser.select(value.id, true)).element());
            }
            valueContainer.textContent = value.text;
            breadcrumb.insertBefore(li, breadcrumbToolsItem);
        }
    }
}
Also used : 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) ModelBrowser(org.jboss.hal.core.modelbrowser.ModelBrowser) HTMLElement(elemental2.dom.HTMLElement) FinderSegment(org.jboss.hal.core.finder.FinderSegment) Segment(org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment)

Example 2 with Segment

use of org.jboss.hal.core.modelbrowser.ModelBrowserPath.Segment 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)

Aggregations

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