use of org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder in project kie-wb-common by kiegroup.
the class BPMNPaletteDefinitionBuilder method createPaletteCustomTasksCategory.
private void createPaletteCustomTasksCategory(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 customTasksTitle = categoryMessageProvider.getTitle(BPMNCategories.CUSTOM_TASKS);
final String customTasksDesc = categoryMessageProvider.getDescription(BPMNCategories.CUSTOM_TASKS);
final DefaultPaletteCategory workItemsCategory = new CategoryBuilder().setItemId(BPMNCategories.CUSTOM_TASKS).setTitle(customTasksTitle).setDescription(customTasksDesc).setTooltip(customTasksTitle).setGlyph(categoryGlyphProvider.apply(BPMNCategories.CUSTOM_TASKS)).build();
int i = 0;
for (final WorkItemDefinition workItemDefinition : workItemDefinitions) {
final CustomTask customTask = customTaskBuilder.apply(workItemDefinition);
final DefinitionAdapter<Object> adapter = definitionManager.adapters().registry().getDefinitionAdapter(customTask.getClass());
final String category = adapter.getCategory(customTask);
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(customTask).value();
final String title = adapter.getTitle(customTask);
final String description = adapter.getDescription(customTask);
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.DefaultPaletteDefinitionBuilders.ItemBuilder in project kie-wb-common by kiegroup.
the class ExpandedPaletteDefinitionBuilder method createItem.
@Override
protected DefaultPaletteItem createItem(final Object definition, final String categoryId, final Metadata metadata, final Function<String, DefaultPaletteItem> itemSupplier) {
final DefinitionAdapter<Object> definitionAdapter = getDefinitionManager().adapters().forDefinition();
final String id = definitionAdapter.getId(definition).value();
DefaultPaletteCategory result = null;
DefaultPaletteCategory category = (DefaultPaletteCategory) itemSupplier.apply(categoryId);
if (null == category) {
final String catDefId = categoryDefinitionIdProvider.apply(categoryId);
final String catTitle = categoryMessageProvider.getTitle(categoryId);
final String catDesc = categoryMessageProvider.getDescription(categoryId);
final Glyph categoryGlyph = categoryGlyphProvider.apply(categoryId);
category = new CategoryBuilder().setItemId(categoryId).setDefinitionId(catDefId).setTitle(catTitle).setDescription(catDesc).setTooltip(catTitle).setGlyph(categoryGlyph).build();
result = category;
}
final MorphDefinition morphDefinition = morphDefinitionProvider.apply(definition);
final boolean hasMorphBase = null != morphDefinition;
String morphDefault = null;
DefaultPaletteGroup group = null;
if (hasMorphBase) {
final String morphBaseId = morphDefinition.getBase();
if (groupFilter.test(morphBaseId)) {
morphDefault = morphDefinition.getDefault();
final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(morphBaseId)).findFirst();
if (!groupOp.isPresent()) {
final String groupTitle = groupMessageProvider.getTitle(morphBaseId);
final String groupDesc = groupMessageProvider.getDescription(morphBaseId);
group = new GroupBuilder().setItemId(morphBaseId).setDefinitionId(morphDefault).setTitle(groupTitle).setDescription(groupDesc).build();
category.getItems().add(group);
} else {
group = (DefaultPaletteGroup) groupOp.get();
}
}
} else {
// item has no morph base, but might belong to a custom group
final String customGroupId = customGroupIdProvider != null ? customGroupIdProvider.apply(id) : null;
if (customGroupId != null && groupFilter.test(customGroupId)) {
final Optional<DefaultPaletteItem> groupOp = category.getItems().stream().filter(g -> g.getId().equals(customGroupId)).findFirst();
if (!groupOp.isPresent()) {
final String groupTitle = customGroupMessageProvider.getTitle(customGroupId);
final String groupDesc = groupMessageProvider.getDescription(customGroupId);
group = new GroupBuilder().setItemId(customGroupId).setTitle(groupTitle).setDescription(groupDesc).build();
category.getItems().add(group);
} else {
group = (DefaultPaletteGroup) groupOp.get();
}
}
}
final String title = definitionAdapter.getTitle(definition);
final String description = definitionAdapter.getDescription(definition);
final DefaultPaletteItem item = new ItemBuilder().setItemId(id).setDefinitionId(id).setTitle(title).setDescription(description).build();
if (null != group) {
if (null != morphDefault && morphDefault.equals(id)) {
group.getItems().add(0, item);
} else {
group.getItems().add(item);
}
} else {
category.getItems().add(item);
}
return result;
}
use of org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder 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);
}
Aggregations