@@ -21,10 +21,29 @@ var ClassView = function (parent, container) {
21
21
this . CLASS_DOC_PATH = "/csp/documatic/%25CSP.Documatic.cls" ;
22
22
this . SYMBOL_12_WIDTH = 6.6 ;
23
23
24
+ this . HIGHLIGHTED_VIEW = null ;
25
+ this . SEARCH_INDEX = 0 ;
26
+
24
27
this . init ( ) ;
25
28
26
29
} ;
27
30
31
+ ClassView . prototype . highlightElement = function ( jointElement ) {
32
+
33
+ if ( this . HIGHLIGHTED_VIEW || ( ! jointElement && this . HIGHLIGHTED_VIEW ) ) {
34
+ this . HIGHLIGHTED_VIEW . unhighlight ( ) ;
35
+ this . HIGHLIGHTED_VIEW = null ;
36
+ }
37
+
38
+ if ( ! jointElement ) return ;
39
+ var view = this . paper . findViewByModel ( jointElement ) ;
40
+ if ( ! view ) return ;
41
+
42
+ view . highlight ( ) ;
43
+ this . HIGHLIGHTED_VIEW = view ;
44
+
45
+ } ;
46
+
28
47
ClassView . prototype . showLoader = function ( html ) {
29
48
30
49
var d2 ;
@@ -60,6 +79,9 @@ ClassView.prototype.resetView = function () {
60
79
this . objects = [ ] ;
61
80
this . paper . setOrigin ( 0 , 0 ) ;
62
81
this . graph . clear ( ) ;
82
+ this . HIGHLIGHTED_VIEW = null ;
83
+ this . SEARCH_INDEX = 0 ;
84
+ this . cacheUMLExplorer . elements . diagramSearch . value = "" ;
63
85
64
86
} ;
65
87
@@ -268,6 +290,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
268
290
var classParams = classMetaData [ "parameters" ] ,
269
291
classProps = classMetaData [ "properties" ] ,
270
292
classMethods = classMetaData [ "methods" ] ,
293
+ keyWordsArray = [ name ] ,
271
294
self = this ;
272
295
273
296
var classInstance = new joint . shapes . uml . Class ( {
@@ -283,6 +306,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
283
306
params : ( function ( params ) {
284
307
var arr = [ ] , n ;
285
308
for ( n in params ) {
309
+ keyWordsArray . push ( n ) ;
286
310
arr . push ( {
287
311
text : n + ( params [ n ] [ "type" ] ? ": " + params [ n ] [ "type" ] : "" )
288
312
} ) ;
@@ -292,6 +316,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
292
316
attributes : ( function ( ps ) {
293
317
var arr = [ ] , n ;
294
318
for ( n in ps ) {
319
+ keyWordsArray . push ( n ) ;
295
320
arr . push ( {
296
321
text : n + ( ps [ n ] [ "type" ] ? ": " + ps [ n ] [ "type" ] : "" ) ,
297
322
icons : self . getMethodIcons ( ps [ n ] )
@@ -302,6 +327,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
302
327
methods : ( function ( met ) {
303
328
var arr = [ ] , n ;
304
329
for ( n in met ) {
330
+ keyWordsArray . push ( n ) ;
305
331
arr . push ( {
306
332
text : n + ( met [ n ] [ "returns" ] ? ": " + met [ n ] [ "returns" ] : "" ) ,
307
333
styles : ( function ( t ) {
@@ -319,6 +345,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
319
345
SYMBOL_12_WIDTH : self . SYMBOL_12_WIDTH
320
346
} ) ;
321
347
348
+ classInstance . SEARCH_KEYWORDS = keyWordsArray . join ( "," ) . toLowerCase ( ) ;
322
349
this . objects . push ( classInstance ) ;
323
350
this . graph . addCell ( classInstance ) ;
324
351
@@ -562,6 +589,69 @@ ClassView.prototype.zoom = function (delta) {
562
589
563
590
} ;
564
591
592
+ /**
593
+ * Focus on joint instance.
594
+ * @param jointInstance
595
+ */
596
+ ClassView . prototype . focusOnInstance = function ( jointInstance ) {
597
+
598
+ var bb = jointInstance . getBBox ( ) ;
599
+
600
+ this . focusOnXY ( bb . x + bb . width / 2 , bb . y + bb . height / 2 ) ;
601
+
602
+ } ;
603
+
604
+ /**
605
+ * Focus on x and y coordinates considering scale.
606
+ * @param {number } x
607
+ * @param {number } y
608
+ */
609
+ ClassView . prototype . focusOnXY = function ( x , y ) {
610
+
611
+ var sw = this . cacheUMLExplorer . elements . classViewContainer . offsetWidth ,
612
+ sh = this . cacheUMLExplorer . elements . classViewContainer . offsetHeight ,
613
+ scale = this . PAPER_SCALE ;
614
+
615
+ this . paper . setOrigin (
616
+ - ( x * scale ) + sw / 2 ,
617
+ - ( y * scale ) + sh / 2
618
+ ) ;
619
+
620
+ } ;
621
+
622
+ /**
623
+ * Find text on diagram and focus on element.
624
+ *
625
+ * @param {string } text
626
+ */
627
+ ClassView . prototype . searchOnDiagram = function ( text ) {
628
+
629
+ var p , found = [ ] , o ;
630
+
631
+ if ( ! text ) {
632
+ this . highlightElement ( null ) ;
633
+ return ;
634
+ }
635
+
636
+ text = text . toLowerCase ( ) ;
637
+
638
+ for ( p in this . objects ) {
639
+ if ( this . objects [ p ] . SEARCH_KEYWORDS . indexOf ( text ) !== - 1 ) {
640
+ found . push ( this . objects [ p ] ) ;
641
+ }
642
+ }
643
+
644
+ if ( found . length ) {
645
+ o = found [ this . SEARCH_INDEX % found . length ] ;
646
+ this . focusOnInstance ( o ) ;
647
+ this . highlightElement ( o ) ;
648
+ return ;
649
+ }
650
+
651
+ this . highlightElement ( null ) ;
652
+
653
+ } ;
654
+
565
655
ClassView . prototype . init = function ( ) {
566
656
567
657
var p , self = this ,
@@ -635,6 +725,19 @@ ClassView.prototype.init = function () {
635
725
this . cacheUMLExplorer . elements . helpButton . addEventListener ( "click" , function ( ) {
636
726
self . renderInfoGraphic ( ) ;
637
727
} ) ;
728
+ this . cacheUMLExplorer . elements . diagramSearch . addEventListener ( "input" , function ( e ) {
729
+ self . searchOnDiagram ( ( e . target || e . srcElement ) . value ) ;
730
+ } ) ;
731
+ this . cacheUMLExplorer . elements . diagramSearch . addEventListener ( "keydown" , function ( e ) {
732
+ if ( e . keyCode === 13 ) {
733
+ self . SEARCH_INDEX ++ ;
734
+ self . searchOnDiagram ( ( e . target || e . srcElement ) . value ) ;
735
+ }
736
+ } ) ;
737
+ this . cacheUMLExplorer . elements . diagramSearchButton . addEventListener ( "click" , function ( ) {
738
+ self . SEARCH_INDEX ++ ;
739
+ self . searchOnDiagram ( self . cacheUMLExplorer . elements . diagramSearch . value ) ;
740
+ } ) ;
638
741
639
742
this . SYMBOL_12_WIDTH = ( function ( ) {
640
743
var e = document . createElementNS ( "http://www.w3.org/2000/svg" , "text" ) ,
0 commit comments