package gov.nih.nci.cbiit.cmps.ui.tree;

import gov.nih.nci.cbiit.cmps.ui.mapping.ElementMetaLoader;
import gov.nih.nci.cbiit.cmps.ui.properties.PropertiesSwitchController;

import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class TreeSelectionHandler implements TreeSelectionListener {

	private PropertiesSwitchController propertyController;
	public TreeSelectionHandler(PropertiesSwitchController controller)
	{
		propertyController=controller;
	}
	// TODO Auto-generated method stub
	/**
	 * Called whenever the value of the selection changes.
	 *
	 * @param e the event that characterizes the change.
	 */
	public void valueChanged(TreeSelectionEvent e)
	{
		TreePath newPath = e.getNewLeadSelectionPath();
		if(newPath==null)
		{
			propertyController.setSelectedItem(null);
		}
		else
		{
			DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) newPath.getLastPathComponent();
			Object newSelection = treeNode.getUserObject();
			if(newSelection instanceof ElementMetaLoader.MyTreeObject)
				newSelection = ((ElementMetaLoader.MyTreeObject)newSelection).getObj();
			
			propertyController.setSelectedItem(newSelection);
		}
		propertyController.getPropertiesPage().updateProptiesDisplay(null);
	}

}

package gov.nih.nci.cbiit.cmps.ui.tree;

import gov.nih.nci.cbiit.cmps.ui.jgraph.MiddlePanelJGraphController;
import gov.nih.nci.cbiit.cmps.ui.mapping.ElementMetaLoader;

import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class TreeSelectionHandler implements TreeSelectionListener {

	private MiddlePanelJGraphController graphController;
	public TreeSelectionHandler(MiddlePanelJGraphController controller)
	{
		graphController=controller;
	}
	// TODO Auto-generated method stub
	/**
	 * Called whenever the value of the selection changes.
	 *
	 * @param e the event that characterizes the change.
	 */
	public void valueChanged(TreeSelectionEvent e)
	{
		if (graphController.isGraphSelected())
			return;
		
		TreePath newPath = e.getNewLeadSelectionPath();
		if(newPath==null)
		{
			graphController.getPropertiesSwitchController().setSelectedItem(null);
		}
		else
		{
			//clear graph selection
			graphController.getMiddlePanel().getGraph().clearSelection();
			DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) newPath.getLastPathComponent();
			//clear selection of "the other tree"
			if (treeNode instanceof DefaultSourceTreeNode)
				graphController.getMappingPanel().getTargetTree().clearSelection();
			else if (treeNode instanceof DefaultTargetTreeNode)
				graphController.getMappingPanel().getSourceTree().clearSelection();
			
			Object newSelection = treeNode.getUserObject();
			if(newSelection instanceof ElementMetaLoader.MyTreeObject)
				newSelection = ((ElementMetaLoader.MyTreeObject)newSelection).getObj();
			
			graphController.getPropertiesSwitchController().setSelectedItem(newSelection);
		}
		graphController.getPropertiesSwitchController().getPropertiesPage().updateProptiesDisplay(null);
	}

}

clear gaph and other tree selection