DefaultOrgChartNode.as
9.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package control{
import com.adobe.utils.StringUtil;
import flash.display.DisplayObject;
import flash.events.MouseEvent;
import flash.geom.Point;
import mx.collections.ArrayCollection;
import mx.collections.IViewCursor;
import mx.controls.Alert;
import mx.controls.Button;
import mx.core.Application;
import mx.core.IUITextField;
import mx.core.UITextField;
//import tipBubble.BubbleTipManager;
// import view.DetailsPanel;
public class DefaultOrgChartNode extends Button implements IOrgChartNode{
public var _data:Object;
private var dataChanged:Boolean = true;
private var _expanded:Boolean = true;
private var _parent:IOrgChartNode;
private var _subNodes:ArrayCollection=new ArrayCollection();
private var _lines:ArrayCollection = new ArrayCollection();
private var _linesChanged:Boolean = false;
// private var tipManager:BubbleTipManager;
public var _textField:IUITextField;
public var _otherChildren:String="";
private var _parentLinePoints:String="";
private var _labels:String="";
private var _isShows:String = "";
private var _hasShow:Boolean=false;
// private var detailsPanel:DetailsPanel;
//private var fader:Fade;
public function DefaultOrgChartNode(canView:Boolean){
super();
//fader.
//buttonMode = true;
//cornerRadius=0;
//styleName="companyNode";
if(canView){
addEventListener(MouseEvent.CLICK, onClick);
}
//addEventListener(MouseEvent.MOUSE_OVER, onOver);
//addEventListener(MouseEvent.MOUSE_OVER, onOver);
/* addEventListener(FlexEvent.SHOW, onShow);
addEventListener(FlexEvent.HIDE, onHide); */
//addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
}
private function onClick(e:MouseEvent):void{
Application.application.showCompany(name)
}
private function onOver(e:MouseEvent):void{
//this.toolTip = this;
return;
}
/* private function onShow(event:Event):void{
fader.alphaFrom = .5;
fader.alphaTo = 1;
if(fader.isPlaying){
fader.stop();
}
fader.play();
}
private function onHide(event:Event):void{
fader.alphaFrom = 1;
fader.alphaTo = .5;
if(fader.isPlaying){
fader.stop();
}
fader.play();
} */
public function set parentNode(node:IOrgChartNode):void{
if( node!= null){
_parent = node;
_parent.addChildNode(this);
}
}
public function get parentNode():IOrgChartNode{
return _parent;
}
public function get subNodes():ArrayCollection{
return _subNodes;
}
public function addChildNode(node:IOrgChartNode):void{
if(node != null){
node.visible = expanded;
subNodes.addItem(node);
}
}
public function removeChildNode(node:IOrgChartNode):void{
}
public function removeChildNodeAt(index:int):void{
}
public function get hasChildren():Boolean{
return subNodes.length == 0 ? false : true;
}
public function get depth():int{
if(parentNode == null){
return 0;
}else{
return parentNode.depth + 1;
}
}
public function addLine(line:DisplayObject):void{
if(line == null)return;
line.visible = expanded;
_lines.addItem(line);
_linesChanged = true;
}
public function get firstChild():IOrgChartNode{
if(subNodes.length == 0){
return null;
}else{
return subNodes.getItemAt(0) as IOrgChartNode;
}
}
public function get lastChild():IOrgChartNode{
if(subNodes.length == 0){
return null;
}else{
return subNodes.getItemAt(subNodes.length - 1) as IOrgChartNode;
}
}
public function get previousSibling():IOrgChartNode{
if(parentNode == null
|| parentNode.subNodes.length == 1
|| parentNode.subNodes.getItemIndex(this) == 0){
return null;
}else{
return parentNode.subNodes.getItemAt(parentNode.subNodes.getItemIndex(this)-1) as IOrgChartNode;
}
}
public function get nextSibling():IOrgChartNode{
if(parentNode == null){
return null;
}
var subNodes:ArrayCollection = parentNode.subNodes;
if(subNodes.length == 1){
return null;
}else if(subNodes.getItemIndex(this) == (subNodes.length - 1)){
return null;
}else{
return subNodes.getItemAt(subNodes.getItemIndex(this) + 1) as IOrgChartNode;
}
}
public function get expanded():Boolean{
return _expanded;
}
public function expand():void{
if(_expanded) return;
for(var cursor:IViewCursor=subNodes.createCursor(); !cursor.afterLast; cursor.moveNext()){
cursor.current.expand();
cursor.current.visible = true;
}
for(cursor=_lines.createCursor(); !cursor.afterLast; cursor.moveNext()){
cursor.current.visible = true;
}
_expanded = true;
}
public function collapse():void{
if(!_expanded) return;
for(var j:int=0; j<_lines.length; j++){
_lines.getItemAt(j).visible = false;
}
for(var i:int=0; i<subNodes.length; i++){
subNodes.getItemAt(i).collapse();
subNodes.getItemAt(i).visible = false;
}
_expanded = false;
}
private var _oriented:String = "v";
public function get oriented():String{
return _oriented;
}
public function set oriented(theOriented:String):void{
_oriented = theOriented;
}
public function get otherChildren():String{
return _otherChildren;
}
public function set otherChildren(otherChildren:String):void{
_otherChildren = otherChildren
}
override public function get data():Object{
return _data;
}
//[Embed(source='/images/female.png')]
//private var femaleIcon:Class;
override public function set data(value:Object):void{
_data = value;
_otherChildren = _data.@childid;
_labels = _data.@Investment;
_isShows = _data.@isshow;
name=_data.@id;
_parentLinePoints = _data.@point;
dataChanged = true;
invalidateProperties();
}
override protected function createChildren():void{
super.createChildren();
if(_textField == null){
_textField = new UITextField();
_textField.multiline = true;
_textField.wordWrap = true;
addChild(DisplayObject(_textField));
}
}
override protected function measure():void{
super.measure();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(_linesChanged){
for(var cursor:IViewCursor = _lines.createCursor(); !cursor.afterLast; cursor.moveNext()){
cursor.current.draw();
}
_linesChanged = false;
}
//Alert.show(oriented);
if(oriented == "v"){
_textField.y = 5;
_textField.height = unscaledHeight - 5;
_textField.width = unscaledWidth;
}else{
_textField.width = unscaledWidth;
_textField.height = _textField.textHeight + 4;
_textField.y = (unscaledHeight - _textField.height) / 2;
}
//make text on top tier
super.setChildIndex(DisplayObject(_textField), super.numChildren-1);
}
override protected function commitProperties():void{
super.commitProperties();
if(dataChanged && _data != null){
//Alert.show(_data.@children);
//otherChildre
name=_data.@id;
//Alert.show( _data.@childid);
_otherChildren = _data.@childid;
_labels = _data.@Investment;
_isShows = _data.@isshow;
//_parentLinePoints = _data.@point;
//Alert.show(_data.@children);
_textField.text = _data.@archivenum+"-"+_data.@cnName;
this.toolTip = _textField.text;
//_textField.toolTip = _textField.text;
if(_data.@type == "person" || _data.@type == "department"){
//tipManager = new BubbleTipManager();
// if(detailsPanel == null){
// detailsPanel = new DetailsPanel();
// detailsPanel.data = _data;
// }
//tipManager.createBubbleTip(this, "", detailsPanel);
}
if(_data.@type == "more"){
setStyle("color", "red");
//setStyle("icon", femaleIcon);
//setStyle("fontWeight", "bold");
}
if(_data.@selected=='true'){
styleName = "companyNodeSelected";
}else{
styleName = "companyNode";
}
}
}
public function set hasShow(flag:Boolean):void{
this._hasShow = flag;
}
public function get hasShow():Boolean{
return _hasShow;
}
public function getChildLine(id:String):Array{
//if()
//Alert.show(_parentLinePoints);
var childrenPoints:Array = new Array();
var childrens:Array = _parentLinePoints.split("|");
for(var i:int = 0;i<childrens.length;i++){
var pointStr:String = childrens[i];
if(pointStr.indexOf(id+"/")!=-1){
pointStr = pointStr.substr(pointStr.indexOf("/")+1,pointStr.length);
// Alert.show(pointStr+"%%%"+id);
if(pointStr!=""){
var points:Array = pointStr.split(",")
for(var i:int = 0;i<points.length;i++){
var point :Point = new Point(points[i],points[i+1])
childrenPoints.push(point);
i++;
}
}
}
}
return childrenPoints;
}
public function getChildLabel(id:String):String{
//if()
var label:String="";
//Alert.show(_parentLinePoints);
var childrenPoints:Array = new Array();
var childrens:Array = _labels.split("|");
for(var i:int = 0;i<childrens.length;i++){
var pointStr:String = childrens[i];
if(pointStr.indexOf(id+"/")!=-1){
//
pointStr = StringUtil.trim(pointStr);
pointStr = pointStr.substr(pointStr.indexOf("/")+1,pointStr.length);
//Alert.show(pointStr+"%%%"+id.length+"%%%"+pointStr.length);
label = pointStr;
}
}
return label;
}
public function getChildIsShow(id:String):String{
var isshow:String="";
//Alert.show(_parentLinePoints);
var childrenPoints:Array = new Array();
var childrens:Array = _isShows.split("|");
for(var i:int = 0;i<childrens.length;i++){
var pointStr:String = childrens[i];
if(pointStr.indexOf(id+"/")!=-1){
pointStr = pointStr.substr(pointStr.indexOf("/")+1,pointStr.length);
//Alert.show(pointStr+"%%%"+id);
isshow = pointStr;
}
}
return isshow;
}
}
}