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