| Summary: | Context Menus and AbstractEditPartViewer | ||
|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Casey Best <cbest> |
| Component: | GEF-Legacy GEF (MVC) | Assignee: | gef-inbox <gef-inbox> |
| Status: | RESOLVED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | ||
| Version: | 3.1.1 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows XP | ||
| Whiteboard: | |||
Not sure if this is an SWT problem or not. When a control is disposed that has a context menu, the context menu is disposed. If that menu is shared in another control, it is possible that when the menu is queried from the other control, it will be disposed. If this is what is happening, please move this bug back to SWT. Thanks. Why are you calling unhookControl? This method should only be called when the Control is actually disposed. Control already sets its menu to null when it is disposed, so this would be redundant. Randy, Sorry for the lack of detail. We don't call unhookControl. You do. See setControl(Control control) in AbstractEditPartViewer. Since setControl is a public method, calling it should not cause exceptions. Unfortunately it does because you do not set the menu to null in unhookControl. Cheers, Casey You still haven't provided the scenario. Surely you are aware that clients already call setControl and use context menus. Where's the exception? How about a stack trace or anything to go on. Unforunately the stack trace and any other information I could produce to help you is IBM confidential. I have fixed the bug in our product. I only filed this bug report to assist you in yours. Cheers, Casey |
Reproduce: 1) Create an instance of AbstractEditPartViewer 2) Have the viewer create a tree for its control, and set a context menu on it. 3) Call unhookControl on the AbstractEditPartViewer 4) Call hookControl on the AbstractEditPartViewer 5) Allow the GUI to refresh Problem: Causes a Disposed Widget Exception (SWTException). Reason: When unhookControl is called, the context menu is disposed, but not unhooked from the control. When the control refreshes, it tries to refresh the context menu, thus causing the exception. The solution: Set the control's menu to null when unhooking. This will force the control to release the disposed menu. The unhookControl method should look like: protected void unhookControl() { Assert.isTrue(getControl() != null); if (disposeListener != null) { getControl().removeDisposeListener(disposeListener); disposeListener = null; } if (getContextMenu() != null) getContextMenu().dispose(); if (getRootEditPart() != null) getRootEditPart().deactivate(); getControl().setMenu(null); }