简体   繁体   English

eclipse中的插件开发

[英]plugin development in eclipse

i have this problem with my project these days. 这些天我的项目有这个问题。 i'm developing a plugin in eclipse, i need to write a text on the active window(coding area) when i click a button. 我正在用eclipse开发插件,单击按钮时需要在活动窗口(编码区域)上写文本。

i use the following code in my button.java class 我在我的button.java类中使用以下代码

public class Button implements IWorkbenchWindowActionDelegate {
private IWorkbenchWindow window;
/**
 * The constructor.
 */
public Button() {
}

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI.
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    MessageDialog.openInformation(
        window.getShell(),
        "Button",
        "Code of the Button goes here");
}

how can i do it inside the run method? 我如何在run方法中执行此操作? here I'm displaying a message, instead of showing a message i want to display some text in the text editor pane. 我在这里显示一条消息,而不是显示一条消息,而是要在文本编辑器窗格中显示一些文本。 please help me to achieve this. 请帮助我实现这一目标。

if you guys can please give me some links to understand about eclipse plug-in developments? 如果你们可以给我一些链接,以了解有关Eclipse插件的开发? any blog posts that are easy to understand will be much better? 任何易于理解的博客文章会更好吗?

You should do something like this. 你应该做这样的事情。 It is completely untested and you will need to add lots of null checks and try-catch blocks, but the code below gets the currently active editor and replaces the current selection with whatever is passed in as an argument: 它是完全未经测试的,您将需要添加许多空检查和try-catch块,但是下面的代码获取了当前活动的编辑器,并用任何传入的参数替换了当前选择:

void method (String text) {
    IEditorPart part = Workbench.getInstance().getWorkbenchWindows()[0].getActivePage().getActiveEditor();
    IEditorInput editorInput = part.getEditorInput();
    if (part instanceof ITextEditor) {
        ITextEditor textEditor = (ITextEditor) part;
        IDocument doc = textEditor.getDocumentProvider().getDocument(editorInput);
        ITextSelection sel = textEditor.getSelectionProvider().getSelection();
        doc.replace(sel.getOffset(), sel.getLength(), text);
    }
}

It is messy and complicated, but that's the Eclipse framework for you. 它很麻烦而且很复杂,但这就是您的Eclipse框架。

This might be a good place for you to look at Eclipse plugin development: http://www.ibm.com/developerworks/views/opensource/libraryview.jsp?search_by=Create+commercial-quality+eclipse+ide 这可能是您查看Eclipse插件开发的好地方: http : //www.ibm.com/developerworks/views/opensource/libraryview.jsp? search_by=Create+commercial-quality+eclipse+ide

Developer Works in general has a lot of good content on Eclipse, so if this series is not exactly what you need, you can explore Developer Works for other things. 通常,Developer Works在Eclipse上有很多不错的内容,因此,如果本系列不是您所需要的,您可以探索Developer Works来进行其他工作。

I'd recommend this one . 我推荐这个 It is a very good introductory tutorial 这是一个很好的入门教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM