Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ public Optional<MPerspective> switchPerspective(String perspectiveId) {
}

private void switchPerspectiveInternal(MPerspective perspective) {
perspective.getParent().setSelectedElement(perspective);
// Only set the perspective as selected if it is still to be rendered
if (perspective.isToBeRendered()) {
perspective.getParent().setSelectedElement(perspective);
}
UIEvents.publishEvent(UIEvents.UILifeCycle.PERSPECTIVE_SWITCHED, perspective);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private void selectForcedPerspective() {

for (MPerspective persp : perspStack.getChildren()) {
if (persp.getElementId().equals(forcedPerspectiveId)) {
perspStack.setSelectedElement(persp);
// Only set as selected if it's to be rendered
if (persp.isToBeRendered()) {
perspStack.setSelectedElement(persp);
}
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,10 @@ public void bringToTop(MUIElement element) {
element.setToBeRendered(true);
}

window.getParent().setSelectedElement(window);
// Only set the window as selected if it is still to be rendered (not being removed)
if (window.isToBeRendered()) {
window.getParent().setSelectedElement(window);
}
} else {
showElementInWindow(window, element);
}
Expand Down Expand Up @@ -647,7 +650,10 @@ private void showElementInWindow(MWindow window, MUIElement element) {

@SuppressWarnings("unchecked")
MElementContainer<MUIElement> container = (MElementContainer<MUIElement>) parent;
container.setSelectedElement(element);
// Only set as selected if the element is still to be rendered
if (element.isToBeRendered()) {
container.setSelectedElement(element);
}
if (window != parent) {
showElementInWindow(window, parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,10 @@ public void switchPerspective(MPerspective perspective) {
Assert.isNotNull(perspective);
MWindow window = getWindow();
if (window != null && isInContainer(window, perspective)) {
perspective.getParent().setSelectedElement(perspective);
// Only set the perspective as selected if it is still to be rendered
if (perspective.isToBeRendered()) {
perspective.getParent().setSelectedElement(perspective);
}
List<MPart> newPerspectiveParts = modelService.findElements(perspective, null,
MPart.class, null);
// if possible, keep the same active part across perspective switches
Expand Down Expand Up @@ -771,7 +774,10 @@ private void activate(MPart part, boolean requiresFocus, boolean activateBranch)
recordStackActivation(part);

delegateBringToTop(part);
window.getParent().setSelectedElement(window);
// Only set the window as selected if it is still to be rendered (not being removed)
if (window.isToBeRendered()) {
window.getParent().setSelectedElement(window);
}

partActivationHistory.activate(part, activateBranch);

Expand Down Expand Up @@ -1323,7 +1329,10 @@ private void createElement(MUIElement element) {
parent = element.getParent();
if (parent != null && parent.getChildren().size() == 1) {
// if we're the only child, set ourselves as the selected element
parent.setSelectedElement(element);
// only if we're still to be rendered
if (element.isToBeRendered()) {
parent.setSelectedElement(element);
}
}
}

Expand Down Expand Up @@ -1390,7 +1399,7 @@ public void hidePart(MPart part, boolean force) {
MUIElement candidate = partActivationHistory.getSiblingSelectionCandidate(part);
candidate = candidate == null ? null
: candidate.getCurSharedRef() == null ? candidate : candidate.getCurSharedRef();
if (candidate != null && children.contains(candidate)) {
if (candidate != null && children.contains(candidate) && candidate.isToBeRendered()) {
parent.setSelectedElement(candidate);
} else {
for (MUIElement child : children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10100,6 +10100,39 @@ public void partVisible(MPart part) {

}

/**
* Test for Bug 3509: IllegalArgumentException when exiting e4-RCP application.
* This test verifies that activating a part when the window is being removed
* (toBeRendered=false) doesn't throw an IllegalArgumentException.
*/
@Test
public void testActivatePartDuringWindowCleanup() {
createApplication("partId");

MWindow window = application.getChildren().get(0);
getEngine().createGui(window);

EPartService partService = window.getContext().get(EPartService.class);
MPart part = partService.findPart("partId");
assertNotNull(part);

// Activate the part first
partService.activate(part);
assertEquals(part, partService.getActivePart());

// Simulate window cleanup by setting toBeRendered to false
window.setToBeRendered(false);

// Now activate the part again - this should not throw an IllegalArgumentException
// even though the window is no longer toBeRendered
try {
partService.activate(part);
// If we reach here, the fix is working
} catch (IllegalArgumentException e) {
fail("Should not throw IllegalArgumentException when activating part during window cleanup: " + e.getMessage());
}
}

static class ExceptionListener implements IPartListener {

@Override
Expand Down