KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > util > browser > core > common > DynamicTree


1 /*====================================================================
2
3 Objectweb Browser framework
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Moroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.util.browser.core.common;
28
29 /** The console's imports */
30 import org.objectweb.util.browser.core.naming.DefaultEntry;
31 import org.objectweb.util.browser.core.naming.DefaultName;
32 import org.objectweb.util.browser.core.naming.InitialContextContainer;
33 import org.objectweb.util.browser.core.naming.InitialContextContainerFactory;
34 import org.objectweb.util.browser.core.naming.InitialEntry;
35 import org.objectweb.util.browser.api.Context;
36 import org.objectweb.util.browser.api.DropAction;
37 import org.objectweb.util.browser.api.Entry;
38 import org.objectweb.util.browser.api.Table;
39 import org.objectweb.util.browser.api.Tree;
40 import org.objectweb.util.browser.api.TreeView;
41 import org.objectweb.util.browser.api.Panel;
42 import org.objectweb.util.browser.api.Wrapper;
43 import org.objectweb.util.browser.api.Info;
44 import org.objectweb.util.browser.core.api.BrowserProperty;
45 import org.objectweb.util.browser.core.api.ContextContainer;
46 import org.objectweb.util.browser.core.api.ContextContainerFactory;
47 import org.objectweb.util.browser.core.api.ContextProperty;
48 import org.objectweb.util.browser.core.api.ExtendedEntry;
49 import org.objectweb.util.browser.core.api.Role;
50 import org.objectweb.util.browser.core.api.RoleManagement;
51 import org.objectweb.util.browser.core.api.StatusBar;
52 import org.objectweb.util.browser.core.api.ViewPanel;
53 import org.objectweb.util.browser.core.api.TreeConfiguration;
54 import org.objectweb.util.browser.core.dnd.DefaultDropTreeView;
55 import org.objectweb.util.browser.core.dnd.EntryViewTransferable;
56 import org.objectweb.util.browser.core.panel.WhitePanel;
57 import org.objectweb.util.browser.core.xmlparser.ContextXMLParser;
58 import org.objectweb.util.browser.core.xmlparser.XMLParser;
59 import org.objectweb.util.browser.core.xmlparser.BrowserXMLParser;
60
61 import org.objectweb.util.browser.core.popup.DefaultAction;
62
63 /** The java API's imports */
64 import java.util.Arrays JavaDoc;
65 import java.util.Comparator JavaDoc;
66 import java.util.Enumeration JavaDoc;
67 import java.util.HashMap JavaDoc;
68 import java.util.Iterator JavaDoc;
69 import java.util.List JavaDoc;
70 import java.util.Map JavaDoc;
71 import java.util.Vector JavaDoc;
72 import java.io.IOException JavaDoc;
73
74 /** The Drag and Drop API's imports */
75 import java.awt.datatransfer.DataFlavor JavaDoc;
76 import java.awt.datatransfer.Transferable JavaDoc;
77 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
78 import java.awt.dnd.Autoscroll JavaDoc;
79 import java.awt.dnd.DnDConstants JavaDoc;
80 import java.awt.dnd.DragGestureEvent JavaDoc;
81 import java.awt.dnd.DragGestureListener JavaDoc;
82 import java.awt.dnd.DragSource JavaDoc;
83 import java.awt.dnd.DragSourceContext JavaDoc;
84 import java.awt.dnd.DragSourceDragEvent JavaDoc;
85 import java.awt.dnd.DragSourceDropEvent JavaDoc;
86 import java.awt.dnd.DragSourceEvent JavaDoc;
87 import java.awt.dnd.DragSourceListener JavaDoc;
88 import java.awt.dnd.DropTarget JavaDoc;
89 import java.awt.dnd.DropTargetDragEvent JavaDoc;
90 import java.awt.dnd.DropTargetDropEvent JavaDoc;
91 import java.awt.dnd.DropTargetEvent JavaDoc;
92 import java.awt.dnd.DropTargetListener JavaDoc;
93 import java.awt.dnd.InvalidDnDOperationException JavaDoc;
94
95 /** The java swing API's imports */
96 import javax.swing.AbstractAction JavaDoc;
97 import javax.swing.ButtonGroup JavaDoc;
98 import javax.swing.JCheckBoxMenuItem JavaDoc;
99 import javax.swing.JMenu JavaDoc;
100 import javax.swing.JMenuBar JavaDoc;
101 import javax.swing.JMenuItem JavaDoc;
102 import javax.swing.JOptionPane JavaDoc;
103 import javax.swing.JRadioButtonMenuItem JavaDoc;
104 import javax.swing.JToolBar JavaDoc;
105 import javax.swing.JTree JavaDoc;
106 import javax.swing.JPopupMenu JavaDoc;
107 import javax.swing.Icon JavaDoc;
108 import javax.swing.event.TreeWillExpandListener JavaDoc;
109 import javax.swing.event.TreeSelectionListener JavaDoc;
110 import javax.swing.event.TreeSelectionEvent JavaDoc;
111 import javax.swing.event.TreeExpansionEvent JavaDoc;
112 import javax.swing.event.TreeExpansionListener JavaDoc;
113
114 import java.awt.Dimension JavaDoc;
115 import java.awt.Insets JavaDoc;
116 import java.awt.Point JavaDoc;
117 import java.awt.Component JavaDoc;
118 import java.awt.Rectangle JavaDoc;
119 import java.awt.event.ActionEvent JavaDoc;
120 import java.awt.event.MouseAdapter JavaDoc;
121 import java.awt.event.MouseEvent JavaDoc;
122
123 /** The java swing tree API's imports */
124 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
125 import javax.swing.tree.DefaultTreeModel JavaDoc;
126 import javax.swing.tree.DefaultTreeSelectionModel JavaDoc;
127 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
128 import javax.swing.tree.TreeNode JavaDoc;
129 import javax.swing.tree.TreePath JavaDoc;
130 import javax.swing.tree.TreeSelectionModel JavaDoc;
131
132 /**
133  * Implementation of a Entry tree which is dynamic.
134  * You can customize icons, panels and popup menus
135  * for every objects you display.
136  *
137  * @author <a HREF="mailto:Jerome.Moroy@lifl.fr">Jerome Moroy</a>
138  * @version 0.1
139  */

