|
|
Re: Calling getObject On A Populated Part Returns null [message #923007 is a reply to message #922845] |
Tue, 25 September 2012 14:31 |
Rob Hatcherson Messages: 33 Registered: July 2009 Location: Fort Worth, TX, USA |
Member |
|
|
Hi Brian,
Thanks for the reply. You wrote:
>> Sounds like you don't have the right object -- perhaps you have
>> something from the snippets or part descriptors?. Trace up the part's
>> container chain and verify that you're getting the right part.
Given my relative E4-noobness anything is possible . I have aired at least one other careless user error on the forums, and this one might be another.
This part is being created from a view descriptor that's defined in a fragment e4xmi file. I'm creating the part from a utility class in a snippet that looks something like this:
final EPartService partService = context.get( EPartService.class ) ;
MPart part = partService.createPart( viewDescriptor ) ;
...some other stuff happens here...
partService.activate( part ) ;
If I call part.getObject() just after activate() returns then I get null. I thought perhaps this is too early to ask for the object, so I added a button on the part's toolbar. The associated handler is similar to:
@Execute
public void execute( @Named(IServiceConstants.ACTIVE_PART) MPart part ) {
System.err.println( ">>>> part label = " + part.getLabel() ) ;
if( part.getObject() != null ) {
System.err.println( "Part object class = " + part.getObject().getClass().getName() ) ;
} else {
System.err.println( "The part's object was null" ) ;
}
}
This also always says the object is null. The label that gets printed is the right one, and in this case this should be (and appears to be) the only such part in the window. Between the label being what I expect and the ACTIVE_PART annotation on the argument, I expect this is the part I'm looking at in the on-screen window.
On your advice I stopped in this handler in the debugger and looked at part.getParent().getParent()... (seemed easier than rooting through the data structures where I'm not quite sure what I'm looking at yet), and I see something like Part->PartSashContainer->Perspective->PerspectiveStack->TrimmedWindow, so I'm pretty sure it's the real part - or at least it's "a" real part, but it also appears to be the right one.
This may have nothing to do with it, but this is the only part in our nascent system that's being created from a view descriptor (because it happens to be the only one with a toolbar currently, and this was easier to create in the model editor). The other parts are created like this:
MPart part = MBasicFactory.INSTANCE.createPart() ;
part.setCloseable( true ) ;
part.setToBeRendered( true ) ;
part.setVisible( true ) ;
part.setContributionURI( whateverItIs ) ;
...some other stuff happens here...
partService.activate( part ) ;
For these I can call part.getObject() just after activate() returns and I get a non-null object of the expected type. The part created via the view descriptor and the part created by the code snippet immediately above ultimately end up at the same partService.activate(); the primary difference is that one is created from a view descriptor, and one is created through MBasicFactory.INSTANCE.createPart().
Is it safe to say that at no time should an instantiated and populated on-screen part return null from getObject()? I would not expect this, but sometimes large and complex frameworks have little corner cases that do surprising things.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05287 seconds