Say
Say

Reputation: 25

How create Part not restorable in e4 application

In e3 to create not restorable View I set field "restorable" to false in extension org.eclipse.ui.views and it works. In my e4 application I create PartDescriptor with tag "NoRestore" but it do nothing. After restart Part is shown. What I do wrong? Or it is bug?

Upvotes: 0

Views: 229

Answers (2)

Say
Say

Reputation: 25

For compatibility with future versions, in which the IPresentationEngine.NO_RESTORE("NoRestore") tag will be present, you can use the following code.

@PreSave
void preSave(MApplication a_app, EModelService a_modelService){

    ArrayList<MElementContainer<MUIElement>> containers = new ArrayList<>();
    List<MPart> parts = a_modelService.findElements(a_app, null, MPart.class, Arrays.asList("NoRestore"));
    parts.forEach(p -> {
        p.setToBeRendered(false); // hide parts 
        containers.add(p.getParent()); // collect containers with no restorable parts
    });
    // hide containers which contains only no restorable parts
    containers.stream().filter(c -> c.getChildren().stream().allMatch(ch -> ch.getTags().contains("NoRestore"))).forEach(c -> c.setToBeRendered(false));
}

NOTE. Attempts to add the same code to methods with annotations @ProcessAdditions or @ProcessRemovals did not help: errors occurred and after the restart of the application no parts were displayed. So I added my code to the @PreSave method.

Upvotes: 1

greg-449
greg-449

Reputation: 111142

If you let e4 save the workbench model on exit it is restored exactly as saved the next time the RCP is started. There is no support for a NoRestore tag.

Specifying the -clearPersistedState flag on startup will reset the model to the initial state. You can also specify -persistState false to stop the model being saved on exit.

If you just want to deal with one part you can alter the model in your life cycle class during startup. Something like:

@ProcessAdditions
public void processAdditions(MApplication app, EModelService modelService)
{
  MUIElement el = modelService.find("your part id", app);
  if (el != null) {
    el.setToBeRendered(false);
  }
}

which just finds a part and turns off the 'to be rendered' flag.

Upvotes: 2

Related Questions