KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > tax > beans > editor > TreeNodeFilterCustomEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.tax.beans.editor;
20
21 import java.util.*;
22 import java.awt.event.KeyAdapter JavaDoc;
23 import java.awt.event.KeyEvent JavaDoc;
24 import javax.swing.*;
25 import javax.swing.table.AbstractTableModel JavaDoc;
26 import javax.swing.event.ListSelectionListener JavaDoc;
27 import javax.swing.event.ListSelectionEvent JavaDoc;
28
29 import org.openide.util.HelpCtx;
30 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor;
31
32 import org.netbeans.tax.*;
33 import org.netbeans.tax.traversal.TreeNodeFilter;
34 import org.netbeans.modules.xml.tax.util.TAXUtil;
35
36 /**
37  *
38  * @author Libor Kramolis
39  * @version 0.1
40  */

41 public class TreeNodeFilterCustomEditor extends JPanel implements EnhancedCustomPropertyEditor {
42     /** */
43     private static final long serialVersionUID = 1767193347881681541L;
44
45     
46     /** */
47     private static final Map publicNodeTypeNamesMap = new HashMap();
48
49
50     //
51
// Static initialization
52
//
53

54     static {
55         publicNodeTypeNamesMap.put (TreeNode.class, Util.THIS.getString ("NAME_Any_Node_Type"));
56         publicNodeTypeNamesMap.put (TreeParentNode.class, Util.THIS.getString ("NAME_Any_Parent_Node_Type"));
57         publicNodeTypeNamesMap.put (TreeCharacterData.class, Util.THIS.getString ("NAME_Any_Character_Data_Node_Type"));
58         publicNodeTypeNamesMap.put (TreeReference.class, Util.THIS.getString ("NAME_Any_Reference_Node_Type"));
59 // publicNodeTypeNamesMap.put (TreeEntityReference.class, Util.THIS.getString ("NAME_Any_Entity_Reference_Node_Type"));
60
publicNodeTypeNamesMap.put (TreeNodeDecl.class, Util.THIS.getString ("NAME_Any_Declaration_Node_Type"));
61
62         publicNodeTypeNamesMap.put (TreeComment.class, Util.THIS.getString ("NAME_Comment_Node_Type"));
63         publicNodeTypeNamesMap.put (TreeProcessingInstruction.class, Util.THIS.getString ("NAME_Processing_Instruction_Node_Type"));
64         publicNodeTypeNamesMap.put (TreeText.class, Util.THIS.getString ("NAME_Text_Node_Type"));
65         publicNodeTypeNamesMap.put (TreeCDATASection.class, Util.THIS.getString ("NAME_CDATA_Section_Node_Type"));
66         publicNodeTypeNamesMap.put (TreeElement.class, Util.THIS.getString ("NAME_Element_Node_Type"));
67         publicNodeTypeNamesMap.put (TreeAttribute.class, Util.THIS.getString ("NAME_Attribute_Node_Type"));
68 // publicNodeTypeNamesMap.put (TreeDocument.class, Util.THIS.getString ("NAME_Document_Node_Type"));
69
// publicNodeTypeNamesMap.put (TreeDTD.class, Util.THIS.getString ("NAME_DTD_Node_Type"));
70
publicNodeTypeNamesMap.put (TreeConditionalSection.class, Util.THIS.getString ("NAME_Conditional_Section_Node_Type"));
71         publicNodeTypeNamesMap.put (TreeDocumentType.class, Util.THIS.getString ("NAME_Document_Type_Node_Type"));
72         publicNodeTypeNamesMap.put (TreeGeneralEntityReference.class, Util.THIS.getString ("NAME_General_Entity_Reference_Node_Type"));
73         publicNodeTypeNamesMap.put (TreeParameterEntityReference.class, Util.THIS.getString ("NAME_Parameter_Entity_Reference_Node_Type"));
74         publicNodeTypeNamesMap.put (TreeElementDecl.class, Util.THIS.getString ("NAME_Element_Declaration_Node_Type"));
75         publicNodeTypeNamesMap.put (TreeEntityDecl.class, Util.THIS.getString ("NAME_Entity_Declaration_Node_Type"));
76         publicNodeTypeNamesMap.put (TreeAttlistDecl.class, Util.THIS.getString ("NAME_Attlist_Declaration_Node_Type"));
77         publicNodeTypeNamesMap.put (TreeNotationDecl.class, Util.THIS.getString ("NAME_Notation_Declaration_Node_Type"));
78     }
79
80
81     /** */
82     private final TreeNodeFilter filter;
83     
84     /** */
85     private final List nodeTypesList;
86
87     /** */
88     private NodeTypesTableModel tableModel;
89
90
91     //
92
// init
93
//
94

95     
96     /** Creates new TreeNodeFilterEditor */
97     public TreeNodeFilterCustomEditor (TreeNodeFilter filter) {
98         this.filter = filter;
99         this.nodeTypesList = new LinkedList (Arrays.asList (filter.getNodeTypes()));
100         
101         initComponents();
102         ownInitComponents();
103         initAccessibility();
104
105         HelpCtx.setHelpIDString (this, this.getClass().getName());
106     }
107
108
109     /**
110      */

111     private void ownInitComponents () {
112         tableModel = (NodeTypesTableModel)nodeTypesTable.getModel();
113
114         ListSelectionModel selModel = nodeTypesTable.getSelectionModel();
115         selModel.addListSelectionListener (new ListSelectionListener JavaDoc () {
116                 public void valueChanged (ListSelectionEvent JavaDoc e) {
117                     if (e.getValueIsAdjusting())
118                         return;
119                     ListSelectionModel lsm = (ListSelectionModel)e.getSource();
120                     if (lsm.isSelectionEmpty()) {
121                         removeButton.setEnabled (false);
122                     } else {
123                         removeButton.setEnabled (true);
124                     }
125                 }
126             });
127             
128 // Object[] array = publicNodeTypeNamesMap.keySet().toArray();
129
// for (int i = 0; i < array.length; i++) {
130
// array[i] = new NamedClass ((Class)array[i]);
131
// }
132
// Arrays.sort (array, new NamedClassComparator());
133
// JComboBox cb = new JComboBox (array);
134

135         JComboBox cb = new JComboBox (getPublicNodeTypesInheritanceTree());
136         cb.setEditable (false);
137         DefaultCellEditor dce = new DefaultCellEditor (cb);
138 // dce.setClickCountToStart (2);
139
nodeTypesTable.getColumnModel().getColumn (0).setCellEditor (dce);
140     }
141
142     
143     /**
144      * @return Returns the property value that is result of the CustomPropertyEditor.
145      * @exception InvalidStateException when the custom property editor does not represent valid property value
146      * (and thus it should not be set)
147      */

148     public Object JavaDoc getPropertyValue () throws IllegalStateException JavaDoc {
149         short acceptPolicy = acceptRadioButton.isSelected() ?
150             TreeNodeFilter.ACCEPT_TYPES :
151             TreeNodeFilter.REJECT_TYPES;
152         Class JavaDoc[] nodeTypes = (Class JavaDoc[])nodeTypesList.toArray (new Class JavaDoc[0]);
153
154         return new TreeNodeFilter (nodeTypes, acceptPolicy);
155     }
156
157
158     /** This method is called from within the constructor to
159      * initialize the form.
160      * WARNING: Do NOT modify this code. The content of this method is
161      * always regenerated by the FormEditor.
162      */

163     private void initComponents() {//GEN-BEGIN:initComponents
164
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
165
166         acceptPolicyGroup = new javax.swing.ButtonGroup JavaDoc();
167         acceptPolicyPanel = new javax.swing.JPanel JavaDoc();
168         acceptRejectLabel = new javax.swing.JLabel JavaDoc();
169         rbPanel = new javax.swing.JPanel JavaDoc();
170         acceptRadioButton = new javax.swing.JRadioButton JavaDoc();
171         acceptRadioButton.setSelected (filter.getAcceptPolicy() == TreeNodeFilter.ACCEPT_TYPES);
172         rejectRadioButton = new javax.swing.JRadioButton JavaDoc();
173         rejectRadioButton.setSelected (filter.getAcceptPolicy() == TreeNodeFilter.REJECT_TYPES);
174         tablePanel = new javax.swing.JPanel JavaDoc();
175         tableScrollPane = new javax.swing.JScrollPane JavaDoc();
176         nodeTypesTable = new javax.swing.JTable JavaDoc();
177         nodeTypesTable.setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
178         addButton = new javax.swing.JButton JavaDoc();
179         removeButton = new javax.swing.JButton JavaDoc();
180
181         setLayout(new java.awt.BorderLayout JavaDoc());
182
183         acceptPolicyPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
184
185         acceptRejectLabel.setText(Util.THIS.getString ("LBL_acceptReject"));
186         acceptRejectLabel.setLabelFor(rbPanel);
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
189         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
190         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
191         acceptPolicyPanel.add(acceptRejectLabel, gridBagConstraints);
192
193         rbPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
194
195         acceptRadioButton.setText(Util.THIS.getString ("LBL_showItRadioButton"));
196         acceptPolicyGroup.add(acceptRadioButton);
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 0;
199         gridBagConstraints.gridy = 0;
200         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
201         gridBagConstraints.weightx = 1.0;
202         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
203         rbPanel.add(acceptRadioButton, gridBagConstraints);
204
205         rejectRadioButton.setText(Util.THIS.getString ("LBL_hideItRadioButton"));
206         acceptPolicyGroup.add(rejectRadioButton);
207         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
208         gridBagConstraints.gridx = 0;
209         gridBagConstraints.gridy = 1;
210         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
211         gridBagConstraints.weightx = 1.0;
212         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
213         rbPanel.add(rejectRadioButton, gridBagConstraints);
214
215         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
216         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
217         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
218         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
219         gridBagConstraints.weightx = 1.0;
220         gridBagConstraints.weighty = 1.0;
221         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 11);
222         acceptPolicyPanel.add(rbPanel, gridBagConstraints);
223
224         add(acceptPolicyPanel, java.awt.BorderLayout.NORTH);
225
226         tablePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
227
228         nodeTypesTable.setModel(new NodeTypesTableModel());
229         nodeTypesTable.setPreferredScrollableViewportSize(new java.awt.Dimension JavaDoc(300, 200));
230         tableScrollPane.setViewportView(nodeTypesTable);
231
232         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
233         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
234         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
235         gridBagConstraints.weightx = 1.0;
236         gridBagConstraints.weighty = 1.0;
237         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 12, 0, 0);
238         tablePanel.add(tableScrollPane, gridBagConstraints);
239
240         addButton.setText(Util.THIS.getString ("LBL_addButton"));
241         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
242             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
243                 addButtonActionPerformed(evt);
244             }
245         });
246
247         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
248         gridBagConstraints.gridx = 1;
249         gridBagConstraints.gridy = 0;
250         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
251         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
253         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 11, 0, 11);
254         tablePanel.add(addButton, gridBagConstraints);
255
256         removeButton.setText(Util.THIS.getString ("LBL_removeButton"));
257         removeButton.setEnabled(false);
258         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
259             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
260                 removeButtonActionPerformed(evt);
261             }
262         });
263
264         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
265         gridBagConstraints.gridx = 1;
266         gridBagConstraints.gridy = 1;
267         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
268         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
269         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
271         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 11, 11, 11);
272         tablePanel.add(removeButton, gridBagConstraints);
273
274         add(tablePanel, java.awt.BorderLayout.CENTER);
275
276     }//GEN-END:initComponents
277

