IntelliJ, is it possible to "Make a controller", as in NetBeans?

Does anyone know who knows IntelliJ and NetBeans, if IntelliJ has a similar function, as for NetBeans "Make a controller" when you right-click on the corresponding FXML file?

I think this is very important, since it is updated if I added something new (for example, FXID), and if I deleted it, etc., and also placed it in the right place by itself.

I know that in Scene Builder you can go to "View → Show Sklerton Controller", but this is not enough for automation, especially not from the Jetbrains environment.

It also means that the following link is not the answer: how to make netbeans "make controller" in the intellectual idea

[ Menu in Netbeans, showing the "Make controller" feature ]

IntelliJ menu displaying nothing about controllers

+5
source share
2 answers

Instead of creating an action to create a controller, IDEA uses intentions (activate via Alt + Enter or ⌄ āŽ ). And his philosophy would be to synchronize the controller when you edit the FXML file, rather than recreate it to update it with the changes.

For example, when you create an FXML file, IDEA suggests creating a controller: enter image description here

First I will name it as desired, and then I will use Intention to create the appropriate class:

enter image description here

Then, when I add things to FXML, IDEA suggests creating the appropriate elements in the controller:

enter image description here

Similarly with fx:id :

enter image description here

And if I use the rename refactor to change fx:id

enter image description here

it renames the corresponding field name in the controller to match. Therefore, instead of editing it and then re-creating the controller to record the name change, it simply synchronizes them. But again, the key is to use rename refactoring, and not just manually edit fx:id .

Edit to answer further questions in the comments

Firstly, disclaimer ... I am only in JavaFX to write simple dialogs in the form of command line interfaces. Therefore, I am by no means an expert and may not know about the JavaFX-related function in IDEA. But I have been using IDEA for 14 years and usually know what to look for in terms of features and ā€œlike meā€ questions.

Can you shed some light on the use of these kinds of materials with Scene Builder if you know something about this?

Whenever I use a WYSIYWG editor like Scene Builder, I still monitor and clear the code that it generates. So I'm still a little old school. And I believe that IntelliJ IDEA adheres to this philosophy.

I find it very hard to believe that IDEA has no way to edit "bulk automatic updates" in Scene Builder

I can tell you how an IDE, IDEA is small for creating Wizards or bulk code. Instead, it is more "surgical" in nature. The ā€œcode of intentā€ philosophy is to enter / change your intention, and then use the intention / quick fix to realize that intention. Thus, any codeword it generates is small and focused. But ... in some cases, you can ask him to apply the intention to several elements at the same time by opening the intent bonuses menu (using the arrow key ā€œarrowā€ → ) and choosing the name of the problem ā€œFix allā€ in the file. Again, given my limited experience with JavaFx, I probably don’t know anything, but I don’t see anything wherever it is, and I don’t see anything on the help pages.

<soap box> When I first started using IDEA in 2003, I also wondered where all the wizards and the massive code generation functions that were provided by my old IDE. (I previously used Forte for Java, the predecessor of NetBeans.) First I skipped them. Then I started using intentions and refactoring for everything. After a couple of months, I did not miss the wizards. After a few months, I began to hate wizards in other IDEs. In the end, I was much more productive using intentions and refactoring. And I noticed that I no longer spend much time on compilation problems and errors that I made when I used the wizards. </ soap dish>

If I assign fx: id to many buttons and the like in Scene Builder, then I need to manually go to the code view of the fxml file, find all fx: id and enter alt + for each of them to enter them into the controller?

Unfortunately, for the intention of ā€œcreating a fieldā€ for missing identifiers, ā€œthere is no batch mode available, so you cannot use theā€œ fix all ā€option. My educated guess about why is not when creating a field that you if you have the opportunity to select type for Labeled example, with the label fx:id for the label, I can enter the field as Label , Labeled , Control , etc. In most cases, you most likely get to print it as the actual type that is in your FXML. , you can open a feature request by offering a pack Native mode so that it is available for the ā€œCreate Fieldā€ intent, which by default uses the field type used in FXML. However, if you use F2 to go to the next error, then use Alt + Enter (or ⌄ āŽ ) to open a quick fix, you will find that you can add the missing fields very quickly.

If I deleted some fx: id, then I would have to remember which ones they were, did they manually delete in the controller?

Again, instead of just manually deleting fx:id , use IDEA refactoring. When deleting fx:ids (or something), use the "Safe Delete" refactoring. Use the cursor on the identifier (either in the FXML file or in the controller) to enter Alt + Delete (or ⌘ ⌦ ) to start the "Safe Delete".

enter image description here

If there is no custom, the field is deleted. Otherwise, you will receive a warning:

enter image description here

Click the "View Usage" button. The Find toolbar will open showing usage.

enter image description here

Update your code to remove their use. Use the Repeat Safe Deletion button to monitor your progress. After all the actions are completed, click the "Do Refactor" button to remove the usages. Although this may seem more active than some kind of regenerative version of the controller, my question will be, how would such a function relate to the use of this field in a method inside the controller? Would it just not recreate the field leaving a compilation error in my controller? How would he ā€œrestoreā€ all the settings that I made for the controller?

Safe deletion also prevents your code error. If I had a dollar for every time I sent to delete something that I absolutely knew, it was not used anywhere just to safely remove refactoring to give a warning about what place it uses, about which I completely forgot.

+5
source

If you use the Javaru solution, then the created fields will be public and without @FXML annotations.

To change this, go to: File | Settings | Editor | Code Style | Java | Code Creation | Default visibility - select ā€œEscalationā€ or ā€œPrivateā€, and at the bottom ā€œcheck external annotationsā€.

The second solution: open the fxml file in the scene builder, set the controller class in the controller section in the lower left part of the window. Jump to: view | show controller controller skeleton and copy controller class code.

This is my first post, I hope I helped. :)

+1
source

Source: https://habr.com/ru/post/1273268/


All Articles