// Map perspective id to descriptor.
IPerspectiveRegistry reg = PlatformUI.getWorkbench().getPerspectiveRegistry();
// leave this code in - the perspective of a given project may map to
// activities other than those that the wizard itself maps to.
IPerspectiveDescriptor finalPersp = reg.findPerspectiveWithId(finalPerspId);
if (finalPersp != null && finalPersp instanceof IPluginContribution) {
IPluginContribution contribution = (IPluginContribution) finalPersp;
if (contribution.getPluginId() != null) {
IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI.getWorkbench().getActivitySupport();
IActivityManager activityManager = workbenchActivitySupport.getActivityManager();
IIdentifier identifier = activityManager.getIdentifier(WorkbenchActivityHelper.createUnifiedId(contribution));
Set<Object> idActivities = identifier.getActivityIds();
if (!idActivities.isEmpty()) {
Set<Object> enabledIds = new HashSet<Object>(activityManager.getEnabledActivityIds());
if (enabledIds.addAll(idActivities)) {
workbenchActivitySupport.setEnabledActivityIds(enabledIds);
}
}
}
} else {
IDEWorkbenchPlugin.log("Unable to find persective " //$NON-NLS-1$
+
finalPerspId + " in BasicNewProjectResourceWizard.updatePerspective"); //$NON-NLS-1$
return;
}
// gather the preferred perspectives
// always consider the final perspective (and those derived from it)
// to be preferred
ArrayList<String> preferredPerspIds = new ArrayList<String>();
addPerspectiveAndDescendants(preferredPerspIds, finalPerspId);
String preferred = configElement.getAttribute(PREFERRED_PERSPECTIVES);
if (preferred != null) {
StringTokenizer tok = new StringTokenizer(preferred, " \t\n\r\f,"); //$NON-NLS-1$
while (tok.hasMoreTokens()) {
addPerspectiveAndDescendants(preferredPerspIds, tok.nextToken());
}
}
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
IWorkbenchPage page = window.getActivePage();
if (page != null) {
IPerspectiveDescriptor currentPersp = page.getPerspective();
// don't switch if the current perspective is a preferred
// perspective
if (currentPersp != null && preferredPerspIds.contains(currentPersp.getId())) {
return;
}
}
// prompt the user to switch