File: ModelerEntityEditor.m

package info (click to toggle)
gnustep-dl2 0.12.0-16
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,076 kB
  • sloc: objc: 61,761; makefile: 33
file content (253 lines) | stat: -rw-r--r-- 7,704 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
/**
    ModelerEntityEditor.m
 
    Author: Matt Rice <ratmice@gmail.com>
    Date: 2005, 2006

    This file is part of DBModeler.
    
    <license>
    DBModeler 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 3 of the License, or
    (at your option) any later version.

    DBModeler 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 DBModeler; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    </license>
**/


#include "DefaultColumnProvider.h"
#include "ModelerAttributeEditor.h"
#include "ModelerEntityEditor.h"
#include "KVDataSource.h"

#include <EOInterface/EODisplayGroup.h>
#include <EOAccess/EOEntity.h>
#include <EOAccess/EOModel.h>
#include <EOControl/EOEditingContext.h>
#include <EOControl/EOObserver.h>
#include <EOModeler/EOModelerApp.h>
#include <EOModeler/EOModelerDocument.h>

#ifdef NeXT_GUI_LIBRARY
#include <AppKit/AppKit.h>
#else
#include <Foundation/NSRunLoop.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSSplitView.h>
#include <AppKit/NSScrollView.h>
#include <AppKit/NSTableColumn.h>
#include <AppKit/NSTableView.h>
#include <AppKit/NSMenu.h>
#include <AppKit/NSMenuItem.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSPopUpButtonCell.h>
#endif

#include <GNUstepBase/GNUstep.h>
#include <GNUstepBase/GSVersionMacros.h>

@interface EOModelerDocument (asdf)
-(void)_setDisplayGroup:(id)displayGroup;
@end

@interface ModelerEntityEditor (Private)
- (void) _loadColumnsForClass:(Class) aClass;
@end

@implementation ModelerEntityEditor

- (BOOL) canSupportCurrentSelection
{
  id selection = [self selectionWithinViewedObject];
  BOOL flag;

  if ([selection count] == 0)
    {
      flag = NO;
      return flag;
    }
  selection = [selection objectAtIndex:0]; 
  flag = [selection isKindOfClass:[EOModel class]];
  return flag;
}

- (NSArray *) friendEditorClasses
{
  return [NSArray arrayWithObjects: [ModelerAttributeEditor class], nil];
}

- (void) dealloc
{
  [EOObserverCenter removeObserver:self forObject:[[self document] model]];
  RELEASE(_splitView);
  RELEASE(dg);
  [super dealloc];
}

- (id) initWithParentEditor: (EOModelerCompoundEditor *)parentEditor
{
  if ((self = [super initWithParentEditor:parentEditor]))
    {
      EOClassDescription *classDescription = nil;
      KVDataSource   *wds;
      NSScrollView *scrollView;
      NSPopUpButton *cornerView;
      NSMenuItem *mi = [[NSMenuItem alloc] initWithTitle:@"+" action:(SEL)nil keyEquivalent:@""];

      _splitView = [[NSSplitView alloc] initWithFrame:NSMakeRect(0,0,10,10)];
      scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,10,10)];
      [scrollView setHasHorizontalScroller:YES];
      [scrollView setHasVerticalScroller:YES];
      [scrollView setBorderType: NSBezelBorder];

      _topTable = [[NSTableView alloc] initWithFrame:NSMakeRect(0,0,10,10)];
      _bottomTable = [[NSTableView alloc] initWithFrame:NSMakeRect(0,0,10,10)];

#if OS_API_VERSION(GS_API_NONE, MAC_OS_X_VERSION_10_4)
      [_topTable setAutoresizesAllColumnsToFit:NO];
#else
      [_topTable setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
#endif

#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) || GNU_GUI_LIBRARY
      [_topTable setUsesAlternatingRowBackgroundColors:YES];
      [_topTable setGridStyleMask:NSTableViewSolidVerticalGridLineMask];
#endif

      [scrollView setDocumentView:_topTable];
      RELEASE(_topTable);
      [_splitView addSubview:scrollView];
      RELEASE(scrollView);

      scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0,0,10,10)];
      [scrollView setHasHorizontalScroller:YES];
      [scrollView setHasVerticalScroller:YES];
      [scrollView setBorderType: NSBezelBorder];

