1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AdminGui.cxx // |
---|
4 | // Purpose : alignment admin GUI // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #include <AliAdmin.h> |
---|
12 | #include <insdel.h> |
---|
13 | |
---|
14 | #include <awt_sel_boxes.hxx> |
---|
15 | #include <awt_prompt.hxx> |
---|
16 | |
---|
17 | #include <aw_question.hxx> |
---|
18 | #include <aw_msg.hxx> |
---|
19 | |
---|
20 | #include <arbdbt.h> |
---|
21 | |
---|
22 | static void alignment_vars_callback(AW_root *, AliAdmin *admin) { |
---|
23 | ali_assert(!GB_have_error()); |
---|
24 | |
---|
25 | GBDATA *gb_main = admin->get_gb_main(); |
---|
26 | GB_transaction ta(gb_main); |
---|
27 | GBDATA *ali_cont = GBT_get_alignment(gb_main, admin->get_selected_ali()); |
---|
28 | |
---|
29 | if (!ali_cont) { |
---|
30 | GB_clear_error(); |
---|
31 | admin->type_awar()->unmap(); |
---|
32 | admin->len_awar()->unmap(); |
---|
33 | admin->aligned_awar()->unmap(); |
---|
34 | admin->security_awar()->unmap(); |
---|
35 | admin->remark_awar()->unmap(); |
---|
36 | admin->auto_awar()->unmap(); |
---|
37 | } |
---|
38 | else { |
---|
39 | GBDATA *ali_len = GB_search(ali_cont, "alignment_len", GB_INT); |
---|
40 | GBDATA *ali_aligned = GB_search(ali_cont, "aligned", GB_INT); |
---|
41 | GBDATA *ali_type = GB_search(ali_cont, "alignment_type", GB_STRING); |
---|
42 | GBDATA *ali_security = GB_search(ali_cont, "alignment_write_security", GB_INT); |
---|
43 | GBDATA *ali_rem = GB_search(ali_cont, "alignment_rem", GB_STRING); |
---|
44 | GBDATA *ali_auto_format = GB_search(ali_cont, "auto_format", GB_INT); |
---|
45 | |
---|
46 | admin->type_awar() ->map(ali_type); |
---|
47 | admin->len_awar() ->map(ali_len); |
---|
48 | admin->aligned_awar() ->map(ali_aligned); |
---|
49 | admin->security_awar()->map(ali_security); |
---|
50 | admin->remark_awar() ->map(ali_rem); |
---|
51 | admin->auto_awar() ->map(ali_auto_format); |
---|
52 | } |
---|
53 | |
---|
54 | ali_assert(!GB_have_error()); |
---|
55 | } |
---|
56 | |
---|
57 | static void create_admin_awars(AW_root *aw_root, AW_default aw_def, AliAdmin *admin) { |
---|
58 | aw_root->awar_string(admin->type_name(), "", aw_def); |
---|
59 | aw_root->awar_string(admin->remark_name(), "", aw_def); |
---|
60 | |
---|
61 | aw_root->awar_int(admin->len_name(), 0, aw_def); |
---|
62 | aw_root->awar_int(admin->aligned_name(), 0, aw_def); |
---|
63 | aw_root->awar_int(admin->security_name(), 0, aw_def); |
---|
64 | aw_root->awar_int(admin->auto_name(), 0, aw_def); |
---|
65 | |
---|
66 | RootCallback rcb = makeRootCallback(alignment_vars_callback, admin); |
---|
67 | admin->select_awar()->add_callback(rcb); |
---|
68 | rcb(aw_root); |
---|
69 | } |
---|
70 | |
---|
71 | static void delete_ali_cb(AW_window *, AliAdmin *admin) { |
---|
72 | if (aw_ask_sure("delete_ali_data", "Are you sure to delete all data belonging to this alignment?")) { |
---|
73 | GBDATA *gb_main = admin->get_gb_main(); |
---|
74 | GB_transaction ta(gb_main); |
---|
75 | GB_ERROR error = GBT_rename_alignment(gb_main, admin->get_selected_ali(), NULp, 0, 1); |
---|
76 | |
---|
77 | error = ta.close(error); |
---|
78 | if (error) aw_message(error); |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | static void ali_checklen_cb(AW_window *, AliAdmin *admin) { |
---|
83 | GBDATA *gb_main = admin->get_gb_main(); |
---|
84 | GB_transaction ta(gb_main); |
---|
85 | GB_ERROR error = GBT_check_data(gb_main, admin->get_selected_ali()); |
---|
86 | |
---|
87 | error = ta.close(error); |
---|
88 | aw_message_if(error); |
---|
89 | } |
---|
90 | |
---|
91 | static void never_auto_format_ali_genom_cb(AW_window *, AliAdmin *admin) { |
---|
92 | if (strcmp(admin->get_selected_ali(), "ali_genom") == 0) { |
---|
93 | admin->auto_awar()->write_int(2); // ali_genom is always forced to "skip" |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | static void ali_format_cb(AW_window *aww, AliAdmin *admin) { |
---|
98 | { |
---|
99 | GB_transaction ta(admin->get_gb_main()); |
---|
100 | GB_ERROR error = ARB_format_alignment(admin->get_gb_main(), admin->get_selected_ali()); |
---|
101 | aw_message_if(error); |
---|
102 | } |
---|
103 | ali_checklen_cb(aww, admin); |
---|
104 | } |
---|
105 | |
---|
106 | enum CopyRenameMode { |
---|
107 | CRM_RENAME, |
---|
108 | CRM_COPY, |
---|
109 | }; |
---|
110 | |
---|
111 | static GB_ERROR copy_rename_handler(const char *dest, AliAdmin *admin, CopyRenameMode mode) { |
---|
112 | ali_assert(!GB_have_error()); |
---|
113 | |
---|
114 | GBDATA *gb_main = admin->get_gb_main(); |
---|
115 | const char *source = admin->get_selected_ali(); |
---|
116 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
117 | |
---|
118 | if (!error) error = GBT_rename_alignment(gb_main, source, dest, 1, mode == CRM_RENAME); |
---|
119 | if (!error) { |
---|
120 | char *nfield = GBS_global_string_copy("%s/data", dest); |
---|
121 | error = GBT_add_new_changekey(gb_main, nfield, GB_STRING); |
---|
122 | free(nfield); |
---|
123 | } |
---|
124 | |
---|
125 | error = GB_end_transaction(gb_main, error); |
---|
126 | |
---|
127 | ali_assert(!GB_have_error()); |
---|
128 | return error; |
---|
129 | } |
---|
130 | static void copy_rename_cb(AW_window *, AliAdmin *admin, CopyRenameMode mode) { |
---|
131 | ResultHandler handler = makeResultHandler(copy_rename_handler, admin, mode); |
---|
132 | const char *old_name = admin->get_selected_ali(); |
---|
133 | |
---|
134 | switch (mode) { |
---|
135 | case CRM_RENAME: |
---|
136 | AWT_activate_prompt("Rename alignment", "Enter the new name of the alignment:", old_name, "Rename", handler, NULp, SRT_AUTOCORRECT_ALINAME); |
---|
137 | break; |
---|
138 | case CRM_COPY: |
---|
139 | AWT_activate_prompt("Copy alignment", "Enter the name of the new alignment:", old_name, "Copy", handler, NULp, SRT_AUTOCORRECT_ALINAME); |
---|
140 | break; |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | static GB_ERROR create_ali_handler(const char *name, AliAdmin *admin) { |
---|
145 | GBDATA *gb_main = admin->get_gb_main(); |
---|
146 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
147 | if (!error) { |
---|
148 | GBDATA *gb_ali = GBT_create_alignment(gb_main, name, 0, 0, 0, "dna"); |
---|
149 | |
---|
150 | if (!gb_ali) error = GB_await_error(); |
---|
151 | else { |
---|
152 | char *nfield = GBS_global_string_copy("%s/data", name); |
---|
153 | error = GBT_add_new_changekey(gb_main, nfield, GB_STRING); |
---|
154 | free(nfield); |
---|
155 | } |
---|
156 | } |
---|
157 | error = GB_end_transaction(gb_main, error); |
---|
158 | return error; |
---|
159 | } |
---|
160 | static void create_ali_cb(AW_window *, AliAdmin *admin) { |
---|
161 | AWT_activate_prompt("Create alignment", "Enter the name of the new alignment:", "", "Create", makeResultHandler(create_ali_handler, admin), NULp, SRT_AUTOCORRECT_ALINAME); |
---|
162 | } |
---|
163 | |
---|
164 | AW_window *ALI_create_admin_window(AW_root *root, AliAdmin *admin) { |
---|
165 | if (!admin->get_window()) { |
---|
166 | GBDATA *gb_main = admin->get_gb_main(); |
---|
167 | AW_window_simple *aws = new AW_window_simple; |
---|
168 | |
---|
169 | create_admin_awars(root, AW_ROOT_DEFAULT, admin); |
---|
170 | admin->store_window(aws); |
---|
171 | |
---|
172 | admin->window_init(aws, "INFO_OF_%s", "%s information"); |
---|
173 | aws->load_xfig("ad_align.fig"); |
---|
174 | |
---|
175 | aws->at("close"); |
---|
176 | aws->callback(AW_POPDOWN); |
---|
177 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
178 | |
---|
179 | aws->at("help"); |
---|
180 | aws->callback(makeHelpCallback("ad_align.hlp")); |
---|
181 | aws->create_button("HELP", "HELP", "H"); |
---|
182 | |
---|
183 | // button column |
---|
184 | aws->button_length(13); |
---|
185 | |
---|
186 | aws->at("delete"); |
---|
187 | aws->callback(makeWindowCallback(delete_ali_cb, admin)); |
---|
188 | aws->create_button("DELETE", "DELETE", "D"); |
---|
189 | |
---|
190 | aws->at("rename"); |
---|
191 | aws->callback(makeWindowCallback(copy_rename_cb, admin, CRM_RENAME)); |
---|
192 | aws->create_button("RENAME", "RENAME", "R"); |
---|
193 | |
---|
194 | aws->at("create"); |
---|
195 | aws->callback(makeWindowCallback(create_ali_cb, admin)); |
---|
196 | aws->create_button("CREATE", "CREATE", "N"); |
---|
197 | |
---|
198 | aws->at("copy"); |
---|
199 | aws->callback(makeWindowCallback(copy_rename_cb, admin, CRM_COPY)); |
---|
200 | aws->create_button("COPY", "COPY", "C"); |
---|
201 | |
---|
202 | aws->at("check_len"); |
---|
203 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); |
---|
204 | aws->create_button("CHECK_LEN", "CHECK LEN", "L"); |
---|
205 | |
---|
206 | aws->at("align"); |
---|
207 | aws->callback(makeWindowCallback(ali_format_cb, admin)); |
---|
208 | aws->create_button("FORMAT", "FORMAT", "F"); |
---|
209 | |
---|
210 | // ali selection list |
---|
211 | aws->at("list"); |
---|
212 | awt_create_ALI_selection_list(gb_main, aws, admin->select_name(), "*="); |
---|
213 | |
---|
214 | // alignment settings |
---|
215 | aws->at("aligned"); |
---|
216 | aws->create_option_menu(admin->aligned_name(), true); |
---|
217 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); aws->insert_default_option("not formatted", "n", 0); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
218 | aws->callback(makeWindowCallback(ali_format_cb, admin)); aws->insert_option("formatted", "j", 1); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
219 | aws->update_option_menu(); |
---|
220 | |
---|
221 | aws->at("len"); |
---|
222 | aws->create_input_field(admin->len_name(), 8); |
---|
223 | |
---|
224 | aws->at("type"); |
---|
225 | aws->create_option_menu(admin->type_name(), true); |
---|
226 | aws->insert_option("dna", "d", "dna"); |
---|
227 | aws->insert_option("rna", "r", "rna"); |
---|
228 | aws->insert_option("pro", "p", "ami"); |
---|
229 | aws->insert_default_option("???", "?", "usr"); |
---|
230 | aws->update_option_menu(); |
---|
231 | |
---|
232 | aws->at("security"); |
---|
233 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
234 | aws->create_option_menu(admin->security_name(), true); |
---|
235 | aws->insert_option("0", "0", 0); |
---|
236 | aws->insert_option("1", "1", 1); |
---|
237 | aws->insert_option("2", "2", 2); |
---|
238 | aws->insert_option("3", "3", 3); |
---|
239 | aws->insert_option("4", "4", 4); |
---|
240 | aws->insert_option("5", "5", 5); |
---|
241 | aws->insert_default_option("6", "6", 6); |
---|
242 | aws->update_option_menu(); |
---|
243 | |
---|
244 | aws->at("auto_format"); |
---|
245 | aws->callback(makeWindowCallback(never_auto_format_ali_genom_cb, admin)); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
246 | aws->create_option_menu(admin->auto_name(), true); |
---|
247 | aws->insert_default_option("ask", "a", 0); |
---|
248 | aws->insert_option("always", "", 1); |
---|
249 | aws->insert_option("never", "", 2); |
---|
250 | aws->update_option_menu(); |
---|
251 | |
---|
252 | aws->at("rem"); |
---|
253 | aws->create_text_field(admin->remark_name()); |
---|
254 | } |
---|
255 | |
---|
256 | return admin->get_window(); |
---|
257 | } |
---|
258 | |
---|