278     private void removeButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeButtonActionPerformed
279
// Add your handling code here:
280
int sel = nodeTypesTable.getSelectedRow();
281         if (sel != -1) {
282             tableModel.removeRow (sel);
283
284             int numRows = nodeTypesTable.getModel().getRowCount();
285             if (numRows > 0) {
286                 sel = Math.min (sel, numRows - 1);
287                 nodeTypesTable.getSelectionModel().setSelectionInterval (sel, sel);
288             }
289         }
290     }//GEN-LAST:event_removeButtonActionPerformed
291

292     private void addButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addButtonActionPerformed
293
// Add your handling code here:
294
nodeTypesList.add (TreeNode.class);
295         tableModel.fireTableDataChanged();
296     }//GEN-LAST:event_addButtonActionPerformed
297

298     
299     // Variables declaration - do not modify//GEN-BEGIN:variables
300
private javax.swing.JRadioButton JavaDoc rejectRadioButton;
301     private javax.swing.JPanel JavaDoc rbPanel;
302     private javax.swing.JPanel JavaDoc acceptPolicyPanel;
303     private javax.swing.JButton JavaDoc addButton;
304     private javax.swing.JLabel JavaDoc acceptRejectLabel;
305     private javax.swing.JScrollPane JavaDoc tableScrollPane;
306     private javax.swing.JTable JavaDoc nodeTypesTable;
307     private javax.swing.JRadioButton JavaDoc acceptRadioButton;
308     private javax.swing.JPanel JavaDoc tablePanel;
309     private javax.swing.ButtonGroup JavaDoc acceptPolicyGroup;
310     private javax.swing.JButton JavaDoc removeButton;
311     // End of variables declaration//GEN-END:variables
312