140 public class DynamicTree
141     extends JTree JavaDoc
142     implements TreeConfiguration, Tree, Autoscroll JavaDoc, RoleManagement {
143
144     // ==================================================================
145
//
146
// Internal states.
147
//
148
// ==================================================================
149

150     /** To access to the customization */
151     protected AdminCustomization custom;
152
153     /** Parent panel, use to refresh right panel */
154     protected ViewPanel viewPanel_;
155
156     /** Root node */
157     protected DefaultMutableTreeNode JavaDoc rootNode;
158
159     /** The graphical initial context (The entries might be replaced by their associated context) */
160     protected ContextContainer graphicalInitialContext_;
161     
162     /** The inital context. */
163     protected Vector JavaDoc initialContext_;
164
165     /** Model to manipulate node */
166     protected DefaultTreeModel JavaDoc treeModel;
167
168     /** Model to define what to do when a node is selected */
169     protected DefaultTreeSelectionModel JavaDoc selectionModel;
170
171     /** Model to display node */
172     protected DefaultTreeCellRenderer JavaDoc treeCellRenderer;
173
174     /** A map which informs about the node state (expanded or collapsed) */
175     protected Map JavaDoc nodeState_;
176
177     /** To know the selected node */
178     protected String JavaDoc selectedNode_;
179
180     /** To know the selected treepath*/
181     protected TreePath JavaDoc selectedTreePath_;
182
183     /** Panel display when any panel was found */
184     protected Panel blankPanel_;
185
186     /** The associated contextProperty */
187     protected ContextProperty contextProperty_;
188
189     /** The associated browserProperty */
190     protected XMLParser browserProperty_;
191     
192     /** The current TreeView*/
193     protected TreeView currentTreeView_;
194     
195     /** To know if the popup menus have to be enabled or not */
196     protected boolean popupEnabled_;
197     
198     /** To know if the Drag and Drop have to be enabled or not */
199     protected boolean dndEnabled_;
200     
201     /** To know if the application allows the selection of several roles at the same time. */
202     protected boolean multipleRolesEnabled_;
203     
204     /** The status bar */
205     protected StatusBar statusBar_;
206     
207     /** The MenuBar to use. */
208     protected JMenuBar JavaDoc menuBar_;
209
210     /** The ToolBar to use. */
211     protected JToolBar JavaDoc toolBar_ = null;
212     
213     /** The number of element of the toolBar which has to be removed. */
214     protected int nbElementsToRemove_ = 0;
215
216     /** The action menu. */
217     protected JMenu JavaDoc actionMenu_, roleMenu_;
218     
219     /** The PopupMenu corresponding to the selected node. */
220     protected JPopupMenu JavaDoc currentJPopupMenu_ = null;
221
222     /** List of elements which have already been added into the initial context. */
223     protected Vector JavaDoc alreadyInInitialContext_ = null;
224                 
225     // Drag and Drop attributes
226

227     /** The DragSource to use */
228     protected DragSource JavaDoc dragSource_;
229     
230     /** The DragGestureListener to use */
231     protected DragGestureListener JavaDoc dragGestureListener_;
232     
233     /** The DragSourceListener to use */
234     protected DragSourceListener JavaDoc dragSourceListener_;
235     
236     /** The dragAction */
237     protected int dragAction_ = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK;
238     
239     /** The allowed drop action */
240     protected int acceptableActions_ = DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK;
241
242     /** The DropTarget */
243     protected DropTarget JavaDoc dropTarget_;
244         
245     /** The DropTargetListener to use */
246     protected DropTargetListener JavaDoc dropTargetListener_;
247     
248     // ==================================================================
249
//
250
// Constructors.
251
//
252
// ==================================================================
253

254     /**
255      * Calls by the constructor
256      */

257     private void buildDnD(){
258         // Drag
259
dragSource_ = DragSource.getDefaultDragSource();
260         dragSourceListener_ = new TreeDragSourceListener();
261         dragGestureListener_ = new TreeDragGestureListener();
262         dragSource_.createDefaultDragGestureRecognizer(this, dragAction_, dragGestureListener_);
263         
264         // Drop
265
dropTargetListener_ = new TreeDropTargetListener();
266         dropTarget_ = new DropTarget JavaDoc(this, acceptableActions_, dropTargetListener_, true);
267     }
268
269     /**
270      * Builds a new DynamicTree
271      * @param initialContext The context to be displayed
272      * @param initAll Uses to know if the constructor may initialize all the attribute
273      */

274     private void build(ContextContainer initialContext, boolean initAll) {
275         graphicalInitialContext_ = initialContext;
276         if(initialContext instanceof InitialContextContainer)
277             ((InitialContextContainer)initialContext).setDynamicTree(this);
278         
279         rootNode = new DefaultMutableTreeNode JavaDoc(new DefaultEntry(graphicalInitialContext_,new DefaultName("Root"),null));
280         treeModel = new MyTreeModel(rootNode);
281         setModel(treeModel);
282
283         if (initAll) {
284             nodeState_ = new HashMap JavaDoc();
285             initialContext_ = new Vector JavaDoc();
286             alreadyInInitialContext_ = new Vector JavaDoc();
287             selectedNode_ = "";
288             blankPanel_ = new WhitePanel();
289             selectionModel = new DefaultTreeSelectionModel JavaDoc();
290             selectionModel.setSelectionMode(
291                 TreeSelectionModel.SINGLE_TREE_SELECTION);
292             setSelectionModel(selectionModel);
293             addMouseListener(new MyMouseAdapter());
294             addTreeWillExpandListener(new MyTreeWillExpandListener());
295             addTreeExpansionListener(new MyTreeExpansionListener());
296             addTreeSelectionListener(new MyTreeSelectionListener());
297             setCellRenderer(new MyTreeCellRenderer());
298             popupEnabled_ = true;
299             dndEnabled_ = true;
300             multipleRolesEnabled_ = false;
301             buildDnD();
302             setToolTipText("");
303         }
304
305         setShowsRootHandles(true);
306         collapseRow(0);
307         expandRow(0);
308
309         setRootVisible(false);
310     }
311
312     /**
313      * Constructs a new DynamicTree.
314      */

315     public DynamicTree() {
316         ContextContainerFactory ccf = new InitialContextContainerFactory(null);
317         build(ccf.create(), true);
318     }
319
320     /**
321      * Constructs a new DynamicTree initialized with the specified context.
322      * @param initialContext The context to be displayed
323      */

324     public DynamicTree(ContextContainer initialContext) {
325         build(initialContext, true);
326     }
327
328     // ==================================================================
329
//
330
// Internal methods.
331
//
332
// ==================================================================
333

334     /**
335      * Adds an entry to a node.
336      * @param parent Node which is the parent of the new entry
337      * @param child Entry to add
338      * @return The created node
339      */

340     protected DefaultMutableTreeNode JavaDoc addObject(
341         DefaultMutableTreeNode JavaDoc parent,
342         ExtendedEntry child) {
343         if (custom != null) {
344             Context context = custom.getContext(child.getValue());
345             if (context != null) {
346                 child.setOWValue(context);
347                 child.setWrappedObject(((Wrapper) context).getWrapped());
348             }
349         }
350         DefaultMutableTreeNode JavaDoc childNode = new DefaultMutableTreeNode JavaDoc(child);
351         if (parent == null) {
352             parent = rootNode;
353         }
354         treeModel.insertNodeInto(childNode, parent, parent.getChildCount());
355
356         return childNode;
357     }
358
359     /**
360      * Gets a string representation of the path
361      *
362      * @param node The node
363      * @return The path from th root to the node
364      *
365      */

366     protected String JavaDoc pathToString(DefaultMutableTreeNode JavaDoc node) {
367         StringBuffer JavaDoc sf = new StringBuffer JavaDoc();
368         Object JavaDoc[] o = node.getUserObjectPath();
369         for (int i = 0; i < o.length; i++) {
370             sf.append(((Entry) o[i]).getName().toString());
371             if (i != o.length - 1)
372                 sf.append("/");
373         }
374         return sf.toString();
375     }
376
377     /**
378      * Returns the entry associates to a node
379      * @param o The node
380      * @return The associated entry
381      */

382     protected Entry objectToEntry(Object JavaDoc o) {
383         if (o != null) {
384             DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) o;
385             return (Entry) node.getUserObject();
386         }
387         return null;
388     }
389
390     /**
391      * Gives the path of the object pointing by the cursor
392      * @param p The position of the cursor
393      */

394     protected TreePath JavaDoc getPath(Point JavaDoc p){
395         if(p!=null){
396             return getPathForLocation((int) p.getX(), (int) p.getY());
397         }
398         return null;
399     }
400
401     /**
402      * Shows the associated PopupMenu, if exists and if displaying is enabled
403      * @param p Point which indicates where is the mouse
404      */

405     protected void showMenu(Point JavaDoc p) {
406         TreePath JavaDoc path = getPath(p);
407         if (path != null) {
408             selectionModel.setSelectionPath(path);
409             Entry entry = objectToEntry(getLastSelectedPathComponent());
410             if (custom != null) {
411                 JPopupMenu JavaDoc menu = custom.getMenu((ExtendedEntry) entry);
412                 if (menu != null) {
413                     menu.show((Component JavaDoc) this,(int) (p.getX()),(int) (p.getY()));
414                 }
415             }
416         }
417     }
418
419     /**
420      * Gives the TreePath correspoding to the given id
421      * @param id The id of the node of the tree
422      * @return The associated TreePath or null
423      */

424     protected TreePath JavaDoc getPathFromInitialContext(String JavaDoc id) {
425         if (id != null) {
426             Enumeration JavaDoc children = rootNode.children();
427             while (children.hasMoreElements()) {
428                 DefaultMutableTreeNode JavaDoc childNode = (DefaultMutableTreeNode JavaDoc) children.nextElement();
429                 Entry entry = (Entry) childNode.getUserObject();
430                 if (entry.getName().toString().equals(id))
431                     return new TreePath JavaDoc(childNode.getPath());
432             }
433         }
434         return null;
435     }
436
437     /**
438      * Copies the content of the initialContext into the graphicalIntialContext
439      */

440     protected void createGraphicalInitialContext() {
441         // Clears the existing initial context.
442
graphicalInitialContext_.clear();
443         if(custom!=null){
444             // Finds and copies the root context
445
Entry[] entries = custom.getRoot();
446             for (int i = 0 ; i < entries.length ; i++){
447                 InitialEntry initialEntry = null;
448                 try{
449                     initialEntry = (InitialEntry)entries[i];
450                 } catch (ClassCastException JavaDoc e) {
451                     initialEntry = new InitialEntry(entries[i].getName().toString(), entries[i].getValue(), 0);
452                 }
453                 addToInitialContext(initialEntry.getName().toString(), initialEntry.getValue(), initialEntry.getLevel());
454             }
455         }
456         // Copies the content of the initialContext
457
InitialEntry entryToAdd = null;
458         for(int i=0 ; i<initialContext_.size() ; i++) {
459             entryToAdd = (InitialEntry)initialContext_.get(i);
460             addToInitialContext(entryToAdd.getName().toString(), entryToAdd.getValue(), entryToAdd.getLevel());
461         }
462         
463     }
464
465     /**
466      * Open the tree nodes until a specific level
467      *
468      * @param root The root TreePath to develop
469      * @param level The level (>0 for a specific level)
470      */

471     protected void openTree(TreePath JavaDoc root, int level) {
472         if (level > 0) {
473             DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) root.getLastPathComponent();
474             Enumeration JavaDoc children = node.children();
475             while (children.hasMoreElements()) {
476                 DefaultMutableTreeNode JavaDoc childNode = (DefaultMutableTreeNode JavaDoc) children.nextElement();
477                 TreePath JavaDoc p = new TreePath JavaDoc(childNode.getPath());
478                 expandPath(p);
479                 openTree(p, level - 1);
480             }
481             // }else if (level <0){
482
// for(int i=0;i<getRowCount();i++)
483
// expandRow(i);
484
}
485     }
486
487     /**
488      * Refreshes the view panel
489      */

490     protected void refreshPanel(){
491         if(viewPanel_!=null){
492             // Obtaining the current panel
493
Panel currentPanel = viewPanel_.getViewPanel();
494             if(currentPanel!=null && currentTreeView_!=null)
495                 currentPanel.unselected(currentTreeView_);
496             Entry entry = null;
497             Object JavaDoc object = getLastSelectedPathComponent();
498             String JavaDoc newSelectedNode = null;
499             if (object != null) {
500                 DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) object;
501                 if (!node.equals(rootNode)) {
502                     newSelectedNode = pathToString(node);
503                 }
504                 entry = (Entry) node.getUserObject();
505             }
506             if (newSelectedNode==null || newSelectedNode.equals("")) {
507                 viewPanel_.setViewPanel(blankPanel_);
508             } else if (selectedNode_ != null && newSelectedNode != null && !selectedNode_.equals(newSelectedNode)) {
509                 // New selected node
510
selectedNode_ = newSelectedNode;
511                 // Obtaining the new panel
512
Panel panel = null;
513                 Table table = null;
514                 if (entry != null && custom != null) {
515                     
516                     panel = custom.getPanel((ExtendedEntry) entry);
517                     if (panel != null) {
518                         currentTreeView_ = new DefaultTreeView(this);
519                         panel.selected(currentTreeView_);
520                         viewPanel_.setViewPanel(panel);
521                     }
522                     
523                /* // Look for a panel for the wrapped object by the entry
524                     panel = custom.getPanel(((ExtendedEntry)entry).getWrappedObject(), true);
525                     if(panel==null) {
526                         // Look for a table for the wrapped object by the entry
527                         table = custom.getTable(((ExtendedEntry)entry).getWrappedObject(), true);
528                     }
529                     if(panel==null && table==null) {
530                         // Look for a panel for the value of the entry
531                         panel = custom.getPanel(entry.getValue());
532                         if(panel==null) {
533                             // Look for a table for the value of the entry
534                             table = custom.getTable(entry.getValue());
535                         }
536                     }
537                     // A table is defined
538                     if(panel == null && table != null){
539                         if(contextProperty_!=null)
540                             panel = new DefaultTablePanel(table, custom, contextProperty_.getDecoder());
541                         else
542                             panel = new DefaultTablePanel(table, custom);
543                     }
544                     if (panel != null) {
545                         currentTreeView_ = new DefaultTreeView(this);
546                         panel.selected(currentTreeView_);
547                         viewPanel_.setViewPanel(panel);
548                     }
549                */

550                 }
551                 if (entry == null || custom == null || panel == null) {
552                     viewPanel_.setViewPanel(blankPanel_);
553                 }
554             }
555         }
556     }
557
558     /**
559      * Refreshes the status bar depending on the selected object
560      */

