Flex: Updating a Tree control
I've found the Tree control a little touchy in Flex. The way I ended up forcing a redraw was to disconnect the dataProvider and reconnect it, then force validation, something a bit like this :
private function forceRedraw(tree:Tree, dataProvider:Object):void
{
var scrollPosition:Number = tree.verticalScrollPosition;
var openItems:Object = tree.openItems;
tree.dataProvider = dataProvider;
tree.openItems = openItems;
tree.validateNow();
tree.verticalScrollPosition = scrollPosition;
}
I guess this incidentally answers the second part of your question since all you'd have to do is null out the openItems collection and set the verticalScrollPosition to 0.
PProteus
Updated on August 22, 2022Comments
-
PProteus almost 2 years
I have a large set of objects, and I need to be able to do some complex stuff with each object, so I have some fairly long functions.
In general, is it better to put the long functions in the class that they'll actually be used in (
GreatObject
, below) for proper encapsulation, or is it better for efficiency to put one function in the collection class (GreatSet
, which will only ever have one instance)?class GreatSet(object): def __init__(self): self.great_set = [] # Will contain a lot of GreatObjects. def long_method(self, great_object): # Is this function better here? [Many lines of code] class GreatObject(object): def __init__(self, params): self.params = params def.long_method(self): # Or here? [Many lines of code]
I'm using Python 2.7.
-
PartialOrder over 7 yearsIn general, it belongs with the object. How may objects will be instantiated at a given time? How long is long? Long method is a code smell. Perhaps you should consider refactoring. Then, if still you are concerned about cost of instantiation do some testing of different implementations.
-
PProteus over 7 yearsThere could be up to 400 objects. There are a few methods—let's say altogether they are 300 lines of code. I'm not sure how Python handles this sort of thing, but that could be the equivalent of 120000 LOC, right?
-
bruno desthuilliers over 7 years@PProteus totally wrong - the code (the executable bytecode compiled from your sources) is of course shared between objects, you don't have one instance of the "long_method" function's code for each instance xD
-
PProteus over 7 yearsThank you, Bruno. That seems like the better way to do it, but I have practically no knowledge of that level of the language.
-
-
Chrisg over 15 yearsIt depends how many items you have in the tree. Do you have a large tree being displayed and have you actually scrolled when you're trying to force a redraw?
-
Mes over 15 yearsYes, even when the Tree is scrolled the verticalScrollPosition is still 0.
-
Roopesh Shenoy almost 13 years2 years down, and this is still useful! awesome!
-
Roopesh Shenoy over 12 yearsthis is good for stackoverflow but bad for Flex if they have still not fixed this issue.
-
the_new_mr about 12 yearsAce! +1 for three years on. Thanks inferis! Was going crazy trying to fix this. You saved me!