313
314     
315     //
316
// class RowKeyListener
317
//
318

319     /** deletes whole row by pressing DELETE on row column. */
320     private class RowKeyListener extends KeyAdapter JavaDoc {
321         
322         /** */
323         private JTable table;
324         
325         
326         //
327
// init
328
//
329

330         public RowKeyListener (JTable table) {
331             this.table = table;
332         }
333         
334         
335         //
336
// itself
337
//
338

339         /**
340          */

341         public void keyReleased (KeyEvent JavaDoc e) {
342             if (e.getKeyCode() == KeyEvent.VK_DELETE) {
343                 tableModel.removeRow (table.getSelectedRow());
344             }
345         }
346     }
347
348
349     //
350
// class NodeTypesTableModel
351
//
352

353     /**
354      *
355      */

356     private class NodeTypesTableModel extends AbstractTableModel JavaDoc {
357
358         private static final long serialVersionUID =-1438087942670592779L;
359         
360         /**
361          */

362         public void removeRow (int row) {
363             nodeTypesList.remove (row);
364             fireTableDataChanged();
365         }
366
367
368         /** Returns the number of rows in the model */
369         public int getRowCount () {
370             return nodeTypesList.size();
371         }
372
373         /** Returns the number of columns in the model */
374         public int getColumnCount () {
375             return 1;
376         }
377
378         /** Returns the class for a model. */
379         public Class JavaDoc getColumnClass (int index) {
380             return Class JavaDoc.class;
381         }
382
383     /**
384      */

385         public Object JavaDoc getValueAt (int row, int column) {
386             Object JavaDoc retVal = new Item (new NamedClass ((Class JavaDoc)nodeTypesList.get (row)));
387
388             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("<-- getValue: row = " + row); // NOI18N
389
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("<-- getValue: column = " + column); // NOI18N
390
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("<-- getValue: " + retVal.getClass().getName() + " -- '" + retVal + "'"); // NOI18N
391

392             return retVal;
393         }
394
395     /**
396      */

397         public void setValueAt (Object JavaDoc val, int row, int column) {
398             if ( row >= nodeTypesList.size() ) {
399                 // fixed ArrayIndexOutOfBounds on nodeTypesList.set (row, type);
400
// 1) select last row of multi row table
401
// 2) try to edit -- show combo box
402
// 3) remove this row
403
// 4) click to another row
404
// 5) exception occur
405
return;
406             }
407
408             Class JavaDoc type = null;
409
410             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("--> setValue: " + val.getClass().getName() + " -- '" + val + "'"); // NOI18N
411
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("--> setValue: row = " + row); // NOI18N
412
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("--> setValue: column = " + column); // NOI18N
413

414             if ( val instanceof String JavaDoc ) {
415                 try {
416                     type = Class.forName (val.toString());
417                 } catch (ClassNotFoundException JavaDoc exc) {
418                     // DO NOTHING
419
}
420             } else if ( val instanceof Item ) {
421                 type = ((Item)val).clazz.clazz;
422             } else if ( val instanceof NamedClass ) {
423                 type = ((NamedClass)val).clazz;
424             }
425             
426             if ( ( type == null ) ||
427                  ( TreeNodeFilter.isValidNodeType (type) == false ) ) {
428                 TAXUtil.notifyWarning (Util.THIS.getString ("MSG_invalidNodeType", val.toString()));
429                 return;
430             }
431             nodeTypesList.set (row, type);
432         }
433
434     /**
435      */

436         public String JavaDoc getColumnName (int column) {
437             return Util.THIS.getString ("LBL_nodeType");
438         }
439
440         /** Returns true for all cells which are editable. For a
441          * a new cell is editable only name field.
442          */

443         public boolean isCellEditable (int rowIndex, int columnIndex) {
444             return true;
445         }
446
447     } // end: class NodeTypesTableModel
448

