tools/JavaCodeBundleEditor.st
branchdevelopment
changeset 2392 692a6e18e95e
parent 2391 b4a008ed9bc4
child 2429 ebece4dcaab9
--- a/tools/JavaCodeBundleEditor.st	Fri Feb 22 00:34:22 2013 +0000
+++ b/tools/JavaCodeBundleEditor.st	Fri Feb 22 16:06:12 2013 +0000
@@ -359,12 +359,14 @@
 !
 
 updateTree
-    self bundleTree root:
-        (Item libraryOrBundle: self bundleHolder value parent: nil).
+    self bundleTree root notNil ifTrue:[
+        self bundleTree removeAll; root: nil.
+    ].
+    self bundleTree root: (Item libraryOrBundle: self bundleHolder value parent: nil).
     self bundleTree root expand.
 
     "Created: / 25-01-2013 / 21:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 28-01-2013 / 20:35:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-02-2013 / 14:01:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaCodeBundleEditor methodsFor:'hooks'!
@@ -378,7 +380,7 @@
 !JavaCodeBundleEditor methodsFor:'menu actions'!
 
 doAdd: libraryOrBundle
-    | libraryOrBundleItem parent parentItem |
+    | parent parentItem |
 
     parentItem := self bundleTreeSelectionHolder value.
     parentItem isNil ifTrue:[
@@ -392,39 +394,38 @@
 
     parent add: libraryOrBundle.
 
-    libraryOrBundleItem := Item libraryOrBundle: libraryOrBundle parent: parentItem.
-    parentItem add: libraryOrBundleItem.
     parentItem expand.
 
-    self bundleTreeSelectionHolder value: libraryOrBundleItem.
+    self doSelect: libraryOrBundle.
     self updateModifiedChannel
 
     "Created: / 30-01-2013 / 17:20:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 21-02-2013 / 23:44:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-02-2013 / 15:36:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doAddBundle
     | name bundle |
 
     name := Dialog request: (resources string: 'Enter name of new bundle').
-    name isNil ifTrue:[^self].
+    name isEmptyOrNil ifTrue:[^self].
     bundle := JavaCodeBundle new.
     bundle name: name.
 
     self doAdd: bundle
 
-    "Modified: / 30-01-2013 / 17:20:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-02-2013 / 13:19:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doAddLibrary
     | dialog |
 
     dialog := JavaCodeLibraryEditor new.
-    dialog open ifTrue:[
+    dialog open.
+    dialog accepted ifTrue:[
         self doAdd: dialog acceptedValue.
     ]
 
-    "Modified: / 21-02-2013 / 23:30:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-02-2013 / 13:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 doBrowseFiles
@@ -464,12 +465,25 @@
     parent := parentItem libraryOrBundle.
 
     parent remove: sel.
-    parentItem remove: selItem.
+    parent libraries size > 0 ifTrue:[
+        parentItem expand.
+    ].
 
-    self bundleTreeSelectionHolder value: parentItem.
+    self doSelect: parent.
     self updateModifiedChannel
 
-    "Modified: / 30-01-2013 / 17:22:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 22-02-2013 / 15:53:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+doSelect: libraryOrBundle
+    self bundleTree root recursiveDo:[:e|
+        e libraryOrBundle == libraryOrBundle ifTrue:[
+            self bundleTreeSelectionHolder value: e.
+            ^self
+        ]
+    ]
+
+    "Created: / 22-02-2013 / 15:36:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaCodeBundleEditor::Item class methodsFor:'instance creation'!
@@ -500,8 +514,55 @@
     ^ libraryOrBundle
 !
 
-libraryOrBundle:something
-    libraryOrBundle := something.
+libraryOrBundle:aJavaCodeLibraryOrBundle
+    libraryOrBundle notNil ifTrue:[
+        libraryOrBundle removeDependent: self
+    ].
+    libraryOrBundle := aJavaCodeLibraryOrBundle.
+    libraryOrBundle notNil ifTrue:[
+        libraryOrBundle addDependent: self
+    ].
+
+    "Modified: / 22-02-2013 / 15:19:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!JavaCodeBundleEditor::Item methodsFor:'change & update'!
+
+update:aspect with: parameter from:changedObject
+    "Invoked when an object that I depend upon sends a change notification."
+
+    changedObject == libraryOrBundle ifTrue:[
+        self updateChildren.
+        ^ self.
+    ].
+    super update:aspect with:parameter from:changedObject
+
+    "Modified: / 22-02-2013 / 15:20:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+updateChildren
+    | oldChildren newChildren |
+
+    children isNil ifTrue:[
+        self children: self fetchChildren.
+        ^self.
+    ].
+    libraryOrBundle isLibrary ifTrue:[ ^ self ].
+
+
+    oldChildren := children copy.
+    newChildren := OrderedCollection new.
+    libraryOrBundle libraries do:[:e|
+        | item |
+
+        item := oldChildren 
+                detect:[:item|item libraryOrBundle == e] 
+                ifNone:[self class libraryOrBundle:e parent: self].
+        newChildren add: item.
+    ].
+    self children: newChildren
+
+    "Created: / 22-02-2013 / 15:20:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaCodeBundleEditor::Item methodsFor:'protocol-accessing'!