Java 类org.eclipse.jface.text.ITextOperationTarget 实例源码

项目:codelens-eclipse    文件:EditorTracker.java   
private void editorOpened(IEditorPart part) {
    if (part instanceof ITextEditor) {
        ITextViewer textViewer = (ITextViewer) part.getAdapter(ITextOperationTarget.class);
        if (textViewer != null) {
            ICodeLensController controller = codeLensControllers.get(part);
            if (controller == null) {
                ITextEditor textEditor = (ITextEditor) part;
                controller = CodeLensControllerRegistry.getInstance().create(textEditor);
                if (controller != null) {
                    controller.setProgressMonitor(new NullProgressMonitor());
                    codeLensControllers.put(textEditor, controller);
                    //controller.install();
                }
            }
        }
    }
}
项目:iTrace-Archive    文件:AstManager.java   
/**
 * Constructor. Loads the AST and sets up the StyledText to automatically
 * reload after certain events.
 * @param editor IEditorPart which owns the following StyledText.
 * @param styledText StyledText to which this AST pertains.
 */
public AstManager(IEditorPart editor, StyledText styledText) {
    try {
        editorPath = ((IFileEditorInput) editor.getEditorInput()).getFile()
                .getFullPath().toFile().getCanonicalPath();
    } catch (IOException e) {
        // ignore IOErrors while constructing path
        editorPath = "?";
    }
    this.editor = editor;
    this.styledText = styledText;
    //This is the only why I know to get the ProjectionViewer. Perhaps there is better way. ~Ben
    ITextOperationTarget t = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class);
    if(t instanceof ProjectionViewer) projectionViewer = (ProjectionViewer)t;
    hookupAutoReload();
    reload();
}
项目:iTrace-Archive    文件:ITrace.java   
public void showTokenHighLights(){
    showTokenHighlights = !showTokenHighlights;
    if(activeEditor == null) return;
if(!tokenHighlighters.containsKey(activeEditor)){
    StyledText styledText = (StyledText) activeEditor.getAdapter(Control.class);
    if(styledText != null){
        ITextOperationTarget t = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        if(t instanceof ProjectionViewer){
            ProjectionViewer projectionViewer = (ProjectionViewer)t;
            tokenHighlighters.put(activeEditor, new TokenHighlighter(styledText, showTokenHighlights, projectionViewer));
        }
    }
}
    for(TokenHighlighter tokenHighlighter: tokenHighlighters.values()){
        tokenHighlighter.setShow(showTokenHighlights);
    }
  }
