API  0.9.10
CPCibControlConnector.j
Go to the documentation of this file.
1 /*
2  * CPCibControlConnector.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 @implementation CPCibControlConnector : CPCibConnector
23 {
24  id __doxygen__;
25 }
26 
28 {
29  var selectorName = _label,
30  selectorNameLength = [selectorName length];
31 
32  if (selectorNameLength && selectorName.charAt(selectorNameLength - 1) !== ':')
33  selectorName += ':';
34 
35  var selector = CPSelectorFromString(selectorName);
36 
37  // Not having a selector is a fatal error.
38  if (!selector)
39  {
41  raise:CPInvalidArgumentException
42  reason:@"-[" + [self className] + ' ' + _cmd + @"] selector " + selectorName + @" does not exist."];
43  }
44 
45  // If the destination doesn't respond to this selector, warn but don't die.
46  if (_destination && ![_destination respondsToSelector:selector])
47  CPLog.warn(@"Could not connect the action " + selector + @" to target of class " + [_destination className]);
48 
49  // Not being able to set the action is a fatal error.
50  if ([_source respondsToSelector:@selector(setAction:)])
51  [_source setAction:selector];
52 
53  else
55  raise:CPInvalidArgumentException
56  reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + @" does not respond to setAction:"];
57 
58  // Not being able to set the target is a fatal error.
59  if ([_source respondsToSelector:@selector(setTarget:)])
60  [_source setTarget:_destination];
61 
62  else
64  raise:CPInvalidArgumentException
65  reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + @" does not respond to setTarget:"];
66 }
67 
68 @end
69 @implementation _CPCibControlConnector : CPCibControlConnector
70 {
71  id __doxygen__;
72 }
73 
74 @end
75 
Used to implement exception handling (creating & raising).
Definition: CPException.h:2
CPString className()
Definition: CPObject.j:527
void raise:reason:(CPString aName, [reason] CPString aReason)
Definition: CPException.j:66
function CPSelectorFromString(aSelectorName)
Definition: CPObjJRuntime.j:28