Пример #1
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;
  }
Пример #2
0
  public ComponentItem injectComponent(ComponentItemConfig config)
      throws ComponentCreationException {
    ComponentItemConfig componentConf = getConfig().addNewComponent();
    componentConf.set(config);
    try {
      return loadComponent(componentConf);
    } catch (ComponentCreationException e) {
      getConfig().removeComponent(getConfig().sizeOfComponentArray() - 1);

      throw e;
    }
  }
Пример #3
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;
  }
Пример #4
0
  @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);
    }
  }