3

I already have a Java application with Swing GUI which reads a bunch of XML files and makes some graphs based on the information found in those XML files.

Now I was asked to turn that application into an Eclipse Plugin so the application can be launched from inside the Eclipse IDE. On top of that I have to make my application to sometimes open an XML file which contains the data that the user clicks.

Now, after a fast walk through a tutorial about how to make an Eclipse Plugin, it does not seem that I will be able to use Swing components inside a Plugin Project. I have seen that there are other tools and frameworks for making GUI for a plugin.

I need a suggestion for how can I turn my Swing application into an Eclipse plugin, the easiest possible. Even with some frameworks for Swing I had a hard time to make a treelayout graph. I imagine that should be even harder to implement into Eclipse plugin if Swing components do not work over there.

Here it is how my application looks like right now, based on Swing components: enter image description here

asked May 15, 2014 at 10:37
1
  • Easiest solution? Hire someone who intimately knows Eclipse plugin development to do it. Other than that this is going to be a very costly job, because you're going to have to learn the Eclipse platform and then build a plugin that does the same as the Swing application. I hope the Swing application is designed well enough that you can reuse classes from it. Commented May 15, 2014 at 10:40

2 Answers 2

3

If you don't want to rewrite the whole application, you may want to check possibilities of using SWT_AWT bridge, which allows to integrate Swing applications into SWT world. It is pretty easy, but you may want to check some articles as well.

I used it to integrate some Swing-based print preview functionality into existing Eclipse-RCP application. Worked well, though it still has its own underwater rocks.

answered May 15, 2014 at 10:42
Sign up to request clarification or add additional context in comments.

Comments

2

You can use Swing components inside a Eclipse plugin.

For demonstaration I took the Swing components from https://code.google.com/p/treelayout/ and put them into an Eclipse view:

enter image description here

The important file looks like this:

package createaview.views;
import org.abego.treelayout.demo.swing.SwingDemo;
import org.eclipse.jface.viewers.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;
public class TreeView extends ViewPart {
 public static final String ID = "createaview.views.SampleView";
 private TableViewer viewer;
 class ViewContentProvider implements IStructuredContentProvider {
 public void inputChanged(Viewer v, Object oldInput, Object newInput) {}
 public void dispose() {}
 public Object[] getElements(Object parent) {
 return new String[] {"One", "Two", "Three"};
 }
 }
 class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
 public String getColumnText(Object obj, int index) {
 return getText(obj);
 }
 public Image getColumnImage(Object obj, int index) {
 return getImage(obj);
 }
 public Image getImage(Object obj) {
 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
 }
 }
 class NameSorter extends ViewerSorter {
 }
 public TreeView() {}
 public void createPartControl(Composite parent) {
 Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
 java.awt.Frame frame = SWT_AWT.new_Frame(composite);
 frame.add(SwingDemo.getPanel());
 }
 public void setFocus() {
 viewer.getControl().setFocus();
 }
}

and if you pass me an email address I'll bundle up the demo project I did and send them to you (actually, it should probably be that if this is looking like the right answer, I'll put the projects in a zip file somewhere around here for the community to have a look at)

answered May 17, 2014 at 17:27

1 Comment

Seems to be very useful, but it would help a lot more if I could see your demo project. Could you please upload your demo project on a website like github.com ? It seems that stackoverflow does not allow me to send you my email address via private message.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.