Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » EPartService is null after hiding a Part
EPartService is null after hiding a Part [message #642995] Fri, 03 December 2010 15:40 Go to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
Hi,

I try to change the visible Part by calling a Command. This is the Handler-Code:

public class ShowPart2 {
	
	@Inject
	private EPartService service;
	
	@Execute
	public void execute() {

		MPart partToShow = this.service.findPart("part2");
		MPart partToHide = this.service.findPart("part1");
		
		if (partToShow != null) {
			if (partToHide != null) {
				this.service.hidePart(partToHide);
			}
			this.service.showPart(partToShow, PartState.VISIBLE);
		}
		
	}
}


While debugging i saw the following:
partToShow, partToHide and service are NOT null until hidePart is called. After this, service is null and a NullPointerException is thrown when showPart is called.

How can this be?

thanx,
mike
Re: EPartService is null after hiding a Part [message #643097 is a reply to message #642995] Sat, 04 December 2010 09:37 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
btw, this is a snippet of my Application.e4xmi:

  <children xsi:type="basic:TrimmedWindow" xmi:id="_pty7Qfh1Ed-HXdg12mxwcQ" elementId="window" selectedElement="_bHzPYP5NEd-cdYlZAiNo-g" label="e4 test" x="525" y="350" width="550" height="500">
    <tags>topLevel</tags>
    <children xsi:type="basic:Part" xmi:id="_nEstMPjREd-Cd4UENK8qBw" elementId="part1" contributionURI="platform:/plugin/e4.test/Part1" containerData="" label="Part1">
      <tags>active</tags>
      <handlers xmi:id="_gC2lYP5TEd-cdYlZAiNo-g" contributionURI="platform:/plugin/e4.test/ShowPart2" command="_4bHYcP5NEd-cdYlZAiNo-g"/>
    </children>
    <children xsi:type="basic:Part" xmi:id="_bHzPYP5NEd-cdYlZAiNo-g" elementId="part2" contributionURI="platform:/plugin/e4.test/Part2" label="Part2">
      <handlers xmi:id="_1ybWkP5bEd-aN5SL9G4zOw" contributionURI="platform:/plugin/e4.test/ShowPart1" command="_vEY5oP5NEd-cdYlZAiNo-g"/>
    </children>
  </children>
Re: EPartService is null after hiding a Part [message #643169 is a reply to message #642995] Sun, 05 December 2010 15:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5321
Registered: July 2009
Senior Member
Don't use injection in handlers, it's not really working at the moment
and as you noticed strange things can happen - only use things this way:

@Execute
public void execute(EPartService service) {
}

Tom

Am 03.12.10 16:40, schrieb Mike Moor:
> Hi,
>
> I try to change the visible Part by calling a Command. This is the
> Handler-Code:
>
>
> public class ShowPart2 {
>
> @Inject
> private EPartService service;
>
> @Execute
> public void execute() {
>
> MPart partToShow = this.service.findPart("part2");
> MPart partToHide = this.service.findPart("part1");
>
> if (partToShow != null) {
> if (partToHide != null) {
> this.service.hidePart(partToHide);
> }
> this.service.showPart(partToShow, PartState.VISIBLE);
> }
>
> }
> }
>
>
> While debugging i saw the following:
> partToShow, partToHide and service are NOT null until hidePart is
> called. After this, service is null and a NullPointerException is thrown
> when showPart is called.
>
> How can this be?
>
> thanx,
> mike
Re: EPartService is null after hiding a Part [message #643315 is a reply to message #642995] Mon, 06 December 2010 13:32 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

As Tom mentions, use @Execute void execute(EPartService service).

That still might not solve the issue, however. The original one was
that the handler was attached to your MPart. When you hide your MPart
(and it is disposed) your handler is getting uninjected (hence the
service going to null).

If you handler is to work on multiple parts, perhaps it should be
defined at the window level?

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: EPartService is null after hiding a Part [message #643428 is a reply to message #643315] Mon, 06 December 2010 19:56 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
thank you for your answers.

this solves the NPE-Problem. But it doesn't work either... Sad

What the Handlers should do is changing the visible part...
The Part i want to hide disappears but the one i want to be visible is not. So the result is an empty window...

Do you have any ideas for sovling this problem?

thanx,
mike
Re: EPartService is null after hiding a Part [message #643434 is a reply to message #643428] Mon, 06 December 2010 20:10 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Mike Moor wrote:
> thank you for your answers.
>
> this solves the NPE-Problem.

Did you move the handler to the window level? When your MPart goes
away, all of its services become nothing more than shells.

PW


--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Platform_Expression_Framework
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: EPartService is null after hiding a Part [message #643517 is a reply to message #643434] Tue, 07 December 2010 08:46 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
no, i just used @Execute void execute(EPartService service).

this works (no NPE) if i first call showPart and then hidePart. but the gui still does not what it should Sad even when i move the handlers to the window level...
Re: EPartService is null after hiding a Part [message #644131 is a reply to message #643517] Thu, 09 December 2010 15:57 Go to previous messageGo to next message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
Mike Moor wrote on Tue, 07 December 2010 03:46
this works (no NPE) if i first call showPart and then hidePart. but the gui still does not what it should Sad even when i move the handlers to the window level...

Did you step through the code to see what's going on? Is the part being rendered by the rendering engine? Are its parents being rendered? Do they have physical widgets (see getWidget())?
Re: EPartService is null after hiding a Part [message #645376 is a reply to message #644131] Thu, 16 December 2010 19:24 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
i step through the code and what i saw is this:

- the part has the same parent as the active part
- the part is not beeing rendered by the PartRenderingEngine because it has already been rendered at startup (the @PostConstruct annotated method was called)
- the @Focus annotated method of the Part is called when i call showPart

but the part is not visible Sad

[Updated on: Fri, 17 December 2010 08:49]

Report message to a moderator

Re: EPartService is null after hiding a Part [message #645986 is a reply to message #645376] Tue, 21 December 2010 13:31 Go to previous messageGo to next message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
Based on your original XML snippet, it seems both parts should be "up" on startup. You also noted that this is indeed the case given that the other part's @PostConstruct method was invoked.

Given the structure, the window should begin with both parts rendered and visible to the end user, is this not the case?
Re: EPartService is null after hiding a Part [message #646118 is a reply to message #645986] Wed, 22 December 2010 08:21 Go to previous messageGo to next message
Mike Moor is currently offline Mike Moor
Messages: 20
Registered: November 2010
Location: Steffisburg, Switzerland
Junior Member
No, just the first Part is visible at startup. And that is correct. Maybe i deleted to much when i tried to shorten the XML Snippet...

My first part is my LoginPart, where the Username/PW Textfields are located. Now i have a Link-Widget with the Text: "You don't have a Username? Please register here." As soon as the user clicks on that Link, the LoginPart shoud hide and the second Part, the RegistrationPart should be visible.

On the RegistrationPart i have a Link-Widget too to go back to the LoginPart (hide the RegistrationPart, show the LoginPart).
Re: EPartService is null after hiding a Part [message #647117 is a reply to message #646118] Tue, 04 January 2011 16:28 Go to previous messageGo to next message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
Mike Moor wrote on Wed, 22 December 2010 03:21
No, just the first Part is visible at startup.

For me, the second part is visible, although really, they both should be visible so there is a bug here.

You should be able to workaround the problem by wrapping the two parts in an MPartSashContainer and setting your second part's 'toBeRendered' attribute to 'false'.

Something like this...
Quote:
<children xsi:type="basic:TrimmedWindow" xmi:id="_pty7Qfh1Ed-HXdg12mxwcQ" elementId="window" label="e4 test" x="525" y="350" width="550" height="500">
<children xsi:type="basic:PartSashContainer" xmi:id="_SeXUCu8EEd6FC9cDb6iV7g" elementId="_SeXUCu8EEd6FC9cDb6iV7g" horizontal="true">
<children xsi:type="basic:Part" xmi:id="_nEstMPjREd-Cd4UENK8qBw" elementId="part1" contributionURI=" platform:/plugin/org.eclipse.e4.demo.contacts/org.eclipse.e4 .demo.contacts.views.ListView " containerData="" label="Part1"/>
<children xsi:type="basic:Part" xmi:id="_bHzPYP5NEd-cdYlZAiNo-g" elementId="part2" contributionURI=" platform:/plugin/org.eclipse.e4.demo.contacts/org.eclipse.e4 .demo.contacts.views.DetailsView " label="Part2" toBeRendered="false"/>
</children>
</children>


Quote:
@Execute
public void execute(final EPartService partService) {
MPart part1 = partService.findPart("part1");
MPart part2 = partService.findPart("part2");
partService.hidePart(part1);
partService.showPart(part2, PartState.ACTIVATE);
}
Re: EPartService is null after hiding a Part [message #647123 is a reply to message #647117] Tue, 04 January 2011 16:39 Go to previous message
Remy Suen is currently offline Remy Suen
Messages: 462
Registered: July 2009
Senior Member
I have opened bug 333496 for the problem where only one part is visible when there should be two visible parts.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=333496
Previous Topic:could E4 team change the schedule to make E4 better now
Next Topic:e4 still broken on Ubuntu Linux
Goto Forum:
  


Current Time: Wed Sep 17 17:43:51 GMT 2014

Powered by FUDForum. Page generated in 0.02575 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software