ARB
db_scanner.hxx
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : db_scanner.hxx //
4 // Purpose : ARB database scanner //
5 // //
6 // //
7 // Coded by Ralf Westram (coder@reallysoft.de) in May 2005 //
8 // Copyright Department of Microbiology (Technical University Munich) //
9 // //
10 // Visit our web site at: http://www.arb-home.de/ //
11 // //
12 // ==================================================================== //
13 #ifndef DB_SCANNER_HXX
14 #define DB_SCANNER_HXX
15 
16 #ifndef ARBDB_H
17 #include <arbdb.h>
18 #endif
19 #ifndef AW_WINDOW_HXX
20 #include <aw_window.hxx>
21 #endif
22 #ifndef AW_AWAR_HXX
23 #include <aw_awar.hxx>
24 #endif
25 #ifndef ITEMS_H
26 #include <items.h>
27 #endif
28 
30  // -------------- used for | properties:
31  DB_SCANNER, // SAI-info, | * recursively show all existing subentries of a container
32  // SAI/species in merge-tool, | * order as occurring in DB
33  // species in import-tester
34  //
35  DB_KEYVIEWER // item-info (species, gene, experiment) | * show all fields (defined as key data)
36  // | -> allows to hide fields
37  // | -> user-defined order
38  // | * used fields at top + unused fields at bottom
39 };
40 
41 class DbScanner { // @@@ derive from AW_DB_selection?
42  // Basically displays DB-fields of a selected item
43  // (e.g. a species or an SAI) in a field-selection list.
44  //
45  // - optionally provides an edit-box (allowing to edit the selected field)
46  // - optionally provides a mark-toggle (show/edit mark-flag of item)
47 
48  ItemSelector& selector;
49  AW_window *aws;
50 
51  GBDATA *gb_main;
52 
53  AW_selection_list *field_sel;
54 
55  GBDATA *gb_item; // currently mapped item (e.g. species)
56  GBDATA *gb_field; // currently selected field
57 
58  DB_SCANNERMODE scannermode;
59 
60  bool ignore_editfield_change;
61  bool ignore_marktoggle_change;
62 
63  int previous_max_keyname_length; // length of longest keyname (during previous "fill")
64 
65  AW_awar *awar_editfield; // only exists for scanners providing an edit-field. contains content of selected field.
66  AW_awar *awar_edit_enabled; // only (may) exist if awar_editfield exists and scanner provides an enable-edit-toggle. contains value of toggle.
67  AW_awar *awar_selected_field; // contains key of selected field (hkey is allowed!)
68  AW_awar *awar_mapped_item_ID; // contains id (e.g. name) of currently mapped item (or '<none selected>')
69  AW_awar *awar_mark; // only exists for scanners providing a marked-toggle. contains current status of mark-flag of the currently mapped item.
70 
71  AW_root *get_root() const { return aws->get_root(); }
72 
73  GBDATA *search_selected_field() const {
74  if (gb_item) {
75  const char *field_name = awar_selected_field->read_char_pntr();
76  if (field_name[0]) {
77  return GB_search(gb_item, field_name, GB_FIND);
78  }
79  }
80  return NULp;
81  }
82 
83  void append_field_data(GBS_strstruct& buf, GB_TYPES type, GBDATA *gbd);
84  int fill_fields_recursive(GBDATA *gbd, const int depth, GBS_strstruct& buf);
85  int fill_fields_by_keydata(GBS_strstruct& buf);
86 
87  // GUI methods:
88  void create_awars(const char *scanner_id, bool have_edit_field, bool have_edit_toggle, bool have_mark_toggle);
89  void create_field_selection_list() {
90  field_sel = aws->create_selection_list(awar_selected_field->awar_name, 20, 10, true);
91  }
92  void create_mark_toggle() {
93  aws->create_toggle(awar_mark->awar_name);
94  awar_mark->add_callback(makeRootCallback(DbScanner::toggle_marked_cb, this));
95  }
96  void create_field_edit_widgets(const char *edit_pos_fig, const char *edit_enable_pos_fig);
97 
98  // callback-handlers:
99  void changed_cb(GB_CB_TYPE cbtype);
100  void field_changed_cb(GB_CB_TYPE cbtype);
101  void keydata_modified_cb(GB_CB_TYPE cbtype);
102  void editfield_value_changed_cb();
103  void toggle_marked_cb();
104  void remap_edit_box();
105 
106  // callback-wrappers (called by DB-callback, RootCallback or WindowCallback):
107  static void changed_cb(UNFIXED, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->changed_cb(cbtype); }
108  static void field_changed_cb(GBDATA *, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->field_changed_cb(cbtype); }
109  static void keydata_modified_cb(GBDATA*, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->keydata_modified_cb(cbtype); }
110  static void editfield_value_changed_cb(UNFIXED, DbScanner *scanner) { scanner->editfield_value_changed_cb(); }
111  static void toggle_marked_cb(UNFIXED, DbScanner *scanner) { scanner->toggle_marked_cb(); }
112  static void remap_edit_box(UNFIXED, DbScanner *scanner) { scanner->remap_edit_box(); }
113 
114  DbScanner(DB_SCANNERMODE smode, ItemSelector& selector_, AW_window *aws_, GBDATA *gb_main_) :
115  selector(selector_),
116  aws(aws_),
117  gb_main(gb_main_),
118  field_sel(NULp),
119  gb_item(NULp),
120  gb_field(NULp),
121  scannermode(smode),
122  ignore_editfield_change(false),
123  ignore_marktoggle_change(false),
124  previous_max_keyname_length(8),
125  awar_editfield(NULp),
126  awar_edit_enabled(NULp),
127  awar_selected_field(NULp),
128  awar_mapped_item_ID(NULp),
129  awar_mark(NULp)
130  {
131  arb_assert(&selector);
132  }
133 
134 public:
135  // scanner factory:
136  static DbScanner *create(GBDATA *gb_main,
137  const char *scanner_id, // unique id (will crash if not)
138  AW_window *aws,
139  const char *box_pos_fig, // xfig-position of field-selection
140  const char *edit_pos_fig, // xfig-position of edit-field (or NULp to disable it)
141  const char *edit_enable_pos_fig, // xfig-position of edit-toggle (or NULp)
142  DB_SCANNERMODE scannermode,
143  const char *mark_pos_fig, // xfig-position of mark-toggle (or NULp)
144  ItemSelector& selector);
145 
146  const ItemSelector& get_selector() const { return selector; }
147  GBDATA *get_gb_main() const { return gb_main; }
148 
149  char *get_mapped_item_id() const {
150  char *id = NULp;
151  if (gb_item) {
152  GB_transaction ta(gb_main);
153  id = selector.generate_item_id(gb_main, gb_item);
154  }
155  return id;
156  }
157  const char *get_mapped_itemID_awarname() const {
158  return awar_mapped_item_ID->awar_name;
159  }
160  void Map(GBDATA *gb_new_item, const char *key_path);
161 
162  void RemapToDatabase(GBDATA *gb_new_main) {
163  gb_main = gb_new_main;
164  }
165 };
166 
167 void collectKeysRegisteredInDatabase(StrArray& fields, GBDATA *gb_main, ItemSelector& sel, bool skipContainers, bool skipHidden);
168 
169 #else
170 #error db_scanner.hxx included twice
171 #endif // DB_SCANNER_HXX
172 
#define arb_assert(cond)
Definition: arb_assert.h:245
GB_TYPES type
const char * id
Definition: AliAdmin.cxx:17
const char * get_mapped_itemID_awarname() const
Definition: db_scanner.hxx:157
GBDATA * get_gb_main() const
Definition: db_scanner.hxx:147
char * get_mapped_item_id() const
Definition: db_scanner.hxx:149
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
struct Unfixed_cb_parameter * UNFIXED
Definition: cb_base.h:15
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
DB_SCANNERMODE
Definition: db_scanner.hxx:29
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows, bool fallback2default)
Definition: AW_button.cxx:1212
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 *(* generate_item_id)(GBDATA *gb_main, GBDATA *gb_item)
Definition: items.h:58
void RemapToDatabase(GBDATA *gb_new_main)
Definition: db_scanner.hxx:162
Definition: arbdb.h:86
char * awar_name
Definition: aw_awar.hxx:103
const ItemSelector & get_selector() const
Definition: db_scanner.hxx:146
void Map(GBDATA *gb_new_item, const char *key_path)
Definition: db_scanner.cxx:489
AW_root * get_root()
Definition: aw_window.hxx:348
#define NULp
Definition: cxxforward.h:97
GB_TYPES
Definition: arbdb.h:62
void collectKeysRegisteredInDatabase(StrArray &fields, GBDATA *gb_main, ItemSelector &sel, bool skipContainers, bool skipHidden)
Definition: db_scanner.cxx:513
GB_transaction ta(gb_var)
GBDATA * gb_main
Definition: adname.cxx:33
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GB_CB_TYPE
Definition: arbdb_base.h:46