Modifying Generate POJOs.groovy with user prompt

Answered

I'm looking to modify the Generate POJOs.groovy sample generator to generate multiple files, and to include certain boilerplate within some of them. Ideally, I'd like to prompt the user for certain strings to use when generating these files. Is there a way to create such prompts when using the scripting engine?

0
2 comments

Hi,

Yes, you could open `Scratches and Consoles -> Extensions -> Database Tools and SQL -> Schema`, open the `Generate POJOs.groovy` file, write some groovy code there by using Java swing API or IDE's UI API (the swing API should be easier to use if you are not familiar with our IntelliJ IDEA platform API) to show a GUI with some input fields to let the user fill it and then you could use these strings to generate the needed one.

For example, adding the below code would show a window to let you input something:

```
import javax.swing.JFrame
import javax.swing.JPanel
import javax.swing.JTextField

....

JFrame f = new JFrame("textfield");
JTextField t = new JTextField(16);
JPanel p = new JPanel();
p.add(t);
f.add(p);
f.setSize(300, 300);
f.setVisible(true);
```

0

Thank you, that was precisely what I was hoping/looking for!

0

Please sign in to leave a comment.