项目:mesfavoris    文件:SpellcheckableMessageArea.java   
private ActionHandler createContentAssistActionHandler(
        final ITextOperationTarget textOperationTarget) {
    Action proposalAction = new Action() {
        @Override
        public void run() {
            if (textOperationTarget
                    .canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS)
                    && getTextWidget().isFocusControl())
                textOperationTarget
                        .doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
        }
    };
    proposalAction
            .setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
    return new ActionHandler(proposalAction);
}
项目:typescript.java    文件:EditTemplateDialog.java   
private void handleVerifyKeyPressed(VerifyEvent event) {
    if (!event.doit)
        return;

    if (event.stateMask != SWT.MOD1)
        return;

    switch (event.character) {
    case ' ':
        fPatternEditor.doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
        event.doit = false;
        break;

    // CTRL-Z
    case 'z' - 'a' + 1:
        fPatternEditor.doOperation(ITextOperationTarget.UNDO);
        event.doit = false;
        break;
    }
}
项目:bts    文件:XtextMarkerRulerAction.java   
@Override
public void run() {
    try {
        // Move offset to the line of the annotation, if necessary
        IDocument document = getDocument();
        int annotationLine = ruler.getLineOfLastMouseButtonActivity();
        int annotationLineOffet = document.getLineOffset(annotationLine);
        Point currentSelection = textEditor.getInternalSourceViewer().getSelectedRange();
        int currentLine = document.getLineOfOffset(currentSelection.x);
        if (currentLine != annotationLine)
            textEditor.getInternalSourceViewer().setSelectedRange(annotationLineOffet, 0);

        // show QuickFix dialog
        ITextOperationTarget operation = (ITextOperationTarget) textEditor.getAdapter(ITextOperationTarget.class);
        final int opCode = ISourceViewer.QUICK_ASSIST;
        if (operation != null && operation.canDoOperation(opCode))
            operation.doOperation(opCode);
    } catch (BadLocationException e) {
        // Ignore -> do nothing
    }
}
项目:APICloud-Studio    文件:HTMLContentAssistProcessor.java   
@Override
public void apply(final ITextViewer viewer, char trigger, int stateMask, int offset)
{
    super.apply(viewer, trigger, stateMask, offset);
    // HACK pop CA back up if user selected a folder, but do it on a delay so that the folder
    // proposal insertion can finish properly (like updating selection/offset)
    if (viewer instanceof ITextOperationTarget && isDirectory)
    {
        UIUtils.getDisplay().asyncExec(new Runnable()
        {
            public void run()
            {
                if (((ITextOperationTarget) viewer).canDoOperation(ISourceViewer.CONTENTASSIST_PROPOSALS))
                {
                    ((ITextOperationTarget) viewer).doOperation(ISourceViewer.CONTENTASSIST_PROPOSALS);
                }
            }
        });
    }
}
项目:APICloud-Studio    文件:CommandExecutionUtils.java   
public static CommandResult executeCommand(CommandElement command, InvocationType invocationType,
        ITextEditor textEditor)
{
    ITextViewer textViewer = null;
    if (textEditor != null)
    {
        // FIXME This is pretty bad here. What we want is the ISourceViewer of the editor (which is a subinterface
        // of ITextViewer). It just happens that sourceViewer.getTextOperationTarget returns self in this case.
        Object adapter = textEditor.getAdapter(ITextOperationTarget.class);
        if (adapter instanceof ITextViewer)
        {
            textViewer = (ITextViewer) adapter;
        }
    }
    return executeCommand(command, invocationType, textViewer, textEditor);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSelectAnnotationRulerAction.java   
@Override
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();
}
项目:Eclipse-Postfix-Code-Completion    文件:ClipboardOperationAction.java   
/**
 * Creates the action.
 * @param bundle the resource bundle
 * @param prefix a prefix to be prepended to the various resource keys
 *   (described in <code>ResourceAction</code> constructor), or
 *   <code>null</code> if none
 * @param editor the text editor
 * @param operationCode the operation code
 */
public ClipboardOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) {
    super(bundle, prefix, editor);
    fOperationCode= operationCode;

    if (operationCode == ITextOperationTarget.CUT) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.CUT_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT);
    } else if (operationCode == ITextOperationTarget.COPY) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.COPY_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
    } else if (operationCode == ITextOperationTarget.PASTE) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.PASTE_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE);
    } else {
        Assert.isTrue(false, "Invalid operation code"); //$NON-NLS-1$
    }
    update();
}
项目:translationstudio8    文件:SegmentViewer.java   
/**
 * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
 */
private void copy() {
    super.doOperation(ITextOperationTarget.COPY);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    XLiffTextTransfer hsTextTransfer = XLiffTextTransfer.getInstance();
    Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
    String plainText = (String) clipboard.getContents(plainTextTransfer);
    if (plainText == null || plainText.length() == 0) {
        return;
    }
    plainText = plainText.replaceAll(Utils.getLineSeparator(), "\n");
    plainText = plainText.replaceAll(Constants.LINE_SEPARATOR_CHARACTER + "", "");
    plainText = plainText.replaceAll(Constants.TAB_CHARACTER + "", "\t");
    plainText = plainText.replaceAll(Constants.SPACE_CHARACTER + "", " ");
    plainText = plainText.replaceAll("\u200B", "");
    clipboard.clearContents();
    Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
    Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };

    clipboard.setContents(data, types, DND.CLIPBOARD);
    clipboard.dispose();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaSelectAnnotationRulerAction.java   
@Override
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();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:ClipboardOperationAction.java   
/**
 * Creates the action.
 * @param bundle the resource bundle
 * @param prefix a prefix to be prepended to the various resource keys
 *   (described in <code>ResourceAction</code> constructor), or
 *   <code>null</code> if none
 * @param editor the text editor
 * @param operationCode the operation code
 */
public ClipboardOperationAction(ResourceBundle bundle, String prefix, ITextEditor editor, int operationCode) {
    super(bundle, prefix, editor);
    fOperationCode= operationCode;

    if (operationCode == ITextOperationTarget.CUT) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.CUT_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_CUT);
    } else if (operationCode == ITextOperationTarget.COPY) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.COPY_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
    } else if (operationCode == ITextOperationTarget.PASTE) {
        setHelpContextId(IAbstractTextEditorHelpContextIds.PASTE_ACTION);
        setActionDefinitionId(IWorkbenchCommandConstants.EDIT_PASTE);
    } else {
        Assert.isTrue(false, "Invalid operation code"); //$NON-NLS-1$
    }
    update();
}
项目:tmxeditor8    文件:CellEditorTextViewer.java   
/**
 * 执行复制时对标记的处理,复制后在OS系统中不能包含标记占位符 ;
 */
