Added classes to manage simple tabular data of known structure using a
popup containing a wxGrid object.
BasePicker : Abstract class adding a popup to wxPickerBase styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.
JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.
XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.
JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..
The structure of managed tabular data :
Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.
Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.
Other changes :
Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.
LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives
LBoundControl::SetNull must be void.
LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::
LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.
Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
|
|
|
/*
|
|
|
|
|
* File: XmlGridPickerCtrl.cpp
|
2020-01-04 17:04:08 +01:00
|
|
|
* Author: SET - nmset@yandex.com
|
Added classes to manage simple tabular data of known structure using a
popup containing a wxGrid object.
BasePicker : Abstract class adding a popup to wxPickerBase styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.
JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.
XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.
JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..
The structure of managed tabular data :
Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.
Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.
Other changes :
Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.
LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives
LBoundControl::SetNull must be void.
LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::
LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.
Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
|
|
|
* License : LGPL version 2.1
|
|
|
|
|
* Copyright SET, M. D. - © 2014
|
|
|
|
|
*
|
|
|
|
|
* Created on December 14, 2019, 3:28 PM
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "XmlGridPickerCtrl.h"
|
|
|
|
|
#include <wx/sstream.h>
|
|
|
|
|
#include "XmlHelper.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* <?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<TABLE>
|
|
|
|
|
<ROW Type="Work" Preferred="1" Notes="Do not use">+33 1 23 45 67 89</ROW>
|
|
|
|
|
<ROW Type="Home" Preferred="0" Notes="Neither">+33 9 87 65 43 21</ROW>
|
|
|
|
|
</TABLE>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_CLASS(XmlGridPickerCtrl, BaseGridPicker)
|
|
|
|
|
|
|
|
|
|
XmlGridPickerCtrl::XmlGridPickerCtrl(wxWindow *parent,
|
|
|
|
|
wxWindowID id,
|
|
|
|
|
const wxArrayString& types,
|
|
|
|
|
wxSize popupSize,
|
|
|
|
|
const wxString& text,
|
|
|
|
|
const wxPoint& pos,
|
|
|
|
|
const wxSize& size,
|
|
|
|
|
long style,
|
|
|
|
|
const wxValidator& validator,
|
|
|
|
|
const wxString& name)
|
|
|
|
|
: BaseGridPicker(parent, id, types, popupSize, text, pos, size, style, validator, name)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Don't create the grid here. Let SetValue() do it, deleting the previous
|
|
|
|
|
* one every time new data is fed in.
|
|
|
|
|
*/
|
|
|
|
|
SetValue(wxEmptyString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XmlGridPickerCtrl::~XmlGridPickerCtrl()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XmlGridPickerCtrl::SetValue(const wxString& value)
|
|
|
|
|
{
|
|
|
|
|
if (value.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
m_value = EMPTY_DOC;
|
|
|
|
|
BaseGridPicker::CreateGrid(); // +++
|
|
|
|
|
GetTextCtrl()->SetValue(INVALID_INTENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
m_value = value;
|
|
|
|
|
BaseGridPicker::CreateGrid(); // +++
|
|
|
|
|
GetTextCtrl()->SetValue(INVALID_INTENT);
|
|
|
|
|
wxXmlDocument doc;
|
|
|
|
|
wxXmlNode * root = XmlHelper::ValidateXmlValue(doc, m_value);
|
|
|
|
|
if (root == NULL)
|
|
|
|
|
{
|
|
|
|
|
GetTextCtrl()->SetValue(INVALID_INTENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// Look for preferred
|
|
|
|
|
wxXmlNode * row = root->GetChildren();
|
|
|
|
|
while (row)
|
|
|
|
|
{
|
|
|
|
|
const wxString pref = row->GetAttribute(XML_ATTR_PREF);
|
|
|
|
|
if (!pref.IsEmpty()
|
|
|
|
|
&& pref != _T("0"))
|
|
|
|
|
{
|
|
|
|
|
GetTextCtrl()->SetValue(row->GetNodeContent());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
row = row->GetNext();
|
|
|
|
|
}
|
|
|
|
|
GetTextCtrl()->SetValue(INVALID_INTENT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
wxString XmlGridPickerCtrl::GetValue()
|
|
|
|
|
{
|
|
|
|
|
DumpGrid();
|
|
|
|
|
|
|
|
|
|
wxXmlDocument doc;
|
|
|
|
|
wxXmlNode * root = new wxXmlNode(wxXML_ELEMENT_NODE, XML_ROOT_NAME);
|
|
|
|
|
doc.SetRoot(root);
|
|
|
|
|
wxString emptyXmlData;
|
|
|
|
|
wxStringOutputStream sos(&emptyXmlData);
|
|
|
|
|
doc.Save(sos);
|
|
|
|
|
|
|
|
|
|
if (m_value == emptyXmlData)
|
|
|
|
|
return wxEmptyString;
|
|
|
|
|
return m_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XmlGridPickerCtrl::FillGrid()
|
|
|
|
|
{
|
2022-10-15 18:54:17 +02:00
|
|
|
wxASSERT_MSG(m_grid != NULL, _T("m_grid IS NULL"));
|
Added classes to manage simple tabular data of known structure using a
popup containing a wxGrid object.
BasePicker : Abstract class adding a popup to wxPickerBase styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.
JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.
XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.
JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..
The structure of managed tabular data :
Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.
Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.
Other changes :
Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.
LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives
LBoundControl::SetNull must be void.
LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::
LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.
Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
|
|
|
wxXmlDocument doc;
|
|
|
|
|
wxXmlNode * root = XmlHelper::ValidateXmlValue(doc, m_value);
|
|
|
|
|
if (root == NULL)
|
|
|
|
|
{
|
|
|
|
|
GetTextCtrl()->SetValue(INVALID_INTENT);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
wxXmlNode * row = root->GetChildren();
|
|
|
|
|
int idx = 0;
|
|
|
|
|
while (row)
|
|
|
|
|
{
|
|
|
|
|
m_grid->InsertRows(idx);
|
|
|
|
|
m_grid->SetCellValue(idx, 0, row->GetNodeContent());
|
|
|
|
|
m_grid->SetCellValue(idx, 1, row->GetAttribute(XML_ATTR_TYPE));
|
|
|
|
|
m_grid->SetCellValue(idx, 2, row->GetAttribute(XML_ATTR_PREF));
|
|
|
|
|
m_grid->SetCellValue(idx, 3, row->GetAttribute(XML_ATTR_NOTES));
|
|
|
|
|
idx++;
|
|
|
|
|
row = row->GetNext();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void XmlGridPickerCtrl::DumpGrid()
|
|
|
|
|
{
|
2022-10-15 18:54:17 +02:00
|
|
|
wxASSERT_MSG(m_grid != NULL, _T("m_grid IS NULL"));
|
|
|
|
|
wxASSERT_MSG(m_stringTable != NULL, _T("m_stringTable IS NULL"));
|
Added classes to manage simple tabular data of known structure using a
popup containing a wxGrid object.
BasePicker : Abstract class adding a popup to wxPickerBase styled with
a wxTextCtrl.
BaseGridPicker : Abstract class adding a wxGrid in the popup.
JsonGridPickerCtrl : UI control storing the tabular data in a JSON
array.
LBoundJsonGridPicker : connect JsonGridPicker to database.
LGridJsonCellEditor : use LBoundJsonGridPicker in other wxGrid objects.
LGridJsonCellRenderer : render cell JSON data.
XmlGridPickerCtrl : UI control storing the tabular data in as XML
document.
LBoundXmlGridPicker : connect XmlGridPicker to database.
LGridXmlCellEditor : grid editor for LBoundXmlGridPicker.
LGridXmlCellRenderer : grid renderer for LBoundXmlGridPicker.
JsonHelper and XmlHelper : for applications to quickly get intent value
from database data..
The structure of managed tabular data :
Column 1 : Intent - this is what we want to store/edit. This can be
telephone numbers, email addresses, instant messaging addresses...
any single line piece of information that can exist many times for one
entity (person, company...).
Column 2 : Type - A short description of the intent : 'Home, Work,
Mobile, Fax, Other...'. It is displayed in a non editable wxComboBox.
Column 3 : Preferred - One line of data can be selected as the preferred
one. It is not mandatory, but it must be a single choice.
Column 4 : Notes - single line notes.
Adjust sql scripts and L7.dox.
Applied ANSI formatting style to all files.
Other changes :
Work around a nasty misbehavior.
Grid columns edited by a translated combobox expect full string
data as cell values. LResultSet::BEData() will report these mapped strings,
instead of database real data. LBoundComboBox::IsDirty() will always be
true even if the editor is unchanged once created.
Simplest workaround : disconnect m_BoundComboBox if unchanged.
LGridTextEditor::ProvideFormEditor() : set the form editor's value
explicitely.; wxTextCtrl does not interpret data it receives
LBoundControl::SetNull must be void.
LBoundGrid : Unbind:: instructions should limit to the widget's id, like Bind::
LConnection::GetReturnedKeys should return NULL.
LConnection::SetData should return void.
Notes : wxJSON must be configured with the same prefix as wxWidgets,
here /usr/local/{wxWidgets,wxWidgets-Release}.
2019-12-22 16:35:16 +01:00
|
|
|
if (!m_editable || !m_stringTable || !m_grid)
|
|
|
|
|
return;
|
|
|
|
|
wxXmlDocument doc;
|
|
|
|
|
// This is EMPTY_DOC
|
|
|
|
|
wxXmlNode * root = new wxXmlNode(wxXML_ELEMENT_NODE, XML_ROOT_NAME);
|
|
|
|
|
doc.SetRoot(root);
|
|
|
|
|
for (uint grow = 0; grow < m_stringTable->GetRowsCount(); grow++)
|
|
|
|
|
{
|
|
|
|
|
if (m_stringTable->GetValue(grow, 0).IsEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
/*
|
|
|
|
|
* Don't use the other constructor :
|
|
|
|
|
* wxXmlNode(wxXmlNode *parent, wxXmlNodeType type ...
|
|
|
|
|
* The row order will be reversed each time.
|
|
|
|
|
* Explicitly add independent nodes to root.
|
|
|
|
|
*/
|
|
|
|
|
wxXmlNode * row = new wxXmlNode(wxXML_ELEMENT_NODE, XML_ROW_NAME);
|
|
|
|
|
wxXmlAttribute * attr = new wxXmlAttribute(XML_ATTR_TYPE, m_stringTable->GetValue(grow, 1));
|
|
|
|
|
row->AddAttribute(attr);
|
|
|
|
|
attr = new wxXmlAttribute(XML_ATTR_PREF, (m_stringTable->GetValue(grow, 2) == _T("0")
|
|
|
|
|
|| m_stringTable->GetValue(grow, 2).IsEmpty()) ? _T("0") : _T("1"));
|
|
|
|
|
row->AddAttribute(attr);
|
|
|
|
|
attr = new wxXmlAttribute(XML_ATTR_NOTES, m_stringTable->GetValue(grow, 3));
|
|
|
|
|
row->AddAttribute(attr);
|
|
|
|
|
new wxXmlNode(row, wxXML_TEXT_NODE, _T("irrelevant_name"), m_stringTable->GetValue(grow, 0));
|
|
|
|
|
root->AddChild(row);
|
|
|
|
|
}
|
|
|
|
|
wxString xmlData;
|
|
|
|
|
wxStringOutputStream sos(&xmlData);
|
|
|
|
|
bool res = doc.Save(sos);
|
|
|
|
|
if (!res)
|
|
|
|
|
{
|
|
|
|
|
wxASSERT_MSG(res, _T("Error dumping to XML"));
|
|
|
|
|
// Let's not empty m_value.
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_value = xmlData; // May be empty XML with XML_ROOT_NAME tag only
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|