Skip to content

Commit

Permalink
No issue. Stop processing when dialog is closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
lff0305 committed Jul 14, 2017
1 parent e2eb164 commit d85ed93
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/org/lff/plugin/dupfinder/Dialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -74,7 +75,7 @@ public void windowClosing(WindowEvent e) {

@Override
public void windowClosed(WindowEvent e) {

fireStop();
}

@Override
Expand Down Expand Up @@ -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<SourceVO> dependents) {
new Thread(()-> {
List<DuplicateClass> clz = new Finder().process(this, dependents);
Finder finder = new Finder();
setFinder(finder);
List<DuplicateClass> clz = finder.process(this, dependents);
Collections.sort(clz);
SwingUtilities.invokeLater(() -> {
this.listModal.clear();
Expand All @@ -211,6 +224,7 @@ private void process(List<SourceVO> dependents) {
getWindow().setCursor(Cursor.getDefaultCursor());
btnOK.setEnabled(true);
btnClear.setEnabled(true);
this.finder = null;
});
}).start();
}
Expand Down
18 changes: 18 additions & 0 deletions src/org/lff/plugin/dupfinder/Finder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@
*/
public class Finder {

private volatile boolean stopped = false;


private static final Logger logger = Logger.getLogger(Finder.class.getName());

public List<DuplicateClass> process(ProgressListener listener, List<SourceVO> dependents) {
Map<String, HashSet<SourceVO>> map = new HashMap<>();
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++;
Expand Down Expand Up @@ -53,6 +60,9 @@ public List<DuplicateClass> process(ProgressListener listener, List<SourceVO> de
private List<DuplicateClass> findDuplicates(Map<String, HashSet<SourceVO>> map) {
List<DuplicateClass> result = new ArrayList<>();
for (String clz : map.keySet()) {
if (stopped) {
return new ArrayList<>();
}
HashSet<SourceVO> dependents = map.get(clz);
if (dependents != null && dependents.size() > 1) {
result.add(new DuplicateClass(clz, dependents));
Expand Down Expand Up @@ -92,9 +102,17 @@ private List<String> 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;
}
}

0 comments on commit d85ed93

Please sign in to comment.