01: package org.osbl.agent.gui;
02:
03: import org.osbl.agent.model.Action;
04: import org.osbl.agent.model.Condition;
05:
06: /**
07: * Knows how to return its corresponding Condition and how to set up the
08: * UI-controls to reflect a Condition given.
09: *
10: * @author Sebastian Nozzi.
11: */
12: public abstract class ConditionController extends OperationController {
13:
14: /** The Constant CONDITION_CONTROLLERS_PACKAGE. */
15: private static final String CONDITION_CONTROLLERS_PACKAGE = "org.osbl.agent.gui.condition";
16:
17: /**
18: * Given a Condition instance, it tries to retrieve a corresponding ConditionController object.
19: * That object reflects the state of the given Condition.
20: *
21: * @param condition a Condition instance.
22: *
23: * @return the corresponding instantiated ConditionController.
24: *
25: * @throws InstantiationException the instantiation exception
26: * @throws IllegalAccessException the illegal access exception
27: * @throws ClassNotFoundException the class not found exception
28: */
29: public static ConditionController newInstance(Condition condition)
30: throws InstantiationException, IllegalAccessException,
31: ClassNotFoundException {
32:
33: // Create the ConditionController corresponding to the given condition.
34: ConditionController result = (ConditionController) newInstance(
35: condition, CONDITION_CONTROLLERS_PACKAGE);
36:
37: // Make the ConditionController set itself up according to the
38: // parameters in the condition.
39: result.setCondition(condition);
40:
41: // Return the recently created and set-up Controller
42: return result;
43: }
44:
45: /**
46: * Makes the ConditionController re-configure itself based on the passed Condition.
47: * (So, this is no normal setter method; the Condition is not retained).
48: *
49: * @param condition the Condition this ConditionController should reflect.
50: */
51: public abstract void setCondition(Condition condition);
52:
53: /**
54: * Generates a (new) Condition instance according to the state of the UI controls.
55: * Subclasses should not override this method but {@link #populateCondition(Condition)} instead.
56: *
57: * @return a new Condition instance.
58: */
59: public final Condition getCondition() {
60:
61: // Create the corresponding Condition instance.
62: // (for example, creates a StringCondition if we are a StringConditionController).
63: Condition result = (Condition) newOperationInstance();
64:
65: // Ask our subclass to populate it according to its current settings.
66: populateCondition(result);
67:
68: // Now the Condition reflects the state of the Controller.
69: // Return the populated Condition.
70: return result;
71:
72: }
73:
74: /**
75: * Populates and configures a given Condition object to reflect the state of this Controller.
76: * (especially the UI components).
77: *
78: * @param condition the Condition to be populated.
79: */
80: protected abstract void populateCondition(Condition condition);
81:
82: }
|