1 | // ================================================================ // |
---|
2 | // // |
---|
3 | // File : species.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ================================================================ // |
---|
10 | |
---|
11 | #include "item_sel_list.h" |
---|
12 | |
---|
13 | #include <arbdbt.h> |
---|
14 | #include <aw_root.hxx> |
---|
15 | #include <aw_awars.hxx> |
---|
16 | |
---|
17 | |
---|
18 | static GBDATA *get_first_species_data(GBDATA *gb_main, AW_root *, QUERY_RANGE) { |
---|
19 | return GBT_get_species_data(gb_main); |
---|
20 | } |
---|
21 | static GBDATA *get_next_species_data(GBDATA *, QUERY_RANGE) { |
---|
22 | return NULp; // there is only ONE species_data |
---|
23 | } |
---|
24 | |
---|
25 | static void select_species(GBDATA*, AW_root *aw_root, const char *item_name) { |
---|
26 | aw_root->awar(AWAR_SPECIES_NAME)->write_string(item_name); |
---|
27 | } |
---|
28 | |
---|
29 | static GBDATA* get_selected_species(GBDATA *gb_main, AW_root *aw_root) { |
---|
30 | char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
31 | GBDATA *gb_species = NULp; |
---|
32 | if (species_name[0]) { |
---|
33 | gb_species = GBT_find_species(gb_main, species_name); |
---|
34 | } |
---|
35 | free(species_name); |
---|
36 | return gb_species; |
---|
37 | } |
---|
38 | |
---|
39 | static void add_selected_species_changed_cb(AW_root *aw_root, const RootCallback& cb) { |
---|
40 | aw_root->awar(AWAR_SPECIES_NAME)->add_callback(cb); |
---|
41 | } |
---|
42 | |
---|
43 | static char* get_species_id(GBDATA *, GBDATA *gb_species) { |
---|
44 | GBDATA *gb_name = GB_entry(gb_species, "name"); |
---|
45 | if (!gb_name) return NULp; // species w/o name -> skip |
---|
46 | return GB_read_as_string(gb_name); |
---|
47 | } |
---|
48 | |
---|
49 | static GBDATA *find_species_by_id(GBDATA *gb_main, const char *id) { |
---|
50 | return GBT_find_species(gb_main, id); // id is 'name' field |
---|
51 | } |
---|
52 | |
---|
53 | static GBDATA *get_first_species(GBDATA *gb_species_data, QUERY_RANGE range) { |
---|
54 | GBDATA *gb_first = NULp; |
---|
55 | switch (range) { |
---|
56 | case QUERY_ALL_ITEMS: gb_first = GBT_first_species_rel_species_data(gb_species_data); break; |
---|
57 | case QUERY_MARKED_ITEMS: gb_first = GBT_first_marked_species_rel_species_data(gb_species_data); break; |
---|
58 | case QUERY_CURRENT_ITEM: gb_first = get_selected_species(GB_get_root(gb_species_data), AW_root::SINGLETON); break; |
---|
59 | } |
---|
60 | return gb_first; |
---|
61 | } |
---|
62 | static GBDATA *get_next_species(GBDATA *gb_prev, QUERY_RANGE range) { |
---|
63 | GBDATA *gb_next = NULp; |
---|
64 | switch (range) { |
---|
65 | case QUERY_ALL_ITEMS: gb_next = GBT_next_species(gb_prev); break; |
---|
66 | case QUERY_MARKED_ITEMS: gb_next = GBT_next_marked_species(gb_prev); break; |
---|
67 | case QUERY_CURRENT_ITEM: gb_next = NULp; break; |
---|
68 | } |
---|
69 | return gb_next; |
---|
70 | } |
---|
71 | |
---|
72 | static void refresh_displayed_species() { |
---|
73 | AW_root::SINGLETON->awar(AWAR_TREE_REFRESH)->touch(); |
---|
74 | } |
---|
75 | |
---|
76 | static struct MutableItemSelector ITEM_species = { |
---|
77 | QUERY_ITEM_SPECIES, |
---|
78 | select_species, |
---|
79 | get_species_id, |
---|
80 | find_species_by_id, |
---|
81 | species_field_selection_list_update_cb, |
---|
82 | 12, |
---|
83 | CHANGE_KEY_PATH, |
---|
84 | "species", |
---|
85 | "species", |
---|
86 | "name", |
---|
87 | get_first_species_data, |
---|
88 | get_next_species_data, |
---|
89 | get_first_species, |
---|
90 | get_next_species, |
---|
91 | get_selected_species, |
---|
92 | add_selected_species_changed_cb, |
---|
93 | NULp, NULp, |
---|
94 | refresh_displayed_species, |
---|
95 | }; |
---|
96 | |
---|
97 | static struct MutableItemSelector ITEM_organism = { |
---|
98 | QUERY_ITEM_SPECIES, |
---|
99 | select_species, |
---|
100 | get_species_id, |
---|
101 | find_species_by_id, |
---|
102 | species_field_selection_list_update_cb, |
---|
103 | 12, |
---|
104 | CHANGE_KEY_PATH, |
---|
105 | "organism", |
---|
106 | "organism", |
---|
107 | "name", |
---|
108 | get_first_species_data, |
---|
109 | get_next_species_data, |
---|
110 | get_first_species, |
---|
111 | get_next_species, |
---|
112 | get_selected_species, |
---|
113 | add_selected_species_changed_cb, |
---|
114 | NULp, NULp, |
---|
115 | refresh_displayed_species, |
---|
116 | }; |
---|
117 | |
---|
118 | ItemSelector& SPECIES_get_selector() { return ITEM_species; } |
---|
119 | ItemSelector& ORGANISM_get_selector() { return ITEM_organism; } |
---|
120 | |
---|