Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Can't create part from part descriptor
Can't create part from part descriptor [message #1729928] Wed, 20 April 2016 10:11 Go to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

Another issue in porting over from SWT - again, working code in e4 SWT that doesn't work in e(fx)clipse 2.3.0.

This time it is creating a part from a part descriptor. I have a sash part container in fixed layout, with a tree view on the left (similar to the Project Explorer). From there you can either view or edit documents, which will open in an editor area that is defined as an empty part stack in the model.

Here's my method that opens the part. I search for an open part with a matching id, and show that if present, otherwise create a part from the part service, put the relevant object ID into the parts persisted state, and add it to the editor area part stack.

  public void openPart(String partId, String objectKey, int objectId, String objectName) {
    String elementId = partId + ":" + objectId;
    // if the editor is open show it
    Optional<MPart> openPart = partService.getParts().stream().filter(p -> p.getElementId().equals(elementId)).findAny();
    if (openPart.isPresent()) {
      partService.showPart(openPart.get(), PartState.ACTIVATE);
    } else {
      MPart part = partService.createPart(partId);
      part.getPersistedState().put(objectKey, Integer.toString(objectId));
      part.setLabel(objectName);
      part.setTooltip(objectName);
      part.setElementId(elementId);
      MPartStack editorArea = (MPartStack) modelService.find(Resources.Part.EDITOR_AREA, application);
      editorArea.getChildren().add(part);
      partService.showPart(part, PartState.ACTIVATE);
    }
  }



As I said, this worked perfectly well in SWT, but in e(fx)clipse, there is a brief flash of something appearing, then it disappears. Subsequent calls to open parts hit the first branch, i.e. the part service believes the part is open and shows it, but still nothing appears.

I can run the part in a standalone application, and it is able to display the component, retrieve data from the persisted state of the MPart and render okay, so it is not just something wrong with my component. Any ideas what might be going on?


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Can't create part from part descriptor [message #1729935 is a reply to message #1729928] Wed, 20 April 2016 10:55 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Where is EPartService coming from! I guess this is once more handler and
you injected the EPartService?

Tom

On 20.04.16 12:11, Colin Sharples wrote:
> Another issue in porting over from SWT - again, working code in e4 SWT
> that doesn't work in e(fx)clipse 2.3.0.
>
> This time it is creating a part from a part descriptor. I have a sash
> part container in fixed layout, with a tree view on the left (similar to
> the Project Explorer). From there you can either view or edit documents,
> which will open in an editor area that is defined as an empty part stack
> in the model.
>
> Here's my method that opens the part. I search for an open part with a
> matching id, and show that if present, otherwise create a part from the
> part service, put the relevant object ID into the parts persisted state,
> and add it to the editor area part stack.
>
> public void openPart(String partId, String objectKey, int objectId,
> String objectName) {
> String elementId = partId + ":" + objectId;
> // if the editor is open show it
> Optional<MPart> openPart = partService.getParts().stream().filter(p
> -> p.getElementId().equals(elementId)).findAny();
> if (openPart.isPresent()) {
> partService.showPart(openPart.get(), PartState.ACTIVATE);
> } else {
> MPart part = partService.createPart(partId);
> part.getPersistedState().put(objectKey, Integer.toString(objectId));
> part.setLabel(objectName);
> part.setTooltip(objectName);
> part.setElementId(elementId);
> MPartStack editorArea = (MPartStack)
> modelService.find(Resources.Part.EDITOR_AREA, application);
> editorArea.getChildren().add(part);
> partService.showPart(part, PartState.ACTIVATE);
> }
> }
>
>
>
> As I said, this worked perfectly well in SWT, but in e(fx)clipse, there
> is a brief flash of something appearing, then it disappears. Subsequent
> calls to open parts hit the first branch, i.e. the part service believes
> the part is open and shows it, but still nothing appears.
>
> I can run the part in a standalone application, and it is able to
> display the component, retrieve data from the persisted state of the
> MPart and render okay, so it is not just something wrong with my
> component. Any ideas what might be going on?
Re: Can't create part from part descriptor [message #1729997 is a reply to message #1729935] Wed, 20 April 2016 18:34 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

Yes, that method belongs to a controller class, which is a @Creatable @Singleton, shared among all the handlers and the tree view part that generates the selections for the handlers.

It seems that e(fx)clipse is creating the controller in a different context to the handlers and parts, which is odd, because it doesn't do that in e4/SWT. To investigate this, I injected ESelectionService into my tree part, and discovered that the tree part and the controller are receiving different instances of ESelectionService. That explains my problem with the selection in the previous post - if I use the ESelectionService that's injected into the part to set the selection, then the selection does show up in the handlers (even using the method you said only works by chance Smile.

So, why is the controller getting created somewhere else? As I said, there is no issue with this in e4/SWT. I went back to the old application, and injected ESelectionService into the part, and on debugging found that the part and the controller both had the same instance of ESelectionService. This means that e4/SWT and e4/e(fx)clipse are behaving differently with regard to @Creatables, which is not a good thing.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Can't create part from part descriptor [message #1730000 is a reply to message #1729997] Wed, 20 April 2016 18:51 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

I just moved the openPart method from the controller into the handler, and the editor part now appears no problem.

This is quite a big issue for me. If I can't use @Creatable to inject controllers the way that you can on e4/SWT, then it's a much bigger job for me to refactor my code.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Can't create part from part descriptor [message #1730004 is a reply to message #1730000] Wed, 20 April 2016 19:38 Go to previous messageGo to next message
Colin Sharples is currently offline Colin SharplesFriend
Messages: 96
Registered: July 2009
Location: Wellington, New Zealand
Member

Aha, tracked it down. My bad after all, phew Smile

I was using the same controller in a different window for a different part - it uses some, but not all of the same controller methods. When I created my new e(fx)clipse app, I had the windows defined in a different order, so the controller was picking up the wrong selection service. Changing the order of the windows brought back the old functionality. However, I realise that it was just chance that it was working in the old SWT app, not by design! I will split out the controllers so that I have one per window, which should fix the issue properly.


Colin Sharples
CTG Games Ltd
Wellington, New Zealand
Re: Can't create part from part descriptor [message #1730018 is a reply to message #1730004] Wed, 20 April 2016 22:37 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Yeah it looks like you depend on a brittle condition! Please note that
with regard to handlers and @Execute/@CanExecute there's been a bug
lately fixed in 2.4.0 builds!

Tom

On 20.04.16 21:38, Colin Sharples wrote:
> Aha, tracked it down. My bad after all, phew :)
> I was using the same controller in a different window for a different
> part - it uses some, but not all of the same controller methods. When I
> created my new e(fx)clipse app, I had the windows defined in a different
> order, so the controller was picking up the wrong selection service.
> Changing the order of the windows brought back the old functionality.
> However, I realise that it was just chance that it was working in the
> old SWT app, not by design! I will split out the controllers so that I
> have one per window, which should fix the issue properly.
Previous Topic:javafx problem with mutiple scenes hellp me fix it
Next Topic:2.3.0 version to maven central?
Goto Forum:
  


Current Time: Tue Apr 16 21:45:20 GMT 2024

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

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

Back to the top