Dynamic TopComponent

View: New views
15 Messages — Rating Filter:   Alert me  

Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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)

Sorry for my english.

Re: Dynamic TopComponent

by Tonny Kohar-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Dynamic TopComponent

by tomwheel :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

See here for details on how to do that:

http://wiki.netbeans.org/DevFaqNonSingletonTopComponents

On Tue, May 12, 2009 at 8:52 PM, Tonny Kohar <tonny.kohar@...> wrote:
> 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)



--
Tom Wheeler
http://www.tomwheeler.com/

Re: Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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) "

Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

 

Re: Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> 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 )

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)


Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


Re: Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Marek Slama ha scritto:

> 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
Thank you, everything seems to be clear enough :-)

But, how do I remove that annoying log? I could not find a way to remove
it, I can not understand how to set the level of the log.

Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I]ark wrote:

> Marek Slama ha scritto:
>> 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
> Thank you, everything seems to be clear enough :-)
>
> But, how do I remove that annoying log? I could not find a way to
> remove it, I can not understand how to set the level of the log.
If you really want to remove it you can set log level for
PersistenceManager higher than Level.INFO
-J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level=900

WARNING is 900
INFO is 800

Also Level.INFO is used only once for given ID. Next is FINE.

You can see method PersistenceManager.getTopComponentPersistentForID

Marek

Re: Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> If you really want to remove it you can set log level for
> PersistenceManager higher than Level.INFO
> -J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level=900
>
> WARNING is 900
> INFO is 800
>
> Also Level.INFO is used only once for given ID. Next is FINE.
>
> You can see method PersistenceManager.getTopComponentPersistentForID
>
> Marek
>  
    If I try to put in the compilation command, it says " javac: invalid
flag:-J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level
= 900 "
Also I can not access the class ersistenceManager and then to see the
methods. How do I get?


Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I]ark wrote:

>
>> If you really want to remove it you can set log level for
>> PersistenceManager higher than Level.INFO
>> -J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level=900
>>
>> WARNING is 900
>> INFO is 800
>>
>> Also Level.INFO is used only once for given ID. Next is FINE.
>>
>> You can see method PersistenceManager.getTopComponentPersistentForID
>>
>> Marek
>>  
>    If I try to put in the compilation command, it says " javac:
> invalid
> flag:-J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level
> = 900 "
> Also I can not access the class ersistenceManager and then to see the
> methods. How do I get?
>
This is runtime command to set log level for this class. It must be put
to command line when you start your app
or to netbeans.conf at line with params.

I meant you can 'look' at sources how exactly log level is assigned in
method mentioned above.

M.

Re: Dynamic TopComponent

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Marek Slama ha scritto:

> I]ark wrote:
>>
>>> If you really want to remove it you can set log level for
>>> PersistenceManager higher than Level.INFO
>>> -J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level=900
>>>
>>> WARNING is 900
>>> INFO is 800
>>>
>>> Also Level.INFO is used only once for given ID. Next is FINE.
>>>
>>> You can see method PersistenceManager.getTopComponentPersistentForID
>>>
>>> Marek
>>>  
>>    If I try to put in the compilation command, it says " javac:
>> invalid
>> flag:-J-Dorg.netbeans.core.windows.persistence.PersistenceManager.level
>> = 900 "
>> Also I can not access the class ersistenceManager and then to see the
>> methods. How do I get?
>>
> This is runtime command to set log level for this class. It must be
> put to command line when you start your app
> or to netbeans.conf at line with params.
>
> I meant you can 'look' at sources how exactly log level is assigned in
> method mentioned above.
>
> M.
    Thanks for all the explanations, one last thing. But creating the
dynamic TopComponents and setting the persistence as PERSISTENCE_NEVER ,
you can delete the TopComponent by winsys? I mean, I would delete  the
TopComponent by winsys, so that a next call of WindowManager (for id of
TopComponent deleted), it can return "null". Or TopComponent are
maintained in winsys until the closing of the application?


Re: Dynamic TopComponent

by Marek Slama :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


>> I meant you can 'look' at sources how exactly log level is assigned
>> in method mentioned above.
>>
>> M.
>    Thanks for all the explanations, one last thing. But creating the
> dynamic TopComponents and setting the persistence as PERSISTENCE_NEVER
> , you can delete the TopComponent by winsys? I mean, I would delete  
> the TopComponent by winsys, so that a next call of WindowManager (for
> id of TopComponent deleted), it can return "null". Or TopComponent are
> maintained in winsys until the closing of the application?
>
There is no explicit winsys 'delete TC' or 'dispose TC' method. If TC is
closed (TC.close()) then winsys keeps only weak regerence
to TC instance. So then if nobody else (your code) has strong reference
to TC TC can be garbage collected any time. It means that
WindowManager.findTopComponent(String) will return null.

It purely depends on garbage collector so it is unpredictable when TC
will be gone.

M.


Favorite window

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

how can I do to view in the favorites, the root of the disc , rather
than the default folder?

I tried to change something in layer.xml but nothing.

Can someone help me?

Re: Favorite window

by I]ark :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

nobody knows how to help me?

> how can I do to view in the favorites, the root of the disc , rather
> than the default folder?
>
> I tried to change something in layer.xml but nothing.
>
> Can someone help me?
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 8.5.375 / Virus Database: 270.13.3/2216 - Release Date: 07/03/09 05:53:00
>
>