source: trunk/gli/src/org/greenstone/gatherer/gui/table/GTableCellEditor.java@ 4293

Last change on this file since 4293 was 4293, checked in by jmt12, 21 years ago

Initial revision

  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * <BR><BR>
9 *
10 * Author: John Thompson, Greenstone Digital Library, University of Waikato
11 *
12 * <BR><BR>
13 *
14 * Copyright (C) 1999 New Zealand Digital Library Project
15 *
16 * <BR><BR>
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * <BR><BR>
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * <BR><BR>
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *########################################################################
36 */
37
38
39
40
41
42
43package org.greenstone.gatherer.gui.table;
44
45import java.awt.Component;
46import javax.swing.DefaultCellEditor;
47import javax.swing.JTable;
48import javax.swing.JTextField;
49import org.greenstone.gatherer.Gatherer;
50import org.greenstone.gatherer.msm.Metadata;
51import org.greenstone.gatherer.gui.combobox.GComboBox;
52import org.greenstone.gatherer.gui.combobox.GComboBoxModel;
53/** This implementation of the TableCellRenderer interface allows for us
54 * to return a GComboBox with the correct model given a reference to the
55 * original metadata row within the given table. All edit calls, other than
56 * those from the third column, ie the values column, get the default
57 * editor component.
58 */
59public class GTableCellEditor
60 extends DefaultCellEditor {
61
62 private Gatherer gatherer = null;
63
64 private GComboBox editor = null;
65
66 private GComboBoxModel editor_model = null;
67
68 /** The default constructor simply add the standard new argument, a
69 * reference to the Gatherer class.
70 * @param gatherer A reference to Gatherer for communication and dictionary
71 * purposes.
72 */
73 public GTableCellEditor(Gatherer gatherer) {
74 super(new JTextField());
75 this.gatherer = gatherer;
76 }
77
78 /** This method returns the currently selected value of our editor
79 * GCombobox.
80 * @return An Object which is the selected items value.
81 */
82 public Object getCellEditorValue() {
83 return editor.getSelectedItem();
84 }
85
86 /** Returns a reference to the editor GComboBox.
87 * @return A Component reference to our editor.
88 */
89 public Component getComponent() {
90 return editor;
91 }
92
93 /** This method is called to retrieve the correct editor component for
94 * a certain row and column within the target JTable. It is here that
95 * we create the custom GComboBox for each row of the 'values' column
96 * using a different model for each. If the call comes from any other
97 * column (which it shouldn't but what the hell) we let the super
98 * handle it which returns a plain old JTextField as the editing component.
99 * @param table The JTable which called this method.
100 * @param value The initial value of the cell this editor will be used
101 * for, as an Object. Format this to suit the editor you wish to return.
102 * @param isSelected A Boolean specifying whether the selected cell
103 * is currently highlighted in such a way so as to allow the user to
104 * know it is being edited.
105 * @param row An Int specifying the cells row.
106 * @param column An Int specifying the cells column.
107 * @return A Component which will be placed in the table as the method
108 * of editing the specified cell.
109 */
110 public Component getTableCellEditorComponent(JTable table, Object value,
111 boolean isSelected, int row,
112 int column) {
113 GTableModel model = (GTableModel)table.getModel();
114 // Create a new GComboBox with a model based on the selected
115 // records metadata.
116 Metadata selected_metadata = model.getMetadataAtRow(row);
117 //editor_model = gatherer.c_man.getCollection().getValueModel
118 // (selected_metadata.element);
119 editor = new GComboBox(editor_model);
120 editor.setEditable(true);
121 // Make sure that value is the currently selected option in the
122 // editor.
123 editor.setSelectedItem(value);
124 // Done.
125 return editor;
126 }
127}
128
Note: See TracBrowser for help on using the repository browser.