Refactoring of NavigatorModel's environment.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 25 Feb 2014 11:41:59 +0100
changeset 14030 d13f6b1ea9b9
parent 14029 50d760740995
child 14031 8bdb5f42adc9
Refactoring of NavigatorModel's environment. The environment is taken from an environmentHolder (if provided) or defaults to Smalltalk (if holder is not provided)
Tools_NavigatorModel.st
--- a/Tools_NavigatorModel.st	Tue Feb 25 11:41:53 2014 +0100
+++ b/Tools_NavigatorModel.st	Tue Feb 25 11:41:59 2014 +0100
@@ -14,7 +14,7 @@
 "{ NameSpace: Tools }"
 
 ApplicationModel subclass:#NavigatorModel
-	instanceVariableNames:'environment'
+	instanceVariableNames:'environmentHolder environment'
 	classVariableNames:'AllEntry SuperSendEntry UncommentedEntry'
 	poolDictionaries:''
 	category:'Interface-Browsers-New'
@@ -346,6 +346,17 @@
     ^ NewSystemBrowser classResources
 ! !
 
+!NavigatorModel class methodsFor:'plugIn spec'!
+
+aspectSelectors
+
+    ^#(
+        environmentHolder
+    )
+
+    "Created: / 24-02-2014 / 10:35:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !NavigatorModel class methodsFor:'queries'!
 
 hasSubversionSupport
@@ -371,33 +382,67 @@
 !
 
 environment:env
-    self assert:env notNil.
-    environment := env.
+    self environmentHolder value: env.
+
+    "Modified: / 24-02-2014 / 10:21:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!NavigatorModel methodsFor:'hooks'!
+!NavigatorModel methodsFor:'aspects'!
+
+environmentHolder
+    "return/create the 'environmentHolder' value holder (automatically generated)"
 
-commonPreBuild
-    | topApp envFromTopApp |
+    environmentHolder isNil ifTrue:[
+        environmentHolder := ValueHolder new.
+        environmentHolder addDependent:self.
+    ].
+    ^ environmentHolder
+!
+
+environmentHolder:aValueModel
+    "set the 'environmentHolder' value holder (automatically generated)"
+
+    |oldValue newValue|
 
-    super commonPreBuild.
-    topApp := self topApplication.
-    (topApp notNil and:[topApp ~~ self]) ifTrue:[
-        "Fetch the environment from the top application, fallback to previous environment"
-        "/ HACK alert: it is very bad if a component fetches info from its container itself,
-        "/ instead of being passed down explicitely.And especially bad, if it is done in the way below
-        "/ noone would ever know, that environment is now part of a contract with the component.
-        "/ THIS needs change!!
+    environmentHolder notNil ifTrue:[
+        oldValue := environmentHolder value.
+        environmentHolder removeDependent:self.
+    ].
+    environmentHolder := aValueModel.
+    environmentHolder notNil ifTrue:[
+        environmentHolder addDependent:self.
+    ].
+    newValue := environmentHolder value.
+    oldValue ~~ newValue ifTrue:[
+        self update:#value with:newValue from:environmentHolder.
+    ].
+! !
+
+!NavigatorModel methodsFor:'change & update'!
+
+environmentChanged
+    "My environment has changed. Update cached environment value.
+     Subclasses may need to override and invalidate it's contents."
 
-        envFromTopApp := topApp perform:#environment ifNotUnderstood:[environment].
-        "/ fails if the topApp does sth. different with environmen!!!!!!!!
-        (envFromTopApp isNameSpace or:[envFromTopApp == Smalltalk]) ifTrue:[
-            self environment: envFromTopApp
-        ]
-    ]
+    | env |
+
+    env := environmentHolder value.
+    environment := env.
+
+    "Created: / 24-02-2014 / 10:18:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-02-2014 / 23:34:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
 
-    "Created: / 03-09-2013 / 16:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (format): / 03-09-2013 / 18:31:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+update:something with:aParameter from:changedObject
+    "Invoked when an object that I depend upon sends a change notification."
+
+    changedObject == environmentHolder ifTrue:[
+        self environmentChanged.
+        ^ self.
+    ].
+    super update:something with:aParameter from:changedObject
+
+    "Modified: / 24-02-2014 / 10:18:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !NavigatorModel methodsFor:'initialization'!
@@ -408,6 +453,7 @@
     super initialize.
 
     "Created: / 03-09-2013 / 15:35:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 24-02-2014 / 23:27:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !NavigatorModel methodsFor:'misc'!
@@ -435,11 +481,11 @@
 !NavigatorModel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Tools_NavigatorModel.st,v 1.28 2014-02-22 12:40:43 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools_NavigatorModel.st,v 1.29 2014-02-25 10:41:59 vrany Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools_NavigatorModel.st,v 1.28 2014-02-22 12:40:43 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools_NavigatorModel.st,v 1.29 2014-02-25 10:41:59 vrany Exp $'
 !
 
 version_HG
@@ -448,7 +494,7 @@
 !
 
 version_SVN
-    ^ '$Id: Tools_NavigatorModel.st,v 1.28 2014-02-22 12:40:43 cg Exp $'
+    ^ '$Id: Tools_NavigatorModel.st,v 1.29 2014-02-25 10:41:59 vrany Exp $'
 ! !