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 
115 // -------------------------
116 // MG_SAI_selector
117 
118 static void mg_select_sai1(GBDATA*, AW_root *aw_root, const char *item_name) {
119  aw_root->awar(AWAR_EX_NAME_SRC)->write_string(item_name);
120 }
121 static void mg_select_sai2(GBDATA*, AW_root *aw_root, const char *item_name) {
122  aw_root->awar(AWAR_EX_NAME_DST)->write_string(item_name);
123 }
124 
127 }
130 }
131 
134  const char *sai_name = aw_root->awar(AWAR_EX_NAME_SRC)->read_char_pntr();
135  return sai_name[0] ? GBT_find_SAI(GLOBAL_gb_src, sai_name) : NULp;
136 }
139  const char *sai_name = aw_root->awar(AWAR_EX_NAME_DST)->read_char_pntr();
140  return sai_name[0] ? GBT_find_SAI(GLOBAL_gb_dst, sai_name) : NULp;
141 }
142 
144 
146  static bool initialized = false;
147  if (!initialized) {
148  MG_SAI_selector[0] = MG_SAI_selector[1] = SAI_get_selector();
149 
150  for (int s = 0; s <= 1; ++s) {
151  MutableItemSelector& sel = MG_SAI_selector[s];
152 
156  }
157 
158  initialized = true;
159  }
160 }
161 
162 
164  AW_window_simple *aws = new AW_window_simple;
165 
167 
168  aws->init(awr, "MERGE_SAI", "MERGE SAI");
169  aws->load_xfig("merge/extended.fig");
170 
171  aws->at("close");
172  aws->callback(AW_POPDOWN);
173  aws->create_button("CLOSE", "CLOSE", "C");
174 
175  aws->at("help");
176  aws->callback(makeHelpCallback("mg_extendeds.hlp"));
177  aws->create_button("HELP", "HELP", "H");
178 
179  aws->at("ex1");
181  DbScanner *scanner = DbScanner::create(GLOBAL_gb_src, "merge_sai1", aws, "info1", NULp, NULp, DB_SCANNER, NULp, MG_SAI_selector[0]);
182  aws->get_root()->awar(AWAR_EX_NAME_SRC)->add_callback(makeRootCallback(map_extended, scanner, SRC_DB));
183 
184  aws->at("ex2");
186  scanner = DbScanner::create(GLOBAL_gb_dst, "merge_sai2", aws, "info2", NULp, NULp, DB_SCANNER, NULp, MG_SAI_selector[1]);
187  aws->get_root()->awar(AWAR_EX_NAME_DST)->add_callback(makeRootCallback(map_extended, scanner, DST_DB));
188 
189  aws->button_length(20);
190 
191  aws->at("delete1");
192  aws->callback(makeWindowCallback(MG_extended_delete_cb, SRC_DB));
193  aws->create_button("DELETE_SAI_DB1", "Delete SAI");
194 
195  aws->at("delete2");
196  aws->callback(makeWindowCallback(MG_extended_delete_cb, DST_DB));
197  aws->create_button("DELETE_SAI_DB2", "Delete SAI");
198 
199  aws->at("rename1");
200  aws->callback(makeWindowCallback(extended_rename_cb, SRC_DB));
201  aws->create_button("RENAME_SAI_DB1", "Rename SAI");
202 
203  aws->at("rename2");
204  aws->callback(makeWindowCallback(extended_rename_cb, DST_DB));
205  aws->create_button("RENAME_SAI_DB2", "Rename SAI");
206 
207  aws->at("transfer");
208  aws->callback(MG_transfer_extended);
209  aws->create_button("TRANSFER_SAI", "Transfer SAI");
210 
211  aws->button_length(0);
212  aws->shadow_width(1);
213  aws->at("icon");
214  aws->callback(makeHelpCallback("mg_extendeds.hlp"));
215  aws->create_button("HELP_MERGE", "#merge/icon.xpm");
216 
217  return aws;
218 }
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
GB_ERROR GB_copy_dropProtectMarksAndTempstate(GBDATA *dest, GBDATA *source)
Definition: arbdb.cxx:2152
static GB_ERROR extended_rename_handler(const char *dest, DbSel db)
const char * GB_ERROR
Definition: arb_core.h:25
AW_DB_selection * awt_create_SAI_selection_list(GBDATA *gb_main, AW_window *aws, const char *varname, const SaiSelectionlistFilterCallback &fcb)
static GBDATA * mg_get_first_sai_data1(GBDATA *, AW_root *, QUERY_RANGE)
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
void GB_end_transaction_show_error(GBDATA *gbd, GB_ERROR error, void(*error_handler)(GB_ERROR))
Definition: arbdb.cxx:2584
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
Definition: merge.hxx:35
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
#define AWAR_EX_NAME(db)
static GBDATA * mg_get_selected_sai1(GBDATA *, AW_root *aw_root)
static GBDATA * mg_get_selected_sai2(GBDATA *, AW_root *aw_root)
GBDATA * GLOBAL_gb_dst
Definition: MG_main.cxx:32
#define AWAR_EX_NAME_SRC
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1916
static MutableItemSelector MG_SAI_selector[2]
static bool initialized
Definition: AW_advice.cxx:36
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:177
const char * read_char_pntr() const
Definition: AW_awar.cxx:168
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
static AW_root * SINGLETON
Definition: aw_root.hxx:102
GBDATA * GB_create_container(GBDATA *father, const char *key)
Definition: arbdb.cxx:1829
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
AW_window * MG_create_merge_SAIs_window(AW_root *awr)
GBDATA *(* get_selected_item)(GBDATA *gb_main, AW_root *aw_root)
Definition: items.h:76
GBDATA *(* get_first_item_container)(GBDATA *, AW_root *, QUERY_RANGE)
Definition: items.h:70
static void MG_extended_delete_cb(AW_window *aww, DbSel db)
static void error(const char *msg)
Definition: mkptypes.cxx:96
ItemSelector & SAI_get_selector()
Definition: SAIs.cxx:92
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:198
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GBDATA * GLOBAL_gb_src
Definition: MG_main.cxx:31
QUERY_RANGE
Definition: items.h:41
void(* update_item_awars)(GBDATA *gb_main, AW_root *aw_root, const char *item_name)
Definition: items.h:58
static void mg_select_sai2(GBDATA *, AW_root *aw_root, const char *item_name)
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
static void mg_initialize_SAI_selectors()
static void mg_select_sai1(GBDATA *, AW_root *aw_root, const char *item_name)
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
void MG_create_extendeds_awars(AW_root *aw_root, AW_default aw_def)
AW_root * get_root()
Definition: aw_window.hxx:359
static void MG_transfer_extended(AW_window *aww)
#define NULp
Definition: cxxforward.h:116
GB_ERROR write_string(const char *aw_string)
GBDATA * GBT_find_SAI_rel_SAI_data(GBDATA *gb_sai_data, const char *name)
Definition: aditem.cxx:171
GB_transaction ta(gb_var)
GBDATA * gb_main
Definition: adname.cxx:32
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
static GBDATA * mg_get_first_sai_data2(GBDATA *, AW_root *, QUERY_RANGE)
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_write_int const char s
Definition: AW_awar.cxx:154