01: package org.openwfe.gpe.model;
02:
03: import org.eclipse.jface.dialogs.MessageDialog;
04:
05: /**
06: * @author helena
07: */
08: public class WhenComposite extends Composite {
09:
10: private int maximum = 0;
11: public static String name = "When";
12: private String errorMessage = "Error Message";
13:
14: public String getName() {
15: return name;
16: }
17:
18: public void setName(String s) {
19: name = s;
20: }
21:
22: public void addChild(FlowElement child) {
23: addChild(child, -1);
24: }
25:
26: public void addChild(FlowElement child, int index) {
27: if (index >= 0 && maximum < 2) {
28: children.add(index, child);
29: maximum++;
30: fireStructureChange(CHILDREN, child);
31: } else if (maximum == 0
32: && (child instanceof CompareElement
33: || child instanceof DefinedElement
34: || child instanceof UndefinedElement
35: || child instanceof OneChild || child instanceof BooleanComposite)) {
36: children.add(child);
37: maximum++;
38: fireStructureChange(CHILDREN, child);
39: } else if (maximum == 1
40: && (!(child instanceof CompareElement || child instanceof NotElement))) {
41: children.add(child);
42: maximum++;
43: fireStructureChange(CHILDREN, child);
44: } else {
45: switch (maximum) {
46: case 0:
47: errorMessage = "First a condition must be added";
48: break;
49: case 1:
50: errorMessage = "No boolean or not elements allowed";
51: break;
52: case 2:
53: errorMessage = "No more elements can be added";
54: break;
55: default:
56: System.out.println("Default");
57: }
58: MessageDialog.openInformation(null, "Alert", errorMessage);
59: }
60:
61: }
62:
63: public void removeChild(AbstractFlow child) {
64: children.remove(child);
65: maximum--;
66: fireStructureChange(CHILDREN, child);
67: }
68: }
|