Exemplo n.º 1
0
 /**
  * Implementation of the <code>IUpdate</code> prototype method discovers the operation through the
  * current editor's <code>ITextOperationTarget</code> adapter, and sets the enabled state
  * accordingly.
  */
 public void update() {
   boolean isEnabled =
       (fOperationTarget != null
           && fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX)
           && fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
   setEnabled(isEnabled);
 }
 /**
  * Implementation of the <code>IUpdate</code> prototype method discovers the operation through the
  * current editor's <code>ITextOperationTarget</code> adapter, and sets the enabled state
  * accordingly.
  */
 public void update() {
   super.update();
   if (!canModifyEditor()) {
     setEnabled(false);
     return;
   }
   ITextEditor editor = getTextEditor();
   if (fOperationTarget == null && editor != null)
     fOperationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
   boolean isEnabled =
       (fOperationTarget != null
           && fOperationTarget.canDoOperation(ITextOperationTarget.PREFIX)
           && fOperationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
   setEnabled(isEnabled);
 }
  /**
   * Implementation of the <code>IAction</code> prototype. Checks if the selected lines are all
   * commented or not and uncomments/comments them respectively.
   */
  public void run() {
    if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null) return;
    ITextEditor editor = getTextEditor();
    if (editor == null) return;
    if (!validateEditorInputState()) return;
    final int operationCode;
    if (isSelectionCommented(editor.getSelectionProvider().getSelection()))
      operationCode = ITextOperationTarget.STRIP_PREFIX;
    else operationCode = ITextOperationTarget.PREFIX;
    Shell shell = editor.getSite().getShell();
    if (!fOperationTarget.canDoOperation(operationCode)) {
      if (shell != null)
        // MessageDialog.openError(shell,
        // JavaEditorMessages.getString("ToggleComment.error.title"),
        // JavaEditorMessages.getString("ToggleComment.error.message"));
        // //$NON-NLS-1$ //$NON-NLS-2$
        return;
    }
    Display display = null;
    if (shell != null && !shell.isDisposed()) display = shell.getDisplay();
    BusyIndicator.showWhile(
        display,
        new Runnable() {

          public void run() {
            fOperationTarget.doOperation(operationCode);
          }
        });
  }
Exemplo n.º 4
0
  /**
   * Implementation of the <code>IAction</code> prototype. Checks if the selected lines are all
   * commented or not and uncomments/comments them respectively.
   */
  @Override
  public void run() {
    if (fOperationTarget == null || fDocumentPartitioning == null || fPrefixesMap == null) return;

    final int operationCode;
    if (isSelectionCommented(fViewer.getSelectionProvider().getSelection()))
      operationCode = ITextOperationTarget.STRIP_PREFIX;
    else operationCode = ITextOperationTarget.PREFIX;

    Shell shell = fViewer.getTextWidget().getShell();
    if (!fOperationTarget.canDoOperation(operationCode)) {
      if (shell != null)
        MessageDialog.openError(
            shell,
            "An error occured",
            "ToggleComment_error_message=An error occurred while toggling comments."); //$NON-NLS-1$//$NON-NLS-2$
      return;
    }

    Display display = null;
    if (shell != null && !shell.isDisposed()) display = shell.getDisplay();

    BusyIndicator.showWhile(
        display,
        new Runnable() {
          public void run() {
            fOperationTarget.doOperation(operationCode);
          }
        });
  }
    @Override
    public void runWithEvent(Event event) {
      if (mCanFix) {
        ITextOperationTarget operation =
            (ITextOperationTarget) mTextEditor.getAdapter(ITextOperationTarget.class);
        final int opCode = ISourceViewer.QUICK_ASSIST;
        if (operation != null && operation.canDoOperation(opCode)) {
          mTextEditor.selectAndReveal(mPosition.getOffset(), mPosition.getLength());
          operation.doOperation(opCode);
        }
        return;
      }

      super.run();
    }
Exemplo n.º 6
0
    /**
     * Updates the enabled state of the action. Fires a property change if the enabled state
     * changes.
     *
     * @see Action#firePropertyChange(String, Object, Object)
     */
    public void update() {
      // XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=206111
      if (fOperationCode == ITextOperationTarget.REDO) return;

      boolean wasEnabled = isEnabled();
      boolean isEnabled =
          (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
      setEnabled(isEnabled);

      if (wasEnabled != isEnabled)
        firePropertyChange(
            ENABLED,
            wasEnabled ? Boolean.TRUE : Boolean.FALSE,
            isEnabled ? Boolean.TRUE : Boolean.FALSE);
    }
  /* (non-Javadoc)
   * @see org.eclipse.ui.texteditor.IUpdate#update()
   */
  @Override
  public void update() {
    super.update();

    if (!isReadOnlyOperation() && !canModifyEditor()) {
      setEnabled(false);
      return;
    }

    ITextEditor editor = getTextEditor();
    if (fOperationTarget == null && editor != null && fOperationCode != -1)
      fOperationTarget = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);

    boolean isEnabled =
        (fOperationTarget != null && fOperationTarget.canDoOperation(fOperationCode));
    setEnabled(isEnabled);
  }
  /*
   * @see org.eclipse.jface.action.IAction#runWithEvent(org.eclipse.swt.widgets.Event)
   * @since 3.2
   */
  public void runWithEvent(Event event) {
    if (fAnnotation instanceof OverrideIndicatorManager.OverrideIndicator) {
      ((OverrideIndicatorManager.OverrideIndicator) fAnnotation).open();
      return;
    }

    if (fHasCorrection) {
      ITextOperationTarget operation =
          (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class);
      final int opCode = ISourceViewer.QUICK_ASSIST;
      if (operation != null && operation.canDoOperation(opCode)) {
        fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength());
        operation.doOperation(opCode);
      }
      return;
    }

    super.run();
  }