Source Editor in Eclipse plug-in - java

I'm developing an Eclipse plug-in, mostly as a learning exercise, in which I have a wizard page. In this wizard page I would like to have a small text area that behaves like a code editor with the appropriate content assist and information hovers etc, much like the breakpoint properties wizard has for adding conditions.
I'm new to plug-in development and I may not have quite picked up the vocabulary, so I'm not having much luck searching for examples. Can someone please point me in the right direction?

I assume that you are looking for an embeddable Java source editor - and with that you hit a difficult topic.
The source viewer mentioned by Chris Gerken is called JDISourceViewer. It is instantiated and configured in JavaBreakpointConditionEditor::createControl.
If you cannot find the mentioned classes, or if you want to experiment with them, then open the Plug-ins view, find the org.eclipse.jdt.debug.ui plug-in and select Import As > Source Project from the context menu.
Unfortunately - in the beginning - the (Java) editors weren't designed to be embedded outside of the editor area and many editor participants (e.g. actions, formatter, etc) still expect an IEditorPart. Hence it is a quirky and complicated endeavour to use an editor in a dialog or the like.
Moreover, the Java source editing infrastructure is not exposed as public API. It isn't meant to be used by clients and can change at any time without prior notice. You will see respective warnings in yoyur code. For a learning exercise, however, that shouldn't matter much.

Related

Automatic creation of complete class diagram from Java project

Is there a solution for automatic creation of a complete class diagram from a Java project?
I've spent significant time looking online, trying Papyrus, Jar2UML, UML2Tools, DiaGen, jGraps, Class-visualizer, but have not found any currently working solution. Although most of the mentioned tools work (some do not currently work), they do not automatically generate a diagram of the full class hierarchy. I realise this might be the holy grail, and may require parameterisation, but thought it should be possible this day.
Requirements for wider use would be:
Currently working
Easy to use, or up-to-date tutorial on exactly how to do this
Does not require manual coding
Stand alone or Eclipse/NetBeans/IntelliJ plugin
Free
If there is nothing like this available, I'm considering creating something like this.
Out of the fact I am not sure to have all the classes of a project into one class diagram is a good idea because the result is unreadable with lot of classes, you can do that for instance with my tool BoUML. After you download/install/run it :
create a new project
select Java in the global menu Languages
for the first directory dialog appearing press the button cancel (you do not have a java catalog) then for the second directory dialog select the root directory containing all the sources of Java you want to model, then wait for end
in the browser on the left in any of the created class view or in a new one you create yourself do a right mouse click and choose New class diagram and double click on it to open it
probably you need to hide details of classes in the diagram to limit its size (you can do that later but better to do that right now in case you have lot of classes), in that case do a right mouse click into the diagram or on it into the browser to edit the drawing settings and set to yes the settings hide classes attributes and hide classes operations then confirm (button ok)
use the button binocular on the top (near print button), change kind to class then use buttons search then mark them then close
into the open diagram (shown into the right part of the window) do a right mouse click and choose add marked elements placing classes in random position then redo a right mouse click and choose automatic layout (you can also move the classes by yourself of course)
As you can see all the relations between classes are drawn, not only the generalization/realization. If you want only them without having for instance to hide all other relations one by one by hand you can develop a plug-out marking all the classes and generalization/realization of the model, then changing the procedure I given :
when you edit the drawing settings also go into the second tab and set to no the setting draw all relations
rather than to use the browser search (binocular button) to select all he classes use your plug-out
Anyway, again, to show all the classes into one diagram is a bad idea except if you have few.
In the page documentation you have the reference manual and (old) video tutorials including the two ones dedicated to Java and an other one about to write a plug-out
Note you can also use Doxygen to make your diagram without using an UML modeler
Although BoUML does an ok job on this, for a large project it's not pretty.
For a better solution to fully automatically create a basic but complete class diagram from source code, try the simple extractor I put together in Java:
https://github.com/folterj/ClassDiagramExtractor
The project uses reflection, and produces a diagram from all the packages in a folder (and sub-folders).
Notes:
No command line options - clone & run setting source folder in code
This produces a gv file for use with GraphViz (dot), available here: https://www.graphviz.org/
The result looks quite good, as it groups packages together and even uses coloring.

Eclipse RCP - Open a View in the Editor Area (3.8/e4 hybrid)

