[libgda] Improved SimpleUIForm example with RO and RW versions
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] Improved SimpleUIForm example with RO and RW versions
- Date: Wed, 20 Jan 2010 15:13:07 +0000 (UTC)
commit 11991f7b83261daef07d593750f0cce64d39f8c6
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Jan 20 15:21:06 2010 +0100
Improved SimpleUIForm example with RO and RW versions
samples/README | 2 +-
samples/SimpleUIForm/README | 10 +++++++---
samples/SimpleUIForm/example.c | 19 +++++++++++++++++++
3 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/samples/README b/samples/README
index 3ab22d4..09b494e 100644
--- a/samples/README
+++ b/samples/README
@@ -24,6 +24,6 @@ Currently the contents are:
the execution of a SELECT statement
And using the UI extension:
-* in SimpleUIForm/: a very simple form
+* in SimpleUIForm/: a very simple form, with read-only and read-write versions
Good luck and happy hacking!
diff --git a/samples/SimpleUIForm/README b/samples/SimpleUIForm/README
index 93028d8..f328b3c 100644
--- a/samples/SimpleUIForm/README
+++ b/samples/SimpleUIForm/README
@@ -1,5 +1,5 @@
-Libgda simple example
-=====================
+LibgdaUI simple example
+=======================
Description:
------------
@@ -10,6 +10,9 @@ It displays a form containing the customers of Libgda's SalesTest database, and
each customer, displays its ID, its name and the associated sales representative, using
the name of the representative in a combo box rather than the representative's own ID.
+The same example.c produces two executables, one for a read-only form (example-ro) and
+one for a writeable form (example-rw, depending on the existence of the WRITABLE #define).
+
Compiling and running:
----------------------
@@ -17,4 +20,5 @@ To compile (make sure Libgdaui is installed prior to this):
> make
and to run:
-> ./example
+> ./example-ro
+> ./example-rw
diff --git a/samples/SimpleUIForm/example.c b/samples/SimpleUIForm/example.c
index 2bd1e7c..3d25906 100644
--- a/samples/SimpleUIForm/example.c
+++ b/samples/SimpleUIForm/example.c
@@ -24,6 +24,23 @@ main (int argc, char *argv[])
GdaDataModel *customers, *salesrep;
customers = get_customers (cnc);
salesrep = get_salesrep (cnc);
+#ifdef WRITABLE
+ /* make the form writable:
+ * 1 - fetch meta data
+ * 2 - compute modification statements
+ */
+ GError *error = NULL;
+ GdaMetaContext mcontext = {"_tables", 0, NULL, NULL};
+ if (!gda_connection_update_meta_store (cnc, &mcontext, &error)) {
+ g_print ("Can't get meta data: %s\n", error && error->message ? error->message : "No detail");
+ g_clear_error (&error);
+ }
+
+ if (! gda_data_select_compute_modification_statements (GDA_DATA_SELECT (customers), &error)) {
+ g_print ("Can't make form writable: %s\n", error && error->message ? error->message : "No detail");
+ g_clear_error (&error);
+ }
+#endif
/* create UI */
GtkWidget *window, *vbox, *button, *form;
@@ -38,8 +55,10 @@ main (int argc, char *argv[])
/* main form to list customers */
form = gdaui_form_new (customers);
+ gdaui_data_proxy_set_write_mode (GDAUI_DATA_PROXY (form), GDAUI_DATA_PROXY_WRITE_ON_VALUE_CHANGE);
gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
+ /* use a combo box to liste salesrep by their name and not ID */
GdaDataModelIter *iter;
GdaHolder *holder;
iter = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (form));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]