001/*
002 * Copyright (c) 2006-2010 The Regents of the University of California.
003 * All rights reserved.
004 *
005 * '$Author: welker $'
006 * '$Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $' 
007 * '$Revision: 24234 $'
008 * 
009 * Permission is hereby granted, without written agreement and without
010 * license or royalty fees, to use, copy, modify, and distribute this
011 * software and its documentation for any purpose, provided that the above
012 * copyright notice and the following two paragraphs appear in all copies
013 * of this software.
014 *
015 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
016 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
017 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
018 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
019 * SUCH DAMAGE.
020 *
021 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
022 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
023 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
024 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
025 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 * ENHANCEMENTS, OR MODIFICATIONS.
027 *
028 */
029
030package org.ecoinformatics.seek.querybuilder;
031
032import java.awt.event.ActionEvent;
033import java.util.Hashtable;
034import java.util.Vector;
035
036import javax.swing.AbstractAction;
037
038/**
039 * This class will express an action which will delete a selected row from
040 * DBselectTableModel
041 * 
042 * @author tao
043 * 
044 */
045public class DBSelectTableModelDeleteAction extends AbstractAction {
046        private DBSelectTableModelStd model;
047        private int selectedRow;
048        private DBSelectTableUIBase table;
049        private static final boolean FALSE = false;
050
051        /**
052         * Conscturct
053         * 
054         * @param model
055         * @param selectedRow
056         */
057        public DBSelectTableModelDeleteAction(String name,
058                        DBSelectTableUIBase table, DBSelectTableModelStd model,
059                        int selectedRow) {
060                super(name);
061                this.table = table;
062                this.model = model;
063                this.selectedRow = selectedRow;
064        }
065
066        /**
067         * Invoked when an action occurs. It will delete selected row from model
068         * 
069         * @param e
070         *            ActionEvent
071         */
072        public void actionPerformed(ActionEvent e) {
073                if (model != null && selectedRow >= 0) {
074                        Vector itemList = model.getItemVector();
075                        Hashtable modelHash = model.getModelHashtable();
076                        // System.out.println("the old list is "+itemList);
077                        if (itemList != null) {
078                                // System.out.println("remove the selected row "+selectedRow);
079                                DBSelectTableModelItem selectedItem = (DBSelectTableModelItem) itemList
080                                                .elementAt(selectedRow);
081                                String tableName = selectedItem.getTableName();
082                                String fieldName = selectedItem.getName();
083                                // System.out.println("the talbe name is "+tableName);
084                                // System.out.println("the file name is "+fieldName);
085                                // make sure the upper pane unselected the deleted field
086                                DBSelectTableOverviewModel overViewModel = (DBSelectTableOverviewModel) modelHash
087                                                .get(tableName);
088                                DBSelectTableModelItem overViewItem = overViewModel
089                                                .getItemByName(fieldName);
090                                overViewItem.setDisplayed(FALSE);
091                                // delete the selected row.
092                                itemList.remove(selectedRow);
093                                // Vector newList = model.getItemVector();
094                                // System.out.println("the new list is "+newList);
095                                // update the lower panel
096                                table.setModel(model);
097                                model.fireTableDataChanged();
098                                // update upper panel
099                                overViewModel.fireTableDataChanged();
100                                if (overViewModel.getTableView() != null) {
101                                        overViewModel.getTableView().repaint();
102                                }
103
104                        }
105                }
106
107        }
108
109}