01: package org.openwfe.gpe.model;
02:
03: import org.eclipse.jface.dialogs.MessageDialog;
04:
05: /**
06: * @author christelle
07: */
08: public class IfComposite extends Composite {
09:
10: public static String name = "If";
11: private int maximum = 0;
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 < 3) {
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 < 3 && maximum > 0) {
40: children.add(child);
41: maximum++;
42: fireStructureChange(CHILDREN, child);
43: } else {
44: switch (maximum) {
45: case 0:
46: errorMessage = "First a condition must be added";
47: break;
48: case 3:
49: errorMessage = "No more elements can be added";
50: break;
51: default:
52: System.out.println("Default");
53: }
54: MessageDialog.openInformation(null, "Alert", errorMessage);
55: }
56:
57: }
58:
59: public void removeChild(AbstractFlow child) {
60: children.remove(child);
61: maximum--;
62: fireStructureChange(CHILDREN, child);
63: }
64: }
|