1

Is it possible to cancel the creation of a view in the @PostConstruct phase? I have:

@PostConstruct
public void createPartControl(Composite parent) {
    try {
        // do something where an exception is thrown
    } catch (Exception e) {
        // I want to cancel construction, close the view and show an error dialog
    }
}
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • Rather than trying to cancel a lot of views just put the error message in the view instead of the normal contents. – greg-449 Oct 07 '15 at 08:51

2 Answers2

3

You can run the part service hide part immediately after the part creation has finished using something like:

@PostConstruct
public void postConstruct(Composite parent, UISynchronize uiSync,
                          EPartService partService, MPart part)
{
  // Other code

  // Run hidePart as soon as possible after part creation has finished

  uiSync.asyncExec(() -> partService.hidePart(part));
}

(Above is using Java 8 lambda).

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

Just close the view, e4 style

MPart part = partService.findPart(viewId);
part.setVisible(true);
Georgian
  • 8,795
  • 8
  • 46
  • 87
  • `setVisible(false)` doesn't close the view. `setToBeRendered(false)` destroys the view object, but I'm not sure that will run correctly during the part construction. – greg-449 Oct 07 '15 at 08:59
  • Thanks, it works. But @greg-449 point is what I was also wondering about. Does setVisibile() really destroy the whole part? setToBeRendered() unfortunately does not work, as it leaves the view open. – user2202755 Oct 08 '15 at 07:06