Skip to content

Commit 55481d3

Browse files
ptzieglervogella
authored andcommitted
Fix: Statusline not cleared after job completion if sub-tasks are used
Similar to `setTaskName()`, the string created when calling `subTask()` must also be stored in the `fTaskName`, rather than in `fMessageText` field. Otherwise the label of the status line is not cleared after calling done() on the progress monitor. Because the text of the sub-task is calculated using the value of `fTaskName`, the original name of the task needs to be stored in a separate field to avoid the name of the previous sub-task to be contained in the next sub-task. Closes #2762
1 parent 92e290e commit 55481d3

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

bundles/org.eclipse.jface/src/org/eclipse/jface/action/StatusLine.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2018 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -82,6 +82,9 @@
8282
/** name of the task */
8383
protected volatile String fTaskName;
8484

85+
/** name of the task without sub-tasks */
86+
protected volatile String fBaseTaskName;
87+
8588
/** is the task is cancled */
8689
protected volatile boolean fIsCanceled;
8790

@@ -580,6 +583,7 @@ public void setTaskName(String name) {
580583
boolean changed = !Objects.equals(fTaskName, s);
581584
if (changed) {
582585
fTaskName = s;
586+
fBaseTaskName = s;
583587
updateMessageLabel();
584588
}
585589
}
@@ -650,9 +654,13 @@ public void subTask(String name) {
650654
if (fTaskName == null || fTaskName.isEmpty()) {
651655
text = newName;
652656
} else {
653-
text = JFaceResources.format("Set_SubTask", fTaskName, newName);//$NON-NLS-1$
657+
text = JFaceResources.format("Set_SubTask", fBaseTaskName, newName);//$NON-NLS-1$
658+
}
659+
boolean changed = !Objects.equals(fTaskName, text);
660+
if (changed) {
661+
fTaskName = text;
662+
updateMessageLabel();
654663
}
655-
setMessage(text);
656664
}
657665

658666
/**

tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/api/IWorkbenchWindowTest.java

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,11 +14,15 @@
1414
package org.eclipse.ui.tests.api;
1515

1616
import org.eclipse.core.resources.ResourcesPlugin;
17+
import org.eclipse.jface.action.StatusLineManager;
18+
import org.eclipse.swt.custom.CLabel;
19+
import org.eclipse.swt.widgets.Composite;
1720
import org.eclipse.swt.widgets.Shell;
1821
import org.eclipse.ui.IWorkbenchActionConstants;
1922
import org.eclipse.ui.IWorkbenchPage;
2023
import org.eclipse.ui.IWorkbenchWindow;
2124
import org.eclipse.ui.WorkbenchException;
25+
import org.eclipse.ui.internal.WorkbenchWindow;
2226
import org.eclipse.ui.tests.harness.util.ArrayUtil;
2327
import org.eclipse.ui.tests.harness.util.EmptyPerspective;
2428
import org.eclipse.ui.tests.harness.util.UITestCase;
@@ -197,4 +201,33 @@ public void testIsApplicationMenu() {
197201
assertEquals(fWin.isApplicationMenu(id), false);
198202
}
199203
}
204+
205+
@Test
206+
public void testRunJobInStatusLine() throws Throwable {
207+
fWin.run(false, false, monitor -> {
208+
monitor.beginTask("Task", 1);
209+
assertStatusText("Task");
210+
});
211+
assertStatusText("");
212+
}
213+
214+
@Test
215+
public void testRunJobInStatusLineWithSubtasks() throws Throwable{
216+
fWin.run(false, false, monitor -> {
217+
monitor.beginTask("Task", 1);
218+
assertStatusText("Task");
219+
monitor.subTask("SubTask");
220+
assertStatusText("Task: SubTask");
221+
monitor.subTask("OtherSubTask");
222+
assertStatusText("Task: OtherSubTask");
223+
});
224+
assertStatusText("");
225+
}
226+
227+
private void assertStatusText(String text) {
228+
StatusLineManager statusManager = ((WorkbenchWindow) fWin).getStatusLineManager();
229+
Composite statusLine = (Composite) statusManager.getControl();
230+
CLabel statusLabel = (CLabel) statusLine.getChildren()[0];
231+
assertEquals("Status line was not updated.", text, statusLabel.getText());
232+
}
200233
}

0 commit comments

Comments
 (0)