Re: Registering of a new ContextGlobalProvider implementation
Tim Boudreau <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CA+qecRMWXGiKkgMTr=dZAoFcvLfASV8cebjKyVC9o9+NeQTm0w@mail.gmail.com> |
Sorry, no clue - best I can suggest is to look at the NetBeans sources. -Tim On Tue, Jan 12, 2016 at 11:43 AM, Casqueiro Gilles < [email protected]> wrote: > Hi Tim, > > > > I came back on the implementation of the selection model and it is still > not working yet. > > > > Now, Utilities.actionsGlobalContext() returns the Lookup produced by > MyCustomContextProvider createGlobalContext(). This Lookup is a ProxyLookup > that merges the globalContextLookup returned by GlobalActionContextImpl > with the one of my TopComponent. The latter contains a DataObject > implementing SaveAsCapable. > > > > If I test the presence of a SaveAsCapable in the globalContext Lookup, I > observe that my custom selection model works as expected. However the Save > As menu item don’t react accordingly. The only effect I can is to disable > it permanently by using an empty ProxyLookup. > > > > Do you know why the Save As menu item is sometimes de-activated even if > there is a SaveAsCapable in the globalContext Lookup? > > > > Gilles > > > > *From:* Tim Boudreau [mailto:[email protected]] > *Sent:* vendredi 4 décembre 2015 21:59 > > *To:* [email protected] > *Subject:* [platform-dev] Re: Registering of a new ContextGlobalProvider > implementation > > > > Here's an implementation that works: > > > https://java.net/projects/imagine/sources/hg/content/Imagine/paintapi/src/main/java/net/java/dev/imagine/ApplicationContext.java?rev=41 > > > > It's a little more elaborate than what you're after, since it allows > modules to register a SelectionContextContributer (a Lookup.Provider by any > other name) in the default Lookup, and finds them all and merges them to > create the selection context, so multiple modules can add stuff into the > selection. > > > > It's old code, so there may be prettier ways to do some of what it does > today, but it should still work fine. > > > > -Tim > > > > > > On Fri, Dec 4, 2015 at 8:29 AM, Casqueiro Gilles < > [email protected]> wrote: > > Ok fine thank I will change that. And what about the service registration? > For now the new implementation methods are never called. I don’t have > compilation errors, I suspect the service provider configuration file to be > ineffective. Is it correct the way I described in my previous email (file > name, file content, file location)? > > Gilles > > > > *From:* Tim Boudreau [mailto:[email protected]] > *Sent:* vendredi 4 décembre 2015 12:13 > *To:* [email protected] > *Subject:* [platform-dev] Re: Registering of a new ContextGlobalProvider > implementation > > > > 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 > > > > ----------------------------------------------------------------------- > > 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 > > > ----------------------------------------------------------------------- > > 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