1 package org.oddjob.monitor.control; 2 3 import javax.swing.JTree ; 4 import javax.swing.event.ChangeEvent ; 5 import javax.swing.event.ChangeListener ; 6 import javax.swing.event.TreeSelectionEvent ; 7 import javax.swing.event.TreeSelectionListener ; 8 9 import org.oddjob.monitor.model.DetailModel; 10 import org.oddjob.monitor.model.JobTreeNode; 11 import org.oddjob.monitor.view.DetailView; 12 13 19 20 public class DetailController implements TreeSelectionListener { 21 22 23 private final DetailModel detailModel; 24 25 26 private final DetailView detailView; 27 28 29 private JobTreeNode currentNode; 30 31 34 public DetailController(DetailModel detailModel, DetailView detailView) { 35 this.detailModel = detailModel; 36 this.detailView = detailView; 37 38 detailView.addChangeListener(new ChangeListener () { 40 public void stateChanged(ChangeEvent e) { 41 if (currentNode != null) { 42 DetailController.this.detailModel.deSelect( 43 currentNode.getExplorerContext(), currentNode.getComponent()); 44 DetailController.this.detailModel.setTabSelected( 45 DetailController.this.detailView.getSelectedIndex()); 46 DetailController.this.detailModel.select(currentNode.getExplorerContext(), currentNode.getComponent()); 47 48 } 49 } 50 }); 51 } 52 53 57 public void valueChanged(TreeSelectionEvent event) { 58 if (currentNode != null) { 59 detailModel.deSelect(currentNode.getExplorerContext(), currentNode.getComponent()); 60 currentNode = null; 61 } 62 JTree tree = (JTree )event.getSource(); 63 JobTreeNode node = (JobTreeNode)tree.getLastSelectedPathComponent(); 64 if (node != null) { 65 currentNode = node; 66 detailModel.setTabSelected(detailView.getSelectedIndex()); 67 detailModel.select(node.getExplorerContext(), node.getComponent()); 68 } 69 } 70 71 } 72 | Popular Tags |