@Override
 public void fillContextMenu(IMenuManager aMenu) {
   IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
   if (selection.size() != 1) {
     return;
   }
   Object object = selection.getFirstElement();
   IFolder folder = Adapters.adapt(object, IFolder.class);
   if (folder == null) {
     return;
   }
   if (folder.getFile(IProjectDescription.DESCRIPTION_FILE_NAME).exists()) {
     for (IProject project : folder.getWorkspace().getRoot().getProjects()) {
       if (project.getLocation().equals(folder.getLocation())) {
         // project already in workspace
         SelectProjectForFolderAction action =
             new SelectProjectForFolderAction(project, this.viewer);
         aMenu.appendToGroup(ICommonMenuConstants.GROUP_OPEN, action);
         return;
       }
     }
     OpenFolderAsProjectAction action = new OpenFolderAsProjectAction(folder, this.viewer);
     aMenu.prependToGroup(ICommonMenuConstants.GROUP_PORT, action);
   }
 }
 @SuppressWarnings("unchecked")
 @Override
 public <T> T getAdapter(Class<T> adapter) {
   if (adapter.equals(IUndoContext.class)) {
     return (T) undoContext;
   }
   if (adapter.equals(IProgressMonitor.class)) {
     if (progressDialog != null) {
       return (T) progressDialog.getProgressMonitor();
     }
   }
   if (site != null) {
     if (adapter.equals(Shell.class)) {
       return (T) getWorkbenchWindow().getShell();
     }
     if (adapter.equals(IWorkbenchWindow.class)) {
       return (T) getWorkbenchWindow();
     }
     if (adapter.equals(IWorkbenchPart.class)) {
       return (T) site.getPart();
     }
     // Refer all other requests to the part itself.
     // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=108144
     IWorkbenchPart part = site.getPart();
     if (part != null) {
       return Adapters.adapt(part, adapter);
     }
   }
   return null;
 }
 @Override
 public void init(IWorkbench workbench, IStructuredSelection selection) {
   if (selection != null) {
     for (Object item : selection.toList()) {
       File asFile = toFile(item);
       if (asFile != null && this.initialSelection == null) {
         this.initialSelection = asFile;
       } else {
         IWorkingSet asWorkingSet = Adapters.adapt(item, IWorkingSet.class);
         if (asWorkingSet != null) {
           this.initialWorkingSets.add(asWorkingSet);
         }
       }
     }
   }
 }