View Javadoc

1   /*
2    * Created on Apr 26, 2005, Copyright UC Regents
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"; //$NON-NLS-1$
40  
41  	String authorNotes = ""; //$NON-NLS-1$
42  
43  	List<PasStep> stepsList = new ArrayList<PasStep>();
44  
45  	static int instanceCount = 0;
46  
47  	// nth step in VM for identification in toString()
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); //$NON-NLS-1$
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")); //$NON-NLS-1$
73  		PasStep old = (stepsList.size() <= index) ? null : stepsList.get(index);
74  
75  		// expand as necessary
76  		while (index >= stepsList.size())
77  			stepsList.add(null);
78  		stepsList.set(index, bean);
79  
80  		pcSupport.fireIndexedPropertyChange(STEPS, index, old, getSteps()); //$NON-NLS-1$
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  		}// for
89  
90  		// need to check the order
91  		if (logger.isDebugEnabled()) {
92  			if (oldBeans.equals(beans)) {
93  				logger
94  						.debug("setSteps(PasStep[]) - old beans .equals new beans"); //$NON-NLS-1$
95  			}
96  		}
97  
98  		firePropertyChange(STEPS, oldBeans, beans); //$NON-NLS-1$
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); //$NON-NLS-1$
109 	}
110 
111 	// added so the bean editor can detect which properties are bound
112 	public void addPropertyChangeListener(PropertyChangeListener listener) {
113 		pcSupport.addPropertyChangeListener(listener);
114 	}
115 
116 	// added so the bean editor can detect which properties are bound
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 		// TODO Auto-generated method stub
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 		// TODO Auto-generated method stub
147 		super.setBeanContext(bc);
148 		
149 		// If we aren't in a Pod then our children's bean context won't be set so we need
150 		// to set it ourselves.
151 		if(!isInPod()){
152 			for (PasStep steps : stepsList) {
153 				bc.add(steps);
154 			}
155 		}
156 	}
157 
158 }