Bug 324849 [Compatibility] NPE thrown when trying to close unavailable perspectives
If a perspective cannot be found anymore in their Eclipse installation, they may wish to close it. This is currently not possible. java.lang.NullPointerException at org.eclipse.ui.internal.WorkbenchPage.closePerspective(WorkbenchPage.java:1086) at org.eclipse.e4.ui.workbench.addons.perspectiveswitcher.PerspectiveSwitcher.closePerspective(PerspectiveSwitcher.java:475) at org.eclipse.e4.ui.workbench.addons.perspectiveswitcher.PerspectiveSwitcher.access$6(PerspectiveSwitcher.java:471) at org.eclipse.e4.ui.workbench.addons.perspectiveswitcher.PerspectiveSwitcher$13.widgetSelected(PerspectiveSwitcher.java:466) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/perspectiveswitcher/PerspectiveSwitcher.java
MenuItem menuItem = new MenuItem(menu, SWT.NONE);
		menuItem.setText("&Reset");
		menuItem.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				final MPerspective persp = (MPerspective) menu.getData();
				if (persp == null)
					return;
				IWorkbenchPage page = persp.getContext().get(IWorkbenchPage.class);
				page.resetPerspective();
			}
		});
	}
	private void addShowTextItem(final Menu menu) {
		final MenuItem showtextMenuItem = new MenuItem(menu, SWT.CHECK);
		showtextMenuItem.setText("&Show Text");
		showtextMenuItem.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				boolean preference = showtextMenuItem.getSelection();
				if (preference != PrefUtil.getAPIPreferenceStore().getDefaultBoolean(
						IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR)) {
					PrefUtil.getInternalPreferenceStore().setValue(
							IPreferenceConstants.OVERRIDE_PRESENTATION, true);
				}
				PrefUtil.getAPIPreferenceStore().setValue(
						IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR, preference);
				changeShowText(preference);
			}
		});
		showtextMenuItem.setSelection(PrefUtil.getAPIPreferenceStore().getBoolean(
				IWorkbenchPreferenceConstants.SHOW_TEXT_ON_PERSPECTIVE_BAR));