|
1 | 1 | package net.seesharpsoft.intellij.plugins.csv.editor.table.swing; |
2 | 2 |
|
3 | 3 | import com.intellij.openapi.application.ApplicationManager; |
| 4 | +import com.intellij.openapi.util.Computable; |
4 | 5 | import com.intellij.psi.PsiElement; |
5 | 6 | import net.seesharpsoft.intellij.plugins.csv.CsvHelper; |
6 | 7 | import net.seesharpsoft.intellij.plugins.csv.editor.table.CsvTableEditor; |
|
25 | 26 |
|
26 | 27 | public class CsvTableModelSwing extends CsvTableModelBase<CsvTableEditor> implements TableModel { |
27 | 28 |
|
28 | | - /** |
29 | | - * List of listeners |
30 | | - */ |
31 | 29 | protected EventListenerList listenerList = new EventListenerList(); |
32 | 30 |
|
33 | | - protected ScheduledFuture delayedUpdate; |
| 31 | + protected ScheduledFuture<?> delayedUpdate; |
34 | 32 |
|
35 | 33 | protected ScheduledExecutorService executorService; |
36 | 34 |
|
@@ -64,10 +62,7 @@ private void doNotifyUpdate() { |
64 | 62 | } |
65 | 63 |
|
66 | 64 | protected void fireTableChanged(TableModelEvent e) { |
67 | | - // Guaranteed to return a non-null array |
68 | 65 | Object[] listeners = listenerList.getListenerList(); |
69 | | - // Process the listeners last to first, notifying |
70 | | - // those that are interested in this event |
71 | 66 | for (int i = listeners.length - 2; i >= 0; i -= 2) { |
72 | 67 | if (listeners[i] == TableModelListener.class) { |
73 | 68 | ((TableModelListener) listeners[i + 1]).tableChanged(e); |
@@ -97,17 +92,17 @@ public void removeTableModelListener(TableModelListener l) { |
97 | 92 |
|
98 | 93 | @Override |
99 | 94 | public String getColumnName(int column) { |
100 | | - PsiElement headerField = PsiHelper.findFirst(getPsiFile(), CsvTypes.FIELD); |
101 | | - if (headerField != null) { |
102 | | - headerField = PsiHelper.getNextNthSiblingOfType(headerField, column, CsvField.class); |
103 | | - } |
104 | | - String headerText = headerField == null ? "" : CsvHelper.unquoteCsvValue(headerField.getText(), getEscapeCharacter()).trim(); |
105 | | - |
106 | | - Map<String, Object> params = new HashMap<>(); |
107 | | - params.put("header", headerText); |
108 | | - params.put("index", CsvEditorSettings.getInstance().isZeroBasedColumnNumbering() ? column : column + 1); |
109 | | - |
110 | | - return CsvHelper.formatString("${header} (${index})", params); |
| 95 | + return ApplicationManager.getApplication().runReadAction((Computable<String>) () -> { |
| 96 | + PsiElement headerField = PsiHelper.findFirst(getPsiFile(), CsvTypes.FIELD); |
| 97 | + if (headerField != null) { |
| 98 | + headerField = PsiHelper.getNextNthSiblingOfType(headerField, column, CsvField.class); |
| 99 | + } |
| 100 | + String headerText = headerField == null ? "" : CsvHelper.unquoteCsvValue(headerField.getText(), getEscapeCharacter()).trim(); |
| 101 | + Map<String, Object> params = new HashMap<>(); |
| 102 | + params.put("header", headerText); |
| 103 | + params.put("index", CsvEditorSettings.getInstance().isZeroBasedColumnNumbering() ? column : column + 1); |
| 104 | + return CsvHelper.formatString("${header} (${index})", params); |
| 105 | + }); |
111 | 106 | } |
112 | 107 |
|
113 | 108 | @Override |
|
0 commit comments