@Override
 public Object execute(ExecutionEvent event) throws ExecutionException {
   IWorkbenchWindow activeWorkbenchWindow = HandlerUtil.getActiveWorkbenchWindow(event);
   if (activeWorkbenchWindow != null) {
     WorkbenchPage page = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
     if (page != null) {
       Map parameters = event.getParameters();
       String value =
           (String) parameters.get(IWorkbenchCommandConstants.WINDOW_CLOSE_PERSPECTIVE_PARM_ID);
       if (value == null) {
         page.closePerspective(page.getPerspective(), true, true);
       } else {
         IPerspectiveDescriptor perspective =
             activeWorkbenchWindow
                 .getWorkbench()
                 .getPerspectiveRegistry()
                 .findPerspectiveWithId(value);
         if (perspective != null) {
           page.closePerspective(perspective, true, true);
         }
       }
     }
   }
   return null;
 }
  private void closePerspective(MPerspective persp) {
    MWindow win = modelService.getTopLevelWindowFor(persp);
    WorkbenchPage page = (WorkbenchPage) win.getContext().get(IWorkbenchPage.class);
    String perspectiveId = persp.getElementId();
    IPerspectiveDescriptor desc = getDescriptorFor(perspectiveId);
    page.closePerspective(desc, perspectiveId, true, false);

    // removePerspectiveItem(persp);
  }
  /**
   * Adds the new wizards to the current perspective displayed in <code>activeWorkbenchWindow</code>
   * , if they've not been added already. Adds listeners on the window so that the same is done
   * whenever the user switches perspectives in the window.
   *
   * <p>Note: This method can only be called once the workbench has been started.
   */
  private void maybeAddNewWizardActionsToWindow(IWorkbenchWindow activeWorkbenchWindow) {
    if (activeWorkbenchWindow == null) {
      return;
    }

    activeWorkbenchWindow.addPerspectiveListener(perspectiveListener);

    WorkbenchPage activePage = (WorkbenchPage) activeWorkbenchWindow.getActivePage();
    if (activePage == null) {
      return;
    }

    IPerspectiveDescriptor perspectiveDesc = activePage.getPerspective();
    maybeAddNewWizardActionsToPerspective(activePage, perspectiveDesc);
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(
  * org.eclipse.jface.viewers.SelectionChangedEvent)
  */
 public void selectionChanged(SelectionChangedEvent e) {
   MPart part = page.findPart(activePart);
   ESelectionService selectionService =
       (ESelectionService) part.getContext().get(ESelectionService.class.getName());
   selectionService.setSelection(e.getSelection());
 }