/** * Category query. * @param category Category to filter. * @return The requested query or {@code null} if the argument is {@code null}. */ public static NodeQuery category(Category category) { if (category == null) { return null; } return term(Schema.CATEGORY, category.getId()); }
private void addItems(List<Category> categoryList) { for (Category category : categoryList) { cloud.add(createItem(category, (int) Math.ceil(Math.random() * 10), 10)); addItems(categories.getChildren(category.getId())); } }
public void edit() { this.cloud = new LinkedList<CloudItem>(); final Category categoryRoot = categories.getRoot(); addItems(categories.getChildren(categoryRoot.getId())); }
private Predicate<Category> calculateSelected() { Category c = getSelected(); if (c == null || !categories.containsValue(c)) { return Predicates.alwaysFalse(); } if (config != null && config.selectParents()) { Set<Category> selected = Sets.newHashSet(); do { selected.add(c); c = categories.getParent(c.getId()); } while (c != null); return Predicates.in(selected); } return Predicates.equalTo(c); }
/** Component execution. */ public ComponentResponse execute() { if (config == null || categories == null || navigationKey == null || !navigationKey.isCategory()) { return ComponentResponse.OK; } final int distance = config.distance(); if (distance < 1) { return ComponentResponse.OK; } final Category current = navigationKey.getCategory(); final Category category = config.category(); if (!categories.containsKey(current.getId()) || !categories.containsKey(category.getId())) { return ComponentResponse.OK; } final List<Category> list = Lists.newLinkedList(); list.add(current); Category p = current; while ((p = categories.getParent(p.getId())) != null) { if (p.equals(category)) { if (list.isEmpty()) { return ComponentResponse.OK; } else { goTo(list.get(Math.min(list.size() - 1, distance - 1))); } } else { list.add(0, p); } } return ComponentResponse.OK; }
protected void add(List<MenuItem> list, int depth, int maxDepth, Iterable<Category> level, Predicate<Category> selected, MenuItem parent) { if (depth > maxDepth) { return; } for (Category c : filter(level, include())) { MenuItem mi = createItem(c, selected); mi.setParent(parent); list.add(mi); add(mi.getChildren(), depth + 1, maxDepth, categories.getChildren(c.getId()), selected, mi); } }
@Override NodeQuery and() { if (getNavigationKey() == null) { return null; } final Category category = getNavigationKey().getCategory(); if (category == null) { return null; } return NodeQueries.term(Schema.CATEGORY, category.getId()); }
/** * Adds items related to a category. * * @param category * Category to add. */ protected final void add(Category category) { if (category == null || !categories.containsKey(category.getId())) { return; } final List<Category> cats = newLinkedList(); Category parent; while ((parent = categories.getParent(category.getId())) != null) { cats.add(0, category); category = parent; } for (Category c : cats) { add(c.getName().get(locale).getDisplayName(), getURI(PageKey .navigation(c))); } }
.getRoot().getId())))); final SecureRandom random = new SecureRandom();
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { final Categories categories = getCategories(); final Category root = categories.getRoot(); add(categories.getChildren(root.getId()), selected(), null); }
protected MenuItem createParentItem(Category category, Predicate<Category> selected) { if (categories == null || category == null) { return null; } final UUID id = category.getId(); if (!categories.containsKey(id)) { return null; } final Category parent = categories.getParent(id); if (parent == null || !include().apply(parent)) { return null; } final MenuItem item = createItem(parent, selected); item.setParent(createParentItem(parent, selected)); return item; }
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { final Categories categories = getCategories(); final Category root = categories.getRoot(); Iterable<Category> level = categories.getChildren(root.getId()); Category c = getCurrent(); MenuItem parent = null; final Predicate<Category> selected = selected(); if (c != null) { final UUID pk = categories.getParentKey(c.getId()); if (pk != null) { level = categories.getChildren(pk); parent = createParentItem(c, selected); } } add(level, selected, parent); } }
/** * @see com.isotrol.impe3.api.component.EditModeComponent#edit() */ public void edit() { final Category current = getCurrent(); final Predicate<Category> selected = selected(); if (current == null) { return; } final MenuItem item = createItem(current, selected); getItems().add(item); add(item.getChildren(), 0, depth(), getCategories().getChildren(current.getId()), selected, item); }