1
+ /* ************************************************************************
2
+ Copyright: 2018 ITIS Foundation
3
+ License: MIT
4
+ Authors: Odei Maiz <[email protected] >
5
+ Utf8Check: äöü
6
+ ************************************************************************ */
7
+
8
+ /**
9
+ * Creates the widget that shows the outputs of the node in a key: value way.
10
+ * If the value is an object, it will show the internal key-value pairs
11
+ * [PortLabel]: [PortValue]
12
+ *
13
+ */
14
+
1
15
qx . Class . define ( "qxapp.component.widget.inputs.NodeOutputLabel" , {
2
16
extend : qx . ui . core . Widget ,
3
17
@@ -6,15 +20,28 @@ qx.Class.define("qxapp.component.widget.inputs.NodeOutputLabel", {
6
20
7
21
this . setNodeModel ( nodeModel ) ;
8
22
9
- let toolTip = new qx . ui . tooltip . ToolTip ( port . description ) ;
10
- let portLabel = this . __portLabel = new qx . ui . basic . Label ( port . label ) . set ( {
11
- toolTip : toolTip ,
12
- textAlign : "right" ,
13
- allowGrowX : true ,
14
- paddingRight : 20
23
+ this . _setLayout ( new qx . ui . layout . HBox ( 5 ) ) ;
24
+
25
+ let portLabel = this . _createChildControlImpl ( "portLabel" ) ;
26
+ portLabel . set ( {
27
+ value : "<b>" + port . label + "</b>: " ,
28
+ toolTip : new qx . ui . tooltip . ToolTip ( port . description )
29
+ } ) ;
30
+
31
+ let portOutput = this . _createChildControlImpl ( "portOutput" ) ;
32
+ let outputValue = "Unknown value" ;
33
+ if ( Object . prototype . hasOwnProperty . call ( port , "value" ) ) {
34
+ if ( typeof port . value === "object" ) {
35
+ outputValue = this . __pretifyObject ( port . value ) ;
36
+ } else {
37
+ outputValue = JSON . stringify ( port . value ) ;
38
+ }
39
+ }
40
+ portOutput . set ( {
41
+ value : outputValue
15
42
} ) ;
16
43
17
- this . __createDragMechanism ( portLabel , portKey ) ;
44
+ this . __createDragMechanism ( this , portKey ) ;
18
45
} ,
19
46
20
47
properties : {
@@ -25,7 +52,39 @@ qx.Class.define("qxapp.component.widget.inputs.NodeOutputLabel", {
25
52
} ,
26
53
27
54
members : {
28
- __portLabel : null ,
55
+ _createChildControlImpl : function ( id ) {
56
+ let control ;
57
+ switch ( id ) {
58
+ case "portLabel" : {
59
+ const title14Font = qx . bom . Font . fromConfig ( qxapp . theme . Font . fonts [ "title-14" ] ) ;
60
+ control = new qx . ui . basic . Label ( ) . set ( {
61
+ font : title14Font ,
62
+ textAlign : "right" ,
63
+ allowGrowX : true ,
64
+ padding : 15 ,
65
+ rich : true
66
+ } ) ;
67
+ this . _add ( control , {
68
+ flex : 1
69
+ } ) ;
70
+ break ;
71
+ }
72
+ case "portOutput" : {
73
+ const title14Font = qx . bom . Font . fromConfig ( qxapp . theme . Font . fonts [ "title-14" ] ) ;
74
+ control = new qx . ui . basic . Label ( ) . set ( {
75
+ font : title14Font ,
76
+ textAlign : "right" ,
77
+ allowGrowX : true ,
78
+ padding : 15 ,
79
+ rich : true
80
+ } ) ;
81
+ this . _add ( control ) ;
82
+ break ;
83
+ }
84
+ }
85
+
86
+ return control || this . base ( arguments , id ) ;
87
+ } ,
29
88
30
89
__createDragMechanism : function ( uiPort , portKey ) {
31
90
uiPort . setDraggable ( true ) ;
@@ -40,8 +99,21 @@ qx.Class.define("qxapp.component.widget.inputs.NodeOutputLabel", {
40
99
} , this ) ;
41
100
} ,
42
101
102
+ __pretifyObject : function ( object ) {
103
+ let myText = "" ;
104
+ const entries = Object . entries ( object ) ;
105
+ for ( let i = 0 ; i < entries . length ; i ++ ) {
106
+ const entry = entries [ i ] ;
107
+ myText += String ( entry [ 0 ] ) ;
108
+ myText += ": " ;
109
+ myText += String ( entry [ 1 ] ) ;
110
+ myText += "<br/>" ;
111
+ }
112
+ return myText ;
113
+ } ,
114
+
43
115
getOutputWidget : function ( ) {
44
- return this . __portLabel ;
116
+ return this ;
45
117
}
46
118
}
47
119
} ) ;
0 commit comments