How can I track one file's change event?

I'm developing a logviewer plugin to track logs. and I alomost done, but the errors down confuse me,
I find that if try to create a thread or a timer to check the file and write to the editor, the errors will throw out.
and I don't know how to use com.intellij.openapi.application.Application.runReadAction() to track the file's change event....'
i only can use it to print log once to the editor
who can help me? T_T

i really want to know how to use background thread to write datas to UI

----------------------------------------------------------------------------------------------
[  52994]  ERROR - plication.impl.ApplicationImpl - IntelliJ IDEA 14.1.4  Build #IU-141.1532.4
[  52994]  ERROR - plication.impl.ApplicationImpl - JDK: 1.7.0_75
[  52994]  ERROR - plication.impl.ApplicationImpl - VM: Java HotSpot(TM) 64-Bit Server VM
[  52994]  ERROR - plication.impl.ApplicationImpl - Vendor: Oracle Corporation
[  52994]  ERROR - plication.impl.ApplicationImpl - OS: Windows 7
[  52994]  ERROR - plication.impl.ApplicationImpl - Last Action:
[  52994]  ERROR - plication.impl.ApplicationImpl - Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())
Details: Current thread: Thread[AnimatorThread,5,main] 971639290
; dispatch thread: false; isDispatchThread(): false
SystemEventQueueThread: Thread[AWT-EventQueue-0 14.1.4#IU-141.1532.4, eap:false,6,main] 786992080
java.lang.Throwable
 at com.intellij.openapi.diagnostic.Logger.error(Logger.java:126)
 at com.intellij.openapi.application.impl.ApplicationImpl.assertReadAccessAllowed(ApplicationImpl.java:976)
 at com.intellij.openapi.editor.impl.EditorImpl.D(EditorImpl.java:5105)
 at com.intellij.openapi.editor.impl.EditorImpl.logicalPositionToOffset(EditorImpl.java:3728)
 at com.intellij.openapi.editor.impl.SoftWrapModelImpl.logicalPositionToOffset(SoftWrapModelImpl.java:382)
 at com.intellij.openapi.editor.impl.EditorImpl.logicalPositionToOffset(EditorImpl.java:3726)
 at com.intellij.openapi.editor.impl.EditorImpl.logicalPositionToOffset(EditorImpl.java:3719)
 at com.intellij.openapi.editor.impl.CaretImpl.a(CaretImpl.java:502)
 at com.intellij.openapi.editor.impl.CaretImpl.moveToLogicalPosition(CaretImpl.java:720)
 at com.intellij.openapi.editor.impl.CaretImpl.updateCaretPosition(CaretImpl.java:872)
 at com.intellij.openapi.editor.impl.CaretModelImpl$2.run(CaretModelImpl.java:89)
 at com.intellij.openapi.editor.impl.CaretModelImpl.doWithCaretMerging(CaretModelImpl.java:422)
 at com.intellij.openapi.editor.impl.CaretModelImpl.documentChanged(CaretModelImpl.java:85)
 at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:795)
 at com.intellij.openapi.editor.impl.DocumentImpl.a(DocumentImpl.java:731)
 at com.intellij.openapi.editor.impl.DocumentImpl.insertString(DocumentImpl.java:504)
 at cn.fishy.plugin.idea.logviewer.LogViewerConsole.append(LogViewerConsole.java:139)
 at cn.fishy.plugin.idea.logviewer.LogViewerConsole.processLine(LogViewerConsole.java:157)
 at cn.fishy.plugin.idea.logviewer.LogViewerConsole.readNext(LogViewerConsole.java:148)
 at cn.fishy.plugin.idea.logviewer.process.TrackTimer.onTimer(TrackTimer.java:27)
 at com.intellij.util.ui.Timer.fireAndReschedule(Timer.java:109)
 at com.intellij.util.ui.Timer.run(Timer.java:81)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
 at java.util.concurrent.FutureTask.run(FutureTask.java:262)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at java.lang.Thread.run(Thread.java:745)
[  52994]  ERROR - plication.impl.ApplicationImpl - IntelliJ IDEA 14.1.4  Build #IU-141.1532.4
[  52994]  ERROR - plication.impl.ApplicationImpl - JDK: 1.7.0_75
[  52994]  ERROR - plication.impl.ApplicationImpl - VM: Java HotSpot(TM) 64-Bit Server VM
[  52994]  ERROR - plication.impl.ApplicationImpl - Vendor: Oracle Corporation
[  52994]  ERROR - plication.impl.ApplicationImpl - OS: Windows 7
[  52995]  ERROR - plication.impl.ApplicationImpl - Last Action:
[  52995]  ERROR - plication.impl.ApplicationImpl - Read access is allowed from event dispatch thread or inside read-action only (see com.intellij.openapi.application.Application.runReadAction())
Details: Current thread: Thread[AnimatorThread,5,main] 971639290
; dispatch thread: false; isDispatchThread(): false

2 comments
Comment actions Permalink

finally i resolved it.... by searching for EDT, i find that UI event should only handled by AWT EventQueue... so if we create a thread and need to change ui we shuold use such as  SwingUtilities.invokeLater() ...

0

Please sign in to leave a comment.