From 3e04561f54baa53d5ca6cdc18b38e7f34dbe34e3 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 23 Apr 2018 20:11:24 +0400 Subject: [PATCH] Remove SWF upload component #444 --- .../client/upload/CubaUploadConnector.java | 67 -------------- .../client/upload/CubaUploadWidget.java | 32 ------- .../gui/components/WebFileUploadField.java | 92 +------------------ 3 files changed, 2 insertions(+), 189 deletions(-) delete mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadConnector.java delete mode 100644 modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadWidget.java diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadConnector.java b/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadConnector.java deleted file mode 100644 index 74943eacfe..0000000000 --- a/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadConnector.java +++ /dev/null @@ -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); - } - } - } -} \ No newline at end of file diff --git a/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadWidget.java b/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadWidget.java deleted file mode 100644 index 187be11f49..0000000000 --- a/modules/web-toolkit/src/com/haulmont/cuba/web/widgets/client/upload/CubaUploadWidget.java +++ /dev/null @@ -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"); - } - } -} \ No newline at end of file diff --git a/modules/web/src/com/haulmont/cuba/web/gui/components/WebFileUploadField.java b/modules/web/src/com/haulmont/cuba/web/gui/components/WebFileUploadField.java index 67063fccb2..5b4efbc06b 100644 --- a/modules/web/src/com/haulmont/cuba/web/gui/components/WebFileUploadField.java +++ b/modules/web/src/com/haulmont/cuba/web/gui/components/WebFileUploadField.java @@ -31,10 +31,7 @@ import com.haulmont.cuba.gui.export.FileDataProvider; import com.haulmont.cuba.gui.upload.FileUploadingAPI; import com.haulmont.cuba.web.gui.FileUploadTypesHelper; import com.haulmont.cuba.web.widgets.CubaFileUpload; -import com.haulmont.cuba.web.widgets.CubaUpload; 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.Component; import org.apache.commons.io.IOUtils; @@ -52,7 +49,7 @@ import static com.haulmont.cuba.gui.components.Frame.NotificationType; public class WebFileUploadField extends WebAbstractUploadField implements FileUploadField { - private final Logger log = LoggerFactory.getLogger(WebFileUploadField.class); + private static final Logger log = LoggerFactory.getLogger(WebFileUploadField.class); protected FileUploadingAPI fileUploading; protected ExportDisplay exportDisplay; @@ -81,12 +78,7 @@ public class WebFileUploadField extends WebAbstractUploadField { - 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() { uploadButton = createComponent(); CubaFileUpload impl = (CubaFileUpload) uploadButton; @@ -307,22 +235,6 @@ public class WebFileUploadField extends WebAbstractUploadField 0) { - String fileExtension = name.substring(name.lastIndexOf("."), name.length()); - return !getPermittedExtensions().contains(fileExtension.toLowerCase()); - } else { - return true; - } - } - return false; - } - @Override public String getFileName() { if (fileName == null) {