コード例 #1
0
ファイル: CanvasItemImpl.java プロジェクト: umaxfun/loadui
  @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;
  }