GUIBuilderRefactoring RenameComponentVariable

Renaming a component variable from inside the UI builder

The user can rename a component variable from inside the UI designer. This is entered into in multiple ways:

  • ) The user right clicks on a Node in the Inspector and chooses "Change Variable Name..."
  • ) The user clicks on the name of the Node in the Inspector and enters a new value
  • ) The user right clicks on a UI element in the designer and chooses "Change Variable Name..."
  • ) The user clicks in the code section of the properties window, finds the "Variable Name" field, and enters a new value

In all cases the code will enter RADComponent.setName where the value is actually set. Here the code is configured and changes to the model are made.

Wade Chandler Updated 2005-05-31 A new method rename was added which code renaming the variable can use. There is also a new class called RADComponentRenameRefactoringSupport. The changes are in the trunk. To try out the refactoring support a System property form.refactoring=true must be set. Currently the refactoring support is not actually changing the users custom code inside the guarded blocks, though it should automatically change the users non-guarded code in the file(s). This is being worked on. Refactoring is used however to rename the variable names instead of just renaming them directly.

The following should now be ignored. After talking with Tomas we decided to just let the refactoring run with no user input other than changing the variable name as this will more than likely not affect more than 1 file. This only affects component variables created by the form editor and not user variables in the source or non-guarded blocks.

At first, I thought about the code to kick off refactoring here, but that doesn't seem like such a good idea now. setName may be called by other places where user interaction did not take place or may need to be used at some point with no UI available such as a memory efficient batch refactoring where the form is never loaded.

What seems to be needed is a new action. Instead of "Change Variable Name..." there needs to be a sub-menu "Change Variable Name ->" with options "Quick Change" and "Change with Refactoring". The values can be worked on if they do not suite anyone. This way a quick change on an unused form will just take place as usual and be very quick. Refactoring will fire off a UI and allow the user to preview or go ahead and refactor while remaining a specific user task as it takes more time.

I have added two screen shots showing the menu working in the inspector and in the UI editor. One shows the menu in the inspector, and the other shows the menu in the UI editor/builder.




Apart from giving the user the distinct option to refactor, this also makes the design easier to implement and follow. On the "Change with Refactoring" action, a separate thread will run to kick off the refactoring outside of the UI thread unless I find in refactoring support it makes sense to do so; the goal is to keep as little UI block as possible and keep things responsive.

The Java Infrastructure Developer's guide has an example of how to kick off this process. This can be used to figure out exactly which code will tie into the Refactoring. Assuming the refactoring support will already be in place to allow renaming of objects in the guarded code this should be straight forward as setting up a rename refactoring and allowing the process to complete normally. I will attempt to write a test to launch the process and see how far it gets to confirm this.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo