1 package org.telscenter.pas.otrunk.skeleton.controllers;
2
3 import java.awt.Frame;
4 import java.beans.PropertyChangeEvent;
5 import java.beans.PropertyChangeListener;
6 import java.util.Arrays;
7 import java.util.List;
8
9 import org.apache.commons.collections.ListUtils;
10 import org.concord.framework.otrunk.DefaultOTController;
11 import org.concord.framework.otrunk.OTChangeEvent;
12 import org.concord.framework.otrunk.OTChangeListener;
13 import org.concord.framework.otrunk.OTObject;
14 import org.concord.framework.otrunk.OTObjectList;
15 import org.telscenter.pas.beans.PasActivity;
16 import org.telscenter.pas.beans.PasStep;
17 import org.telscenter.pas.otrunk.OTrunkStep;
18 import org.telscenter.pas.otrunk.skeleton.OTPasActivity;
19 import org.telscenter.pas.otrunk.skeleton.OTPasStep;
20
21 public class OTPasActivityController extends DefaultOTController {
22
23 public static Class[] realObjectClasses = { PasActivity.class };
24 public static Class otObjectClass = OTPasActivity.class;
25
26 private OTChangeListener otListener;
27 private PropertyChangeListener pListener;
28
29 public void loadRealObject(Object realObject) {
30 PasActivity activity = (PasActivity) realObject;
31 OTPasActivity otActivity = (OTPasActivity) otObject;
32
33
34
35
36 activity.setTitle(otActivity.getTitle());
37
38
39 activity.setAuthorNotes(otActivity.getAuthorNotes());
40
41
42
43 OTObjectList stepList = otActivity.getStepList();
44 PasStep[] steps = new PasStep[stepList.size()];
45 for (int i = 0; i < steps.length; i++) {
46 OTPasStep otStep = (OTPasStep) stepList.get(i);
47 if(otStep == null){
48 System.err.println("null otStep");
49 continue;
50 }
51 steps[i] = (PasStep) controllerService
52 .getRealObject(otStep);
53 }
54 activity.setSteps(steps);
55
56 }
57
58 public void registerRealObject(Object realObject) {
59 final PasActivity activity = (PasActivity) realObject;
60 final OTPasActivity otActivity = (OTPasActivity) otObject;
61
62 otListener = new OTChangeListener() {
63
64 public void stateChanged(OTChangeEvent e) {
65 String operation = e.getOperation();
66 System.out.println("ACTVITY OT OPERATION: " + operation);
67 }
68 };
69
70 pListener = new PropertyChangeListener() {
71
72 public void propertyChange(PropertyChangeEvent evt) {
73
74
75
76
77 if( activity.getSteps().length < otActivity.getStepList().size() ) {
78
79 Object deltaStep = OTPasProjectController.deltaArrays((Object[])evt.getOldValue(), (Object[])evt.getNewValue());
80 OTObject otStep = controllerService.getOTObject(deltaStep);
81 otActivity.getStepList().remove(otStep);
82 } else if( activity.getSteps().length > otActivity.getStepList().size() ) {
83 Object newStep = OTPasProjectController.deltaArrays((Object[])evt.getOldValue(), (Object[])evt.getNewValue());
84
85 if (newStep instanceof OTrunkStep) {
86 ((OTrunkStep)newStep).setControllerService(controllerService);
87 }
88
89 OTObject otStep = controllerService.getOTObject(newStep);
90 otActivity.getStepList().add(otStep);
91 }
92 }
93
94 };
95
96 activity.addPropertyChangeListener(PasActivity.STEPS,pListener);
97 otActivity.addOTChangeListener(otListener);
98
99
100 }
101
102
103
104 public void saveRealObject(Object realObject) {
105 PasActivity activity = (PasActivity) realObject;
106 OTPasActivity otActivity = (OTPasActivity) otObject;
107
108
109
110 otActivity.setTitle(activity.getTitle());
111
112
113 otActivity.setAuthorNotes(activity.getAuthorNotes());
114
115
116
117 PasStep[] steps = activity.getSteps();
118 OTObjectList stepList = otActivity.getStepList();
119 stepList.removeAll();
120
121 for (int i = 0; i < steps.length; i++) {
122 PasStep step = steps[i];
123 OTObject otStep = controllerService.getOTObject(step);
124 controllerService.saveRealObject(step, otStep);
125 stepList.add(otStep);
126 }
127 activity.setSteps(steps);
128
129 }
130
131 }