bool PropertiesHandler::handleURI(URI& uri) { if (uri.action != "properties") return false; MetadataItemPropertiesPanel* parent = dynamic_cast< MetadataItemPropertiesPanel*>(getParentWindow(uri)); if (!parent) return true; DatabasePtr db = parent->getObservedObject()->getDatabase(); if (!db) return true; NodeType n = getTypeByName(uri.getParam("object_type")); MetadataItem* object = db->findByNameAndType(n, uri.getParam("object_name")); if (!object) { ::wxMessageBox( _("Cannot find destination object\nThis should never happen."), _("Error"), wxICON_ERROR); return true; } if (uri.getParam("target") == "new_tab") { MetadataItemPropertiesFrame::openNewPropertyPageInTab(object, parent->getParentFrame()); } else if (uri.getParam("target") == "new") MetadataItemPropertiesFrame::openNewPropertyPageInFrame(object); else MetadataItemPropertiesFrame::showPropertyPage(object); return true; }
bool PageHandler::handleURI(URI& uri) { if (uri.action != "page") return false; MetadataItemPropertiesPanel* mpp = dynamic_cast< MetadataItemPropertiesPanel*>(getParentWindow(uri)); if (!mpp) return true; if (uri.getParam("target") == "new") { mpp = MetadataItemPropertiesFrame::openNewPropertyPageInFrame( mpp->getObservedObject()); } else if (uri.getParam("target") == "new_tab") { mpp = MetadataItemPropertiesFrame::openNewPropertyPageInTab( mpp->getObservedObject(), mpp->getParentFrame()); } mpp->setPage(uri.getParam("type")); //frameManager().rebuildMenu(); return true; }
bool AddConstraintHandler::handleURI(URI& uri) { if (uri.action != "add_constraint") return false; wxString type = uri.getParam("type"); // pk, fk, check, unique Table* t = extractMetadataItemFromURI<Table>(uri); wxWindow* w = getParentWindow(uri); if (!t || !w) return true; // Find first available constraint name: DatabasePtr db = t->getDatabase(); wxString prefix = type + "_" + t->getName_(); wxString stmt( "select rdb$constraint_name from rdb$relation_constraints " "where rdb$relation_name = '" + t->getName_() + "' and rdb$constraint_name starting with '" + prefix + "' order by 1"); wxString default_value; wxArrayString constraintNames(db->loadIdentifiers(stmt)); for (int i = 0; ; ++i) { default_value = prefix + wxString::Format("_%d", i); if (constraintNames.Index(default_value, false) == wxNOT_FOUND) break; } wxString cname = ::wxGetTextFromUser(_("Enter constraint name"), _("Adding new table constraint"), default_value, w); if (cname.IsEmpty()) // cancel return true; wxString sql = "alter table " + t->getQuotedName() + "\nadd constraint " + Identifier::userString(cname); if (type == "PK") { wxString columnlist = selectRelationColumns(t, w); if (columnlist.IsEmpty()) // cancel return true; sql += "\nprimary key (" + columnlist + ")"; } else if (type == "FK") { wxString columnlist = selectRelationColumns(t, w); if (columnlist == "") return true; TablePtr ref = selectTable(t->getDatabase(), w); if (!ref) return true; wxString refcolumnlist = selectRelationColumns(ref.get(), w); if (refcolumnlist == "") return true; sql += "\nforeign key (" + columnlist + ") \nreferences " + ref->getQuotedName() + " (" + refcolumnlist + ")"; wxString action = selectAction(_("update"), w); if (action == "CANCEL") return true; else if (action != "RESTRICT") sql += "\non update " + action + " "; action = selectAction(_("delete"), w); if (action == "CANCEL") return true; else if (action != "RESTRICT") sql += "\non delete " + action + " "; } else if (type == "CHK") { wxString source; if (!GetMultilineTextFromUser(w, _("Enter check condition"), source)) return true; sql += "\ncheck (" + source + ")"; } else if (type == "UNQ") { wxString columnlist = selectRelationColumns(t, w); if (columnlist.IsEmpty()) // cancel return true; sql += "\nunique (" + columnlist + ")"; } else { ::wxMessageBox(_("Unknown constraint type"), _("Error."), wxOK | wxICON_ERROR); return true; } execSql(w, "", db, sql, true); // true = commit + close at once return true; }