001: package com.xoetrope.carousel.survey;
002:
003: import com.xoetrope.survey.Condition;
004: import com.xoetrope.survey.DefaultRule;
005: import com.xoetrope.survey.Option;
006: import com.xoetrope.survey.Question;
007: import com.xoetrope.survey.QuestionGroup;
008: import net.xoetrope.editor.project.XEditorProject;
009: import net.xoetrope.xui.XProject;
010: import net.xoetrope.xui.XProjectManager;
011:
012: /**
013: * A wrapper class for DefaultRule, notifies its observers when new condition
014: * is added, changed, deleted, etc.
015: *
016: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
017: * the GNU Public License (GPL), please see license.txt for more details. If
018: * you make commercial use of this software you must purchase a commercial
019: * license from Xoetrope.</p>
020: * <p> $Revision: 1.5 $</p>
021: */
022: public class XRule extends DefaultRule {
023: protected XNotifier addConditionNotifier;
024: protected XNotifier deleteConditionNotifier;
025: protected XNotifier changeTargetNotifier;
026:
027: public XRule(int i, XQuestionGroup g, String n) {
028: super (i, g, null, n);
029: XProject project = XProjectManager.getCurrentProject();
030: XEditorProject editorProject = (project instanceof XEditorProject ? (XEditorProject) project
031: : null);
032: addConditionNotifier = new XNotifier(editorProject, true);
033: deleteConditionNotifier = new XNotifier(editorProject, true);
034: changeTargetNotifier = new XNotifier(editorProject, true);
035: }
036:
037: public XRule(int i, XQuestionGroup g, XQuestionGroup t, String n) {
038: super (i, g, t, n);
039: XProject project = XProjectManager.getCurrentProject();
040: XEditorProject editorProject = (project instanceof XEditorProject ? (XEditorProject) project
041: : null);
042: addConditionNotifier = new XNotifier(editorProject, true);
043: deleteConditionNotifier = new XNotifier(editorProject, true);
044: changeTargetNotifier = new XNotifier(editorProject, true);
045: }
046:
047: public void setName(String newName) {
048: if (!newName.equals(name))
049: XSurvey.setProjectModified(true);
050: super .setName(newName);
051: }
052:
053: public void setId(int newId) {
054: if (newId != id)
055: XSurvey.setProjectModified(true);
056: super .setId(newId);
057: }
058:
059: public Condition addCondition(Question q, Option o, String a) {
060: Condition condition = super .addCondition(q, o, a);
061: addConditionNotifier.notifyObservers(condition);
062: return condition;
063: }
064:
065: public Condition addCondition(Question q) {
066: Condition condition = new Condition(q);
067: conditions.add(condition);
068: addConditionNotifier.notifyObservers(condition);
069: return condition;
070: }
071:
072: public void deleteCondition(Condition condition) {
073: if (conditions.remove(condition))
074: deleteConditionNotifier.notifyObservers(condition);
075: }
076:
077: public void changeTarget(XQuestionGroup newTarget) {
078: if (target == null || !target.equals(newTarget)) {
079: target = newTarget;
080: changeTargetNotifier.notifyObservers(target);
081: }
082: }
083:
084: public XQuestionGroup getTarget() {
085: return (XQuestionGroup) target;
086: }
087:
088: public XQuestionGroup getGroup() {
089: return (XQuestionGroup) group;
090: }
091:
092: public XNotifier getAddConditionNotifier() {
093: return addConditionNotifier;
094: }
095:
096: public XNotifier getDeleteConditionNotifier() {
097: return deleteConditionNotifier;
098: }
099:
100: public XNotifier getChangeTargetNotifier() {
101: return changeTargetNotifier;
102: }
103:
104: }
|