1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : MG_extendeds.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 | |
---|
13 | #include <db_scanner.hxx> |
---|
14 | #include <awt_sel_boxes.hxx> |
---|
15 | #include <awt_prompt.hxx> |
---|
16 | #include <aw_msg.hxx> |
---|
17 | #include <aw_root.hxx> |
---|
18 | #include <arbdbt.h> |
---|
19 | |
---|
20 | #define AWAR_EX_NAME_SRC AWAR_MERGE_TMP_SRC "extended_name" |
---|
21 | #define AWAR_EX_NAME_DST AWAR_MERGE_TMP_DST "extended_name" |
---|
22 | #define AWAR_EX_NAME(db) awar_name_tmp(db, "extended_name") |
---|
23 | |
---|
24 | void MG_create_extendeds_awars(AW_root *aw_root, AW_default aw_def) { |
---|
25 | aw_root->awar_string(AWAR_EX_NAME_SRC, "", aw_def); |
---|
26 | aw_root->awar_string(AWAR_EX_NAME_DST, "", aw_def); |
---|
27 | } |
---|
28 | |
---|
29 | static GB_ERROR extended_rename_handler(const char *dest, DbSel db) { |
---|
30 | GBDATA *gbmain = get_gb_main(db); |
---|
31 | AW_root *awr = AW_root::SINGLETON; |
---|
32 | const char *source = awr->awar(AWAR_EX_NAME(db))->read_char_pntr(); |
---|
33 | |
---|
34 | GB_ERROR error = GB_begin_transaction(gbmain); |
---|
35 | if (!error) { |
---|
36 | GBDATA *gb_sai_data = GBT_get_SAI_data(gbmain); |
---|
37 | if (!gb_sai_data) error = GB_await_error(); |
---|
38 | else { |
---|
39 | GBDATA *gb_sai = GBT_find_SAI_rel_SAI_data(gb_sai_data, source); |
---|
40 | GBDATA *gb_dest_sai = GBT_find_SAI_rel_SAI_data(gb_sai_data, dest); |
---|
41 | |
---|
42 | if (gb_dest_sai) error = GBS_global_string("SAI '%s' already exists", dest); |
---|
43 | else if (!gb_sai) error = "Please select a SAI"; |
---|
44 | else error = GBT_write_string(gb_sai, "name", dest); |
---|
45 | } |
---|
46 | } |
---|
47 | error = GB_end_transaction(gbmain, error); |
---|
48 | |
---|
49 | return error; |
---|
50 | } |
---|
51 | |
---|
52 | static void extended_rename_cb(AW_window *aww, DbSel db) { |
---|
53 | ResultHandler handler = makeResultHandler(extended_rename_handler, db); |
---|
54 | const char *source = aww->get_root()->awar(AWAR_EX_NAME(db))->read_char_pntr(); |
---|
55 | AWT_activate_prompt("Rename SAI", "Enter the new name of the SAI:", source, "Rename", handler); |
---|
56 | } |
---|
57 | |
---|
58 | static void MG_extended_delete_cb(AW_window *aww, DbSel db) { |
---|
59 | GBDATA *gbmain = get_gb_main(db); |
---|
60 | GB_ERROR error = GB_begin_transaction(gbmain); |
---|
61 | |
---|
62 | if (!error) { |
---|
63 | char *source = aww->get_root()->awar(AWAR_EX_NAME(db))->read_string(); |
---|
64 | GBDATA *gb_sai = GBT_find_SAI(gbmain, source); |
---|
65 | if (gb_sai) error = GB_delete(gb_sai); |
---|
66 | else error = "Please select a SAI first"; |
---|
67 | |
---|
68 | free(source); |
---|
69 | } |
---|
70 | GB_end_transaction_show_error(gbmain, error, aw_message); |
---|
71 | } |
---|
72 | |
---|
73 | static void MG_transfer_extended(AW_window *aww) { |
---|
74 | AW_root *awr = aww->get_root(); |
---|
75 | char *sainame = awr->awar(AWAR_EX_NAME_SRC)->read_string(); |
---|
76 | |
---|
77 | GB_ERROR error = GB_begin_transaction(GLOBAL_gb_dst); |
---|
78 | if (!error) error = GB_begin_transaction(GLOBAL_gb_src); |
---|
79 | |
---|
80 | if (!error) { |
---|
81 | GBDATA *gb_src = GBT_find_SAI(GLOBAL_gb_src, sainame); |
---|
82 | |
---|
83 | if (!gb_src) error = "Please select the SAI you want to transfer"; |
---|
84 | else { |
---|
85 | GBDATA *gb_dst_sai_data = GBT_get_SAI_data(GLOBAL_gb_dst); |
---|
86 | if (!gb_dst_sai_data) error = GB_await_error(); |
---|
87 | else { |
---|
88 | GBDATA *gb_dest_sai = GBT_find_SAI_rel_SAI_data(gb_dst_sai_data, sainame); |
---|
89 | if (gb_dest_sai) { |
---|
90 | error = GBS_global_string("SAI '%s' exists, delete it first", sainame); |
---|
91 | } |
---|
92 | if (!error) { |
---|
93 | gb_dest_sai = GB_create_container(gb_dst_sai_data, "extended"); |
---|
94 | if (!gb_dest_sai) error = GB_await_error(); |
---|
95 | else error = GB_copy_dropProtectMarksAndTempstate(gb_dest_sai, gb_src); |
---|
96 | } |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|
101 | error = GB_end_transaction(GLOBAL_gb_dst, error); |
---|
102 | error = GB_end_transaction(GLOBAL_gb_src, error); |
---|
103 | if (error) aw_message(error); |
---|
104 | |
---|
105 | free(sainame); |
---|
106 | } |
---|
107 | |
---|
108 | static void map_extended(AW_root *aw_root, DbScanner *scanner, DbSel db) { |
---|
109 | GBDATA *gb_main = get_gb_main(db); |
---|
110 | GB_transaction ta(gb_main); |
---|
111 | GBDATA *gb_sai = GBT_find_SAI(gb_main, aw_root->awar(AWAR_EX_NAME(db))->read_char_pntr()); |
---|
112 | scanner->Map(gb_sai, CHANGE_KEY_PATH); |
---|
113 | } |
---|
114 | |
---|
115 | AW_window *MG_create_merge_SAIs_window(AW_root *awr) { |
---|
116 | AW_window_simple *aws = new AW_window_simple; |
---|
117 | |
---|
118 | aws->init(awr, "MERGE_SAI", "MERGE SAI"); |
---|
119 | aws->load_xfig("merge/extended.fig"); |
---|
120 | |
---|
121 | aws->at("close"); |
---|
122 | aws->callback(AW_POPDOWN); |
---|
123 | aws->create_button("CLOSE", "CLOSE", "C"); |
---|
124 | |
---|
125 | aws->at("help"); |
---|
126 | aws->callback(makeHelpCallback("mg_extendeds.hlp")); |
---|
127 | aws->create_button("HELP", "HELP", "H"); |
---|
128 | |
---|
129 | aws->at("ex1"); |
---|
130 | awt_create_SAI_selection_list(GLOBAL_gb_src, aws, AWAR_EX_NAME_SRC, true); |
---|
131 | DbScanner *scanner = DbScanner::create(GLOBAL_gb_src, "merge_sai1", aws, "info1", NULp, NULp, DB_SCANNER, NULp, SPECIES_get_selector()); // @@@ use SAI_get_selector |
---|
132 | aws->get_root()->awar(AWAR_EX_NAME_SRC)->add_callback(makeRootCallback(map_extended, scanner, SRC_DB)); |
---|
133 | |
---|
134 | aws->at("ex2"); |
---|
135 | awt_create_SAI_selection_list(GLOBAL_gb_dst, aws, AWAR_EX_NAME_DST, true); |
---|
136 | scanner = DbScanner::create(GLOBAL_gb_dst, "merge_sai2", aws, "info2", NULp, NULp, DB_SCANNER, NULp, SPECIES_get_selector()); // @@@ use SAI_get_selector |
---|
137 | aws->get_root()->awar(AWAR_EX_NAME_DST)->add_callback(makeRootCallback(map_extended, scanner, DST_DB)); |
---|
138 | |
---|
139 | aws->button_length(20); |
---|
140 | |
---|
141 | aws->at("delete1"); |
---|
142 | aws->callback(makeWindowCallback(MG_extended_delete_cb, SRC_DB)); |
---|
143 | aws->create_button("DELETE_SAI_DB1", "Delete SAI"); |
---|
144 | |
---|
145 | aws->at("delete2"); |
---|
146 | aws->callback(makeWindowCallback(MG_extended_delete_cb, DST_DB)); |
---|
147 | aws->create_button("DELETE_SAI_DB2", "Delete SAI"); |
---|
148 | |
---|
149 | aws->at("rename1"); |
---|
150 | aws->callback(makeWindowCallback(extended_rename_cb, SRC_DB)); |
---|
151 | aws->create_button("RENAME_SAI_DB1", "Rename SAI"); |
---|
152 | |
---|
153 | aws->at("rename2"); |
---|
154 | aws->callback(makeWindowCallback(extended_rename_cb, DST_DB)); |
---|
155 | aws->create_button("RENAME_SAI_DB2", "Rename SAI"); |
---|
156 | |
---|
157 | aws->at("transfer"); |
---|
158 | aws->callback(MG_transfer_extended); |
---|
159 | aws->create_button("TRANSFER_SAI", "Transfer SAI"); |
---|
160 | |
---|
161 | aws->button_length(0); |
---|
162 | aws->shadow_width(1); |
---|
163 | aws->at("icon"); |
---|
164 | aws->callback(makeHelpCallback("mg_extendeds.hlp")); |
---|
165 | aws->create_button("HELP_MERGE", "#merge/icon.xpm"); |
---|
166 | |
---|
167 | return aws; |
---|
168 | } |
---|