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