2

I am developing a plugin in eclipse which can generate a text file (based on user input) and can trigger a perl script. I can easily make a simple plugin (like Hello World) and I can add new menus and commands to it. I understand how those things are related to one another, but the place where I am getting stuck is the User Input.

How can I ask the user to enter his choices? I mean what extension point should I use to ask him out? I can't find anything that can ask the user to enter data. Once I can get him to enter the required info, I can easily access that information to proceed further.

PLZ. NOTE: this is my first time in an online community, so I have tried to be as thorough as possible in my description. I am new to eclipse and have a very basic knowledge of Java. I took some Java lessons online by Mark Dexter. I do have a solid understanding and work experience in C++.

user4252523
  • 69
  • 2
  • 8
  • 1
    I may not be understanding your question correctly, but you should be able to register an action with the workbench and then use that action hook to pop a dialog or provide another way for the user to interact with your plugin. – TK Gospodinov Jan 26 '12 at 20:11
  • Thanks for the reply first of all.I don't know what registering an action to the workbench means? I believe it is something that happens automatically when you add an extension point to your plugin. And I think i can easily pop up a dialogue using org.eclipse.ui.menus. Do you agree with me?? – user4252523 Jan 26 '12 at 21:26

3 Answers3

2

Continued from my comment above (sorry, couldn't fit into the 600 character limit for comments, so I'm adding this as a possible answer to your question) -- A quick search led me to this - http://www.eclipse.org/articles/article.php?file=Article-action-contribution/index.html. You can use actions to easily add toolbar buttons, menu items, etc, that are handled by your plugin. In short, this is how you plug functionality into the workbench. I recommend checking the link above to gain a better understanding. As for collecting the input, you can use a JFace dialog (http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjface%2Fdialogs%2FDialog.html). There are many pre-canned dialog that you may find useful, so I recommend doing a little more research to see what will work best for your use case. Good luck!

TK Gospodinov
  • 8,302
  • 6
  • 24
  • 25
  • can you please suggest me something about SWT? I created a java class (SWT) and now I wish to integrate it with my existing plug-in. Do you think if that it possible? Can you throw some light on it? Thanks TK. 8) – user4252523 Mar 01 '12 at 19:01
1

Starting Eclipse plug-in development might be a bit overwhelming.

The sort answer: I assume that you have create a new plug-in project with the "hello, world command" template. If not you can easily do it. It will help you to get started. In this sample project, eclipse created a simple menu contribution for you. I'm not going to go over the details, but essentially, you create a command (org.eclipse.ui.commands) and associate it with some location in the workbench like a menu or toolbar icon (org.eclipse.ui.menus). Then you need to create something that will handle this command like when it is executed (by user clicking on the menu). This is done by by handlers (org.eclipse.ui.handlers) and handlers are when you want your code to go into.

  1. Open the "plugin.xml" file in your plug-in and navigate to the "Extension" section
  2. Expand the "org.eclipse.ui.handlers" branch and select the only "(handler)" item.
  3. Click on the "class" link the right part of the editor and that will navigate you to the generated class.
  4. Your code goes to the "execute" method. This is what will be run when user executes the command. In your case if you want to ask for an input you can use an input dialog:

Code:

public Object execute(ExecutionEvent event) throws ExecutionException {
       InputDialog dlg = new InputDialog(
          HandlerUtil.getActiveShellChecked(event), "Title",
          "Enter text", "Initial value", null);
      if (dlg.open() == Window.OK) {
        // User clicked OK; run perl
        String input = dlg.getValue();
        // TODO:do something with value
      }
      return null; 
 }  

No to ask user for an input you will need to show a dialog. I suggest you go over this nice tutorial: http://www.vogella.de/articles/EclipseDialogs/article.html which describes this in a great detail.

The long answer is to look at http://www.vogella.de/articles/EclipsePlugIn/article.html and http://www.vogella.de/articles/EclipseCommands/article.html to see the basics behind Eclipse RPC and commands.

Lastly, you will also need to look in here http://www.vogella.de/articles/EclipseJobs/article.html to understand how to run longer tasks like the perl script you are talking about.

Manuel
  • 496
  • 6
  • 20
fikovnik
  • 3,473
  • 3
  • 28
  • 29
  • I seems to have a problem with formatting - here it is formatted well: https://gist.github.com/1733662 – fikovnik Feb 03 '12 at 23:24
  • thanks a ton fikovnik......it is really helping in confirming many things i have been reading...i couldnt give you ratings coz my rep is not good enough to rate...thanks again – user4252523 Feb 06 '12 at 16:40
  • you have helped me so much, that i have no words to describe how thankful I am to you. But from where did you gain all this info about Plugin Development? I have been doing it for weeks, but it is so difficult to put together all the bits and pieces of information i find on the internet. Please advise. Thanks – user4252523 Feb 08 '12 at 17:32
  • You are most welcome (may be you can mark the question as answered). The RCP book is a good start: http://eclipsercp.org/ that will help you started and understand basics. Then I would recommend to actually checkout the eclipse source and browse through the code. I use the Eclipse Spy plugin (http://www.eclipse.org/pde/incubator/spy/) every time I find a functionality that I would like to have and then I look into the corresponding source. Here's a plenty of info as well: http://www.toedter.com/ – fikovnik Feb 10 '12 at 10:21
  • hi fikovnik, recently I learnt about SWT (software widget toolkit). It has quite a few nifty features that could be really useful to me. I was wondering if there is a way to include this java class I wrote (i.e. SWT) into my existing plugin? Can you refer any links to me? thanks!!!! – user4252523 Mar 01 '12 at 17:04
0

There are no extension points in Eclipse used to input information from the user. For this you typically use a dialog or a view depending on the specific use case.

Tonny Madsen
  • 12,628
  • 4
  • 31
  • 70
  • Can you please tell me what exactly do you mean by a view? I am just overwhelmed with all the new stuff i'm coming across. Does view refer to to the normal views, like Package Explorer, Error-Logs, problems, etc.?? It would be great if you can just give me a link on views that you are referring to. THANKS!!!! – user4252523 Jan 27 '12 at 13:56
  • For some use cases, you might want to have the input area "open" all the time, so you can make changes to the values in the area at any time. This could be done by opening a dialog to make changes to the existing values, but it could also be done by having a view in Eclipse where the current values can be changed directly. Whenever you make change, these are reflected immediately in the results. In Eclipse the "Properties" view can be considered an example, as you can change the value for the backing object directly. – Tonny Madsen Jan 27 '12 at 14:14