/* 
 * © 2007-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#ifndef _EDITOR_TABLE_INSERTS_H_
#define _EDITOR_TABLE_INSERTS_H_

#include "grt/tree_model.h"

#include "wbpublic_public_interface.h"

#include "grts/structs.db.h"

#include <deque>


namespace bec
{
  class TableEditorBE;

  class WBPUBLICBACKEND_PUBLIC_FUNC TableInsertsGridBE : public GridModel
  {
  public:
    TableInsertsGridBE(TableEditorBE *table);

    virtual int get_column_count();
    virtual std::string get_column_caption(int column);
    db_ColumnRef get_column(int column);
    virtual ColumnType get_column_type(int column);

    virtual int count();

    virtual bool get_field(const NodeId &node, int column, std::string &value);
    virtual bool set_convert_field(const NodeId &node, int column, const std::string &value);

    virtual void refresh();

    bool set_inserts_text(const std::string &text);
    std::string get_inserts_text();

    virtual bool delete_node(const NodeId &node);

    void enable_placeholder_row(bool flag);

    virtual MenuItemList get_popup_items_for_nodes(const std::vector<NodeId> &nodes);
    //! Returns true if item was processed by BE, false - BE is unable to process command and FE should do it
    virtual bool activate_popup_item_for_nodes(const std::string &name, const std::vector<NodeId> &nodes);
  protected:
    TableEditorBE *_owner;
   
    db_SimpleDatatypeRef get_column_simpletype(int column);
    void add_new_row(int column, const std::string &value);
    void update_data_rows(const std::list<int> &mapping);

    std::list<db_ColumnRef> columns;
    std::deque<std::vector<std::string> > rows;
    
    bool _placeholder_row;
  };

} 

#endif
