Skip to content

Commit

Permalink
Fix: Statusline not cleared after job completion if sub-tasks are used
Browse files Browse the repository at this point in the history
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 eclipse-platform#2762
  • Loading branch information
ptziegler authored and vogella committed Jan 29, 2025
1 parent 92e290e commit 55481d3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2018 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -82,6 +82,9 @@
/** name of the task */
protected volatile String fTaskName;

/** name of the task without sub-tasks */
protected volatile String fBaseTaskName;

/** is the task is cancled */
protected volatile boolean fIsCanceled;

Expand Down Expand Up @@ -580,6 +583,7 @@ public void setTaskName(String name) {
boolean changed = !Objects.equals(fTaskName, s);
if (changed) {
fTaskName = s;
fBaseTaskName = s;
updateMessageLabel();
}
}
Expand Down Expand Up @@ -650,9 +654,13 @@ public void subTask(String name) {
if (fTaskName == null || fTaskName.isEmpty()) {
text = newName;
} else {
text = JFaceResources.format("Set_SubTask", fTaskName, newName);//$NON-NLS-1$
text = JFaceResources.format("Set_SubTask", fBaseTaskName, newName);//$NON-NLS-1$
}
boolean changed = !Objects.equals(fTaskName, text);
if (changed) {
fTaskName = text;
updateMessageLabel();
}
setMessage(text);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2013 IBM Corporation and others.
* Copyright (c) 2000, 2025 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,11 +14,15 @@
package org.eclipse.ui.tests.api;

import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.jface.action.StatusLineManager;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.internal.WorkbenchWindow;
import org.eclipse.ui.tests.harness.util.ArrayUtil;
import org.eclipse.ui.tests.harness.util.EmptyPerspective;
import org.eclipse.ui.tests.harness.util.UITestCase;
Expand Down Expand Up @@ -197,4 +201,33 @@ public void testIsApplicationMenu() {
assertEquals(fWin.isApplicationMenu(id), false);
}
}

@Test
public void testRunJobInStatusLine() throws Throwable {
fWin.run(false, false, monitor -> {
monitor.beginTask("Task", 1);
assertStatusText("Task");
});
assertStatusText("");
}

@Test
public void testRunJobInStatusLineWithSubtasks() throws Throwable{
fWin.run(false, false, monitor -> {
monitor.beginTask("Task", 1);
assertStatusText("Task");
monitor.subTask("SubTask");
assertStatusText("Task: SubTask");
monitor.subTask("OtherSubTask");
assertStatusText("Task: OtherSubTask");
});
assertStatusText("");
}

private void assertStatusText(String text) {
StatusLineManager statusManager = ((WorkbenchWindow) fWin).getStatusLineManager();
Composite statusLine = (Composite) statusManager.getControl();
CLabel statusLabel = (CLabel) statusLine.getChildren()[0];
assertEquals("Status line was not updated.", text, statusLabel.getText());
}
}

0 comments on commit 55481d3

Please sign in to comment.