public static PropertyValue createFromSuggested(
      DesignComponent component,
      String suggestedMainName,
      Collection<String> additionalReservedNames) {
    assert component.getDocument().getTransactionManager().isAccess();
    Collection<? extends CodeNamePresenter> presenters =
        component.getPresenters(CodeNamePresenter.class);
    if (presenters.isEmpty())
      Debug.warning("CodeNamePresenter is missing for", component); // NOI18N
    HashSet<String> names = new HashSet<String>();
    gatherNames(component.getDocument().getRootComponent(), component, names);
    if (additionalReservedNames != null) names.addAll(additionalReservedNames);

    suggestedMainName = checkForJavaIdentifierCompliant(suggestedMainName);
    if (checkIfNameAlreadyReserved(presenters, suggestedMainName, names)) {
      int index = suggestedMainName.length();
      while (index >= 1 && Character.isDigit(suggestedMainName.charAt(index - 1))) index--;
      int number =
          index < suggestedMainName.length()
              ? Integer.parseInt(suggestedMainName.substring(index))
              : 1;
      suggestedMainName = suggestedMainName.substring(0, index);

      suggestedMainName = findNumberedInstanceName(presenters, suggestedMainName, number, names);
    }
    return MidpTypes.createStringValue(suggestedMainName);
  }
  private DesignComponent getCommandEvenSource(final String name) {
    final DesignComponent[] itemCommandEvenSource = new DesignComponent[1];
    if (component != null && component.get() != null) {
      final DesignComponent listComponent = component.get();
      listComponent
          .getDocument()
          .getTransactionManager()
          .writeAccess(
              new Runnable() {

                public void run() {
                  DesignComponent command = values.get(name);
                  List<PropertyValue> listESValues =
                      listComponent.readProperty(DisplayableCD.PROP_COMMANDS).getArray();
                  for (PropertyValue esValue : listESValues) {
                    DesignComponent existingES = esValue.getComponent();
                    if (existingES
                        .readProperty(CommandEventSourceCD.PROP_COMMAND)
                        .getComponent()
                        .equals(command)) {
                      itemCommandEvenSource[0] = existingES;
                      break;
                    }
                  }

                  if (itemCommandEvenSource[0] == null) {
                    // create new ItemCommandEvenSource
                    itemCommandEvenSource[0] =
                        MidpDocumentSupport.attachCommandToDisplayable(listComponent, command);
                  }
                }
              });
    }
    return itemCommandEvenSource[0];
  }
 private static void gatherNames(
     DesignComponent component, DesignComponent excludeComponent, HashSet<String> names) {
   assert component.getDocument().getTransactionManager().isAccess();
   if (component == excludeComponent) return;
   Collection<? extends CodeNamePresenter> presenters =
       component.getPresenters(CodeNamePresenter.class);
   for (CodeNamePresenter presenter : presenters) {
     List<String> reservedNames = presenter.getReservedNames();
     if (reservedNames != null) names.addAll(reservedNames);
   }
   for (DesignComponent child : component.getComponents())
     gatherNames(child, excludeComponent, names);
 }
 @Override
 public DesignComponent createComponent(DesignComponent parentComponent) {
   DesignComponent dc = parentComponent.getDocument().createComponent(getTypeID());
   if (myEventType != null) {
     DesignComponent svgES = parentComponent.getDocument().createComponent(myEventType);
     svgES.writeProperty(
         SVGComponentEventSourceCD.PROP_SVGCOMPONENT,
         PropertyValue.createComponentReference(dc));
     parentComponent.addComponent(svgES);
   }
   dc.writeProperty(SVGComponentCD.PROP_ID, MidpTypes.createStringValue(getId()));
   Map<String, Object> properties = getProperties();
   if (properties != null) {
     for (Entry<String, Object> entry : properties.entrySet()) {
       if (!entry.getKey().equals(SVGRadioButtonCD.PROP_BUTTON_GROUP)) {
         dc.writeProperty(
             entry.getKey(), MidpTypes.createStringValue(entry.getValue().toString()));
       }
     }
   }
   return dc;
 }
  private String getDecodeValue(final PropertyValue value) {
    final String[] decodeValue = new String[1];
    final DesignComponent valueComponent = value.getComponent();
    if (valueComponent != null) {
      final DesignDocument document = valueComponent.getDocument();
      if (document != null) {
        document
            .getTransactionManager()
            .readAccess(
                new Runnable() {

                  public void run() {
                    DesignComponent valueComponent = value.getComponent();
                    if (valueComponent != null) {
                      PropertyValue pv =
                          valueComponent.readProperty(CommandEventSourceCD.PROP_COMMAND);
                      if (pv != null) {
                        DesignComponent refComponent = pv.getComponent();
                        if (refComponent != null
                            && refComponent.equals(getListSelectCommand(document))) {
                          decodeValue[0] = defaultItem;
                        } else {
                          decodeValue[0] = getComponentDisplayName(valueComponent);
                        }
                      } else {
                        decodeValue[0] = noneItem;
                      }
                    } else {
                      decodeValue[0] = noneItem;
                    }
                  }
                });
      }
    }

    return decodeValue[0];
  }
  public static synchronized void parseSVGForm(
      final InputStream svgInputStream, final DesignComponent svgForm) {
    final SVGFormComponent[] srcComponents = getFormComponents(svgInputStream);
    if (srcComponents != null) {
      svgForm
          .getDocument()
          .getTransactionManager()
          .writeAccess(
              new Runnable() {

                public void run() {
                  Map<SVGFormComponent, DesignComponent> producer2Component =
                      new HashMap<SVGFormComponent, DesignComponent>();
                  for (SVGFormComponent srcComponent : srcComponents) {
                    DesignComponent svgComponent = srcComponent.createComponent(svgForm);
                    svgForm.addComponent(svgComponent);
                    producer2Component.put(srcComponent, svgComponent);
                    MidpArraySupport.append(svgForm, SVGFormCD.PROP_COMPONENTS, svgComponent);
                  }
                  initButtonGroup(producer2Component);
                }
              });
    }
  }