Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » E4 RCP Part createContents gets executed multiple times(E4 RCP Part createContents gets executed multiple times)
E4 RCP Part createContents gets executed multiple times [message #1006853] Sat, 02 February 2013 17:37 Go to next message
matus majchrak is currently offline matus majchrak
Messages: 5
Registered: November 2012
Junior Member
Hi,
I run into a very strange problem with UI creation/injection in RCP 2.0
Basically I have a part with flag Multiple=true with a method responsible for creating its UI annotated with @Inject like this:
@Inject
public void createControls(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL) final Shell shell) {
		//Create the UI
}


Part represents a detail view of some item selected from a treeView; here is how I create/show the part in doubleclick handler of the treeviewer:
List<String> tags = new ArrayList<String>();
tags.add("SAMPLE" + node.getId());
List<MPart> found = modelService.findElements(application, null, MPart.class, tags);
	if (found != null && !found.isEmpty()) {
		partService.showPart(found.get(0), PartState.VISIBLE);
		((SampleDetailPart) found.get(0).getObject()).setSample(node.getId());
	} else {
                MPart newPart = partService.createPart(SampleDetailPart.PART_ID);
		newPart.getTags().add("SAMPLE" + node.getId());
		partService.showPart(newPart, PartState.VISIBLE);
		newPart.setLabel(node.getName());//Set the model data for the part
		((SampleDetailPart) newPart.getObject()).setSample(node.getId());
	}


For some reason, the createContents method get executed multiple times, everytime the part is moved or has regaind focus, creating duplicate UI as can be seen in the picture below
Part after being created:
index.php/fa/13272/0/
Part after switching to another part in the same stack and back - createContents has been called twice
index.php/fa/13273/0/


Did I miss something obvious? Any advice would be most appreciated.

Thanks a lot
cheers
matus
  • Attachment: correct.png
    (Size: 11.68KB, Downloaded 328 times)
  • Attachment: wrong.png
    (Size: 13.98KB, Downloaded 321 times)
Re: E4 RCP Part createContents gets executed multiple times [message #1006958 is a reply to message #1006853] Sun, 03 February 2013 03:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5014
Registered: July 2009
Senior Member
Better asked at e4-newsgroup, but anyways: You should not use @Inject
but @PostConstruct for the creation of the UI. @Inject methods will be
called everytime a value changes.

Tom

Am 02.02.13 23:38, schrieb matus majchrak:
> Hi,
> I run into a very strange problem with UI creation/injection in RCP 2.0
> Basically I have a part with flag Multiple=true with a method responsible for creating its UI annotated with @Inject like this:
>
> @Inject
> public void createControls(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL) final Shell shell) {
> //Create the UI
> }
>
>
> Part represents a detail view of some item selected from a treeView; here is how I create/show the part in doubleclick handler of the treeviewer:
>
> List<String> tags = new ArrayList<String>();
> tags.add("SAMPLE" + node.getId());
> List<MPart> found = modelService.findElements(application, null, MPart.class, tags);
> if (found != null && !found.isEmpty()) {
> partService.showPart(found.get(0), PartState.VISIBLE);
> ((SampleDetailPart) found.get(0).getObject()).setSample(node.getId());
> } else {
> MPart newPart = partService.createPart(SampleDetailPart.PART_ID);
> newPart.getTags().add("SAMPLE" + node.getId());
> partService.showPart(newPart, PartState.VISIBLE);
> newPart.setLabel(node.getName());//Set the model data for the part
> ((SampleDetailPart) newPart.getObject()).setSample(node.getId());
> }
>
>
> For some reason, the createContents method get executed multiple times, everytime the part is moved or has regaind focus, creating duplicate UI as can be seen in the picture below
> Part after being created:
>
> Part after switching to another part in the same stack and back - createContents has been called twice
>
>
>
> Did I miss something obvious? Any advice would be most appreciated.
>
> Thanks a lot
> cheers
> matus
>
Re: E4 RCP Part createContents gets executed multiple times [message #1006978 is a reply to message #1006958] Sun, 03 February 2013 08:45 Go to previous messageGo to next message
matus majchrak is currently offline matus majchrak
Messages: 5
Registered: November 2012
Junior Member
Hi and thanks for the quick response.
The problem is, I had my methods annotated with @PostConstruct, but than they would not be executed at all. When I debug this I could see, that constructors got invoked, but not the createContents method. I actually managed to reproduce it with this sample:
Just add a Part to e4xmi manifest with the following code - the result is I can see the part, but it has not UI contents.
public class BasicNavigatorPart {

	private static final Logger log = Logger.getLogger(BasicNavigatorPart.class);
	
	public BasicNavigatorPart(){
		log.info("** Constructor "+BasicNavigatorPart.class.getSimpleName());
	}

	@PostConstruct
	public void createControls(Composite parent) {
		log.info("** creating UI "+BasicNavigatorPart.class.getSimpleName());
        }
}


The constructor is invoked, but not the @postConstruct annotated method.

Any pointers?
Re: E4 RCP Part createContents gets executed multiple times [message #1006979 is a reply to message #1006978] Sun, 03 February 2013 09:02 Go to previous message
matus majchrak is currently offline matus majchrak
Messages: 5
Registered: November 2012
Junior Member
OK I found the solution, seems to be related to this bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=348123
Changing javax.annotation to 1.0.0 fixed the issues, and now the method with @postConstructs get invoked the way it should.

Thanks again for your help.
cheers
matus
Previous Topic:Get the Command id in a PropertyTester
Next Topic:How enable and disable buttons using event in SWT.
Goto Forum:
  


Current Time: Mon Apr 21 11:53:07 EDT 2014

Powered by FUDForum. Page generated in 0.11063 seconds