<commit_before>/*
 * TNViewHypervisorControl.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>

@import <AppKit/CPButton.j>
@import <AppKit/CPButtonBar.j>
@import <AppKit/CPCollectionView.j>
@import <AppKit/CPSearchField.j>
@import <AppKit/CPTableView.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPView.j>

@import <LPKit/LPMultiLineTextField.j>
@import <TNKit/TNAlert.j>
@import <TNKit/TNTableViewDataSource.j>

@import "TNNetworkEditionController.j"
@import "TNNetworkDataView.j"

@import "Model/TNLibvirtNet.j"

var TNArchipelPushNotificationNetworks          = @"archipel:push:network",
    TNArchipelTypeHypervisorNetwork             = @"archipel:hypervisor:network",
    TNArchipelTypeHypervisorNetworkGet          = @"get",
    TNArchipelTypeHypervisorNetworkDefine       = @"define",
    TNArchipelTypeHypervisorNetworkUndefine     = @"undefine",
    TNArchipelTypeHypervisorNetworkCreate       = @"create",
    TNArchipelTypeHypervisorNetworkDestroy      = @"destroy",
    TNArchipelTypeHypervisorNetworkGetNics      = @"getnics";


/*! @defgroup  hypervisornetworks Module Hypervisor Networks
    @desc This manages hypervisors' virtual networks
*/

/*! @ingroup hypervisornetworks
    The main module controller
*/
@implementation TNHypervisorNetworksController : TNModule
{
    @outlet CPButton                    buttonDefineXMLString;
    @outlet CPButtonBar                 buttonBarControl;
    @outlet CPSearchField               fieldFilterNetworks;
    @outlet CPTableView                 tableViewNetworks;
    @outlet CPView                      viewTableContainer;
    @outlet LPMultiLineTextField        fieldXMLString;
    @outlet TNNetworkDataView           networkDataViewPrototype;
    @outlet TNNetworkEditionController  networkController;
    @outlet CPPopover                   popoverXMLString;

    CPButton                            _activateButton;
    CPButton                            _deactivateButton;
    CPButton                            _editButton;
    CPButton                            _minusButton;
    CPButton                            _plusButton;
    CPButton                            _editXMLButton;
    TNLibvirtNetwork                    _networkHolder;
    TNTableViewDataSource               _datasourceNetworks;
    CPDictionary                        _networksRAW;

}

#pragma mark -
#pragma mark Initialization

