Project: Eclipse_Platform_UI
Bug 138400 [Workbench] Problem deleting a perspective descriptor created from restore state
Reported: 2006-04-25 11:23:37 | Status: verified fixed

I am running into an issue with perspectives within our product. The issue is that the perspectives are created "dynamically", meaning that an xml file is used to describe layout. The xml is parsed and associated with a perspective id, the perspectivefactory code then has a mthod call which builds the layout based on the xml. All fine and good. Works great. The issue is that whnever the xml file is changed, I need to be able to have the perspective rebuild itself to reflect the new layout in the xml. This always works as long as perspective states are not saved. However, we must support perspective states to be saved. So the issue is occuring in the use case where I start the client, the perspective is created, shown etc. Then I make a change to the xml file without changing the active perspective. The client is shut down, then restarts and reloads the new changed xml. However, instead of my perspective updating, it is the perspective that was saved in the perspective state. Calling reset perspective doesn't do anything. It is also important to note that the perspective is created using the new addContribution method. So the extension is created every time the client starts up since these "dynamic extensions" are currently not persisted. After debugging extensively, I noticed that it is using the custom definition which is saved in the workbench preferences. So my initial thought was to delete the custom definition and see what happens. I tried that, and what happens now is I get an error trying to open the perspective. The code path goes fine until it gets here: IPerspectiveFactory factory = null; try { factory = persp.createFactory(); } catch (CoreException e) { throw new WorkbenchException(NLS.bind(WorkbenchMessages.Perspective_unableToLoad, persp.getId() )); } createFactory is always returning null. I think this is because the perspective descriptor being used here is the perspective descriptor created from the custom definition, so the descriptor does not have the configElement reference. // otherwise try to create the executable extension if (configElement != null) try { return (IPerspectiveFactory) configElement .createExecutableExtension(IWorkbenchRegistryConstants.ATT_CLASS); } catch (CoreException e) { // do nothing } return null; The workaround I have found that works is if I change the isPreDefined method in the PerspectiveDescriptor class to the followng: public boolean isPredefined() { return (getClassName() != null && configElement != null); } I'm not sure if this is the proper way to handle this. When would a saved persepective have a config element when it is restored? It always has a class name because the class name is saved in the xml that gets written to the preferences file.

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/PerspectiveDescriptor.java