[libgda] GdaBrowser: it's now possible to view the contents for all the tables in a tables relations canvas



commit c1f23ff3aea4a7350a3bc0f2e6475ef5be71148c
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Mar 31 21:26:26 2010 +0200

    GdaBrowser: it's now possible to view the contents for all the tables in a tables relations canvas

 tools/browser/canvas/browser-canvas-db-relations.c |   55 +++++++++++++++++++
 tools/browser/canvas/browser-canvas-db-relations.h |   20 ++++---
 tools/browser/data-manager/data-source.c           |   14 +++++-
 tools/browser/decl.h                               |    4 +-
 tools/browser/schema-browser/relations-diagram.c   |   58 +++++++++++++++++++-
 tools/browser/schema-browser/table-info.c          |    3 +-
 6 files changed, 139 insertions(+), 15 deletions(-)
---
diff --git a/tools/browser/canvas/browser-canvas-db-relations.c b/tools/browser/canvas/browser-canvas-db-relations.c
index 7650756..b9a6e44 100644
--- a/tools/browser/canvas/browser-canvas-db-relations.c
+++ b/tools/browser/canvas/browser-canvas-db-relations.c
@@ -647,3 +647,58 @@ browser_canvas_db_relations_select_table (BrowserCanvasDbRelations *canvas,
 	browser_canvas_item_toggle_select (BROWSER_CANVAS (canvas), (BrowserCanvasItem*) table);
 }
 
+/**
+ * browser_canvas_db_relations_items_to_data_manager
+ */
+gchar *
+browser_canvas_db_relations_items_to_data_manager (BrowserCanvasDbRelations *canvas)
+{
+	gchar *retval = NULL;
+	GSList *list;
+	xmlDocPtr doc;
+	xmlNodePtr topnode;
+
+	g_return_val_if_fail (IS_BROWSER_CANVAS (canvas), NULL);
+	
+	/* create XML doc and root node */
+	doc = xmlNewDoc (BAD_CAST "1.0");
+	topnode = xmlNewDocNode (doc, NULL, BAD_CAST "data", NULL);
+        xmlDocSetRootElement (doc, topnode);
+	
+	/* actually serialize all the items which can be serialized */
+	for (list = BROWSER_CANVAS (canvas)->priv->items; list; list = list->next) {
+                BrowserCanvasItem *item = BROWSER_CANVAS_ITEM (list->data);
+		GdaMetaTable *mtable;
+
+		mtable = g_hash_table_lookup (canvas->priv->hash_tables, item);
+		if (mtable) {
+			xmlNodePtr node;
+			node = xmlNewChild (topnode, NULL, BAD_CAST "table", NULL);
+			xmlSetProp (node, BAD_CAST "name",
+				    BAD_CAST GDA_META_DB_OBJECT (mtable)->obj_short_name);
+
+			GSList *fklist;
+			for (fklist = mtable->fk_list; fklist; fklist = fklist->next) {
+				GdaMetaTableForeignKey *fk = (GdaMetaTableForeignKey*) fklist->data;
+				GooCanvasItem *fk_item;
+				
+				fk_item = g_hash_table_lookup (canvas->priv->hash_fkeys, fk);
+				if (fk_item)
+					xmlNewChild (node, NULL, BAD_CAST "link_with",
+						     BAD_CAST fk->depend_on->obj_short_name);
+			}
+
+		}
+	}
+
+	/* create buffer from XML tree */
+	xmlChar *xstr = NULL;
+	xmlDocDumpFormatMemory (doc, &xstr, NULL, 1);
+	if (xstr) {
+		retval = g_strdup ((gchar *) xstr);
+		xmlFree (xstr);
+	}
+	xmlFreeDoc (doc);
+	
+	return retval;	
+}
diff --git a/tools/browser/canvas/browser-canvas-db-relations.h b/tools/browser/canvas/browser-canvas-db-relations.h
index b9270f7..0ade836 100644
--- a/tools/browser/canvas/browser-canvas-db-relations.h
+++ b/tools/browser/canvas/browser-canvas-db-relations.h
@@ -51,17 +51,19 @@ struct _BrowserCanvasDbRelationsClass
 };
 
 /* generic widget's functions */
