mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 19:57:36 +08:00
Remove SWF upload component #444
This commit is contained in:
parent
6b0eb39bce
commit
3e04561f54
@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2008-2016 Haulmont.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.haulmont.cuba.web.widgets.client.upload;
|
|
||||||
|
|
||||||
import com.haulmont.cuba.web.widgets.CubaUpload;
|
|
||||||
import com.vaadin.client.communication.StateChangeEvent;
|
|
||||||
import com.vaadin.client.ui.Icon;
|
|
||||||
import com.vaadin.client.ui.upload.UploadConnector;
|
|
||||||
import com.vaadin.shared.ui.Connect;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
@Connect(CubaUpload.class)
|
|
||||||
public class CubaUploadConnector extends UploadConnector {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CubaUploadState getState() {
|
|
||||||
return (CubaUploadState) super.getState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CubaUploadWidget getWidget() {
|
|
||||||
return (CubaUploadWidget) super.getWidget();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean delegateCaptionHandling() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStateChanged(StateChangeEvent stateChangeEvent) {
|
|
||||||
super.onStateChanged(stateChangeEvent);
|
|
||||||
|
|
||||||
if (stateChangeEvent.hasPropertyChanged("accept")) {
|
|
||||||
getWidget().setAccept(getState().accept);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stateChangeEvent.hasPropertyChanged("resources")) {
|
|
||||||
if (getWidget().submitButton.icon != null) {
|
|
||||||
getWidget().submitButton.wrapper.removeChild(getWidget().submitButton.icon.getElement());
|
|
||||||
getWidget().submitButton.icon = null;
|
|
||||||
}
|
|
||||||
Icon icon = getIcon();
|
|
||||||
if (icon != null) {
|
|
||||||
getWidget().submitButton.icon = icon;
|
|
||||||
|
|
||||||
getWidget().submitButton.wrapper.insertBefore(icon.getElement(),
|
|
||||||
getWidget().submitButton.captionElement);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2008-2016 Haulmont.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.haulmont.cuba.web.widgets.client.upload;
|
|
||||||
|
|
||||||
import com.vaadin.client.ui.VUpload;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class CubaUploadWidget extends VUpload {
|
|
||||||
|
|
||||||
public void setAccept(String accept) {
|
|
||||||
if (accept != null) {
|
|
||||||
fu.getElement().setAttribute("accept", accept);
|
|
||||||
} else {
|
|
||||||
fu.getElement().removeAttribute("accept");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -31,10 +31,7 @@ import com.haulmont.cuba.gui.export.FileDataProvider;
|
|||||||
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
|
import com.haulmont.cuba.gui.upload.FileUploadingAPI;
|
||||||
import com.haulmont.cuba.web.gui.FileUploadTypesHelper;
|
import com.haulmont.cuba.web.gui.FileUploadTypesHelper;
|
||||||
import com.haulmont.cuba.web.widgets.CubaFileUpload;
|
import com.haulmont.cuba.web.widgets.CubaFileUpload;
|
||||||
import com.haulmont.cuba.web.widgets.CubaUpload;
|
|
||||||
import com.haulmont.cuba.web.widgets.UploadComponent;
|
import com.haulmont.cuba.web.widgets.UploadComponent;
|
||||||
import com.vaadin.server.Page;
|
|
||||||
import com.vaadin.server.WebBrowser;
|
|
||||||
import com.vaadin.ui.Button;
|
import com.vaadin.ui.Button;
|
||||||
import com.vaadin.ui.Component;
|
import com.vaadin.ui.Component;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -52,7 +49,7 @@ import static com.haulmont.cuba.gui.components.Frame.NotificationType;
|
|||||||
|
|
||||||
public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWrapper> implements FileUploadField {
|
public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWrapper> implements FileUploadField {
|
||||||
|
|
||||||
private final Logger log = LoggerFactory.getLogger(WebFileUploadField.class);
|
private static final Logger log = LoggerFactory.getLogger(WebFileUploadField.class);
|
||||||
|
|
||||||
protected FileUploadingAPI fileUploading;
|
protected FileUploadingAPI fileUploading;
|
||||||
protected ExportDisplay exportDisplay;
|
protected ExportDisplay exportDisplay;
|
||||||
@ -81,12 +78,7 @@ public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWra
|
|||||||
exportDisplay = AppBeans.get(ExportDisplay.NAME);
|
exportDisplay = AppBeans.get(ExportDisplay.NAME);
|
||||||
messages = AppBeans.get(Messages.NAME);
|
messages = AppBeans.get(Messages.NAME);
|
||||||
|
|
||||||
WebBrowser webBrowser = Page.getCurrent().getWebBrowser();
|
initUploadButton();
|
||||||
if ((webBrowser.isIE() && !webBrowser.isEdge()) && webBrowser.getBrowserMajorVersion() < 10) {
|
|
||||||
initOldUploadButton();
|
|
||||||
} else {
|
|
||||||
initUploadButton();
|
|
||||||
}
|
|
||||||
|
|
||||||
initComponent();
|
initComponent();
|
||||||
attachListener(component);
|
attachListener(component);
|
||||||
@ -173,70 +165,6 @@ public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWra
|
|||||||
return AppBeans.get(DataManager.class).commit(fileDescriptor);
|
return AppBeans.get(DataManager.class).commit(fileDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initOldUploadButton() {
|
|
||||||
uploadButton = createOldComponent();
|
|
||||||
final CubaUpload impl = (CubaUpload) uploadButton;
|
|
||||||
|
|
||||||
impl.setButtonCaption(messages.getMainMessage("upload.submit"));
|
|
||||||
impl.setDescription(null);
|
|
||||||
|
|
||||||
impl.setReceiver((fileName1, MIMEType) -> {
|
|
||||||
FileOutputStream outputStream;
|
|
||||||
try {
|
|
||||||
tempFileId = fileUploading.createEmptyFile();
|
|
||||||
File tmpFile = fileUploading.getFile(tempFileId);
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
outputStream = new FileOutputStream(tmpFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Unable to receive file", e);
|
|
||||||
}
|
|
||||||
return outputStream;
|
|
||||||
});
|
|
||||||
|
|
||||||
impl.addStartedListener(event -> {
|
|
||||||
if (event.getContentLength() > getActualFileSizeLimit()) {
|
|
||||||
impl.interruptUpload();
|
|
||||||
String warningMsg = messages.formatMainMessage("upload.fileTooBig.message", event.getFilename(), getFileSizeLimitString());
|
|
||||||
|
|
||||||
getFrame().showNotification(warningMsg, NotificationType.WARNING);
|
|
||||||
} else if (hasInvalidExtensionOld(event.getFilename())) {
|
|
||||||
impl.interruptUpload();
|
|
||||||
String warningMsg = messages.formatMainMessage("upload.fileIncorrectExtension.message", event.getFilename());
|
|
||||||
getFrame().showNotification(warningMsg, NotificationType.WARNING);
|
|
||||||
} else {
|
|
||||||
fireFileUploadStart(event.getFilename(), event.getContentLength());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
impl.addFinishedListener(event -> fireFileUploadFinish(event.getFilename(), event.getLength()));
|
|
||||||
|
|
||||||
impl.addSucceededListener(event -> {
|
|
||||||
fileName = event.getFilename();
|
|
||||||
fileId = tempFileId;
|
|
||||||
|
|
||||||
saveFile(getFileDescriptor());
|
|
||||||
component.setFileNameButtonCaption(fileName);
|
|
||||||
|
|
||||||
fireFileUploadSucceed(event.getFilename(), event.getLength());
|
|
||||||
});
|
|
||||||
|
|
||||||
impl.addFailedListener(event -> {
|
|
||||||
try {
|
|
||||||
fileUploading.deleteFile(tempFileId);
|
|
||||||
tempFileId = null;
|
|
||||||
} catch (Exception e) {
|
|
||||||
if (e instanceof FileStorageException) {
|
|
||||||
FileStorageException fse = (FileStorageException) e;
|
|
||||||
if (fse.getType() != FileStorageException.Type.FILE_NOT_FOUND)
|
|
||||||
log.warn(String.format("Could not remove temp file %s after broken uploading", tempFileId));
|
|
||||||
}
|
|
||||||
log.warn(String.format("Error while delete temp file %s", tempFileId));
|
|
||||||
}
|
|
||||||
|
|
||||||
fireFileUploadError(event.getFilename(), event.getLength(), event.getReason());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initUploadButton() {
|
protected void initUploadButton() {
|
||||||
uploadButton = createComponent();
|
uploadButton = createComponent();
|
||||||
CubaFileUpload impl = (CubaFileUpload) uploadButton;
|
CubaFileUpload impl = (CubaFileUpload) uploadButton;
|
||||||
@ -307,22 +235,6 @@ public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWra
|
|||||||
return new CubaFileUpload();
|
return new CubaFileUpload();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CubaUpload createOldComponent() {
|
|
||||||
return new CubaUpload();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean hasInvalidExtensionOld(String name) {
|
|
||||||
if (getPermittedExtensions() != null && !getPermittedExtensions().isEmpty()) {
|
|
||||||
if (name.lastIndexOf(".") > 0) {
|
|
||||||
String fileExtension = name.substring(name.lastIndexOf("."), name.length());
|
|
||||||
return !getPermittedExtensions().contains(fileExtension.toLowerCase());
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user