thank you, i found out these code works, but some object is null so I have to
filter it out
Set<TopComponent> set = WindowManager.getDefault().getRegistry().getOpened();
for (TopComponent com : set) {
DataObject d = com.getLookup().lookup(DataObject.class);
System.out.println("d=" + d);
if (d != null) {
com.repaint();
}
}
Thanks
>From Peter (System Architect, Quantr Limited https://www.quantr.hk , Mobile :
>96554595)
________________________________
From: John Kostaras <[email protected]>
Sent: Wednesday, September 28, 2022 2:46 AM
To: [email protected] <[email protected]>
Subject: Re: super confuse for years
Also look at this <https://dzone.com//articles/netbeans-lookups-explained>.
On Tue, Sep 27, 2022 at 3:40 PM Moacir da Roza <[email protected]> wrote:
> Lookups is like a bag of objects, you can have global lookups or local
> lookups.
> *Globals*
> 1-*Lookup.getDefault() *- Is default lookup in general it will have all
> services that exists on META-INF/services.
> 2- *Utilities.actionsGlobalContext() *- In this you can have the lookup of
> all that have focus on Netbeans
> *Ex.:* Utilities.actionsGlobalContext().lookup(FileObject.class);
> Will probably give you the file opened that have focus on Netbeans.
> *Local*
> All other classes that implements Lookup.Provider*. *
> TopComponent.getRegistry().getActivated().getLookup(), note that this
> lookup probably can have all items of the default with additional items of
> the TopComponent, because the constructor of TopComponent receives a
> lookup.
>
>
> TopComponent.getRegistry().getActivated().getLookup().lookup(FileObject.class);
> Will give you same as
> Utilities.actionsGlobalContext().lookup(FileObject.class);
>
> *If I want to lookup all opened files, that mean all DataObjects. What I
> should use?*
>
> You must to find what is the default class responsible by editor, is a
> TopComponent, so you must get all TopComponent Implementations and get his
> lookup.
>
> > var list = TopComponent.getRegistry().getOpened();
> > for(TopComponent item : list){
> > if(item instanceof CloneableTopComponent){
> >
> > System.out.println(item.getLookup().lookup(FileObject.class));
> > }
> > }
> >
>
> Probably has other ways, but this way works.
>
>
> Em ter., 27 de set. de 2022 às 01:00, Peter Cheung <[email protected]>
> escreveu:
>
> > Dear All
> > I have been super confused by these for many years, what is the
> > difference? when I use should which?
> >
> >
> > 1. Lookup.getDefault().lookupAll
> > 2.
> > DataObject.find(FileUtil.toFileObject(realFile)).getLookup().lookupAll
> > 3. Utilities.actionsGlobalContext().lookupAll
> > 4. TopComponent.getRegistry().getActivated().getLookup().lookupAll
> >
> > If I want to lookup all opened files, that mean all DataObjects. What I
> > should use?
> >
> >
> > Thanks
> >
> > From Peter (System Architect, Quantr Limited https://www.quantr.hk ,
> > Mobile : 96554595)
> >
>
>
> --
> Moacir R.F
> Desenvolvedor de Softwares
>
> https://www.moacirrf.com.br <http://www.moacirrf.com.br>
>