View Javadoc

1   /***
2    * Created on May 27, 2005, Copyright UC Regents
3    */
4   package org.telscenter.pas.steps;
5   
6   import java.util.logging.Logger;
7   
8   import java.awt.Component;
9   import java.beans.beancontext.BeanContextServices;
10  import java.util.HashMap;
11  import java.util.Map;
12  import java.util.TooManyListenersException;
13  
14  import javax.swing.JLabel;
15  
16  import org.telscenter.pas.beans.PasStep;
17  import org.telscenter.pas.service.IHingeState;
18  
19  import net.sf.sail.core.util.SailBeanUtils;
20  
21  /***
22   * @author turadg
23   */
24  public class HingedDelegator extends PasStep {
25  	/***
26  	 * Logger for this class
27  	 */
28  	private static final Logger logger = Logger.getLogger(HingedDelegator.class
29  			.getName());
30  
31  	Map<String,PasStep> statesToSteps = new HashMap<String, PasStep>();
32  
33  	public Map<String, PasStep> getStatesToSteps() {
34  		return statesToSteps;
35  	}
36  
37  	public void setStatesToSteps(Map<String, PasStep> statesToSteps) {
38  		this.statesToSteps = statesToSteps;
39  	}
40  
41  	private IHingeState hingeService;
42  
43  	protected void consumeService(BeanContextServices bcs, Class<? extends Object> serviceClass) {
44  		if (serviceClass == IHingeState.class) {
45  			try {
46  				hingeService = (IHingeState) bcs.getService(this, this,
47  						IHingeState.class, this, this);
48  			} catch (TooManyListenersException e) {
49  				// TODO Auto-generated catch block
50  				logger
51  						.severe("BeanContextServices, Class -  : exception: " + e); //$NON-NLS-1$
52  			}
53  		}
54  	}
55  
56  	public Component getComponent() {
57  		BeanContextServices bcs = SailBeanUtils.findServicesContextOf(this);
58  		consumeService(bcs, IHingeState.class);
59  
60  		String state = hingeService.getState();
61  
62  		if (state == null) {
63  			JLabel label = new JLabel("no hinge yet selected");
64  			label.setOpaque(false);
65  			return label;
66  		}
67  
68  		PasStep appropriateStep = statesToSteps.get(state);
69  		if (appropriateStep == null) {
70  			
71  			JLabel label = new JLabel("no step for hinge state: " + state);
72  			label.setOpaque(false);
73  			return label;
74  		}
75  
76  		return appropriateStep.getComponent();
77  	}
78  
79  }