01: /*
02: * JacORB - a free Java ORB
03: *
04: * Copyright (C) 1997-2004 Gerald Brose.
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Library General Public
08: * License as published by the Free Software Foundation; either
09: * 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 extends javax.swing.JTable {
27: private ContextNode current;
28: private NSTableCellRenderer nsRenderer;
29:
30: /**
31: * NSTable constructor comment.
32: */
33:
34: public NSTable() {
35: super (new NSTableModel());
36: setShowGrid(false);
37: setAutoCreateColumnsFromModel(false);
38: setDoubleBuffered(true);
39: setCellSelectionEnabled(false);
40: setColumnSelectionAllowed(false);
41: nsRenderer = new NSTableCellRenderer();
42: }
43:
44: public TableCellRenderer getCellRenderer(int row, int column) {
45: String type = (String) getValueAt(row, 2);
46:
47: if (type.startsWith("IDL:omg.org/CosNaming/NamingContext")) {
48: return nsRenderer;
49: } else
50: return super .getCellRenderer(row, column);
51: }
52:
53: /**
54: * @return the context node that is the source for this table
55: */
56: public ContextNode currentSource() {
57: return current;
58: }
59:
60: /**
61: *
62: * @param newData Vector
63: */
64: public void setData(Vector newData, ContextNode currentSource) {
65: current = currentSource;
66: ((NSTableModel) super .getModel()).setDataVector(newData);
67: }
68:
69: /**
70: * unbind a name and remove it from the table
71: */
72: public synchronized void unbind() {
73: int row = getSelectedRow();
74: if (row > -1) {
75: try {
76: org.omg.CosNaming.NameComponent[] ncs = new org.omg.CosNaming.NameComponent[1];
77: ncs[0] = new org.omg.CosNaming.NameComponent(
78: (String) getValueAt(row, 0),
79: (String) getValueAt(row, 1));
80: current.unbind(ncs);
81: update();
82: } catch (Exception e) {
83: }
84: }
85: }
86:
87: /**
88: *
89: */
90: public void update() {
91: if (current != null)
92: current.display();
93: }
94: }
|