@Test public void testBind() { when(paletteDefinition.getDefinitionSetId()).thenReturn(DEFINITION_SET_ID); boolean arbitraryHidePanelValue = true; when(diagramEditorPreferences.isAutoHidePalettePanel()).thenReturn(arbitraryHidePanelValue); List<DefaultPaletteItem> items = new ArrayList<>(); items.addAll(mockCategoryItems(CATEGORY_ITEMS_COUNT)); items.addAll(mockSimpleItems(SIMPLE_ITEMS_COUNT)); items.addAll(mockCollapsedItems(COLLAPSED_ITEMS_COUNT)); when(paletteDefinition.getItems()).thenReturn(items); palette.bind(paletteDefinition); verify(categoryWidgetInstance, times(CATEGORY_ITEMS_COUNT)).get(); verify(definitionPaletteItemWidgets, times(SIMPLE_ITEMS_COUNT)).get(); verify(collapsedDefinitionPaletteItemWidgets, times(COLLAPSED_ITEMS_COUNT)).get(); assertEquals(CATEGORY_ITEMS_COUNT, createdCategoryWidgets.size()); assertEquals(SIMPLE_ITEMS_COUNT, createdItemWidgets.size()); assertEquals(COLLAPSED_ITEMS_COUNT, createdCollapsedItemWidgets.size()); List<DefaultPaletteCategory> categoryItems = items.stream() .filter(item -> (item instanceof DefaultPaletteCategory)) .map(categoryItem -> (DefaultPaletteCategory) categoryItem) .collect(Collectors.toList()); for (int i = 0; i < createdCategoryWidgets.size(); i++) { DefaultPaletteCategory category = categoryItems.get(i); DefinitionPaletteCategoryWidget widget = createdCategoryWidgets.get(i); widget.setOnOpenCallback(anyObject()); widget.setOnCloseCallback(anyObject()); verify(widget, times(1)).initialize(eq(category), eq(shapeFactory), anyObject()); verify(widget, times(1)).setAutoHidePanel(arbitraryHidePanelValue); } List<DefaultPaletteItem> paletteItems = items.stream() .filter(item -> !(item instanceof DefaultPaletteCategory) && !(item instanceof CollapsedDefaultPaletteItem)) .collect(Collectors.toList()); for (int i = 0; i < createdItemWidgets.size(); i++) { DefaultPaletteItem item = paletteItems.get(i); DefinitionPaletteItemWidget widget = createdItemWidgets.get(i); verify(widget, times(1)).initialize(eq(item), eq(shapeFactory), anyObject()); } List<CollapsedDefaultPaletteItem> collapsedPaletteItems = items.stream() .filter(item -> (item instanceof CollapsedDefaultPaletteItem)) .map(item -> (CollapsedDefaultPaletteItem) item) .collect(Collectors.toList()); for (int i = 0; i < createdCollapsedItemWidgets.size(); i++) { CollapsedDefaultPaletteItem item = collapsedPaletteItems.get(i); CollapsedDefinitionPaletteItemWidget widget = createdCollapsedItemWidgets.get(i); verify(widget, times(1)).initialize(eq(item), eq(shapeFactory), anyObject()); } }
@Override @SuppressWarnings("unchecked") protected AbstractPalette<DefaultPaletteDefinition> bind() { if (null != paletteDefinition) { final StunnerPreferences preferences = preferencesRegistries.get(paletteDefinition.getDefinitionSetId(), StunnerPreferences.class); final boolean autoHidePanel = preferences.getDiagramEditorPreferences().isAutoHidePalettePanel(); paletteDefinition.getItems().forEach(item -> { BS3PaletteWidgetPresenter widget; if (item instanceof DefaultPaletteCategory) { DefinitionPaletteCategoryWidget categoryWidget = newDefinitionPaletteCategoryWidget(); categoryWidget.setOnOpenCallback(category -> onOpenCategory(category.getId())); categoryWidget.setOnCloseCallback(category -> onCloseCategory(category.getId())); categoryWidget.setAutoHidePanel(autoHidePanel); categoryWidgets.put(item.getId(), categoryWidget); widget = categoryWidget; } else if (item instanceof CollapsedDefaultPaletteItem) { widget = newCollapsedDefinitionPaletteItemWidget(); } else { widget = newDefinitionPaletteItemWidget(); } final Consumer<PaletteItemMouseEvent> itemMouseEventHandler = event -> handleMouseDownEvent(item, event); widget.initialize(item, getShapeFactory(), itemMouseEventHandler); view.add(widget); }); } return this; }
BS3PaletteWidgetImpl extends AbstractPalette<DefaultPaletteDefinition> implements BS3PaletteWidget,
                   IsElement { @Override @SuppressWarnings("unchecked") protected AbstractPalette<DefaultPaletteDefinition> bind() { if (null != paletteDefinition) { final StunnerPreferences preferences = preferencesRegistries.get(paletteDefinition.getDefinitionSetId(), StunnerPreferences.class); final boolean autoHidePanel = preferences.getDiagramEditorPreferences().isAutoHidePalettePanel(); paletteDefinition.getItems().forEach(item -> { BS3PaletteWidgetPresenter widget; if (item instanceof DefaultPaletteCategory) { DefinitionPaletteCategoryWidget categoryWidget = newDefinitionPaletteCategoryWidget(); categoryWidget.setOnOpenCallback(category -> onOpenCategory(category.getId())); categoryWidget.setOnCloseCallback(category -> onCloseCategory(category.getId())); categoryWidget.setAutoHidePanel(autoHidePanel); categoryWidgets.put(item.getId(), categoryWidget); widget = categoryWidget; } else if (item instanceof CollapsedDefaultPaletteItem) { widget = newCollapsedDefinitionPaletteItemWidget(); } else { widget = newDefinitionPaletteItemWidget(); } final Consumer<PaletteItemMouseEvent> itemMouseEventHandler = event -> handleMouseDownEvent(item, event); widget.initialize(item, getShapeFactory(), itemMouseEventHandler); view.add(widget); }); } return this; } }
