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>
|
2021-07-15 16:32:35 +08:00
|
|
|
#import <DoricCore/DoricRootNode.h>
|
2021-07-21 20:15:10 +08:00
|
|
|
#import <DoricCore/DoricSuperNode.h>
|
2021-07-14 19:54:34 +08:00
|
|
|
|
|
|
|
@interface DoricShowNodeTreeViewController () <RATreeViewDelegate, RATreeViewDataSource>
|
|
|
|
@property(nonatomic, weak) DoricContext *doricContext;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricShowNodeTreeViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-14 19:54:34 +08:00
|
|
|
self.doricContext = [[DoricContextManager instance] getContext:self.contextId];
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-14 19:54:34 +08:00
|
|
|
RATreeView *treeView = [[RATreeView alloc] initWithFrame:self.view.bounds];
|
|
|
|
[self.view addSubview:treeView];
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-14 19:54:34 +08:00
|
|
|
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-21 20:15:10 +08:00
|
|
|
DoricViewNode *viewNode = (DoricViewNode *) item;
|
|
|
|
|
2021-07-15 16:32:35 +08:00
|
|
|
NSString *type = viewNode.type;
|
|
|
|
if ([item isKindOfClass:[DoricRootNode class]]) {
|
|
|
|
type = @"Root";
|
|
|
|
}
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-15 14:51:19 +08:00
|
|
|
NSString *viewId = [[@" <" stringByAppendingString:viewNode.viewId] stringByAppendingString:@"> "];
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-15 16:32:35 +08:00
|
|
|
NSString *value = [type stringByAppendingString:viewId];
|
|
|
|
if ([item isKindOfClass:[DoricGroupNode class]]) {
|
|
|
|
DoricGroupNode *groupNode = item;
|
|
|
|
NSString *childDesc = [[@"(" stringByAppendingString:[@(groupNode.childNodes.count) stringValue]] stringByAppendingString:@" Child)"];
|
|
|
|
value = [value stringByAppendingString:childDesc];
|
|
|
|
} else if ([item isKindOfClass:[DoricSuperNode class]]) {
|
|
|
|
DoricSuperNode *superNode = item;
|
|
|
|
NSArray *viewIds = [superNode getSubNodeViewIds];
|
2021-07-21 20:15:10 +08:00
|
|
|
NSString *childDesc = [[@"(" stringByAppendingString:[@(viewIds.count) stringValue]] stringByAppendingString:@" Child)"];
|
2021-07-15 16:32:35 +08:00
|
|
|
value = [value stringByAppendingString:childDesc];
|
|
|
|
}
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-15 16:32:35 +08:00
|
|
|
cell.nodeNameLabel.text = value;
|
2021-07-15 14:51:19 +08:00
|
|
|
[cell.nodeNameLabel sizeToFit];
|
2021-07-21 20:15:10 +08:00
|
|
|
|
2021-07-14 19:54:34 +08:00
|
|
|
NSInteger indent = [treeView levelForCellForItem:item];
|
2021-07-15 16:32:35 +08:00
|
|
|
cell.nodeIcon.left = 5 + indent * 15;
|
|
|
|
cell.nodeNameLabel.left = 30 + indent * 15;
|
2021-07-21 20:15:10 +08:00
|
|
|
|
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
|