449
450     //
451
// NamedClass
452
//
453

454     /**
455      *
456      */

457     private static class NamedClass {
458
459         /** */
460         private final Class JavaDoc clazz;
461         
462         /** */
463         public NamedClass (Class JavaDoc clazz) {
464             this.clazz = clazz;
465         }
466
467
468         /**
469          */

470         public String JavaDoc toString () {
471             String JavaDoc name = (String JavaDoc)publicNodeTypeNamesMap.get (clazz);
472
473             if ( name == null ) {
474                 name = clazz.getName();
475             }
476
477             return name;
478         }
479
480         /**
481          */

482         public boolean equals (Object JavaDoc obj) {
483             if ( (obj instanceof NamedClass) == false ) {
484                 return false;
485             }
486             NamedClass peer = (NamedClass)obj;
487             return clazz.equals (peer.clazz);
488         }
489
490     } // end: class NamedClass
491

492
493     //
494
// NamedClassComparator
495
//
496

497     /**
498      *
499      */

500     private static class NamedClassComparator implements Comparator {
501
502         /**
503          */

504         public int compare (Object JavaDoc obj1, Object JavaDoc obj2) throws ClassCastException JavaDoc {
505             return (obj1.toString().compareTo (obj2.toString()));
506         }
507
508         /**
509          */

510         public boolean equals (Object JavaDoc obj) {
511             return ( obj instanceof NamedClassComparator );
512         }
513
514     } // end: class NamedClassComparator
515

516
517
518     //
519
// InheritanceTree
520
//
521

522     /** */
523     private static Vector publicNodeTypesInheritanceTree;
524
525
526     /**
527      */

528     private static Vector getPublicNodeTypesInheritanceTree () {
529         if ( publicNodeTypesInheritanceTree == null ) {
530             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("Init Set"); // NOI18N
531

532             Item rootItem = new Item();
533             Object JavaDoc[] array = publicNodeTypeNamesMap.keySet().toArray();
534             for (int i = 0; i < array.length; i++) {
535                 Class JavaDoc clazz = (Class JavaDoc)array[i];
536                 Item.insertItemIntoLayer (rootItem.layer, Item.getItem (clazz));
537                 
538                 if ( clazz.isInterface() ) {
539                     for (int j = 0; j < i; j++) {
540                         Item.insertItemIntoLayer (rootItem.layer, Item.getItem ((Class JavaDoc)array[j]));
541                     }
542                 }
543             }
544             
545             publicNodeTypesInheritanceTree = new Vector();
546             fillPublicNodeTypesInheritanceTree (rootItem.layer, ""); // NOI18N
547

548             Item.itemMap.clear();
549             Item.itemMap = null;
550             rootItem = null;
551         }
552
553         return publicNodeTypesInheritanceTree;
554     }
555     
556     /**
557      */

558     private static void fillPublicNodeTypesInheritanceTree (Set layer, String JavaDoc prefix) {
559         Iterator it = layer.iterator();
560         while ( it.hasNext() ) {
561             Item item = (Item) it.next();
562             String JavaDoc itemPrefix = ""; // NOI18N
563
if ( prefix.length() != 0 ) {
564                 if ( it.hasNext() ) {
565                     itemPrefix = prefix + "|- "; // NOI18N
566
} else {
567                     itemPrefix = prefix + "`- "; // NOI18N
568
}
569             }
570             Item newItem = new Item (item, itemPrefix);
571             
572             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (">>" + newItem.toString() + "<<"); // NOI18N
573

574             publicNodeTypesInheritanceTree.add (newItem);
575
576             String JavaDoc newPrefix;
577             if ( prefix.length() == 0 ) {
578                 newPrefix = " "; // NOI18N
579
} else {
580                 if ( it.hasNext() ) {
581                     newPrefix = prefix + "| "; // NOI18N
582
} else {
583                     newPrefix = prefix + " "; // NOI18N
584
}
585             }
586             fillPublicNodeTypesInheritanceTree (item.layer, newPrefix);
587         }
588     }
589
590
591     /**
592      *
593      */

