use of org.kie.workbench.common.stunner.core.definition.shape.Glyph 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);
DefaultPaletteCategory result = null;
DefaultPaletteCategory category = (DefaultPaletteCategory) itemSupplier.apply(categoryId);
if (null == category) {
final int catPriority = getItemPriority(categoryId);
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().setPriority(catPriority).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 int groupPriority = getItemPriority(morphBaseId);
final String groupTitle = groupMessageProvider.getTitle(morphBaseId);
final String groupDesc = groupMessageProvider.getDescription(morphBaseId);
group = new GroupBuilder().setPriority(groupPriority).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 int groupPriority = getItemPriority(customGroupId);
final String groupTitle = customGroupMessageProvider.getTitle(customGroupId);
final String groupDesc = groupMessageProvider.getDescription(customGroupId);
group = new GroupBuilder().setPriority(groupPriority).setItemId(customGroupId).setTitle(groupTitle).setDescription(groupDesc).build();
category.getItems().add(group);
} else {
group = (DefaultPaletteGroup) groupOp.get();
}
}
}
final int itemPriority = getItemPriority(id);
final String title = definitionAdapter.getTitle(definition);
final String description = definitionAdapter.getDescription(definition);
final DefaultPaletteItem item = new ItemBuilder().setPriority(itemPriority).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.definition.shape.Glyph in project kie-wb-common by kiegroup.
the class DefinitionPaletteCategoryWidget method initialize.
@Override
public void initialize(final DefaultPaletteCategory category, final ShapeFactory<?, ?> shapeFactory, final Consumer<PaletteItemMouseEvent> itemMouseDownCallback) {
this.category = category;
this.itemMouseDownCallback = itemMouseDownCallback;
final Glyph categoryGlyph = category.getGlyph();
view.render(categoryGlyph, category.getIconSize(), category.getIconSize());
renderItems(category.getItems(), shapeFactory);
}
use of org.kie.workbench.common.stunner.core.definition.shape.Glyph in project kie-wb-common by kiegroup.
the class DefinitionPaletteItemWidget method initialize.
@Override
public void initialize(DefaultPaletteItem item, ShapeFactory<?, ?> shapeFactory, Consumer<PaletteItemMouseEvent> itemMouseDownCallback) {
this.item = item;
final Glyph glyph = shapeFactory.getGlyph(item.getDefinitionId());
this.itemMouseDownCallback = itemMouseDownCallback;
view.render(glyph, item.getIconSize(), item.getIconSize());
}
use of org.kie.workbench.common.stunner.core.definition.shape.Glyph in project kie-wb-common by kiegroup.
the class TreeExplorer method addItem.
@SuppressWarnings("unchecked")
private void addItem(final Element parent, final Node element, final boolean expand, final boolean checkParent) {
final boolean isContainer = isContainer().test(element);
final Glyph glyph = getGlyph(getShapeSetId(), element);
final String name = getItemName(element);
final IsElement icon = domGlyphRenderers.render(glyph, icoWidth, icoHeight);
// Check the parent, in case a TreeItem mutates from/to ITEM type to CONTAINER type.
final boolean isValidParentItem = null != parent && isValidTreeItem().test(parent);
if (checkParent && isValidParentItem) {
final boolean isParentContainer = isContainer().test((Node) parent);
final boolean wasParentContainer = view.isContainer(parent.getUUID());
if (isParentContainer != wasParentContainer) {
view.removeItem(parent.getUUID());
addItem(GraphUtils.getParent((Node<?, ? extends Edge>) parent), (Node) parent, expand, false);
}
}
final ElementWrapperWidget<?> widget = wrapIconElement(icon);
// Create and add the tree item.
if (isValidParentItem) {
view.addItem(element.getUUID(), parent.getUUID(), name, widget, isContainer, expand);
} else {
view.addItem(element.getUUID(), name, widget, isContainer, expand);
}
}
use of org.kie.workbench.common.stunner.core.definition.shape.Glyph in project kie-wb-common by kiegroup.
the class CaseManagementShapeFactoryTest method assertShapeGlyph.
@SuppressWarnings("unchecked")
private void assertShapeGlyph(final BPMNDefinition definition) {
final String id = BindableAdapterUtils.getDefinitionId(definition.getClass());
final Glyph glyph = factory.getGlyph(id);
verify(delegate, times(1)).getGlyph(eq(id));
assertEquals(this.glyph, glyph);
}
Aggregations