From d85ed93e05ccbe4dc91701b46df1cf5eeae030b5 Mon Sep 17 00:00:00 2001 From: FeifeiLiu Date: Fri, 14 Jul 2017 14:21:20 +0800 Subject: [PATCH] No issue. Stop processing when dialog is closed. --- src/org/lff/plugin/dupfinder/Dialog.java | 18 ++++++++++++++++-- src/org/lff/plugin/dupfinder/Finder.java | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/org/lff/plugin/dupfinder/Dialog.java b/src/org/lff/plugin/dupfinder/Dialog.java index 7cdf6e9..d84ef1d 100644 --- a/src/org/lff/plugin/dupfinder/Dialog.java +++ b/src/org/lff/plugin/dupfinder/Dialog.java @@ -45,6 +45,7 @@ public class Dialog extends DialogWrapper implements ProgressListener { private final Project project; + private Finder finder; private ProjectRootManager rootManager = null; public Dialog(Project project, ProjectRootManager rootManager) { @@ -74,7 +75,7 @@ public void windowClosing(WindowEvent e) { @Override public void windowClosed(WindowEvent e) { - + fireStop(); } @Override @@ -198,9 +199,21 @@ public boolean process(Library library) { process(dependents); } + private void setFinder(Finder finder) { + this.finder = finder; + } + + private void fireStop() { + if (this.finder != null) { + this.finder.stop(); + } + } + private void process(List dependents) { new Thread(()-> { - List clz = new Finder().process(this, dependents); + Finder finder = new Finder(); + setFinder(finder); + List clz = finder.process(this, dependents); Collections.sort(clz); SwingUtilities.invokeLater(() -> { this.listModal.clear(); @@ -211,6 +224,7 @@ private void process(List dependents) { getWindow().setCursor(Cursor.getDefaultCursor()); btnOK.setEnabled(true); btnClear.setEnabled(true); + this.finder = null; }); }).start(); } diff --git a/src/org/lff/plugin/dupfinder/Finder.java b/src/org/lff/plugin/dupfinder/Finder.java index cdd722f..e857f00 100644 --- a/src/org/lff/plugin/dupfinder/Finder.java +++ b/src/org/lff/plugin/dupfinder/Finder.java @@ -16,6 +16,9 @@ */ public class Finder { + private volatile boolean stopped = false; + + private static final Logger logger = Logger.getLogger(Finder.class.getName()); public List process(ProgressListener listener, List dependents) { @@ -23,6 +26,10 @@ public List process(ProgressListener listener, List de int totalSize = dependents.size() + 2; int count = 0; for (SourceVO vo : dependents) { + if (stopped) { + return new ArrayList<>(); + } + String name = vo.getUrl(); String library = vo.getLibrary(); count++; @@ -53,6 +60,9 @@ public List process(ProgressListener listener, List de private List findDuplicates(Map> map) { List result = new ArrayList<>(); for (String clz : map.keySet()) { + if (stopped) { + return new ArrayList<>(); + } HashSet dependents = map.get(clz); if (dependents != null && dependents.size() > 1) { result.add(new DuplicateClass(clz, dependents)); @@ -92,9 +102,17 @@ private List loadClassNames(String name) { } logger.info("Adding " + entryName); result.add(entryName); + if (stopped) { + return result; + } } } catch (IOException e) { } return result; } + + public void stop() { + logger.info("STOP called"); + this.stopped = true; + } }