@Override
 public void setContext(ActionContext context) {
   super.setContext(context);
   if (context != null) {
     ISelection selection = context.getSelection();
     IStructuredSelection structuredSelection =
         selection instanceof IStructuredSelection
             ? (IStructuredSelection) selection
             : StructuredSelection.EMPTY;
     removeAction.setEnabled(removeAction.updateSelection(structuredSelection));
     cutAction.setEnabled(cutAction.updateSelection(structuredSelection));
     copyAction.setEnabled(copyAction.updateSelection(structuredSelection));
     pasteAction.setEnabled(pasteAction.updateSelection(structuredSelection));
     undoAction.update();
     redoAction.update();
   }
 }
  @Override
  public void fillContextMenu(IMenuManager menuManager) {
    menuManager.appendToGroup(
        ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(undoAction));
    menuManager.appendToGroup(
        ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(redoAction));
    menuManager.appendToGroup(ICommonMenuConstants.GROUP_EDIT, new Separator());
    menuManager.appendToGroup(
        ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(cutAction));
    menuManager.appendToGroup(
        ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(copyAction));
    menuManager.appendToGroup(
        ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(pasteAction));

    IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();

    boolean anyResourceSelected = !selection.isEmpty();
    if (anyResourceSelected) {
      removeAction.selectionChanged(selection);
      menuManager.appendToGroup(
          ICommonMenuConstants.GROUP_EDIT, new ActionContributionItem(removeAction));
    }
  }
  /**
   * Open a file
   *
   * @param jf
   */
  @Override
  public void init(ICommonActionExtensionSite aSite) {
    super.init(aSite);
    ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
    EditingDomain domain = new MindEditingDomain((MindUICore.mindViewAdapterFactory()));
    removeAction =
        new DeleteAction(domain, removeAllReferencesOnDelete()) {
          public void run() {
            if (MessageDialog.openConfirm(null, "Do you want delete ?", "Do you want delete ?"))
              super.run();
          }

          public boolean updateSelection(IStructuredSelection selection) {
            for (Object obj : selection.toArray()) {
              if (obj instanceof MindObject && isReadOnly((MindObject) obj)) return false;
            }
            return super.updateSelection(selection);
          }

          private boolean isReadOnly(EObject obj) {
            if (obj == MindIdeCore.getModel().getLocalRepo()) return true;
            if (obj.eContainer() != null) return isReadOnly(obj.eContainer());
            return false;
          };
        };

    /* The delete action is now a "remove" action, the previous "delete" behavior was too extreme.
     * We just want to delete EMF references but not the files.
     */
    removeAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_ELCL_REMOVE));

    cutAction = new CutAction(domain);
    cutAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_CUT));

    copyAction = new CopyAction(domain);
    copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));

    pasteAction = new PasteAction(domain);
    pasteAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));

    undoAction = new UndoAction(domain);
    undoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));

    redoAction = new RedoAction(domain);
    redoAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_REDO));

    aSite
        .getStructuredViewer()
        .addDoubleClickListener(
            new IDoubleClickListener() {
              public void doubleClick(DoubleClickEvent event) {
                StructuredSelection ss = (StructuredSelection) event.getSelection();
                Object obj = ss.getFirstElement();
                if (obj != null) {
                  if (!(obj instanceof IFile) && obj instanceof IAdaptable) {
                    obj = ((IAdaptable) obj).getAdapter(IFile.class);
                  } else {
                    obj = Platform.getAdapterManager().getAdapter(obj, IFile.class);
                  }
                  if (obj instanceof IFile) {
                    Activator.openFile((IFile) obj);
                  }
                }
              }
            });
  }