예제 #1
0
/**
 * table_relations_new
 *
 * Returns: a new #GtkWidget
 */
GtkWidget *
table_relations_new (TableInfo *tinfo)
{
	TableRelations *trels;

	g_return_val_if_fail (IS_TABLE_INFO (tinfo), NULL);

	trels = TABLE_RELATIONS (g_object_new (TABLE_RELATIONS_TYPE, NULL));

	trels->priv->tinfo = tinfo;
	trels->priv->tcnc = g_object_ref (table_info_get_connection (tinfo));
	g_signal_connect (trels->priv->tcnc, "meta-changed",
			  G_CALLBACK (meta_changed_cb), trels);
	
	/*
	 * Relations
	 */
	trels->priv->canvas = browser_canvas_db_relations_new (NULL);
	gtk_box_pack_start (GTK_BOX (trels), trels->priv->canvas, TRUE, TRUE, 0);
	gtk_widget_show (GTK_WIDGET (trels));

	/*
	 * initial update
	 */
	GdaMetaStruct *mstruct;
	mstruct = t_connection_get_meta_struct (trels->priv->tcnc);
	if (mstruct)
		meta_changed_cb (trels->priv->tcnc, mstruct, trels);

	return (GtkWidget*) trels;
}
예제 #2
0
static void
fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
			  const gchar *selection, SchemaBrowserPerspective *bpers)
{
	if (fav_type == T_FAVORITES_TABLES) {
		GdaQuarkList *ql;
		const gchar *type;
		const gchar *schema = NULL, *table = NULL, *short_name = NULL;

		ql = gda_quark_list_new_from_string (selection);
		if (ql) {
			type = gda_quark_list_find (ql, "OBJ_TYPE");
			schema = gda_quark_list_find (ql, "OBJ_SCHEMA");
			table = gda_quark_list_find (ql, "OBJ_NAME");
			short_name = gda_quark_list_find (ql, "OBJ_SHORT_NAME");
		}
		
		if (!type || !schema || !table) {
			if (ql)
				gda_quark_list_free (ql);
			return;
		}

		if (!strcmp (type, "table")) {
			schema_browser_perspective_display_table_info (bpers, schema, table, short_name);
		}
		else {
			gint ntabs, i;
			ntabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (bpers->priv->notebook));
			for (i = 0; i < ntabs; i++) {
				GtkWidget *child;
				child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
				if (IS_TABLE_INFO (child)) {
					if (!strcmp (schema, table_info_get_table_schema (TABLE_INFO (child))) &&
					    !strcmp (table, table_info_get_table_name (TABLE_INFO (child)))) {
						gtk_notebook_set_current_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
						return;
					}
				}
			}

			g_warning ("Non handled favorite type: %s", type);
			TO_IMPLEMENT;
		}
	
		if (ql)
			gda_quark_list_free (ql);
	}
	else if (fav_type == T_FAVORITES_DIAGRAMS) {
#ifdef HAVE_GOOCANVAS
		schema_browser_perspective_display_diagram (bpers, fav_id);
#else
		g_warning ("Can't display diagram because canvas not compiled.");
#endif
	}
#ifdef GDA_DEBUG_NO
	g_print ("Reacted to selection fav_id=>%d type=>%u, contents=>%s\n", fav_id, fav_type, selection);	
#endif
}
예제 #3
0
/**
 * schema_browser_perspective_display_table_info
 *
 * Display (and create if necessary) a new page for the table's properties
 */
void
schema_browser_perspective_display_table_info (SchemaBrowserPerspective *bpers,
					       const gchar *table_schema,
					       const gchar *table_name,
					       G_GNUC_UNUSED const gchar *table_short_name)
{
	g_return_if_fail (IS_SCHEMA_BROWSER_PERSPECTIVE (bpers));

	gint ntabs, i;
	ntabs = gtk_notebook_get_n_pages (GTK_NOTEBOOK (bpers->priv->notebook));
	for (i = 0; i < ntabs; i++) {
		GtkWidget *child;
		child = gtk_notebook_get_nth_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
		if (IS_TABLE_INFO (child)) {
			if (!strcmp (table_schema, table_info_get_table_schema (TABLE_INFO (child))) &&
			    !strcmp (table_name, table_info_get_table_name (TABLE_INFO (child)))) {
				gtk_notebook_set_current_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
				return;
			}
		}
	}
	
	GtkWidget *ti;
	ti = table_info_new (browser_window_get_connection (bpers->priv->bwin), table_schema, table_name);
	if (ti) {
		GtkWidget *close_btn;
		GtkWidget *tab_label;
		gint i;
		
		tab_label = browser_page_get_tab_label (BROWSER_PAGE (ti), &close_btn);
		i = gtk_notebook_append_page (GTK_NOTEBOOK (bpers->priv->notebook), ti, tab_label);
		g_signal_connect (close_btn, "clicked",
				  G_CALLBACK (close_button_clicked_cb), ti);
		
		gtk_widget_show (ti);

		tab_label = browser_page_get_tab_label (BROWSER_PAGE (ti), NULL);
		gtk_notebook_set_menu_label (GTK_NOTEBOOK (bpers->priv->notebook), ti, tab_label);

		gtk_notebook_set_current_page (GTK_NOTEBOOK (bpers->priv->notebook), i);
		gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (bpers->priv->notebook), ti,
						  TRUE);
		gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (bpers->priv->notebook), ti,
						 TRUE);
	}
}
예제 #4
0
/**
 * table_preferences_new
 *
 * Returns: a new #GtkWidget
 */
GtkWidget *
table_preferences_new (TableInfo *tinfo)
{
	TablePreferences *tpref;

	g_return_val_if_fail (IS_TABLE_INFO (tinfo), NULL);

	tpref = TABLE_PREFERENCES (g_object_new (TABLE_PREFERENCES_TYPE, NULL));

	tpref->priv->tinfo = tinfo;
	tpref->priv->bcnc = g_object_ref (table_info_get_connection (tinfo));
	g_signal_connect (tpref->priv->bcnc, "meta-changed",
			  G_CALLBACK (meta_changed_cb), tpref);
	g_signal_connect (tpref->priv->bcnc, "table-column-pref-changed",
			  G_CALLBACK (table_column_pref_changed_cb), tpref);
	
	/* top vbox */
	GtkWidget *top_vbox;
	top_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
	gtk_box_pack_start (GTK_BOX (tpref), top_vbox, TRUE, TRUE, 0);

	/* Field's display properties */
	GtkWidget *grid;

	grid = gtk_grid_new ();
	gtk_box_pack_start (GTK_BOX (top_vbox), grid, TRUE, TRUE, 0);
	gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
	gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
	gtk_container_set_border_width (GTK_CONTAINER (grid), 6);

	/* left column */
	GtkWidget *label;
	gchar *str;
	label = gtk_label_new ("");
	str = g_strdup_printf ("<b>%s:</b>", _("Table's fields"));
	gtk_label_set_markup (GTK_LABEL (label), str);
	g_free (str);
	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
	gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);

	GtkWidget *sw, *treeview;
	sw = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
					     GTK_SHADOW_ETCHED_IN);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
					GTK_POLICY_NEVER,
					GTK_POLICY_AUTOMATIC);
	gtk_grid_attach (GTK_GRID (grid), sw, 0, 1, 1, 1);

	tpref->priv->columns_store = gtk_list_store_new (NUM_COLUMNS,
							 G_TYPE_POINTER, G_TYPE_GTYPE,
							 G_TYPE_STRING);
	treeview = browser_make_tree_view (GTK_TREE_MODEL (tpref->priv->columns_store));
	tpref->priv->columns_treeview = GTK_TREE_VIEW (treeview);
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
	gtk_container_add (GTK_CONTAINER (sw), treeview);

	/* treeview's columns */
	GtkTreeViewColumn *col;
	GtkCellRenderer *cell;
	cell = gtk_cell_renderer_text_new ();
	col = gtk_tree_view_column_new ();
	gtk_tree_view_column_pack_start (col, cell, TRUE);
	gtk_tree_view_column_set_cell_data_func (col, cell,
						 (GtkTreeCellDataFunc) cell_name_data_func, NULL, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), col);
	
	/* selection handling */
	GtkTreeSelection *select;
	select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
	gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
	g_signal_connect (G_OBJECT (select), "changed",
			  G_CALLBACK (selection_changed_cb), tpref);


	/* right column */
	label = gtk_label_new ("");
	str = g_strdup_printf ("<b>%s:</b>", _("Field's display preferences"));
	gtk_label_set_markup (GTK_LABEL (label), str);
	g_free (str);
	gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
	gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);

	tpref->priv->field_props = create_column_properties (tpref);
	gtk_grid_attach (GTK_GRID (grid), tpref->priv->field_props, 1, 1, 1, 1);

	/* show all */
	gtk_widget_show_all (top_vbox);

	/*
	 * initial update
	 */
	GdaMetaStruct *mstruct;
	mstruct = browser_connection_get_meta_struct (tpref->priv->bcnc);
	if (mstruct)
		meta_changed_cb (tpref->priv->bcnc, mstruct, tpref);
	selection_changed_cb (select, tpref);

	g_signal_connect (tpref->priv->columns_store, "row-changed",
			  G_CALLBACK (columns_model_row_changed_cb), tpref);

	return (GtkWidget*) tpref;
}