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 * RestrictionTableUI.java
26 *
27 * The Viewer/Controller for displaying and editing restrictions
28 *****************************************************************************/
29
30 package zeus.ontology.database;
31
32 import javax.swing.*;
33 import javax.swing.table.*;
34 import javax.swing.border.*;
35 import javax.swing.event.*;
36
37 import java.awt.*;
38 import java.awt.event.*;
39 import java.util.*;
40
41 import zeus.util.*;
42 import zeus.concepts.*;
43 import zeus.ontology.*;
44 import zeus.gui.help.*;
45 import zeus.gui.editors.*;
46 import zeus.gui.fields.*;
47
48
49 public class TablesTableUI extends JPanel
50 {
51 static final String[] ERROR_MESSAGE = {
52 "Please select a row before\ncalling this operation"
53 };
54
55 protected JTable table;
56
57 protected TablesTableModel model;
58 protected ColumnsTableModel cmodel;
59
60 protected int selRow = -1;
61
62
63 public TablesTableUI(ColumnsTableModel cm)
64 {
65 cmodel = cm;
66 model = new TablesTableModel();
67
68 TableColumnModel tm = new DefaultTableColumnModel();
69 TableColumn column;
70 column = new TableColumn(0);
71 column.setHeaderValue(model.getColumnName(0));
72 tm.addColumn(column);
73 table = new JTable(model,tm);
74
75 table.getTableHeader().setReorderingAllowed(false);
76 table.setColumnSelectionAllowed(false);
77
78 JScrollPane scrollPane = new JScrollPane(table);
79 scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
80 scrollPane.setPreferredSize(new Dimension(140, 180));
81 table.setBackground(Color.white);
82
83 GridBagLayout gridBagLayout = new GridBagLayout();
84 setLayout(gridBagLayout);
85
86
87 GridBagConstraints gbc = new GridBagConstraints();
88
89 gbc.gridwidth = GridBagConstraints.REMAINDER;
90 gbc.anchor = GridBagConstraints.WEST;
91 gbc.fill = GridBagConstraints.BOTH;
92 gbc.weightx = gbc.weighty = 1;
93 gbc.insets = new Insets(16,16,16,16);
94 gridBagLayout.setConstraints(scrollPane, gbc);
95 add(scrollPane);
96
97 ListSelectionModel selectionModel = table.getSelectionModel();
98 selectionModel.addListSelectionListener(new SymListAction());
99 }
100
101 public TablesTableModel getModel() { return model; }
102
103
104 private void errorMsg(int tag) {
105 JOptionPane.showMessageDialog(this,ERROR_MESSAGE[tag],
106 "Error", JOptionPane.ERROR_MESSAGE);
107 }
108
109 public String getSelectedRow()
110 {
111 if (selRow == -1) {
112 return null;
113 }
114 return (String)model.getValueAt(selRow, 0);
115 }
116
117 class SymListAction implements ListSelectionListener {
118 public void valueChanged(ListSelectionEvent e)
119 {
120 int row = table.getSelectedRow();
121 if (row != selRow)
122 {
123
124 selRow = row;
125 String name = (String)model.getValueAt(row, 0);
126
127 cmodel.refreshColumns(name);
128 }
129 }
130 }
131 }