private boolean checkEnabled(ITextSelection selection) {
    if (selection == null || selection.isEmpty()) return false;

    // XXX: Must be changed to IStorageEditorInput once support for JARs is available (see class
    // Javadoc for details)
    return fEditor.getEditorInput() instanceof IFileEditorInput;
  }
Beispiel #2
0
  public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    ITextEditor textEditor = null;
    if (editor instanceof ITextEditor) textEditor = (ITextEditor) editor;
    else {
      Object o = editor.getAdapter(ITextEditor.class);
      if (o != null) textEditor = (ITextEditor) o;
    }
    if (textEditor != null) {
      IDocument document =
          textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());

      if (document != null) {
        // get current text selection
        ITextSelection textSelection = getCurrentSelection(textEditor);

        // If there is alternating or more then one block in the text
        // selection, action is aborted !
        if (isMoreThanOneContextBlockSelected(document, textSelection)) {
          // displayCommentActinosErrorDialog(editor);
          // return null;
          org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
              addBlockCommentHandlerWST =
                  new org.eclipse.wst.sse.ui.internal.handlers
                      .AddBlockCommentHandler(); // org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
          return addBlockCommentHandlerWST.execute(event);
        }

        if (textSelection.isEmpty()) {
          return null;
        }
        if (document instanceof IStructuredDocument) {
          int selectionOffset = textSelection.getOffset();
          IStructuredDocument sDoc = (IStructuredDocument) document;
          IStructuredDocumentRegion sdRegion = sDoc.getRegionAtCharacterOffset(selectionOffset);
          ITextRegion textRegion = sdRegion.getRegionAtCharacterOffset(selectionOffset);

          ITextRegionCollection container = sdRegion;

          if (textRegion instanceof ITextRegionContainer) {
            container = (ITextRegionContainer) textRegion;
            textRegion = container.getRegionAtCharacterOffset(selectionOffset);
          }
          if (textRegion.getType() == PHPRegionContext.PHP_CONTENT) {
            processAction(textEditor, document, textSelection);
          } else {
            org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler
                addBlockCommentHandlerWST =
                    new org.eclipse.wst.sse.ui.internal.handlers.AddBlockCommentHandler();
            return addBlockCommentHandlerWST.execute(event);
          }
        }
      }
    }
    return null;
  }
 /*
  * @see
  * org.eclipse.jdt.internal.ui.actions.BlockCommentAction#validSelection(org.eclipse
  * .jface.text.ITextSelection)
  */
 @Override
 protected boolean isValidSelection(ITextSelection selection) {
   return selection != null && !selection.isEmpty() && selection.getLength() > 0;
 }