Re: Registering of a new ContextGlobalProvider implementation

Tim Boudreau <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CA+qecRMaoFFdSQja0i8th6dpFjpqUUP_aL903V_vB9D49Cak_A@mail.gmail.com>
Yes, you probably want the contents of the selected TopComponent's Lookup,
not just the selected TopComponent, in the selection context.

The recipe for that is similar to what you have, but:

 - Instead of an AbstractLookup, use a ProxyLookup subclass that exposes a
method that calls (protected final) setLookups() so you can call it from
your setter
 - Call that with the result of your TopComponent's getLookup() method

-Tim


On Fri, Dec 4, 2015 at 3:52 AM, Casqueiro Gilles <
[email protected]> wrote:

> Hi Tim,
>
>
>
> I tried to follow your tutorial in order to change the selection model. As
> it is not currently online I used this version:
> https://web.archive.org/web/20101023185130/http://weblogs.java.net/blog/2007/01/23/how-replace-selection-model-netbeans-platform
> <https://web.archive.org/web/20101023185130/http:/weblogs.java.net/blog/2007/01/23/how-replace-selection-model-netbeans-platform>
>
>
>
> It looks like the service isn’t correctly registered, here is what I did:
>
>
>
> First I have the custom implementation of the ContextGlobalProvider:
>
>
>
> package com.bracco.qihc.selectionModel;
>
>
>
> import com.bracco.qihc.combinedResult.CombinedResultTopComponent;
>
> import org.openide.util.ContextGlobalProvider;
>
> import org.openide.util.Lookup;
>
> import org.openide.util.lookup.AbstractLookup;
>
> import org.openide.util.lookup.InstanceContent;
>
>
>
> public final class QihcContextProvider implements ContextGlobalProvider {
>
>
>
>     private final InstanceContent ic = new InstanceContent();
>
>     private final Lookup lkp = new AbstractLookup(ic);
>
>
>
>     public Lookup getLookup() {
>
>         return lkp;
>
>     }
>
>
>
>     @Override
>
>     public Lookup createGlobalContext() {
>
>         return lkp;
>
>     }
>
>
>
>     public void setCombinedResultTopComponent (CombinedResultTopComponent
> combinedResultTopComponent) {
>
>         CombinedResultTopComponent old =
> lkp.lookup(CombinedResultTopComponent.class);
>
>         if (combinedResultTopComponent != null) {
>
>             if (old != null) {
>
>                 ic.remove(old);
>
>             }
>
>             ic.add(combinedResultTopComponent);
>
>         }
>
>     }
>
> }
>
>
>
>
>
> And then I have the service provider configuration file called
> org.openide.util.ContextGlobalProvider and placed at the root of the src
> folder (<default package>), it contains this:
>
>
>
> #-org.netbeans.modules.openide.windows.GlobalActionContextImpl
>
> com.bracco.qihc.selectionModel.QihcContextProvider
>
>
>
> Do you see something wrong?
>
>
>
> Gilles
>
>
>
>
> -----------------------------------------------------------------------
>
> Le informazioni contenute in questo messaggio di posta elettronica e
> relativi allegati sono riservate e confidenziali e ne è vietata la
> diffusione in qualunque modo eseguita. Qualora Lei non fosse la persona a
> cui il presente messaggio è destinato, La invitiamo ad eliminarlo e a
> darcene gentile comunicazione.
>
> The information contained in this e-mail and any attachments is
> confidential and may also be privileged. If you are not the named recipient
> please notify the sender immediately and do not disclose the contents to
> any other person, use it for any purpose, or store or copy the information
> in any medium.
>
> -----------------------------------------------------------------------
>



-- 
http://timboudreau.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.