Community
Participate
Working Groups
Required if you desire to reuse an IPerspectiveFactory, (e.g. when creating dynamic perspectives). The same IPerspectiveFactory class may be used to generate perspectives based on some criteria (user identity etc.). The IPerspectiveFactory may read the definition of the perspective from a dynamic store (database, XML stream) etc. and needs some way of differentiating one call to creatInitialLayout() from another. Granting access to the the descriptor of the perspective it's laying out would give it a unique identifier (perpsective ID) that can be used as a key to perform a lookup to obtain the information required to generate the perspective. As a suggestion the public method in the org.eclipse.ui.internal.PageLayout class called getDescriptor() could be promoted to the IPageLayout interface.
You could simply have your IPerspectiveFactory implement IExecutableExtension. From the data provided to this methods interfaces you could look up any useful info stored in the perspective descriptor or elsewhere within the workbench. I would be inclined to mark this as WONTFIX.
I actually don't think it's unreasonable to let the factory know the id of the perspective, and use that to look up information. I'm -strongly- against giving semantics to the id itself, e.g. encoding parameters or other info in the id proper. Implementing IExecutableExtension in your perspective factory would work. You can get the id using configElement.getAttribute("id"). As of 3.1, you can also use IExecutableExtensionFactory. In the perspective extension, instead of referring the class implementing IPerspectiveFactory directly, provide a class implementing IExecutableExtensionFactory. This can also implement IExecutableExtension to obtain data from the configuration element. For an example, see how the progress view is declared in org.eclipse.ui.ide's plugin.xml. It refers to org.eclipse.ui.ExtensionFactory passing "progressView" as the data.
IExecutableExtension works well except when cloning an existing perspective. If you use the IPerspectiveRegistry.clone() method than the new perspective gets the IConfigurationElement of the original perspective, thus the same ID, etc. If I cast the IPageLayout instance to a PageLayout than I can get the IPerspectiveDescriptor with the correct information, including the ID and label passed to the clone method (e.g. ((PageLayout)layout).getDescriptor().getId(); )
Fixed as suggested in builds >= N20051130.
Verified in I20051213-0010. Added an API test for it: IPageLayoutTest.testGetDescriptor()