File: MGRTRevEngFilterPane.cc

package info (click to toggle)
mysql-admin 1.2.5rc-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 80,944 kB
  • ctags: 43,103
  • sloc: sql: 295,916; pascal: 256,535; cpp: 74,487; ansic: 68,881; objc: 26,417; sh: 16,867; yacc: 10,755; java: 9,917; xml: 8,453; php: 2,806; python: 2,068; makefile: 1,252; perl: 3
file content (324 lines) | stat: -rw-r--r-- 10,360 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/* Copyright (C) 2005 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "MGRTRevEngFilterPane.h"
#include "mygpriv.h"
#include "myg_gtkutils.h"
/**
 * @file  MGRTRevEngFilterPane.cc
 * @brief 
 */



MGRTRevEngFilterPane::MGRTRevEngFilterPane(MGRT *grt, const Glib::ustring &struct_name)
  : _grt(grt), _table(4,3), _label1("", 0.0, 0.5), _label2("", 0.0, 0.5), 
    _label3(_("<small>Click [Show Detailed Selection] to put objects in the ignore list.</small>"), 1.0, 0.5, false),
    _button_box(true, 4), _detail_table(1, 3), _struct_name(struct_name)
{
  MYX_GRT_STRUCT *gstruct= myx_grt_struct_get(_grt->grt(), _struct_name.c_str());
  Glib::ustring caption;
  int inherited;
  const char *imagePath;

  _label3.set_use_markup(true);
  
  _table.set_border_width(12);
  _table.set_row_spacings(8);
  _table.set_col_spacings(8);
  
  if (gstruct)
    caption=  myx_grt_struct_get_caption(_grt->grt(), gstruct, &inherited);
  else
    caption= struct_name;

  _label1.set_markup("<b>"+caption+"</b>");
  _label1.show();

  _check.set_label(ufmt(_("Migrate Objects of Type %s"), caption.c_str()));
  _check.signal_toggled().connect(sigc::mem_fun(*this,&MGRTRevEngFilterPane::toggle_migrate));
  _check.show();
  set_label_widget(_check);

  while (gstruct)
  {
    imagePath= myx_grt_struct_get_icon_path(_grt->grt(),
                                            gstruct, MYX_IT_MANY_STANDARD);
    if (imagePath)
    {
      Gtk::Image *img= new Gtk::Image(PIXCACHE->load(imagePath));
      
      _table.attach(*Gtk::manage(img), 0,1, 0, 1, Gtk::FILL, Gtk::FILL);
      img->show();
      break;
    }
    
    gstruct= myx_grt_struct_get(_grt->grt(), myx_grt_struct_get_parent_name(gstruct));
  }

  _source_store= Gtk::ListStore::create(_columns);
  _source_tree.set_model(_source_store);
  _ignore_store= Gtk::ListStore::create(_columns);
  _ignore_tree.set_model(_ignore_store);
  
  Gtk::ScrolledWindow *scroll1, *scroll2;
  
  scroll1= Gtk::manage(new Gtk::ScrolledWindow());
  scroll2= Gtk::manage(new Gtk::ScrolledWindow());
  
  scroll1->set_policy(Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC);
  scroll1->set_shadow_type(Gtk::SHADOW_IN);
  scroll1->add(_source_tree);

  scroll2->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
  scroll2->set_shadow_type(Gtk::SHADOW_IN);
  scroll2->add(_ignore_tree);

  _source_tree.append_column(_("Objects to Migrate"), _columns.text);
  _ignore_tree.append_column(_("Ignored Objects"), _columns.text);

  _table.attach(*Gtk::manage(new Gtk::Label(_("Objects of Type:"), 1.0, 0.5)),
                       0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
  _table.attach(*Gtk::manage(new Gtk::Label(_("Number to Migrate:"), 1.0, 0.5)),
                       0, 1, 1, 2, Gtk::FILL, Gtk::FILL);

  _table.attach(_label1, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
  _table.attach(_label2, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);

  _table.attach(_label3, 3, 4, 0, 1, Gtk::FILL, Gtk::FILL);

  Gtk::Button *btn;
  
  btn= Gtk::manage(new Gtk::Button(">"));
  _button_box.pack_start(*btn, false, false);
  btn->signal_clicked().connect(sigc::bind<const char*>(sigc::mem_fun(*this,&MGRTRevEngFilterPane::move_object),"add"));
  btn= Gtk::manage(new Gtk::Button("<"));
  _button_box.pack_start(*btn, false, false);
  btn->signal_clicked().connect(sigc::bind<const char*>(sigc::mem_fun(*this,&MGRTRevEngFilterPane::move_object),"del"));
  btn= Gtk::manage(new Gtk::Button(">>"));
  _button_box.pack_start(*btn, false, false);
  btn->signal_clicked().connect(sigc::bind<const char*>(sigc::mem_fun(*this,&MGRTRevEngFilterPane::move_object),"addall"));
  btn= Gtk::manage(new Gtk::Button("<<"));
  _button_box.pack_start(*btn, false, false);
  btn->signal_clicked().connect(sigc::bind<const char*>(sigc::mem_fun(*this,&MGRTRevEngFilterPane::move_object),"delall"));
  
  _detail_table.set_col_spacings(8);
  _detail_table.set_row_spacings(8);
  _detail_table.attach(*scroll1, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
  _detail_table.attach(_button_box, 1, 2, 1, 2, Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
  _detail_table.attach(*scroll2, 2, 3, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);

  _detail_table.show_all();
  _table.attach(_detail_table, 1, 4, 2, 3, Gtk::FILL, Gtk::EXPAND|Gtk::FILL);

  _detail_button.set_label(_("Show Detailed Selection"));
  _detail_button.signal_clicked().connect(sigc::mem_fun(*this,&MGRTRevEngFilterPane::show_details));

  _detail_button.show();
  _table.attach(_detail_button, 3, 4, 3, 4, Gtk::FILL, Gtk::FILL);

  _table.show_all();
  _detail_table.hide();
  add(_table);
}



void MGRTRevEngFilterPane::move_object(const char *dir)
{
  MGRTValue ignoreL(MGRTValue::fromGlobal(_grt->grt(), "/migration/ignoreList"));
  
  if (strcmp(dir, "add")==0)
  {
    Gtk::TreeIter iter;
    std::list<Gtk::TreePath> sel= _source_tree.get_selection()->get_selected_rows();

    for (std::list<Gtk::TreePath>::const_iterator i= sel.begin(); i != sel.end(); ++i)
    {
      iter= _source_store->get_iter(*i);
      Gtk::TreeRow row= *iter;

      ignoreL.append(MGRTValue(ufmt("%s:%s", _struct_name.c_str(), ((Glib::ustring)row[_columns.text]).c_str()).c_str()));
    }
  }
  else if (strcmp(dir, "del")==0)
  {
    Gtk::TreeIter iter;
    std::list<Gtk::TreePath> sel= _ignore_tree.get_selection()->get_selected_rows();

    for (std::list<Gtk::TreePath>::reverse_iterator i= sel.rbegin(); i != sel.rend(); ++i)
    {
      ignoreL.remove((*i)[0]);
    }
  }
  else if (strcmp(dir, "addall")==0)
  {
    Gtk::TreeNodeChildren sel= _source_store->children();

    for (Gtk::TreeNodeChildren::const_iterator i= sel.begin(); i != sel.end(); ++i)
    {
      Gtk::TreeRow row= **i;

      ignoreL.append(MGRTValue(ufmt("%s:%s", _struct_name.c_str(), ((Glib::ustring)row[_columns.text]).c_str()).c_str()));
    }
  }
  else if (strcmp(dir, "delall")==0)
  {
    ignoreL.clear();
  }
  refresh();
}


void MGRTRevEngFilterPane::set_selected(bool flag)
{
  _check.set_active(flag);
  toggle_migrate();
}


void MGRTRevEngFilterPane::show_details()
{
  if (_detail_table.is_visible())
  {
    _detail_table.hide();
    _detail_button.set_label(_("Show Detailed Selection"));
  }
  else
  {
    _detail_table.show();
    _detail_button.set_label(_("Hide Details"));
  }
}


void MGRTRevEngFilterPane::toggle_migrate()
{
  MGRTValue ignoreL(MGRTValue::fromGlobal(_grt->grt(), "/migration/ignoreList"));
  if (_check.get_active())
  {
    _table.set_sensitive(true);
    myx_grt_list_item_del_as_string(ignoreL.grtValue(),
                                    ufmt("%s:*", _struct_name.c_str()).c_str());
  }
  else
  {
    _table.set_sensitive(false);
    myx_grt_list_item_add_as_string(ignoreL.grtValue(),
                                    ufmt("%s:*", _struct_name.c_str()).c_str());
  }
}



void MGRTRevEngFilterPane::refresh()
{
  Gtk::TreeIter iter;
  Gtk::TreeRow row;
  MGRTValue ignoreL(MGRTValue::fromGlobal(_grt->grt(), "/migration/ignoreList"));
  MGRTValue sourceL(MGRTValue::fromGlobal(_grt->grt(), "/migration/sourceObjects"));
  int totalObjectCount= 0;
  
  _source_store->clear();
  _ignore_store->clear();

  for (unsigned int i= 0; i < sourceL.count(); i++)
  {
    MGRTValue obj(myx_grt_list_item_get_reference_value(_grt->grt(), sourceL.grtValue(), i));
    const char *objStructName;

    if (obj.isValid())
      objStructName= obj.contentStruct();

    //If the object is of the same struct
    if (obj.isValid()
        && myx_grt_struct_is_or_inherits_from(_grt->grt(),
                                              objStructName,
                                              _struct_name.c_str()) == 1)
    {
      MYX_GRT_VALUE *ownerObj;
      Glib::ustring name;

      totalObjectCount++;

      //Find owner schema
      ownerObj = myx_grt_dict_item_get_reference_value(_grt->grt(), obj.grtValue(), "owner");

      //Build name
      if (ownerObj)
        name= ufmt("%s.%s",
                   myx_grt_dict_item_get_as_string(ownerObj, "name"),
                   obj["name"].asString());
      else
      {
        g_message("Owner object of %s not found", myx_grt_dict_item_get_as_string(obj.grtValue(), "name"));
        continue;
      }

      //Check object name against filter list
      bool filterHit= false;
      for (unsigned int i= 0; i < ignoreL.count(); i++)
      {
        if (strncmp(ignoreL[i].asString(), _struct_name.c_str(), _struct_name.size()) == 0 &&
            ignoreL[i].asString()[_struct_name.size()] == ':'
            && strcmp(ignoreL[i].asString() + _struct_name.size() + 1, name.c_str())==0)
          filterHit= true;
      }

      /*
      for (int j= 0; j < [_ignoreFilters count]; j++)
      {
        const char *filter= [[_ignoreFilters objectAtIndex:j] UTF8String];

        if (myx_match_pattern([[NSString stringWithFormat:@"%@:%@", _struct_name, name] UTF8String],
                              filter, 1, 1)==1)
        {
          filterHit= YES;
          break;
        }
      }*/
      //Check if the object was searched
      if (!filterHit)
      {
        //if (myx_match_pattern([name UTF8String],
        //                      [
        //                     FilterMigrateListEd.SearchEd.Text + '*', 0, 1)==1)

        iter= _source_store->append();
        row= *iter;
        //else
        //Inc(SearchIgnores);
      }
      else
      {
        iter= _ignore_store->append();
        row= *iter;
      }
      row[_columns.text]= name;
      row[_columns.grt]= obj;
      row[_columns.owner]= MGRTValue(ownerObj);
    }
  }

  _label2.set_markup(ufmt("<b>%i / %i</b>", _source_store->children().size(), totalObjectCount));

  if (totalObjectCount == 0)
  {
    _check.set_active(false);
    toggle_migrate();
  }
}