Search in sources :

Example 1 with ItemBuilder

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);
}
Also used : DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CustomTask(org.kie.workbench.common.stunner.bpmn.workitem.CustomTask) Map(java.util.Map) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) CategoryDefinitionProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.CategoryDefinitionProvider) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Lists(org.kie.soup.commons.util.Lists) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Objects(java.util.Objects) DefaultPaletteDefinitionProviders.isType(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.isType) BPMN(org.kie.workbench.common.stunner.bpmn.qualifiers.BPMN) List(java.util.List) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) DefaultPaletteDefinition(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) Maps(org.kie.soup.commons.util.Maps) Function(java.util.function.Function) Supplier(java.util.function.Supplier) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Inject(javax.inject.Inject) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) PaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.PaletteDefinitionBuilder) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) MorphAdapter(org.kie.workbench.common.stunner.core.definition.adapter.MorphAdapter) DefaultPaletteDefinitionProviders(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders) CustomTaskFactory(org.kie.workbench.common.stunner.bpmn.workitem.CustomTaskFactory) Association(org.kie.workbench.common.stunner.bpmn.definition.Association) BaseSubprocess(org.kie.workbench.common.stunner.bpmn.definition.BaseSubprocess) Consumer(java.util.function.Consumer) BPMNCategories(org.kie.workbench.common.stunner.bpmn.definition.BPMNCategories) Dependent(javax.enterprise.context.Dependent) WorkItemDefinitionRegistry(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry) Comparator(java.util.Comparator) Collections(java.util.Collections) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) CustomTask(org.kie.workbench.common.stunner.bpmn.workitem.CustomTask)

Example 2 with ItemBuilder

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;
}
Also used : Default(javax.enterprise.inject.Default) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) DefinitionsCacheRegistry(org.kie.workbench.common.stunner.core.registry.impl.DefinitionsCacheRegistry) Predicate(java.util.function.Predicate) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) DomainProfileManager(org.kie.workbench.common.stunner.core.profile.DomainProfileManager) Function(java.util.function.Function) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Inject(javax.inject.Inject) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) DefaultMorphGroupMessageProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.DefaultMorphGroupMessageProvider) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) Dependent(javax.enterprise.context.Dependent) Optional(java.util.Optional) DefaultMessageProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.DefaultMessageProvider) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph)

Example 3 with ItemBuilder

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);
}
Also used : StartNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.StartNoneEvent) DefaultPaletteDefinition(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinition) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) SequenceFlow(org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) BPMNImageResources(org.kie.workbench.common.stunner.bpmn.client.resources.BPMNImageResources) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) HashMap(java.util.HashMap) ParallelGateway(org.kie.workbench.common.stunner.bpmn.definition.ParallelGateway) Function(java.util.function.Function) Supplier(java.util.function.Supplier) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) Inject(javax.inject.Inject) DefinitionAdapter(org.kie.workbench.common.stunner.core.definition.adapter.DefinitionAdapter) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph) Map(java.util.Map) Lane(org.kie.workbench.common.stunner.bpmn.definition.Lane) ReusableSubprocess(org.kie.workbench.common.stunner.bpmn.definition.ReusableSubprocess) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) CategoryDefinitionProvider(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.CategoryDefinitionProvider) Builder(org.kie.workbench.common.stunner.core.client.shape.SvgDataUriGlyph.Builder) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ServiceTaskFactory(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTaskFactory) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) StunnerTranslationService(org.kie.workbench.common.stunner.core.i18n.StunnerTranslationService) PaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.PaletteDefinitionBuilder) Predicate(java.util.function.Predicate) Collection(java.util.Collection) BPMNDiagramImpl(org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) DefaultPaletteDefinitionProviders(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders) Consumer(java.util.function.Consumer) BPMNCategories(org.kie.workbench.common.stunner.bpmn.definition.BPMNCategories) DefaultPaletteDefinitionProviders.isType(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionProviders.isType) BPMN(org.kie.workbench.common.stunner.bpmn.qualifiers.BPMN) AbstractPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.AbstractPaletteDefinitionBuilder) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) IntermediateTimerEvent(org.kie.workbench.common.stunner.bpmn.definition.IntermediateTimerEvent) WorkItemDefinitionRegistry(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinitionRegistry) ApplicationScoped(javax.enterprise.context.ApplicationScoped) NoneTask(org.kie.workbench.common.stunner.bpmn.definition.NoneTask) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) EndNoneEvent(org.kie.workbench.common.stunner.bpmn.definition.EndNoneEvent) ServiceTask(org.kie.workbench.common.stunner.bpmn.workitem.ServiceTask) WorkItemDefinition(org.kie.workbench.common.stunner.bpmn.workitem.WorkItemDefinition) GroupBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder) ExpandedPaletteDefinitionBuilder(org.kie.workbench.common.stunner.core.client.components.palette.ExpandedPaletteDefinitionBuilder) DefaultPaletteCategory(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteCategory) DefaultPaletteItem(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteItem) DefaultPaletteGroup(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteGroup) ItemBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder) CategoryBuilder(org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder) Glyph(org.kie.workbench.common.stunner.core.definition.shape.Glyph)

Aggregations

Optional (java.util.Optional)3 Function (java.util.function.Function)3 Predicate (java.util.function.Predicate)3 Inject (javax.inject.Inject)3 CategoryBuilder (org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.CategoryBuilder)3 GroupBuilder (org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.GroupBuilder)3 ItemBuilder (org.kie.workbench.common.stunner.core.client.components.palette.DefaultPaletteDefinitionBuilders.ItemBuilder)3 Collection (java.util.Collection)2 Map (java.util.Map)2 Consumer (java.util.function.Consumer)2 Supplier (java.util.function.Supplier)2 PostConstruct (javax.annotation.PostConstruct)2 Dependent (javax.enterprise.context.Dependent)2 ManagedInstance (org.jboss.errai.ioc.client.api.ManagedInstance)2 BPMNCategories (org.kie.workbench.common.stunner.bpmn.definition.BPMNCategories)2 BPMNDiagramImpl (org.kie.workbench.common.stunner.bpmn.definition.BPMNDiagramImpl)2 Lane (org.kie.workbench.common.stunner.bpmn.definition.Lane)2 NoneTask (org.kie.workbench.common.stunner.bpmn.definition.NoneTask)2 SequenceFlow (org.kie.workbench.common.stunner.bpmn.definition.SequenceFlow)2 BPMN (org.kie.workbench.common.stunner.bpmn.qualifiers.BPMN)2