Pregunta

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++.

¿Fue útil?

Solución

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!

Otros consejos

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.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top