2 // IpConfiguratorCommander.m
5 // Created by Claudio Bisegni on
18/06/07.
6 // Copyright
2007 INFN
- National Institute of Nuclear Physics.
All rights reserved.
9 #import "IpConfiguratorCommander.h"
10 #import "AFSCommanderPref.h"
12 @implementation IpConfiguratorCommander
14 // -------------------------------------------------------------------------------
16 // -------------------------------------------------------------------------------
19 [tableViewCellIP setDelegate
:self
];
20 [tableViewCellIP setDataSource
:self
];
23 // -------------------------------------------------------------------------------
25 // -------------------------------------------------------------------------------
26 - (void
) setWorkCell
:(DBCellElement
*)cell {
28 currentSelectedIP
= nil
;
31 // -------------------------------------------------------------------------------
33 // -------------------------------------------------------------------------------
34 - (IBAction
) save:(id
) sender
38 [NSApp endSheet
:confPanel
];
41 // -------------------------------------------------------------------------------
43 // -------------------------------------------------------------------------------
47 [cellElement setCellName
:[textFieldCellName stringValue
]];
48 [cellElement setCellComment
:[textFieldComment stringValue
]];
49 [bkIPArray removeAllObjects
];
50 [bkIPArray setArray
:workIPArray
];
51 [workIPArray release
];
54 // -------------------------------------------------------------------------------
56 // -------------------------------------------------------------------------------
57 - (IBAction
) cancel
:(id
) sender
60 [self rollbackModify
];
61 [NSApp endSheet
:confPanel
];
65 // -------------------------------------------------------------------------------
67 // -------------------------------------------------------------------------------
68 - (void
) rollbackModify
71 [workIPArray release
];
75 // -------------------------------------------------------------------------------
77 // -------------------------------------------------------------------------------
78 - (IBAction
) createNewIP
:(id
) sender
80 CellIp
*ip
= [[CellIp alloc
] init
];
81 [workIPArray addObject
:ip
];
83 currentSelectedIP
= ip
;
84 [tableViewCellIP reloadData
];
85 [tableViewCellIP scrollRowToVisible
:[[cellElement getIp
] count
]-1];
88 // -------------------------------------------------------------------------------
90 // -------------------------------------------------------------------------------
91 - (IBAction
) cancelIP
:(id
) sender
93 [workIPArray removeObjectAtIndex
:[tableViewCellIP selectedRow
]];
94 [tableViewCellIP deselectAll
:nil
];
95 [self manageTableSelection
:-1];
96 [tableViewCellIP reloadData
];
100 // -------------------------------------------------------------------------------
102 // -------------------------------------------------------------------------------
108 // -------------------------------------------------------------------------------
109 // loadValueFromCellIPClass
:
110 // -------------------------------------------------------------------------------
111 - (void
) loadValueFromCellIPClass
113 [textFieldCellName setStringValue
:[cellElement getCellName
]];
114 [textFieldComment setStringValue
:[cellElement getCellComment
]];
115 [tableViewCellIP reloadData
];
118 // -------------------------------------------------------------------------------
119 // manageTableSelection
:
120 // -------------------------------------------------------------------------------
121 - (void
) manageTableSelection
:(int
)row
123 //[((NSControl
*) modifyButton
) setEnabled
:row
>=0];
124 [deleteButton setEnabled
:row
>=0];
134 @implementation IpConfiguratorCommander
(PanelDelegator
)
135 // -------------------------------------------------------------------------------
136 // windowDidBecomeKey
:
137 // -------------------------------------------------------------------------------
138 - (void
)windowDidBecomeKey
:(NSNotification
*)aNotification
141 [NSApp endSheet
:confPanel
];
145 bkIPArray
= [cellElement getIp
];
146 workIPArray
= [[NSMutableArray alloc
] initWithArray
:bkIPArray
];
147 [self loadValueFromCellIPClass
];
150 // -------------------------------------------------------------------------------
152 // -------------------------------------------------------------------------------
153 - (void
)windowWillClose
:(NSNotification
*)aNotification
159 @implementation IpConfiguratorCommander
(NSTableDataSource
)
160 // -------------------------------------------------------------------------------
162 // -------------------------------------------------------------------------------
163 - (id
) tableView
:(NSTableView
*) aTableView
164 objectValueForTableColumn
:(NSTableColumn
*) aTableColumn
168 NSString
*result
= nil
;
169 //NSMutableArray
*cellArray
= [cellElement getIp
];
170 CellIp
*ipElement
= (CellIp
*)[workIPArray objectAtIndex
:rowIndex
];
171 NSString
*identifier
= (NSString
*)[aTableColumn identifier
];
172 switch([identifier intValue
]){
174 result
= [ipElement getCellIp
];
178 result
= [ipElement getCellComment
];
185 // -------------------------------------------------------------------------------
186 // numberOfRowsInTableView
:
187 // -------------------------------------------------------------------------------
188 - (int
)numberOfRowsInTableView
:(NSTableView
*)aTableView
190 return [workIPArray count
];
193 - (void
)tableView
:(NSTableView
*)aTable setObjectValue
:(id
)aData
194 forTableColumn
:(NSTableColumn
*)aCol row
:(int
)aRow
196 CellIp
*ipElement
= (CellIp
*)[workIPArray objectAtIndex
:aRow
];
197 switch([[aCol identifier
] intValue
])
200 [ipElement setCellIp
:[aData description
]];
204 [ipElement setCellComment
:[aData description
]];
211 @implementation IpConfiguratorCommander
(TableDelegate
)
212 // -------------------------------------------------------------------------------
213 // selectionShouldChangeInTableView
:
214 // -------------------------------------------------------------------------------
215 - (BOOL
)selectionShouldChangeInTableView
:(NSTableView
*)aTable
217 [self manageTableSelection
:[aTable selectedRow
]];
221 // -------------------------------------------------------------------------------
223 // -------------------------------------------------------------------------------
224 - (BOOL
)tableView
:(NSTableView
*)aTable shouldSelectRow
:(int
)aRow
226 [self manageTableSelection
:aRow
];