BS3PaletteWidgetImpl extends AbstractPalette<DefaultPaletteDefinition> implements BS3PaletteWidget,
                   IsElement { @Override @SuppressWarnings("unchecked") protected AbstractPalette<DefaultPaletteDefinition> bind() { if (null != paletteDefinition) { final StunnerPreferences preferences = preferencesRegistries.get(paletteDefinition.getDefinitionSetId(), StunnerPreferences.class); final boolean autoHidePanel = preferences.getDiagramEditorPreferences().isAutoHidePalettePanel(); paletteDefinition.getItems().forEach(item -> { BS3PaletteWidgetPresenter widget; if (item instanceof DefaultPaletteCategory) { DefinitionPaletteCategoryWidget categoryWidget = newDefinitionPaletteCategoryWidget(); categoryWidget.setOnOpenCallback(category -> onOpenCategory(category.getId())); categoryWidget.setOnCloseCallback(category -> onCloseCategory(category.getId())); categoryWidget.setAutoHidePanel(autoHidePanel); categoryWidgets.put(item.getId(), categoryWidget); widget = categoryWidget; } else if (item instanceof CollapsedDefaultPaletteItem) { widget = newCollapsedDefinitionPaletteItemWidget(); } else { widget = newDefinitionPaletteItemWidget(); } final Consumer<PaletteItemMouseEvent> itemMouseEventHandler = event -> handleMouseDownEvent(item, event); widget.initialize(item, getShapeFactory(), itemMouseEventHandler); view.add(widget); }); } return this; } @Inject  BS3PaletteWidgetImpl(final ShapeManager shapeManager,
                                final ClientFactoryService clientFactoryServices,
                                final BS3PaletteWidgetView view,
                                final ShapeGlyphDragHandler shapeGlyphDragHandler,
                                final StunnerPreferencesRegistries preferencesRegistries,
                                final ManagedInstance<DefinitionPaletteCategoryWidget> categoryWidgetInstance,
                                final ManagedInstance<DefinitionPaletteItemWidget> definitionPaletteItemWidgets,
                                final ManagedInstance<CollapsedDefinitionPaletteItemWidget> collapsedDefinitionPaletteItemWidgets); }
