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 | |
---|
29 | enum DB_SCANNERMODE { |
---|
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); |
---|
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 remap_item(); |
---|
103 | void editfield_value_changed_cb(); |
---|
104 | void toggle_marked_cb(); |
---|
105 | void remap_edit_box(); |
---|
106 | |
---|
107 | // callback-wrappers (called by DB-callback, RootCallback or WindowCallback): |
---|
108 | static void changed_cb(UNFIXED, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->changed_cb(cbtype); } |
---|
109 | static void field_changed_cb(GBDATA *, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->field_changed_cb(cbtype); } |
---|
110 | static void keydata_modified_cb(GBDATA*, DbScanner *scanner, GB_CB_TYPE cbtype) { scanner->keydata_modified_cb(cbtype); } |
---|
111 | static void remap_item(UNFIXED, DbScanner *scanner) { scanner->remap_item(); } |
---|
112 | static void editfield_value_changed_cb(UNFIXED, DbScanner *scanner) { scanner->editfield_value_changed_cb(); } |
---|
113 | static void toggle_marked_cb(UNFIXED, DbScanner *scanner) { scanner->toggle_marked_cb(); } |
---|
114 | static void remap_edit_box(UNFIXED, DbScanner *scanner) { scanner->remap_edit_box(); } |
---|
115 | |
---|
116 | DbScanner(DB_SCANNERMODE smode, ItemSelector& selector_, AW_window *aws_, GBDATA *gb_main_) : |
---|
117 | selector(selector_), |
---|
118 | aws(aws_), |
---|
119 | gb_main(gb_main_), |
---|
120 | field_sel(NULp), |
---|
121 | gb_item(NULp), |
---|
122 | gb_field(NULp), |
---|
123 | scannermode(smode), |
---|
124 | ignore_editfield_change(false), |
---|
125 | ignore_marktoggle_change(false), |
---|
126 | previous_max_keyname_length(8), |
---|
127 | awar_editfield(NULp), |
---|
128 | awar_edit_enabled(NULp), |
---|
129 | awar_selected_field(NULp), |
---|
130 | awar_mapped_item_ID(NULp), |
---|
131 | awar_mark(NULp) |
---|
132 | { |
---|
133 | arb_assert(&selector); |
---|
134 | } |
---|
135 | |
---|
136 | public: |
---|
137 | // scanner factory: |
---|
138 | static DbScanner *create(GBDATA *gb_main, |
---|
139 | const char *scanner_id, // unique id (will crash if not) |
---|
140 | AW_window *aws, |
---|
141 | const char *box_pos_fig, // xfig-position of field-selection |
---|
142 | const char *edit_pos_fig, // xfig-position of edit-field (or NULp to disable it) |
---|
143 | const char *edit_enable_pos_fig, // xfig-position of edit-toggle (or NULp) |
---|
144 | DB_SCANNERMODE scannermode, |
---|
145 | const char *mark_pos_fig, // xfig-position of mark-toggle (or NULp) |
---|
146 | ItemSelector& selector); |
---|
147 | |
---|
148 | const ItemSelector& get_selector() const { return selector; } |
---|
149 | GBDATA *get_gb_main() const { return gb_main; } |
---|
150 | |
---|
151 | char *get_mapped_item_id() const { |
---|
152 | char *id = NULp; |
---|
153 | if (gb_item) { |
---|
154 | GB_transaction ta(gb_main); |
---|
155 | id = selector.generate_item_id(gb_main, gb_item); |
---|
156 | } |
---|
157 | return id; |
---|
158 | } |
---|
159 | const char *get_mapped_itemID_awarname() const { |
---|
160 | return awar_mapped_item_ID->awar_name; |
---|
161 | } |
---|
162 | void Map(GBDATA *gb_new_item, const char *key_path); |
---|
163 | |
---|
164 | void RemapToDatabase(GBDATA *gb_new_main) { |
---|
165 | gb_main = gb_new_main; |
---|
166 | } |
---|
167 | }; |
---|
168 | |
---|
169 | void collectKeysRegisteredInDatabase(StrArray& fields, GBDATA *gb_main, ItemSelector& sel, bool skipContainers, bool skipHidden); |
---|
170 | |
---|
171 | #else |
---|
172 | #error db_scanner.hxx included twice |
---|
173 | #endif // DB_SCANNER_HXX |
---|
174 | |
---|