ARB
AdminGui.cxx
Go to the documentation of this file.
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) {
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) {
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 
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);
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 
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());
101  aw_message_if(error);
102  }
103  ali_checklen_cb(aww, admin);
104 }
105 
109 };
110 
111 static GB_ERROR copy_rename_handler(const char *dest, AliAdmin *admin, CopyRenameMode mode) {
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
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 
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();
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 
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 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
const char * GB_ERROR
Definition: arb_core.h:25
AW_awar * len_awar() const
Definition: AliAdmin.h:74
const char * type_name() const
Definition: AliAdmin.h:65
AW_window * ALI_create_admin_window(AW_root *root, AliAdmin *admin)
Definition: AdminGui.cxx:162
GB_ERROR GBT_rename_alignment(GBDATA *gbMain, const char *source, const char *dest)
Definition: adali.cxx:587
static void alignment_vars_callback(AW_root *, AliAdmin *admin)
Definition: AdminGui.cxx:22
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:808
static void never_auto_format_ali_genom_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:91
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
AW_awar * select_awar() const
Definition: AliAdmin.h:72
bool GB_have_error()
Definition: arb_msg.cxx:337
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
static void ali_format_cb(AW_window *aww, AliAdmin *admin)
Definition: AdminGui.cxx:97
void store_window(AW_window *aw)
Definition: AliAdmin.h:59
const char * get_selected_ali() const
Definition: AliAdmin.h:80
const char * auto_name() const
Definition: AliAdmin.h:70
GB_ERROR GBT_delete_alignment(GBDATA *gbMain, const char *source)
Definition: adali.cxx:590
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
GB_ERROR GBT_add_alignment_changekeys(GBDATA *gb_main, const char *ali)
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:341
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
GB_ERROR ARB_format_alignment(GBDATA *Main, const char *alignment_name)
Definition: insdel.cxx:1439
const char * remark_name() const
Definition: AliAdmin.h:69
AW_awar * security_awar() const
Definition: AliAdmin.h:76
void GB_clear_error()
Definition: arb_msg.cxx:353
void window_init(class AW_window_simple *aw, const char *id_templ, const char *title_templ) const
Definition: AliAdmin.cxx:24
GB_ERROR GBT_copy_alignment(GBDATA *gbMain, const char *source, const char *dest)
Definition: adali.cxx:584
AW_awar * auto_awar() const
Definition: AliAdmin.h:78
static void error(const char *msg)
Definition: mkptypes.cxx:96
AW_awar * remark_awar() const
Definition: AliAdmin.h:77
GBDATA * get_gb_main() const
Definition: AliAdmin.h:57
static void delete_ali_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:71
#define SRT_AUTOCORRECT_ALINAME
Definition: arbdbt.h:80
AW_window * get_window() const
Definition: AliAdmin.h:60
const char * len_name() const
Definition: AliAdmin.h:66
AW_awar * type_awar() const
Definition: AliAdmin.h:73
const char * aligned_name() const
Definition: AliAdmin.h:67
AW_awar * unmap()
Definition: AW_awar.cxx:596
static void create_ali_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:158
const char * select_name() const
Definition: AliAdmin.h:64
AW_DB_selection * awt_create_ALI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const char *ali_type_match)
bool aw_ask_sure(const char *unique_id, const char *msg)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
GB_ERROR close(GB_ERROR error)
Definition: arbdbpp.cxx:35
#define ali_assert(cond)
Definition: AliAdmin.h:24
static GB_ERROR copy_rename_handler(const char *dest, AliAdmin *admin, CopyRenameMode mode)
Definition: AdminGui.cxx:111
AW_awar * map(const char *awarn)
Definition: AW_awar.cxx:521
static void create_admin_awars(AW_root *aw_root, AW_default aw_def, AliAdmin *admin)
Definition: AdminGui.cxx:57
static GB_ERROR create_ali_handler(const char *name, AliAdmin *admin)
Definition: AdminGui.cxx:146
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
GBDATA * GBT_create_alignment(GBDATA *gb_main, const char *name, long len, long aligned, long security, const char *type, const char *why_created)
Definition: adali.cxx:388
#define NULp
Definition: cxxforward.h:114
const char * security_name() const
Definition: AliAdmin.h:68
AW_awar * aligned_awar() const
Definition: AliAdmin.h:75
static void ali_checklen_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:82
CopyRenameMode
Definition: AdminGui.cxx:106
GB_transaction ta(gb_var)
GBDATA * gb_main
Definition: adname.cxx:33
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GB_ERROR GBT_check_data(GBDATA *Main, const char *alignment_name)
Definition: adali.cxx:218
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
static void copy_rename_cb(AW_window *, AliAdmin *admin, CopyRenameMode mode)
Definition: AdminGui.cxx:132
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
GB_ERROR write_int(long aw_int)
void aw_message_if(GB_ERROR error)
Definition: aw_msg.hxx:21
Definition: arbdb.h:66
void AWT_activate_prompt(const char *title, const char *prompt, const char *defaultResult, const char *button, const ResultHandler &handle_result, const char *helpfile, const char *srt)
Definition: AWT_prompt.cxx:62