Line data Source code
1 : /* File: gui_attributes_editor.c; Copyright and License: see below */
2 :
3 : #include "gui_attributes_editor.h"
4 : #include "gui_attribute_type_of_classifier.h"
5 : #include "gui_attribute_type_of_diagram.h"
6 : #include "gui_attribute_type_of_feature.h"
7 : #include "gui_attribute_type_of_relationship.h"
8 : #include "draw/draw_stereotype_image.h"
9 : #include "u8/u8_trace.h"
10 : #include "ctrl_simple_changer.h"
11 : #include "entity/data_table.h"
12 : #include "entity/data_id.h"
13 : #include "utf8stringbuf/utf8string.h"
14 : #include <gtk/gtk.h>
15 : #include <stdbool.h>
16 :
17 0 : void gui_attributes_editor_init ( gui_attributes_editor_t *this_,
18 : GtkLabel *id_label,
19 : GtkEntry *name_entry,
20 : GtkEntry *stereotype_entry,
21 : GtkDropDown *type_dropdown,
22 : GtkWidget *type_diag_grid,
23 : GtkWidget *type_clas_grid,
24 : GtkWidget *type_feat_grid,
25 : GtkWidget *type_rel_grid,
26 : GtkTextView *description_text_view,
27 : GtkButton *commit_button,
28 : gui_resources_t *resources,
29 : ctrl_controller_t *controller,
30 : data_database_reader_t *db_reader,
31 : data_database_t *database,
32 : gui_simple_message_to_user_t *message_to_user )
33 : {
34 0 : U8_TRACE_BEGIN();
35 0 : assert( NULL != id_label );
36 0 : assert( NULL != name_entry );
37 0 : assert( NULL != stereotype_entry );
38 0 : assert( NULL != type_dropdown );
39 0 : assert( NULL != type_diag_grid );
40 0 : assert( NULL != type_clas_grid );
41 0 : assert( NULL != type_feat_grid );
42 0 : assert( NULL != type_rel_grid );
43 0 : assert( NULL != description_text_view );
44 0 : assert( NULL != commit_button );
45 :
46 0 : assert( NULL != resources );
47 0 : assert( NULL != controller );
48 0 : assert( NULL != db_reader );
49 0 : assert( NULL != message_to_user );
50 :
51 0 : (*this_).id_label = id_label;
52 0 : (*this_).name_entry = name_entry;
53 0 : (*this_).stereotype_entry = stereotype_entry;
54 0 : (*this_).type_dropdown = type_dropdown;
55 0 : (*this_).type_diag_grid = type_diag_grid;
56 0 : (*this_).type_clas_grid = type_clas_grid;
57 0 : (*this_).type_feat_grid = type_feat_grid;
58 0 : (*this_).type_rel_grid = type_rel_grid;
59 0 : (*this_).description_text_view = description_text_view;
60 0 : (*this_).commit_button = commit_button;
61 :
62 0 : (*this_).db_reader = db_reader;
63 0 : (*this_).controller = controller;
64 0 : (*this_).database = database;
65 0 : (*this_).message_to_user = message_to_user;
66 0 : (*this_).sync_dir = GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI;
67 0 : data_id_init_void( &((*this_).latest_created_id) );
68 0 : data_id_init_void( &((*this_).second_latest_id) );
69 0 : data_diagram_init_empty( &((*this_).private_diagram_cache) );
70 0 : data_classifier_init_empty( &((*this_).private_classifier_cache) );
71 0 : data_feature_init_empty( &((*this_).private_feature_cache) );
72 0 : data_relationship_init_empty( &((*this_).private_relationship_cache) );
73 0 : data_id_init_void( &((*this_).selected_object_id) );
74 :
75 0 : gui_type_resource_list_init( &((*this_).type_lists), resources );
76 0 : (*this_).temp_search_me = GUI_TYPE_RESOURCE( g_object_new( gui_type_resource_get_type(), NULL ) );
77 0 : (*this_).previous_selected_object_id = DATA_ID_VOID;
78 :
79 : /* update widgets */
80 0 : gui_attributes_editor_update_widgets( this_ );
81 :
82 0 : U8_TRACE_END();
83 0 : }
84 :
85 0 : void gui_attributes_editor_destroy ( gui_attributes_editor_t *this_ )
86 : {
87 0 : U8_TRACE_BEGIN();
88 :
89 0 : data_id_destroy( &((*this_).selected_object_id) );
90 0 : data_diagram_destroy( &((*this_).private_diagram_cache) );
91 0 : data_classifier_destroy( &((*this_).private_classifier_cache) );
92 0 : data_feature_destroy( &((*this_).private_feature_cache) );
93 0 : data_relationship_destroy( &((*this_).private_relationship_cache) );
94 0 : data_id_destroy( &((*this_).second_latest_id) );
95 0 : data_id_destroy( &((*this_).latest_created_id) );
96 :
97 0 : g_object_unref( (*this_).temp_search_me );
98 0 : gui_type_resource_list_destroy( &((*this_).type_lists) );
99 :
100 0 : (*this_).db_reader = NULL;
101 0 : (*this_).controller = NULL;
102 0 : (*this_).message_to_user = NULL;
103 :
104 0 : (*this_).id_label = NULL;
105 0 : (*this_).name_entry = NULL;
106 0 : (*this_).stereotype_entry = NULL;
107 0 : (*this_).type_dropdown = NULL;
108 0 : (*this_).type_diag_grid = NULL;
109 0 : (*this_).type_clas_grid = NULL;
110 0 : (*this_).type_feat_grid = NULL;
111 0 : (*this_).type_rel_grid = NULL;
112 0 : (*this_).description_text_view = NULL;
113 :
114 0 : U8_TRACE_END();
115 0 : }
116 :
117 0 : void gui_attributes_editor_update_widgets ( gui_attributes_editor_t *this_ )
118 : {
119 0 : U8_TRACE_BEGIN();
120 :
121 0 : if ( (*this_).sync_dir == GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI )
122 : {
123 0 : gui_attributes_editor_private_id_update_view( this_ );
124 0 : gui_attributes_editor_private_name_update_view ( this_ );
125 0 : gui_attributes_editor_private_stereotype_update_view( this_ );
126 0 : gui_attributes_editor_private_description_update_view( this_ );
127 0 : gui_attributes_editor_private_type_update_view( this_ );
128 : }
129 : else
130 : {
131 : /* widgets are not updated in GUI TO DB mode */
132 0 : U8_LOG_WARNING( "gui_attributes_editor_update_widgets called in GUI_ATTRIBUTES_EDITOR_SYNC_DIR_GUI_TO_DB mode!" );
133 : }
134 :
135 0 : U8_TRACE_END();
136 0 : }
137 :
138 0 : void gui_attributes_editor_commit_changes ( gui_attributes_editor_t *this_ )
139 : {
140 0 : U8_TRACE_BEGIN();
141 :
142 0 : const gui_attributes_editor_sync_dir_t original_dir = (*this_).sync_dir;
143 0 : if ( (*this_).sync_dir == GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI )
144 : {
145 0 : U8_LOG_EVENT( "gui_attributes_editor entering state GUI_ATTRIBUTES_EDITOR_SYNC_DIR_GUI_TO_DB." );
146 0 : (*this_).sync_dir = GUI_ATTRIBUTES_EDITOR_SYNC_DIR_GUI_TO_DB;
147 : }
148 :
149 0 : gui_attributes_editor_private_name_commit_changes ( this_ );
150 0 : gui_attributes_editor_private_stereotype_commit_changes ( this_ );
151 0 : gui_attributes_editor_private_description_commit_changes ( this_ );
152 :
153 0 : if ( original_dir == GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI )
154 : {
155 0 : U8_LOG_EVENT( "gui_attributes_editor leaving state GUI_ATTRIBUTES_EDITOR_SYNC_DIR_GUI_TO_DB." );
156 0 : (*this_).sync_dir = GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI;
157 0 : gui_attributes_editor_private_load_object( this_, (*this_).selected_object_id );
158 0 : gui_attributes_editor_update_widgets( this_ );
159 : }
160 :
161 0 : U8_TRACE_END();
162 0 : }
163 :
164 0 : void gui_attributes_editor_trace ( const gui_attributes_editor_t *this_ )
165 : {
166 0 : U8_TRACE_BEGIN();
167 :
168 0 : U8_TRACE_INFO( "gui_attributes_editor_t" );
169 0 : U8_TRACE_INFO( "- selected_object_id:" );
170 0 : data_id_trace( &((*this_).selected_object_id) );
171 :
172 0 : switch ( data_id_get_table( &((*this_).selected_object_id ) ) )
173 : {
174 0 : case DATA_TABLE_VOID:
175 : {
176 0 : U8_TRACE_INFO( "- cached object: none" );
177 : }
178 0 : break;
179 :
180 0 : case DATA_TABLE_CLASSIFIER:
181 : {
182 0 : U8_TRACE_INFO( "- cached object:" );
183 0 : data_classifier_trace( &((*this_).private_classifier_cache) );
184 : }
185 0 : break;
186 :
187 0 : case DATA_TABLE_FEATURE:
188 : {
189 0 : U8_TRACE_INFO( "- cached object:" );
190 0 : data_feature_trace( &((*this_).private_feature_cache) );
191 : }
192 0 : break;
193 :
194 0 : case DATA_TABLE_RELATIONSHIP:
195 : {
196 0 : U8_TRACE_INFO( "- cached object:" );
197 0 : data_relationship_trace( &((*this_).private_relationship_cache) );
198 : }
199 0 : break;
200 :
201 0 : case DATA_TABLE_DIAGRAMELEMENT:
202 : {
203 0 : U8_TRACE_INFO( "- cached object: ANOMALY, UNEXPECTED VALUE OF data_table_t" );
204 : }
205 0 : break;
206 :
207 0 : case DATA_TABLE_DIAGRAM:
208 : {
209 0 : U8_TRACE_INFO( "- cached object:" );
210 0 : data_diagram_trace( &((*this_).private_diagram_cache) );
211 : }
212 0 : break;
213 :
214 0 : default:
215 : {
216 0 : U8_TRACE_INFO( "- cached object: ERROR, ILLEGAL ENUM VALUE OF data_table_t" );
217 : }
218 0 : break;
219 : }
220 :
221 : /* id: */
222 : if ( U8_TRACE_ACTIVE )
223 : {
224 : GtkLabel *id_widget;
225 : const char* text;
226 0 : id_widget = GTK_LABEL( (*this_).id_label );
227 0 : text = gtk_label_get_text( id_widget );
228 :
229 0 : U8_TRACE_INFO_STR( "- visible id:", text );
230 : }
231 :
232 : /* name: */
233 : if ( U8_TRACE_ACTIVE )
234 : {
235 : const char* text;
236 0 : GtkEntry *const name_widget = GTK_ENTRY( (*this_).name_entry );
237 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
238 0 : text = gtk_entry_buffer_get_text( name_buf );
239 0 : U8_TRACE_INFO_STR( "- visible name:", text );
240 : }
241 :
242 : /* stereotype: */
243 : if ( U8_TRACE_ACTIVE )
244 : {
245 : const char* text;
246 0 : GtkEntry *const stereotype_widget = GTK_ENTRY( (*this_).stereotype_entry );
247 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
248 0 : text = gtk_entry_buffer_get_text( stereotype_buf );
249 0 : U8_TRACE_INFO_STR( "- visible stereotype:", text );
250 : }
251 :
252 : /* type: */
253 : if ( U8_TRACE_ACTIVE )
254 : {
255 : int obj_type;
256 0 : GObject *selected = gtk_drop_down_get_selected_item ( (*this_).type_dropdown );
257 0 : if ( selected == NULL )
258 : {
259 0 : obj_type = -1;
260 : }
261 : else
262 : {
263 0 : const data_type_t *obj_full_type = gui_type_resource_get_type_id( ((GuiTypeResource*)selected) );
264 0 : obj_type = data_type_get_type_as_int( obj_full_type );
265 : }
266 0 : U8_TRACE_INFO_INT( "- visible type id:", obj_type );
267 : }
268 :
269 : /* description: */
270 : if ( U8_TRACE_ACTIVE )
271 : {
272 : GtkTextView *description_widget;
273 : GtkTextBuffer *buffer;
274 0 : description_widget = GTK_TEXT_VIEW( (*this_).description_text_view );
275 0 : buffer = gtk_text_view_get_buffer ( description_widget );
276 : GtkTextIter start;
277 : GtkTextIter end;
278 0 : gtk_text_buffer_get_start_iter ( buffer, &start );
279 0 : gtk_text_buffer_get_end_iter ( buffer, &end );
280 : const char* text;
281 0 : text = gtk_text_buffer_get_text ( buffer, &start, &end, false );
282 0 : U8_TRACE_INFO_STR( "- visible description:", text );
283 : }
284 :
285 0 : U8_TRACE_INFO_STR( "- sync mode:", ((*this_).sync_dir==GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI)?"db-2-gui":"GUI_TO_DB" );
286 :
287 0 : U8_TRACE_END();
288 0 : }
289 :
290 : /* ================================ USER INPUT CALLBACKS ================================ */
291 :
292 0 : void gui_attributes_editor_name_focus_left_callback( GtkEventControllerFocus* self, gpointer user_data )
293 : {
294 0 : U8_TRACE_BEGIN();
295 0 : assert( user_data != NULL );
296 0 : gui_attributes_editor_t *const this_ = (gui_attributes_editor_t*) user_data;
297 0 : assert( gtk_event_controller_get_widget( GTK_EVENT_CONTROLLER(self) ) == GTK_WIDGET( (*this_).name_entry ) );
298 :
299 : //gui_attributes_editor_private_name_commit_changes( this_ );
300 0 : gui_attributes_editor_commit_changes( this_ );
301 :
302 0 : U8_TRACE_TIMESTAMP();
303 0 : U8_TRACE_END();
304 0 : }
305 :
306 0 : void gui_attributes_editor_name_enter_callback ( GtkEntry *widget, gpointer user_data )
307 : {
308 0 : U8_TRACE_BEGIN();
309 0 : assert( user_data != NULL );
310 0 : gui_attributes_editor_t *const this_ = (gui_attributes_editor_t*) user_data;
311 0 : assert( GTK_ENTRY( widget ) == GTK_ENTRY( (*this_).name_entry ) );
312 :
313 : //gui_attributes_editor_private_name_commit_changes( this_ );
314 0 : gui_attributes_editor_commit_changes ( this_ );
315 :
316 0 : U8_TRACE_TIMESTAMP();
317 0 : U8_TRACE_END();
318 0 : }
319 :
320 0 : void gui_attributes_editor_stereotype_focus_left_callback( GtkEventControllerFocus* self, gpointer user_data )
321 : {
322 0 : U8_TRACE_BEGIN();
323 0 : assert( user_data != NULL );
324 0 : gui_attributes_editor_t *const this_ = (gui_attributes_editor_t*) user_data;
325 0 : assert( gtk_event_controller_get_widget( GTK_EVENT_CONTROLLER(self) ) == GTK_WIDGET( (*this_).stereotype_entry ) );
326 :
327 : //gui_attributes_editor_private_stereotype_commit_changes( this_ );
328 0 : gui_attributes_editor_commit_changes( this_ );
329 :
330 0 : U8_TRACE_TIMESTAMP();
331 0 : U8_TRACE_END();
332 0 : }
333 :
334 0 : void gui_attributes_editor_stereotype_enter_callback ( GtkEntry *widget, gpointer user_data )
335 : {
336 0 : U8_TRACE_BEGIN();
337 0 : assert( user_data != NULL );
338 0 : gui_attributes_editor_t *const this_ = (gui_attributes_editor_t*) user_data;
339 0 : assert( GTK_ENTRY(widget) == GTK_ENTRY( (*this_).stereotype_entry ) );
340 :
341 : //gui_attributes_editor_private_stereotype_commit_changes( this_ );
342 0 : gui_attributes_editor_commit_changes ( this_ );
343 :
344 0 : U8_TRACE_TIMESTAMP();
345 0 : U8_TRACE_END();
346 0 : }
347 :
348 0 : void gui_attributes_editor_type_changed_callback ( GObject* self, GParamSpec* pspec, gpointer user_data )
349 : {
350 0 : U8_TRACE_BEGIN();
351 : gui_attributes_editor_t *this_;
352 0 : this_ = (gui_attributes_editor_t*) user_data;
353 0 : assert ( NULL != this_ );
354 0 : assert ( GTK_DROP_DOWN( self ) == (*this_).type_dropdown );
355 :
356 : /* if the selected object has changed, this callback is triggered by that change, */
357 : /* not by the user selecting another type */
358 0 : bool user_requested = data_id_equals( &((*this_).previous_selected_object_id), &((*this_).selected_object_id) );
359 0 : (*this_).previous_selected_object_id = (*this_).selected_object_id;
360 :
361 : /* get type id from widget */
362 0 : GObject *selected = gtk_drop_down_get_selected_item ( (*this_).type_dropdown );
363 0 : if (( selected != NULL )&& user_requested )
364 : {
365 : const data_type_t *const obj_full_type
366 0 : = gui_type_resource_get_type_id( ((GuiTypeResource*)selected) );
367 0 : const int obj_type = data_type_get_type_as_int( obj_full_type );
368 0 : U8_TRACE_INFO_INT( "selected type_id:", obj_type );
369 :
370 : /* commit possibly changed texts before causing update events */
371 0 : gui_attributes_editor_commit_changes( this_ );
372 :
373 0 : gui_attributes_editor_private_type_commit_changes( this_, obj_type );
374 : }
375 :
376 0 : U8_TRACE_TIMESTAMP();
377 0 : U8_TRACE_END();
378 0 : }
379 :
380 0 : void gui_attributes_editor_type_of_diagram_btn_callback( GtkWidget* button, gpointer data )
381 : {
382 0 : U8_TRACE_BEGIN();
383 0 : const gui_attribute_type_of_diagram_t *const btn_data = (gui_attribute_type_of_diagram_t*) data;
384 0 : assert ( NULL != btn_data );
385 0 : gui_attributes_editor_t *const this_ = gui_attribute_type_of_diagram_get_editor( btn_data );
386 0 : assert ( NULL != this_ );
387 0 : const data_diagram_type_t selected_type = gui_attribute_type_of_diagram_get_selected_type( btn_data );
388 0 : U8_TRACE_INFO_INT( "selected type:", selected_type );
389 :
390 : /* commit possibly changed texts before causing update events */
391 0 : gui_attributes_editor_commit_changes( this_ );
392 :
393 0 : gui_attributes_editor_private_type_commit_changes ( this_, selected_type );
394 :
395 0 : U8_TRACE_TIMESTAMP();
396 0 : U8_TRACE_END();
397 0 : }
398 :
399 0 : void gui_attributes_editor_type_of_classifier_btn_callback( GtkWidget* button, gpointer data )
400 : {
401 0 : U8_TRACE_BEGIN();
402 0 : const gui_attribute_type_of_classifier_t *const btn_data = (gui_attribute_type_of_classifier_t*) data;
403 0 : assert ( NULL != btn_data );
404 0 : gui_attributes_editor_t *const this_ = gui_attribute_type_of_classifier_get_editor( btn_data );
405 0 : assert ( NULL != this_ );
406 0 : const data_diagram_type_t selected_type = gui_attribute_type_of_classifier_get_selected_type( btn_data );
407 0 : U8_TRACE_INFO_INT( "selected type:", selected_type );
408 :
409 : /* commit possibly changed texts before causing update events */
410 0 : gui_attributes_editor_commit_changes( this_ );
411 :
412 0 : gui_attributes_editor_private_type_commit_changes ( this_, selected_type );
413 :
414 0 : U8_TRACE_TIMESTAMP();
415 0 : U8_TRACE_END();
416 0 : }
417 :
418 0 : void gui_attributes_editor_type_of_feature_btn_callback( GtkWidget* button, gpointer data )
419 : {
420 0 : U8_TRACE_BEGIN();
421 0 : const gui_attribute_type_of_feature_t *const btn_data = (gui_attribute_type_of_feature_t*) data;
422 0 : assert ( NULL != btn_data );
423 0 : gui_attributes_editor_t *const this_ = gui_attribute_type_of_feature_get_editor( btn_data );
424 0 : assert ( NULL != this_ );
425 0 : const data_diagram_type_t selected_type = gui_attribute_type_of_feature_get_selected_type( btn_data );
426 0 : U8_TRACE_INFO_INT( "selected type:", selected_type );
427 :
428 : /* commit possibly changed texts before causing update events */
429 0 : gui_attributes_editor_commit_changes( this_ );
430 :
431 0 : gui_attributes_editor_private_type_commit_changes ( this_, selected_type );
432 :
433 0 : U8_TRACE_TIMESTAMP();
434 0 : U8_TRACE_END();
435 0 : }
436 :
437 0 : void gui_attributes_editor_type_of_relationship_btn_callback( GtkWidget* button, gpointer data )
438 : {
439 0 : U8_TRACE_BEGIN();
440 0 : const gui_attribute_type_of_relationship_t *const btn_data = (gui_attribute_type_of_relationship_t*) data;
441 0 : assert ( NULL != btn_data );
442 0 : gui_attributes_editor_t *const this_ = gui_attribute_type_of_relationship_get_editor( btn_data );
443 0 : assert ( NULL != this_ );
444 0 : const data_diagram_type_t selected_type = gui_attribute_type_of_relationship_get_selected_type( btn_data );
445 0 : U8_TRACE_INFO_INT( "selected type:", selected_type );
446 :
447 : /* commit possibly changed texts before causing update events */
448 0 : gui_attributes_editor_commit_changes( this_ );
449 :
450 0 : gui_attributes_editor_private_type_commit_changes ( this_, selected_type );
451 :
452 0 : U8_TRACE_TIMESTAMP();
453 0 : U8_TRACE_END();
454 0 : }
455 :
456 0 : void gui_attributes_editor_description_focus_left_callback( GtkEventControllerFocus* self, gpointer user_data )
457 : {
458 0 : U8_TRACE_BEGIN();
459 0 : assert( user_data != NULL );
460 0 : gui_attributes_editor_t *const this_ = (gui_attributes_editor_t*) user_data;
461 0 : assert( gtk_event_controller_get_widget( GTK_EVENT_CONTROLLER(self) ) == GTK_WIDGET( (*this_).description_text_view ) );
462 :
463 0 : gui_attributes_editor_commit_changes( this_ );
464 : //gui_attributes_editor_private_description_commit_changes( this_ );
465 :
466 0 : U8_TRACE_TIMESTAMP();
467 0 : U8_TRACE_END();
468 0 : }
469 :
470 : /* ================================ SELECTION or MODEL CHANGED CALLBACKS ================================ */
471 :
472 0 : void gui_attributes_editor_focused_object_changed_callback( GtkWidget *widget, data_id_t *id, gpointer user_data )
473 : {
474 0 : U8_TRACE_BEGIN();
475 : gui_attributes_editor_t *this_;
476 0 : this_ = (gui_attributes_editor_t*) user_data;
477 0 : assert ( NULL != this_ );
478 0 : assert ( NULL != id );
479 0 : assert ( NULL != widget );
480 :
481 : /* is a new object selected ? */
482 0 : if ( ! data_id_equals( &((*this_).selected_object_id), id ) )
483 : {
484 : /* store all changes on the old object */
485 0 : gui_attributes_editor_commit_changes( this_ );
486 :
487 : /* load the new object */
488 0 : data_id_trace( id );
489 0 : gui_attributes_editor_private_load_object( this_, *id );
490 :
491 : /* update all widgets now */
492 0 : gui_attributes_editor_update_widgets( this_ );
493 :
494 : /* select the name so that typing replaces it immediately */
495 : /* latest_created_id allows to check if selected id new */
496 0 : if ( ( data_id_equals( &((*this_).latest_created_id), &((*this_).selected_object_id) ) )
497 0 : || ( data_id_equals( &((*this_).second_latest_id), &((*this_).selected_object_id) ) ) )
498 : {
499 0 : gtk_widget_grab_focus( GTK_WIDGET((*this_).name_entry) );
500 : /* the grab focus may cause focus-lost signals - which update the widgets */
501 0 : gtk_editable_select_region( GTK_EDITABLE((*this_).name_entry), 0, -1 );
502 0 : U8_TRACE_INFO( "gui_attributes_editor called gtk_widget_grab_focus" );
503 : }
504 : }
505 :
506 0 : U8_TRACE_TIMESTAMP();
507 0 : U8_TRACE_END();
508 0 : }
509 :
510 0 : void gui_attributes_editor_data_changed_callback( GtkWidget *widget, data_change_message_t *msg, gpointer user_data )
511 : {
512 0 : U8_TRACE_BEGIN();
513 : gui_attributes_editor_t *this_;
514 0 : this_ = (gui_attributes_editor_t*) user_data;
515 0 : assert ( NULL != this_ );
516 0 : assert ( NULL != msg );
517 0 : assert ( NULL != widget );
518 :
519 : data_id_t id;
520 : data_change_event_type_t evt_type;
521 0 : id = data_change_message_get_modified( msg );
522 0 : evt_type = data_change_message_get_event ( msg );
523 :
524 0 : if ( evt_type == DATA_CHANGE_EVENT_TYPE_DB_PREPARE_CLOSE )
525 : {
526 : /* store all changes on the old object */
527 0 : gui_attributes_editor_commit_changes( this_ );
528 : }
529 0 : else if ( evt_type == DATA_CHANGE_EVENT_TYPE_DB_CLOSED )
530 : {
531 0 : data_id_reinit_void( &((*this_).latest_created_id) );
532 0 : data_id_reinit_void( &((*this_).second_latest_id) );
533 : /* data_id_t nothing;
534 : data_id_init_void( ¬hing );
535 : gui_attributes_editor_private_load_object( this_, nothing ); / * clear cached data */
536 0 : gui_attributes_editor_private_load_object( this_, DATA_ID_VOID ); /* clear cached data */
537 0 : gui_attributes_editor_update_widgets ( this_ );
538 : }
539 0 : else if ( data_id_equals( &id, &((*this_).selected_object_id) ) )
540 : {
541 : /* DO NOT STORE DATA IN A DATA CHANGED CALLBACK - MAY CAUSE ENDLESS RECURSION */
542 0 : data_change_message_trace( msg );
543 0 : if ( (*this_).sync_dir == GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI )
544 : {
545 : /* overwrite/update displayed values */
546 0 : gui_attributes_editor_private_load_object( this_, id ); /* checks if object still exists */
547 0 : gui_attributes_editor_update_widgets ( this_ );
548 : }
549 : }
550 0 : else if ( evt_type == DATA_CHANGE_EVENT_TYPE_CREATE )
551 : {
552 : /* diagram elements should not be remembered, only the new classifier is important */
553 0 : if ( DATA_TABLE_DIAGRAMELEMENT != data_id_get_table( &id ) )
554 : {
555 0 : (*this_).second_latest_id = (*this_).latest_created_id;
556 0 : (*this_).latest_created_id = id;
557 : }
558 : };
559 :
560 0 : U8_TRACE_TIMESTAMP();
561 0 : U8_TRACE_END();
562 0 : }
563 :
564 : /* ================================ PRIVATE METHODS ================================ */
565 :
566 0 : void gui_attributes_editor_private_load_object ( gui_attributes_editor_t *this_, data_id_t id )
567 : {
568 0 : U8_TRACE_BEGIN();
569 :
570 : /* before overwriting the current data, trace this_: */
571 0 : gui_attributes_editor_trace( this_ );
572 0 : if ( (*this_).sync_dir != GUI_ATTRIBUTES_EDITOR_SYNC_DIR_DB_TO_GUI )
573 : {
574 0 : U8_LOG_WARNING( "gui_attributes_editor_private_load_object called in GUI_ATTRIBUTES_EDITOR_SYNC_DIR_GUI_TO_DB mode!" );
575 : }
576 :
577 0 : switch ( data_id_get_table(&id) )
578 : {
579 0 : case DATA_TABLE_VOID:
580 : {
581 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
582 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
583 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
584 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
585 0 : data_id_reinit_void( &((*this_).selected_object_id) );
586 : }
587 0 : break;
588 :
589 0 : case DATA_TABLE_CLASSIFIER:
590 : {
591 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
592 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
593 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
594 :
595 : /* load the object */
596 : {
597 : u8_error_t db_err;
598 :
599 0 : data_classifier_destroy( &((*this_).private_classifier_cache) );
600 0 : db_err = data_database_reader_get_classifier_by_id ( (*this_).db_reader, data_id_get_row_id(&id), &((*this_).private_classifier_cache) );
601 0 : data_id_replace( &((*this_).selected_object_id), &id );
602 :
603 0 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
604 : {
605 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading a classifier" );
606 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
607 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
608 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
609 : );
610 : }
611 0 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
612 : {
613 : /* error at loading */
614 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
615 0 : data_id_reinit_void( &((*this_).selected_object_id) );
616 : }
617 : }
618 : }
619 0 : break;
620 :
621 0 : case DATA_TABLE_FEATURE:
622 : {
623 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
624 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
625 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
626 :
627 : /* load the object */
628 : {
629 : u8_error_t db_err;
630 :
631 0 : data_feature_destroy( &((*this_).private_feature_cache) );
632 0 : db_err = data_database_reader_get_feature_by_id ( (*this_).db_reader, data_id_get_row_id(&id), &((*this_).private_feature_cache) );
633 0 : data_id_replace( &((*this_).selected_object_id), &id );
634 :
635 0 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
636 : {
637 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading a feature" );
638 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
639 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
640 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
641 : );
642 : }
643 0 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
644 : {
645 : /* error at loading */
646 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
647 0 : data_id_reinit_void( &((*this_).selected_object_id) );
648 : }
649 : }
650 : }
651 0 : break;
652 :
653 0 : case DATA_TABLE_RELATIONSHIP:
654 : {
655 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
656 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
657 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
658 :
659 : /* load the object */
660 : {
661 : u8_error_t db_err;
662 :
663 0 : data_relationship_destroy( &((*this_).private_relationship_cache) );
664 0 : db_err = data_database_reader_get_relationship_by_id ( (*this_).db_reader, data_id_get_row_id(&id), &((*this_).private_relationship_cache) );
665 0 : data_id_replace( &((*this_).selected_object_id), &id );
666 :
667 0 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
668 : {
669 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading a relationship" );
670 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
671 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
672 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
673 : );
674 : }
675 0 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
676 : {
677 : /* error at loading */
678 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
679 0 : data_id_reinit_void( &((*this_).selected_object_id) );
680 : }
681 : }
682 : }
683 0 : break;
684 :
685 0 : case DATA_TABLE_DIAGRAMELEMENT:
686 : {
687 : /* (*this_).selected_object_id should not be of type DATA_TABLE_DIAGRAMELEMENT */
688 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
689 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
690 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
691 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
692 0 : data_id_reinit_void( &((*this_).selected_object_id) );
693 : }
694 0 : break;
695 :
696 0 : case DATA_TABLE_DIAGRAM:
697 : {
698 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
699 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
700 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
701 :
702 : /* load the object */
703 : {
704 : u8_error_t db_err;
705 :
706 0 : data_diagram_destroy( &((*this_).private_diagram_cache) );
707 0 : db_err = data_database_reader_get_diagram_by_id ( (*this_).db_reader, data_id_get_row_id(&id), &((*this_).private_diagram_cache) );
708 0 : data_id_replace( &((*this_).selected_object_id), &id );
709 :
710 0 : if ( u8_error_contains( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
711 : {
712 0 : U8_LOG_ERROR( "U8_ERROR_STRING_BUFFER_EXCEEDED at loading a diagram" );
713 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
714 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
715 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
716 : );
717 : }
718 0 : if ( u8_error_more_than( db_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
719 : {
720 : /* error at loading */
721 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
722 0 : data_id_reinit_void( &((*this_).selected_object_id) );
723 : }
724 : }
725 : }
726 0 : break;
727 :
728 0 : default:
729 : {
730 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
731 :
732 0 : data_diagram_reinit_empty( &((*this_).private_diagram_cache) );
733 0 : data_classifier_reinit_empty( &((*this_).private_classifier_cache) );
734 0 : data_feature_reinit_empty( &((*this_).private_feature_cache) );
735 0 : data_relationship_reinit_empty( &((*this_).private_relationship_cache) );
736 0 : data_id_reinit_void( &((*this_).selected_object_id) );
737 : }
738 0 : break;
739 : }
740 :
741 : /* after loading the current data, trace this_: */
742 0 : gui_attributes_editor_trace( this_ );
743 :
744 0 : U8_TRACE_END();
745 0 : }
746 :
747 0 : void gui_attributes_editor_private_name_commit_changes ( gui_attributes_editor_t *this_ )
748 : {
749 0 : U8_TRACE_BEGIN();
750 :
751 : const char* text;
752 0 : GtkEntry *const name_widget = GTK_ENTRY( (*this_).name_entry );
753 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
754 0 : text = gtk_entry_buffer_get_text( name_buf );
755 :
756 0 : U8_TRACE_INFO_STR( "text:", text );
757 :
758 : u8_error_t ctrl_err;
759 0 : switch ( data_id_get_table( &((*this_).selected_object_id) ) )
760 : {
761 0 : case DATA_TABLE_VOID:
762 : {
763 : /* nothing to do */
764 0 : U8_TRACE_INFO( "no object selected where name can be updated." );
765 : }
766 0 : break;
767 :
768 0 : case DATA_TABLE_CLASSIFIER:
769 : {
770 : const char *const unchanged_text
771 0 : = data_classifier_get_name_const( &((*this_).private_classifier_cache) );
772 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
773 : {
774 : u8_error_t handled_err;
775 : {
776 : ctrl_simple_changer_t name_disambiguator;
777 0 : ctrl_simple_changer_init( &name_disambiguator, (*this_).controller, (*this_).db_reader );
778 0 : ctrl_err = ctrl_simple_changer_update_classifier_name( &name_disambiguator,
779 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
780 : text,
781 : &handled_err
782 : );
783 0 : ctrl_simple_changer_destroy( &name_disambiguator );
784 : }
785 :
786 0 : if ( u8_error_contains( handled_err, U8_ERROR_DUPLICATE_NAME ) )
787 : {
788 0 : gui_simple_message_to_user_show_message_with_name( (*this_).message_to_user,
789 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
790 : GUI_SIMPLE_MESSAGE_CONTENT_NAME_NOT_UNIQUE,
791 : text
792 : );
793 : }
794 0 : else if ( u8_error_contains( ctrl_err, U8_ERROR_STRING_BUFFER_EXCEEDED ) )
795 : {
796 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
797 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
798 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
799 : );
800 : }
801 0 : else if ( u8_error_contains( ctrl_err, U8_ERROR_READ_ONLY_DB ) )
802 : {
803 : /* notify read-only warning to user */
804 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
805 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
806 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
807 : );
808 : }
809 0 : else if ( U8_ERROR_NONE != ctrl_err )
810 : {
811 0 : U8_LOG_ERROR_HEX( "update name failed:", ctrl_err );
812 : }
813 : }
814 : }
815 0 : break;
816 :
817 0 : case DATA_TABLE_FEATURE:
818 : {
819 : const char *const unchanged_text
820 0 : = data_feature_get_key_const( &((*this_).private_feature_cache) );
821 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
822 : {
823 : ctrl_classifier_controller_t *class_ctrl;
824 0 : class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
825 :
826 0 : ctrl_err = ctrl_classifier_controller_update_feature_key( class_ctrl,
827 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
828 : text
829 : );
830 0 : if ( U8_ERROR_STRING_BUFFER_EXCEEDED == ctrl_err )
831 : {
832 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
833 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
834 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
835 : );
836 : }
837 0 : else if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
838 : {
839 : /* notify read-only warning to user */
840 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
841 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
842 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
843 : );
844 : }
845 0 : else if ( U8_ERROR_NONE != ctrl_err )
846 : {
847 0 : U8_LOG_ERROR_HEX( "update key/name failed:", ctrl_err );
848 : }
849 : }
850 : }
851 0 : break;
852 :
853 0 : case DATA_TABLE_RELATIONSHIP:
854 : {
855 : const char *const unchanged_text
856 0 : = data_relationship_get_name_const( &((*this_).private_relationship_cache) );
857 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
858 : {
859 : ctrl_classifier_controller_t *class_ctrl;
860 0 : class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
861 :
862 0 : ctrl_err = ctrl_classifier_controller_update_relationship_name( class_ctrl,
863 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
864 : text
865 : );
866 0 : if ( U8_ERROR_STRING_BUFFER_EXCEEDED == ctrl_err )
867 : {
868 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
869 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
870 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
871 : );
872 : }
873 0 : else if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
874 : {
875 : /* notify read-only warning to user */
876 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
877 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
878 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
879 : );
880 : }
881 0 : else if ( U8_ERROR_NONE != ctrl_err )
882 : {
883 0 : U8_LOG_ERROR_HEX( "update name failed:", ctrl_err );
884 : }
885 : }
886 : }
887 0 : break;
888 :
889 0 : case DATA_TABLE_DIAGRAMELEMENT:
890 : {
891 : /* (*this_).selected_object_id should not be of type DATA_TABLE_DIAGRAMELEMENT */
892 0 : U8_LOG_WARNING( "no object selected where name can be updated." );
893 : }
894 0 : break;
895 :
896 0 : case DATA_TABLE_DIAGRAM:
897 : {
898 : const char *const unchanged_text
899 0 : = data_diagram_get_name_const( &((*this_).private_diagram_cache) );
900 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
901 : {
902 : ctrl_diagram_controller_t *diag_ctrl;
903 0 : diag_ctrl = ctrl_controller_get_diagram_control_ptr ( (*this_).controller );
904 :
905 0 : ctrl_err = ctrl_diagram_controller_update_diagram_name( diag_ctrl,
906 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
907 : text
908 : );
909 0 : if ( U8_ERROR_STRING_BUFFER_EXCEEDED == ctrl_err )
910 : {
911 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
912 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
913 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
914 : );
915 : }
916 0 : else if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
917 : {
918 : /* notify read-only warning to user */
919 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
920 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
921 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
922 : );
923 : }
924 0 : else if ( U8_ERROR_NONE != ctrl_err )
925 : {
926 0 : U8_LOG_ERROR_HEX( "update name failed:", ctrl_err );
927 : }
928 : }
929 : }
930 0 : break;
931 :
932 0 : default:
933 : {
934 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
935 : }
936 0 : break;
937 : }
938 :
939 0 : U8_TRACE_END();
940 0 : }
941 :
942 0 : void gui_attributes_editor_private_stereotype_commit_changes ( gui_attributes_editor_t *this_ )
943 : {
944 0 : U8_TRACE_BEGIN();
945 :
946 : const char* text;
947 0 : GtkEntry *const stereotype_widget = GTK_ENTRY( (*this_).stereotype_entry );
948 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
949 0 : text = gtk_entry_buffer_get_text( stereotype_buf );
950 :
951 0 : U8_TRACE_INFO_STR( "text:", text );
952 :
953 0 : ctrl_classifier_controller_t *const class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
954 0 : ctrl_diagram_controller_t *const diag_ctrl = ctrl_controller_get_diagram_control_ptr ( (*this_).controller );
955 0 : u8_error_t ctrl_update_err = U8_ERROR_NONE;
956 0 : switch ( data_id_get_table( &((*this_).selected_object_id) ) )
957 : {
958 0 : case DATA_TABLE_VOID:
959 : {
960 : /* nothing to do */
961 0 : U8_TRACE_INFO( "no object selected where stereotype can be updated." );
962 : }
963 0 : break;
964 :
965 0 : case DATA_TABLE_CLASSIFIER:
966 : {
967 0 : const char *const unchanged_text = data_classifier_get_stereotype_const( &((*this_).private_classifier_cache) );
968 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
969 : {
970 0 : ctrl_update_err = ctrl_classifier_controller_update_classifier_stereotype( class_ctrl,
971 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
972 : text
973 : );
974 : }
975 : }
976 0 : break;
977 :
978 0 : case DATA_TABLE_FEATURE:
979 : {
980 0 : const char *const unchanged_text = data_feature_get_value_const( &((*this_).private_feature_cache) );
981 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
982 : {
983 0 : ctrl_update_err = ctrl_classifier_controller_update_feature_value( class_ctrl,
984 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
985 : text
986 : );
987 : }
988 : }
989 0 : break;
990 :
991 0 : case DATA_TABLE_RELATIONSHIP:
992 : {
993 0 : const char *const unchanged_text = data_relationship_get_stereotype_const( &((*this_).private_relationship_cache) );
994 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
995 : {
996 0 : ctrl_update_err = ctrl_classifier_controller_update_relationship_stereotype( class_ctrl,
997 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
998 : text
999 : );
1000 : }
1001 : }
1002 0 : break;
1003 :
1004 0 : case DATA_TABLE_DIAGRAMELEMENT:
1005 : {
1006 : /* (*this_).selected_object_id should not be of type DATA_TABLE_DIAGRAMELEMENT */
1007 0 : U8_LOG_WARNING( "no object selected where stereotype can be updated." );
1008 : }
1009 0 : break;
1010 :
1011 0 : case DATA_TABLE_DIAGRAM:
1012 : {
1013 0 : const char *const unchanged_text = data_diagram_get_stereotype_const( &((*this_).private_diagram_cache) );
1014 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
1015 : {
1016 0 : ctrl_update_err = ctrl_diagram_controller_update_diagram_stereotype( diag_ctrl,
1017 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1018 : text
1019 : );
1020 : }
1021 : }
1022 0 : break;
1023 :
1024 0 : default:
1025 : {
1026 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1027 : }
1028 0 : break;
1029 : }
1030 :
1031 : /* show warning to user in case of error: */
1032 0 : if ( U8_ERROR_STRING_BUFFER_EXCEEDED == ctrl_update_err )
1033 : {
1034 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1035 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1036 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
1037 : );
1038 : }
1039 0 : else if ( U8_ERROR_READ_ONLY_DB == ctrl_update_err )
1040 : {
1041 : /* notify read-only warning to user */
1042 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1043 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1044 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1045 : );
1046 : }
1047 0 : else if ( U8_ERROR_NONE != ctrl_update_err )
1048 : {
1049 0 : U8_LOG_ERROR_HEX( "update stereotype failed:", ctrl_update_err );
1050 : }
1051 :
1052 0 : U8_TRACE_END();
1053 0 : }
1054 :
1055 0 : void gui_attributes_editor_private_type_commit_changes ( gui_attributes_editor_t *this_, int obj_type )
1056 : {
1057 0 : U8_TRACE_BEGIN();
1058 :
1059 0 : U8_TRACE_INFO_INT( "obj_type:", obj_type );
1060 :
1061 : u8_error_t ctrl_err;
1062 0 : switch ( data_id_get_table( &((*this_).selected_object_id) ) )
1063 : {
1064 0 : case DATA_TABLE_VOID:
1065 : {
1066 : /* nothing to do */
1067 0 : U8_TRACE_INFO( "no object selected where type can be updated." );
1068 : }
1069 0 : break;
1070 :
1071 0 : case DATA_TABLE_CLASSIFIER:
1072 : {
1073 : const data_classifier_type_t unchanged_main_type
1074 0 : = data_classifier_get_main_type( &((*this_).private_classifier_cache) );
1075 0 : if ( obj_type != unchanged_main_type )
1076 : {
1077 : ctrl_classifier_controller_t *class_ctrl;
1078 0 : class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
1079 :
1080 0 : ctrl_err = ctrl_classifier_controller_update_classifier_main_type ( class_ctrl, data_id_get_row_id( &((*this_).selected_object_id) ), obj_type );
1081 0 : if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
1082 : {
1083 : /* notify read-only warning to user */
1084 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1085 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1086 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1087 : );
1088 : }
1089 0 : else if ( U8_ERROR_NONE != ctrl_err )
1090 : {
1091 0 : U8_LOG_ERROR_HEX( "update main type failed:", ctrl_err );
1092 : }
1093 : }
1094 : }
1095 0 : break;
1096 :
1097 0 : case DATA_TABLE_FEATURE:
1098 : {
1099 : const data_feature_type_t unchanged_main_type
1100 0 : = data_feature_get_main_type( &((*this_).private_feature_cache) );
1101 0 : if ( obj_type != unchanged_main_type )
1102 : {
1103 : ctrl_classifier_controller_t *class_ctrl;
1104 0 : class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
1105 :
1106 0 : ctrl_err = ctrl_classifier_controller_update_feature_main_type ( class_ctrl, data_id_get_row_id( &((*this_).selected_object_id) ), obj_type );
1107 0 : if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
1108 : {
1109 : /* notify read-only warning to user */
1110 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1111 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1112 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1113 : );
1114 : }
1115 0 : else if ( U8_ERROR_NONE != ctrl_err )
1116 : {
1117 0 : U8_LOG_ERROR_HEX( "update main type failed:", ctrl_err );
1118 : }
1119 : }
1120 : }
1121 0 : break;
1122 :
1123 0 : case DATA_TABLE_RELATIONSHIP:
1124 : {
1125 : const data_relationship_type_t unchanged_main_type
1126 0 : = data_relationship_get_main_type( &((*this_).private_relationship_cache) );
1127 0 : if ( obj_type != unchanged_main_type )
1128 : {
1129 : ctrl_classifier_controller_t *class_ctrl;
1130 0 : class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
1131 :
1132 0 : ctrl_err = ctrl_classifier_controller_update_relationship_main_type ( class_ctrl, data_id_get_row_id( &((*this_).selected_object_id) ), obj_type );
1133 0 : if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
1134 : {
1135 : /* notify read-only warning to user */
1136 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1137 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1138 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1139 : );
1140 : }
1141 0 : else if ( U8_ERROR_NONE != ctrl_err )
1142 : {
1143 0 : U8_LOG_ERROR_HEX( "update main type failed:", ctrl_err );
1144 : }
1145 : }
1146 : }
1147 0 : break;
1148 :
1149 0 : case DATA_TABLE_DIAGRAMELEMENT:
1150 : {
1151 : /* (*this_).selected_object_id should not be of type DATA_TABLE_DIAGRAMELEMENT */
1152 0 : U8_LOG_WARNING( "no object selected where type can be updated." );
1153 : }
1154 0 : break;
1155 :
1156 0 : case DATA_TABLE_DIAGRAM:
1157 : {
1158 : const data_diagram_type_t unchanged_type
1159 0 : = data_diagram_get_diagram_type( &((*this_).private_diagram_cache) );
1160 0 : if ( obj_type != unchanged_type )
1161 : {
1162 : ctrl_diagram_controller_t *diag_ctrl;
1163 0 : diag_ctrl = ctrl_controller_get_diagram_control_ptr ( (*this_).controller );
1164 : data_stat_t stat;
1165 0 : data_stat_init(&stat);
1166 0 : ctrl_err = ctrl_diagram_controller_update_diagram_type ( diag_ctrl,
1167 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1168 : obj_type,
1169 : &stat
1170 : );
1171 0 : if ( U8_ERROR_READ_ONLY_DB == ctrl_err )
1172 : {
1173 : /* notify read-only warning to user */
1174 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1175 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1176 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1177 : );
1178 : }
1179 : else
1180 : {
1181 0 : if ( U8_ERROR_NONE != ctrl_err )
1182 : {
1183 0 : U8_LOG_ERROR_HEX( "update type failed:", ctrl_err );
1184 : }
1185 0 : gui_simple_message_to_user_show_message_with_stat ( (*this_).message_to_user,
1186 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
1187 : GUI_SIMPLE_MESSAGE_CONTENT_TYPE_CHANGE,
1188 : &stat
1189 : );
1190 : }
1191 0 : data_stat_destroy(&stat);
1192 : }
1193 : }
1194 0 : break;
1195 :
1196 0 : default:
1197 : {
1198 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1199 : }
1200 0 : break;
1201 : }
1202 :
1203 0 : U8_TRACE_END();
1204 0 : }
1205 :
1206 0 : void gui_attributes_editor_private_description_commit_changes ( gui_attributes_editor_t *this_ )
1207 : {
1208 0 : U8_TRACE_BEGIN();
1209 : GtkTextView *description_widget;
1210 : GtkTextBuffer *buffer;
1211 0 : description_widget = GTK_TEXT_VIEW( (*this_).description_text_view );
1212 0 : buffer = gtk_text_view_get_buffer ( description_widget );
1213 :
1214 : GtkTextIter start;
1215 : GtkTextIter end;
1216 0 : gtk_text_buffer_get_start_iter ( buffer, &start );
1217 0 : gtk_text_buffer_get_end_iter ( buffer, &end );
1218 :
1219 : const char* text;
1220 0 : text = gtk_text_buffer_get_text ( buffer, &start, &end, false );
1221 :
1222 0 : U8_TRACE_INFO_STR( "text:", text );
1223 :
1224 0 : ctrl_classifier_controller_t *const class_ctrl = ctrl_controller_get_classifier_control_ptr ( (*this_).controller );
1225 0 : ctrl_diagram_controller_t *const diag_ctrl = ctrl_controller_get_diagram_control_ptr ( (*this_).controller );
1226 0 : u8_error_t ctrl_update_err = U8_ERROR_NONE;
1227 0 : switch ( data_id_get_table( &((*this_).selected_object_id) ) )
1228 : {
1229 0 : case DATA_TABLE_VOID:
1230 : {
1231 : /* nothing to do */
1232 0 : U8_TRACE_INFO( "no object selected where description can be updated." );
1233 : }
1234 0 : break;
1235 :
1236 0 : case DATA_TABLE_CLASSIFIER:
1237 : {
1238 : const char *const unchanged_text
1239 0 : = data_classifier_get_description_const( &((*this_).private_classifier_cache) );
1240 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
1241 : {
1242 0 : ctrl_update_err = ctrl_classifier_controller_update_classifier_description( class_ctrl,
1243 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1244 : text
1245 : );
1246 :
1247 : /* report errors in svg images in description in case of stereotype: */
1248 : const data_classifier_type_t main_type
1249 0 : = data_classifier_get_main_type( &((*this_).private_classifier_cache) );
1250 0 : if ( main_type == DATA_CLASSIFIER_TYPE_STEREOTYPE )
1251 : {
1252 : geometry_rectangle_t view_rect;
1253 : u8_error_info_t svg_err_info;
1254 : draw_stereotype_image_t svg_parser;
1255 0 : draw_stereotype_image_init( &svg_parser );
1256 : const u8_error_t svg_err
1257 0 : = draw_stereotype_image_parse_svg_xml( &svg_parser,
1258 : text, /* drawing_directives */
1259 : &view_rect,
1260 : &svg_err_info
1261 : );
1262 0 : draw_stereotype_image_destroy( &svg_parser );
1263 0 : if ( svg_err == U8_ERROR_NOT_FOUND )
1264 : {
1265 0 : U8_TRACE_INFO( "the stereotype has no image." );
1266 : }
1267 0 : else if ( svg_err != U8_ERROR_NONE )
1268 : {
1269 0 : gui_simple_message_to_user_show_error_info( (*this_).message_to_user, &svg_err_info );
1270 : }
1271 : }
1272 : }
1273 : }
1274 0 : break;
1275 :
1276 0 : case DATA_TABLE_FEATURE:
1277 : {
1278 : const char *const unchanged_text
1279 0 : = data_feature_get_description_const( &((*this_).private_feature_cache) );
1280 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
1281 : {
1282 0 : ctrl_update_err = ctrl_classifier_controller_update_feature_description( class_ctrl,
1283 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1284 : text
1285 : );
1286 : }
1287 : }
1288 0 : break;
1289 :
1290 0 : case DATA_TABLE_RELATIONSHIP:
1291 : {
1292 : const char *const unchanged_text
1293 0 : = data_relationship_get_description_const( &((*this_).private_relationship_cache) );
1294 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
1295 : {
1296 0 : ctrl_update_err = ctrl_classifier_controller_update_relationship_description( class_ctrl,
1297 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1298 : text
1299 : );
1300 : }
1301 : }
1302 0 : break;
1303 :
1304 0 : case DATA_TABLE_DIAGRAMELEMENT:
1305 : {
1306 : /* (*this_).selected_object_id should not be of type DATA_TABLE_DIAGRAMELEMENT */
1307 0 : U8_LOG_WARNING( "no object selected where description can be updated." );
1308 : }
1309 0 : break;
1310 :
1311 0 : case DATA_TABLE_DIAGRAM:
1312 : {
1313 : const char *const unchanged_text
1314 0 : = data_diagram_get_description_const( &((*this_).private_diagram_cache) );
1315 0 : if ( ! utf8string_equals_str( text, unchanged_text ) )
1316 : {
1317 0 : ctrl_update_err = ctrl_diagram_controller_update_diagram_description( diag_ctrl,
1318 0 : data_id_get_row_id( &((*this_).selected_object_id) ),
1319 : text
1320 : );
1321 : }
1322 : }
1323 0 : break;
1324 :
1325 0 : default:
1326 : {
1327 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1328 : }
1329 0 : break;
1330 : }
1331 :
1332 : /* show warning to user in case of error: */
1333 0 : if ( U8_ERROR_STRING_BUFFER_EXCEEDED == ctrl_update_err )
1334 : {
1335 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1336 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1337 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
1338 : );
1339 : }
1340 0 : else if ( U8_ERROR_READ_ONLY_DB == ctrl_update_err )
1341 : {
1342 : /* notify read-only warning to user */
1343 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
1344 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
1345 : GUI_SIMPLE_MESSAGE_CONTENT_DB_IS_READ_ONLY
1346 : );
1347 : }
1348 0 : else if ( U8_ERROR_NONE != ctrl_update_err )
1349 : {
1350 0 : U8_LOG_ERROR_HEX( "update description failed:", ctrl_update_err );
1351 : }
1352 :
1353 0 : U8_TRACE_END();
1354 0 : }
1355 :
1356 0 : void gui_attributes_editor_private_id_update_view ( gui_attributes_editor_t *this_ )
1357 : {
1358 0 : U8_TRACE_BEGIN();
1359 : GtkLabel *id_widget;
1360 0 : id_widget = GTK_LABEL( (*this_).id_label );
1361 :
1362 : char data_id_string_buf[DATA_ID_MAX_UTF8STRING_SIZE];
1363 0 : utf8stringbuf_t data_id_string = UTF8STRINGBUF( data_id_string_buf );
1364 0 : utf8stringbuf_clear( data_id_string );
1365 0 : if ( data_id_is_valid( &((*this_).selected_object_id) ) )
1366 : {
1367 0 : utf8error_t str_err = data_id_to_utf8stringbuf ( &((*this_).selected_object_id), data_id_string );
1368 0 : if ( UTF8ERROR_SUCCESS != str_err )
1369 : {
1370 0 : U8_LOG_ERROR_HEX( "data_id_to_utf8stringbuf failed:", str_err );
1371 : }
1372 : }
1373 0 : gtk_label_set_text ( id_widget, utf8stringbuf_get_string( data_id_string ) );
1374 :
1375 0 : U8_TRACE_END();
1376 0 : }
1377 :
1378 0 : void gui_attributes_editor_private_name_update_view ( gui_attributes_editor_t *this_ )
1379 : {
1380 0 : U8_TRACE_BEGIN();
1381 : GtkEntry *name_widget;
1382 0 : name_widget = GTK_ENTRY( (*this_).name_entry );
1383 :
1384 0 : switch ( data_id_get_table( &((*this_).selected_object_id )) )
1385 : {
1386 0 : case DATA_TABLE_VOID:
1387 : {
1388 : /* prevent that a user accitentially enters text to a non-existing object */
1389 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), FALSE );
1390 : }
1391 0 : break;
1392 :
1393 0 : case DATA_TABLE_CLASSIFIER:
1394 : {
1395 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), TRUE );
1396 :
1397 : const char *const text
1398 0 : = data_classifier_get_name_const( &((*this_).private_classifier_cache) );
1399 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
1400 0 : gtk_entry_buffer_set_text( name_buf, text, -1 /* = n_chars */ );
1401 : }
1402 0 : break;
1403 :
1404 0 : case DATA_TABLE_FEATURE:
1405 : {
1406 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), TRUE );
1407 :
1408 : const char *const text
1409 0 : = data_feature_get_key_const( &((*this_).private_feature_cache) );
1410 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
1411 0 : gtk_entry_buffer_set_text( name_buf, text, -1 /* = n_chars */ );
1412 : }
1413 0 : break;
1414 :
1415 0 : case DATA_TABLE_RELATIONSHIP:
1416 : {
1417 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), TRUE );
1418 :
1419 : const char *const text
1420 0 : = data_relationship_get_name_const( &((*this_).private_relationship_cache) );
1421 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
1422 0 : gtk_entry_buffer_set_text( name_buf, text, -1 /* = n_chars */ );
1423 : }
1424 0 : break;
1425 :
1426 0 : case DATA_TABLE_DIAGRAMELEMENT:
1427 : {
1428 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), FALSE );
1429 : }
1430 0 : break;
1431 :
1432 0 : case DATA_TABLE_DIAGRAM:
1433 : {
1434 0 : gtk_widget_set_visible( GTK_WIDGET ( name_widget ), TRUE );
1435 :
1436 : const char *const text
1437 0 : = data_diagram_get_name_const( &((*this_).private_diagram_cache) );
1438 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
1439 0 : gtk_entry_buffer_set_text( name_buf, text, -1 /* = n_chars */ );
1440 : }
1441 0 : break;
1442 :
1443 0 : default:
1444 : {
1445 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1446 0 : GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( name_widget );
1447 0 : gtk_entry_buffer_set_text( name_buf, "", 0 /* = n_chars */ );
1448 : }
1449 0 : break;
1450 : }
1451 :
1452 0 : U8_TRACE_END();
1453 0 : }
1454 :
1455 0 : void gui_attributes_editor_private_stereotype_update_view ( gui_attributes_editor_t *this_ )
1456 : {
1457 0 : U8_TRACE_BEGIN();
1458 : GtkEntry *stereotype_widget;
1459 0 : stereotype_widget = GTK_ENTRY( (*this_).stereotype_entry );
1460 :
1461 0 : switch ( data_id_get_table( &((*this_).selected_object_id ) ) )
1462 : {
1463 0 : case DATA_TABLE_VOID:
1464 : {
1465 : /* prevent that a user accitentially enters text to a non-existing object */
1466 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), FALSE );
1467 : /*gtk_entry_set_text( GTK_ENTRY ( stereotype_widget ), " -- n/a --" );*/
1468 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), false );
1469 : }
1470 0 : break;
1471 :
1472 0 : case DATA_TABLE_CLASSIFIER:
1473 : {
1474 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), TRUE );
1475 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), true );
1476 :
1477 : const char *const text
1478 0 : = data_classifier_get_stereotype_const( &((*this_).private_classifier_cache) );
1479 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
1480 0 : gtk_entry_buffer_set_text( stereotype_buf, text, -1 /* = n_chars */ );
1481 : }
1482 0 : break;
1483 :
1484 0 : case DATA_TABLE_FEATURE:
1485 : {
1486 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), TRUE );
1487 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), true );
1488 :
1489 : const char *const text
1490 0 : = data_feature_get_value_const( &((*this_).private_feature_cache) );
1491 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
1492 0 : gtk_entry_buffer_set_text( stereotype_buf, text, -1 /* = n_chars */ );
1493 : }
1494 0 : break;
1495 :
1496 0 : case DATA_TABLE_RELATIONSHIP:
1497 : {
1498 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), TRUE );
1499 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), true );
1500 :
1501 : const char *const text
1502 0 : = data_relationship_get_stereotype_const( &((*this_).private_relationship_cache) );
1503 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
1504 0 : gtk_entry_buffer_set_text( stereotype_buf, text, -1 /* = n_chars */ );
1505 : }
1506 0 : break;
1507 :
1508 0 : case DATA_TABLE_DIAGRAMELEMENT:
1509 : {
1510 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), FALSE );
1511 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), false );
1512 : }
1513 0 : break;
1514 :
1515 0 : case DATA_TABLE_DIAGRAM:
1516 : {
1517 0 : gtk_widget_set_visible( GTK_WIDGET ( stereotype_widget ), TRUE );
1518 0 : gtk_editable_set_editable ( GTK_EDITABLE ( stereotype_widget ), true );
1519 :
1520 : const char *const text
1521 0 : = data_diagram_get_stereotype_const( &((*this_).private_diagram_cache) );
1522 0 : GtkEntryBuffer *const stereotype_buf = gtk_entry_get_buffer( stereotype_widget );
1523 0 : gtk_entry_buffer_set_text( stereotype_buf, text, -1 /* = n_chars */ );
1524 : }
1525 0 : break;
1526 :
1527 0 : default:
1528 : {
1529 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1530 : }
1531 0 : break;
1532 : }
1533 :
1534 0 : U8_TRACE_END();
1535 0 : }
1536 :
1537 0 : void gui_attributes_editor_private_type_update_view ( gui_attributes_editor_t *this_ )
1538 : {
1539 0 : U8_TRACE_BEGIN();
1540 0 : GtkDropDown *type_widget = (*this_).type_dropdown;
1541 :
1542 0 : switch ( data_id_get_table( &((*this_).selected_object_id ) ) )
1543 : {
1544 0 : case DATA_TABLE_VOID:
1545 : {
1546 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), FALSE );
1547 0 : GListStore *const undef_type_list = gui_type_resource_list_get_undef( &((*this_).type_lists) );
1548 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( undef_type_list ) );
1549 :
1550 : /* hide icon grid: */
1551 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1552 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1553 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1554 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1555 : }
1556 0 : break;
1557 :
1558 0 : case DATA_TABLE_CLASSIFIER:
1559 : {
1560 0 : const data_classifier_type_t class_type = data_classifier_get_main_type( &((*this_).private_classifier_cache) );
1561 0 : GListStore *const classifier_type_list = gui_type_resource_list_get_classifiers( &((*this_).type_lists) );
1562 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( classifier_type_list ) );
1563 : guint selected_pos;
1564 0 : gui_type_resource_init_classifier( (*this_).temp_search_me, class_type, "", NULL ); /* type, name, icon */
1565 0 : const gboolean found = g_list_store_find_with_equal_func( classifier_type_list,
1566 0 : (*this_).temp_search_me,
1567 : (GEqualFunc)&gui_type_resource_equal,
1568 : &selected_pos
1569 : );
1570 0 : if ( found )
1571 : {
1572 0 : gtk_drop_down_set_selected( (*this_).type_dropdown, selected_pos );
1573 : }
1574 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), TRUE );
1575 :
1576 : /* show classifier icon grid: */
1577 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1578 0 : gtk_widget_set_visible( (*this_).type_clas_grid, TRUE );
1579 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1580 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1581 : }
1582 0 : break;
1583 :
1584 0 : case DATA_TABLE_FEATURE:
1585 : {
1586 0 : const data_feature_type_t feature_type = data_feature_get_main_type( &((*this_).private_feature_cache) );
1587 0 : if ( DATA_FEATURE_TYPE_LIFELINE == feature_type )
1588 : {
1589 0 : GListStore *const lifeline_type_list = gui_type_resource_list_get_feature_lifeline( &((*this_).type_lists) );
1590 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( lifeline_type_list ) );
1591 : guint selected_pos;
1592 0 : gui_type_resource_init_feature( (*this_).temp_search_me, feature_type, "", NULL ); /* type, name, icon */
1593 0 : const gboolean found = g_list_store_find_with_equal_func( lifeline_type_list,
1594 0 : (*this_).temp_search_me,
1595 : (GEqualFunc)&gui_type_resource_equal,
1596 : &selected_pos
1597 : );
1598 0 : if ( found )
1599 : {
1600 0 : gtk_drop_down_set_selected( (*this_).type_dropdown, selected_pos );
1601 : }
1602 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), TRUE );
1603 :
1604 : /* hide icon grid: */
1605 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1606 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1607 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1608 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1609 : }
1610 : else
1611 : {
1612 0 : GListStore *const feature_type_list = gui_type_resource_list_get_features( &((*this_).type_lists) );
1613 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( feature_type_list ) );
1614 : guint selected_pos;
1615 0 : gui_type_resource_init_feature( (*this_).temp_search_me, feature_type, "", NULL ); /* type, name, icon */
1616 0 : const gboolean found = g_list_store_find_with_equal_func( feature_type_list,
1617 0 : (*this_).temp_search_me,
1618 : (GEqualFunc)&gui_type_resource_equal,
1619 : &selected_pos
1620 : );
1621 0 : if ( found )
1622 : {
1623 0 : gtk_drop_down_set_selected( (*this_).type_dropdown, selected_pos );
1624 : }
1625 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), TRUE );
1626 :
1627 : /* show feature icon grid: */
1628 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1629 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1630 0 : gtk_widget_set_visible( (*this_).type_feat_grid, TRUE );
1631 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1632 : }
1633 : }
1634 0 : break;
1635 :
1636 0 : case DATA_TABLE_RELATIONSHIP:
1637 : {
1638 : const data_relationship_type_t relationship_type
1639 0 : = data_relationship_get_main_type( &((*this_).private_relationship_cache) );
1640 0 : GListStore *const relationship_type_list = gui_type_resource_list_get_relationships( &((*this_).type_lists) );
1641 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( relationship_type_list ) );
1642 : guint selected_pos;
1643 0 : gui_type_resource_init_relationship( (*this_).temp_search_me, relationship_type, "", NULL ); /* type, name, icon */
1644 0 : const gboolean found = g_list_store_find_with_equal_func( relationship_type_list,
1645 0 : (*this_).temp_search_me,
1646 : (GEqualFunc)&gui_type_resource_equal,
1647 : &selected_pos
1648 : );
1649 0 : if ( found )
1650 : {
1651 0 : gtk_drop_down_set_selected( (*this_).type_dropdown, selected_pos );
1652 : }
1653 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), TRUE );
1654 :
1655 : /* show relationship icon grid: */
1656 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1657 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1658 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1659 0 : gtk_widget_set_visible( (*this_).type_rel_grid, TRUE );
1660 : }
1661 0 : break;
1662 :
1663 0 : case DATA_TABLE_DIAGRAMELEMENT:
1664 : {
1665 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), FALSE );
1666 0 : GListStore *const undef_type_list = gui_type_resource_list_get_undef( &((*this_).type_lists) );
1667 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( undef_type_list ) );
1668 :
1669 : /* hide icon grid: */
1670 0 : gtk_widget_set_visible( (*this_).type_diag_grid, FALSE );
1671 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1672 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1673 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1674 : }
1675 0 : break;
1676 :
1677 0 : case DATA_TABLE_DIAGRAM:
1678 : {
1679 0 : const data_diagram_type_t diag_type = data_diagram_get_diagram_type( &((*this_).private_diagram_cache) );
1680 0 : GListStore *const diagram_type_list = gui_type_resource_list_get_diagrams( &((*this_).type_lists) );
1681 0 : gtk_drop_down_set_model( (*this_).type_dropdown, G_LIST_MODEL( diagram_type_list ) );
1682 : guint selected_pos;
1683 0 : gui_type_resource_init_diagram( (*this_).temp_search_me, diag_type, "", NULL ); /* type, name, icon */
1684 0 : const gboolean found = g_list_store_find_with_equal_func( diagram_type_list,
1685 0 : (*this_).temp_search_me,
1686 : (GEqualFunc)&gui_type_resource_equal,
1687 : &selected_pos
1688 : );
1689 0 : if ( found )
1690 : {
1691 0 : gtk_drop_down_set_selected( (*this_).type_dropdown, selected_pos );
1692 : }
1693 0 : gtk_widget_set_visible( GTK_WIDGET ( type_widget ), TRUE );
1694 :
1695 : /* show diagram icon grid: */
1696 0 : gtk_widget_set_visible( (*this_).type_diag_grid, TRUE );
1697 0 : gtk_widget_set_visible( (*this_).type_clas_grid, FALSE );
1698 0 : gtk_widget_set_visible( (*this_).type_feat_grid, FALSE );
1699 0 : gtk_widget_set_visible( (*this_).type_rel_grid, FALSE );
1700 : }
1701 0 : break;
1702 :
1703 0 : default:
1704 : {
1705 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1706 : }
1707 0 : break;
1708 : }
1709 :
1710 0 : U8_TRACE_END();
1711 0 : }
1712 :
1713 0 : void gui_attributes_editor_private_description_update_view ( gui_attributes_editor_t *this_ )
1714 : {
1715 0 : U8_TRACE_BEGIN();
1716 :
1717 : GtkTextView *description_widget;
1718 : GtkTextBuffer *buffer;
1719 0 : description_widget = GTK_TEXT_VIEW( (*this_).description_text_view );
1720 0 : buffer = gtk_text_view_get_buffer ( GTK_TEXT_VIEW( description_widget ) );
1721 :
1722 0 : switch ( data_id_get_table( &((*this_).selected_object_id ) ) )
1723 : {
1724 0 : case DATA_TABLE_VOID:
1725 : {
1726 : /* prevent that a user accitentially enters text to a non-existing object */
1727 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), FALSE );
1728 : }
1729 0 : break;
1730 :
1731 0 : case DATA_TABLE_CLASSIFIER:
1732 : {
1733 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), TRUE );
1734 :
1735 : const char* text;
1736 0 : text = data_classifier_get_description_const( &((*this_).private_classifier_cache) );
1737 0 : gtk_text_buffer_set_text ( buffer, text, -1 /*len*/ );
1738 : }
1739 0 : break;
1740 :
1741 0 : case DATA_TABLE_FEATURE:
1742 : {
1743 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), TRUE );
1744 :
1745 : const char* text;
1746 0 : text = data_feature_get_description_const( &((*this_).private_feature_cache) );
1747 0 : gtk_text_buffer_set_text ( buffer, text, -1 /*len*/ );
1748 : }
1749 0 : break;
1750 :
1751 0 : case DATA_TABLE_RELATIONSHIP:
1752 : {
1753 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), TRUE );
1754 :
1755 : const char* text;
1756 0 : text = data_relationship_get_description_const( &((*this_).private_relationship_cache) );
1757 0 : gtk_text_buffer_set_text ( buffer, text, -1 /*len*/ );
1758 : }
1759 0 : break;
1760 :
1761 0 : case DATA_TABLE_DIAGRAMELEMENT:
1762 : {
1763 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), FALSE );
1764 : }
1765 0 : break;
1766 :
1767 0 : case DATA_TABLE_DIAGRAM:
1768 : {
1769 0 : gtk_widget_set_visible( GTK_WIDGET ( description_widget ), TRUE );
1770 :
1771 : const char* text;
1772 0 : text = data_diagram_get_description_const( &((*this_).private_diagram_cache) );
1773 0 : gtk_text_buffer_set_text ( buffer, text, -1 /*len*/ );
1774 : }
1775 0 : break;
1776 :
1777 0 : default:
1778 : {
1779 0 : U8_LOG_ERROR( "invalid data in data_id_t." );
1780 : }
1781 0 : break;
1782 : }
1783 :
1784 0 : U8_TRACE_END();
1785 0 : }
1786 :
1787 :
1788 : /*
1789 : Copyright 2016-2024 Andreas Warnke
1790 :
1791 : Licensed under the Apache License, Version 2.0 (the "License");
1792 : you may not use this file except in compliance with the License.
1793 : You may obtain a copy of the License at
1794 :
1795 : http://www.apache.org/licenses/LICENSE-2.0
1796 :
1797 : Unless required by applicable law or agreed to in writing, software
1798 : distributed under the License is distributed on an "AS IS" BASIS,
1799 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1800 : See the License for the specific language governing permissions and
1801 : limitations under the License.
1802 : */
|