/*! called at cib awaking
*/
- (void)awakeFromCib
{
    _networksRAW = [CPDictionary dictionary];

    [viewTableContainer setBorderedWithHexColor:@"#C0C7D2"];

    /* VM table view */
    _datasourceNetworks     = [[TNTableViewDataSource alloc] init];
    var prototype = [CPKeyedArchiver archivedDataWithRootObject:networkDataViewPrototype];
    [[tableViewNetworks tableColumnWithIdentifier:@"self"] setDataView:[CPKeyedUnarchiver unarchiveObjectWithData:prototype]];
    [tableViewNetworks setTarget:self];
    [tableViewNetworks setDoubleAction:@selector(editNetwork:)];
    [tableViewNetworks setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleNone];
    [tableViewNetworks setBackgroundColor:[CPColor colorWithHexString:@"F7F7F7"]];

    [_datasourceNetworks setTable:tableViewNetworks];
    [_datasourceNetworks setSearchableKeyPaths:[@"networkName", @"UUID", @"bridgeName"]];
    [tableViewNetworks setDataSource:_datasourceNetworks];
    [tableViewNetworks setDelegate:self];
    [networkController setDelegate:self];

    [fieldFilterNetworks setTarget:_datasourceNetworks];
    [fieldFilterNetworks setAction:@selector(filterObjects:)];

    _plusButton = [CPButtonBar plusButton];
    [_plusButton setTarget:self];
    [_plusButton setAction:@selector(addNetwork:)];
    [_plusButton setToolTip:CPBundleLocalizedString(@"Create a new network", @"Create a new network")];

    _minusButton = [CPButtonBar minusButton];
    [_minusButton setTarget:self];
    [_minusButton setAction:@selector(delNetwork:)];
    [_minusButton setToolTip:CPBundleLocalizedString(@"Delete selected networks", @"Delete selected networks")];

    _activateButton = [CPButtonBar plusButton];
    [_activateButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/check.png"] size:CPSizeMake(16, 16)]];
    [_activateButton setTarget:self];<commit_msg>Fix crash when using the network search field<commit_after>/*
 * TNViewHypervisorControl.j
 *
 * Copyright (C) 2010 <NAME> <<EMAIL>>
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

@import <Foundation/Foundation.j>

@import <AppKit/CPButton.j>
@import <AppKit/CPButtonBar.j>
@import <AppKit/CPCollectionView.j>
@import <AppKit/CPSearchField.j>
@import <AppKit/CPTableView.j>
@import <AppKit/CPTextField.j>
@import <AppKit/CPView.j>

@import <LPKit/LPMultiLineTextField.j>
@import <TNKit/TNAlert.j>
@import <TNKit/TNTableViewDataSource.j>

@import "TNNetworkEditionController.j"
@import "TNNetworkDataView.j"

@import "Model/TNLibvirtNet.j"

var TNArchipelPushNotificationNetworks          = @"archipel:push:network",
    TNArchipelTypeHypervisorNetwork             = @"archipel:hypervisor:network",
    TNArchipelTypeHypervisorNetworkGet          = @"get",
    TNArchipelTypeHypervisorNetworkDefine       = @"define",
    TNArchipelTypeHypervisorNetworkUndefine     = @"undefine",
    TNArchipelTypeHypervisorNetworkCreate       = @"create",
    TNArchipelTypeHypervisorNetworkDestroy      = @"destroy",
    TNArchipelTypeHypervisorNetworkGetNics      = @"getnics";


/*! @defgroup  hypervisornetworks Module Hypervisor Networks
    @desc This manages hypervisors' virtual networks
*/

/*! @ingroup hypervisornetworks
    The main module controller
*/
@implementation TNHypervisorNetworksController : TNModule
{
    @outlet CPButton                    buttonDefineXMLString;
    @outlet CPButtonBar                 buttonBarControl;
    @outlet CPSearchField               fieldFilterNetworks;
    @outlet CPTableView                 tableViewNetworks;
    @outlet CPView                      viewTableContainer;
    @outlet LPMultiLineTextField        fieldXMLString;
    @outlet TNNetworkDataView           networkDataViewPrototype;
    @outlet TNNetworkEditionController  networkController;
    @outlet CPPopover                   popoverXMLString;

    CPButton                            _activateButton;
    CPButton                            _deactivateButton;
    CPButton                            _editButton;
    CPButton                            _minusButton;
    CPButton                            _plusButton;
    CPButton                            _editXMLButton;
    TNLibvirtNetwork                    _networkHolder;
    TNTableViewDataSource               _datasourceNetworks;
    CPDictionary                        _networksRAW;

}

#pragma mark -
#pragma mark Initialization

/*! called at cib awaking
*/
- (void)awakeFromCib
{
    _networksRAW = [CPDictionary dictionary];

    [viewTableContainer setBorderedWithHexColor:@"#C0C7D2"];

    /* VM table view */
    _datasourceNetworks     = [[TNTableViewDataSource alloc] init];
    var prototype = [CPKeyedArchiver archivedDataWithRootObject:networkDataViewPrototype];
    [[tableViewNetworks tableColumnWithIdentifier:@"self"] setDataView:[CPKeyedUnarchiver unarchiveObjectWithData:prototype]];
    [tableViewNetworks setTarget:self];
    [tableViewNetworks setDoubleAction:@selector(editNetwork:)];
    [tableViewNetworks setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleNone];
    [tableViewNetworks setBackgroundColor:[CPColor colorWithHexString:@"F7F7F7"]];

    [_datasourceNetworks setTable:tableViewNetworks];
    [_datasourceNetworks setSearchableKeyPaths:[@"name", @"UUID", @"bridge.name"]];
    [tableViewNetworks setDataSource:_datasourceNetworks];
    [tableViewNetworks setDelegate:self];
    [networkController setDelegate:self];

    [fieldFilterNetworks setTarget:_datasourceNetworks];
    [fieldFilterNetworks setAction:@selector(filterObjects:)];

    _plusButton = [CPButtonBar plusButton];
    [_plusButton setTarget:self];
    [_plusButton setAction:@selector(addNetwork:)];
    [_plusButton setToolTip:CPBundleLocalizedString(@"Create a new network", @"Create a new network")];

    _minusButton = [CPButtonBar minusButton];
    [_minusButton setTarget:self];
    [_minusButton setAction:@selector(delNetwork:)];
    [_minusButton setToolTip:CPBundleLocalizedString(@"Delete selected networks", @"Delete selected networks")];

    _activateButton = [CPButtonBar plusButton];
    [_activateButton setImage:[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:@"IconsButtons/check.png"] size:CPSizeMake(16, 16)]];
    [_activateButton setTarget:self];
{'fraction_non_alphanumeric': 0.0847, 'fraction_numerical': 0.003, 'mean_word_length': 3.6451463074779378, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1894192', 'n_tokens_mistral': 2906, 'n_tokens_neox': 2731, 'n_words': 640}