From 2067987bcc380d6122f379d711ee80e7a222c348 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 11 Sep 2009 14:16:19 +0000 Subject: [PATCH] Fix [1772490] - Popup menu in VTreePanel finally works as expected https://sourceforge.net/tracker/?func=detail&atid=879335&aid=1772490&group_id=176962 Thanks to igor_adempiere and felixmoeller --- client/src/org/compiere/apps/AMenu.java | 7 +++++ .../org/compiere/grid/tree/VTreePanel.java | 28 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/client/src/org/compiere/apps/AMenu.java b/client/src/org/compiere/apps/AMenu.java index 83e5ebbbd3..373bf5c6f7 100644 --- a/client/src/org/compiere/apps/AMenu.java +++ b/client/src/org/compiere/apps/AMenu.java @@ -317,6 +317,7 @@ public final class AMenu extends CFrame mainLayout.setVgap(2); // treePanel.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this); + treePanel.addPropertyChangeListener(VTreePanel.NODE_SELECTION_RIGHT, this); // infoPanel.setLayout(infoLayout); infoLayout.setColumns(2); @@ -574,6 +575,12 @@ public final class AMenu extends CFrame */ public void propertyChange(PropertyChangeEvent e) { + if(e.getPropertyName().equals(VTreePanel.NODE_SELECTION_RIGHT)){ + MTreeNode nd = (MTreeNode)e.getNewValue(); + progressBar.setString(nd.toString()); + return; + } + MTreeNode nd = (MTreeNode)e.getNewValue(); log.info(nd.getNode_ID() + " - " + nd.toString()); diff --git a/client/src/org/compiere/grid/tree/VTreePanel.java b/client/src/org/compiere/grid/tree/VTreePanel.java index 2c46c07d2c..f97d3367bd 100644 --- a/client/src/org/compiere/grid/tree/VTreePanel.java +++ b/client/src/org/compiere/grid/tree/VTreePanel.java @@ -99,7 +99,7 @@ import de.schaeffer.compiere.tools.DocumentSearch; /** * Tree Panel displays trees. *
- * When a node is selected, a propertyChange (NODE_SELECTION) event is fired + * When a node is selected by Left Click, a propertyChange (NODE_SELECTION) event is fired *
  *		PropertyChangeListener -
  *			treePanel.addPropertyChangeListener(VTreePanel.NODE_SELECTION, this);
@@ -362,8 +362,10 @@ public final class VTreePanel extends CPanel
 
 	private JScrollPane barScrollPane;
 
-	/**	Property Listener NodeSelected			*/
+	/**	Property Listener NodeSelected	by Left Click		*/
 	public static final String NODE_SELECTION = "NodeSelected";
+	/**	Property Listener NodeSelected	by Right Click		*/
+	public static final String NODE_SELECTION_RIGHT = "NodeSelectedRight";
 
 	/**
 	 *  Static Component initialization.
@@ -443,8 +445,10 @@ public final class VTreePanel extends CPanel
 		//
 		popMenuTree.setLightWeightPopupEnabled(false);
 		popMenuTree.add(mBarAdd);
-		popMenuTree.addSeparator();
 		popMenuTree.add(mFrom);
+		if(!m_hasBar){
+			popMenuTree.addSeparator();
+		}
 		popMenuTree.add(mTo);
 		popMenuBar.setLightWeightPopupEnabled(false);
 		popMenuBar.add(mBarRemove);
@@ -811,11 +815,21 @@ public final class VTreePanel extends CPanel
 				&& SwingUtilities.isRightMouseButton(e)
 				&& tree.getSelectionPath() != null)         //  need select first
 			{
-				// MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent();
-			    //	if (nd.isLeaf())                    //  only leaves
-				{
+				int selRow = tree.getRowForLocation(e.getX(), e.getY());
+				TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());
+				if(selRow != -1){
+					tree.setSelectionPath(selPath);
+					
 					Rectangle r = tree.getPathBounds(tree.getSelectionPath());
-					popMenuTree.show(tree, (int)r.getMaxX(), (int)r.getY());
+					if(r!=null){
+						popMenuTree.show(tree, (int)r.getMaxX(), (int)r.getY());
+					}else{
+					  popMenuTree.show(tree, e.getX(), e.getY());
+					}
+					if(m_hasBar){
+						MTreeNode nd = (MTreeNode)tree.getSelectionPath().getLastPathComponent();
+						firePropertyChange(NODE_SELECTION_RIGHT, null, nd);
+					}
 				}
 			}
 		}   //  JTree