bonjour,
je suis en train de developper un TreeModel qui selon certains criteres affiche ou pas certains noeuds. J'ai une ebauche qui fonctionne a peu pres, mais c'est a le a peu pres qui est genant
Ca marche presque avec un decalage de "1" dans les noeuds masqués (le premier noeud qui devrait etre masqué est affiché, le premier noeud suivant qui devrai etre affiché ne l'est pas).
Pour mon TreeModel j'ai fait ca si vous pouvez y jeter un oeil (enfin un coup devrait suffire) si vous voyez une boulette.
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97 public class HiddenNodeTreeModel extends DefaultTreeModel { public HiddenNodeTreeModel(TreeNode root) { super(root); } public HiddenNodeTreeModel(TreeNode root, boolean asksAllowsChildren) { super(root, asksAllowsChildren); } @Override public int getChildCount( Object parent ) { System.out.println( "Entrée getChildCount for : " + ((AttributeTypedMutableTreeNode)parent).getType().getNomEnum() ); int res = 0; if( parent == root ){ res = 1; } else { if ( parent instanceof AttributeTypedMutableTreeNode ) { AttributeTypedMutableTreeNode node = (AttributeTypedMutableTreeNode)parent; if( !node.isLeaf() ) { Enumeration enu = node.children(); while( enu.hasMoreElements() ) { AttributeTypedMutableTreeNode child = (AttributeTypedMutableTreeNode)enu.nextElement(); if( child.isVisible() ) { res += 1; } } } } } System.out.println( "sortie getChildCount res = " + res ); return res ; } @Override public int getIndexOfChild(Object parent, Object child) { System.out.println( "Entrée getIndexOfChild for : " + ((AttributeTypedMutableTreeNode)parent).getType().getNomEnum() ); if( ( parent!= root ) && ( parent instanceof AttributeTypedMutableTreeNode ) && ( child instanceof AttributeTypedMutableTreeNode ) ){ AttributeTypedMutableTreeNode pere = (AttributeTypedMutableTreeNode)parent; AttributeTypedMutableTreeNode fils = (AttributeTypedMutableTreeNode)child; if( !pere.isLeaf() ) { Enumeration enu = pere.children(); int res = -1; while( enu.hasMoreElements() ) { AttributeTypedMutableTreeNode tmp = (AttributeTypedMutableTreeNode)enu.nextElement(); if( ( tmp.isVisible() ) && ( !tmp.equals( fils ) ) ){ res += 1; } if( tmp.equals( fils ) ) { System.out.println( "Sortie getIndexChild count : " + res ); return res; } tmp = (AttributeTypedMutableTreeNode)tmp.getNextSibling(); } } } System.out.println( "Sortie raté getIndexOfChild" ); return 0; } public Object getChild( Object parent, int index ) { System.out.println( "Entrée getChild for : " + ((AttributeTypedMutableTreeNode)parent).getType().getNomEnum() ); Object res = null; if( parent == root ) { res = ((AttributeTypedMutableTreeNode)root).getFirstChild(); } else { if( ( parent != null ) && ( parent instanceof AttributeTypedMutableTreeNode ) ) { AttributeTypedMutableTreeNode tmp = (AttributeTypedMutableTreeNode)parent; if( ( !tmp.isLeaf() ) && ( tmp.getChildCount() >= index ) ){ res = tmp.getChildAt( index ); } } } System.out.println( "Entrée getChild obj res : " + res ); return res; } }
Partager