E4 RCP Part createContents gets executed multiple times [message #1006853] |
Sat, 02 February 2013 17:37  |
Eclipse User |
|
|
|
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
Attachment: correct.png
(Size: 11.68KB, Downloaded 1220 times)
Attachment: wrong.png
(Size: 13.98KB, Downloaded 1169 times)
|
|
|
Re: E4 RCP Part createContents gets executed multiple times [message #1006958 is a reply to message #1006853] |
Sun, 03 February 2013 03:36   |
Eclipse User |
|
|
|
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
>
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.23295 seconds