All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fluximpl.HttpFileTransferActionImplBeanInfo Maven / Gradle / Ivy

The newest version!
package fluximpl;

import java.awt.*;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.util.Arrays;
import java.util.ResourceBundle;
import java.util.Vector;

/**
 * BeanInfo for HttpFileTransferAction.
 *
 * @author [email protected]
 */
public class HttpFileTransferActionImplBeanInfo extends ActionImplBeanInfo {
  /**
   * A small image for this custom action to be displayed in the Flux GUI.
   */
  private Image smallImage;

  /**
   * A large image for this custom action to be displayed in the Flux GUI.
   */
  private Image bigImage;

  protected BeanDescriptor bd = new BeanDescriptor(HttpFileTransferActionImpl.class);

  public HttpFileTransferActionImplBeanInfo(BeanDescriptor bd) {
    super();
    this.bd = bd;
    setCategory(bd, ActionImplBeanInfo.FILE);
  }

  public HttpFileTransferActionImplBeanInfo() {
    super();
    bd.setDisplayName("HTTP File Transfer Action");
    bd.setShortDescription("Performs HTTP File Transfer.");
    setCategory(bd, ActionImplBeanInfo.FILE);
  }


  public Image getIcon(int type) {
    if (type == BeanInfo.ICON_COLOR_16x16) {
      return getSmallImage();
    } // if
    if (type == BeanInfo.ICON_COLOR_32x32) {
      return getBigImage();
    } // if
    return null;
  } // getIcon()

  /**
   * Returns a small image that represents this JavaBean.
   *
   * @return A small image that represents this JavaBean.
   */
  private Image getSmallImage() {
    if (smallImage == null) {
      smallImage = loadImage("/HttpFileTransferActionImpl_small.png");
    } // if
    return smallImage;
  } // getSmallImage()

  /**
   * Returns a large image that represents this JavaBean.
   *
   * @return A large image that represents this JavaBean.
   */
  private Image getBigImage() {
    if (bigImage == null) {
      bigImage = loadImage("/HttpFileTransferActionImpl_big.png");
    } // if
    return bigImage;
  } // getBigImage()


  public BeanDescriptor getBeanDescriptor() {
    return bd;
  }

  public PropertyDescriptor[] getPropertyDescriptors() {
    Vector descriptors = new Vector(Arrays.asList(super.getPropertyDescriptors()));
    try {
      int order = 10;
      descriptors.add(makePropertyDescriptor("source", "Source File", HttpFileTransferActionImpl.class.getName(), "getSource", true, null, order++, false, false, false, false));
      descriptors.add(makePropertyDescriptor("destination", "Destination File", HttpFileTransferActionImpl.class.getName(), "getDestination", true, null, order++, false, false, false, false));
    } catch (Exception e) {
      e.printStackTrace();
      throw new IllegalStateException("Could not create property descriptor.");
    } // catch

    return descriptors.toArray(new PropertyDescriptor[descriptors.size()]);
  }

  public PropertyDescriptor makePropertyDescriptor(String propertyName, String displayName, String className, String readMethod, boolean required, String propertyEditor, int order, boolean preferred, boolean common, boolean indexed, boolean password) throws IntrospectionException, ClassNotFoundException {
    PropertyDescriptor descriptor;
    try {
      descriptor = new PropertyDescriptor(propertyName, getClazz(className));
    }
    catch (IntrospectionException e) {
      descriptor = new PropertyDescriptor(propertyName, getClazz(className), readMethod, null);
    }

    return makePropertyDescriptor(displayName, required, propertyEditor, order, preferred, common, descriptor, password);
  }

  public PropertyDescriptor makePropertyDescriptor(String displayName, boolean required, String propertyEditor, int order, boolean preferred, boolean common, PropertyDescriptor descriptor, boolean password) throws ClassNotFoundException {
    descriptor.setDisplayName(displayName);
    descriptor.setValue("required", required);
    descriptor.setValue("common", common);
    descriptor.setValue("password", password);
    descriptor.setPreferred(preferred);
    String description = findPropertyDescription(this.getBeanDescriptor().getBeanClass(), descriptor.getName(), resourceBundle);
    if (description != null) {
      descriptor.setShortDescription(description);
    }
    descriptor.setHidden(false);
    if (propertyEditor != null) {
      descriptor.setPropertyEditorClass(getClazz(propertyEditor));
    }
    if (order != 0) {
      descriptor.setValue("order", new Integer(order));
    }
    return descriptor;
  }

  private String findPropertyDescription(Class beanClass, String propertyName, ResourceBundle resourceBundle) {
    String description = null;
    try {
      String className = beanClass.toString().replaceFirst("^class ", "");
      String descPropertyName = className + "." + propertyName;
      description = resourceBundle.getString(descPropertyName);
    } catch (Exception e) {
      Class superClass = beanClass.getSuperclass();
      if (superClass != null) {
        return findPropertyDescription(superClass, propertyName, resourceBundle);
      } else {
        return null;
      }
    }
    return description;
  }

  public Class getClazz(String className) throws ClassNotFoundException {
    try {
      return Class.forName(className);
    }
    catch (ClassNotFoundException e) {
      Thread t = Thread.currentThread();
      ClassLoader cl = t.getContextClassLoader();
      return cl.loadClass(className);
    }
  }

  public void setCategory(BeanDescriptor beanDescriptor, String category) {
    beanDescriptor.setValue("category", category);
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy