Esempio n. 1
0
  private ComponentItemImpl loadComponent(ComponentItemConfig config)
      throws ComponentCreationException {
    final ComponentItemImpl component = ComponentItemImpl.newInstance(this, config);
    try {
      component.setBehavior(
          componentRegistry.loadBehavior(config.getType(), component.getContext()));
      componentList.addItem(
          component,
          new Runnable() {
            @Override
            public void run() {
              component.addEventListener(BaseEvent.class, componentListener);
              if (counterSupport instanceof AggregatedCounterSupport)
                ((AggregatedCounterSupport) counterSupport).addChild(component);
            }
          });
    } catch (ComponentCreationException e) {
      log.error("Unable to load component: " + component, e);
      badComponents.add(config);
      component.release();
      throw e;
    }

    return component;
  }
Esempio n. 2
0
  @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;
  }