Populate Class Hierarchy in ListBox

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Alan >> Wed, 12 Nov 2008 20:18:05 GMT

We have an application that populates a list box with a class hierarchy. The problem is it appears to be taking an excessively long time (over a minute for 1400 entries). The Jade class browser does the same thing considerably quicker.

We do need to work across the schema hierarchy as well as the class hierarchy. We use recursion to build the listbox but am not sure if we are using the correct collections etc.

attached is a slightly cut down version of the method we are using - would appreciate any advice that would help in speeding this up.
Attachments
5453.mth
(1.91 KiB) Downloaded 94 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 4:33 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Allistar >> Wed, 12 Nov 2008 20:48:18 GMT

Hi Alan,
If I were doing this I would only populate the top level classes (i.e. those directly underneath "Object") and only populate subclasses of those top level classes when the use expands that item in the list box. You can add a dummy entry underneath classes that have subclasses to get the ListBox to put a "+" next to it. Doing it this way will improve load performance. You can use the Class::getSubclasses method to retrieve the direct subclasses of a class. Of course, this means that by default the class hierarchy will not be expanded.

You'll also need some way of working out which top level classes to add to the list box as a lot of them will not be defined in your schema. Ideally you'd want to add all classes in all superschemas that have a class in your schema as a descendant of it. Examples
are "Window", "Application", "Global" etc.

I'm not sure how the Jade IDE does it so fast. Perhaps part of this has been put into an external dll? Of perhaps there is metadata that has precalculated the positioning etc. in the hierarchy?

Allistar.
--
A.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Tim M >> Wed, 12 Nov 2008 21:32:10 GMT

No text entered

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Tim M >> Wed, 12 Nov 2008 21:35:27 GMT

Sorry for the double post but my last one appeared blank. What I said in the previous was:

I haven't look at your method yet but I found it real fast first time I did this. I've attached a schema that is did in 6.0 but should work in 6.1 and 6.2. I wrote so I could quickly find some of the Jade hidden methods incase they were any use to me but those hidden methods should be used the with great caution and probably not for production use as they could change without warning.
Attachments
5456.rar
(11.76 KiB) Downloaded 97 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 4:33 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Alan >> Thu, 13 Nov 2008 0:25:26 GMT

Thanks for the help guys
Tim, your code is simpler than mine so I will implement that (the load times are very close - which means its all the additional stuff I am doing that is causing the problem)
Allistar, I will have a look at implementing your idea - I expect when we establish a pattern for this it should be fairly straight forward :-)

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Dean Cooper >> Thu, 13 Nov 2008 17:52:45 GMT

The JADE IDE does what Allistar suggests and populates/expands only the required levels in the hierarchy. It's all implemented in JADE code - none of the Class Hierarchy Browser is implemented in an external DLL.

Dean.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Alan >> Fri, 14 Nov 2008 7:27:57 GMT

Dean, would you be willing (able?) to make that piece of code available? - would save a bit of work

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Dean Cooper >> Tue, 18 Nov 2008 1:00:41 GMT

Hi Alan,

I think the performance issue you're encountering is to do with the calls to allLocalSubclasses. This method returns *all* subclasses for the receiver class (not just the first level), so when you call it initially for Object, it's populating a transient collection with all classes in the schema. Each time you recursively call classListBuild, allLocalSubclasses is getting the entire subclass branch again for each class in the next level, even though you only need the classes in the level that you're dealing with. For a large schema, this will be creating, populating and deleting a lot of transient collections that you can avoid. You can also avoid the calls to refreshNow.

Attached is a RAR of a 6.1.14 schema with an example form that demonstrates a class hierarchy list box. It's not the code out of the JADE IDE, but it works in a similar way. Run the default app in the schema, pick a schema from the combo at the top of the form and the list box will be populated with the classes. The list box population starts in the ClassListExampleForm::loadClassHierarchy method. This method will add "Object" and it's immediate subclasses by calling the expandItem method. When an entry in the list is expanded, the required subclasses are added at that point (see lstClasses_dblClick, lstClasses_pictureClick and expandItem). The expandItem method is also used to collapse an entry in the list box. When a class is selected, its name and number is shown in the status line (see lstClasses_click and selectClass).

The code makes use of the Class::subclasses dictionary that every class has. This is a protected property, but you can access it via a method on Class (see the Class::getSubclassesDict subschema copy method). This gives you a direct/fast way of accessing the immediate subclasses of a class without requiring a transient collection and without having to retrieve all subclasses for a class.

Hope this helps.

Cheers,
Dean.

PS: When you run the app, if you see a message saying "You are running a GUI application that has no startup form", just click Continue and the app will run ok. This is probably because I've built the schema using the English (UK) locale and that's not your default locale. It's a glitch that has been fixed in a future release.
Attachments
5462_1.rar
(6.58 KiB) Downloaded 94 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 4:34 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox - updated example schema

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Dean Cooper >> Tue, 18 Nov 2008 11:30:10 GMT

Just further to my previous post. The prevously attached schema contained a bunch of test remap tables. While they don't do any harm at all, they're just "noise" that can end up being extracted in other schemas if you don't uncheck "Extract Remap Tables" on the "Schema Options" sheet of the JADE 6.1 Schema Extract form. A new schema is attached with the remap tables removed. If you've loaded the previous schema in 6.1, you can use Browse | Remap Tables to delete them.

Dean.


<Dean Cooper (JADE Tech General)> wrote in message news:5462@news.jadeworld.com...

Hi Alan,

I think the performance issue you're encountering is to do with the calls to allLocalSubclasses. This method returns *all* subclasses for the receiver class (not just the first level), so when you call it initially for Object, it's populating a transient collection with all classes in the schema. Each time you recursively call classListBuild, allLocalSubclasses is getting the entire subclass branch again for each class in the next level, even though you only need the classes in the level that you're dealing with. For a large schema, this will be creating, populating and deleting a lot of transient collections that you can avoid. You can also avoid the calls to refreshNow.

Attached is a RAR of a 6.1.14 schema with an example form that demonstrates a class hierarchy list box. It's not the code out of the JADE IDE, but it works in a similar way. Run the default app in the schema, pick a schema from the combo at the top of the form and the list box will be populated with the classes. The list box population starts in the ClassListExampleForm::loadClassHierarchy method. This method will add "Object" and it's immediate subclasses by calling the expandItem method. When an entry in the list is expanded, the required subclasses are added at that point (see lstClasses_dblClick, lstClasses_pictureClick and expandItem). The expandItem method is also used to collapse an entry in the list box. When a class is selected, its name and number is shown in the status line (see lstClasses_click and selectClass).

The code makes use of the Class::subclasses dictionary that every class has. This is a protected property, but you can access it via a method on Class (see the Class::getSubclassesDict subschema copy method). This gives you a direct/fast way of accessing the immediate subclasses of a class without requiring a transient collection and without having to retrieve all subclasses for a class.

Hope this helps.

Cheers,
Dean.

PS: When you run the app, if you see a message saying "You are running a GUI application that has no startup form", just click Continue and the app will run ok. This is probably because I've built the schema using the English (UK) locale and that's not your default locale. It's a glitch that has been fixed in a future release.
Attachments
5463_1.rar
(6.35 KiB) Downloaded 86 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 4:34 pm, edited 1 time in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Populate Class Hierarchy in ListBox - updated example schema

Postby ConvertFromOldNGs » Fri Aug 07, 2009 1:24 pm

by Alan >> Wed, 19 Nov 2008 7:37:45 GMT

Thanks for your efforts Dean - will try to apply code in next couple of days


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 32 guests