#if OS_API_VERSION(GS_API_NONE, MAC_OS_X_VERSION_10_4)
      [_bottomTable setAutoresizesAllColumnsToFit:NO];
#else
      [_bottomTable setColumnAutoresizingStyle:NSTableViewLastColumnOnlyAutoresizingStyle];
#endif

#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) || GNU_GUI_LIBRARY
      [_bottomTable setUsesAlternatingRowBackgroundColors:YES];
      [_bottomTable setGridStyleMask:NSTableViewSolidVerticalGridLineMask];
#endif

      [scrollView setDocumentView:_bottomTable];
      RELEASE(_bottomTable);
      [_splitView addSubview:scrollView];
      RELEASE(scrollView);

      
      [DefaultColumnProvider class]; // calls +initialize
      
      cornerView = [[NSPopUpButton alloc] initWithFrame:[[_topTable cornerView] bounds] pullsDown:YES];
      [cornerView setPreferredEdge:NSMinYEdge];
      [cornerView setTitle:@"+"];
      [cornerView setBezelStyle:NSShadowlessSquareBezelStyle];
      [[cornerView cell] setBezelStyle:NSShadowlessSquareBezelStyle];
      [[cornerView cell] setArrowPosition:NSPopUpNoArrow];
      //[mi setImage:[NSImage imageNamed:@"plus"]];
     // [mi setOnStateImage:[NSImage imageNamed:@"plus"]];
     // [mi setOffStateImage:[NSImage imageNamed:@"plus"]];
      //[mi setState:NSOnState];
      [[cornerView cell] setUsesItemFromMenu:NO];
      [[cornerView cell] setShowsFirstResponder:NO];
      [[cornerView cell] setShowsStateBy:NSContentsCellMask];
      [[cornerView cell] setMenuItem:mi];
      RELEASE(mi);
      [[cornerView cell] setImagePosition:NSNoImage];
      
      [_topTable setCornerView:cornerView];
      RELEASE(cornerView);
      [_topTable setAllowsMultipleSelection:YES];  
      
      classDescription = nil; 
      wds = [[KVDataSource alloc]
              initWithClassDescription:classDescription 
                        editingContext:[[self document] editingContext]];
  
      [wds setDataObject: [[self document] model]];
      [wds setKey:@"entities"];
      dg = [[EODisplayGroup alloc] init];
      [EOObserverCenter addObserver:self forObject:[[self document] model]];
      [dg setDataSource: wds];
      RELEASE(wds);
      [dg setFetchesOnLoad:YES];
      [dg setDelegate: self]; 
      
      [self setupCornerView:cornerView
          tableView:_topTable
          displayGroup:dg
          forClass:[EOEntity class]];
  
      [self addDefaultTableColumnsForTableView:_topTable
                                  displayGroup:dg];

      
    }
  return self;
}

- (NSArray *)defaultColumnNamesForClass:(Class)aClass
{
  NSArray *colNames = [super defaultColumnNamesForClass:aClass];
  if (colNames == nil || [colNames count] == 0)
    {
      if (aClass == [EOEntity class])
        return DefaultEntityColumns;
      else return nil;
    }

  return colNames;
}

- (void) activate
{
  [dg fetch];

  [dg selectObjectsIdenticalTo:[self selectionWithinViewedObject]
          selectFirstOnNoMatch:NO];
}

- (NSView *)mainView
{
  return _splitView;
}

- (void) objectWillChange:(id)anObject
{
  [[NSRunLoop currentRunLoop]
          performSelector:@selector(needToFetch:)
                   target:self
                 argument:nil
                    order:999 /* this number is probably arbitrary */
                    modes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
}

- (void) needToFetch:(id)sth
{
  [dg fetch];
}

@end

@implementation ModelerEntityEditor (DisplayGroupDelegate)
- (void) displayGroupDidChangeSelection:(EODisplayGroup *)displayGroup
{
  [[self parentEditor] setSelectionWithinViewedObject: [displayGroup selectedObjects]];
}

@end