1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
*
* 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; version 2 of the
* License.
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "stdafx.h"
#include "edit_table_data_wizard.h"
#include "grt/grt_manager.h"
#include "grtpp_util.h"
#include "base/string_utilities.h"
#include "sqlide/wb_sql_editor_form.h"
using namespace base;
//----------------- TableSelectionPage ----------------------------------------------------------------
TableSelectionPage::TableSelectionPage(WizardForm* wizard)
:
WizardPage(wizard, "table selection page"),
_schema_selector_contents(true),
_table_selector_contents(true),
_log_panel(mforms::TitledBoxPanel),
_log_text(mforms::BothScrollBars),
_context(NULL)
{
set_short_title(_("Table Selection"));
set_title(_("Database Schema and Table Selection"));
// schema selector
_schema_selector_heading.set_text(_("Please select the Database Schema that holds the table you want to edit."));
_schema_selector_heading.set_wrap_text(true);
add(&_schema_selector_heading, false, false);
add(&_schema_selector_table, false, false);
_schema_selector_table.set_row_count(1);
_schema_selector_table.set_column_count(2);
_schema_selector_table.set_column_spacing(4);
_schema_selector_caption.set_text_align(mforms::WizardLabelAlignment);
_schema_selector_caption.set_text(_("Schema:"));
_schema_selector_table.add(&_schema_selector_caption, 0, 1, 0, 1, mforms::HFillFlag);
_schema_selector_contents.set_spacing(8);
_schema_selector_table.add(&_schema_selector_contents, 1, 2, 0, 1, mforms::HExpandFlag|mforms::HFillFlag);
_schema_selector_contents.add(&_schema_selector, true, true);
scoped_connect(_schema_selector.signal_changed(),boost::bind(&TableSelectionPage::schema_changed, this));
// table selector
_table_selector_heading.set_text(_("Select the table you want to edit."));
_table_selector_heading.set_wrap_text(true);
add(&_table_selector_heading, false, false);
add(&_table_selector_table, false, false);
_table_selector_table.set_row_count(1);
_table_selector_table.set_column_count(2);
_table_selector_table.set_column_spacing(4);
_table_selector_caption.set_text_align(mforms::WizardLabelAlignment);
_table_selector_caption.set_text(_("Table:"));
_table_selector_table.add(&_table_selector_caption, 0, 1, 0, 1, mforms::HFillFlag);
_table_selector_contents.set_spacing(8);
_table_selector_table.add(&_table_selector_contents, 1, 2, 0, 1, mforms::HExpandFlag|mforms::HFillFlag);
_table_selector_contents.add(&_table_selector, true, true);
scoped_connect(_table_selector.signal_changed(),boost::bind(&TableSelectionPage::table_changed, this));
// last message
_last_message.set_text(_(
"Press [Finish] to start editing the table data.\n"
"An SQL Editor will be opened and the table data will be displayed for editing."));
_last_message.set_wrap_text(true);
add(&_last_message, false, false);
// log panel
add(&_log_panel, true, true);
_log_panel.set_title(_("Database Connection Log"));
_log_panel.show(false);
_log_text.set_read_only(true);
_log_panel.add(&_log_text);
}
//--------------------------------------------------------------------------------------------------
void TableSelectionPage::enter(bool advancing)
{
if (advancing)
{
std::string exception_message;
_log_text.clear();
_log_panel.show(false);
_last_message.show(true);
relayout();
try
{
_schema_selector.clear();
sql::ConnectionWrapper dbc_conn= _db_conn->get_dbc_connection();
std::auto_ptr<sql::ResultSet> rs(dbc_conn->getMetaData()->getSchemata());
while (rs->next())
{
std::string name= rs->getString(1);
_schema_selector.add_item(name);
}
_log_text.set_value(_("Database connection completed successfully."));
schema_changed();
}
catch (std::exception &e)
{
std::string exception_message= strfmt(_("Error occured: %s"), e.what());
_log_text.set_value(exception_message);
_form->set_problem(exception_message);
_log_panel.show(true);
_last_message.show(false);
relayout();
}
}
}
//--------------------------------------------------------------------------------------------------
void TableSelectionPage::schema_changed()
{
try
{
_table_selector.clear();
if (!_schema_selector.get_string_value().empty())
{
sql::ConnectionWrapper dbc_conn= _db_conn->get_dbc_connection();
std::auto_ptr<sql::ResultSet> rs(dbc_conn->getMetaData()->getSchemaObjects("", _schema_selector.get_string_value(), "table"));
while (rs->next())
{
std::string name= rs->getString(4);
_table_selector.add_item(name);
}
table_changed();
}
}
catch (std::exception &e)
{
_form->set_problem(strfmt(_("Failed to fetch table list: %s"), e.what()));
}
}
//--------------------------------------------------------------------------------------------------
void TableSelectionPage::table_changed()
{
//validate(); // Commented out to fix bug #57127
// The validate check is done in allow_next
}
//--------------------------------------------------------------------------------------------------
void TableSelectionPage::do_validate()
{
if (_schema_selector.get_string_value().empty() || _table_selector.get_string_value().empty())
_form->set_problem(_("Either schema or table is not selected."));
else
_form->clear_problem();
}
//--------------------------------------------------------------------------------------------------
bool TableSelectionPage::allow_next()
{
return !(_schema_selector.get_string_value().empty() || _table_selector.get_string_value().empty());
}
//--------------------------------------------------------------------------------------------------
bool TableSelectionPage::advance()
{
db_mgmt_ConnectionRef conn = _db_conn->get_connection();
if (conn.is_valid())
{
_context->show_status_text("Opening SQL Editor...");
Db_sql_editor::Ref db_sql_editor(_context->add_new_query_window(conn));
if (db_sql_editor)
db_sql_editor->schema_object_activated(
"edit_data",
wb::LiveSchemaTree::Table,
_schema_selector.get_string_value(),
_table_selector.get_string_value());
}
return true;
}
//--------------------------------------------------------------------------------------------------
std::string TableSelectionPage::next_button_caption()
{
return _("Finish");
}
//--------------------------------------------------------------------------------------------------
void TableSelectionPage::set_db_connection(DbConnection *value)
{
_db_conn= value;
}
//----------------- EditTableDataWizard ---------------------------------------------------------
void TableSelectionPage::set_context(wb::WBContext* context)
{
_context= context;
}
//----------------- EditTableDataWizard ---------------------------------------------------------
EditTableDataWizard::EditTableDataWizard(wb::WBContext* context)
:
WizardForm(context->get_grt_manager()),
_context(context)
{
_db_conn.init(_context->get_root()->rdbmsMgmt(), true);
set_title(_("Edit Table Data"));
_db_conn_page= new ConnectionPage(this);
_db_conn_page->set_db_connection(&_db_conn);
add_page(manage(_db_conn_page));
_table_selection_page= new TableSelectionPage(this);
_table_selection_page->set_db_connection(&_db_conn);
_table_selection_page->set_context(_context);
add_page(manage(_table_selection_page));
}
//--------------------------------------------------------------------------------------------------
EditTableDataWizard::~EditTableDataWizard()
{
// Pages are freed by the WizardForm ancestor.
}
//--------------------------------------------------------------------------------------------------
|