Refreshing ProjectView after compilation

Hi,

I am running post-compile task that is possibly changing files status and requires updating file icons. To make the changes visible I am using:

ProjectView.getInstance (project).refresh ();

As was advised in another thread. Refresh is write action thus could be run only from Swing event dispatch thread using Application.runWriteAction() method. On the other hand the post-compile task is being run in Compilation thread that does not allow performing write actions (I get all kinds of assertion errors if I try).

I tried to wait for completion of my post-compile task in a GUI dispatch thread that triggered compilation but it causes deadlock. I am using:

CompilerManager.getInstance (project).make(new ProjectCompileScope (project), null);

To start compilation. I tried a few different approaches and as far as I can see the compilation thread is not started my actionPerfromed() method in Swing dispatch thread has exited. This makes sense to me because compilation is obviously write action that should wait for all possible read actions to complete, but leaves no way to perform an after-compilation write action.

I also tried to start a new thread from event dispatch thread that waits for post-compile task to complete and then starts refresh, but it is no better because the same assertions naturally fail.

Note: the action is actually performed correctly regardless the assertions, the project view is updated.

Any suggestions are greatly appreciated.

Misha

3 comments

Hello Misha,

MB> I am running post-compile task that is possibly changing files
MB> status and requires updating file icons. To make the changes visible
MB> I am using:
MB>
MB> ProjectView.getInstance (project).refresh ();
MB>
MB> As was advised in another thread. Refresh is write action thus could
MB> be run only from Swing event dispatch thread using
MB> Application.runWriteAction() method. On the other hand the
MB> post-compile task is being run in Compilation thread that does not
MB> allow performing write actions (I get all kinds of assertion errors
MB> if I try).
MB>
MB> I tried to wait for completion of my post-compile task in a GUI
MB> dispatch thread that triggered compilation but it causes deadlock. I
MB> am using:
MB>
MB> CompilerManager.getInstance (project).make(new ProjectCompileScope
MB> (project), null);
MB>
MB> To start compilation. I tried a few different approaches and as far
MB> as I can see the compilation thread is not started my
MB> actionPerfromed() method in Swing dispatch thread has exited. This
MB> makes sense to me because compilation is obviously write action that
MB> should wait for all possible read actions to complete, but leaves no
MB> way to perform an after-compilation write action.
MB>
MB> I also tried to start a new thread from event dispatch thread that
MB> waits for post-compile task to complete and then starts refresh, but
MB> it is no better because the same assertions naturally fail.
MB>
MB> Note: the action is actually performed correctly regardless the
MB> assertions, the project view is updated.
MB>
MB> Any suggestions are greatly appreciated.

Why can't you simply use SwingUtilities.invokeLater() to invoke a runnable
performing the project view refresh?

--
Dmitry Jemerov
Software Developer
http://www.jetbrains.com/
"Develop with Pleasure!"


0

Oh, thanks Dmitry, this is because of my lack of Swing experience. But it does not seem to always help. I now call

SwingUtilities.invokeLater()

immediately after:

CompilerManager.getInstance (project).make()

and sometimes it works but sometimes make waits for runnable called in invokeLater to complete before even starting. Any ideas why this would happen?

Thanks,

Misha

0

OK, I figured it out. I can call SwingUtilities.invokeLater()
from compiler thread not necessarily from Siwng even dispatch thread. My bad again.

Thanks Dmitry.

0

Please sign in to leave a comment.