Fix #8009 - remove libgda dependancy
[roobuilder] / src / Builder4 / DialogTemplateSelect.vala
1 static DialogTemplateSelect  _DialogTemplateSelect;
2
3 public class DialogTemplateSelect : Object
4 {
5         public Gtk.Dialog el;
6         private DialogTemplateSelect  _this;
7
8         public static DialogTemplateSelect singleton()
9         {
10                 if (_DialogTemplateSelect == null) {
11                     _DialogTemplateSelect= new DialogTemplateSelect();
12                 }
13                 return _DialogTemplateSelect;
14         }
15         public Xcls_combo combo;
16         public Xcls_cellrenderer cellrenderer;
17         public Xcls_model model;
18         public Xcls_dbcombo dbcombo;
19         public Xcls_dbcellrenderer dbcellrenderer;
20         public Xcls_dbmodel dbmodel;
21
22                 // my vars (def)
23         public Xcls_MainWindow window;
24         public signal void complete (JsRender.Node? node);
25         public Palete.Palete palete;
26         public JsRender.Node node;
27         public Project.Project project;
28
29         // ctor
30         public DialogTemplateSelect()
31         {
32                 _this = this;
33                 this.el = new Gtk.Dialog();
34
35                 // my vars (dec)
36
37                 // set gobject values
38                 this.el.title = "Add an Object";
39                 this.el.default_height = 200;
40                 this.el.default_width = 400;
41                 this.el.modal = true;
42                 var child_1 = new Xcls_Box1( _this );
43                 child_1.ref();
44                 this.el.get_content_area().append ( child_1.el  );
45                 var child_2 = new Xcls_Button12( _this );
46                 child_2.ref();
47                 this.el.add_action_widget ( child_2.el , 0 );
48                 var child_3 = new Xcls_Button13( _this );
49                 child_3.ref();
50                 this.el.add_action_widget ( child_3.el , 1 );
51                 var child_4 = new Xcls_Button14( _this );
52                 child_4.ref();
53                 this.el.add_action_widget ( child_4.el , 2 );
54
55                 //listeners
56                 this.el.close_request.connect( ( ) => {
57                 
58                  this.el.hide();
59                     return true;;
60                 });
61                 this.el.response.connect( (res) => {
62                 
63                         //var node = _this.node;
64                         //var project = _this.project;
65                         return;
66                    /*
67                    
68                    if (this.plugin == null) {
69                            this.plugin = new Xcls_DialogPluginWebkit();
70                            this.plugin.complete.connect((json_str) => {
71                                         print("json_str = %s\n", json_str);
72                             if (json_str.length < 1) {
73                                                 this.complete(_this.node);
74                                                 return; 
75                             }
76                             var pa = new Json.Parser();
77                             try {
78                 
79                                         pa.load_from_data(json_str);
80                                         } catch(Error e) {
81                                              this.complete(node);
82                                         return; // 1 = just add it..
83                                 }
84                                 var new_node = pa.get_root();
85                                 
86                                         if (new_node.get_node_type () != Json.NodeType.OBJECT) {
87                                                  this.complete(node);
88                                                                 return; 
89                                         }
90                                         var obj = new_node.get_object ();
91                 
92                                         var ret = new JsRender.Node();
93                 
94                                         ret.loadFromJson(obj, 1);
95                                         this.complete(ret);
96                                 });
97                   
98                    }
99                    
100                    
101                      
102                         
103                      this.el.hide();    
104                     //var ix = _this.combo.el.get_active();
105                     if (res < 1 ) {
106                         this.complete(null);
107                         return; // 0 = cancel.
108                     }
109                     if (res < 2 ) {
110                         this.complete(node);
111                         return; // 1 = just add it..
112                     }
113                     
114                     
115                     // have they selected a table??
116                     
117                    Gtk.TreeIter iter; 
118                     Value vfname;   
119                     if (_this.dbcombo.el.get_active_iter (out iter)) {    
120                          this.dbmodel.el.get_value (iter, 0, out vfname);
121                          if (((string)vfname).length > 0 && this.plugin.has_plugin(node.fqn())) {
122                             this.plugin.showIt(this.window.el, project, node.fqn(), (string)vfname);
123                             return;
124                         }
125                             this.complete(node);
126                          return; // 1 = just add it..
127                          
128                         
129                     }
130                 
131                     if (!_this.combo.el.get_active_iter (out iter)) {
132                 
133                          this.complete(node);
134                         return; // 1 = just add it../ nothing selected...
135                     }
136                    
137                     this.model.el.get_value (iter, 0, out vfname);
138                     
139                      this.complete(this.palete.loadTemplate((string)vfname));
140                       return; // 1 = just add it..
141                   
142                 */
143                 });
144         }
145
146         // user defined functions
147         public void showIt (
148                 Xcls_MainWindow mwindow, 
149                 Palete.Palete pal, 
150                  JsRender.Node node, 
151                  Project.Project project
152          ) {
153         
154                 this.el.show();
155         
156                 var opts = pal.listTemplates(node);
157                 if (opts.length() < 1) {
158                 this.el.hide();
159                         this.complete(node);
160                         return; 
161                 }
162                 this.el.set_transient_for( mwindow.el);
163         
164                 //opts.unshift({ path: '' , name :'Just add Element' });
165                 _this.model.loadData(opts);
166                 _this.combo.el.set_active(-1);
167         
168          /*
169                 var db =  new Palete.RooDatabase.from_project((Project.Roo) project);
170                 _this.dbmodel.loadData(db.readTablesGee());
171         
172         */
173                 _this.dbcombo.el.set_active(-1);
174          
175                 this.window = mwindow;
176                 this.palete = pal;
177                 this.node = node;
178                 this.project = project;
179            
180         }
181         public class Xcls_Box1 : Object
182         {
183                 public Gtk.Box el;
184                 private DialogTemplateSelect  _this;
185
186
187                         // my vars (def)
188
189                 // ctor
190                 public Xcls_Box1(DialogTemplateSelect _owner )
191                 {
192                         _this = _owner;
193                         this.el = new Gtk.Box( Gtk.Orientation.VERTICAL, 0 );
194
195                         // my vars (dec)
196
197                         // set gobject values
198                         var child_1 = new Xcls_Box2( _this );
199                         child_1.ref();
200                         this.el.append ( child_1.el  );
201                         var child_2 = new Xcls_Box7( _this );
202                         child_2.ref();
203                         this.el.append ( child_2.el  );
204                 }
205
206                 // user defined functions
207         }
208         public class Xcls_Box2 : Object
209         {
210                 public Gtk.Box el;
211                 private DialogTemplateSelect  _this;
212
213
214                         // my vars (def)
215
216                 // ctor
217                 public Xcls_Box2(DialogTemplateSelect _owner )
218                 {
219                         _this = _owner;
220                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
221
222                         // my vars (dec)
223
224                         // set gobject values
225                         this.el.margin_end = 3;
226                         this.el.margin_start = 3;
227                         var child_1 = new Xcls_Label3( _this );
228                         child_1.ref();
229                         this.el.append ( child_1.el  );
230                         new Xcls_combo( _this );
231                         this.el.append ( _this.combo.el  );
232                 }
233
234                 // user defined functions
235         }
236         public class Xcls_Label3 : Object
237         {
238                 public Gtk.Label el;
239                 private DialogTemplateSelect  _this;
240
241
242                         // my vars (def)
243
244                 // ctor
245                 public Xcls_Label3(DialogTemplateSelect _owner )
246                 {
247                         _this = _owner;
248                         this.el = new Gtk.Label( "Select Template : " );
249
250                         // my vars (dec)
251
252                         // set gobject values
253                 }
254
255                 // user defined functions
256         }
257
258         public class Xcls_combo : Object
259         {
260                 public Gtk.ComboBox el;
261                 private DialogTemplateSelect  _this;
262
263
264                         // my vars (def)
265
266                 // ctor
267                 public Xcls_combo(DialogTemplateSelect _owner )
268                 {
269                         _this = _owner;
270                         _this.combo = this;
271                         this.el = new Gtk.ComboBox();
272
273                         // my vars (dec)
274
275                         // set gobject values
276                         new Xcls_cellrenderer( _this );
277                         this.el.pack_start ( _this.cellrenderer.el , true );
278                         new Xcls_model( _this );
279                         this.el.set_model ( _this.model.el  );
280
281                         // init method
282
283                         this.el.add_attribute(_this.cellrenderer.el , "markup", 1 );
284                 }
285
286                 // user defined functions
287         }
288         public class Xcls_cellrenderer : Object
289         {
290                 public Gtk.CellRendererText el;
291                 private DialogTemplateSelect  _this;
292
293
294                         // my vars (def)
295
296                 // ctor
297                 public Xcls_cellrenderer(DialogTemplateSelect _owner )
298                 {
299                         _this = _owner;
300                         _this.cellrenderer = this;
301                         this.el = new Gtk.CellRendererText();
302
303                         // my vars (dec)
304
305                         // set gobject values
306                 }
307
308                 // user defined functions
309         }
310
311         public class Xcls_model : Object
312         {
313                 public Gtk.ListStore el;
314                 private DialogTemplateSelect  _this;
315
316
317                         // my vars (def)
318
319                 // ctor
320                 public Xcls_model(DialogTemplateSelect _owner )
321                 {
322                         _this = _owner;
323                         _this.model = this;
324                         this.el = new Gtk.ListStore.newv(  { typeof(string),typeof(string) }  );
325
326                         // my vars (dec)
327
328                         // set gobject values
329                 }
330
331                 // user defined functions
332                 public void loadData (GLib.List<string> data) {
333                     this.el.clear();                                    
334                     Gtk.TreeIter iter;
335                     var el = this.el;
336                     
337                    /// el.append(out iter);
338                     
339                      
340                    // el.set_value(iter, 0, "");
341                    // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
342                     
343                     for (var i = 0; i < data.length();i++) {
344                     
345                 
346                         el.append(out iter);
347                         var str = data.nth_data(i);
348                         var fn = Path.get_basename (str);
349                         fn.replace(".json", "");
350                         
351                         el.set_value(iter, 0, str);
352                         el.set_value(iter, 1, fn);
353                         
354                     }
355                     this.el.set_sort_column_id(1, Gtk.SortType.ASCENDING);          
356                                                      
357                 }
358         }
359
360
361
362         public class Xcls_Box7 : Object
363         {
364                 public Gtk.Box el;
365                 private DialogTemplateSelect  _this;
366
367
368                         // my vars (def)
369
370                 // ctor
371                 public Xcls_Box7(DialogTemplateSelect _owner )
372                 {
373                         _this = _owner;
374                         this.el = new Gtk.Box( Gtk.Orientation.HORIZONTAL, 0 );
375
376                         // my vars (dec)
377
378                         // set gobject values
379                         this.el.margin_end = 3;
380                         this.el.margin_start = 3;
381                         var child_1 = new Xcls_Label8( _this );
382                         child_1.ref();
383                         this.el.append ( child_1.el  );
384                         new Xcls_dbcombo( _this );
385                         this.el.append ( _this.dbcombo.el  );
386                 }
387
388                 // user defined functions
389         }
390         public class Xcls_Label8 : Object
391         {
392                 public Gtk.Label el;
393                 private DialogTemplateSelect  _this;
394
395
396                         // my vars (def)
397
398                 // ctor
399                 public Xcls_Label8(DialogTemplateSelect _owner )
400                 {
401                         _this = _owner;
402                         this.el = new Gtk.Label( "Select Database Table : " );
403
404                         // my vars (dec)
405
406                         // set gobject values
407                 }
408
409                 // user defined functions
410         }
411
412         public class Xcls_dbcombo : Object
413         {
414                 public Gtk.ComboBox el;
415                 private DialogTemplateSelect  _this;
416
417
418                         // my vars (def)
419
420                 // ctor
421                 public Xcls_dbcombo(DialogTemplateSelect _owner )
422                 {
423                         _this = _owner;
424                         _this.dbcombo = this;
425                         this.el = new Gtk.ComboBox();
426
427                         // my vars (dec)
428
429                         // set gobject values
430                         new Xcls_dbcellrenderer( _this );
431                         this.el.pack_start ( _this.dbcellrenderer.el , true );
432                         new Xcls_dbmodel( _this );
433                         this.el.set_model ( _this.dbmodel.el  );
434
435                         // init method
436
437                         this.el.add_attribute(_this.dbcellrenderer.el , "markup", 1 );
438                 }
439
440                 // user defined functions
441         }
442         public class Xcls_dbcellrenderer : Object
443         {
444                 public Gtk.CellRendererText el;
445                 private DialogTemplateSelect  _this;
446
447
448                         // my vars (def)
449
450                 // ctor
451                 public Xcls_dbcellrenderer(DialogTemplateSelect _owner )
452                 {
453                         _this = _owner;
454                         _this.dbcellrenderer = this;
455                         this.el = new Gtk.CellRendererText();
456
457                         // my vars (dec)
458
459                         // set gobject values
460                 }
461
462                 // user defined functions
463         }
464
465         public class Xcls_dbmodel : Object
466         {
467                 public Gtk.ListStore el;
468                 private DialogTemplateSelect  _this;
469
470
471                         // my vars (def)
472
473                 // ctor
474                 public Xcls_dbmodel(DialogTemplateSelect _owner )
475                 {
476                         _this = _owner;
477                         _this.dbmodel = this;
478                         this.el = new Gtk.ListStore.newv(  { typeof(string),typeof(string) }  );
479
480                         // my vars (dec)
481
482                         // set gobject values
483                 }
484
485                 // user defined functions
486                 public void loadData (Gee.ArrayList<string> data) {
487                     this.el.clear();                                    
488                     Gtk.TreeIter iter;
489                     var el = this.el;
490                     
491                    /// el.append(out iter);
492                     
493                      
494                    // el.set_value(iter, 0, "");
495                    // el.set_value(iter, 1, "aaa  - Just add Element - aaa");
496                 
497                     el.append(out iter);
498                 
499                     
500                     el.set_value(iter, 0, "");
501                     el.set_value(iter, 1, "-- select a table --");
502                     
503                     
504                     for (var i = 0; i < data.size;i++) {
505                     
506                 
507                         el.append(out iter);
508                         
509                         el.set_value(iter, 0, data.get(i));
510                         el.set_value(iter, 1, data.get(i));
511                         
512                     }
513                      this.el.set_sort_column_id(0, Gtk.SortType.ASCENDING);          
514                                                      
515                 }
516         }
517
518
519
520
521         public class Xcls_Button12 : Object
522         {
523                 public Gtk.Button el;
524                 private DialogTemplateSelect  _this;
525
526
527                         // my vars (def)
528
529                 // ctor
530                 public Xcls_Button12(DialogTemplateSelect _owner )
531                 {
532                         _this = _owner;
533                         this.el = new Gtk.Button();
534
535                         // my vars (dec)
536
537                         // set gobject values
538                         this.el.label = "Cancel";
539                 }
540
541                 // user defined functions
542         }
543
544         public class Xcls_Button13 : Object
545         {
546                 public Gtk.Button el;
547                 private DialogTemplateSelect  _this;
548
549
550                         // my vars (def)
551
552                 // ctor
553                 public Xcls_Button13(DialogTemplateSelect _owner )
554                 {
555                         _this = _owner;
556                         this.el = new Gtk.Button();
557
558                         // my vars (dec)
559
560                         // set gobject values
561                         this.el.label = "Just add it";
562                 }
563
564                 // user defined functions
565         }
566
567         public class Xcls_Button14 : Object
568         {
569                 public Gtk.Button el;
570                 private DialogTemplateSelect  _this;
571
572
573                         // my vars (def)
574
575                 // ctor
576                 public Xcls_Button14(DialogTemplateSelect _owner )
577                 {
578                         _this = _owner;
579                         this.el = new Gtk.Button();
580
581                         // my vars (dec)
582
583                         // set gobject values
584                         this.el.label = "OK";
585                 }
586
587                 // user defined functions
588         }
589
590 }