private void copy() {
    super.doOperation(ITextOperationTarget.COPY);
    TextTransfer plainTextTransfer = TextTransfer.getInstance();
    HSTextTransfer hsTextTransfer = HSTextTransfer.getInstance();
    Clipboard clipboard = new Clipboard(getTextWidget().getDisplay());
    String plainText = (String) clipboard.getContents(plainTextTransfer);
    if (plainText == null || plainText.length() == 0) {
        return;
    }
    plainText = plainText.replaceAll(System.getProperty("line.separator"), "\n");
    plainText = plainText.replaceAll(TmxEditorConstanst.LINE_SEPARATOR_CHARACTER + "", "");
    plainText = plainText.replaceAll(TmxEditorConstanst.TAB_CHARACTER + "", "\t");
    plainText = plainText.replaceAll(TmxEditorConstanst.SPACE_CHARACTER + "", " ");
    plainText = plainText.replaceAll("\u200B", "");
    clipboard.clearContents();
    Object[] data = new Object[] { PATTERN.matcher(plainText).replaceAll(""), plainText };
    Transfer[] types = new Transfer[] { plainTextTransfer, hsTextTransfer };

    clipboard.setContents(data, types);
    clipboard.dispose();
}
项目:wt-studio    文件:JsonTextEditor.java   
public void restoreTextLocation() {

        if (!restoreCursorLocation) {
            return;
        }

        restoreCursorLocation = false;

        ITextOperationTarget target = (ITextOperationTarget) this.getAdapter(ITextOperationTarget.class);
        if (!(target instanceof ITextViewer)) {
            return ;
        }
        ITextViewer textViewer = (ITextViewer) target;
        if (nodes != null && nodes.size() > nodePosition) {
            Node node = nodes.get(nodePosition);
            if (node != null) {
                int textLocation = node.getPosition().getOffset() + nodePositionOffset;
                textViewer.getTextWidget().setSelection(textLocation);
            }
        }
    }
项目:eclipseRecorder    文件:MultiEditorPageChangedListener.java   
@Override
public void pageChanged(PageChangedEvent event) {
    Object selectedPage = event.getSelectedPage();
    if (seenPages.contains(selectedPage))
        return;

    seenPages.add(selectedPage);
    if (selectedPage instanceof AbstractTextEditor) {
        IEditorPart editorPart = (IEditorPart) selectedPage;
        IProject project = plugin.getProjectForEditor(editorPart.getEditorInput());
        if (plugin.getIgnoreProjectsList().contains(project.getName()))
            return;
        ISourceViewer sourceViewer = (ISourceViewer) editorPart.getAdapter(ITextOperationTarget.class);
        sourceViewer.getDocument().addDocumentListener(new DocumentListener());
    }
}
项目:logan    文件:SearchResultViewer.java   
@Override
protected void createControl(Composite parent, int styles) {
  super.createControl(parent, styles);
  final StyledText styledText = getTextWidget();

  IMenuListener menuListener = new IMenuListener() {
    @Override
    public void menuAboutToShow(IMenuManager menu) {
      Action copyAction = createAction(ITextOperationTarget.COPY, IWorkbenchCommandConstants.EDIT_COPY);
      copyAction.setText(WorkbenchMessages.Workbench_copy);
      copyAction.setToolTipText(WorkbenchMessages.Workbench_copyToolTip);
      ISharedImages sharedImages = AppUtils.getActiveWorkbenchWindow().getWorkbench().getSharedImages();
      copyAction.setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
      copyAction.setDisabledImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_COPY_DISABLED));
      menu.add(copyAction);
    }
  };

  MenuManager manager = new MenuManager(CONTEXT_MENU_ID, CONTEXT_MENU_ID);
  manager.setRemoveAllWhenShown(true);
  Menu contextMenu = manager.createContextMenu(styledText);
  styledText.setMenu(contextMenu);
  manager.addMenuListener(menuListener);
}
项目:ContentAssist    文件:EditorUtilities.java   
/**
 * Obtains the source viewer of an editor.
 * @param editor the editor
 * @return the source viewer of the editor
 */
public static ISourceViewer getSourceViewer(IEditorPart editor) {
    if (editor == null) {
        return null;
    }

    ISourceViewer viewer = (ISourceViewer)editor.getAdapter(ITextOperationTarget.class);
    return viewer;
}
项目:codelens-eclipse    文件:EditorTracker.java   
@Override
public void partActivated(IWorkbenchPart part) {
    if (part instanceof ITextEditor) {
        ITextViewer textViewer = (ITextViewer) part.getAdapter(ITextOperationTarget.class);
        if (textViewer != null) {
            ICodeLensController controller = codeLensControllers.get(part);
            if (controller != null) {
                controller.refresh();
            }
        }
    }
}
项目:codelens-eclipse    文件:DefaultCodeLensController.java   
@Override
public void refresh() {
    if (textViewer == null) {
        this.textViewer = (ITextViewer) getTextEditor().getAdapter(ITextOperationTarget.class);
        reconciler.install(textViewer);
    }
    getStrategy().initialReconcile();
}
项目:iTrace-Archive    文件:ITrace.java   
public void setActiveEditor(IEditorPart editorPart){
    activeEditor = editorPart;
    if(activeEditor == null) return;
    if(!tokenHighlighters.containsKey(editorPart)){
        StyledText styledText = (StyledText) editorPart.getAdapter(Control.class);
        if(styledText != null){
    ITextOperationTarget t = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
    if(t instanceof ProjectionViewer){
        ProjectionViewer projectionViewer = (ProjectionViewer)t;
        tokenHighlighters.put(activeEditor, new TokenHighlighter(styledText, showTokenHighlights, projectionViewer));
    }
}
    }

 }
项目:tm4e    文件:TMPresentationReconciler.java   
public static TMPresentationReconciler getTMPresentationReconciler(IEditorPart editorPart) {
    ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class);
    if (target instanceof ITextViewer) {
        ITextViewer textViewer = ((ITextViewer) target);
        return TMPresentationReconciler.getTMPresentationReconciler(textViewer);
    }
    return null;
}
项目:DarwinSPL    文件:DwprofileToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof de.darwinspl.preferences.resource.dwprofile.ui.DwprofileEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HyexpressionToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.feature.expression.resource.hyexpression.ui.HyexpressionEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HyvalidityformulaToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.context.contextValidity.resource.hyvalidityformula.ui.HyvalidityformulaEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HydatavalueToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.dataValues.resource.hydatavalue.ui.HydatavalueEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HymappingToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.feature.mapping.resource.hymapping.ui.HymappingEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HyconstraintsToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.feature.constraint.resource.hyconstraints.ui.HyconstraintsEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:DarwinSPL    文件:HymanifestToggleCommentHandler.java   
@Override

