import de.todesbaum.util.io.Closer;
import de.todesbaum.util.io.ReplacingOutputStream;
import de.todesbaum.util.io.StreamCopier;
+import de.todesbaum.util.io.StreamCopier.ProgressListener;
/**
* Manages project inserts.
/** Whether the insert is cancelled. */
private volatile boolean cancelled = false;
+ /** Progress listener for payload transfers. */
+ private ProgressListener progressListener;
+
/**
* Adds a listener to the list of registered listeners.
*
/**
* Starts the insert.
*/
- public void start() {
+ public void start(ProgressListener progressListener) {
cancelled = false;
+ this.progressListener = progressListener;
fileScanner = new FileScanner(project);
fileScanner.addFileScannerListener(this);
new Thread(fileScanner).start();
/* start request */
try {
- client.execute(putDir);
+ client.execute(putDir, progressListener);
+ fireProjectUploadFinished();
} catch (IOException ioe1) {
fireProjectInsertFinished(false, ioe1);
return;
/* parse progress and success messages */
String finalURI = null;
- boolean firstMessage = true;
boolean success = false;
boolean finished = false;
boolean disconnected = false;
while (!finished && !cancelled) {
Message message = client.readMessage();
finished = (message == null) || (disconnected = client.isDisconnected());
- if (firstMessage) {
- fireProjectUploadFinished();
- firstMessage = false;
- }
logger.log(Level.FINE, "Received message: " + message);
if (!finished) {
@SuppressWarnings("null")
import de.todesbaum.jsite.application.ProjectInserter;
import de.todesbaum.jsite.i18n.I18n;
import de.todesbaum.jsite.i18n.I18nContainer;
+import de.todesbaum.util.io.StreamCopier.ProgressListener;
import de.todesbaum.util.swing.TWizard;
import de.todesbaum.util.swing.TWizardPage;
progressBar.setValue(0);
progressBar.setString(I18n.getMessage("jsite.insert.starting"));
progressBar.setFont(progressBar.getFont().deriveFont(Font.PLAIN));
- projectInserter.start();
+ projectInserter.start(new ProgressListener() {
+
+ public void onProgress(final long copied, final long length) {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ int divisor = 1;
+ while (((copied / divisor) > Integer.MAX_VALUE) || ((length / divisor) > Integer.MAX_VALUE)) {
+ divisor *= 10;
+ }
+ progressBar.setMaximum((int) (length / divisor));
+ progressBar.setValue((int) (copied / divisor));
+ progressBar.setString("Uploaded: " + copied + " / " + length);
+ }
+ });
+ }
+ });
}
/**
*/
public void projectUploadFinished(Project project) {
startTime = System.currentTimeMillis();
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @SuppressWarnings("synthetic-access")
+ public void run() {
+ progressBar.setString(I18n.getMessage("jsite.insert.starting"));
+ progressBar.setValue(0);
+ }
+ });
}
/**
import de.todesbaum.jsite.application.Node;
import de.todesbaum.jsite.application.Project;
import de.todesbaum.jsite.application.ProjectInserter;
+import de.todesbaum.util.io.StreamCopier.ProgressListener;
/**
* Command-line interface for jSite.
return false;
}
projectInserter.setProject(currentProject);
- projectInserter.start();
+ projectInserter.start(new ProgressListener() {
+
+ public void onProgress(long copied, long length) {
+ System.out.print("Uploaded: " + copied + " / " + length + " bytes...\r");
+ }
+ });
synchronized (lockObject) {
while (!finished) {
try {