Implement cancelling the insert when the “cancel” button is pressed.
[jSite.git] / src / de / todesbaum / jsite / gui / ProjectInsertPage.java
index e8e2154..b722ceb 100644 (file)
@@ -91,6 +91,9 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
        /** Whether the “copy URI to clipboard” button was used. */
        private boolean uriCopied;
 
+       /** Whether the insert is currently running. */
+       private volatile boolean running = false;
+
        /**
         * Creates a new progress insert wizard page.
         *
@@ -203,7 +206,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
        public void pageAdded(TWizard wizard) {
                this.wizard.setPreviousName(I18n.getMessage("jsite.wizard.previous"));
                this.wizard.setPreviousEnabled(false);
-               this.wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
+               this.wizard.setNextName(I18n.getMessage("jsite.general.cancel"));
                this.wizard.setQuitName(I18n.getMessage("jsite.wizard.quit"));
        }
 
@@ -211,7 +214,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
         * Starts the insert.
         */
        public void startInsert() {
-               wizard.setNextEnabled(false);
+               running = true;
                copyURIAction.setEnabled(false);
                progressBar.setValue(0);
                progressBar.setString(I18n.getMessage("jsite.insert.starting"));
@@ -220,6 +223,26 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
        }
 
        /**
+        * Stops the currently running insert.
+        */
+       public void stopInsert() {
+               if (running) {
+                       wizard.setNextEnabled(false);
+                       projectInserter.stop();
+               }
+       }
+
+       /**
+        * Returns whether the insert is currently running.
+        *
+        * @return {@code true} if the insert is currently running, {@code false}
+        *         otherwise
+        */
+       public boolean isRunning() {
+               return running;
+       }
+
+       /**
         * Sets the project to insert.
         *
         * @param project
@@ -356,9 +379,10 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
         * {@inheritDoc}
         */
        public void projectInsertFinished(Project project, boolean success, Throwable cause) {
+               running = false;
                if (success) {
                        String copyURILabel = I18n.getMessage("jsite.insert.okay-copy-uri");
-                       int selectedValue = JOptionPane.showOptionDialog(this, I18n.getMessage("jsite.insert.inserted"), I18n.getMessage("jsite.insert.done.title"), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { I18n.getMessage("jsite.general.okay"), copyURILabel }, copyURILabel);
+                       int selectedValue = JOptionPane.showOptionDialog(this, I18n.getMessage("jsite.insert.inserted"), I18n.getMessage("jsite.insert.done.title"), 0, JOptionPane.INFORMATION_MESSAGE, null, new Object[] { I18n.getMessage("jsite.general.ok"), copyURILabel }, copyURILabel);
                        if (selectedValue == 1) {
                                actionCopyURI();
                        }
@@ -375,6 +399,7 @@ public class ProjectInsertPage extends TWizardPage implements InsertListener, Cl
                        public void run() {
                                progressBar.setValue(progressBar.getMaximum());
                                progressBar.setString(I18n.getMessage("jsite.insert.done") + " (" + getTransferRate() + " " + I18n.getMessage("jsite.insert.k-per-s") + ")");
+                               wizard.setNextName(I18n.getMessage("jsite.wizard.next"));
                                wizard.setNextEnabled(true);
                                wizard.setQuitEnabled(true);
                        }