594     private static class Item {
595         /** */
596         private static Map itemMap;
597
598         /** */
599         private final NamedClass clazz;
600         /** */
601         private final Set layer;
602         /** */
603         private final String JavaDoc prefix;
604
605         /** */
606         private Item (NamedClass clazz, Set layer, String JavaDoc prefix) {
607             this.clazz = clazz;
608             this.layer = layer;
609             this.prefix = prefix;
610         }
611
612         /** */
613         private Item (Item item, String JavaDoc prefix) {
614             this (item.clazz, null, prefix);
615         }
616
617         /** */
618         private Item (NamedClass clazz) {
619             this (clazz, new TreeSet (new NamedClassComparator()), new String JavaDoc());
620         }
621
622         /** */
623         private Item () {
624             this (new NamedClass (null));
625         }
626
627
628         /**
629          */

630         public String JavaDoc toString () {
631             return prefix + clazz.toString();
632         }
633
634
635         /**
636          */

637         public boolean equals (Object JavaDoc obj) {
638             if ( (obj instanceof Item) == false ) {
639                 return false;
640             }
641
642             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("___ Item::equals: this = " + this); // NOI18N
643
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("___ ::equals: obj = " + obj); // NOI18N
644

645             Item peer = (Item)obj;
646             return clazz.equals (peer.clazz);
647         }
648
649
650         /**
651          */

652         private static Item getItem (Class JavaDoc clazz) {
653             if ( itemMap == null ) {
654                 itemMap = new HashMap();
655             }
656             
657             Item item = (Item) itemMap.get (clazz);
658             if ( item == null ) {
659                 itemMap.put (clazz, item = new Item (new NamedClass (clazz)));
660             }
661             return item;
662         }
663
664         /**
665          */

666         private static void insertItemIntoLayer (Set layer, Item newItem) {
667             if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug ("\n\nInsert newItem : " + newItem); // NOI18N
668
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : set = " + layer); // NOI18N
669

670             boolean inserted = false;
671
672             Object JavaDoc[] array = layer.toArray();
673             for (int i = 0; i < array.length; i++) {
674                 Item item = (Item) array[i];
675             
676                 if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : item [" + i + "] = " + item); // NOI18N
677

678                 if ( item.clazz.clazz == newItem.clazz.clazz ) { // previously inserted
679
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : #1 -= [ ITEM.clazz.clazz == NEW_ITEM.clazz.clazz => IGNORE insert ]=-"); // NOI18N
680
// DO NOTHING
681
inserted = true;
682                 } else if ( item.clazz.clazz.isAssignableFrom (newItem.clazz.clazz) ) { // II.
683
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : #2 -= [ NEW_ITEM is subclass of actual ITEM => insert to ITEM.LAYER ]=-"); // NOI18N
684

685                     insertItemIntoLayer (item.layer, newItem);
686                     inserted = true;
687                 } else if ( newItem.clazz.clazz.isAssignableFrom (item.clazz.clazz) ) { // I.
688
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : #3 -= [ actual ITEM '" + item + "' is subclass of NEW_ITEM => item REMOVED & insert to NEW_ITEM.LAYER ]=-"); // NOI18N
689

690                     if ( newItem.clazz.clazz.isInterface() == false ) {
691                         layer.remove (item);
692                         insertItemIntoLayer (newItem.layer, item);
693                     }
694                 }
695             }
696
697             if ( inserted == false ) { // III.
698
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug (" Item : #4 -= [ item '" + newItem + "' INSERTED into " + layer + " ] =-"); // NOI18N
699

700                 layer.add (newItem);
701             }
702         }
703
704     }
705     
706    /** Initialize accesibility
707      */

708     public void initAccessibility(){
709         
710        this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_TreeNodeFilterCustomEditor"));
711        
712        acceptRadioButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_acceptRejectLabel"));
713        acceptRadioButton.setMnemonic((Util.THIS.getString ("LBL_showItRadioButton_Mnem")).charAt(0));
714        
715        rejectRadioButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_rejectRadioButton"));
716        rejectRadioButton.setMnemonic((Util.THIS.getString ("LBL_hideItRadioButton_Mnem")).charAt(0));
717        
718        addButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_addButton1"));
719        addButton.setMnemonic((Util.THIS.getString ("LBL_addButton_Mnem")).charAt(0));
720        
721        removeButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_removeButton1"));
722        removeButton.setMnemonic((Util.THIS.getString ("LBL_removeButton_Mnem")).charAt(0));
723        
724        nodeTypesTable.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_nodeTypesTable"));
725        nodeTypesTable.getAccessibleContext().setAccessibleName(Util.THIS.getString("ACSN_nodeTypesTable"));
726     }
727
728
729     // debug
730
public static final void main (String JavaDoc[] args) throws Exception JavaDoc {
731         Vector vector = getPublicNodeTypesInheritanceTree();
732
733 // Iterator it = vector.iterator();
734
// System.out.println ("+==================================="); // NOI18N
735
// while (it.hasNext()) {
736
// System.out.println ("-= [ " + it.next().toString() + " ] =-"); // NOI18N
737
// }
738
}
739
740 }
741
Popular Tags