@@ -21,10 +21,29 @@ var ClassView = function (parent, container) {
2121 this . CLASS_DOC_PATH = "/csp/documatic/%25CSP.Documatic.cls" ;
2222 this . SYMBOL_12_WIDTH = 6.6 ;
2323
24+ this . HIGHLIGHTED_VIEW = null ;
25+ this . SEARCH_INDEX = 0 ;
26+
2427 this . init ( ) ;
2528
2629} ;
2730
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+
2847ClassView . prototype . showLoader = function ( html ) {
2948
3049 var d2 ;
@@ -60,6 +79,9 @@ ClassView.prototype.resetView = function () {
6079 this . objects = [ ] ;
6180 this . paper . setOrigin ( 0 , 0 ) ;
6281 this . graph . clear ( ) ;
82+ this . HIGHLIGHTED_VIEW = null ;
83+ this . SEARCH_INDEX = 0 ;
84+ this . cacheUMLExplorer . elements . diagramSearch . value = "" ;
6385
6486} ;
6587
@@ -268,6 +290,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
268290 var classParams = classMetaData [ "parameters" ] ,
269291 classProps = classMetaData [ "properties" ] ,
270292 classMethods = classMetaData [ "methods" ] ,
293+ keyWordsArray = [ name ] ,
271294 self = this ;
272295
273296 var classInstance = new joint . shapes . uml . Class ( {
@@ -283,6 +306,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
283306 params : ( function ( params ) {
284307 var arr = [ ] , n ;
285308 for ( n in params ) {
309+ keyWordsArray . push ( n ) ;
286310 arr . push ( {
287311 text : n + ( params [ n ] [ "type" ] ? ": " + params [ n ] [ "type" ] : "" )
288312 } ) ;
@@ -292,6 +316,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
292316 attributes : ( function ( ps ) {
293317 var arr = [ ] , n ;
294318 for ( n in ps ) {
319+ keyWordsArray . push ( n ) ;
295320 arr . push ( {
296321 text : n + ( ps [ n ] [ "type" ] ? ": " + ps [ n ] [ "type" ] : "" ) ,
297322 icons : self . getMethodIcons ( ps [ n ] )
@@ -302,6 +327,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
302327 methods : ( function ( met ) {
303328 var arr = [ ] , n ;
304329 for ( n in met ) {
330+ keyWordsArray . push ( n ) ;
305331 arr . push ( {
306332 text : n + ( met [ n ] [ "returns" ] ? ": " + met [ n ] [ "returns" ] : "" ) ,
307333 styles : ( function ( t ) {
@@ -319,6 +345,7 @@ ClassView.prototype.createClassInstance = function (name, classMetaData) {
319345 SYMBOL_12_WIDTH : self . SYMBOL_12_WIDTH
320346 } ) ;
321347
348+ classInstance . SEARCH_KEYWORDS = keyWordsArray . join ( "," ) . toLowerCase ( ) ;
322349 this . objects . push ( classInstance ) ;
323350 this . graph . addCell ( classInstance ) ;
324351
@@ -562,6 +589,69 @@ ClassView.prototype.zoom = function (delta) {
562589
563590} ;
564591
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+
565655ClassView . prototype . init = function ( ) {
566656
567657 var p , self = this ,
@@ -635,6 +725,19 @@ ClassView.prototype.init = function () {
635725 this . cacheUMLExplorer . elements . helpButton . addEventListener ( "click" , function ( ) {
636726 self . renderInfoGraphic ( ) ;
637727 } ) ;
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+ } ) ;
638741
639742 this . SYMBOL_12_WIDTH = ( function ( ) {
640743 var e = document . createElementNS ( "http://www.w3.org/2000/svg" , "text" ) ,
0 commit comments