Skip to main content


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 22:37 Go to next message
matus majchrak is currently offline matus majchrakFriend
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 1151 times)
  • Attachment: wrong.png
    (Size: 13.98KB, Downloaded 1105 times)
Re: E4 RCP Part createContents gets executed multiple times [message #1006958 is a reply to message #1006853] Sun, 03 February 2013 08:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
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 13:45 Go to previous messageGo to next message
matus majchrak is currently offline matus majchrakFriend
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 14:02 Go to previous message
matus majchrak is currently offline matus majchrakFriend
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: Thu Apr 25 01:59:02 GMT 2024

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

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

Back to the top