« Return to Thread: Dynamic TopComponent

Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View in Thread

I]ark wrote:

> Tonny Kohar ha scritto:
>> Hi,
>>
>> On Wed, May 13, 2009 at 12:18 AM, I]ark
>> <another_half_life@...> wrote:
>>  
>>> Hello, I would like to know if making a TopComponent dynamic , and
>>> creating
>>> different instances with different PREFERRED_ID, i can somehow find
>>> it in my
>>> application. As you type for singleton with WindowManager.getDefault
>>> ().FindTopComponent(tcID)
>>>
>>>    
>>
>> I am not understand what you mean by dynamic TopComponent.
>> But TopComponent does not necesarrily need to be singleton. You can
>> easily create TopComponent which can be always be created the
>> instance. For example, TopComponent in the Editor Mode (eg: display
>> the content of file aka Java Editor or XML editor)
>>
>> Cheers
>> Tonny Kohar
>> --
>> Sketsa SVG Editor
>> imagine, design, create ...
>> http://www.kiyut.com
>    Sorry for my English, I try to explain better.
> I know how to create a dynamic TopComponent and set for each instance
> a different PREFERRED_ID, but I would like to know if i can call it
> from the platform, once created, and subsequently closed. For example,
> as is done with the singleton using method " WindowManager.getDefault
> ().FindTopComponent(tcID) "
TC ID must be unique. If TC is persistent it is usually defined in
module layer. This way TC has its own fixed and unique ID which can be used
to get TC instance.

If you have TC which is not singleton and you create its instances in
runtime then its actual ID can be (and will be) different from string
returned
from method TC.preferredID. Eg. if you create first instance of this TC
class which returns "mytc" from preferredID then winsys first looks
in its set of used IDs if this ID is already used:
a) if not actual TC ID will be "mytc". If yes then winsys tries to add
number suffix "_X" till it is unique.
b) If you create second TC instance and first instance has ID "mytc"
then second instance will get ID "mytc_1".

You can get ID for TC instance using
WindowManager.getDefault().findTopComponentID(TopComponent)

If you have persistent type PERSISTENCE_ALWAYS then TC will live forever
once you dock it into any mode (ie. register it
in winsys). There is currently no way how to 'unregister' persistent TC
from winsys once it is docked into any mode.

Marek

 

 « Return to Thread: Dynamic TopComponent