I'm working on a 3.8-e4 hybrid (i.e we have the Luna dependencies, but we do not use the Application.e4xmi, yet). So we're basically running the compact layer.
With that being said, it would be nice to find an e4 programmatic way to stack these nasty views onto the editor folder.
1.) Problem
I want to place a generic view folder in the editor area, so that each view which is opened at runtime will be opened there.
(pic stolen from this question)
2.1) Possible fix no.1: Using plugin.xml
Create a perspective extension, and add each possible view to that extension, with relationship stack over relative org.eclipse.ui.editorss. This is a bit inconvenient if you have too many views awating to be opened, and if the project scales quickly. I also noticed that wildcard view IDs do not work here.
If you find yourself the time to add each possible view to the perspective extension, that would work. Although, IF you open a view which is not added here (ie: opens in a different folder), then each subsequent opened view will be opened in the previous folder, and NOT in the editor area (inquire further explanation if you don't get it).
2.2) Possible fix no.2: Using code in the perspective factory
In the IPerspectiveFactory, we do have access to the IPageLayout, which happens to be org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout (e4 stuff).
Now, this ModeledPageLayout implementation is reasonable, but also no documentation and weird public APIs. This one gives the possibility to stack a view over any other relative
modeledPageLayout.stackView("newView0", IPageLayout.ID_EDITOR_AREA);
This would be the programmatic version of 2.1. Also, the same problem appears here. If a view is opened somewhere else, the code above becomes useless.
Interesting enough, the stackView API does not support wildcards (while others such as addView do).
2.3) Possible fix no.3: Workarounds yaaay!
I have a lot of perspectives, and a lot of different folders in each one. Everything is precisely placed.
Since Eclipse offers the APIs to get all the view IDs from everywhere around the system, I want to do the following, per perspective: each view ID which wasn't added to a specific folder will be appended to the editor area (ie editor folder, editor stack).
This would be my last resort, unless someone offers a more convenient and timesaving solution.
Remember, an e4 programmatic alternative is more flexible!
3.) Related questions
Eclipse RCP -- Open View in Editor folder
Eclipse RCP - Stacking a view with the editor area?
Custom Eclipse perspective, with initially invisble view stacked to editor area
Google question, Lars answer
These would be rendered deprecated for the e4 release.
4.) Related Bug on Eclipse's Bugzilla:
This recent bug opened by myself has an attachment with a small SSCCE. The steps to reproduce this are described in this comment, so I'm not going to copy-paste them here.
I suggest you go with Possible fix no.3, since i think there isn't a faster method to do this.

Developing a GUI as an Eclipse Plugin

I know there is a very similar topic to this here but I have looked at the answers posted for it and I feel my problem is slightly different and doesn't need the same approach.
I'm developing an Eclipse plugin which is in essence a GUI that provides the user with different menus, buttons, editing areas etc. It's designed to be an all in one tool to help with coding, re-using code and re-structuring it.
I need a few pointers towards the resources available that can help me build this GUI and have it available as a plugin so I can get the ball rolling. I've looked at the suggestions in the link above but I don't feel like my plugin needs for example a model, view, controller design pattern. I just need the ability to have a GUI pop up when the user starts the plugin and have them interact with it.
Any suggestions or ideas are very much appreciated.
Your GUI has to be an multi-page editor. One (or more) page(s) for the GUI, and one page for the code.
Use the "Plug-in with a multi-page editor" template to get started.
This answer should help you fill out your template code.
When you have a specific question, feel free to ask again.
Take a look at the Tutorials at vogella.de especially the Eclipse plugin section. Those tutorials are usually very good. I learned Eclipse RCP with it.

Eclipse JFace FieldEditor for Dates?

I'm building a preferences editor for my Eclipse RCP application using the existing IWorkbenchPreferencePage framework (see http://www.eclipse.org/articles/Article-Field-Editors/field_editors.html for a good tutorial).
It has editors for a number of different types of data:
BooleanFieldEditor
IntegerFieldEditor
StringFieldEditor
RadioGroupFieldEditor
ColorFieldEditor
FontFieldEditor
DirectoryFieldEditor
FileFieldEditor
PathEditor
However, one thing which doesn't seem to exist is a nice DateFieldEditor (ideally with a button to bring up a calendar to allow choosing of a particular date).
So my question is, does such a org.eclipse.jface.preference.FieldEditor subclass exist, either in standard JFace or in a 3rd party plugin or project?
Alternatively, even a SWT calendar component would be useful, because I could build the rest on top of that pretty easily.
JFace doesn't have such a FieldEditor. But there is an official feature request for a DateFieldEditor that even has a basic implementation attached to it. At the very least you could use that as a template to create your own field editor, if it doesn't work for you as is.

Creating a "netbeans property" style dialog box

I've been trying to create a GUI using netbeans, that includes a dialog similar to Netbean's own "property dialog" that appears when designing. ie. a dialog that contains a table that can be expanded by tree nodes. Something like the dialog on this page, http://platform.netbeans.org/tutorials/nbm-property-editors.html
As far as I can understand, the page I linked to describes a custom editor I can set up for use within netbeans while designing - I'm just looking for a way to doing something similar for my actual application I'm writing. Is there an easy way to do this?
I came across this and have tried it but it doesn't quite work in the same way as the standard Netbeans dialog. weblogs.java.net/blog/timboudreau/archive/2008/06/egads_an_actual.html
Any tips greatly appreciated.
This will sound flip... but I am being serious.
The easiest way to do this is to write your app using the NetBeans RCP platform.
You may want to look at the Swing Application Framework, too.
There are a couple SAF samples integrated into NetBeans... You can read about them here: http://netbeans.org/kb/docs/java/gui-saf.html
I could not find a property editor dialog sample, though.
I found a couple other pointers, using this query: http://www.google.com/search?q=how+to+write+a+property+editor+dialog+in+swing
You could take a look into the l2fprod components
(source: l2fprod.com)

Categories

Resources