I have an e4 application that has two perspective:
When a new model is loaded all configuration parts are to be closed. This works fine if a load the new model when the configuration perspective is active.
However, if I open some configurations in the Configuration perspective. Switch to the Operations perspective and load a new model.
I can see in the logs that the code to close the parts is called and everything seems to be alright. However, when i switch back to the configuration perspective the parts are still visible an open.
Could somebody tell me how to make sure that the parts are close, regardless of the which is the active perspective?
I found a "workaround" to solve my issue.
I had an event thrown to detect the model load as follows and use it to "close"/hide the parts:
@Inject @Optional
void modelLoadedHandler(@UIEventTopic(STUConstants.UI_TOPIC_CONFIG_LOADED) Object nothing) {
viewer.setInput(sleConfigService);
//Close open config parts
MPartStack stack = (MPartStack) modelService
.find(STUConstants.PART_STACK_ID_CONFIG_VIEW,
application);
List<MStackElement> parts = new ArrayList<>(stack.getChildren());
MPart mpart;
for (MStackElement element : parts) {
mpart = (MPart) element;
log.error("Removing part {} visible {}", mpart.getElementId(), mpart.isVisible());
partService.hidePart(mpart, true);
}
// Adding this make it work regardless of which perspective is
// active.
stack.getChildren().clear();
}
Adding the stack.getChildren().clear();
did the trick. I am not hundred percent whether that would be the right way to deal with this, as i would have though that the PartStack
should be emptied automatically when i remove a part.