Problem with the IntelliL IDEA progress bar
Hello folks!
I created psi class files using the code below. Everything works as it's supposed to.
The problem is I cant update IntelliL IDEA progress bar.
I need to update it as below:
Started...
Saving file1...
Saving file2...
Saving file3...
Right now I can only see Started... text.
Any advice and suggestions will be highly appreciated!
------------------------------------------------------------------------------------------------------------------------------
generateButton.addActionListener(e -> {
if(selectedList.size() == 0) return;
final Task.Modal saveTask =
new Task.Modal(project, "Creating Services", true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setText("Started...");
THREAD_COUNT = selectedList.size();
System.out.println("Thread count size: " + THREAD_COUNT);
callable = new CallableDelay[THREAD_COUNT];
futureTask = new FutureTask[THREAD_COUNT];
executor = Executors.newFixedThreadPool(THREAD_COUNT);
for (int i = 0; i < THREAD_COUNT; i++) {
callable[i] = new CallableDelay(1000, (i + 1));
futureTask[i] = new FutureTask<>(callable[i]);
executor.execute(futureTask[i]);
}
while (true) {
try {
if (areTasksDone()) {
executor.shutdown();
System.out.println("\nexecutor shutdown");
return;
}
for (int i = 0; i < THREAD_COUNT; i++) {
System.out.println("\nThread: " + i);
if (!futureTask[i].isDone()) {
try {
System.out.println("Thread " + i + " completed: "
+ futureTask[i].get(1500L,
TimeUnit.MILLISECONDS));
indicator.setText(Integer.toString(i));
} catch (final Exception e3) {
System.err.println("An error occurred: " + e3.getMessage());
}
}
}
} catch (final Exception e2) {
System.err.println("An error occurred: " + e2.getMessage());
}
}
}
};
// The progress manager is only good for foreground threads.
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().run(saveTask);
} else {
// Run the scan task when the thread is in the foreground.
SwingUtilities.invokeLater(() -> ProgressManager.getInstance().run(saveTask));
}
});
--------------------------------------------------------------------------------
CallableDelay[] callable = null;
FutureTask<String>[] futureTask = null;
ExecutorService executor = null;
private int THREAD_COUNT;
//---------------------------------------------------------------
class CallableDelay implements Callable<String>
{
private long delay;
private int idx ;
private int cycle;
public CallableDelay(int delay, int idx)
{
this.delay = delay;
this.idx = idx;
this.cycle = idx;
}
@Override
public String call() throws Exception
{
while (cycle > 0) {
Thread.sleep(delay);
cycle--;
if ((idx == 2) && (cycle > 0))
futureTask[futureTask.length - 1].cancel(true);
}
ApplicationManager.getApplication().invokeLater(() -> {
final String sName = serviceName.getText();
final ServiceGenerator serviceGenerator = new ServiceGenerator(
sName,
servicePackage.getText(),
addPaginationCheckBox.isSelected()
);
serviceGenerator.generateServiceSingleNode(selectedList.get(idx), project, sName);
}, ModalityState.any());
return ""+ idx +". "+ Thread.currentThread().getName();
}
}
//---------------------------------------------------------------
private boolean areTasksDone()
{
boolean isDone = true;
for (int i = 0; i < THREAD_COUNT; i++) {
if (!futureTask[i].isDone()) {
isDone = false;
break;
}
}
return isDone;
}
--------------------------------------------------------------------
请先登录再写评论。
You never call indicator.setText("Saving fileN"), so it's no surprise you don't see it. You call indicator.setText(Integer.toString(i)), but you only do it after a future has returned successfully, so it might be that all your threads complete in roughly the same time, and the whole modal progress is finished before it has chance to show you that a file has been saved.