Java 类org.eclipse.ui.texteditor.ITextEditor 实例源码

项目:mesfavoris    文件:GetLinkedBookmarksOperationTest.java   
@Test
public void testGetLinkedBookmarksInMultipageEditor() throws Exception {
    // Given
    importProjectFromTemplate("testGetLinkedBookmarksInMultipageEditor", "commons-cli");
    Bookmark bookmark = bookmark("pom.xml")
            .withProperty(PROP_WORKSPACE_PATH, "/testGetLinkedBookmarksInMultipageEditor/pom.xml")
            .withProperty(PROP_LINE_NUMBER, "10").build();
    addBookmark(rootFolderId, bookmark);
    waitUntil("Cannot find marker", () -> bookmarksMarkers.findMarker(bookmark.getId(), null));

    // When
    IEditorPart editorPart = openEditor(new Path("/testGetLinkedBookmarksInMultipageEditor/pom.xml"));
    // that's why we require org.eclipse.m2e.editor in MANIFEST.MF
    assertThat(editorPart).isInstanceOf(MultiPageEditorPart.class);
    ITextEditor textEditor = getTextEditor(editorPart);
    selectAndReveal(textEditor, getOffset(textEditor, 10));
    List<Bookmark> bookmarks = operation.getLinkedBookmarks(textEditor, getSelection(textEditor));

    // Then
    assertEquals(1, bookmarks.size());
    assertEquals(bookmark, bookmarks.get(0));
}
项目: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();
                }
            }
        }
    }
}
项目:codelens-eclipse    文件:LSPCodeLensProvider.java   
@Override
public CompletableFuture<ICodeLens> resolveCodeLens(ICodeLensContext context, ICodeLens codeLens,
        IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();

    LSPDocumentInfo info = null;
    Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(
            LSPEclipseUtils.getDocument((ITextEditor) textEditor),
            capabilities -> capabilities.getCodeLensProvider() != null
                    && capabilities.getCodeLensProvider().isResolveProvider());
    if (!infos.isEmpty()) {
        info = infos.iterator().next();
    } else {
        info = null;
    }
    if (info != null) {
        LSPCodeLens lscl = ((LSPCodeLens) codeLens);
        CodeLens unresolved = lscl.getCl();
        return info.getLanguageClient().getTextDocumentService().resolveCodeLens(unresolved).thenApply(resolved -> {
            lscl.update(resolved);
            return lscl;
        });
    }
    return null;
}
项目:Open_Source_ECOA_Toolset_AS5    文件:CompDefEditorContributor.java   
public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part)
        return;

    activeEditorPart = part;

    IActionBars actionBars = getActionBars();
    if (actionBars != null) {

        ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;

        actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE));
        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(editor, ITextEditorActionConstants.UNDO));
        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(editor, ITextEditorActionConstants.REDO));
        actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(editor, ITextEditorActionConstants.CUT));
        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(editor, ITextEditorActionConstants.COPY));
        actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(editor, ITextEditorActionConstants.PASTE));
        actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(editor, ITextEditorActionConstants.SELECT_ALL));
        actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction(editor, ITextEditorActionConstants.FIND));
        actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(editor, IDEActionFactory.BOOKMARK.getId()));
        actionBars.updateActionBars();
    }
}
项目:Open_Source_ECOA_Toolset_AS5    文件:TypesEditorContributor.java   
public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part)
        return;

    activeEditorPart = part;

    IActionBars actionBars = getActionBars();
    if (actionBars != null) {

        ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;

        actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE));
        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(editor, ITextEditorActionConstants.UNDO));
        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(editor, ITextEditorActionConstants.REDO));
        actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(editor, ITextEditorActionConstants.CUT));
        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(editor, ITextEditorActionConstants.COPY));
        actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(editor, ITextEditorActionConstants.PASTE));
        actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(editor, ITextEditorActionConstants.SELECT_ALL));
        actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction(editor, ITextEditorActionConstants.FIND));
        actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(editor, IDEActionFactory.BOOKMARK.getId()));
        actionBars.updateActionBars();
    }
}
项目:Open_Source_ECOA_Toolset_AS5    文件:ServicesEditorContributor.java   
public void setActivePage(IEditorPart part) {
    if (activeEditorPart == part)
        return;

    activeEditorPart = part;

    IActionBars actionBars = getActionBars();
    if (actionBars != null) {

        ITextEditor editor = (part instanceof ITextEditor) ? (ITextEditor) part : null;

        actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), getAction(editor, ITextEditorActionConstants.DELETE));
        actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), getAction(editor, ITextEditorActionConstants.UNDO));
        actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), getAction(editor, ITextEditorActionConstants.REDO));
        actionBars.setGlobalActionHandler(ActionFactory.CUT.getId(), getAction(editor, ITextEditorActionConstants.CUT));
        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), getAction(editor, ITextEditorActionConstants.COPY));
        actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), getAction(editor, ITextEditorActionConstants.PASTE));
        actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), getAction(editor, ITextEditorActionConstants.SELECT_ALL));
        actionBars.setGlobalActionHandler(ActionFactory.FIND.getId(), getAction(editor, ITextEditorActionConstants.FIND));
        actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(editor, IDEActionFactory.BOOKMARK.getId()));
        actionBars.updateActionBars();
    }
}
项目:pgcodekeeper    文件:NavigatorOutlineActionProvider.java   
@Override
public void run() {
    if (isEnabled()) {
        try {
            ITextEditor editor = (ITextEditor) IDE.openEditor(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
                    segment.getParentFile(), EDITOR.SQL, true);
            editor.setHighlightRange(segment.offset, segment.length, true);
            editor.selectAndReveal(segment.offset, segment.length);
        } catch (PartInitException e) {
            Log.log(e);
            ExceptionNotifier.notifyDefault(Messages.PgNavigatorActionProvider_failed_to_open_editor, e);
        }
    }
}
项目:pgcodekeeper    文件:FileUtilsUi.java   
/**
 * Saves the content as a temp-file, opens it using SQL-editor
 * and ensures that UTF-8 is used for everything.
 */
public static void saveOpenTmpSqlEditor(String content, String filenamePrefix) throws IOException, CoreException {
    Log.log(Log.LOG_INFO, "Creating file " + filenamePrefix); //$NON-NLS-1$
    Path path = Files.createTempFile(filenamePrefix + '_', ".sql"); //$NON-NLS-1$
    Files.write(path, content.getBytes(StandardCharsets.UTF_8));
    IFileStore externalFile = EFS.getLocalFileSystem().fromLocalFile(path.toFile());
    IEditorInput input = new FileStoreEditorInput(externalFile);

    IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
            .openEditor(input, EDITOR.SQL);
    if (part instanceof ITextEditor) {
        IDocumentProvider prov = ((ITextEditor) part).getDocumentProvider();
        if (prov instanceof TextFileDocumentProvider) {
            ((TextFileDocumentProvider) prov).setEncoding(input, ApgdiffConsts.UTF_8);
            prov.resetDocument(input);
        }
    }
}
项目:vertigo-chroma-kspplugin    文件:UiUtils.java   
public static String getCurrentEditorCurrentWord(WordSelectionType wordSelectionType) {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

    /* Extrait l'éditeur courant. */
    ITextEditor editor = (ITextEditor) activePage.getActiveEditor();
    if (editor == null) {
        return null;
    }

    /* Extrait la sélection courante. */
    ITextSelection selection = (ITextSelection) activePage.getSelection();
    if (selection == null) {
        return null;
    }

    /* Extrait le document courant. */
    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

    /* Extrait le mot sélectionné. */
    ITextSelection currentWordSelection = DocumentUtils.findCurrentWord(document, selection, wordSelectionType);
    if (currentWordSelection == null) {
        return null;
    }

    return currentWordSelection.getText();
}
项目:dsp4e    文件:DSPBreakpointAdapter.java   
@Override
public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
    ITextEditor textEditor = getEditor(part);
    if (textEditor != null) {
        IResource resource = textEditor.getEditorInput().getAdapter(IResource.class);
        ITextSelection textSelection = (ITextSelection) selection;
        int lineNumber = textSelection.getStartLine();
        IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager()
                .getBreakpoints(DSPPlugin.ID_DSP_DEBUG_MODEL);
        for (int i = 0; i < breakpoints.length; i++) {
            IBreakpoint breakpoint = breakpoints[i];
            if (breakpoint instanceof ILineBreakpoint && resource.equals(breakpoint.getMarker().getResource())) {
                if (((ILineBreakpoint) breakpoint).getLineNumber() == (lineNumber + 1)) {
                    // remove
                    breakpoint.delete();
                    return;
                }
            }
        }
        // create line breakpoint (doc line numbers start at 0)
        DSPLineBreakpoint lineBreakpoint = new DSPLineBreakpoint(resource, lineNumber + 1);
        DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
    }
}
项目:ec4e    文件:EditorConfigCodeLensProvider.java   
@Override
protected ICodeLens resolveSyncCodeLens(ICodeLensContext context, ICodeLens codeLens, IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
    IFile file = EditorUtils.getFile(textEditor);
    if (file == null) {
        return null;
    }
    EditorConfigCodeLens cl = (EditorConfigCodeLens) codeLens;
    CountSectionPatternVisitor visitor = new CountSectionPatternVisitor(cl.getSection());
    try {
        file.getParent().accept(visitor, IResource.NONE);
        cl.update(visitor.getNbFiles() + " files match");
    } catch (CoreException e) {
        cl.update(e.getMessage());
    }
    return cl;
}
项目:ec4e    文件:PreferenceStoreHelper.java   
public static IPreferenceStore contributeToPreferenceStore(ITextEditor textEditor,
        IPreferenceStore preferenceStore) {
    try {
        // Get old store
        IPreferenceStore oldStore = getPreferenceStore(textEditor);
        // Create chained store with preference store to add
        IPreferenceStore newStore = new ChainedPreferenceStore(
                new IPreferenceStore[] { preferenceStore, oldStore });
        // Update the text editor with new preference store
        setPreferenceStoreOfTextEditor(textEditor, newStore);
        // Update the source viewer configuration with new preference store
        setPreferenceStoreOfSourceViewerConfiguration(textEditor, newStore);
        return newStore;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

}
项目:eclemma    文件:CoverageAnnotationModel.java   
/**
 * Attaches a coverage annotation model for the given editor if the editor can
 * be annotated. Does nothing if the model is already attached.
 *
 * @param editor
 *          Editor to attach a annotation model to
 */
public static void attach(ITextEditor editor) {
  IDocumentProvider provider = editor.getDocumentProvider();
  // there may be text editors without document providers (SF #1725100)
  if (provider == null)
    return;
  IAnnotationModel model = provider.getAnnotationModel(editor
      .getEditorInput());
  if (!(model instanceof IAnnotationModelExtension))
    return;
  IAnnotationModelExtension modelex = (IAnnotationModelExtension) model;

  IDocument document = provider.getDocument(editor.getEditorInput());

  CoverageAnnotationModel coveragemodel = (CoverageAnnotationModel) modelex
      .getAnnotationModel(KEY);
  if (coveragemodel == null) {
    coveragemodel = new CoverageAnnotationModel(editor, document);
    modelex.addAnnotationModel(KEY, coveragemodel);
  }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Creates warning markers for undefined references. 
 * 
 * @param editor The editor to add the errors to
 * @param errors The errors to add as instances of <code>DocumentReference</code>
 */
public void createReferencingErrorMarkers(ITextEditor editor, List<DocumentReference> errors) {

    IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
    if (resource == null) return;
    IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());

    for (DocumentReference msg : errors) {
        try {
            int beginOffset = document.getLineOffset(msg.getLine() - 1) + msg.getPos();

            Map<String, ? super Object> map = new HashMap<String, Object>();
            map.put(IMarker.LINE_NUMBER, Integer.valueOf(msg.getLine()));
            map.put(IMarker.CHAR_START, Integer.valueOf(beginOffset));
            map.put(IMarker.CHAR_END, Integer.valueOf(beginOffset + msg.getLength()));
            map.put(IMarker.MESSAGE, "Key " + msg.getKey() + " is undefined");
            map.put(IMarker.SEVERITY, Integer.valueOf(IMarker.SEVERITY_WARNING));

            MarkerUtilities.createMarker(resource, map, IMarker.PROBLEM);
        } catch (CoreException ce) {
            TexlipsePlugin.log("Creating marker", ce);
        } catch (BadLocationException ble) {
            TexlipsePlugin.log("Creating marker", ble);
        }
    }
}
项目:texlipse    文件:MarkerHandler.java   
/**
 * Delete all error markers from the currently open file.
 * 
 * @param editor The editor to clear the markers from
 */
public void clearErrorMarkers(ITextEditor editor) {
    // talk about ugly code...
    // TODO if this case occurs, then the user has probably not correctly created a project
    // -> we should somehow inform the user
    IResource resource = (IResource) editor.getEditorInput().getAdapter(IResource.class);
    if (resource == null) return;

    try {
        // TODO what should we clear and when?
        // regular problems == parsing errors
        resource.deleteMarkers(IMarker.PROBLEM, false, IResource.DEPTH_INFINITE);
        // builder markers == build problems (don't clean them)
        //resource.deleteMarkers(TexlipseBuilder.MARKER_TYPE, false, IResource.DEPTH_INFINITE);
        // don't clear spelling errors
    } catch (CoreException e) {
        TexlipsePlugin.log("Deleting error markers", e);
    }
}
项目:texlipse    文件:TexSelections.java   
/**
 * Takes a text editor as a parameter and sets variables 
 * to correspond selection features.
 * 
 * @param textEditor The currenct text editor
 */
public TexSelections(ITextEditor textEditor) {

    // Get the document
    this.document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
    this.editor = textEditor;

    // Get the selection
    this.textSelection = (ITextSelection) this.editor.getSelectionProvider().getSelection();

    this.startLineIndex = this.textSelection.getStartLine();
    this.endLineIndex = this.textSelection.getEndLine();
    this.selLength = this.textSelection.getLength();

    // Store selection information
    select();
}
项目:texlipse    文件:SpellCheckAction.java   
/**
    * Run the spell check action.
    * @param action the action
 */
public void run(IAction action) {

       if (targetEditor == null) {
           return;
       }
       if (!(targetEditor instanceof ITextEditor)) {
           return;
       }

       ITextEditor textEditor = (ITextEditor) targetEditor;
       IEditorInput input = textEditor.getEditorInput();

       IFile file = ((FileEditorInput) input).getFile();

       SpellChecker.checkSpelling(textEditor.getDocumentProvider().getDocument(input), file);
}
项目:mesfavoris    文件:TextEditorBookmarkPropertiesProvider.java   
private void addBookmarkProperties(Map<String, String> properties, ITextEditor textEditor,
        ITextSelection textSelection) {
    int lineNumber = textSelection.getStartLine();
    addLineNumber(properties, lineNumber);
    addLineContent(properties, textEditor, lineNumber);
    addWorkspacePath(properties, textEditor);
    putIfAbsent(properties, PROPERTY_NAME, () -> {
        String lineContent = properties.get(PROP_LINE_CONTENT);
        if (lineContent != null) {
            return textEditor.getEditorInput().getName() + " : " + lineContent;
        } else {
            return textEditor.getEditorInput().getName();
        }
    });
    IPath filePath = getFilePath(textEditor);
    if (filePath != null) {
        addFilePath(properties, filePath);
    }
}
项目:mesfavoris    文件:TextEditorBookmarkPropertiesProvider.java   
private IPath getFilePath(ITextEditor textEditor) {
    IEditorInput editorInput = textEditor.getEditorInput();
    IFile file = ResourceUtil.getFile(editorInput);
    File localFile = null;
    if (file != null) {
        localFile = file.getLocation().toFile();
    } else if (editorInput instanceof FileStoreEditorInput) {
        FileStoreEditorInput fileStoreEditorInput = (FileStoreEditorInput) editorInput;
        URI uri = fileStoreEditorInput.getURI();
        IFileStore location = EFS.getLocalFileSystem().getStore(uri);
        try {
            localFile = location.toLocalFile(EFS.NONE, null);
        } catch (CoreException e) {
            // ignore
        }
    }
    if (localFile == null) {
        return null;
    } else {
        return Path.fromOSString(localFile.toString());
    }
}
项目:mesfavoris    文件:GotoExternalFileBookmark.java   
@Override
public boolean gotoBookmark(IWorkbenchWindow window, Bookmark bookmark, IBookmarkLocation bookmarkLocation) {
    if (!(bookmarkLocation instanceof ExternalFileBookmarkLocation)) {
        return false;
    }
    ExternalFileBookmarkLocation externalFileBookmarkLocation = (ExternalFileBookmarkLocation) bookmarkLocation;
    IEditorPart editorPart = openEditor(window, externalFileBookmarkLocation.getFileSystemPath());
    if (externalFileBookmarkLocation.getLineNumber() == null) {
        return true;
    }
    ITextEditor textEditor = Adapters.adapt(editorPart, ITextEditor.class);
    if (textEditor == null) {
        return false;
    }
    return gotoLine(textEditor, externalFileBookmarkLocation.getLineNumber());
}
项目:mesfavoris    文件:GotoWorkspaceFileBookmark.java   
@Override
public boolean gotoBookmark(IWorkbenchWindow window, Bookmark bookmark, IBookmarkLocation bookmarkLocation) {
    if (!(bookmarkLocation instanceof WorkspaceFileBookmarkLocation)) {
        return false;
    }
    WorkspaceFileBookmarkLocation workspaceFileBookmarkLocation = (WorkspaceFileBookmarkLocation) bookmarkLocation;
    IFile file = workspaceFileBookmarkLocation.getWorkspaceFile();
    IEditorPart editorPart = openEditor(window, file);
    ITextEditor textEditor = Adapters.adapt(editorPart, ITextEditor.class);
    if (textEditor == null) {
        return false;       
    }
    if (workspaceFileBookmarkLocation.getLineNumber() != null) {
        return gotoLine(textEditor, workspaceFileBookmarkLocation.getLineNumber());
    }
    return true;
}
项目:mesfavoris    文件:GotoInsideJavaElementBookmark.java   
@Override
public boolean gotoBookmark(IWorkbenchWindow window, Bookmark bookmark, IBookmarkLocation bookmarkLocation) {
    if (!(bookmarkLocation instanceof JavaTypeMemberBookmarkLocation)) {
        return false;
    }
    JavaTypeMemberBookmarkLocation location = (JavaTypeMemberBookmarkLocation) bookmarkLocation;
    IEditorPart editorPart = openInEditor(location.getMember());;
    ITextEditor textEditor = Adapters.adapt(editorPart, ITextEditor.class);
    if (textEditor == null) {
        return false;
    }
    if (location.getLineNumber() != null) {
        try {
            JavaEditorUtils.gotoLine(textEditor, location.getLineNumber());
        } catch (BadLocationException e) {
            return false;
        }
    }
    return true;
}
项目:mesfavoris    文件:GetLinkedBookmarksOperationTest.java   
@Test
public void testGetLinkedBookmarks() throws Exception {
    // Given
    importProjectFromTemplate("testGetLinkedBookmarks", "commons-cli");
    Bookmark bookmark = bookmark(new BookmarkId(), "LICENSE.txt")
            .withProperty(PROP_WORKSPACE_PATH, "/testGetLinkedBookmarks/LICENSE.txt")
            .withProperty(PROP_LINE_NUMBER, "10").build();
    addBookmark(rootFolderId, bookmark);
    waitUntil("Cannot find marker", () -> bookmarksMarkers.findMarker(bookmark.getId(), null));

    // When
    IEditorPart editorPart = openEditor(new Path("/testGetLinkedBookmarks/LICENSE.txt"));
    ITextEditor textEditor = getTextEditor(editorPart);
    selectAndReveal(textEditor, getOffset(textEditor, 10));
    List<Bookmark> bookmarks = operation.getLinkedBookmarks(textEditor, getSelection(textEditor));

    // Then
    assertEquals(1, bookmarks.size());
    assertEquals(bookmark, bookmarks.get(0));
}
项目:code    文件:TraceUtility.java   
public static void selectInEditor(ASTNode node) {
    if(TraceToCodeUIAction.highlightCode){
        IJavaElement javaElement = getIJavaElement(node);
        if (javaElement != null) {
            try {

                EditorUtility.openInEditor(javaElement);
                IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                if (part instanceof ITextEditor) {
                    ((ITextEditor) part).selectAndReveal(node.getStartPosition(), node.getLength());
                }
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
项目:code    文件:TraceUtility.java   
public static void highlightInEditor(ASTNode enclosingDeclaration , ASTNode expressionNode){
    if(TraceToCodeUIAction.highlightCode){
        IJavaElement javaElement = getIJavaElement(enclosingDeclaration);
        if (javaElement != null) {
            try {

                EditorUtility.openInEditor(javaElement);
                IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
                if (part instanceof ITextEditor) {
                    ((ITextEditor) part).selectAndReveal(expressionNode.getStartPosition(), expressionNode.getLength());

                }
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
项目:tlaplus    文件:TLAMultiPageEditorActionBarContributor.java   
public void contributeToStatusLine(IStatusLineManager statusLineManager)
{
    if (this.activeEditor instanceof ITextEditor)
    {
        if (statusLineManager.find(cursorPositionStatusField.getId()) == null)
        {
            // add the cursor position if not already there
            statusLineManager.add(cursorPositionStatusField);
        }
    } else
    {
        // remove cursor position if the active editor is not a text editor
        statusLineManager.remove(cursorPositionStatusField);
    }
    // must update to show changes in UI
    statusLineManager.update(true);
}
项目:tlaplus    文件:ModelEditor.java   
/**
 * Returns the nested editor instance open on moduleName (without the .tla extension).
 * Returns null if no such editor is open in this model editor.
 * 
 * @param moduleName
 * @return
 */
public ITextEditor getSavedModuleEditor(String moduleName)
{
    for (int i = 0; i < getPageCount(); i++)
    {
        IEditorPart nestedEditor = getEditor(i);
        if (nestedEditor != null
                && nestedEditor instanceof ITextEditor
                && ((FileEditorInput) nestedEditor.getEditorInput()).getName().equals(
                        ResourceHelper.getModuleFileName(moduleName)))
        {
            return (ITextEditor) nestedEditor;
        }
    }
    return null;
}
项目: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    文件:EditorTracker.java   
private void editorClosed(IEditorPart part) {
    if (part instanceof ITextEditor) {
        ICodeLensController controller = codeLensControllers.remove(part);
        if (controller != null) {
            controller.uninstall();
            Assert.isTrue(null == codeLensControllers.get(part),
                    "An old ICodeLensController is not un-installed on Text Editor instance");
        }
    }
}
项目:codelens-eclipse    文件:CodeLensControllerRegistry.java   
public ICodeLensController create(ITextEditor textEditor) {
    ICodeLensControllerFactory factory = getFactory(textEditor);
    if (factory != null) {
        return factory.create(textEditor);
    }
    return null;
}
项目:codelens-eclipse    文件:CodeLensControllerRegistry.java   
public ICodeLensControllerFactory getFactory(ITextEditor textEditor) {
    loadFactoriesIfNeeded();
    for (ICodeLensControllerFactory factory : factories) {
        if (factory.isRelevant(textEditor)) {
            return factory;
        }
    }
    return null;
}
项目:codelens-eclipse    文件:LSPCodeLensControllerProvider.java   
@Override
public boolean isRelevant(ITextEditor textEditor) {
    Collection<LSPDocumentInfo> infos = LanguageServiceAccessor.getLSPDocumentInfosFor(
            LSPEclipseUtils.getDocument(textEditor),
            capabilities -> capabilities.getCodeLensProvider() != null);
    return (!infos.isEmpty());
}
项目:pgcodekeeper    文件:SQLEditorActionContributor.java   
@Override
public void setActiveEditor(IEditorPart part) {
    super.setActiveEditor(part);
    if (part instanceof ITextEditor) {
        fContentAssist.setAction(getAction((ITextEditor) part, SQLEditor.CONTENT_ASSIST));
    }
}
项目:pgcodekeeper    文件:SQLEditorHyperLink.java   
@Override
public void open() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
            .getActivePage();

    try {
        ITextEditor editor = (ITextEditor) IDE.openEditor(
                page, Paths.get(location).toUri(), EDITOR.SQL, true);
        editor.selectAndReveal(region.getOffset(), region.getLength());
    } catch (PartInitException ex) {
        ExceptionNotifier.notifyDefault(
                Messages.ProjectEditorDiffer_error_opening_script_editor, ex);
    }
}
项目:ec4e    文件:EditorConfigCodeLensProvider.java   
@Override
protected ICodeLens[] provideSyncCodeLenses(ICodeLensContext context, IProgressMonitor monitor) {
    ITextEditor textEditor = ((IEditorCodeLensContext) context).getTextEditor();
    IFile file = EditorUtils.getFile(textEditor);
    if (file == null) {
        return null;
    }
    IDocument document = context.getViewer().getDocument();
    IDEEditorConfigManager editorConfigManager = IDEEditorConfigManager.getInstance();
    final ErrorHandler errorHandler = ErrorHandler.IGNORING;
    SectionsHandler handler = new SectionsHandler(editorConfigManager.getRegistry(), editorConfigManager.getVersion());
    EditorConfigParser parser = EditorConfigParser.default_();
    try {
        parser.parse(Resources.ofString(file.getFullPath().toString(), document.get()), handler, errorHandler );
    } catch (IOException e) {
        /* Will not happen with Resources.ofString() */
        throw new RuntimeException(e);
    }
    List<Section> sections = handler.getEditorConfig().getSections();
    List<Location> sectionLocations = handler.getSectionLocations();

    ICodeLens[] lenses = new ICodeLens[sections.size()];
    for (int i = 0; i < lenses.length; i++) {
        lenses[i] = new EditorConfigCodeLens(sections.get(i), sectionLocations.get(i), file);
    }
    return lenses;
}
项目:ec4e    文件:EditorUtils.java   
public static IFile getFile(ITextEditor textEditor) {
    IEditorInput input = textEditor.getEditorInput();
    if (input instanceof IFileEditorInput) {
        return ((IFileEditorInput) input).getFile();
    }
    return null;
}
项目:ec4e    文件:EditorConfigContentProvider.java   
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    this.viewer = (TreeViewer) viewer;
    this.info = (ITextEditor) newInput;
    getDocument().addDocumentListener(this);
    resource = EditorUtils.getFile(info);
    resource.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.POST_CHANGE);
    refreshTreeContentFromLS();
}
项目:ec4e    文件:EditorConfigToOutlineAdapterFactory.java   
@Override
public <T> T getAdapter(Object adaptableObject, Class<T> adapterType) {
    if (adapterType == IContentOutlinePage.class && adaptableObject instanceof ITextEditor
            && EditorUtils.isEditorConfigFile((ITextEditor) adaptableObject)) {
        return (T) new EditorConfigOutlinePage((ITextEditor) adaptableObject);
    }
    return null;
}
项目:ec4e    文件:PreferenceStoreHelper.java   
private static void setPreferenceStoreOfTextEditor(ITextEditor textEditor, IPreferenceStore preferenceStore)
        throws Exception {
    Method m = AbstractTextEditor.class.getDeclaredMethod("setPreferenceStore",
            new Class[] { IPreferenceStore.class });
    m.setAccessible(true);
    m.invoke(textEditor, preferenceStore);
}
项目:ec4e    文件:PreferenceStoreHelper.java   
private static void setPreferenceStoreOfSourceViewerConfiguration(ITextEditor textEditor,
        IPreferenceStore preferenceStore) throws Exception {
    Field f = AbstractTextEditor.class.getDeclaredField("fConfiguration");
    f.setAccessible(true);
    SourceViewerConfiguration oldConfig = (SourceViewerConfiguration) f.get(textEditor);
    if (oldConfig instanceof TextSourceViewerConfiguration) {
        Field f2 = TextSourceViewerConfiguration.class.getDeclaredField("fPreferenceStore");
        f2.setAccessible(true);
        f2.set(oldConfig, preferenceStore);
    }
}