If I right click and detach a view, modelService.getActivePerspective(window)
starts returning null. This means that resetting the perspective doesn't work correctly.
If a view isn't detached it works correctly. I'm thinking that as a new window is open it is passing a different window that doesn't contain the perspective.
Example
public class ResetPerspectiveHandler {
@Execute
public static void resetPerspective(final MApplication app, final EPartService partService,
final EModelService modelService, final MWindow window) {
// Prints null
System.out.println(modelService.getActivePerspective(window));
PerspectiveSnippetsCopier.resetPerspective(modelService, partService, app, window,
modelService.getActivePerspective(window).getElementId());
}
}
What could be causing this?
The code for getActivePerspective
is:
public MPerspective getActivePerspective(MWindow window) {
List<MPerspectiveStack> pStacks = findElements(window, null, MPerspectiveStack.class);
if (pStacks.size() == 1) {
MPerspective perspective = pStacks.get(0).getSelectedElement();
return perspective;
}
return null;
}
So it expects to find a MPerspectiveStack
in the given window, presumbly the detached window does not have this.
You could try finding the main window in the app rather than using the current window.
MWindow mainWindow = (MWindow)modelService.find("main window id", app);