コード例 #1
0
/**
 * make_tree_model_for_element_model:
 * @xml_element:
 *
 * TODO: Write me
 */
GtkTreeModel*
make_tree_model_for_element_model (xmlElementPtr xml_element)
{  
	GtkTreeStore *store;
	GtkTreeIter root_iter;

	g_assert (xml_element);  

	store = gtk_tree_store_new (N_COLUMNS,
				    G_TYPE_STRING);

	gtk_tree_store_append (store, &root_iter, NULL);  /* Acquire a top-level iterator */

	set_node_text_for_element_by_name (store,
					   &root_iter,
					   (const gchar*)xml_element->name);  /* FIXME: namespace? */

	if (xml_element->content) {
		populate_recursive (store, 
				    &root_iter, 
				    xml_element->content);
	}

	return GTK_TREE_MODEL (store);
}
コード例 #2
0
ファイル: AssocPair.cpp プロジェクト: chrismullins/lasso
int AssocPair::set_relation(iBase_EntitySetHandle set1, iBase_EntityHandle ent2)
{
  if (entOrSet[0] == iRel_ENTITY || entOrSet[1] == iRel_SET)
    ERRORR(iBase_FAILURE, "Invalid relation type");

  // check that if we're passing in an ent for a 'both'-type
  // assoc, there's already a set associated to the other ent
  iBase_EntityHandle tmp_ent;
  if (entOrSet[1] == iRel_BOTH &&
      relSides[0]->get_relation_side(&set1, 1, &tmp_ent) != iBase_SUCCESS)
    ERRORR(iBase_FAILURE, "Couldn't find associated set on right side");

  // set set1 => ent2
  if (relStatus[0] == iRel_ACTIVE)
    CHK_ERRORR( relSides[0]->set_relation_side(&set1, 1, &ent2) );

  // set ent1 <= set2
  if (relStatus[1] == iRel_ACTIVE)
    CHK_ERRORR( relSides[1]->set_relation_side(&ent2, 1, &set1) );

  // if the left side is a 'both'-type association, set the contents of set1
  // to point to ent2 as well
  if (entOrSet[0] == iRel_BOTH)
    CHK_ERRORR( populate_recursive(0, set1, ent2) );

  RETURNR(iBase_SUCCESS);
}
コード例 #3
0
ファイル: AssocPair.cpp プロジェクト: chrismullins/lasso
int AssocPair::change_type(int iface_no, iRel_RelationType type)
{
  if (entOrSet[iface_no] == type)
    RETURNR(iBase_SUCCESS);
  if (entOrSet[iface_no] == iRel_ENTITY || type == iRel_ENTITY)
    ERRORR(iBase_FAILURE, "Can only change type from \"set\" to \"both\", or "
           "vice-versa");

  entOrSet[iface_no] = type;
  if (relStatus[iface_no] != iRel_ACTIVE)
    RETURNR(iBase_SUCCESS);

  iBase_EntitySetHandle *sets = NULL;
  int set_alloc = 0, set_size;
  CHK_ERRORR( relSides[iface_no]->get_related_sets(&sets, &set_alloc,
                                                   &set_size) );
  if (type == iRel_BOTH) {
    if (entOrSet[!iface_no] == iRel_ENTITY) {
      std::vector<iBase_EntityHandle> related_ents(set_size);
      CHK_ERRORR( relSides[iface_no]->get_relation_side(sets, set_size,
                                                        &related_ents[0]) );

      for (int i = 0; i < set_size; i++)
        CHK_ERRORR( populate_recursive(iface_no, sets[i], related_ents[i]) );
    }
    else {
      std::vector<iBase_EntitySetHandle> related_sets(set_size);
      CHK_ERRORR( relSides[iface_no]->get_relation_side(sets, set_size,
                                                        &related_sets[0]) );

      for (int i = 0; i < set_size; i++)
        CHK_ERRORR( populate_recursive(iface_no, sets[i], related_sets[i]) );
    }
  }
  else if (type == iRel_SET) {
    for (int i = 0; i < set_size; i++)
      CHK_ERRORR( unpopulate_recursive(iface_no, sets[i]) );
  }

  free(sets);
  RETURNR(iBase_SUCCESS);
}
コード例 #4
0
ファイル: AssocPair.cpp プロジェクト: chrismullins/lasso
int AssocPair::set_relation(iBase_EntitySetHandle set1,
                            iBase_EntitySetHandle set2)
{
  if (entOrSet[0] == iRel_ENTITY || entOrSet[1] == iRel_ENTITY)
    ERRORR(iBase_FAILURE, "Invalid relation type");

  // set set1 => set2
  if (relStatus[0] == iRel_ACTIVE)
    CHK_ERRORR( relSides[0]->set_relation_side(&set1, 1, &set2) );

  // set set1 <= set2
  if (relStatus[1] == iRel_ACTIVE)
    CHK_ERRORR( relSides[1]->set_relation_side(&set2, 1, &set1) );

  // if either side is a 'both'-type association, set the contents of set1
  // to point to set2 as well (and/or vice-versa)
  if (entOrSet[0] == iRel_BOTH)
    CHK_ERRORR( populate_recursive(0, set1, set2) );
  if (entOrSet[1] == iRel_BOTH)
    CHK_ERRORR( populate_recursive(1, set2, set1) );

  RETURNR(iBase_SUCCESS);
}
コード例 #5
0
static void
add_content_for_type (GtkTreeStore *store,
		      GtkTreeIter *parent_iter, 
		      xmlElementContentPtr content)
{
	g_assert (content);

	switch (content->type) {
	default: g_assert_not_reached ();
	case XML_ELEMENT_CONTENT_PCDATA:
		{
			GtkTreeIter iter_new;

			gtk_tree_store_append (store, &iter_new, parent_iter);

			set_node_text (store,
				       &iter_new,
				       _("Text"));
		}
		break;
	case XML_ELEMENT_CONTENT_ELEMENT:
		{
			GtkTreeIter iter_new;

			gtk_tree_store_append (store, &iter_new, parent_iter);

			set_node_text_for_element_by_name (store,
							   &iter_new,
							   (const gchar*)content->name);
		}
		break;
	case XML_ELEMENT_CONTENT_SEQ:
		/* Do both c1 and c2 in sequence: */
		populate_recursive (store,
				    parent_iter,
				    content->c1);
		populate_recursive (store,
				    parent_iter,
				    content->c2);
		break;
	case XML_ELEMENT_CONTENT_OR:
		{
			GtkTreeIter iter_wrap;

			/* The naive implementation is to add a choice node, and recurse.
			   But if we have something like ( tag-a | tag-b | tag-c | ... | tag-z) in the DTD, we get a tree of ( choice tag-a (choice tag-b (choice tag-c ( ... choice tag-y tag-z))))
			   which creates a grim-looking tree.
			   
			   So if we are a CONTENT_ONCE and our parent content is CONTENT_OR, then we can merge into the parent choice; it is associative and hence bracketing should make no difference...
			*/
			if (content->ocur==XML_ELEMENT_CONTENT_ONCE) {
				if (content->parent) {
					if (content->parent->type==XML_ELEMENT_CONTENT_OR) {
						/* optimised case */
						populate_recursive (store,
								    parent_iter,
								    content->c1);
						populate_recursive (store,
								    parent_iter,
								    content->c2);						
						break;
					}
				}
			}

			gtk_tree_store_append (store, &iter_wrap, parent_iter);

			set_node_text (store,
				       &iter_wrap,
				       _("Choice"));
			populate_recursive (store,
					    &iter_wrap,
					    content->c1);
			populate_recursive (store,
					    &iter_wrap,
					    content->c2);						
		}
		break;
	}
}