In NetBeans the GUI Builder generates code that is off limits to you from the editor.
I know you can switch to Design Mode and specify custom code and then enter edit in indirectly that way, but it's a pain to not be able to edit text that's 2 lines from your cursor.
Can I allow editing within those regions... I promise I'll be careful :)
Thanks.
Note: I don't want to lose code generation
If you open it in an external editor, there are two possibilities:
there is no guarantee that the changes you make will work (and not break anything) in the Netbeans UI Editor
The next time you edit the file in Netbeans it will be regenerated.
Either way, probably not what you want. The best thing to do would probably be to make the whole design up in the gui editor and when you are happy with it, delete the comments and continue on.
[sarcasm]
With the drag and drop gui editor, what could you possibly want to change by hand anyway?
[/sarcasm] ;)
If you open the .java files in Notepad or WordPad, you'll find pairs of comments that say
// GEN-BEGIN: <name of section>
...
// GEN-END: <name of section>
Delete those comments, and two things will happen.
You'll be able to edit anywhere in the file in NetBeans.
NetBeans will not be able to regenerate the file from the GUI editor.
So it can be done, but don't do it unless you really mean it.
EDIT: "Note: I don't want to lose code generation." Ok, let's see here.
You want to change what is generated.
You don't want to lose code generation.
You don't want to use the facilities NetBeans provides for adding custom code.
It sounds like you're wishing yourself trouble. :D
I had a same problem. I extended JPanel with my own panel class and I was not able to pack it with the rest of UI. First I searched the web and I found your question. I was not able to find elegant solution to this problem.
Therefore, I decided to create another java class and copy NetBeans created code into it. It worked like a charm.
I agree, it would be nice if we can modify existing code like in .NET.
I copy the initcomponents() method, create my own method newInitComponents() paste the generated code, and override what needs to be overridden before i distribute the code. That way when a change is made in the editor, you can still copy paste the code into your new method. You keep the functionality without costing you the ability to override where necessary. Just call newInitComponents() in your constructor rather than the original. This is not the most efficient way of doing things, but it does what you want.
You can also try moving the .form file in
(project name)\src\(name of JFrame/JPanel).form
NetBeans will now see it as a .java file.
If you did not edit anything necessary for the GUI editor, you can move the .form file back into the src folder.
Can you subclass the class and redefine the method where this code is? Of course then you'll have to maintain the method over time as you make changes to the GUI.
You can maybe also look into AspectJ. It will modify the byte-code at build time and make the changes you define. Not sure if this gives you enough control over what code to change.
If you use APT you can rewrite source code at compile time. This way you can overwrite the code that's there at the moment. You could keep the new code in the same Java file along with comments to explain what is going on. This tutorial makes it pretty easy to get started. Copy that code, get it working, then tweak it to your liking. To find out where in the code the annotated method is call getPosition() on the Declaration.
Go to design page and select any one of the fields. Right click on any selected field and choose Customizer Code , In Customizer Code change all default code to custom creation . Now you can edit your design code as you like...
Very simple... the crappy UTF-8 did not let me compile one JasperReport (everything done by GUI). So, I needed to change Project to iso-8859-1. Result? The project is messed up and some of the things to correct are in the blocked parts of the code. So, I really NEED to edit those automatically generated parts. When they are regenerated, they will be fine because the project is now iso-8859-1.
Step # 1 Close the project in NetBeans
Step # 2 Delete the .form file from the source directory of your project
Reopen the project and it will be editable now!
Related
The refactoring menu in Xcode 9.1 is completely greyed out. I wanted to extract a method from existing swift code and got the following screen:
Do I have to enabled something special to get access to the new refactoring features?
Try cleaning your Xcode. Also try clearing out derived data and restart Xcode.
Clean Build --> (Command-Option-Shift-K)
Delete DerivedData folder in ~/Library/Developer/Xcode/DerivedData
Refactor option hides if you select version editor.
Thanks #paul
I had to change to the Active Schema to the one that matched the Target Membership of the file I was editing.
In other words:
In Project Navigator, select the file you're editing
Show the Inspectors panel on the right
Show the File Inspector
Observe the Target Membership values and set the Active Schema (at the top, by the Build and Stop buttons) to match.
Select text, right click, select Refactor
Observe all the Refactor options are now enabled.
This happened to me too and I could not find anything on it so...
My first post is born.
Mike T. hit on a small portion above (incomplete syntax).
Nothing is wrong. Xcode is amazing! It seems the Refactor/Extract feature is pretty smart. The option is not available if it does not make sense to extract a method.
It may not make sense to extract a method for many reasons. Xcode disables the feature when it encounters them in the selection. A few that I noticed are:
variable declarations
a solitary print statement
continue statements in the selection but I don't include the for loop container. (i'm impressed)
my guess is that there are a bunch of conditions...
Small thing for me was that the code I was trying to access was inside a closure so when I was selecting it and right clicking to Extract to a Method, it was greyed out. removing self on both instances, I could then select both lines to then extract to method
self?.activityIndicator.stopAnimating()
self?.activityIndicator.removeFromSuperview()
Both lines were inside a closure for a UIAlertAction. So removing self allows you to extract to a method in this case. Then just call self on the extracted method inside the closure and it should work.
self?.hideSpinner() //extracted method name
As other posters have already said, its best to make sure you're able to refactor what you want by selecting the right code.
I've got a small homework project, and for whatever reason Eclipse has decided to stop highlighting syntax or allowing intellisense or goto definitions or anything in this Main.java file. I've tried rebooting it, and the computer, but had no luck.
The thing that really has me confused is that it's still compiling and running the code correctly (eg, changes I make in Main.java are compiled and run - it's not running old Main.class files), so it's still in the build path ... right?
Any ideas?
Right click on the file in the Package Explorer and choose the Open With menu. You will probably find that Text Editor is selected, choose Java Editor to open the file with the correct editor.
The Open With menu selection is remembered so you should get the Java Editor in future, but equally if you choose the plain text editor that is also remembered.
I suggest finding a way to reset any setting you might have set by accident. Not saying that you did it. But just to make sure, just try it out. If you customized the preferences already, you could make some kind of note of the settings, then change it. If that doesn't work, let me know. Good Luck!
Copy the text somewhere, delete the file, and then add a new class (of the same name) and paste the text back.
I use an older plugin called Veloeclipse for editing Velocity templates in Eclipse. There's been no development on this since 2009, which isn't a problem because it's mainly just for syntax highlighting and format validation. The really annoying thing about it, however, is that when I try to do Show In to view the current Velocity template within my Package Explorer or Project Explorer, the only available option is Properties. That's not really useful. I really need to be able to get to the file in one of the regular explorer views.
So I have sort of two questions:
Is there a way to configure this without having to monkey with any code? A configuration file or something? I've grepped through my Eclipse installation and haven't seen anything, but I'm hoping that there's something I'm missing.
So assuming that the answer to my first question is no, how do I go about modifying the plugin code so that it will show more than the Properties view in the Show In menu? Most of what I found on the plugin development wiki comes from the other direction: how to make your view or perspective appear in the Show In menu.
Any help with this would be hugely appreciated!
Try to check the plugin source code. it might do something different than other editors. What I mean is that the show in menu item that you have there is not the usual extension point but a hard coded context menu option.
What would be the best approach to launch an editor from the file menu(File>New). Should I encase the editor inside a view and launch the view from a command?
If you want an editor without a file, the best approach would be to go through the normal wizard creation stuff, but instead of creating a real file, use a virtual input instead. These might both be relevant to your interests: http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_a_file_in_the_workspace%3F and http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_programmatically%3F and http://wiki.eclipse.org/FAQ_How_do_I_open_an_editor_on_something_that_is_not_a_file%3F. I did see something ages ago which was about creating totally virtual inputs. If I see it, I'll edit the post. Otherwise, it should be as simple as creating a subclass of org.eclipse.ui.IEditorInput and then not pointing it at any resource, but using it to create the editor.
I would like to automatically convert between tabs and spaces for indentation when I commit/update code to/from our repository. I have found the AnyEdit plugin for eclipse, which can convert directories of files. Not bad for a start, but does anybody have more expierience on how to handle this? Or maybe know of an Ant script or something else?
Make sure you have your editor set to use spaces instead of tabs.
Select all text and hit CMD + I on mac or CTRL + I on windows.
Why not just use the code formatter and/or cleanup function? It has settings that take care of that stuff for you. You can even have it run automatically on save.
Edit: As Peter Perháč points out in the comments, this only answers half the question. I don't have any practical experience, but you could try the Maven Eclipse Format Plugin to format from a Maven build.
Unfortunately, that's Maven only, and I know of no light-weight command line formatter. But if you happen to use Maven, you can bind the format goal to the proper phase, and if you set Eclipse to auto-build, it would format on update.
Depending on the SCM tool (git, svn, etc), you could also create a hook that runs the build (but it might be a bit too heavy-weight for that).
I use the AnyEdit plugin to auto-convert tabs to spaces on the save of a file. I also configure the base text editor (from which pretty much all the others derive) to insert spaces instead of tabs. This sounds redundant, but what it does is ensure that I don't insert any tabs, and any file that I edit that already has tabs will be converted as soon as I save it.
Tabs have no place in source code. If someone else looks at the file with their tab-stops set to a different value, they lose most alignment/formatting anyway.
(Of course, if you have Makefiles that you edit directly, you'll want to make sure their tabs are retained. But in my projects, if make is used at all the Makefile is derived from a different source, such as a Makefile.PL in Perl.)
A bit overkill, and only something to attempt with certain repository products that can handle it, but a hook script to call indent or astyle could do the trick. It'll format everyone's code the same way for every file, depending how you write the hook script, and it'd have to be pre-commit of course.
You may lose alignment/formatting by using tabs instead of spaces if and only if the tabs are not at the beginning of the line. Never use tabs insides lines, always use tabs at the front of lines. This allows you to use your editor to adjust to your desired indent level without impacting your co-workers view of the file. Challenge: Find an example where tabs at the front of the line loses alignment.
I use Kedit for just this thing. It also natively converts text files from Macintosh, UNIX and MS-Dos. Since it's an older editor, I use one of it's scripts to handle unicode files.
You might also want to look at some of the other smart editors.
I use Eclipse for Java EE developer 4.6.0 Neon. I use http://marketplace.eclipse.org/content/anyedit-tools