@Test public void testCrateItemAndAppendIntoCategory() { when(itemSupplier.apply(eq(CAT_ID))).thenReturn(SOME_CATEGORY); DefaultPaletteItem category = tested.createItem(definition1, CAT_ID, metadata, itemSupplier); assertNull(category); assertFalse(SOME_CATEGORY.getItems().isEmpty()); DefaultPaletteItem item = SOME_CATEGORY.getItems().iterator().next(); assertNotNull(item); assertEquals(DEF1_ID, item.getId()); assertEquals(DEF1_ID, item.getDefinitionId()); assertEquals(DEF1_TITLE, item.getTitle()); assertEquals(DEF1_DESC, item.getDescription()); assertEquals(DefaultPaletteDefinitionBuilders.DEFAULT_ICON_SIZE, item.getIconSize()); assertTrue(null == item.getTooltip() || item.getTooltip().trim().length() == 0); }
@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 { 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; }
ExpandedPaletteDefinitionBuilder extends AbstractPaletteDefinitionBuilder<ExpandedPaletteDefinitionBuilder> { @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 { 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; } }
ExpandedPaletteDefinitionBuilder extends AbstractPaletteDefinitionBuilder<ExpandedPaletteDefinitionBuilder> { @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 { 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; } @Inject  ExpandedPaletteDefinitionBuilder(final DefinitionUtils definitionUtils,
                                            final DomainProfileManager profileManager,
                                            final DefinitionsCacheRegistry definitionsRegistry,
                                            final StunnerTranslationService translationService); }
ExpandedPaletteDefinitionBuilder extends AbstractPaletteDefinitionBuilder<ExpandedPaletteDefinitionBuilder> { @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 { 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; } @Inject  ExpandedPaletteDefinitionBuilder(final DefinitionUtils definitionUtils,
                                            final DomainProfileManager profileManager,
                                            final DefinitionsCacheRegistry definitionsRegistry,
                                            final StunnerTranslationService translationService); ExpandedPaletteDefinitionBuilder categoryDefinitionIdProvider(final Function<String, String> categoryDefinitionIdProvider); ExpandedPaletteDefinitionBuilder morphDefinitionProvider(final Function<Object, MorphDefinition> morphDefinitionProvider); ExpandedPaletteDefinitionBuilder groupFilter(final Predicate<String> groupFilter); ExpandedPaletteDefinitionBuilder categoryGlyphProvider(final Function<String, Glyph> categoryGlyphProvider); ExpandedPaletteDefinitionBuilder groupMessages(final ItemMessageProvider provider); ExpandedPaletteDefinitionBuilder categoryMessages(final ItemMessageProvider provider); ExpandedPaletteDefinitionBuilder customGroupIdProvider(final Function<String, String> customGroupIdProvider); ExpandedPaletteDefinitionBuilder customGroupMessages(final ItemMessageProvider provider); Function<Object, MorphDefinition> getMorphDefinitionProvider(); Predicate<String> getGroupFilter(); ItemMessageProvider getCategoryMessageProvider(); ItemMessageProvider getGroupMessageProvider(); Function<String, Glyph> getCategoryGlyphProvider(); Function<String, String> getCategoryDefinitionIdProvider(); }
ExpandedPaletteDefinitionBuilder extends AbstractPaletteDefinitionBuilder<ExpandedPaletteDefinitionBuilder> { @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 { 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; } @Inject  ExpandedPaletteDefinitionBuilder(final DefinitionUtils definitionUtils,
                                            final DomainProfileManager profileManager,
                                            final DefinitionsCacheRegistry definitionsRegistry,
                                            final StunnerTranslationService translationService); ExpandedPaletteDefinitionBuilder categoryDefinitionIdProvider(final Function<String, String> categoryDefinitionIdProvider); ExpandedPaletteDefinitionBuilder morphDefinitionProvider(final Function<Object, MorphDefinition> morphDefinitionProvider); ExpandedPaletteDefinitionBuilder groupFilter(final Predicate<String> groupFilter); ExpandedPaletteDefinitionBuilder categoryGlyphProvider(final Function<String, Glyph> categoryGlyphProvider); ExpandedPaletteDefinitionBuilder groupMessages(final ItemMessageProvider provider); ExpandedPaletteDefinitionBuilder categoryMessages(final ItemMessageProvider provider); ExpandedPaletteDefinitionBuilder customGroupIdProvider(final Function<String, String> customGroupIdProvider); ExpandedPaletteDefinitionBuilder customGroupMessages(final ItemMessageProvider provider); Function<Object, MorphDefinition> getMorphDefinitionProvider(); Predicate<String> getGroupFilter(); ItemMessageProvider getCategoryMessageProvider(); ItemMessageProvider getGroupMessageProvider(); Function<String, Glyph> getCategoryGlyphProvider(); Function<String, String> getCategoryDefinitionIdProvider();  }