SetPropertyActionController.java :  » Workflow-Engines » osbl-1_0 » org » osbl » agent » gui » action » Java Open Source

Java Open Source » Workflow Engines » osbl 1_0 
osbl 1_0 » org » osbl » agent » gui » action » SetPropertyActionController.java
package org.osbl.agent.gui.action;

import java.util.List;

import org.conform.BeanMeta;
import org.conform.PropertyMeta;
import org.osbl.agent.gui.ActionController;
import org.osbl.agent.gui.OperationController;
import org.osbl.agent.model.Action;
import org.osbl.agent.model.action.SetPropertyAction;
import org.osbl.client.wings.shell.Client;
import org.wings.SComponent;
import org.wings.SLabel;



/**
 * The class SetPropertyActionController models a SetPropertyAction.
 * 
 * Depending on the type of the property, it presents different ways to enter 
 * the value to assign.
 * 
 * This is implemented by the subclasses.
 * 
 * @author Sebastian Nozzi.
 */
public abstract class SetPropertyActionController extends ActionController {

  /** The property meta information. */
  private PropertyMeta propertyMeta;

  /* (non-Javadoc)
   * @see org.osbl.agent.gui.ActionController#setAction(org.osbl.agent.model.Action)
   */
  public void setAction(Action action) {

    String className = ((SetPropertyAction) action).getBeanMetaClassName();
    String propertyName = ((SetPropertyAction) action).getPropertyMetaName();

    try {
      BeanMeta beanMeta = Client.getInstance().getBeanMetaProvider().getBeanMeta(Class.forName(className));
      setPropertyMeta(beanMeta.getProperty(propertyName));
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }

  /* (non-Javadoc)
   * @see org.osbl.agent.gui.OperationController#canBeReplacedBy(org.osbl.agent.gui.OperationController)
   */
  public boolean canBeReplacedBy(OperationController candidateController) {

    // We can be replaced only by another SetPropertyActionController 
    // that also changes the same property as we do.
    if (candidateController instanceof SetPropertyActionController)
      return ((SetPropertyActionController) candidateController).propertyMeta
          .equals(this.propertyMeta);
    else
      return false;
  }

  /* (non-Javadoc)
   * @see org.osbl.agent.gui.OperationController#populateComponentList(java.util.List)
   */
  protected void populateComponentList(List<SComponent> componentList) {

    // A label to show that the property will be set to some value.
    componentList.add(new SLabel(msg("setTo")));

  }

  /**
   * Gets the property meta.
   * 
   * @return the property meta
   */
  public PropertyMeta getPropertyMeta() {
    return propertyMeta;
  }

  /**
   * Sets the property meta.
   * 
   * @param propertyMeta the new property meta
   */
  public void setPropertyMeta(PropertyMeta propertyMeta) {
    this.propertyMeta = propertyMeta;
  }

  /* (non-Javadoc)
   * @see java.lang.Object#toString()
   */
  public String toString() {
    // Our string version is the property we want to change, indented.
    return "  " + propertyMeta.getLabel() +"   ("+propertyMeta.getName()+")";
  }
  
  /* (non-Javadoc)
   * @see org.osbl.agent.gui.ActionController#populateAction(org.osbl.agent.model.Action)
   */
  protected void populateAction(Action action) {
    
    // Set the propertyMeta of the SetCurrentTimeAction to whatever propertyMeta
    // the user chose in the UI.
    ((SetPropertyAction) action).setBeanMetaClassName(propertyMeta.getBeanMeta().getName());
    ((SetPropertyAction) action).setPropertyMetaName(propertyMeta.getName());
    
  }


}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.