I have defined an EMF metamodel in which some elements have a String field which will contain some Java code.
I am trying to create/reuse a (Java) source code editor as part of the tabbed properties view to be able to edit that field with some IDE-like functionality. It would be great to adapt the JDT editor to use it here, but for I have read, it is not feasible. Extending org.eclipse.swt.widgets.Text to provide all that functionality seems to be too much of an overkill for this simple project.
Therefore, the question would be, which approach would you recommend as the best functionality/effort ratio to achieve this?, do you now of any source code editor which may be reusable as/within a view?
Buddy...
This is really going to be a hard task.
Re-Using EditorParts in SWT widgets/ViewParts is not easy. The only thing that I got to manage was to reuse the EPF RichText-Widget which was designed for use as an EditorPart.
In that case it was easy, because it only needed an IEditorSite as a constructor parameter. I then extended it and adapted the IViewSite to an IEditorSite.
But concerning JDT: There is so much funcionality which is directly related to the Base-Text-Editor functionality from eclipses IEditorParts... I think it won't be worth the effort.
Could't you find a Java-IDE for Java-Code? Isn't there anything working with Swing/AWT?
You could then possibly include a Source-Code-Editor-Swing-Frame using a SWT_AWT-Brigde-Widget. This way I successfully integrated an Swing-PDF-Viewer into an eclipse ViewPart.
Take a look at the eclipse API desciption.
And as a first rough try for the Java IDE:
drJava
I have done a lot of work with modeling and code generation and this problem has never really been solved satisfactorily. There are many in the Model-to-Text community that argue that code should not be in the model for this and other reasons.
My approach in the past has instead been to generate my code from the model leaving comment-bracketed regions for the developer to enter their business logic and other code snippets directly into the generated code using their favorite editor. If the model changes and the code is regenerated, the developer-supplied code is retained. This also has the benefit of supporting any language (Java, C, Objective-C, JSP/HTML, etc.) and for defaulting to an appropriate default stub of generated code.
Look at the <c:userRegion>
tag in Eclipse M2T-JET as an example. I believe the other Eclipse Model-to-Text technologies have similar functions.