57 #include <wx/button.h>
58 #include <wx/msgdlg.h>
59 #include <wx/settings.h>
61 #include <wx/sstream.h>
62 #include <wx/txtstrm.h>
63 #include <wx/clipbrd.h>
64 #include <wx/dataobj.h>
71 #define ID_EXPORT_TO_CSV 10100
72 #define ID_SEARCH_INCLUDE_VALUE 10101
73 #define ID_SEARCH_EXCLUDE_VALUE 10102
95 , m_ToolbarSizer(
NULL)
98 , m_RefreshButton(
NULL)
100 , m_ShowSelectAll(
true)
103 , m_isShowRefreshButton(
false)
104 , m_isShowGridLines(
true)
105 , m_UseCursorSelection(
true)
110 const wxPoint& pos,
const wxSize&
size,
long style)
111 : m_Grid(), m_GridAdapter(), m_Timer(this), m_ToolbarSizer(
NULL)
114 , m_RefreshButton(
NULL)
116 , m_ShowSelectAll(
true)
117 , m_isShowRefreshButton(
false)
118 , m_isShowGridLines(
true)
119 , m_UseCursorSelection(
true)
135 const wxPoint& pos,
const wxSize&
size,
long style)
137 #ifdef __WXOSX_COCOA__
138 SetBackgroundStyle(wxBG_STYLE_COLOUR);
139 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK));
142 if ( ! wxPanel::Create(parent,
id, pos,
size, style))
166 wxBoxSizer* itemBoxSizer =
new wxBoxSizer(wxVERTICAL);
167 this->SetSizer(itemBoxSizer);
170 itemBoxSizer->Add(
m_Grid, 1, wxGROW|wxALL, 0);
183 wxFont font =
m_Grid->GetDefaultCellFont();
184 wxFont fixed_font(font.GetPointSize(), wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
185 fixed_font.SetSymbolicSize(wxFONTSIZE_LARGE);
186 m_Grid->SetDefaultCellFont(fixed_font);
217 for (
size_t i = 0;
i < vec.size()/2; ++
i) {
243 GetSizer()->Insert(0,
m_ToolbarSizer, 0, wxGROW|wxBOTTOM|wxALIGN_LEFT);
247 m_StaticLine =
new wxStaticLine(
this, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
252 GetSizer()->Layout();
254 m_Grid->EnableEditing(
true);
276 if (edit_menu.get()) {
277 Merge(menu, *edit_menu);
283 if (!sel_objects.empty()) {
284 vector< CIRef<IObjectCmdContributor> > contributors;
287 for(
size_t i = 0;
i < contributors.size();
i++ ){
291 unique_ptr<wxMenu> obj_menu(contrib.first);
292 if (obj_menu.get()) {
293 Merge(menu, *obj_menu);
298 if (menu.GetMenuItemCount() > 0) {
299 menu.AppendSeparator();
301 menu.Append(wxID_COPY);
312 m_Grid->PopupMenu(&menu, evt.GetPosition());
322 if (evt.GetRow() < 0)
332 event.SetModifiers(modifiers);
360 if(evt.GetTopRow() == evt.GetBottomRow()) {
394 if (hide_unselected) {
410 if (hide_unselected) {
414 for (
size_t i=0;
i<query_results.size(); ++
i) {
415 size_t row_idx = query_results[
i];
418 m_Grid->SetGridCursor(
static_cast<int>(current_idx), 0);
420 if (current_idx < (
size_t)
m_Grid->GetNumberRows()) {
421 m_Grid->SelectRow(
static_cast<int>(current_idx),
true);
429 if (hide_unselected) {
451 for (
size_t i=0;
i<query_results.size(); ++
i) {
452 size_t row_idx = query_results[
i];
454 if (current_idx < (
size_t)
m_Grid->GetNumberRows()) {
455 m_Grid->SelectRow(
static_cast<int>(current_idx),
true);
462 if (current_idx < (
size_t)
m_Grid->GetNumberRows()) {
463 m_Grid->SelectRow(
static_cast<int>(current_idx),
true);
480 if (grid_row_idx < (
size_t)
m_Grid->GetNumberRows()) {
481 m_Grid->SelectRow(
static_cast<int>(grid_row_idx),
true);
500 vector<size_t> origRows;
514 origRows.push_back(row);
522 set<size_t> rowSet(origRows.begin(), origRows.end());
525 if (rowSet.
find(row) != rowSet.
end())
526 m_Grid->SelectRow(
static_cast<int>(row),
true);
530 return origRows.empty() ? 0 : origRows[0];
541 wxGridCellCoordsArray selTopLeft =
m_Grid->GetSelectionBlockTopLeft();
542 wxGridCellCoordsArray selBottomRight =
m_Grid->GetSelectionBlockBottomRight();
543 size_t blockCount = selTopLeft.GetCount();
545 if (blockCount > 0 && blockCount == selBottomRight.GetCount()) {
546 for (
size_t i = 0;
i < blockCount; ++
i) {
547 for (
int j = selTopLeft[
i].GetRow(); j <= selBottomRight[
i].GetRow(); ++j)
553 wxArrayInt selRows =
m_Grid->GetSelectedRows();
554 for (
size_t i = 0;
i < selRows.size(); ++
i)
558 wxGridCellCoordsArray selCells =
m_Grid->GetSelectedCells();
559 for (
size_t i = 0;
i < selCells.GetCount(); ++
i)
560 raw_rows.
insert(selCells[
i].GetRow());
565 if (row != (
size_t)-1)
575 vector<size_t> origRows;
579 if (row != (
size_t)-1)
580 origRows.push_back(row);
590 objs.push_back(it->object);
603 vector<size_t> origRows;
607 if (row != (
size_t)-1)
608 origRows.push_back(row);
611 for (
size_t col = 0; col <
m_TableData->GetColsCount(); ++col) {
613 vector<size_t>::const_iterator it2;
614 for (it2 = origRows.begin(); it2 != origRows.end(); ++it2) {
622 vector<size_t>::const_iterator it3;
623 for (it3 = origRows.begin(); it3 != origRows.end(); ++it3) {
643 wxArrayInt rows =
m_Grid->GetSelectedRows();
644 for (
size_t i = 0;
i < rows.size(); ++
i)
645 selRows.push_back(rows[
i]);
648 if (selRows.size() == 0) {
649 wxGridCellCoordsArray selTopLeft =
m_Grid->GetSelectionBlockTopLeft();
650 wxGridCellCoordsArray selBottomRight =
m_Grid->GetSelectionBlockBottomRight();
651 size_t blockCount = selTopLeft.GetCount();
653 if (blockCount > 0 && blockCount == selBottomRight.GetCount()) {
654 for (
size_t i = 0;
i < blockCount; ++
i) {
655 for (
int j = selTopLeft[
i].GetRow(); j <= selBottomRight[
i].GetRow(); ++j)
656 selRows.push_back(j);
662 if (selRows.size() == 0) {
663 wxGridCellCoordsArray selCells =
m_Grid->GetSelectedCells();
664 for (
size_t i = 0;
i < selCells.GetCount(); ++
i)
665 selRows.push_back(selCells[
i].GetRow());
669 if (selRows.size() == 0) {
670 int curRow =
m_Grid->GetGridCursorRow();
672 selRows.push_back(curRow);
675 vector<size_t> origRows;
677 for (vector<int>::const_iterator it = selRows.begin(); it != selRows.end(); ++it) {
679 _TRACE(
"Sel row: " << *it <<
" orig row: " << row);
680 if (row != (
size_t)-1)
681 origRows.push_back(row);
684 for (
size_t col = 0; col <
m_TableData->GetColsCount(); ++col) {
686 vector<size_t>::const_iterator it2;
687 for (it2 = origRows.begin(); it2 != origRows.end(); ++it2) {
695 vector<size_t>::const_iterator it3;
696 for (it3 = origRows.begin(); it3 != origRows.end(); ++it3) {
705 bool visible =
m_Grid->IsVisible(row_idx, 0,
false);
716 m_Grid->GetViewStart(&x, &y);
717 m_Grid->MakeCellVisible(row_idx, 0);
718 m_Grid->GetViewStart(&xdummy,&y);
730 wxGridCellCoordsArray selTopLeft =
m_Grid->GetSelectionBlockTopLeft();
731 wxGridCellCoordsArray selBottomRight =
m_Grid->GetSelectionBlockBottomRight();
732 size_t blockCount = selTopLeft.GetCount();
734 if (blockCount > 0 && blockCount == selBottomRight.GetCount()) {
735 for (
size_t i = 0;
i < blockCount; ++
i) {
736 for (
int j = selTopLeft[
i].GetRow(); j <= selBottomRight[
i].GetRow(); ++j)
742 wxArrayInt selRows =
m_Grid->GetSelectedRows();
743 for (
size_t i = 0;
i < selRows.size(); ++
i)
747 wxGridCellCoordsArray selCells =
m_Grid->GetSelectedCells();
748 for (
size_t i = 0;
i < selCells.GetCount(); ++
i)
749 rows.
insert(selCells[
i].GetRow());
752 int curRow =
m_Grid->GetGridCursorRow();
767 if (count1 > count2) {
768 wxGridTableMessage msg(
m_GridAdapter, wxGRIDTABLE_NOTIFY_ROWS_DELETED, count2, count1-count2);
769 m_Grid->ProcessTableMessage(msg);
771 else if (count1 < count2) {
772 wxGridTableMessage msg(
m_GridAdapter, wxGRIDTABLE_NOTIFY_ROWS_APPENDED, count2-count1);
773 m_Grid->ProcessTableMessage(msg);
815 vector<wxString> selectedColumns;
817 for (
int i = 0;
i < colNum; ++
i) {
826 if (!regPath.empty())
829 if (dlg.ShowModal() != wxID_OK)
833 if (fileName.empty() )
843 if (os.get() ==
NULL)
847 vector<int> rows, cols;
849 wxMessageBox(
wxT(
"Can't export non rectangular selection."),
wxT(
"Export to CSV"),
850 wxOK | wxICON_EXCLAMATION,
this);
854 if (rows.empty() || cols.empty())
861 if (cols.size() != colNum) {
877 if (!err_msg.empty()) {
878 wxMessageBox(
wxT(
"Failed to save file: ") + err_msg,
wxT(
"Error"),
879 wxOK | wxICON_ERROR,
this);
885 if (m_PopupGridX < 0 || m_PopupGridX >=
m_GridAdapter->GetColsCount() ||
886 m_PopupGridY < 0 || m_PopupGridY >=
m_GridAdapter->GetRowsCount())
896 if (cell_value==
"") {
899 else if ((cell_value.find_first_of(
' ') != string::npos) ||
900 (cell_value.find_first_of(
'\t') != string::npos)) {
901 cell_value =
"\"" + cell_value +
"\"";
908 cell_value =
"\"" + cell_value +
"\"";
912 string query_constraint =
"(" + col_name +
" = " + cell_value +
")";
919 if (m_PopupGridX < 0 || m_PopupGridX >=
m_GridAdapter->GetColsCount() ||
920 m_PopupGridY < 0 || m_PopupGridY >=
m_GridAdapter->GetRowsCount())
926 string query_constraint =
"(" + col_name +
" != " + cell_value +
") ";
933 vector<int> rows, cols;
935 wxMessageBox(
wxT(
"Can't copy non rectangular selection."),
wxT(
"Error"),
936 wxOK | wxICON_ERROR,
this);
940 if (rows.empty() || cols.empty())
946 wxStringOutputStream stream;
947 wxTextOutputStream os(stream);
952 os << wxString::FromUTF8(oss.str().c_str());
955 if (wxTheClipboard->Open()) {
956 wxTheClipboard->SetData(
new wxTextDataObject(stream.GetString()));
957 wxTheClipboard->Close();
964 if (!err_msg.empty()) {
965 wxMessageBox(
wxT(
"Copy to Clipboard failed: ") + err_msg,
wxT(
"Error"),
966 wxOK | wxICON_ERROR,
this);
972 int colNum =
m_Grid->GetNumberCols();
976 wxGridCellCoordsArray selTopLeft =
m_Grid->GetSelectionBlockTopLeft();
977 wxGridCellCoordsArray selBottomRight =
m_Grid->GetSelectionBlockBottomRight();
978 size_t blockCount = selTopLeft.GetCount();
980 if (blockCount > 0 && blockCount == selBottomRight.GetCount()) {
981 for (
size_t i = 0;
i < blockCount; ++
i) {
982 for (
int row = selTopLeft[
i].GetRow(); row <= selBottomRight[
i].GetRow(); ++row) {
983 for (
int col = selTopLeft[
i].GetCol(); col <= selBottomRight[
i].GetCol(); ++col) {
984 selected[row].set(col);
991 wxGridCellCoordsArray selCells =
m_Grid->GetSelectedCells();
992 for (
size_t i = 0;
i < selCells.GetCount(); ++
i) {
993 int row = selCells[
i].GetRow(), col = selCells[
i].GetCol();
994 selected[row].set(col);
998 wxArrayInt selRows =
m_Grid->GetSelectedRows();
999 for (
size_t i = 0;
i < selRows.size(); ++
i) {
1000 int row = selRows[
i];
1001 selected[row].set_range(0, colNum - 1);
1004 if (selected.
empty()) {
1005 int curRow =
m_Grid->GetGridCursorRow();
1007 selected[curRow].set(
m_Grid->GetGridCursorCol());
1011 if (selected.
empty())
1016 for (++it; it != selected.
end(); ++it) {
1017 if (it->second !=
front)
1022 cols.push_back(*it2);
1025 for (it = selected.
begin(); it != selected.
end(); ++it) {
1026 rows.push_back(it->first);
virtual void SetRegistryPath(const string &path)
CEvent - generic event implementation TODO TODO - Attachments.
static CGuiRegistry & GetInstance()
access the application-wide singleton
CRegistryReadView GetReadView(const string §ion) const
get a read-only view at a particular level.
virtual void SaveSettings() const
virtual void SetRegistryPath(const string ®_path)
void SetDefaultQueries(const TNamedQueries &q)
Set the set of default queries for the current data source.
void HideSelectAll(void)
Hide the Select All checkbox.
bool IsSelectAll()
Return true if select all checkbox is checked.
virtual void Create(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Create window.
virtual void LoadSettings()
vector< pair< string, string > > TNamedQueries
void AddQueryText(const string &query_mod)
Add given string to currently displayed query text.
class CRegistryReadView provides a nested hierarchical view at a particular key.
void GetStringVec(const string &key, vector< string > &val) const
CSelectionEvent CSelectionEvent is used for broadcasting selection between views.
void GetAllObjects(TConstObjects &objs) const
void GetOther(TConstObjects &objs) const
bool AddObjectSelection(const CObject &obj)
std::vector< size_t > GetQueryResults() const
@ eWidgetSelectionChanged
a view has been destroyed
wxString GetFileName() const
void GetSelectedColumns(vector< int > &columns) const
Gets the columns, selected by the user.
bool GetWithHeaders() const
void SetColumnsList(const vector< wxString > &columns)
Sets the columns lists.
bool GetSelectedOnly() const
virtual void LoadSettings()
virtual void SetSelection(const vector< size_t > &query_sel)
string GetRegPath() const
virtual size_t GetOriginalRow(size_t queryRow) const
virtual void SaveSettings() const
virtual void IterateSelection(int dir)
virtual int GetNumberCols()
virtual wxString GetValue(int row, int col)
virtual wxString GetColLabelValue(int col)
virtual int GetNumberRows()
virtual void SetRegistryPath(const string ®_path)
virtual size_t GetCurrentRow(size_t queryRow) const
Undo/Redo interface for editing operations.
virtual bool GetHideUnselected() const
virtual size_t GetCurrentSelection() const
virtual void HideUnselected(bool b)
IObjectCmdContributor - contributes commands applicable to scoped objects.
pair< wxMenu *, wxEvtHandler * > TContribution
virtual TContribution GetMenu(TConstScopedObjects &objects)=0
returns a menu with commands applicable to the objects and optional command handler for the commands ...
Constant iterator designed to enumerate "ON" bits.
const_iterator begin() const
const_iterator end() const
iterator_bool insert(const value_type &val)
const_iterator begin() const
const_iterator find(const key_type &key) const
const_iterator end() const
std::ofstream out("events_result.xml")
main entry point for tests
#define EVT_HYPERLINK_HOVER(id, fn)
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
const string & GetMsg(void) const
Get message string.
virtual void RemoveListener(CEventHandler *listener)
Remove a listener.
void GetExtensionAsInterface(const string &ext_point_id, vector< CIRef< I > > &interfaces)
GetExtensionAsInterface() is a helper function that extracts all extensions implementing the specifie...
vector< CConstRef< CObject > > TConstObjects
CConstRef< CObject > object
virtual void AddListener(CEventHandler *listener, int pool_name=ePool_Default)
Add a listener.
vector< SConstScopedObject > TConstScopedObjects
virtual bool Send(CEvent *evt, EDispatch disp_how=eDispatch_Default, int pool_name=ePool_Default)
Sends an event synchronously.
@ eEvent_Message
message from one class to another
void Reset(void)
Reset reference object.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate spaces in a string.
constexpr auto front(list< Head, As... >, T=T()) noexcept -> Head
double value_type
The numeric datatype used by the parser.
const struct ncbi::grid::netcache::search::fields::SIZE size
#define EXT_POINT__SCOPED_OBJECTS__CMD_CONTRIBUTOR
This Extension Point allows external components to add commands that can be applied to scoped CObject...
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
void Merge(wxMenu &menu_1, const wxMenu &menu_2)
merges all items form menu_2 into menu_1, preserving the structure if possible
wxString ToWxString(const string &s)
string ToStdString(const wxString &s)
void CleanupSeparators(wxMenu &menu)
Removes extra separators (in the begining or at the end of the menu, ot those that precede other sepa...