NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

findInstance() not generated, what is the "new" way of doing this ?

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users
View previous topic :: View next topic  
Author Message
bruehlicke



Joined: 18 Sep 2009
Posts: 192
Location: Houston

PostPosted: Tue Jan 17, 2017 5:01 pm    Post subject: findInstance() not generated, what is the "new" way of doing this ? Reply with quote

Using Nb 8.2 Wizard to create a new TopComponent I see that the "findInstance()" method is not created anymore linke in older versions. I understand we want to allow for Singletons as well as non-singletons, but
1) Is it still practice to create a method "findInstance" ?
2) If not what is the new way of finding an instance ?

Regards
Bernd
Back to top
bruehlicke



Joined: 18 Sep 2009
Posts: 192
Location: Houston

PostPosted: Tue Jan 17, 2017 6:57 pm    Post subject: Reply with quote

Something similar was asked back in 2013 and not directly answered. So the questions about the "unwritten rule" of having a method called "findInstance()" is still not answered in my view.

The link is here: http://forums.netbeans.org/viewtopic.php?t=56051&highlight=locate+singleton+topcomponent+created+annotation
Back to top
geertjan



Joined: 22 Jan 2014
Posts: 959

PostPosted: Tue Jan 17, 2017 7:29 pm    Post subject: findInstance() not generated, what is the "new" way of doing this ? Reply with quote

windowmanager.getdefault().findtopcomponent

Gj

On 17-1-2017 19:57, bruehlicke wrote:
Quote:
Something similar was asked back in 2013 and not directly answered. So the questions about the "unwritten rule" of having a method called "findInstance()" is still not answered in my view.

The link is here: http://ww.planetnetbeans.org/post-149853.html



Back to top
bruehlicke



Joined: 18 Sep 2009
Posts: 192
Location: Houston

PostPosted: Tue Jan 17, 2017 7:44 pm    Post subject: Reply with quote

Thanx Geertjan, though this guy could return null. Hence in "old days" aka before introduction of annotations (i guess before 7.0) the TopComponent creation Wizard created code with the "findInstance" method like :

Code:

    /**
     * Obtain the MyTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized MyTopComponent findInstance() {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            Logger.getLogger(MyTopComponent.class.getName()).warning(
                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof MyTopComponent) {
            return (MyTopComponent) win;
        }
        Logger.getLogger(MyTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID +
                "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }


Of course this assumed each TopComponent is a Singleton. So I guess that the "findInstance" method is hereby grand-fathered and not "standard" anymore and up to each developer to create or not - fair enough. It was anyhow never in the TopComponent interface. (same as getDefault()).

Bests and Thanx again for all the effort being but into the move to Apache.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Platform Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo