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);
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 
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  const char *source = admin->get_selected_ali();
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 
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();
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 
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 
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2492
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:164
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:2525
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:684
static void never_auto_format_ali_genom_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:91
AW_awar * select_awar() const
Definition: AliAdmin.h:72
bool GB_have_error()
Definition: arb_msg.cxx:349
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_add_new_changekey(GBDATA *gb_main, const char *name, int type)
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
GBDATA * GBT_create_alignment(GBDATA *gbd, const char *name, long len, long aligned, long security, const char *type)
Definition: adali.cxx:387
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:365
void window_init(class AW_window_simple *aw, const char *id_templ, const char *title_templ) const
Definition: AliAdmin.cxx:24
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:598
static void create_ali_cb(AW_window *, AliAdmin *admin)
Definition: AdminGui.cxx:160
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:32
#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:523
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:144
void aw_message(const char *msg)
Definition: AW_status.cxx:932
#define NULp
Definition: cxxforward.h:97
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:217
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:130
#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
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:195
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
GB_ERROR GBT_rename_alignment(GBDATA *gbMain, const char *source, const char *dest, int copy, int dele)
Definition: adali.cxx:481