Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.seesharpsoft.intellij.plugins.csv.editor.table.swing;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.PsiElement;
import net.seesharpsoft.intellij.plugins.csv.CsvHelper;
import net.seesharpsoft.intellij.plugins.csv.editor.table.CsvTableEditor;
Expand Down Expand Up @@ -30,7 +31,7 @@ public class CsvTableModelSwing extends CsvTableModelBase<CsvTableEditor> implem
*/
protected EventListenerList listenerList = new EventListenerList();

protected ScheduledFuture delayedUpdate;
protected ScheduledFuture<?> delayedUpdate;

protected ScheduledExecutorService executorService;

Expand Down Expand Up @@ -95,19 +96,23 @@ public void removeTableModelListener(TableModelListener l) {
listenerList.remove(TableModelListener.class, l);
}

/**
* Gets header name for a given column, with index formatting.
* PSI access is wrapped in a read action for thread safety.
*/
@Override
public String getColumnName(int column) {
PsiElement headerField = PsiHelper.findFirst(getPsiFile(), CsvTypes.FIELD);
if (headerField != null) {
headerField = PsiHelper.getNextNthSiblingOfType(headerField, column, CsvField.class);
}
String headerText = headerField == null ? "" : CsvHelper.unquoteCsvValue(headerField.getText(), getEscapeCharacter()).trim();

Map<String, Object> params = new HashMap<>();
params.put("header", headerText);
params.put("index", CsvEditorSettings.getInstance().isZeroBasedColumnNumbering() ? column : column + 1);

return CsvHelper.formatString("${header} (${index})", params);
return ApplicationManager.getApplication().runReadAction((Computable<String>) () -> {
PsiElement headerField = PsiHelper.findFirst(getPsiFile(), CsvTypes.FIELD);
if (headerField != null) {
headerField = PsiHelper.getNextNthSiblingOfType(headerField, column, CsvField.class);
}
String headerText = headerField == null ? "" : CsvHelper.unquoteCsvValue(headerField.getText(), getEscapeCharacter()).trim();
Map<String, Object> params = new HashMap<>();
params.put("header", headerText);
params.put("index", CsvEditorSettings.getInstance().isZeroBasedColumnNumbering() ? column : column + 1);
return CsvHelper.formatString("${header} (${index})", params);
});
}

@Override
Expand All @@ -119,4 +124,4 @@ public Class<?> getColumnClass(int columnIndex) {
public boolean isCellEditable(int rowIndex, int columnIndex) {
return getPsiFileHolder().isEditable();
}
}
}