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_delete_alignment(gb_main, admin->get_selected_ali()); |
---|
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 | char *source = ARB_strdup(admin->get_selected_ali()); // selected ali may change by calling GBT_rename_alignment |
---|
116 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
117 | |
---|
118 | if (!error) { |
---|
119 | switch (mode) { |
---|
120 | case CRM_RENAME: error = GBT_rename_alignment(gb_main, source, dest); break; |
---|
121 | case CRM_COPY: error = GBT_copy_alignment (gb_main, source, dest); break; |
---|
122 | } |
---|
123 | } |
---|
124 | if (!error) error = GBT_add_alignment_changekeys(gb_main, dest); |
---|
125 | |
---|
126 | error = GB_end_transaction(gb_main, error); |
---|
127 | |
---|
128 | ali_assert(!GB_have_error()); |
---|
129 | free(source); |
---|
130 | return error; |
---|
131 | } |
---|
132 | static void copy_rename_cb(AW_window *, AliAdmin *admin, CopyRenameMode mode) { |
---|
133 | ResultHandler handler = makeResultHandler(copy_rename_handler, admin, mode); |
---|
134 | const char *old_name = admin->get_selected_ali(); |
---|
135 | |
---|
136 | switch (mode) { |
---|
137 | case CRM_RENAME: |
---|
138 | AWT_activate_prompt("Rename alignment", "Enter the new name of the alignment:", old_name, "Rename", handler, NULp, SRT_AUTOCORRECT_ALINAME); |
---|
139 | break; |
---|
140 | case CRM_COPY: |
---|
141 | AWT_activate_prompt("Copy alignment", "Enter the name of the new alignment:", old_name, "Copy", handler, NULp, SRT_AUTOCORRECT_ALINAME); |
---|
142 | break; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | static GB_ERROR create_ali_handler(const char *name, AliAdmin *admin) { |
---|
147 | GBDATA *gb_main = admin->get_gb_main(); |
---|
148 | GB_ERROR error = GB_begin_transaction(gb_main); |
---|
149 | if (!error) { |
---|
150 | GBDATA *gb_ali = GBT_create_alignment(gb_main, name, 0, 0, 0, "dna", "manually by user."); |
---|
151 | |
---|
152 | if (!gb_ali) error = GB_await_error(); |
---|
153 | else error = GBT_add_alignment_changekeys(gb_main, name); |
---|
154 | } |
---|
155 | error = GB_end_transaction(gb_main, error); |
---|
156 | return error; |
---|
157 | } |
---|
158 | static void create_ali_cb(AW_window *, AliAdmin *admin) { |
---|
159 | AWT_activate_prompt("Create alignment", "Enter the name of the new alignment:", "", "Create", makeResultHandler(create_ali_handler, admin), NULp, SRT_AUTOCORRECT_ALINAME); |
---|
160 | } |
---|
161 | |
---|
162 | AW_window *ALI_create_admin_window(AW_root *root, AliAdmin *admin) { |
---|
163 | if (!admin->get_window()) { |
---|
164 | GBDATA *gb_main = admin->get_gb_main(); |
---|
165 | AW_window_simple *aws = new AW_window_simple; |
---|
166 | |
---|
167 | create_admin_awars(root, AW_ROOT_DEFAULT, admin); |
---|
168 | admin->store_window(aws); |
---|
169 | |
---|
170 | admin->window_init(aws, "INFO_OF_%s", "%s information"); |
---|
171 | aws->load_xfig("ad_align.fig"); |
---|
172 | |
---|
173 | aws->at("close"); |
---|
174 | aws->callback(AW_POPDOWN); |
---|
175 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
176 | |
---|
177 | aws->at("help"); |
---|
178 | aws->callback(makeHelpCallback("ad_align.hlp")); |
---|
179 | aws->create_button("HELP", "HELP", "H"); |
---|
180 | |
---|
181 | // button column |
---|
182 | aws->button_length(13); |
---|
183 | |
---|
184 | aws->at("delete"); |
---|
185 | aws->callback(makeWindowCallback(delete_ali_cb, admin)); |
---|
186 | aws->create_button("DELETE", "DELETE", "D"); |
---|
187 | |
---|
188 | aws->at("rename"); |
---|
189 | aws->callback(makeWindowCallback(copy_rename_cb, admin, CRM_RENAME)); |
---|
190 | aws->create_button("RENAME", "RENAME", "R"); |
---|
191 | |
---|
192 | aws->at("create"); |
---|
193 | aws->callback(makeWindowCallback(create_ali_cb, admin)); |
---|
194 | aws->create_button("CREATE", "CREATE", "N"); |
---|
195 | |
---|
196 | aws->at("copy"); |
---|
197 | aws->callback(makeWindowCallback(copy_rename_cb, admin, CRM_COPY)); |
---|
198 | aws->create_button("COPY", "COPY", "C"); |
---|
199 | |
---|
200 | aws->at("check_len"); |
---|
201 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); |
---|
202 | aws->create_button("CHECK_LEN", "CHECK LEN", "L"); |
---|
203 | |
---|
204 | aws->at("align"); |
---|
205 | aws->callback(makeWindowCallback(ali_format_cb, admin)); |
---|
206 | aws->create_button("FORMAT", "FORMAT", "F"); |
---|
207 | |
---|
208 | // ali selection list |
---|
209 | aws->at("list"); |
---|
210 | awt_create_ALI_selection_list(gb_main, aws, admin->select_name(), "*="); |
---|
211 | |
---|
212 | // alignment settings |
---|
213 | aws->at("aligned"); |
---|
214 | aws->create_option_menu(admin->aligned_name()); |
---|
215 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); aws->insert_default_option("not formatted", "n", 0); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
216 | aws->callback(makeWindowCallback(ali_format_cb, admin)); aws->insert_option("formatted", "j", 1); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
217 | aws->update_option_menu(); |
---|
218 | |
---|
219 | aws->at("len"); |
---|
220 | aws->create_input_field(admin->len_name(), 8); |
---|
221 | |
---|
222 | aws->at("type"); |
---|
223 | aws->create_option_menu(admin->type_name()); |
---|
224 | aws->insert_option("dna", "d", "dna"); |
---|
225 | aws->insert_option("rna", "r", "rna"); |
---|
226 | aws->insert_option("pro", "p", "ami"); |
---|
227 | aws->insert_default_option("???", "?", "usr"); |
---|
228 | aws->update_option_menu(); |
---|
229 | |
---|
230 | aws->at("security"); |
---|
231 | aws->callback(makeWindowCallback(ali_checklen_cb, admin)); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
232 | aws->create_option_menu(admin->security_name()); |
---|
233 | aws->insert_option("0", "0", 0); |
---|
234 | aws->insert_option("1", "1", 1); |
---|
235 | aws->insert_option("2", "2", 2); |
---|
236 | aws->insert_option("3", "3", 3); |
---|
237 | aws->insert_option("4", "4", 4); |
---|
238 | aws->insert_option("5", "5", 5); |
---|
239 | aws->insert_default_option("6", "6", 6); |
---|
240 | aws->update_option_menu(); |
---|
241 | |
---|
242 | aws->at("auto_format"); |
---|
243 | aws->callback(makeWindowCallback(never_auto_format_ali_genom_cb, admin)); // @@@ used as OPTIONMENU_SELECT_CB (see #559) |
---|
244 | aws->create_option_menu(admin->auto_name()); |
---|
245 | aws->insert_default_option("ask", "a", 0); |
---|
246 | aws->insert_option("always", "", 1); |
---|
247 | aws->insert_option("never", "", 2); |
---|
248 | aws->update_option_menu(); |
---|
249 | |
---|
250 | aws->at("rem"); |
---|
251 | aws->create_text_field(admin->remark_name()); |
---|
252 | } |
---|
253 | |
---|
254 | return admin->get_window(); |
---|
255 | } |
---|
256 | |
---|