1
2
3
4 package org.telscenter.pas.beans;
5
6 import java.beans.PropertyChangeListener;
7 import java.beans.PropertyVetoException;
8 import java.beans.beancontext.BeanContext;
9 import java.beans.beancontext.BeanContextChildSupport;
10 import java.util.ArrayList;
11 import java.util.List;
12
13 import net.sf.sail.common.beansupport.ITitleAware;
14 import net.sf.sail.core.beans.Pod;
15
16 import org.apache.log4j.Logger;
17
18 /***
19 * Bean representing a Pas activity.
20 *
21 * @author turadg
22 */
23 public class PasActivity extends BeanContextChildSupport implements
24 IAuthorNotation, ITitleAware, IHelp {
25 /***
26 *
27 */
28 public static final String STEPS = "steps";
29
30 /***
31 * Logger for this class
32 */
33 private static final Logger logger = Logger.getLogger(PasActivity.class);
34
35 private static final long serialVersionUID = 1L;
36
37 private static final String HELP_ID = "top";
38
39 String title = "UNDEFINED";
40
41 String authorNotes = "";
42
43 List<PasStep> stepsList = new ArrayList<PasStep>();
44
45 static int instanceCount = 0;
46
47
48 int instanceNumber = instanceCount++;
49
50 public String getTitle() {
51 return title;
52 }
53
54 public void setTitle(String title) {
55 Object old = this.title;
56 this.title = title;
57 firePropertyChange("title", old, title);
58 }
59
60 public PasStep[] getSteps() {
61 PasStep[] beans = new PasStep[stepsList.size()];
62 return stepsList.toArray(beans);
63 }
64
65 public PasStep getSteps(int i) {
66 return stepsList.get(i);
67 }
68
69 public void setSteps(int index, PasStep bean) {
70 if (bean == null)
71 throw new IllegalArgumentException(Messages
72 .getString("PasProject.NO_NULL"));
73 PasStep old = (stepsList.size() <= index) ? null : stepsList.get(index);
74
75
76 while (index >= stepsList.size())
77 stepsList.add(null);
78 stepsList.set(index, bean);
79
80 pcSupport.fireIndexedPropertyChange(STEPS, index, old, getSteps());
81 }
82
83 public void setSteps(PasStep[] beans) {
84 PasStep[] oldBeans = getSteps();
85 stepsList = new ArrayList<PasStep>(beans.length);
86 for (int i = 0; i < beans.length; i++) {
87 stepsList.add(beans[i]);
88 }
89
90
91 if (logger.isDebugEnabled()) {
92 if (oldBeans.equals(beans)) {
93 logger
94 .debug("setSteps(PasStep[]) - old beans .equals new beans");
95 }
96 }
97
98 firePropertyChange(STEPS, oldBeans, beans);
99 }
100
101 public String getAuthorNotes() {
102 return authorNotes;
103 }
104
105 public void setAuthorNotes(String authorNotes) {
106 Object old = this.authorNotes;
107 this.authorNotes = authorNotes;
108 firePropertyChange("authorNotes", old, authorNotes);
109 }
110
111
112 public void addPropertyChangeListener(PropertyChangeListener listener) {
113 pcSupport.addPropertyChangeListener(listener);
114 }
115
116
117 public void removePropertyChangeListener(PropertyChangeListener listener) {
118 pcSupport.removePropertyChangeListener(listener);
119 }
120
121 /***
122 * @see org.telscenter.pas.beans.IHelp#getHelpId()
123 */
124 public String getHelpId() {
125 return HELP_ID;
126 }
127
128 @Override
129 public String toString() {
130
131 return "PasActivity(instance#" + instanceNumber + ") " + getTitle();
132 }
133
134 protected boolean isInPod()
135 {
136 Object beanContext = getBeanContext();
137 return beanContext instanceof Pod;
138 }
139
140 /***
141 * @see java.beans.beancontext.BeanContextChildSupport#setBeanContext(java.beans.beancontext.BeanContext)
142 */
143 @Override
144 public synchronized void setBeanContext(BeanContext bc)
145 throws PropertyVetoException {
146
147 super.setBeanContext(bc);
148
149
150
151 if(!isInPod()){
152 for (PasStep steps : stepsList) {
153 bc.add(steps);
154 }
155 }
156 }
157
158 }