001: package org.openwfe.gpe.model;
002:
003: import org.eclipse.jface.dialogs.MessageDialog;
004:
005: /**
006: * @author helena
007: *
008: */
009: public class CaseComposite extends CompositeOrOneChild {
010:
011: public static String name = "Case";
012: private int level = 0;
013: private String errorMessage = "Error Message";
014: boolean classicElement = true;
015: boolean end = false;
016:
017: public String getName() {
018: return name;
019: }
020:
021: public void setName(String s) {
022: name = s;
023: }
024:
025: public void addChild(FlowElement child) {
026: addChild(child, -1);
027: }
028:
029: public void addChild(FlowElement child, int index) {
030: if (index >= 0 && level < 3) {
031: children.add(index, child);
032: level++;
033: fireStructureChange(CHILDREN, child);
034: } else if (level % 2 == 0
035: && (child instanceof CompareElement
036: || child instanceof DefinedElement
037: || child instanceof UndefinedElement
038: || child instanceof OneChild || child instanceof BooleanComposite)
039: && (end == false)) {
040: children.add(child);
041: classicElement = false;
042: level++;
043: fireStructureChange(CHILDREN, child);
044: } else if (level % 2 == 0
045: && (!(child instanceof CompareElement
046: || child instanceof DefinedElement
047: || child instanceof UndefinedElement
048: || child instanceof OneChild || child instanceof BooleanComposite))
049: && (end == false) && level != 0) {
050: children.add(child);
051: end = true;
052: level++;
053: fireStructureChange(CHILDREN, child);
054: } else if (level % 2 == 1
055: && (!(child instanceof CompareElement
056: || child instanceof DefinedElement
057: || child instanceof UndefinedElement
058: || child instanceof OneChild || child instanceof BooleanComposite))
059: && (end == false)) {
060: children.add(child);
061: level++;
062: fireStructureChange(CHILDREN, child);
063: } else {
064: switch (level % 2) {
065: case 0:
066: errorMessage = "First a condition element must be added";
067: break;
068: case 1:
069: if (end == true) {
070: errorMessage = "No more elements can be added";
071: break;
072: } else {
073: errorMessage = "You cannot add this type of element";
074: break;
075: }
076: default:
077: System.out.println("Default");
078: }
079: MessageDialog.openInformation(null, "Alert", errorMessage);
080: }
081:
082: }
083:
084: public void removeChild(FlowElement child) {
085: int i = children.indexOf(child);
086:
087: if (i % 2 == 0
088: && (child instanceof CompareElement
089: || child instanceof DefinedElement
090: || child instanceof UndefinedElement || child instanceof OneChild)
091: && (end == false)) {
092: children.remove(child);
093: children.remove(children.get(i));
094: level--;
095: level--;
096: fireStructureChange(CHILDREN, child);
097: } else if (i % 2 == 1
098: && (!(child instanceof CompareElement
099: || child instanceof DefinedElement
100: || child instanceof UndefinedElement || child instanceof OneChild))) {
101: children.remove(child);
102: children.remove(children.get(i - 1));
103: level--;
104: level--;
105: fireStructureChange(CHILDREN, child);
106:
107: } else {
108: children.remove(child);
109: level--;
110: end = false;
111: fireStructureChange(CHILDREN, child);
112: }
113: }
114: }
|