|
|
|
|
|
Re: how to capture content in ImageField using uploadEnabled [message #1826213 is a reply to message #1826150] |
Tue, 21 April 2020 05:01   |
Eclipse User |
|
|
|
You're right, there's something else required to make your case work. You must configure the drop-type property, since when upload is enabled, we re-use the existing exec* methods for drag&drop support. Below is a complete, working example. In your project you should also deal with the TODO I added in the code below. When someone uploads a 5 MB PNG, you don't want to show _that_ file as preview image in the browser. Instead you should check supported file-types, scale the image down to a thumbnail version, output the new image in a format of your choice (like JPEG) and set the new image with setImage(), instead the originally uploaded image. Of course you must also store the original image somewhere. However, all this is part of your application and not covered by the ImageField.
@Order(10)
@ClassId("40c78cb8-034c-46b5-a6fc-a60f973e0033")
public class DefaultField extends AbstractImageField {
@Override
protected boolean getConfiguredLabelVisible() {
return false;
}
@Override
protected int getConfiguredGridH() {
return 5;
}
@Override
protected boolean getConfiguredAutoFit() {
return true;
}
protected int getConfiguredDropType() {
return IDNDSupport.TYPE_FILE_TRANSFER;
}
@Override
protected void execDropRequest(TransferObject transObj) {
if (transObj instanceof ResourceListTransferObject) {
List<BinaryResource> resources = ((ResourceListTransferObject) transObj).getResources();
if (resources.size() == 1) {
// TODO: create a thumbnail image with the framework of your choice, for instance JAI
setImage(resources.get(0));
}
}
}
@Override
protected String getConfiguredImageId() {
return Icons.Alarmclock;
}
@Override
protected boolean getConfiguredUploadEnabled() {
return true;
}
@Override
protected void execInitField() {
addPropertyChangeListener(PROP_IMAGE, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
System.out.println("New image is " + getImage());
}
});
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.04445 seconds