1 | // ==================================================================== // |
---|
2 | // // |
---|
3 | // File : item_sel_list.h // |
---|
4 | // Purpose : selection lists for items (ItemSelector) // |
---|
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 | |
---|
14 | #ifndef ITEM_SEL_LIST_H |
---|
15 | #define ITEM_SEL_LIST_H |
---|
16 | |
---|
17 | #ifndef AW_SELECT_HXX |
---|
18 | #include <aw_select.hxx> |
---|
19 | #endif |
---|
20 | #ifndef ITEMS_H |
---|
21 | #include "items.h" |
---|
22 | #endif |
---|
23 | #ifndef _GLIBCXX_STRING |
---|
24 | #include <string> |
---|
25 | #endif |
---|
26 | |
---|
27 | #define PSEUDO_FIELD_ANY_FIELD "[any field]" |
---|
28 | #define PSEUDO_FIELD_ALL_FIELDS "[all fields]" |
---|
29 | #define PSEUDO_FIELD_ANY_FIELD_REC "[any recursive]" |
---|
30 | #define PSEUDO_FIELD_ALL_FIELDS_REC "[all recursive]" |
---|
31 | |
---|
32 | enum SelectableFields { |
---|
33 | SF_STANDARD = 0, // normal fields |
---|
34 | SF_PSEUDO = 1, // pseudo-fields (see defines above) |
---|
35 | SF_HIDDEN = 2, // fields hidden by user |
---|
36 | SF_ALLOW_NEW = 4, // allow on-the-fly creation of new fields |
---|
37 | SF_SHOW_TYPE = 8, // show fieldtype prefix |
---|
38 | }; |
---|
39 | |
---|
40 | |
---|
41 | CONSTEXPR long FIELD_FILTER_STRING = (1<<GB_STRING); |
---|
42 | CONSTEXPR long FIELD_FILTER_STRING_WRITEABLE = (1<<GB_STRING); |
---|
43 | CONSTEXPR long FIELD_FILTER_INT_WRITEABLE = (1<<GB_STRING) | (1<<GB_INT); |
---|
44 | CONSTEXPR long FIELD_FILTER_BYTE_WRITEABLE = (1<<GB_STRING) | (1<<GB_INT) | (1<<GB_BYTE) | (1<<GB_FLOAT); |
---|
45 | CONSTEXPR long FIELD_FILTER_FLOAT_WRITEABLE = (1<<GB_STRING) | (1<<GB_FLOAT); |
---|
46 | |
---|
47 | CONSTEXPR long FIELD_FILTER_STRING_READABLE = (1<<GB_BYTE)|(1<<GB_INT)|(1<<GB_FLOAT)|(1<<GB_STRING)|(1<<GB_BITS); // as supported by GB_read_as_string() |
---|
48 | |
---|
49 | CONSTEXPR long FIELD_UNFILTERED = -1L; // any field or container |
---|
50 | CONSTEXPR long FIELD_FILTER_ANY_FIELD = (FIELD_UNFILTERED ^ (1<<GB_DB)); // no containers |
---|
51 | |
---|
52 | CONSTEXPR long FIELD_FILTER_NDS = FIELD_FILTER_STRING_READABLE; |
---|
53 | |
---|
54 | |
---|
55 | class Itemfield_Selection : public AW_DB_selection { // derived from a Noncopyable |
---|
56 | long type_filter; |
---|
57 | SelectableFields field_filter; |
---|
58 | ItemSelector& selector; |
---|
59 | |
---|
60 | bool shall_display_type(GB_TYPES key_type) const { return type_filter & (1 << key_type); } |
---|
61 | |
---|
62 | public: |
---|
63 | Itemfield_Selection(AW_selection_list *sellist_, |
---|
64 | GBDATA *gb_key_data, |
---|
65 | long type_filter_, |
---|
66 | SelectableFields field_filter_, |
---|
67 | ItemSelector& selector_); |
---|
68 | |
---|
69 | void fill() OVERRIDE; |
---|
70 | |
---|
71 | ItemSelector& get_selector() const { return selector; } |
---|
72 | long get_type_filter() const { return type_filter; } |
---|
73 | }; |
---|
74 | |
---|
75 | class FieldSelDef { |
---|
76 | std::string awar_name; |
---|
77 | std::string purpose; |
---|
78 | RefPtr<GBDATA> gb_main; |
---|
79 | RefPtr<ItemSelector> selector; // @@@ gb_main + selector = BoundItemSel (replace?) |
---|
80 | long type_filter; |
---|
81 | SelectableFields field_filter; |
---|
82 | |
---|
83 | public: |
---|
84 | FieldSelDef(const char *awar_name_, GBDATA *gb_main_, ItemSelector& selector_, long type_filter_, const char *purpose_ = "field", SelectableFields field_filter_ = SF_STANDARD) |
---|
85 | /*! parameter collection for itemfield-selections |
---|
86 | * @param awar_name_ the name of the awar bound to the selection list |
---|
87 | * @param gb_main_ the database |
---|
88 | * @param selector_ describes the item type, for which fields are shown |
---|
89 | * @param type_filter_ is a bitstring which controls what types will be shown in the selection list (several filters are predefined: 'FIELD_FILTER_...', FIELD_UNFILTERED) |
---|
90 | * @param purpose_ describes purpose of field (defaults to 'field'; appears in popup-title and error-messages) |
---|
91 | * @param field_filter_ controls if pseudo-fields and/or hidden fields are added and whether new fields are allowed (defaults to SF_STANDARD) |
---|
92 | */ |
---|
93 | : awar_name(awar_name_), |
---|
94 | purpose(purpose_), |
---|
95 | gb_main(gb_main_), |
---|
96 | selector(&selector_), |
---|
97 | type_filter(type_filter_), |
---|
98 | field_filter(field_filter_) |
---|
99 | {} |
---|
100 | |
---|
101 | const std::string& get_awarname() const { return awar_name; } |
---|
102 | const std::string& get_described_field() const { return purpose; } |
---|
103 | long get_type_filter() const { return type_filter; } |
---|
104 | SelectableFields get_field_filter() const { return field_filter; } |
---|
105 | GBDATA *get_gb_main() const { return gb_main; } |
---|
106 | ItemSelector& get_itemtype() const { return *selector; } |
---|
107 | |
---|
108 | // for internal use only: |
---|
109 | bool new_fields_allowed() const { return field_filter & SF_ALLOW_NEW; } |
---|
110 | Itemfield_Selection *build_sel(AW_selection_list *from_sellist) const; |
---|
111 | bool matches4reuse(const FieldSelDef& other) const; |
---|
112 | }; |
---|
113 | |
---|
114 | enum FailIfField { |
---|
115 | FIF_NAME_SELECTED = 1, // fail if 'name' field selected |
---|
116 | FIF_NO_FIELD_SELECTED = 2, // fail if NO_FIELD_SELECTED |
---|
117 | |
---|
118 | // use-cases: |
---|
119 | FIF_STANDARD = FIF_NAME_SELECTED|FIF_NO_FIELD_SELECTED, |
---|
120 | FIF_ALLOW_NONE = FIF_STANDARD^FIF_NO_FIELD_SELECTED, |
---|
121 | FIF_ALLOW_ID_CHANGE = FIF_STANDARD^FIF_NAME_SELECTED, |
---|
122 | }; |
---|
123 | |
---|
124 | Itemfield_Selection *create_itemfield_selection_list( AW_window *aws, const FieldSelDef& selDef, const char *at); |
---|
125 | void create_itemfield_selection_button(AW_window *aws, const FieldSelDef& selDef, const char *at); |
---|
126 | const char *prepare_and_get_selected_itemfield(AW_root *awr, const char *awar_name, GBDATA *gb_main, const ItemSelector& itemtype, FailIfField failIf = FIF_STANDARD); |
---|
127 | const char *get_itemfield_type_awarname(const char *itemfield_awarname); |
---|
128 | |
---|
129 | enum RescanMode { |
---|
130 | RESCAN_REFRESH = 1, // scan database for unregistered/unused fields and update the field list |
---|
131 | RESCAN_SHOW_ALL = 2, // unhide all hidden fields |
---|
132 | }; |
---|
133 | |
---|
134 | // @@@ generalize (use BoundItemSel) |
---|
135 | |
---|
136 | void species_field_selection_list_rescan(GBDATA *gb_main, RescanMode mode); |
---|
137 | void gene_field_selection_list_rescan (GBDATA *gb_main, RescanMode mode); |
---|
138 | |
---|
139 | void species_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main); |
---|
140 | void species_field_selection_list_update_cb (AW_window*, GBDATA *gb_main); |
---|
141 | |
---|
142 | void gene_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main); |
---|
143 | void gene_field_selection_list_update_cb (AW_window*, GBDATA *gb_main); |
---|
144 | |
---|
145 | void experiment_field_selection_list_unhide_all_cb(AW_window*, GBDATA *gb_main); |
---|
146 | void experiment_field_selection_list_update_cb (AW_window*, GBDATA *gb_main); |
---|
147 | |
---|
148 | #else |
---|
149 | #error item_sel_list.h included twice |
---|
150 | #endif // ITEM_SEL_LIST_H |
---|
151 | |
---|