ARB
MG_extendeds.cxx
Go to the documentation of this file.
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 
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);
32  const char *source = awr->awar(AWAR_EX_NAME(db))->read_char_pntr();
33 
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);
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  }
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 
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 
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");
131  DbScanner *scanner = DbScanner::create(GLOBAL_gb_src, "merge_sai1", aws, "info1", NULp, NULp, DB_SCANNER, NULp, SPECIES_get_selector());
132  aws->get_root()->awar(AWAR_EX_NAME_SRC)->add_callback(makeRootCallback(map_extended, scanner, SRC_DB));
133 
134  aws->at("ex2");
136  scanner = DbScanner::create(GLOBAL_gb_dst, "merge_sai2", aws, "info2", NULp, NULp, DB_SCANNER, NULp, SPECIES_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 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2516
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2144
static GB_ERROR extended_rename_handler(const char *dest, DbSel db)
const char * GB_ERROR
Definition: arb_core.h:25
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2549
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2572
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
Definition: merge.hxx:35
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
#define AWAR_EX_NAME(db)
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:32
#define AWAR_EX_NAME_SRC
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1904
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:177
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:353
static AW_root * SINGLETON
Definition: aw_root.hxx:102
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1827
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
AW_window * MG_create_merge_SAIs_window(AW_root *awr)
static void MG_extended_delete_cb(AW_window *aww, DbSel db)
static void error(const char *msg)
Definition: mkptypes.cxx:96
DbSel
Definition: merge.hxx:35
static void map_extended(AW_root *aw_root, DbScanner *scanner, DbSel db)
static DbScanner * create(GBDATA *gb_main, const char *scanner_id, AW_window *aws, const char *box_pos_fig, const char *edit_pos_fig, const char *edit_enable_pos_fig, DB_SCANNERMODE scannermode, const char *mark_pos_fig, ItemSelector &selector)
Definition: db_scanner.cxx:227
char * read_string() const
Definition: AW_awar.cxx:201
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GBDATA * GLOBAL_gb_src
Definition: MG_main.cxx:31
Definition: merge.hxx:35
#define AWAR_EX_NAME_DST
GB_ERROR GBT_write_string(GBDATA *gb_container, const char *fieldpath, const char *content)
Definition: adtools.cxx:451
#define CHANGE_KEY_PATH
Definition: arbdbt.h:86
void Map(GBDATA *gb_new_item, const char *key_path)
Definition: db_scanner.cxx:489
ItemSelector & SPECIES_get_selector()
Definition: species.cxx:139
void aw_message(const char *msg)
Definition: AW_status.cxx:932
void MG_create_extendeds_awars(AW_root *aw_root, AW_default aw_def)
AW_root * get_root()
Definition: aw_window.hxx:348
static void MG_transfer_extended(AW_window *aww)
#define NULp
Definition: cxxforward.h:97
GBDATA * GBT_find_SAI_rel_SAI_data(GBDATA *gb_sai_data, const char *name)
Definition: aditem.cxx:171
AW_DB_selection * awt_create_SAI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, bool fallback2default, const SaiSelectionlistFilterCallback &fcb)
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
GBDATA * GBT_get_SAI_data(GBDATA *gb_main)
Definition: aditem.cxx:154
static void extended_rename_cb(AW_window *aww, DbSel db)
GBDATA * get_gb_main(DbSel db)
Definition: merge.hxx:88
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