I]ark wrote:
>
>> 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
>
> Now it is much more clear the mechanism, there is a way to avoid it to
> appear the message like: "INFO
> [org.netbeans.core.windows.persistence]:
> [PersistenceManager.getTopComponentForID] Problem when deserializing
> TopComponent for tcID: 'test'. Reason: Top component test could not be
> located or loaded from Components folder. "?
> (I set the PersistenceType to PERSISTENCE_NEVER )
If given TC instance is not registered in winsys ie. it is not yet in
internal winsys map then if you use getTopComponentForID winsys has
no hint if TC is persistent or not from only its ID so it tries to
deserialize TC but it fails as there is no settings file for it. In such
case
it is just informational log and it is harmless.
>
> That appears when I try to find through the WindowManager, a
> TopComponent that still has not been created. (I must see before a
> creation of TopComponent, if the component had already been created)
>
If you create your TC instance yourself winsys does not know about it so
first you must let winsys know about it eg. using
findTopComponentID(TopComponent)
then you can use getTopComponentForID with ID returned from previous
call. But be aware winsys keeps only weak reference to closed TC so if
you do not have string reference to closed TC it can be gc'ed anytime so
getTopComponentForID may fail even if TC instance existed before for
given ID.
(Opened TC is referenced strongly by winsys and usually also by Swing
when it is present in AWT hierarchy ie. visible).
It is not problem with singleton because singleton has its own static
field - reference to itself so singleton is never gc'ed. So singleton
and persistence
type PERSISTENCE_ALWAYS are complementary.
If you have non singleton TC then suitable persistence type is
ONLY_OPENED or NEVER.
Marek