1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : MG_trees.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include "merge.hxx" |
---|
12 | #include <awt_sel_boxes.hxx> |
---|
13 | #include <aw_root.hxx> |
---|
14 | #include <aw_awar.hxx> |
---|
15 | #include <aw_msg.hxx> |
---|
16 | #include <arbdbt.h> |
---|
17 | |
---|
18 | #define AWAR_TREE_NAME1 "tmp/merge1/tree_name" |
---|
19 | #define AWAR_TREE_DEST1 "tmp/merge1/tree_dest" |
---|
20 | #define AWAR_TREE_NAME2 "tmp/merge2/tree_name" |
---|
21 | #define AWAR_TREE_DEST2 "tmp/merge2/tree_dest" |
---|
22 | |
---|
23 | void MG_create_trees_awar(AW_root *aw_root, AW_default aw_def) |
---|
24 | { |
---|
25 | aw_root->awar_string(AWAR_TREE_NAME1, "", aw_def); |
---|
26 | aw_root->awar_string(AWAR_TREE_DEST1, "", aw_def); |
---|
27 | aw_root->awar_string(AWAR_TREE_NAME2, "", aw_def); |
---|
28 | aw_root->awar_string(AWAR_TREE_DEST2, "", aw_def); |
---|
29 | } |
---|
30 | |
---|
31 | static void MG_tree_rename_cb(AW_window *aww, GBDATA *gbd, int tree_nr) { |
---|
32 | const char *tsource = tree_nr == 1 ? AWAR_TREE_NAME1 : AWAR_TREE_NAME2; |
---|
33 | const char *tdest = tree_nr == 1 ? AWAR_TREE_DEST1 : AWAR_TREE_DEST2; |
---|
34 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
35 | char *dest = aww->get_root()->awar(tdest)->read_string(); |
---|
36 | |
---|
37 | GB_ERROR error = GBT_check_tree_name(dest); |
---|
38 | if (!error) { |
---|
39 | error = GB_begin_transaction(gbd); |
---|
40 | |
---|
41 | if (!error) { |
---|
42 | GBDATA *gb_tree_data = GB_search(gbd, "tree_data", GB_CREATE_CONTAINER); |
---|
43 | if (!gb_tree_data) error = GB_await_error(); |
---|
44 | else { |
---|
45 | GBDATA *gb_tree_name = GB_entry(gb_tree_data, source); |
---|
46 | GBDATA *gb_dest_tree = GB_entry(gb_tree_data, dest); |
---|
47 | |
---|
48 | if (gb_dest_tree) { |
---|
49 | error = GBS_global_string("Tree '%s' already exists", dest); |
---|
50 | } |
---|
51 | else if (gb_tree_name) { |
---|
52 | GBDATA *gb_new_tree = GB_create_container(gb_tree_data, dest); |
---|
53 | error = GB_copy(gb_new_tree, gb_tree_name); |
---|
54 | if (!error) error = GB_delete(gb_tree_name); |
---|
55 | } |
---|
56 | else { |
---|
57 | error = "Please select a tree first"; |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | error = GB_end_transaction(gbd, error); |
---|
62 | } |
---|
63 | |
---|
64 | aww->hide_or_notify(error); |
---|
65 | |
---|
66 | free(source); |
---|
67 | free(dest); |
---|
68 | } |
---|
69 | |
---|
70 | static AW_window *MG_create_tree_rename_window1(AW_root *root) |
---|
71 | { |
---|
72 | AW_window_simple *aws = new AW_window_simple; |
---|
73 | aws->init(root, "MERGE_RENAME_TREE_1", "TREE RENAME 1"); |
---|
74 | aws->load_xfig("ad_al_si.fig"); |
---|
75 | |
---|
76 | aws->callback((AW_CB0)AW_POPDOWN); |
---|
77 | aws->at("close"); |
---|
78 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
79 | |
---|
80 | aws->at("label"); |
---|
81 | aws->create_autosize_button(0, "Please enter the new name\nof the tree"); |
---|
82 | |
---|
83 | aws->at("input"); |
---|
84 | aws->create_input_field(AWAR_TREE_DEST1, 15); |
---|
85 | |
---|
86 | aws->at("ok"); |
---|
87 | aws->callback((AW_CB)MG_tree_rename_cb, (AW_CL)GLOBAL_gb_merge, 1); |
---|
88 | aws->create_button("GO", "GO", "G"); |
---|
89 | |
---|
90 | return (AW_window *)aws; |
---|
91 | } |
---|
92 | |
---|
93 | static AW_window *MG_create_tree_rename_window2(AW_root *root) |
---|
94 | { |
---|
95 | AW_window_simple *aws = new AW_window_simple; |
---|
96 | aws->init(root, "MERGE_RENAME_TREE_2", "TREE RENAME 2"); |
---|
97 | aws->load_xfig("ad_al_si.fig"); |
---|
98 | |
---|
99 | aws->callback((AW_CB0)AW_POPDOWN); |
---|
100 | aws->at("close"); |
---|
101 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
102 | |
---|
103 | aws->at("label"); |
---|
104 | aws->create_autosize_button(0, "Please enter the new name\nof the tree"); |
---|
105 | |
---|
106 | aws->at("input"); |
---|
107 | aws->create_input_field(AWAR_TREE_DEST2, 15); |
---|
108 | |
---|
109 | aws->at("ok"); |
---|
110 | aws->callback((AW_CB)MG_tree_rename_cb, (AW_CL)GLOBAL_gb_dest, 2); |
---|
111 | aws->create_button("GO", "GO", "G"); |
---|
112 | |
---|
113 | return (AW_window *)aws; |
---|
114 | } |
---|
115 | static void MG_tr_delete_cb(AW_window *aww, GBDATA *gbd, long tree_nr) { |
---|
116 | const char *tsource = tree_nr == 1 ? AWAR_TREE_NAME1 : AWAR_TREE_NAME2; |
---|
117 | char *source = aww->get_root()->awar(tsource)->read_string(); |
---|
118 | GB_ERROR error = GB_begin_transaction(gbd); |
---|
119 | |
---|
120 | if (!error) { |
---|
121 | GBDATA *gb_tree = GBT_get_tree(gbd, source); |
---|
122 | |
---|
123 | if (gb_tree) error = GB_delete(gb_tree); |
---|
124 | else { |
---|
125 | if (GB_have_error()) error = GBS_global_string("Could not find tree '%s' (Reason: %s)", source, GB_await_error()); |
---|
126 | else error = "Please select a tree"; |
---|
127 | } |
---|
128 | } |
---|
129 | GB_end_transaction_show_error(gbd, error, aw_message); |
---|
130 | free(source); |
---|
131 | } |
---|
132 | static void MG_transfer_tree(AW_window *aww) { |
---|
133 | AW_root *awr = aww->get_root(); |
---|
134 | char *source = awr->awar(AWAR_TREE_NAME1)->read_string(); |
---|
135 | char *dest = awr->awar(AWAR_TREE_NAME1)->read_string(); |
---|
136 | |
---|
137 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_dest); |
---|
138 | if (!error) error = GB_begin_transaction(GLOBAL_gb_merge); |
---|
139 | |
---|
140 | if (!error) { |
---|
141 | GBDATA *gb_tree_data1 = GB_search(GLOBAL_gb_merge, "tree_data", GB_CREATE_CONTAINER); |
---|
142 | GBDATA *gb_tree_data2 = GB_search(GLOBAL_gb_dest, "tree_data", GB_CREATE_CONTAINER); |
---|
143 | |
---|
144 | if (!gb_tree_data1 || !gb_tree_data2) error = GB_await_error(); |
---|
145 | else { |
---|
146 | GBDATA *gb_source = GB_entry(gb_tree_data1, source); |
---|
147 | GBDATA *gb_dest_tree = GB_entry(gb_tree_data2, dest); |
---|
148 | |
---|
149 | if (!gb_source) error = "Please select the tree you want to transfer"; |
---|
150 | else if (gb_dest_tree) error = GBS_global_string("Tree '%s' already exists, delete it first", dest); |
---|
151 | else { |
---|
152 | gb_dest_tree = GB_create_container(gb_tree_data2, dest); |
---|
153 | if (!gb_dest_tree) error = GB_await_error(); |
---|
154 | else error = GB_copy(gb_dest_tree, gb_source); |
---|
155 | } |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | error = GB_end_transaction(GLOBAL_gb_dest, error); |
---|
160 | GB_end_transaction_show_error(GLOBAL_gb_merge, error, aw_message); |
---|
161 | |
---|
162 | free(source); |
---|
163 | free(dest); |
---|
164 | } |
---|
165 | |
---|
166 | AW_window *MG_merge_trees_cb(AW_root *awr) { |
---|
167 | static AW_window_simple *aws = 0; |
---|
168 | if (aws) return (AW_window *)aws; |
---|
169 | |
---|
170 | aws = new AW_window_simple; |
---|
171 | aws->init(awr, "MERGE_TREES", "MERGE TREES"); |
---|
172 | aws->load_xfig("merge/trees.fig"); |
---|
173 | |
---|
174 | aws->button_length(20); |
---|
175 | |
---|
176 | aws->at("close"); aws->callback((AW_CB0)AW_POPDOWN); |
---|
177 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
178 | |
---|
179 | aws->at("help"); |
---|
180 | aws->callback(AW_POPUP_HELP, (AW_CL)"mg_trees.hlp"); |
---|
181 | aws->create_button("HELP", "HELP", "H"); |
---|
182 | |
---|
183 | aws->at("trees1"); |
---|
184 | awt_create_selection_list_on_trees(GLOBAL_gb_merge, (AW_window *)aws, AWAR_TREE_NAME1); |
---|
185 | |
---|
186 | aws->at("trees2"); |
---|
187 | awt_create_selection_list_on_trees(GLOBAL_gb_dest, (AW_window *)aws, AWAR_TREE_NAME2); |
---|
188 | |
---|
189 | aws->at("delete1"); |
---|
190 | aws->callback((AW_CB)MG_tr_delete_cb, (AW_CL)GLOBAL_gb_merge, 1); |
---|
191 | aws->create_button("DELETE TREE_DB1", "Delete Tree"); |
---|
192 | |
---|
193 | aws->at("delete2"); |
---|
194 | aws->callback((AW_CB)MG_tr_delete_cb, (AW_CL)GLOBAL_gb_dest, 2); |
---|
195 | aws->create_button("DELETE_TREE_DB2", "Delete Tree"); |
---|
196 | |
---|
197 | aws->at("rename1"); |
---|
198 | aws->callback((AW_CB1)AW_POPUP, (AW_CL)MG_create_tree_rename_window1); |
---|
199 | aws->create_button("RENAME_TREE_DB1", "Rename Tree"); |
---|
200 | |
---|
201 | aws->at("rename2"); |
---|
202 | aws->callback((AW_CB1)AW_POPUP, (AW_CL)MG_create_tree_rename_window2); |
---|
203 | aws->create_button("RENAME_TREE_DB2", "Rename Tree"); |
---|
204 | |
---|
205 | aws->at("transfer"); |
---|
206 | aws->callback(MG_transfer_tree); |
---|
207 | aws->create_button("TRANSFER_TREE", "Transfer Tree"); |
---|
208 | |
---|
209 | aws->button_length(0); |
---|
210 | aws->shadow_width(1); |
---|
211 | aws->at("icon"); |
---|
212 | aws->callback(AW_POPUP_HELP, (AW_CL)"mg_trees.hlp"); |
---|
213 | aws->create_button("HELP_MERGE", "#merge/icon.bitmap"); |
---|
214 | |
---|
215 | return (AW_window *)aws; |
---|
216 | } |
---|
217 | |
---|