561     protected void refreshStatusBar(){
562         if(statusBar_!=null){
563             Entry entry = null;
564             Object JavaDoc object = getLastSelectedPathComponent();
565             if (object != null) {
566                 DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) object;
567                 entry = (Entry) node.getUserObject();
568             }
569             if (entry != null && custom != null) {
570                 Info info = custom.getInfo((ExtendedEntry) entry);
571                 if (info != null) {
572                     statusBar_.setText(info.getInfo(new DefaultTreeView(this)));
573                 } else {
574                     statusBar_.setText("");
575                 }
576             } else {
577                 statusBar_.setText("");
578             }
579         }
580     }
581
582     /**
583      * Refreshes the action menu depending on the selected object.
584      */

585     protected void refreshActionMenu(){
586         if(menuBar_!=null && actionMenu_ != null){
587             Entry entry = null;
588             Object JavaDoc object = getLastSelectedPathComponent();
589             if (object != null) {
590                 DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) object;
591                 entry = (Entry) node.getUserObject();
592             }
593             if (entry != null && custom != null) {
594                 currentJPopupMenu_ = custom.getMenu((ExtendedEntry) entry);
595                 actionMenu_.removeAll();
596                 Component JavaDoc[] componentList = currentJPopupMenu_.getComponents();
597                 if(componentList.length>0){
598                     actionMenu_.setEnabled(true);
599                     for(int i=0; i<componentList.length;i++){
600                         if(JPopupMenu.Separator JavaDoc.class.isAssignableFrom(componentList[i].getClass()))
601                             actionMenu_.addSeparator();
602                         else
603                             actionMenu_.add((JMenuItem JavaDoc)componentList[i]);
604                     }
605                 } else {
606                     actionMenu_.setEnabled(false);
607                 }
608                 actionMenu_.revalidate();
609             }
610         }
611     }
612
613     protected void refreshToolBar(){
614         if(toolBar_!=null){
615             // Removes the old elements
616
if(nbElementsToRemove_>0){
617                 int nbComp = toolBar_.getComponentCount();
618                 for(int i = nbComp - 1 ; i >= nbComp - nbElementsToRemove_ ; i--)
619                     toolBar_.remove(i);
620                 nbElementsToRemove_ = 0;
621             }
622             
623             // Adds the new elements
624
Entry entry = null;
625             Object JavaDoc object = getLastSelectedPathComponent();
626             if (object != null) {
627                 DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) object;
628                 entry = (Entry) node.getUserObject();
629             }
630             if (entry != null && custom != null) {
631                 currentJPopupMenu_ = custom.getMenu((ExtendedEntry) entry);
632                 Component JavaDoc[] componentList = currentJPopupMenu_.getComponents();
633                 if(componentList.length>0){
634                     boolean isFirst = true;
635                     boolean iconDisplayed = false;
636                     for(int i=0; i<componentList.length;i++){
637                         if(!JPopupMenu.Separator JavaDoc.class.isAssignableFrom(componentList[i].getClass())){
638                             if(((DefaultAction)((JMenuItem JavaDoc)componentList[i]).getAction()).isUserIcon()){
639                                 if(isFirst){
640                                     isFirst = false;
641                                     if(toolBar_.getComponentCount()>0){
642                                         toolBar_.addSeparator();
643                                         nbElementsToRemove_++;
644                                     }
645                                 }
646                                 toolBar_.add(((JMenuItem JavaDoc)componentList[i]).getAction());
647                                 iconDisplayed = true;
648                                 nbElementsToRemove_++;
649                             }
650                         } else if(iconDisplayed){
651                             toolBar_.addSeparator();
652                             iconDisplayed = false;
653                             nbElementsToRemove_++;
654                         }
655                     }
656                 }
657             }
658             if(toolBar_.getComponentCount()==0){
659                 toolBar_.setVisible(false);
660             } else{
661                 toolBar_.setVisible(false);
662                 toolBar_.setVisible(true);
663             }
664         }
665     }
666
667     /**
668      * Returns true if the context has at least one child.
669      * @param context The context to check
670      * @return true if the context has children
671      */

672     protected boolean hasChild(Context context) {
673         if(context!=null){
674             Entry[] entries = context.getEntries();
675             return (entries.length > 0);
676         }
677         return false;
678     }
679
680