File: MGRTRevEngFilterPane.mm

package info (click to toggle)
mysql-gui-tools 5.0r14%2BopenSUSE-2.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 116,956 kB
  • ctags: 48,715
  • sloc: sql: 341,918; pascal: 276,698; ansic: 91,020; cpp: 90,451; objc: 33,236; sh: 29,481; yacc: 10,756; xml: 10,589; java: 10,079; php: 2,806; python: 2,092; makefile: 1,783; perl: 4
file content (374 lines) | stat: -rw-r--r-- 10,002 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
//
//  MGRTRevEngFilterPane.mm
//  MySQLGRT
//
//  Created by Alfredo Kojima on 05/8/30.
//  Copyright 2005 MySQL AB. All rights reserved.
//

#import "MGRTRevEngFilterPane.h"
#include "MGRTValue.h"
#include <MySQLToolsCommon/myxutil.h>
#include <MySQLToolsCommon/NSView_extras.h>

@implementation MGRTRevEngFilterPane



- (void)refreshLists
{
  MGRTValue sourceL= MGRTValue::fromGlobal([_grt grt], "/migration/sourceObjects");
  MGRTValue ignoreL= MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList");
  
  int totalObjectCount= 0;
  
  [_sourceObjects removeAllObjects];
  
  for (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, 
                                              [_structName UTF8String]) == 1) 
    {
      NSDictionary *item;
      MYX_GRT_VALUE *ownerObj;
      NSString *name;
      
      totalObjectCount++;
      
      //Find owner schema
      ownerObj = myx_grt_dict_item_get_reference_value([_grt grt], obj.grtValue(), "owner");
      
      //Build name
      if (ownerObj)
        name= [NSString stringWithFormat:@"%s.%s", 
          myx_grt_dict_item_get_as_string(ownerObj, "name"),
          obj["name"].asString()];
      else
      {
        NSLog(@"Owner object of %s not found", myx_grt_dict_item_get_as_string(obj.grtValue(), "name"));
        continue;
      }

      item= [NSDictionary dictionaryWithObjectsAndKeys:
        [NSValue valueWithPointer:obj.grtValue()], @"object",
        [NSValue valueWithPointer:ownerObj], @"owner",
        name, @"name",
        nil];

      //Check object name against filter list
      BOOL filterHit= NO;
      for (int i= 0; i < ignoreL.count(); i++)
      {
        if (strncmp(ignoreL[i].asString(), [_structName UTF8String], [_structName length]) == 0 &&
            ignoreL[i].asString()[[_structName length]] == ':'
            && strcmp(ignoreL[i].asString() + [_structName length] + 1, [name UTF8String])==0)
          filterHit= YES;
      }

      /*
      for (int j= 0; j < [_ignoreFilters count]; j++)
      {
        const char *filter= [[_ignoreFilters objectAtIndex:j] UTF8String];
        
        if (myx_match_pattern([[NSString stringWithFormat:@"%@:%@", _structName, 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)
        [_sourceObjects addObject:item];
        //else
        //Inc(SearchIgnores);
      }
      //else
      //[_ FObjIgnoreList.Add(ObjListItem);
    }
  }
  
  [[[box contentView] viewWithTag:13] setStringValue:[NSString stringWithFormat:@"%i / %i", [_sourceObjects count], totalObjectCount]];
  
  if (totalObjectCount == 0)
    [[[box contentView] viewWithTag:10] setState:NSOffState];
  
  [objectList reloadData];
  [ignoreList reloadData];
}


- (void)setup
{
  MYX_GRT_STRUCT *gstruct= myx_grt_struct_get([_grt grt], [_structName UTF8String]);
  const char *caption;
  int inherited;
  NSView *content= [box contentView];
  NSImage *icon= nil, *miniIcon= nil;
  unsigned int imageSize;
  const char *imageData;
  
  if (gstruct)
    caption= myx_grt_struct_get_caption([_grt grt], gstruct, &inherited);
  else
    caption= [_structName UTF8String];
  
  [[content viewWithTag:12] setStringValue:[NSString stringWithUTF8String:caption]];
  [[view viewWithTag:10] setTitle:[NSString stringWithFormat:@"Migrate Objects of Type %s", caption]];

  imageData= myx_grt_struct_get_icon([_grt grt], 
                                     [[[NSBundle bundleForClass:[self class]] resourcePath] UTF8String],
                                     gstruct, MYX_IT_MANY_STANDARD, &imageSize);
  if (imageData)
  {
    icon= [[NSImage alloc] initWithData:[NSData dataWithBytes:imageData length:imageSize]];
  
    [[content viewWithTag:11] setImage:icon];
    [icon release];
  }
  
  imageData= myx_grt_struct_get_icon([_grt grt], 
                                     [[[NSBundle bundleForClass:[self class]] resourcePath] UTF8String],
                                     gstruct, MYX_IT_SMALL, &imageSize);
  if (imageData)
  {
    miniIcon= [[NSImage alloc] initWithData:[NSData dataWithBytes:imageData length:imageSize]];
  
    [miniIcon release];
  }
  _sourceObjects= [[NSMutableArray alloc] init];
  
  [self refreshLists];
}


- (id)initWithMGRT:(MGRT*)grt forStruct:(NSString*)structName
{
  self= [super init];
  if (self)
  {
    NSNib *nib= [[NSNib alloc] initWithNibNamed:@"ReverseEngineeringFilter"
                                         bundle:[NSBundle bundleForClass:[self class]]];
    
    _grt= [grt retain];
    _structName= [structName retain];

    if (![nib instantiateNibWithOwner:self topLevelObjects:nil])
      NSLog(@"Error instantiating nib");
    [nib release];
  }
  return self;
}


- (void)awakeFromNib
{
  [self setup];
  [objectList reloadData];
  [ignoreList reloadData];
  [[box contentView] setEnabledRecursive:NO];
  [self hideDetailed:nil];
}


- (void)dealloc
{
  [_sourceObjects release];
  [_structName release];
  [_grt release];
  
  [super dealloc];
}


- (NSView*)topView
{
  return view;
}


- (IBAction)showDetailed:(id)sender
{
  int i;
  for (i= 15; i <= 21; i++)
  {
    [[[box contentView] viewWithTag:i] setHidden:NO];
  }  
  [[objectList enclosingScrollView] setHidden:NO];
  [[ignoreList enclosingScrollView] setHidden:NO];
  [[[box contentView] viewWithTag:14] setHidden:YES];
  
  [view setFrameSize:NSMakeSize(NSWidth([view frame]), 340)];

  [view setNeedsDisplay:YES];
}


- (IBAction)hideDetailed:(id)sender
{
  int i;
  for (i= 15; i <= 21; i++)
  {
    [[[box contentView] viewWithTag:i] setHidden:YES];
  }
  [[objectList enclosingScrollView] setHidden:YES];
  [[ignoreList enclosingScrollView] setHidden:YES];
  [[[box contentView] viewWithTag:14] setHidden:NO];

  [view setFrameSize:NSMakeSize(NSWidth([view frame]), 100)];  
}


- (IBAction)addItem:(id)sender
{
  MGRTValue ignoreL(MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList"));
  
  if ([sender tag] == 16)
  {
    NSIndexSet *indexes= [objectList selectedRowIndexes];
    if (indexes)
    {
      int index;
      for (index= [indexes firstIndex]; index <= [indexes lastIndex]; index= [indexes indexGreaterThanIndex:index])
      {
        id item= [_sourceObjects objectAtIndex:index];
        ignoreL.append(MGRTValue([[NSString stringWithFormat:@"%@:%@", _structName, [item objectForKey:@"name"]] UTF8String]));
      }
    }
  }
  else
  {
    for (int i= [_sourceObjects count]-1; i >= 0; --i)
    {
      id item= [_sourceObjects objectAtIndex:i];
      
      ignoreL.append(MGRTValue([[NSString stringWithFormat:@"%@:%s", _structName, [item objectForKey:@"name"]] UTF8String]));
    }
  }
  [objectList deselectAll:nil];
  [self refreshLists];
}


- (IBAction)deleteItem:(id)sender
{
  MGRTValue ignoreL(MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList"));

  if ([sender tag] == 17)
  {
    NSIndexSet *indexes= [ignoreList selectedRowIndexes];
    if (indexes)
    {
      int index;
      for (index= [indexes lastIndex]; index >= [indexes firstIndex]; index= [indexes indexLessThanIndex:index])
      {
        ignoreL.remove(index);
      }
    }
  }
  else
  {
    ignoreL.clear();
  }
  [ignoreList deselectAll:nil];
  [self refreshLists];
}


- (void)setSelected:(BOOL)flag
{
  if (flag && [[view viewWithTag:10] state] == NSOffState)
  {
    [[view viewWithTag:10] setState:NSOnState];
    [self toggleMigrate: [view viewWithTag:10]];
  }
  else if (!flag && [[view viewWithTag:10] state] == NSOnState)
  {
    [[view viewWithTag:10] setState:NSOffState];
    [self toggleMigrate: [view viewWithTag:10]];
  }
}


- (IBAction)toggleMigrate:(id)sender
{
  MGRTValue ignoreL(MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList"));
  
  if ([sender state] == NSOnState)
  {
    [[box contentView] setEnabledRecursive:YES];
    myx_grt_list_item_del_as_string(ignoreL.grtValue(), 
                                    [[NSString stringWithFormat:@"%@:*", _structName] UTF8String]);
  }
  else
  {
    [[box contentView] setEnabledRecursive:NO];
    myx_grt_list_item_add_as_string(ignoreL.grtValue(), 
                                    [[NSString stringWithFormat:@"%@:*", _structName] UTF8String]);
  }
}


- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
  if (tableView == objectList)
  {
    return [_sourceObjects count];
  }
  else
  {
    MGRTValue ignoreL= MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList");
    int i, count= 0;
    
    for (i= 0; i < ignoreL.count(); i++)
    {
      if (strncmp(ignoreL[i].asString(), [_structName UTF8String], [_structName length]) == 0 &&
          ignoreL[i].asString()[[_structName length]] == ':')
        count++;
    }
      
    return count;
  }
}


- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
  if (tableView == objectList)
  {
    return [[_sourceObjects objectAtIndex:row] objectForKey:@"name"];
  }
  else
  {
    MGRTValue ignoreL= MGRTValue::fromGlobal([_grt grt], "/migration/ignoreList");

    for (int i= 0; i < ignoreL.count(); i++)
    {
      if (strncmp(ignoreL[i].asString(), [_structName UTF8String], [_structName length]) == 0 &&
          ignoreL[i].asString()[[_structName length]] == ':')
      {
        if (row == 0)
          return NSStr(ignoreL[i].asString() + [_structName length] + 1);
        row--;
      }
    }
    
    return nil;
  }
}


@end