View Javadoc

1   /*
2    * Created on Apr 26, 2005, Copyright UC Regents
3    */
4   package org.telscenter.pas.navigation;
5   
6   import javax.swing.JTree;
7   import javax.swing.event.TreeSelectionEvent;
8   import javax.swing.event.TreeSelectionListener;
9   import javax.swing.tree.DefaultMutableTreeNode;
10  import javax.swing.tree.TreeSelectionModel;
11  
12  import org.telscenter.pas.beans.PasActivity;
13  import org.telscenter.pas.beans.PasStep;
14  import org.telscenter.pas.service.PasProjectServiceProvider;
15  import org.telscenter.pas.ui.sidebar.Meditor;
16  
17  
18  public class PasProjectNavigationTreePanel extends PasProjectNavigationPanel {
19  
20  	public PasProjectNavigationTreePanel(PasProjectServiceProvider provider) {
21  		pasProjectServiceProvider = provider;
22  	}
23  
24  	public void updateDisplay() {
25  		removeAll();
26  		DefaultMutableTreeNode top = new DefaultMutableTreeNode("Pas");
27  		createNodes(top);
28  		final JTree tree = new JTree(top);
29  
30  		tree.getSelectionModel().setSelectionMode(
31  				TreeSelectionModel.SINGLE_TREE_SELECTION);
32  
33  		// Listen for when the selection changes.
34  		tree.addTreeSelectionListener(new TreeSelectionListener() {
35  			public void valueChanged(TreeSelectionEvent e) {
36  				DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree
37  						.getLastSelectedPathComponent();
38  
39  				if (node == null)
40  					return;
41  
42  				Object nodeInfo = node.getUserObject();
43  				if (node.isLeaf() && nodeInfo instanceof PasStep) {
44  					PasStep step = (PasStep) nodeInfo;
45  					if (pasProjectServiceProvider.getNavigationService() == null)
46  						throw new IllegalStateException(
47  								"missing navigation service");
48  					pasProjectServiceProvider.getNavigationService()
49  							.setCurrentStep(step);
50  				}
51  			}
52  		});
53  
54  		add(tree);
55  	}
56  
57  	/***
58  	 * @param top
59  	 */
60  	private void createNodes(DefaultMutableTreeNode top) {
61  		DefaultMutableTreeNode acNode = null;
62  		DefaultMutableTreeNode stepNode = null;
63  
64  		for (int i = 0; i < activities.length; i++) {
65  			PasActivity ac = activities[i];
66  			if (ac == null)
67  				continue;
68  
69  			acNode = new DefaultMutableTreeNode(ac.getTitle());
70  			top.add(acNode);
71  
72  			PasStep[] steps = ac.getSteps();
73  			for (int j = 0; j < steps.length; j++) {
74  				PasStep step = steps[j];
75  				stepNode = new DefaultMutableTreeNode(step);
76  				acNode.add(stepNode);
77  			}
78  		}
79  	}
80  
81  	/* (non-Javadoc)
82  	 * @see org.telscenter.pas.ui.sidebar.NavigationMeditor#getMeditor()
83  	 */
84  	public Meditor getMeditor() {
85  		// TODO Auto-generated method stub
86  		return null;
87  	}
88  
89  	/* (non-Javadoc)
90  	 * @see org.telscenter.pas.ui.sidebar.NavigationMeditor#setMeditor(org.telscenter.pas.ui.sidebar.Meditor)
91  	 */
92  	public void setMeditor(Meditor meditor) {
93  		// TODO Auto-generated method stub
94  		
95  	}
96  
97  	/* (non-Javadoc)
98  	 * @see org.telscenter.pas.navigation.PasProjectNavigationPanel#showFirstStep()
99  	 */
100 	@Override
101 	public void showFirstStep() {
102 		// TODO Auto-generated method stub
103 		
104 	}
105 
106 }