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 * ColumnsTableUI.java
26 *
27 * The Viewer/Controller for displaying and editing columns
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 ColumnsTableUI 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 protected ColumnsTableModel model;
57 protected DatabasePane DBPane = null;
58
59
60 public ColumnsTableUI(DatabasePane parent)
61 {
62 DBPane = parent;
63 model = new ColumnsTableModel(parent);
64
65 TableColumnModel tm = new DefaultTableColumnModel();
66 TableColumn column;
67 column = new TableColumn(0, 60);
68 column.setHeaderValue(model.getColumnName(0));
69 tm.addColumn(column);
70 table = new JTable(model,tm);
71
72 column = new TableColumn(1, 60);
73 column.setHeaderValue(model.getColumnName(1));
74 tm.addColumn(column);
75 table = new JTable(model,tm);
76
77 column = new TableColumn(2, 60);
78 column.setHeaderValue(model.getColumnName(2));
79 tm.addColumn(column);
80 table = new JTable(model,tm);
81
82 table.getTableHeader().setReorderingAllowed(false);
83 table.setColumnSelectionAllowed(false);
84
85 JScrollPane scrollPane = new JScrollPane(table);
86 scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
87 scrollPane.setPreferredSize(new Dimension(300, 180));
88 table.setBackground(Color.white);
89
90 GridBagLayout gridBagLayout = new GridBagLayout();
91 setLayout(gridBagLayout);
92
93
94 GridBagConstraints gbc = new GridBagConstraints();
95
96 gbc.gridwidth = GridBagConstraints.REMAINDER;
97 gbc.anchor = GridBagConstraints.WEST;
98 gbc.fill = GridBagConstraints.BOTH;
99 gbc.weightx = gbc.weighty = 1;
100 gbc.insets = new Insets(16,16,16,16);
101 gridBagLayout.setConstraints(scrollPane, gbc);
102 add(scrollPane);
103
104 ListSelectionModel selectionModel = table.getSelectionModel();
105 selectionModel.addListSelectionListener(new SymListAction());
106 }
107
108 public ColumnsTableModel getModel() { return model; }
109 public JTable getTable() { return table; }
110
111
112 private void errorMsg(int tag) {
113 JOptionPane.showMessageDialog(this,ERROR_MESSAGE[tag],
114 "Error", JOptionPane.ERROR_MESSAGE);
115 }
116
117 String[][] getSelectedRows()
118 {
119 if ( table.getSelectedRow() == -1 ) {
120 errorMsg(1);
121 return new String[0][0];
122 }
123 int[] srows = table.getSelectedRows();
124 return model.getRows(srows);
125 }
126
127 class SymListAction implements ListSelectionListener {
128 public void valueChanged(ListSelectionEvent e)
129 {
130 DBPane.importBtn.setEnabled(true);
131 }
132 }
133
134 }