Skip to content

Commit 156d669

Browse files
committed
Load configuration file in background
1 parent 3b1eea0 commit 156d669

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

swan_assist/src/de/fraunhofer/iem/swan/assist/ui/MethodListTree.java

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
import com.intellij.notification.Notifications;
88
import com.intellij.openapi.actionSystem.ActionManager;
99
import com.intellij.openapi.actionSystem.ActionPopupMenu;
10+
import com.intellij.openapi.application.ApplicationManager;
1011
import com.intellij.openapi.editor.Document;
1112
import com.intellij.openapi.fileEditor.FileDocumentManager;
1213
import com.intellij.openapi.fileEditor.FileEditorManager;
1314
import com.intellij.openapi.fileEditor.FileEditorManagerEvent;
1415
import com.intellij.openapi.fileEditor.FileEditorManagerListener;
16+
import com.intellij.openapi.progress.ProgressIndicator;
17+
import com.intellij.openapi.progress.ProgressManager;
18+
import com.intellij.openapi.progress.Task;
1519
import com.intellij.openapi.project.Project;
1620
import com.intellij.openapi.ui.MessageType;
1721
import com.intellij.openapi.ui.popup.Balloon;
@@ -107,6 +111,7 @@ public void mouseClicked(MouseEvent e) {
107111

108112
//Get PSI element location
109113
PsiFile[] files = FilenameIndex.getFilesByName(project, method.getFileName(), GlobalSearchScope.allScope(project));
114+
110115
boolean methodFound = false;
111116

112117
for (PsiFile file : files) {
@@ -116,9 +121,7 @@ public void mouseClicked(MouseEvent e) {
116121
for (PsiClass psiClass : psiJavaFile.getClasses()) {
117122
for (PsiMethod psiMethod : psiClass.getMethods()) {
118123

119-
120-
if (PsiTraversal.getMethodSignature(psiMethod).equals(method.getSignature(true))) {
121-
System.out.println(PsiTraversal.getMethodSignature(psiMethod) + ">>>>" + method.getSignature(true));
124+
if (Objects.equals(PsiTraversal.getMethodSignature(psiMethod), method.getSignature(true))) {
122125

123126
methodFound = true;
124127
FileEditorManager.getInstance(project).openFile(psiJavaFile.getVirtualFile(), true, true);
@@ -147,9 +150,20 @@ public void mouseClicked(MouseEvent e) {
147150
@Override
148151
public void notifyFileChange(String fileName) {
149152

150-
JSONFileLoader.setConfigurationFile(fileName);
151-
JSONFileLoader.loadInitialFile();
152-
loadMethods();
153+
ProgressManager.getInstance().run(new Task.Backgroundable(project, resource.getString("Status.ImportFile")) {
154+
@Override
155+
public void run(@NotNull ProgressIndicator progressIndicator) {
156+
157+
ApplicationManager.getApplication().runReadAction(new Runnable() {
158+
public void run() {
159+
JSONFileLoader.setConfigurationFile(fileName);
160+
JSONFileLoader.loadInitialFile();
161+
loadMethods();
162+
}
163+
});
164+
}
165+
});
166+
153167
DaemonCodeAnalyzer.getInstance(project).restart();
154168
}
155169
});
@@ -159,8 +173,20 @@ public void notifyFileChange(String fileName) {
159173
@Override
160174
public void notifyFileChange(String fileName) {
161175

162-
JSONFileLoader.loadUpdatedFile(fileName);
163-
loadMethods();
176+
ProgressManager.getInstance().run(new Task.Backgroundable(project, resource.getString("Status.ImportFile")) {
177+
@Override
178+
public void run(@NotNull ProgressIndicator progressIndicator) {
179+
180+
ApplicationManager.getApplication().runReadAction(new Runnable() {
181+
public void run() {
182+
JSONFileLoader.loadUpdatedFile(fileName);
183+
loadMethods();
184+
}
185+
});
186+
}
187+
});
188+
189+
DaemonCodeAnalyzer.getInstance(project).restart();
164190
}
165191
});
166192

@@ -200,8 +226,7 @@ public void afterAction(MethodWrapper newMethod) {
200226
@Override
201227
public void afterAction(ArrayList<MethodWrapper> methods) {
202228

203-
System.out.println("n=mi get "+methods.size());
204-
for(MethodWrapper method: methods){
229+
for (MethodWrapper method : methods) {
205230
JSONFileLoader.addMethod(method);
206231
addNode(method);
207232
}
@@ -342,7 +367,7 @@ private DefaultMutableTreeNode searchNode(DefaultMutableTreeNode root, String me
342367
return null;
343368
}
344369

345-
private void addNode(MethodWrapper method){
370+
private void addNode(MethodWrapper method) {
346371
DefaultMutableTreeNode root = (DefaultMutableTreeNode) getModel().getRoot();
347372
DefaultMutableTreeNode newMethodNode = new DefaultMutableTreeNode(method);
348373

0 commit comments

Comments
 (0)