-GType            browser_canvas_db_relations_get_type        (void) G_GNUC_CONST;
+GType               browser_canvas_db_relations_get_type              (void) G_GNUC_CONST;
 
-GtkWidget       *browser_canvas_db_relations_new             (GdaMetaStruct *mstruct);
+GtkWidget          *browser_canvas_db_relations_new                   (GdaMetaStruct *mstruct);
 
-BrowserCanvasTable *browser_canvas_db_relations_get_table_item  (BrowserCanvasDbRelations *canvas, GdaMetaTable *table);
-BrowserCanvasTable *browser_canvas_db_relations_add_table  (BrowserCanvasDbRelations *canvas, 
-							    const GValue *table_catalog,
-							    const GValue *table_schema,
-							    const GValue *table_name);
-void                browser_canvas_db_relations_select_table (BrowserCanvasDbRelations *canvas,
-							      BrowserCanvasTable *table);
+BrowserCanvasTable *browser_canvas_db_relations_get_table_item        (BrowserCanvasDbRelations *canvas,
+								       GdaMetaTable *table);
+BrowserCanvasTable *browser_canvas_db_relations_add_table             (BrowserCanvasDbRelations *canvas, 
+								       const GValue *table_catalog,
+								       const GValue *table_schema,
+								       const GValue *table_name);
+void                browser_canvas_db_relations_select_table          (BrowserCanvasDbRelations *canvas,
+								       BrowserCanvasTable *table);
+gchar              *browser_canvas_db_relations_items_to_data_manager (BrowserCanvasDbRelations *canvas);
 
 G_END_DECLS
 
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index af6c07b..aae9c9c 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -398,12 +398,24 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
 		xmlFree (tname);
 		return FALSE;
 	}
+	gda_sql_builder_select_set_limit (b,
+					  gda_sql_builder_add_expr (b, 0, NULL,
+								    G_TYPE_INT, DEFAULT_DATA_SELECT_LIMIT),
+					  0);
 
 	for (i = 0, list = mtable->columns; list; i++, list = list->next) {
 		GdaMetaTableColumn *mcol;
 		mcol = GDA_META_TABLE_COLUMN (list->data);
 		gda_sql_builder_select_add_field (b, mcol->column_name, NULL, NULL);
 
+		if (mcol->pkey) {
+			/* ORDER BY */
+			gda_sql_builder_select_order_by (b,
+							 gda_sql_builder_add_id (b, 0,
+										 mcol->column_name),
+							 FALSE, NULL);
+		}
+
 		/* export value */
 		gchar *tmp;
 		if (source->priv->id)
@@ -512,7 +524,7 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
 				  G_CALLBACK (params_changed_cb), source);
 	}
 
-	/* g_print ("SQL [%s]\n", gda_statement_to_sql (source->priv->stmt, NULL, NULL)); */
+	/*g_print ("SQL [%s]\n", gda_statement_to_sql (source->priv->stmt, NULL, NULL));*/
 	g_object_unref (b);
 
 	return source->priv->stmt ? TRUE : FALSE;
diff --git a/tools/browser/decl.h b/tools/browser/decl.h
index 42ef116..09eb70b 100644
--- a/tools/browser/decl.h
+++ b/tools/browser/decl.h
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 2009 The GNOME Foundation.
+ * Copyright (C) 2009 - 2010 The GNOME Foundation.
  *
  * AUTHORS:
  * 	Vivien Malerba <malerba gnome-db org>
