This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 258275 - Docking TopComponents under certain conditions leaves them uncloseable
Summary: Docking TopComponents under certain conditions leaves them uncloseable
Status: NEW
Alias: None
Product: platform
Classification: Unclassified
Component: Window System (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Stanislav Aubrecht
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-03-07 21:27 UTC by rfromm
Modified: 2016-03-08 12:54 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description rfromm 2016-03-07 21:27:12 UTC
I am unsure as to the specific means to recreate this bug in NetBeans, but the following is how I believe it works:

If you select 'Dock' from a floating top component such that it will move into a floating mode in the first tab position, and then attempt to dock that mode, the dock will fail, and you will be unable to close the individual windows in the group.

The reason that this occurs can be found in Central.moveTopComponentIntoMode. Specifically in this block:

if (prevMode != null && (intoSliding || intoSeparate)) {
            if (intoSeparate && mode.isPermanent()) {
                //TC is being moved to a undocked mode so from now it will be
                //groupped with other TCs in that mode
                //so change the previous mode to ensure it docks back into
                //the same mode as other TCs in this mode
                List<String> ids = mode.getTopComponentsIDs();
                if (!ids.isEmpty()) {
                    ModeImpl groupPrevMode = model.getModeTopComponentPreviousMode(mode, ids.get(0));
                    if (null != groupPrevMode) {
                        prevMode = groupPrevMode;
                    }
                }
            }
            // remember previous mode and constraints for precise de-auto-hide
            model.setModeTopComponentPreviousMode(mode, tcID, prevMode, prevIndex);
            model.setModeTopComponentPreviousConstraints(mode, tcID, model.getModeConstraints(prevMode));
        }

If the top component you are adding was placed in the 0 index position, groupPrevMode will evaluate to null. Which means that the previous mode of the top component will be the same as it was coming into the method; namely, the mode into which it is currently docking.

If the mode to be docked is permanent, Central.userDockedMode will attempt to dock into the previous mode of the 0 index position. Since we docked our top component to the 0 index earlier, the mode will attempt to dock into the previous mode of that top component; i.e. itself.

I believe the solution to this problem is simple; in the above block, instead of assuming that the first top component id will have a valid previous mode, loop through the ids until you hit one that does:

List<String> ids = mode.getTopComponentsIDs();
                if (!ids.isEmpty()) {
                    for(int i = 0; i < ids.size(); i++) {
                    ModeImpl groupPrevMode = model.getModeTopComponentPreviousMode(mode, ids.get(i));
                    if (null != groupPrevMode) {
                        prevMode = groupPrevMode;
                        break;
                    }
                 }

This should ensure that the previous mode of our top component will always be appropriately assigned.