Pointer vers le noeud jumeaux d'un arbre apres selection d'un click droit

ChristOffAum Messages postés 10 Date d'inscription mardi 6 janvier 2009 Statut Membre Dernière intervention 10 septembre 2009 - 3 sept. 2009 à 10:59
ChristOffAum Messages postés 10 Date d'inscription mardi 6 janvier 2009 Statut Membre Dernière intervention 10 septembre 2009 - 10 sept. 2009 à 17:37
Bonjour à tous,
Voilà je vous explique mon problème, j'ai deux arbre XML en parallèle, ils sont censé avoir la même structure, ou à défaut une légère différence. J'aimerais pouvoir pointer le nœud jumeaux de l'arbre de droite, lorsque je clic sur celui de gauche et inversement.

j'ai réalisé un code, mais en lançant le debug, je m'aperçois qu'il ne passe même pas dedans.

Voilà le code

private class MyTreeMouseAdapter extends MouseAdapter implements ActionListener {
private JTree l_tree = null;
private JTree l_tree2 = tree2;
/** Popup menu for fact elements */
private JPopupMenu m_FactPopup = new JPopupMenu();
/** Popup menu for node elements */
private JPopupMenu m_NodePopup = new JPopupMenu();
/** Current select path in tree */
private TreePath m_clickedPath;
private TreePath m_clickedNode;

/**
 * Constructor : Make popup menus used
 */

public MyTreeMouseAdapter() {


JMenuItem mi = new JMenuItem("Go to Context");
mi.addActionListener(this);
mi.setActionCommand("GoToContext");
m_FactPopup.add(mi);

mi = new JMenuItem("Go to Unit");
mi.addActionListener(this);
mi.setActionCommand("GoToUnit");
m_FactPopup.add(mi);

mi = new JMenuItem("Go to Twin Node");
mi.addActionListener(this);
mi.setActionCommand("GoToTwinNode");
m_NodePopup.add(mi);

}

/*
 * (non-Javadoc)
 * 
 * @see
 * java.awt.event.MouseAdapter#mouseReleased(java.awt.event.MouseEvent)
 */
public void mouseReleased(MouseEvent e) {

log.debug("Entrée dans le constructeur MyTreeMouseAdapter fenêtre de pop up");
// Check if we are on a JTree
if (e.getComponent() instanceof JTree)
l_tree = (JTree) e.getComponent();
else
return;

// Get clicked node, and show appropriate popup menu in function of
// node type
if (l_tree != null && e.isPopupTrigger()) {
// Get tree path
int x = e.getX();
int y = e.getY();
TreePath path = l_tree.getPathForLocation(x, y);

if (path != null) {
// Get clicked node
XMLTreeNode clickedNode = (XMLTreeNode) path.getLastPathComponent();
// Show popup in function of clicked node type
if (clickedNode.getNode() instanceof FactElement){
m_FactPopup.show((JComponent) e.getSource(), x, y);
// Save clicked path
m_clickedPath = path;
}

else if (clickedNode.getNode() instanceof Node){
m_NodePopup.show((JComponent) e.getSource(), x, y);

// Save clicked path
m_clickedNode = path;
}

}
}
}

/*
 * (non-Javadoc)
 * 
 * @see
 * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
//
public void actionNodePerformed(ActionEvent l_ez){
XMLTreeNode clickedNode = (XMLTreeNode) m_clickedNode.getLastPathComponent();
if(clickedNode.getNode() instanceof Node){

Node node = (Node) clickedNode.getNode();
clickedNode.getParent();
TreeModel model2 = l_tree2.getModel();
TreeNode root2 = (MutableTreeNode) model2.getRoot();

if (l_ez.getActionCommand().equals("GoToTwinNode")){
for (int i = 0; i < root2.getChildCount(); i++) {
if (root2.getChildAt(i) instanceof XMLTreeNode) {
XMLTreeNode xmlTreeNode = (XMLTreeNode) root2.getChildAt(i);
if (xmlTreeNode.getNode() instanceof Node) {
Node node2 = (Node) xmlTreeNode.getNode();
if(node2 == node){
Object path[] = new Object[2];
path[0] = root2;
path[1] = xmlTreeNode;
TreePath newpath = new TreePath(path);
l_tree.setSelectionPath(newpath);
l_tree.scrollPathToVisible(newpath);
}

}
}
}

}

}

}




Merci d'avance pour vos réponses

1 réponse

ChristOffAum Messages postés 10 Date d'inscription mardi 6 janvier 2009 Statut Membre Dernière intervention 10 septembre 2009
10 sept. 2009 à 17:37
UP thx
0
Rejoignez-nous