use of org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem in project kie-wb-common by kiegroup.
the class BPMNPaletteDefinitionBuilder method createPaletteServiceTasksCategory.
private void createPaletteServiceTasksCategory(final DefaultPaletteDefinition paletteDefinition, final Consumer<DefaultPaletteDefinition> callback) {
final ExpandedPaletteDefinitionBuilder.ItemMessageProvider categoryMessageProvider = paletteDefinitionBuilder.getCategoryMessageProvider();
final Function<String, Glyph> categoryGlyphProvider = paletteDefinitionBuilder.getCategoryGlyphProvider();
final Collection<WorkItemDefinition> workItemDefinitions = workItemDefinitionRegistry.get().items();
if (!workItemDefinitions.isEmpty()) {
final String serviceTasksTitle = categoryMessageProvider.getTitle(BPMNCategories.SERVICE_TASKS);
final String serviceTasksDesc = categoryMessageProvider.getDescription(BPMNCategories.SERVICE_TASKS);
final DefaultPaletteCategory workItemsCategory = new CategoryBuilder().setItemId(BPMNCategories.SERVICE_TASKS).setTitle(serviceTasksTitle).setDescription(serviceTasksDesc).setTooltip(serviceTasksTitle).setGlyph(categoryGlyphProvider.apply(BPMNCategories.SERVICE_TASKS)).build();
int i = 0;
for (final WorkItemDefinition workItemDefinition : workItemDefinitions) {
final ServiceTask serviceTask = serviceTaskBuilder.apply(workItemDefinition);
final DefinitionAdapter<Object> adapter = definitionManager.adapters().registry().getDefinitionAdapter(serviceTask.getClass());
final String category = adapter.getCategory(serviceTask);
DefaultPaletteGroup subcategoryGroup = null;
final Optional<DefaultPaletteItem> subcategoryGroupOp = workItemsCategory.getItems().stream().filter(item -> category.equals(item.getId())).findFirst();
if (!subcategoryGroupOp.isPresent()) {
subcategoryGroup = new GroupBuilder().setItemId(category).setTitle(category).setDescription(category).build();
workItemsCategory.getItems().add(subcategoryGroup);
} else {
subcategoryGroup = (DefaultPaletteGroup) subcategoryGroupOp.get();
}
final String defId = adapter.getId(serviceTask);
final String title = adapter.getTitle(serviceTask);
final String description = adapter.getDescription(serviceTask);
final DefaultPaletteItem item = new ItemBuilder().setItemId(defId).setDefinitionId(defId).setTitle(title).setDescription(description).build();
subcategoryGroup.getItems().add(item);
// Link the first work item definition found to the work item's palette category.
if (0 == i) {
workItemsCategory.setDefinitionId(defId);
}
i++;
}
paletteDefinition.getItems().add(workItemsCategory);
}
callback.accept(paletteDefinition);
}
use of org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem in project kie-wb-common by kiegroup.
the class DefinitionPaletteGroupWidget method loadItems.
private void loadItems(ShapeFactory<?, ?> shapeFactory) {
view.initView();
definitionPaletteItemWidgets.destroyAll();
List<DefaultPaletteItem> items = group.getItems();
for (int i = 0; i < items.size(); i++) {
DefaultPaletteItem item = items.get(i);
DefinitionPaletteItemWidget itemWidget = definitionPaletteItemWidgets.get();
itemWidget.initialize(item, shapeFactory, itemMouseDownCallback);
if (i >= COMPACT_ELEMENTS_LIST_SIZE) {
itemWidget.getElement().getStyle().setProperty("display", "none");
hiddenList.add(itemWidget);
}
view.addItem(itemWidget);
}
if (!hiddenList.isEmpty()) {
view.addAnchors();
view.showMoreAnchor();
}
}
Aggregations