001 /** 002 * planningtool - A Planning Tool with Critiquing Support. 003 * 004 * Copyright (C) 2006 olale 005 006 * This program is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU General Public License 008 * as published by the Free Software Foundation; either version 2 009 * of the License, or (at your option) any later version. 010 011 * This program is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 016 * You should have received a copy of the GNU General Public License 017 * along with this program; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 019 020 * Contact information: 021 * E-mail: olale@ida.liu.se 022 * olale@lysator.liu.se 023 */ 024 package se.liu.ida.critiquer.gui; 025 026 import javax.swing.JPanel; 027 import javax.swing.JScrollPane; 028 import javax.swing.JTree; 029 import javax.swing.event.TreeSelectionListener; 030 031 import se.liu.ida.critiquer.mics.ReferenceHolder; 032 import se.liu.ida.critiquer.resources.Agent; 033 import se.liu.ida.critiquer.resources.OrganizationModel; 034 035 public class OrganizationTreePanel extends JPanel { 036 037 /** 038 * 039 */ 040 private static final long serialVersionUID = 1L; 041 private OrganizationModel treeModel; 042 private transient JTree tree; 043 private transient JScrollPane scrollPane; 044 045 public OrganizationTreePanel() { 046 treeModel = ReferenceHolder.organizationModel; 047 initComponent(); 048 049 } 050 051 private void initComponent() { 052 tree = new JTree(treeModel); 053 scrollPane = new JScrollPane(tree); 054 add(scrollPane); 055 } 056 057 /* (non-Javadoc) 058 * @see se.liu.ida.critiquer.gui.OrganizationTreeModel#getRoot() 059 */ 060 public Agent getRoot() { 061 return (Agent)treeModel.getRoot(); 062 } 063 064 /* (non-Javadoc) 065 * @see javax.swing.JTree#addTreeSelectionListener(javax.swing.event.TreeSelectionListener) 066 */ 067 public void addTreeSelectionListener(TreeSelectionListener tsl) { 068 tree.addTreeSelectionListener(tsl); 069 } 070 071 public Agent getSelectedAgent() { 072 if (tree.getSelectionPath()!=null) { 073 return (Agent)tree.getSelectionPath().getLastPathComponent(); 074 } else { 075 return null; 076 } 077 } 078 079 /** 080 * @return Returns the tree. 081 */ 082 public JTree getTree() { 083 if (tree==null) { 084 initComponent(); 085 } 086 return tree; 087 } 088 089 }