@@ -51,6 +51,8 @@ typedef struct {
 
 #define DEFAULT_FAVORITES_SIZE 150
 
+#define DEFAULT_DATA_SELECT_LIMIT 500
+
 G_END_DECLS
 
 #endif
diff --git a/tools/browser/schema-browser/relations-diagram.c b/tools/browser/schema-browser/relations-diagram.c
index 97d4514..b12f395 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -30,6 +30,8 @@
 #include "../common/popup-container.h"
 #include "../browser-page.h"
 #include "../browser-perspective.h"
+#include "../browser-window.h"
+#include "../data-manager/data-manager-perspective.h"
 
 struct _RelationsDiagramPrivate {
 	BrowserConnection *bcnc;
@@ -58,6 +60,8 @@ static void relations_diagram_get_property (GObject *object,
 
 /* BrowserPage interface */
 static void                 relations_diagram_page_init (BrowserPageIface *iface);
+static GtkActionGroup      *relations_diagram_page_get_actions_group (BrowserPage *page);
+static const gchar         *relations_diagram_page_get_actions_ui (BrowserPage *page);
 static GtkWidget           *relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button);
 
 static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram);
@@ -99,8 +103,8 @@ relations_diagram_class_init (RelationsDiagramClass *klass)
 static void
 relations_diagram_page_init (BrowserPageIface *iface)
 {
-	iface->i_get_actions_group = NULL;
-	iface->i_get_actions_ui = NULL;
+	iface->i_get_actions_group = relations_diagram_page_get_actions_group;
+	iface->i_get_actions_ui = relations_diagram_page_get_actions_ui;
 	iface->i_get_tab_label = relations_diagram_page_get_tab_label;
 }
 
@@ -492,6 +496,56 @@ relations_diagram_get_fav_id (RelationsDiagram *diagram)
 	return diagram->priv->fav_id;
 }
 
+static void
+action_view_contents_cb  (GtkAction *action, RelationsDiagram *diagram)
+{
+	gchar *str;
+	str = browser_canvas_db_relations_items_to_data_manager (BROWSER_CANVAS_DB_RELATIONS (diagram->priv->canvas));
+	g_print ("%s\n", str);
+
+	if (str) {
+		BrowserWindow *bwin;
+		BrowserPerspective *pers;
+		bwin = (BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) diagram);
+		pers = browser_window_change_perspective (bwin, "Data manager");
+
+		data_manager_perspective_new_tab (DATA_MANAGER_PERSPECTIVE (pers), str);
+		g_free (str);
+	}
+}
+
+
+static GtkActionEntry ui_actions[] = {
+	{ "ViewContents", GTK_STOCK_EDIT, N_("_Contents"), NULL, N_("View contents"),
+	  G_CALLBACK (action_view_contents_cb)},
+};
+static const gchar *ui_actions_info =
+	"<ui>"
+	"  <menubar name='MenuBar'>"
+	"  </menubar>"
+	"  <toolbar name='ToolBar'>"
+	"    <separator/>"
+	"    <toolitem action='ViewContents'/>"
+	"  </toolbar>"
+	"</ui>";
+
+static GtkActionGroup *
+relations_diagram_page_get_actions_group (BrowserPage *page)
+{
+	GtkActionGroup *agroup;
+	agroup = gtk_action_group_new ("SchemaBrowserRelationsDiagramActions");
+	gtk_action_group_add_actions (agroup, ui_actions, G_N_ELEMENTS (ui_actions), page);
+	
+	return agroup;
+}
+
+static const gchar *
+relations_diagram_page_get_actions_ui (BrowserPage *page)
+{
+	return ui_actions_info;
+}
+
+
 static GtkWidget *
 relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button)
 {
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index 64b7adf..40f5c63 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -468,7 +468,6 @@ action_view_contents_cb  (GtkAction *action, TableInfo *tinfo)
 	BrowserPerspective *pers;
 	bwin = (BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo);
 	pers = browser_window_change_perspective (bwin, "Data manager");
-	TO_IMPLEMENT;
 
 	xmlDocPtr doc;
 	xmlNodePtr node, topnode;
@@ -507,7 +506,7 @@ static GtkActionGroup *
 table_info_page_get_actions_group (BrowserPage *page)
 {
 	GtkActionGroup *agroup;
-	agroup = gtk_action_group_new ("SchemaBrowserRelationsDiagramActions");
+	agroup = gtk_action_group_new ("SchemaBrowserTableInfoActions");
 	gtk_action_group_add_actions (agroup, ui_actions, G_N_ELEMENTS (ui_actions), page);
 	
 	return agroup;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]