KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > naming > namemanager > NSTable


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20
21 package org.jacorb.naming.namemanager;
22
23 import java.util.*;
24 import javax.swing.table.*;
25
26 public class NSTable
27     extends javax.swing.JTable JavaDoc
28 {
29     private ContextNode current;
30     private NSTableCellRenderer nsRenderer;
31
32     /**
33      * NSTable constructor comment.
34      */

35     
36     public NSTable()
37     {
38         super( new NSTableModel());
39         setShowGrid(false);
40         setAutoCreateColumnsFromModel(false);
41         setDoubleBuffered(true);
42         setCellSelectionEnabled(false);
43         setColumnSelectionAllowed(false);
44         nsRenderer = new NSTableCellRenderer();
45     }
46
47     public TableCellRenderer getCellRenderer(int row, int column)
48     {
49         String JavaDoc type = (String JavaDoc)getValueAt(row,2);
50
51         if (type.startsWith("IDL:omg.org/CosNaming/NamingContext"))
52         {
53             return nsRenderer;
54         }
55         else
56             return super.getCellRenderer(row, column);
57     }
58
59     /**
60      * @return the context node that is the source for this table
61      */

62     public ContextNode currentSource()
63     {
64         return current;
65     }
66
67     /**
68      *
69      * @param newData Vector
70      */

71     public void setData(Vector newData, ContextNode currentSource)
72     {
73         current = currentSource;
74         ((NSTableModel)super.getModel()).setDataVector( newData );
75     }
76
77     /**
78      * unbind a name and remove it from the table
79      */

80     public synchronized void unbind()
81     {
82         int row = getSelectedRow();
83         if( row > -1 )
84         {
85             try
86             {
87                 org.omg.CosNaming.NameComponent JavaDoc[] ncs =
88                     new org.omg.CosNaming.NameComponent JavaDoc[1];
89                 ncs[0] =
90                     new org.omg.CosNaming.NameComponent JavaDoc(
91                                                         (String JavaDoc)getValueAt(row,0),
92                                                         (String JavaDoc)getValueAt(row,1));
93                 current.unbind(ncs);
94                 update();
95             }
96             catch( Exception JavaDoc e)
97             {}
98         }
99     }
100     /**
101      *
102      */

103     public void update()
104     {
105         if( current != null )
106             current.display();
107     }
108 }
109
110
111
112
113
Popular Tags