I have been recently working on a new JetMinds product (details will be disclosed soon) which included developing set of Eclipse plugins containing (but not limited to) custom editors with syntax coloring, editor outline, content assistant and other various tools similar to ones already available in Eclipse's Java editor.
I have encountered several problems regarding Eclipse complexity, the lack or obscurity of the documentation and examples etc. That's why I began to wrote this series of articles. This is not striving to be complete guide as I just wanted to pinpoint some concepts and ideas I found interesting.
In this article I try to cover:
- UI (SWT) thread issues
- Getting reference to an active editor
- Some IFile issues
- Opening file in its editor
Have a look at Eclipse FAQ - one of the best source of information.
- also see FAQ
Many methods manipulating with UI components must be called from UI-thread. First possibility (somewhat low-level) is to use SWT Display's syncExec() or asyncExec() method:
But Eclipse also offers second (higher-level) method - UIJob:
Get active editor
- also see FAQ
To get active editor use something like this (null checks are important):
Get IFile from EditorInput
Sometimes it is useful to get handle to file opened in editor. It's very easy using adapter pattern (much cleaner approach than casting EditorInput to FileEditorInput etc.).
Getting absolute path of IFile
Getting File from IFile
Open file in editor
Opening file in associated editor is possible using code like this:
I will try to focus on more complex things in later articles.