/** *######################################################################### * * A component of the Gatherer application, part of the Greenstone digital * library suite from the New Zealand Digital Library Project at the * University of Waikato, New Zealand. * * Copyright (C) 2006 New Zealand Digital Library Project * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *######################################################################## */ package org.greenstone.gatherer.cdm; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import java.util.ArrayList; import org.greenstone.gatherer.Configuration; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.Gatherer; import org.greenstone.gatherer.gui.DesignPaneHeader; import org.greenstone.gatherer.util.StaticStrings; public class SearchMetadataManager { private Control controls; public static final String TYPE_INDEX = "index"; public static final String TYPE_LEVEL = "level"; public static final String TYPE_PARTITION = "partition"; public static final String TYPE_LANGUAGE = "language"; CollectionMetaManager collmeta_manager = CollectionDesignManager.collectionmeta_manager; public SearchMetadataManager() { } /** Destructor. */ public void destroy() { if (controls != null) { controls.destroy(); controls = null; } } public void loseFocus() { } public void gainFocus() { } public Control getControls() { if (controls == null) { controls = new DisplayControl(); } return controls; } /** Called when the detail mode has changed which in turn may cause several design elements to be available/hidden * @param mode the new mode as an int */ public void modeChanged(int mode) { } private class DisplayControl extends JPanel implements Control { private SearchMetadataTable metadata_table = null; public DisplayControl() { super(); JPanel header_panel = new DesignPaneHeader("CDM.GUI.SearchMetadata", "searchmetadatasettings"); metadata_table = new SearchMetadataTable(); JScrollPane scroll_panel = new JScrollPane(metadata_table); scroll_panel.getViewport().setBackground(Configuration.getColor("coloring.collection_tree_background", false)); scroll_panel.setOpaque(true); JPanel metadata_table_pane = new JPanel(); metadata_table_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0)); metadata_table_pane.setLayout(new BorderLayout()); metadata_table_pane.add(scroll_panel, BorderLayout.CENTER); setBorder(BorderFactory.createEmptyBorder(0,5,0,0)); setLayout(new BorderLayout()); add(header_panel, BorderLayout.NORTH); add(metadata_table_pane, BorderLayout.CENTER); } public void loseFocus(){ // save the last metadata in case its still editing metadata_table.stopEditing(); } public void gainFocus(){ // refresh the model as we may have changed indexes in the meantime metadata_table.refreshModel(); } public void destroy() {} } private ArrayList getEntries() { ArrayList entries = new ArrayList(); ArrayList indexes = CollectionDesignManager.index_manager.getIndexes(); if (indexes != null) { int indexes_size = indexes.size(); for (int i=0; i= search_metadata_entries.size() || col < 0 || col >= COLUMN_NAMES.length) { return null; } SearchMetadataEntry sme = (SearchMetadataEntry) search_metadata_entries.get(row); if (col == 0) { return sme.toString(); } if (col == 1) { return sme.getValue(); } return null; } public boolean isCellEditable(int row, int col) { if (col == 1) { return true; } return false; } public void refresh() { search_metadata_entries = getEntries(); } public void setValueAt(Object new_value, int row, int col) { SearchMetadataEntry sme = (SearchMetadataEntry) search_metadata_entries.get(row); String old_value = sme.getValue(); if (!new_value.equals(old_value)) { sme.setValue((String)new_value); } } } private static class SearchMetadataTableCellRenderer extends DefaultTableCellRenderer { public void setValue(Object value) { setText((String)value); } /** Returns the default table cell renderer. * @param table The JTable. * @param value The value to assign to the cell at [row, column] as an Object. * @param isSelected true if cell is selected. * @param hasFocus true if cell has focus. * @param row The row of the cell to render as an int. * @param column The column of the cell to render as an int. * @return The default table cell renderer Component. */ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JComponent component = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); // real_column is the column in the model, column is the column in the table - may be different if the user has moved the columns around int real_column = table.convertColumnIndexToModel(column); if (real_column == 1 && isSelected) { table.editCellAt(row, column); if (table.isEditing()) { table.getEditorComponent().requestFocus(); } } // so we can see the background colour component.setOpaque(true); // Background if (isSelected) { component.setBackground(Configuration.getColor("coloring.workspace_heading_background", true)); } else { if (real_column == 0) { component.setBackground(Configuration.getColor("coloring.collection_heading_background", true)); } else { component.setBackground(Configuration.getColor("coloring.collection_tree_background", true)); } } // The value column of cells never paints focus if (real_column == 1) { component.setBorder(BorderFactory.createEmptyBorder(0,2,0,0)); } return component; } } }