Example #1
0
 /**
  * Remove the node from its parent and deletes it. The default implementation obtains write access
  * to the {@link Children#MUTEX children's lock}, and removes the node from its parent(if any).
  * Also fires a property change.
  *
  * <p>This may be overridden by subclasses to do any additional cleanup.
  *
  * @exception java.io.IOException if something fails
  */
 @Override
 public void destroy() throws java.io.IOException {
   if (component.getNodeReference() == this) {
     if (MetaComponentCreator.isTransparentLayoutComponent(component.getParentComponent())) {
       component = component.getParentComponent();
     }
     if (EventQueue.isDispatchThread()) {
       component.getFormModel().removeComponent(component, true);
     } else {
       EventQueue.invokeLater(
           new Runnable() {
             @Override
             public void run() {
               component.getFormModel().removeComponent(component, true);
             }
           });
     }
   } // otherwise the component was likely already removed with a parent component
   super.destroy();
 }
Example #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;
  }