2021-07-14 19:54:34 +08:00
|
|
|
/*
|
|
|
|
* Copyright [2019] [Doric.Pub]
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
//
|
|
|
|
// DoricShowNodeTreeViewController.m
|
|
|
|
// Doric
|
|
|
|
//
|
|
|
|
// Created by jingpeng.wang on 2021/7/8.
|
|
|
|
//
|
|
|
|
#import "DoricShowNodeTreeViewController.h"
|
|
|
|
#import "DoricShowNodeTreeViewCell.h"
|
|
|
|
|
|
|
|
#import "RATreeView.h"
|
|
|
|
#import <DoricCore/DoricContextManager.h>
|
|
|
|
#import <DoricCore/DoricContext.h>
|
|
|
|
#import <DoricCore/DoricGroupNode.h>
|
|
|
|
|
|
|
|
@interface DoricShowNodeTreeViewController () <RATreeViewDelegate, RATreeViewDataSource>
|
|
|
|
@property(nonatomic, weak) DoricContext *doricContext;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricShowNodeTreeViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
self.doricContext = [[DoricContextManager instance] getContext:self.contextId];
|
|
|
|
|
|
|
|
RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.bounds];
|
|
|
|
[self.view addSubview:treeView];
|
|
|
|
|
|
|
|
treeView.delegate = self;
|
|
|
|
treeView.dataSource = self;
|
|
|
|
[treeView registerClass:DoricShowNodeTreeViewCell.self forCellReuseIdentifier:@"cell"];
|
|
|
|
[treeView reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark ratreeview delegate
|
|
|
|
|
|
|
|
- (nonnull UITableViewCell *)treeView:(nonnull RATreeView *)treeView cellForItem:(nullable id)item {
|
|
|
|
DoricShowNodeTreeViewCell *cell = [treeView dequeueReusableCellWithIdentifier:@"cell"];
|
2021-07-15 14:51:19 +08:00
|
|
|
DoricViewNode *viewNode = (DoricViewNode *)item;
|
2021-07-14 19:54:34 +08:00
|
|
|
|
2021-07-15 14:51:19 +08:00
|
|
|
NSString *viewId = [[@" <" stringByAppendingString:viewNode.viewId] stringByAppendingString:@"> "];
|
|
|
|
cell.nodeNameLabel.text = [NSStringFromClass([item class]) stringByAppendingString:viewId];
|
|
|
|
[cell.nodeNameLabel sizeToFit];
|
2021-07-14 19:54:34 +08:00
|
|
|
|
|
|
|
NSInteger indent = [treeView levelForCellForItem:item];
|
2021-07-15 14:51:19 +08:00
|
|
|
cell.nodeIcon.left = 5 + indent * 20;
|
|
|
|
cell.nodeNameLabel.left = 30 + indent * 20;
|
|
|
|
|
2021-07-14 19:54:34 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (nonnull id)treeView:(nonnull RATreeView *)treeView child:(NSInteger)index ofItem:(nullable id)item {
|
|
|
|
if (item == nil) {
|
|
|
|
return self.doricContext.rootNode;
|
2021-07-15 14:51:19 +08:00
|
|
|
} else if ([item isKindOfClass:[DoricGroupNode class]]) {
|
2021-07-14 19:54:34 +08:00
|
|
|
DoricGroupNode *groupNode = item;
|
|
|
|
return groupNode.childNodes[index];
|
2021-07-15 14:51:19 +08:00
|
|
|
} else if ([item isKindOfClass:[DoricSuperNode class]]) {
|
|
|
|
DoricSuperNode *superNode = item;
|
|
|
|
NSArray *viewIds = [superNode getSubNodeViewIds];
|
|
|
|
return [superNode subNodeWithViewId:viewIds[index]];
|
2021-07-14 19:54:34 +08:00
|
|
|
}
|
2021-07-15 14:51:19 +08:00
|
|
|
return nil;
|
2021-07-14 19:54:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)treeView:(nonnull RATreeView *)treeView numberOfChildrenOfItem:(nullable id)item {
|
|
|
|
if (item == nil) {
|
|
|
|
return 1;
|
|
|
|
} else if ([item isKindOfClass:[DoricGroupNode class]]) {
|
|
|
|
DoricGroupNode *groupNode = item;
|
|
|
|
return groupNode.childNodes.count;
|
2021-07-15 14:51:19 +08:00
|
|
|
} else if ([item isKindOfClass:[DoricSuperNode class]]) {
|
|
|
|
DoricSuperNode *superNode = item;
|
|
|
|
return [superNode getSubNodeViewIds].count;
|
2021-07-14 19:54:34 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)treeView:(RATreeView *)treeView heightForRowForItem:(id)item {
|
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
@end
|