BS3PaletteWidgetImpl extends AbstractPalette<DefaultPaletteDefinition> implements BS3PaletteWidget,
                   IsElement { @Override @SuppressWarnings("unchecked") protected AbstractPalette<DefaultPaletteDefinition> bind() { if (null != paletteDefinition) { final StunnerPreferences preferences = preferencesRegistries.get(paletteDefinition.getDefinitionSetId(), StunnerPreferences.class); final boolean autoHidePanel = preferences.getDiagramEditorPreferences().isAutoHidePalettePanel(); paletteDefinition.getItems().forEach(item -> { BS3PaletteWidgetPresenter widget; if (item instanceof DefaultPaletteCategory) { DefinitionPaletteCategoryWidget categoryWidget = newDefinitionPaletteCategoryWidget(); categoryWidget.setOnOpenCallback(category -> onOpenCategory(category.getId())); categoryWidget.setOnCloseCallback(category -> onCloseCategory(category.getId())); categoryWidget.setAutoHidePanel(autoHidePanel); categoryWidgets.put(item.getId(), categoryWidget); widget = categoryWidget; } else if (item instanceof CollapsedDefaultPaletteItem) { widget = newCollapsedDefinitionPaletteItemWidget(); } else { widget = newDefinitionPaletteItemWidget(); } final Consumer<PaletteItemMouseEvent> itemMouseEventHandler = event -> handleMouseDownEvent(item, event); widget.initialize(item, getShapeFactory(), itemMouseEventHandler); view.add(widget); }); } return this; } @Inject  BS3PaletteWidgetImpl(final ShapeManager shapeManager,
                                final ClientFactoryService clientFactoryServices,
                                final BS3PaletteWidgetView view,
                                final ShapeGlyphDragHandler shapeGlyphDragHandler,
                                final StunnerPreferencesRegistries preferencesRegistries,
                                final ManagedInstance<DefinitionPaletteCategoryWidget> categoryWidgetInstance,
                                final ManagedInstance<DefinitionPaletteItemWidget> definitionPaletteItemWidgets,
                                final ManagedInstance<CollapsedDefinitionPaletteItemWidget> collapsedDefinitionPaletteItemWidgets); static int getDefaultWidth(); @PostConstruct void init(); @Override BS3PaletteWidget onItemDrop(final Consumer<PaletteIDefinitionItemEvent> callback); @Override BS3PaletteWidget onItemDragStart(final Consumer<PaletteIDefinitionItemEvent> callback); @Override BS3PaletteWidget onItemDragUpdate(final Consumer<PaletteIDefinitionItemEvent> callback); @SuppressWarnings("unchecked") void onDragStart(final String definitionId,
                            final double x,
                            final double y); @Override void onDragProxyMove(String definitionId,
                                double x,
                                double y); void unbind(); @Override void setVisible(final boolean visible); @Override void onScreenMaximized(final ScreenMaximizedEvent event); @Override void onScreenMinimized(final ScreenMinimizedEvent event); double getIconSize(); @Override @SuppressWarnings("unchecked") void onDragProxyComplete(final String definitionId,
                                    final double x,
                                    final double y); @Override Glyph getShapeGlyph(final String definitionId); @Override Glyph getShapeDragProxyGlyph(final String definitionId); @Override HTMLElement getElement(); }
BS3PaletteWidgetImpl extends AbstractPalette<DefaultPaletteDefinition> implements BS3PaletteWidget,
                   IsElement { @Override @SuppressWarnings("unchecked") protected AbstractPalette<DefaultPaletteDefinition> bind() { if (null != paletteDefinition) { final StunnerPreferences preferences = preferencesRegistries.get(paletteDefinition.getDefinitionSetId(), StunnerPreferences.class); final boolean autoHidePanel = preferences.getDiagramEditorPreferences().isAutoHidePalettePanel(); paletteDefinition.getItems().forEach(item -> { BS3PaletteWidgetPresenter widget; if (item instanceof DefaultPaletteCategory) { DefinitionPaletteCategoryWidget categoryWidget = newDefinitionPaletteCategoryWidget(); categoryWidget.setOnOpenCallback(category -> onOpenCategory(category.getId())); categoryWidget.setOnCloseCallback(category -> onCloseCategory(category.getId())); categoryWidget.setAutoHidePanel(autoHidePanel); categoryWidgets.put(item.getId(), categoryWidget); widget = categoryWidget; } else if (item instanceof CollapsedDefaultPaletteItem) { widget = newCollapsedDefinitionPaletteItemWidget(); } else { widget = newDefinitionPaletteItemWidget(); } final Consumer<PaletteItemMouseEvent> itemMouseEventHandler = event -> handleMouseDownEvent(item, event); widget.initialize(item, getShapeFactory(), itemMouseEventHandler); view.add(widget); }); } return this; } @Inject  BS3PaletteWidgetImpl(final ShapeManager shapeManager,
                                final ClientFactoryService clientFactoryServices,
                                final BS3PaletteWidgetView view,
                                final ShapeGlyphDragHandler shapeGlyphDragHandler,
                                final StunnerPreferencesRegistries preferencesRegistries,
                                final ManagedInstance<DefinitionPaletteCategoryWidget> categoryWidgetInstance,
                                final ManagedInstance<DefinitionPaletteItemWidget> definitionPaletteItemWidgets,
                                final ManagedInstance<CollapsedDefinitionPaletteItemWidget> collapsedDefinitionPaletteItemWidgets); static int getDefaultWidth(); @PostConstruct void init(); @Override BS3PaletteWidget onItemDrop(final Consumer<PaletteIDefinitionItemEvent> callback); @Override BS3PaletteWidget onItemDragStart(final Consumer<PaletteIDefinitionItemEvent> callback); @Override BS3PaletteWidget onItemDragUpdate(final Consumer<PaletteIDefinitionItemEvent> callback); @SuppressWarnings("unchecked") void onDragStart(final String definitionId,
                            final double x,
                            final double y); @Override void onDragProxyMove(String definitionId,
                                double x,
                                double y); void unbind(); @Override void setVisible(final boolean visible); @Override void onScreenMaximized(final ScreenMaximizedEvent event); @Override void onScreenMinimized(final ScreenMinimizedEvent event); double getIconSize(); @Override @SuppressWarnings("unchecked") void onDragProxyComplete(final String definitionId,
                                    final double x,
                                    final double y); @Override Glyph getShapeGlyph(final String definitionId); @Override Glyph getShapeDragProxyGlyph(final String definitionId); @Override HTMLElement getElement();  }