Pārlūkot izejas kodu

set/getProgressListener deprecated, replaced with remove/addListener(ProgressListener).

Fixes #1446.

svn changeset:4442/svn branch:trunk
tags/6.7.0.beta1
Marc Englund pirms 16 gadiem
vecāks
revīzija
226f902fbe

+ 16
- 0
src/com/itmill/toolkit/tests/TestForUpload.java Parādīt failu

@@ -53,6 +53,7 @@ public class TestForUpload extends CustomComponent implements
private final Label l;

private final ProgressIndicator pi = new ProgressIndicator();
private final ProgressIndicator pi2 = new ProgressIndicator();

private final Label memoryStatus;

@@ -91,6 +92,15 @@ public class TestForUpload extends CustomComponent implements
up.addListener((StartedListener) this);

up.setProgressListener(this);
up.addListener(new Upload.ProgressListener() {

public void updateProgress(long readBytes, long contentLenght) {
pi2.setValue(new Float(readBytes / (float) contentLenght));

refreshMemUsage();
}

});

final Button b = new Button("b", this, "readState");

@@ -120,6 +130,10 @@ public class TestForUpload extends CustomComponent implements
pi.setPollingInterval(1000);
main.addComponent(pi);

pi2.setVisible(false);
pi2.setPollingInterval(1000);
main.addComponent(pi2);

memoryStatus = new Label();
main.addComponent(memoryStatus);

@@ -326,6 +340,7 @@ public class TestForUpload extends CustomComponent implements

public void uploadSucceeded(SucceededEvent event) {
pi.setVisible(false);
pi2.setVisible(false);
l.setValue("Finished upload, idle");
System.out.println(event);
setBuffer();
@@ -351,6 +366,7 @@ public class TestForUpload extends CustomComponent implements

public void uploadStarted(StartedEvent event) {
pi.setVisible(true);
pi2.setVisible(true);
l.setValue("Started uploading file " + event.getFilename());
textFieldValue.setValue(" TestFields value at the upload start is:"
+ textField.getValue());

+ 57
- 4
src/com/itmill/toolkit/ui/Upload.java Parādīt failu

@@ -7,6 +7,8 @@ package com.itmill.toolkit.ui;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;

import com.itmill.toolkit.Application;
@@ -77,6 +79,7 @@ public class Upload extends AbstractComponent implements Component.Focusable {
* upload
*/
private ProgressListener progressListener;
private LinkedHashSet progressListeners;

/* TODO: Add a default constructor, receive to temp file. */

@@ -160,8 +163,7 @@ public class Upload extends AbstractComponent implements Component.Focusable {
// update progress if listener set and contentLength
// received
synchronized (application) {
progressListener.updateProgress(totalBytes,
contentLength);
fireUpdateProgress(totalBytes, contentLength);
}
}
}
@@ -710,6 +712,31 @@ public class Upload extends AbstractComponent implements Component.Focusable {
removeListener(SucceededEvent.class, listener, UPLOAD_SUCCEEDED_METHOD);
}

/**
* Adds the upload success event listener.
*
* @param listener
* the Listener to be added.
*/
public void addListener(ProgressListener listener) {
if (progressListeners == null) {
progressListeners = new LinkedHashSet();
}
progressListeners.add(listener);
}

/**
* Removes the upload success event listener.
*
* @param listener
* the Listener to be removed.
*/
public void removeListener(ProgressListener listener) {
if (progressListeners != null) {
progressListeners.remove(listener);
}
}

/**
* Emit upload received event.
*
@@ -775,6 +802,30 @@ public class Upload extends AbstractComponent implements Component.Focusable {
fireEvent(new Upload.SucceededEvent(this, filename, MIMEType, length));
}

/**
* Emits the progress event.
*
* @param totalBytes
* bytes received so far
* @param contentLength
* actual size of the file being uploaded, if known
*
*/
protected void fireUpdateProgress(long totalBytes, long contentLength) {
// this is implemented differently than other listeners to maintain
// backwards compatibility
if (progressListeners != null) {
for (Iterator it = progressListeners.iterator(); it.hasNext();) {
ProgressListener l = (ProgressListener) it.next();
l.updateProgress(totalBytes, contentLength);
}
}
// deprecated:
if (progressListener != null) {
progressListener.updateProgress(totalBytes, contentLength);
}
}

/**
* Returns the current receiver.
*
@@ -886,8 +937,9 @@ public class Upload extends AbstractComponent implements Component.Focusable {
}

/**
* Sets listener to track progress of upload.
* This method is deprecated, use addListener(ProgressListener) instead.
*
* @deprecated Use addListener(ProgressListener) instead.
* @param progressListener
*/
public void setProgressListener(ProgressListener progressListener) {
@@ -895,8 +947,9 @@ public class Upload extends AbstractComponent implements Component.Focusable {
}

/**
* Gets listener that tracks progress of upload.
* This method is deprecated.
*
* @deprecated Replaced with addListener/removeListener
* @return listener
*
*/

Notiek ielāde…
Atcelt
Saglabāt