未验证 提交 a39dfec6 编写于 作者: M Mathieu Bastian 提交者: GitHub

Merge pull request #2737 from gephi/u/totetmatt/bug_fix_empty_gephi_file_on_save

#2736 Fix issue with empty gephi file when save on close
...@@ -356,24 +356,21 @@ public class DesktopImportControllerUI implements ImportControllerUI { ...@@ -356,24 +356,21 @@ public class DesktopImportControllerUI implements ImportControllerUI {
importer.getClass().getSimpleName())); importer.getClass().getSimpleName()));
String taskName = String taskName =
NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource); NbBundle.getMessage(DesktopImportControllerUI.class, "DesktopImportControllerUI.taskName", containerSource);
executor.execute(task, new Runnable() { executor.execute(task, () -> {
@Override try {
public void run() { Container container;
try { if (importer instanceof FileImporter.FileAware && file != null) {
Container container; container = controller.importFile(file, importer);
if (importer instanceof FileImporter.FileAware && file != null) { } else {
container = controller.importFile(file, importer); container = controller.importFile(reader, importer);
} else { }
container = controller.importFile(reader, importer);
}
if (container != null) { if (container != null) {
container.setSource(containerSource); container.setSource(containerSource);
results.add(container); results.add(container);
}
} catch (Exception ex) {
throw new RuntimeException(ex);
} }
} catch (Exception ex) {
throw new RuntimeException(ex);
} }
}, taskName, errorHandler.createHandler(containerSource)); }, taskName, errorHandler.createHandler(containerSource));
} }
......
...@@ -47,6 +47,10 @@ import java.io.IOException; ...@@ -47,6 +47,10 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import javax.swing.JFileChooser; import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
...@@ -222,22 +226,28 @@ public class ProjectControllerUIImpl implements ProjectListener { ...@@ -222,22 +226,28 @@ public class ProjectControllerUIImpl implements ProjectListener {
}); });
} }
private void saveProject(Project project, File file) { private Future<Void> saveProject(Project project, File file) {
longTaskExecutor.execute(null, () -> {
controller.saveProject(project, file);
return longTaskExecutor.execute(null, new Callable<Void>() {
@Override
public Void call() throws Exception {
controller.saveProject(project, file);
return null;
}
}); });
} }
public void saveProject() { public Future<Void> saveProject() {
Project project = controller.getCurrentProject(); Project project = controller.getCurrentProject();
if (project.hasFile()) { if (project.hasFile()) {
saveProject(project, project.getFile()); return saveProject(project, project.getFile());
} else { } else {
saveAsProject(); return saveAsProject();
} }
} }
public void saveAsProject() { public Future<Void> saveAsProject() {
final String LAST_PATH = "SaveAsProject_Last_Path"; final String LAST_PATH = "SaveAsProject_Last_Path";
final String LAST_PATH_DEFAULT = "SaveAsProject_Last_Path_Default"; final String LAST_PATH_DEFAULT = "SaveAsProject_Last_Path_Default";
...@@ -281,8 +291,9 @@ public class ProjectControllerUIImpl implements ProjectListener { ...@@ -281,8 +291,9 @@ public class ProjectControllerUIImpl implements ProjectListener {
NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath()); NbPreferences.forModule(ProjectControllerUIImpl.class).put(LAST_PATH, file.getAbsolutePath());
// Save file // Save file
saveProject(controller.getCurrentProject(), file); return saveProject(controller.getCurrentProject(), file);
} }
return CompletableFuture.completedFuture(null);
} }
private boolean canExport(JFileChooser chooser) { private boolean canExport(JFileChooser chooser) {
...@@ -335,7 +346,14 @@ public class ProjectControllerUIImpl implements ProjectListener { ...@@ -335,7 +346,14 @@ public class ProjectControllerUIImpl implements ProjectListener {
new Object[] {saveBundle, doNotSaveBundle, cancelBundle}, saveBundle); new Object[] {saveBundle, doNotSaveBundle, cancelBundle}, saveBundle);
Object result = DialogDisplayer.getDefault().notify(msg); Object result = DialogDisplayer.getDefault().notify(msg);
if (result == saveBundle) { if (result == saveBundle) {
saveProject(); Future<Void> saveTask = saveProject();
if(saveTask !=null){
try {
saveTask.get();
} catch (InterruptedException | ExecutionException ex) {
Exceptions.printStackTrace(ex);
}
}
} else if (result == cancelBundle) { } else if (result == cancelBundle) {
return false; return false;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册