@Nonnull @Override public ComponentItem createComponent( @Nonnull String label, @Nonnull ComponentDescriptor descriptor) throws ComponentCreationException { Preconditions.checkNotNull(label, "label is null!"); Preconditions.checkNotNull(descriptor, "descriptor is null!"); ComponentItemConfig config = getConfig().addNewComponent(); config.setType(descriptor.getType()); config.setLabel(label); ComponentItemImpl component = ComponentItemImpl.newInstance(this, config); component.setAttribute(ComponentItem.TYPE, descriptor.getLabel()); if (descriptor.getHelpUrl() != null) component.getContext().setHelpUrl(descriptor.getHelpUrl()); try { component.setBehavior(componentRegistry.createBehavior(descriptor, component.getContext())); component.addEventListener(BaseEvent.class, componentListener); if (counterSupport instanceof AggregatedCounterSupport) ((AggregatedCounterSupport) counterSupport).addChild(component); componentList.addItem(component); } catch (ComponentCreationException e) { component.delete(); throw e; } return component; }
@Nonnull public CanvasObjectItem duplicate(@Nonnull CanvasObjectItem obj) { if (!(obj instanceof ComponentItemImpl)) throw new IllegalArgumentException( obj + " needs to be an instance of: " + ComponentItemImpl.class.getName()); ComponentItemConfig config = getConfig().addNewComponent(); config.set(((ComponentItemImpl) obj).getConfig()); if (obj.getCanvas().equals(this)) config.setLabel("Copy of " + config.getLabel()); config.setId(addressableRegistry.generateId()); try { return loadComponent(config); } catch (ComponentCreationException e) { // Shouldn't happen... throw new RuntimeException(e); } }