Skip to content

Commit

Permalink
Don't freeze UI while importing CFP data
Browse files Browse the repository at this point in the history
  • Loading branch information
Musa Talluzi authored and ge0ffrey committed Oct 5, 2018
1 parent 53880f0 commit 8d44244
Showing 1 changed file with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.optaplanner.examples.common.business.SolutionBusiness;
import org.optaplanner.examples.common.swingui.SolutionPanel;
import org.optaplanner.examples.conferencescheduling.domain.ConferenceSolution;
import org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingCfpDevoxxImporter;
import org.optaplanner.examples.conferencescheduling.persistence.ConferenceSchedulingXlsxFileIO;
import org.optaplanner.persistence.common.api.domain.solution.SolutionFileIO;

import static java.util.concurrent.Executors.newSingleThreadExecutor;

public class ConferenceSchedulingPanel extends SolutionPanel<ConferenceSolution> {

public static final String LOGO_PATH = "/org/optaplanner/examples/conferencescheduling/swingui/conferenceSchedulingLogo.png";
Expand All @@ -54,8 +57,8 @@ public ConferenceSchedulingPanel() {
int option = JOptionPane.showConfirmDialog(this, dialogue, "Import", JOptionPane.OK_CANCEL_OPTION);
if (option == JOptionPane.OK_OPTION) {
String conferenceBaseUrl = cfpRestUrlTextField.getText();
ConferenceSchedulingCfpDevoxxImporter conferenceSchedulingImporter = new ConferenceSchedulingCfpDevoxxImporter(conferenceBaseUrl);
solutionBusiness.setSolution(conferenceSchedulingImporter.importSolution());
newSingleThreadExecutor().execute(new ConferenceImporter(conferenceBaseUrl, solutionBusiness));
JOptionPane.showMessageDialog(this, "Importing CFP data in progress ...");
}
});

Expand Down Expand Up @@ -106,4 +109,21 @@ public ConferenceSchedulingPanel() {
@Override
public void resetPanel(ConferenceSolution solution) {
}

private class ConferenceImporter implements Runnable {
String conferenceBaseUrl;
SolutionBusiness<ConferenceSolution> solutionBusiness;

public ConferenceImporter(String conferenceBaseUrl, SolutionBusiness<ConferenceSolution> solutionBusiness) {
this.conferenceBaseUrl = conferenceBaseUrl;
this.solutionBusiness = solutionBusiness;
}

@Override
public void run() {
ConferenceSchedulingCfpDevoxxImporter conferenceSchedulingImporter = new ConferenceSchedulingCfpDevoxxImporter(conferenceBaseUrl);
solutionBusiness.setSolution(conferenceSchedulingImporter.importSolution());
JOptionPane.showMessageDialog(ConferenceSchedulingPanel.this, "CFP data imported successfully.");
}
}
}

0 comments on commit 8d44244

Please sign in to comment.