public boolean isEnabled() {
    IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor instanceof eu.hyvar.mspl.manifest.resource.hymanifest.ui.HymanifestEditor) {
        ITextOperationTarget operationTarget = (ITextOperationTarget) activeEditor.getAdapter(ITextOperationTarget.class);
        return (operationTarget != null && operationTarget.canDoOperation(ITextOperationTarget.PREFIX) && operationTarget.canDoOperation(ITextOperationTarget.STRIP_PREFIX));
    }
    return false;
}
项目:google-cloud-eclipse    文件:ValidationTestUtils.java   
static ITextViewer getViewer(IFile file) {
  IWorkbench workbench = PlatformUI.getWorkbench();
  IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
  IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
  IEditorPart editorPart = ResourceUtil.findEditor(activePage, file);

  ITextOperationTarget target = editorPart.getAdapter(ITextOperationTarget.class);
  if (target instanceof ITextViewer) {
    return (ITextViewer) target;
  }
  return null;
}
项目:mesfavoris    文件:SpellcheckableMessageArea.java   
private ActionHandler createQuickFixActionHandler(
        final ITextOperationTarget textOperationTarget) {
    Action quickFixAction = new Action() {

        @Override
        public void run() {
            textOperationTarget.doOperation(ISourceViewer.QUICK_ASSIST);
        }
    };
    quickFixAction
    .setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST);
    return new ActionHandler(quickFixAction);
}
项目:tlaplus    文件:ToggleCommentAction.java   
/**
 * 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, TLAEditorMessages.getString("ToggleComment.error.title"),
                    TLAEditorMessages.getString("ToggleComment.error.message"));
        return;
    }

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

    BusyIndicator.showWhile(display, new Runnable() {
        public void run()
        {
            fOperationTarget.doOperation(operationCode);
        }
    });
}
项目:typescript.java    文件:EditorUtils.java   
public static ISourceViewer getSourceViewer(IEditorPart editor) {
    if (editor == null) {
        return null;
    }

    ISourceViewer viewer = (ISourceViewer) editor.getAdapter(ITextOperationTarget.class);

    return viewer;
}
项目:bts    文件:ToggleSLCommentAction.java   
/**
 * 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;

    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, Messages.ToggleSLCommentAction_0, Messages.ToggleSLCommentAction_1); 
        return;
    }

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

    BusyIndicator.showWhile(display, new Runnable() {
        public void run() {
            fOperationTarget.doOperation(operationCode);
        }
    });
}
项目:TeamFileList    文件:SourceViewerKeyHandler.java   
public void verifyKey(VerifyEvent event) {
    if (!fViewer.isEditable()) {
        return;
    }
    if (event.stateMask == SWT.CTRL) {
        switch (event.keyCode) {
        case 'z':
            fTarget.doOperation(ITextOperationTarget.UNDO);
            break;
        case 'y':
            fTarget.doOperation(ITextOperationTarget.REDO);
            break;
        }
    }
}
项目:velocity-edit    文件:ToggleCommentAction.java   
/**
 * 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);
        }
    });
}
项目:KaiZen-OpenAPI-Editor    文件:OpenQuickOutlineHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    ISourceViewer viewer = null;

    Object activeFocusControl = HandlerUtil.getVariable(event, "activeFocusControl"); //$NON-NLS-1$
    if (activeFocusControl instanceof Control) {
        Control control = (Control) activeFocusControl;
        if (!control.isDisposed()) {
            viewer = (ISourceViewer) control.getData(ISourceViewer.class.getName());
        }
    }

    if (viewer == null) {
        IEditorPart editor = HandlerUtil.getActiveEditor(event);
        if (editor instanceof JsonEditor) {
            viewer = ((JsonEditor) editor).getProjectionViewer();
        }
    }

    if (viewer != null) {
        ITextOperationTarget operationTarget = viewer.getTextOperationTarget();
        if (operationTarget.canDoOperation(QUICK_OUTLINE)) {
            operationTarget.doOperation(QUICK_OUTLINE);
        }
    }

    return null;
}
项目:APICloud-Studio    文件:CommandExecutionUtils.java   
public static void processCommandResult(CommandElement command, CommandResult commandResult, ITextEditor textEditor)
{
    ITextViewer textViewer = null;
    if (textEditor != null)
    {
        Object adapter = textEditor.getAdapter(ITextOperationTarget.class);
        if (adapter instanceof ITextViewer)
        {
            textViewer = (ITextViewer) adapter;
        }
    }
    processCommandResult(command, commandResult, textViewer);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaSelectMarkerRulerAction2.java   
@Override
public void annotationDefaultSelected(VerticalRulerEvent event) {
    Annotation annotation= event.getSelectedAnnotation();
    IAnnotationModel model= getAnnotationModel();

    if (isOverrideIndicator(annotation)) {
        ((OverrideIndicatorManager.OverrideIndicator)annotation).open();
        return;
    }

    if (isBreakpoint(annotation))
        triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK, event.getEvent());

    Position position= model.getPosition(annotation);
    if (position == null)
        return;

    if (isQuickFixTarget(annotation)) {
        ITextOperationTarget operation= (ITextOperationTarget) getTextEditor().getAdapter(ITextOperationTarget.class);
        final int opCode= ISourceViewer.QUICK_ASSIST;
        if (operation != null && operation.canDoOperation(opCode)) {
            getTextEditor().selectAndReveal(position.getOffset(), position.getLength());
            operation.doOperation(opCode);
            return;
        }
    }

    // default:
    super.annotationDefaultSelected(event);
}
项目:Eclipse-Postfix-Code-Completion    文件:ClipboardOperationAction.java   
protected final void internalDoOperation() {
    if (PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_IMPORTS_ON_PASTE) && isSmartInsertMode()) {
        if (fOperationCode == ITextOperationTarget.PASTE) {
            doPasteWithImportsOperation();
        } else {
            doCutCopyWithImportsOperation();
        }
    } else {
        fOperationTarget.doOperation(fOperationCode);
    }
}