Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 149294 - allow refactoring non-editable parts of code inside initComponents() method
allow refactoring non-editable parts of code inside initComponents() method
Status: RESOLVED DUPLICATE of bug 106831
Product: guibuilder
Classification: Unclassified
Component: Code
All All
: P3 (vote)
Assigned To: issues@guibuilder
Depends on:
  Show dependency treegraph
Reported: 2008-10-06 21:55 UTC by benderamp
Modified: 2008-10-07 18:01 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description benderamp 2008-10-06 21:55:18 UTC

I can have some custom creation code for some component on a frame. For example:

class MyPanel extends JPanel {
    MyParamClass param1;
    MyPanel() {
        param1 = new MyParamClass();
    private void initComponents() {
        MyLabel lab1 = new MyLabel(param1);

Here "param1" value inside "MyLabel lab1 = new MyLabel(param1);" construction is set as custom creation code for the lab1 component in the UI 
Designer view. If I refactor param1 field, changing its name to param21 for example, the non-editable initialization code inside initComponents() 
method will not change - the new "MyLabel(param1)" call would remain the same and I will receive compilation error here (as "MyParamClass 
param1;" declaration is now changed to "MyParamClass param2;") - I have to open UI Designer and change custom creation code there manually to 
fix this.

Also to continue this issue with non-editable area and custom UI creation code - it is not very comfortable to edit custom creation code inside UI 
Designer - by opening modal dialog for each code part for each ui element. I think this could be done inside source code editor without switching 
off the non-editable state of the whole initComponents() method. The initComponent() method section could be non-editable in the whole, but would
have active areas (highlighted by another color), by clicking on which the custom code editor dialog would pop up for the selected section.

For the above example, the line below line:
        MyLabel lab1 = new MyLabel(param1);

would be splitted to sections:
non-editable: "MyLabel lab1 = new MyLabel("
highlighted area: "param1"
non-editable: ");"

By clicking on "param1" section the described dialog would popup and would allow to change the "param1" to any other text ("param21" for 
example like in case with refactoring).
Comment 1 Jan Pokorsky 2008-10-07 10:24:46 UTC
The refactoring of guarded sections inside form files is handled by the form module. Reassigning.
Comment 2 Jan Stola 2008-10-07 10:49:59 UTC

*** This issue has been marked as a duplicate of 106831 ***
Comment 3 Tomas Pavek 2008-10-07 18:01:36 UTC
Not all refactorings work in the custom code in guarded blocks, but such a simple renaming should work. I've just 
tried the described case in current 6.5 dev build and it works for me - the custom creation is updated to the new 
field name properly. This could have been fixed after 6.1.

As for the editing inside initComponents - yes, it would be nice, but it would be quite complicated to implement. The 
main problem is that we don't really know how the code maps back to the GUI elements and attributes - to interpret 
what to do when you click somewhere in the code. If we knew this, we would be quite close to full 2-way editing.

Note that you don't have to "open modal dialog for each code part for each ui element". There is "Customize Code" 
action in context menu opening a dialog where you can edit all custom code for selected component and can select other 
components without leaving the dialog.

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