public <T> T getCustomizer(Class<T> type) {
   for (Customizer c : _customizers) if (type.isAssignableFrom(c.getClass())) return (T) c;
   return null;
 }
Esempio n. 2
0
  /**
   * Creates the customizer component for the node.
   *
   * @return the component, or null if there is no customizer
   */
  @Override
  protected Component createCustomizer() {
    Class customizerClass = component.getBeanInfo().getBeanDescriptor().getCustomizerClass();
    if (customizerClass == null) {
      if (javax.swing.JTable.class.isAssignableFrom(component.getBeanClass())) {
        customizerClass = TableCustomizer.class;
      } else {
        return null;
      }
    }

    Object customizerObject;
    try {
      customizerObject = customizerClass.newInstance();
    } catch (InstantiationException e) {
      ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
      return null;
    } catch (IllegalAccessException e) {
      ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
      return null;
    }

    if (!(customizerObject instanceof Component) || !(customizerObject instanceof Customizer))
      return null;

    if (customizerObject instanceof NodeCustomizer)
      ((NodeCustomizer) customizerObject).attach(component.getNodeReference());

    // Issue 203352 - default values of properties must be initialized
    // before the customizer is shown/used
    component.ensureDefaultPropertyValuesInitialization();

    Customizer customizer = (Customizer) customizerObject;

    customizer.setObject(component.getBeanInstance());

    if (customizerObject instanceof FormAwareEditor) {
      // Hack - returns some property
      Node.Property prop = component.getProperties()[0].getProperties()[0];
      ((FormAwareEditor) customizerObject)
          .setContext(component.getFormModel(), (FormProperty) prop);
    }

    customizer.addPropertyChangeListener(
        new PropertyChangeListener() {
          @Override
          public void propertyChange(PropertyChangeEvent evt) {
            FormProperty[] properties;
            if (evt.getPropertyName() != null) {
              FormProperty changedProperty = component.getBeanProperty(evt.getPropertyName());
              if (changedProperty != null) properties = new FormProperty[] {changedProperty};
              else return; // non-existing property?
            } else {
              properties = component.getAllBeanProperties();
              evt = null;
            }
            updatePropertiesFromCustomizer(properties, evt);
          }
        });
    // [undo/redo for customizer probably does not work...]

    return (Component) customizerObject;
  }