[libgda] GdaBrowser: UI improvements for data manager
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] GdaBrowser: UI improvements for data manager
- Date: Wed, 8 Sep 2010 19:35:00 +0000 (UTC)
commit aafe0f8a0c0f1fa80789f12f89071c47f5b60343
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Sep 8 21:26:49 2010 +0200
GdaBrowser: UI improvements for data manager
tools/browser/data-manager/data-source-editor.c | 115 ++++++++++++++++++++++-
tools/browser/data-manager/data-source-editor.h | 1 +
tools/browser/data-manager/data-widget.c | 34 +++++++-
3 files changed, 146 insertions(+), 4 deletions(-)
---
diff --git a/tools/browser/data-manager/data-source-editor.c b/tools/browser/data-manager/data-source-editor.c
index 4bf1def..cf51da4 100644
--- a/tools/browser/data-manager/data-source-editor.c
+++ b/tools/browser/data-manager/data-source-editor.c
@@ -45,6 +45,7 @@ struct _DataSourceEditorPrivate {
DataSource *source;
GdaSet *attributes;
GdauiBasicForm *form;
+ GtkTextBuffer *tbuffer;
};
GType
@@ -96,6 +97,7 @@ data_source_editor_class_init (DataSourceEditorClass *klass)
static void
data_source_editor_init (DataSourceEditor *editor)
{
+ GtkWidget *vpaned;
editor->priv = g_new0 (DataSourceEditorPrivate, 1);
editor->priv->attributes = gda_set_new_inline (4,
"id", G_TYPE_STRING, "",
@@ -105,10 +107,14 @@ data_source_editor_init (DataSourceEditor *editor)
g_signal_connect (editor->priv->attributes, "holder-changed",
G_CALLBACK (attribute_changed_cb), editor);
+ vpaned = gtk_vpaned_new ();
+ gtk_box_pack_start (GTK_BOX (editor), vpaned, TRUE, TRUE, 0);
+ gtk_widget_show (vpaned);
+
GtkWidget *form;
form = gdaui_basic_form_new (editor->priv->attributes);
editor->priv->form = GDAUI_BASIC_FORM (form);
- gtk_box_pack_start (GTK_BOX (editor), form, TRUE, TRUE, 0);
+ gtk_paned_add1 (GTK_PANED (vpaned), form);
gtk_widget_show (form);
GdaHolder *holder;
@@ -131,10 +137,45 @@ data_source_editor_init (DataSourceEditor *editor)
holder = gda_set_get_holder (editor->priv->attributes, "sql");
g_object_set ((GObject*) holder, "name", _("SELECT\nSQL"),
- "description", _("SQL to select data"), NULL);
+ "description", _("Actual SQL executed\nto select data"), NULL);
value = gda_value_new_from_string ("text:PROG_LANG=gda-sql", G_TYPE_STRING);
gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
gda_value_free (value);
+
+ GtkWidget *hbox, *label, *sw, *text;
+ GtkSizeGroup *sg;
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_paned_add2 (GTK_PANED (vpaned), hbox);
+
+ label = gtk_label_new (_("Dependencies:"));
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ sg = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ gtk_size_group_add_widget (sg, label);
+ gdaui_basic_form_add_to_size_group (GDAUI_BASIC_FORM (form), sg, GDAUI_BASIC_FORM_LABELS);
+ g_object_unref ((GObject*) sg);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
+
+ editor->priv->tbuffer = gtk_text_buffer_new (NULL);
+ text = gtk_text_view_new_with_buffer (editor->priv->tbuffer);
+ sg = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ gtk_size_group_add_widget (sg, sw);
+ gdaui_basic_form_add_to_size_group (GDAUI_BASIC_FORM (form), sg, GDAUI_BASIC_FORM_ENTRIES);
+ g_object_unref ((GObject*) sg);
+
+ gtk_container_add (GTK_CONTAINER (sw), text);
+ gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text), GTK_WRAP_WORD);
+ gtk_text_view_set_editable (GTK_TEXT_VIEW (text), FALSE);
+ gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text), FALSE);
+ gtk_text_buffer_create_tag (editor->priv->tbuffer, "section",
+ "weight", PANGO_WEIGHT_BOLD, NULL);
+
+ gtk_widget_show_all (hbox);
}
static void
@@ -147,6 +188,8 @@ data_source_editor_dispose (GObject *object)
editor = DATA_SOURCE_EDITOR (object);
if (editor->priv) {
+ if (editor->priv->tbuffer)
+ g_object_unref ((GObject*) editor->priv->tbuffer);
if (editor->priv->source)
g_object_unref (editor->priv->source);
if (editor->priv->attributes) {
@@ -181,6 +224,56 @@ data_source_editor_new (void)
return (GtkWidget*) editor;
}
+static void
+update_dependencies_display (DataSourceEditor *editor)
+{
+ GtkTextIter start, end;
+ GtkTextBuffer *tbuffer;
+
+ tbuffer = editor->priv->tbuffer;
+ gtk_text_buffer_get_start_iter (tbuffer, &start);
+ gtk_text_buffer_get_end_iter (tbuffer, &end);
+ gtk_text_buffer_delete (tbuffer, &start, &end);
+ gtk_text_buffer_get_start_iter (tbuffer, &start);
+
+ if (editor->priv->source) {
+ GdaSet *import;
+ import = data_source_get_import ( editor->priv->source);
+ gtk_text_buffer_insert_with_tags_by_name (tbuffer, &start,
+ _("Requires:"), -1,
+ "section", NULL);
+ gtk_text_buffer_insert (tbuffer, &start, "\n", -1);
+ if (import && import->holders) {
+ GSList *list;
+ for (list = import->holders; list; list = list->next) {
+ gtk_text_buffer_insert (tbuffer, &start,
+ gda_holder_get_id (GDA_HOLDER (list->data)), -1);
+ gtk_text_buffer_insert (tbuffer, &start, "\n", -1);
+ }
+ }
+ else
+ gtk_text_buffer_insert (tbuffer, &start, "--\n", -1);
+
+ GArray *export;
+ export = data_source_get_export_names ( editor->priv->source);
+ gtk_text_buffer_insert_with_tags_by_name (tbuffer, &start,
+ _("Exports:"), -1,
+ "section", NULL);
+ gtk_text_buffer_insert (tbuffer, &start, "\n", -1);
+ if (export) {
+ gint i;
+ for (i = 0; i < export->len ; i++) {
+ gchar *tmp;
+ tmp = g_array_index (export, gchar *, i);
+ gtk_text_buffer_insert (tbuffer, &start, tmp, -1);
+ gtk_text_buffer_insert (tbuffer, &start, "\n", -1);
+ }
+ }
+ else
+ gtk_text_buffer_insert (tbuffer, &start, "--\n", -1);
+ }
+}
+
/**
* data_source_editor_display_source
* @editor: a #DataSourceEditor widget
@@ -199,6 +292,7 @@ data_source_editor_display_source (DataSourceEditor *editor, DataSource *source)
g_signal_handlers_block_by_func (editor->priv->attributes,
G_CALLBACK (attribute_changed_cb), editor);
+ /* other variables */
if (editor->priv->source)
g_object_unref (editor->priv->source);
if (source) {
@@ -249,6 +343,9 @@ data_source_editor_display_source (DataSourceEditor *editor, DataSource *source)
g_signal_handlers_unblock_by_func (editor->priv->attributes,
G_CALLBACK (attribute_changed_cb), editor);
+
+ /* dependencies */
+ update_dependencies_display (editor);
}
static void
@@ -310,11 +407,23 @@ attribute_changed_cb (GdaSet *set, GdaHolder *holder, DataSourceEditor *editor)
g_free (sql);
}
}
- else if (!strcmp (id, "sql"))
+ else if (!strcmp (id, "sql")) {
data_source_set_query (editor->priv->source, str, NULL);
+ update_dependencies_display (editor);
+ }
else
g_assert_not_reached ();
g_signal_handlers_unblock_by_func (editor->priv->attributes,
G_CALLBACK (attribute_changed_cb), editor);
}
+
+/**
+ * data_source_editor_set_editable
+ */
+void
+data_source_editor_set_readonly (DataSourceEditor *editor)
+{
+ gdaui_basic_form_entry_set_editable (editor->priv->form, NULL,
+ FALSE);
+}
diff --git a/tools/browser/data-manager/data-source-editor.h b/tools/browser/data-manager/data-source-editor.h
index 7ca4437..4cbdf2e 100644
--- a/tools/browser/data-manager/data-source-editor.h
+++ b/tools/browser/data-manager/data-source-editor.h
@@ -54,6 +54,7 @@ GType data_source_editor_get_type (void) G_GNUC_CONST;
GtkWidget *data_source_editor_new (void);
void data_source_editor_display_source (DataSourceEditor *editor, DataSource *source);
+void data_source_editor_set_readonly (DataSourceEditor *editor);
G_END_DECLS
diff --git a/tools/browser/data-manager/data-widget.c b/tools/browser/data-manager/data-widget.c
index 6185c02..c19b1d0 100644
--- a/tools/browser/data-manager/data-widget.c
+++ b/tools/browser/data-manager/data-widget.c
@@ -28,6 +28,7 @@
#include "../common/ui-formgrid.h"
#include "../browser-window.h"
#include "../support.h"
+#include "data-source-editor.h"
/*
* The DataPart structure represents the execution of a single DataSource
@@ -38,13 +39,17 @@ typedef struct {
GtkWidget *top;
GtkNotebook *nb; /* page 0: spinner
- page 1 or 2, depends on @data_widget_page */
+ page 1 or 2, depends on @data_widget_page, @error_widget_page and @edit_widget_page*/
gint data_widget_page;
gint error_widget_page;
+ gint edit_widget_page;
+ gint edit_widget_previous_page;
+
BrowserSpinner *spinner;
guint spinner_show_timer_id;
GtkWidget *data_widget;
GtkWidget *error_widget;
+ GtkWidget *edit_widget;
GdaSet *export_data;
GSList *dep_parts; /* list of DataPart which need to be re-run when anything in @export_data
@@ -200,6 +205,7 @@ create_or_reuse_part (DataWidget *dwid, DataSource *source, gboolean *out_reused
part = g_new0 (DataPart, 1);
part->dwid = dwid;
part->source = g_object_ref (source);
+ part->edit_widget_previous_page = -1;
g_signal_connect (source, "execution-started",
G_CALLBACK (source_exec_started_cb), part);
g_signal_connect (source, "execution-finished",
@@ -349,6 +355,26 @@ add_data_source_mitem_activated_cb (GtkMenuItem *mitem, DataPart *part)
#endif
}
+static void
+data_source_props_activated_cb (GtkCheckMenuItem *mitem, DataPart *part)
+{
+ if (gtk_check_menu_item_get_active (mitem)) {
+ part->edit_widget_previous_page = gtk_notebook_get_current_page (part->nb);
+ if (! part->edit_widget) {
+ part->edit_widget = data_source_editor_new ();
+ data_source_editor_set_readonly (DATA_SOURCE_EDITOR (part->edit_widget));
+ part->edit_widget_page = gtk_notebook_append_page (part->nb, part->edit_widget,
+ NULL);
+ gtk_widget_show (part->edit_widget);
+ }
+ data_source_editor_display_source (DATA_SOURCE_EDITOR (part->edit_widget),
+ part->source);
+ gtk_notebook_set_current_page (part->nb, part->edit_widget_page);
+ }
+ else
+ gtk_notebook_set_current_page (part->nb, part->edit_widget_previous_page);
+}
+
static gchar *compute_fk_dependency (GdaMetaTableForeignKey *fkey, GSList *selfields, gboolean reverse,
DataPart *part, xmlNodePtr *out_sourcespec);
static void
@@ -365,6 +391,12 @@ data_source_menu_clicked_cb (GtkButton *button, DataPart *part)
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+ mitem = gtk_check_menu_item_new_with_label (_("Show data source's properties"));
+ g_signal_connect (mitem, "activate",
+ G_CALLBACK (data_source_props_activated_cb), part);
+ gtk_widget_show (mitem);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
+
GdaStatement *stmt;
stmt = data_source_get_statement (part->source);
if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_SELECT) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]