001: package org.osbl.agent.gui.action;
002:
003: import java.util.List;
004:
005: import org.conform.BeanMeta;
006: import org.conform.PropertyMeta;
007: import org.osbl.agent.gui.ActionController;
008: import org.osbl.agent.gui.OperationController;
009: import org.osbl.agent.model.Action;
010: import org.osbl.agent.model.action.SetPropertyAction;
011: import org.osbl.client.wings.shell.Client;
012: import org.wings.SComponent;
013: import org.wings.SLabel;
014:
015: /**
016: * The class SetPropertyActionController models a SetPropertyAction.
017: *
018: * Depending on the type of the property, it presents different ways to enter
019: * the value to assign.
020: *
021: * This is implemented by the subclasses.
022: *
023: * @author Sebastian Nozzi.
024: */
025: public abstract class SetPropertyActionController extends
026: ActionController {
027:
028: /** The property meta information. */
029: private PropertyMeta propertyMeta;
030:
031: /* (non-Javadoc)
032: * @see org.osbl.agent.gui.ActionController#setAction(org.osbl.agent.model.Action)
033: */
034: public void setAction(Action action) {
035:
036: String className = ((SetPropertyAction) action)
037: .getBeanMetaClassName();
038: String propertyName = ((SetPropertyAction) action)
039: .getPropertyMetaName();
040:
041: try {
042: BeanMeta beanMeta = Client.getInstance()
043: .getBeanMetaProvider().getBeanMeta(
044: Class.forName(className));
045: setPropertyMeta(beanMeta.getProperty(propertyName));
046: } catch (ClassNotFoundException e) {
047: // TODO Auto-generated catch block
048: e.printStackTrace();
049: }
050: }
051:
052: /* (non-Javadoc)
053: * @see org.osbl.agent.gui.OperationController#canBeReplacedBy(org.osbl.agent.gui.OperationController)
054: */
055: public boolean canBeReplacedBy(
056: OperationController candidateController) {
057:
058: // We can be replaced only by another SetPropertyActionController
059: // that also changes the same property as we do.
060: if (candidateController instanceof SetPropertyActionController)
061: return ((SetPropertyActionController) candidateController).propertyMeta
062: .equals(this .propertyMeta);
063: else
064: return false;
065: }
066:
067: /* (non-Javadoc)
068: * @see org.osbl.agent.gui.OperationController#populateComponentList(java.util.List)
069: */
070: protected void populateComponentList(List<SComponent> componentList) {
071:
072: // A label to show that the property will be set to some value.
073: componentList.add(new SLabel(msg("setTo")));
074:
075: }
076:
077: /**
078: * Gets the property meta.
079: *
080: * @return the property meta
081: */
082: public PropertyMeta getPropertyMeta() {
083: return propertyMeta;
084: }
085:
086: /**
087: * Sets the property meta.
088: *
089: * @param propertyMeta the new property meta
090: */
091: public void setPropertyMeta(PropertyMeta propertyMeta) {
092: this .propertyMeta = propertyMeta;
093: }
094:
095: /* (non-Javadoc)
096: * @see java.lang.Object#toString()
097: */
098: public String toString() {
099: // Our string version is the property we want to change, indented.
100: return " " + propertyMeta.getLabel() + " ("
101: + propertyMeta.getName() + ")";
102: }
103:
104: /* (non-Javadoc)
105: * @see org.osbl.agent.gui.ActionController#populateAction(org.osbl.agent.model.Action)
106: */
107: protected void populateAction(Action action) {
108:
109: // Set the propertyMeta of the SetCurrentTimeAction to whatever propertyMeta
110: // the user chose in the UI.
111: ((SetPropertyAction) action).setBeanMetaClassName(propertyMeta
112: .getBeanMeta().getName());
113: ((SetPropertyAction) action).setPropertyMetaName(propertyMeta
114: .getName());
115:
116: }
117:
118: }
|