View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
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     // setBackground(Color.lightGray);
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 }