This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 66206 - Generated TopComponent.findDefault() should fallback to getDefault()
Summary: Generated TopComponent.findDefault() should fallback to getDefault()
Status: VERIFIED FIXED
Alias: None
Product: apisupport
Classification: Unclassified
Component: Templates (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-07 07:19 UTC by _ tboudreau
Modified: 2005-10-26 14:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 2005-10-07 07:19:12 UTC
See recent thread on nbdev.  The current generated code in the TC template is a little optimistic that 
the layer files will always be intact - this code will throw an NPE if there is a problem with layer 
registration.

I think you can break this as easily as setting the persistence type to persistence_never, and opening 
the component once and closing it and restarting - the original layer-defined file will be gone (same 
reason we have to [idiotically] keep empty usages and search results tabs open on restart - if we don't 
they'll open in the editor area on second invocation).

The code should look more like this:
   public static TopComponent findDefault() {
       TopComponent tc = WindowManager.getDefault().findTopComponent(ID);

       if (tc == null) {
          tc = getDefault();

I'm tempted to suggest going further and generating an overridden open() method, ala

public void open() {
  Mode m = WindowManager.getDefault().findMode("targetMode");
  if (m != null) m.dockInto(this);
  super.open();
}

but that might be overkill.
Comment 1 Milos Kleint 2005-10-17 12:49:23 UTC
I'm not sure where this code should go. the TC or it's action? There's currently
no FindDefault() method in the TC. Maybe the code you put in the open method
should go into the findDefault() body.. docing when the default instance is not
found..

on a more general note, I'm for fixing the winsys usecases and persistence
rather then making winsys template buletproof with the current broken state. 
Comment 2 _ tboudreau 2005-10-18 09:19:56 UTC
I'm for that as well, but lets do something for 5.0.  Most modules do the
fallback to getDefault(), it seems reasonable;  the NPE definitely isn't.
Comment 3 Milos Kleint 2005-10-18 14:47:05 UTC
still not convinced it helps anything but hre you are..

findInstance() method added.

Checking in
project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/templateAction.javx;
/cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/templateAction.javx,v
 <--  templateAction.javx
new revision: 1.9; previous revision: 1.8
done
Checking in
project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/templateTopComponent.javx;
/cvs/apisupport/project/src/org/netbeans/modules/apisupport/project/ui/wizard/winsys/templateTopComponent.javx,v
 <--  templateTopComponent.javx
new revision: 1.8; previous revision: 1.7
done
Command Finished.
Comment 4 pzajac 2005-10-26 14:35:07 UTC
it looks fine