From 632d7caf0d24fac0413c0915f06403d0a39196b3 Mon Sep 17 00:00:00 2001 From: Yuriy Artamonov Date: Mon, 27 Jun 2016 19:27:12 +0400 Subject: [PATCH] PL-7421 Extract duplicated code from FileMultiUploadFieldLoader and FileUploadFieldLoader --- .../loaders/AbstractUploadFieldLoader.java | 87 +++++++++++++++++++ .../loaders/FileMultiUploadFieldLoader.java | 67 +------------- .../layout/loaders/FileUploadFieldLoader.java | 68 +-------------- 3 files changed, 90 insertions(+), 132 deletions(-) create mode 100644 modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractUploadFieldLoader.java diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractUploadFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractUploadFieldLoader.java new file mode 100644 index 0000000000..7d7ecbb2fa --- /dev/null +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/AbstractUploadFieldLoader.java @@ -0,0 +1,87 @@ +/* + * 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.gui.xml.layout.loaders; + +import com.haulmont.cuba.gui.components.BoxLayout; +import com.haulmont.cuba.gui.components.Component; +import com.haulmont.cuba.gui.components.UploadField; +import org.apache.commons.lang.StringUtils; +import org.dom4j.Element; + +import java.util.Arrays; +import java.util.HashSet; + +public abstract class AbstractUploadFieldLoader extends AbstractComponentLoader { + + @Override + public void loadComponent() { + assignFrame(resultComponent); + + loadEnable(resultComponent, element); + loadVisible(resultComponent, element); + + loadStyleName(resultComponent, element); + loadAlign(resultComponent, element); + + loadHeight(resultComponent, element); + loadWidth(resultComponent, element); + loadIcon(resultComponent, element); + + loadCaption(resultComponent, element); + loadDescription(resultComponent, element); + + loadAccept(resultComponent, element); + + loadPermittedExtensions(resultComponent, element); + + loadDropZone(resultComponent, element); + + String fileSizeLimit = element.attributeValue("fileSizeLimit"); + if (StringUtils.isNotEmpty(fileSizeLimit)) { + resultComponent.setFileSizeLimit(Long.valueOf(fileSizeLimit)); + } + } + + protected void loadAccept(UploadField uploadField, Element element) { + String accept = element.attributeValue("accept"); + if (StringUtils.isNotEmpty(accept)) { + uploadField.setAccept(accept); + } + } + + protected void loadPermittedExtensions(UploadField uploadField, Element element) { + String permittedExtensions = element.attributeValue("permittedExtensions"); + if (StringUtils.isNotEmpty(permittedExtensions)) { + uploadField.setPermittedExtensions(new HashSet<>(Arrays.asList(permittedExtensions.split("\\s*,\\s*")))); + } + } + + protected void loadDropZone(UploadField uploadField, Element element) { + String dropZoneId = element.attributeValue("dropZone"); + if (StringUtils.isNotEmpty(dropZoneId)) { + Component dropZone = context.getFrame().getComponent(dropZoneId); + if (dropZone instanceof BoxLayout) { + uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone)); + } + } + + String dropZonePrompt = element.attributeValue("dropZonePrompt"); + if (StringUtils.isNotEmpty(dropZonePrompt)) { + uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt)); + } + } +} \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileMultiUploadFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileMultiUploadFieldLoader.java index 86da31ef8f..a1354a169e 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileMultiUploadFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileMultiUploadFieldLoader.java @@ -16,75 +16,12 @@ */ package com.haulmont.cuba.gui.xml.layout.loaders; -import com.haulmont.cuba.gui.components.*; -import org.apache.commons.lang.StringUtils; -import org.dom4j.Element; +import com.haulmont.cuba.gui.components.FileMultiUploadField; -import java.util.Arrays; -import java.util.HashSet; - -public class FileMultiUploadFieldLoader extends AbstractComponentLoader { +public class FileMultiUploadFieldLoader extends AbstractUploadFieldLoader { @Override public void createComponent() { resultComponent = (FileMultiUploadField) factory.createComponent(FileMultiUploadField.NAME); loadId(resultComponent, element); } - - @Override - public void loadComponent() { - assignFrame(resultComponent); - - loadEnable(resultComponent, element); - loadVisible(resultComponent, element); - - loadStyleName(resultComponent, element); - loadAlign(resultComponent, element); - - loadHeight(resultComponent, element); - loadWidth(resultComponent, element); - loadIcon(resultComponent, element); - - loadCaption(resultComponent, element); - loadDescription(resultComponent, element); - - loadAccept(resultComponent, element); - - loadPermittedExtensions(resultComponent, element); - - loadDropZone(resultComponent, element); - - String fileSizeLimit = element.attributeValue("fileSizeLimit"); - if (StringUtils.isNotEmpty(fileSizeLimit)) { - resultComponent.setFileSizeLimit(Long.valueOf(fileSizeLimit)); - } - } - - protected void loadAccept(FileMultiUploadField uploadField, Element element) { - String accept = element.attributeValue("accept"); - if (StringUtils.isNotEmpty(accept)) { - uploadField.setAccept(accept); - } - } - - protected void loadPermittedExtensions(FileMultiUploadField uploadField, Element element) { - String permittedExtensions = element.attributeValue("permittedExtensions"); - if (StringUtils.isNotEmpty(permittedExtensions)) { - uploadField.setPermittedExtensions(new HashSet<>(Arrays.asList(permittedExtensions.split("\\s*,\\s*")))); - } - } - - protected void loadDropZone(FileMultiUploadField uploadField, Element element) { - String dropZoneId = element.attributeValue("dropZone"); - if (StringUtils.isNotEmpty(dropZoneId)) { - Component dropZone = context.getFrame().getComponent(dropZoneId); - if (dropZone instanceof BoxLayout) { - uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone)); - } - } - - String dropZonePrompt = element.attributeValue("dropZonePrompt"); - if (StringUtils.isNotEmpty(dropZonePrompt)) { - uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt)); - } - } } \ No newline at end of file diff --git a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileUploadFieldLoader.java b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileUploadFieldLoader.java index 4628bee394..40c36240d7 100644 --- a/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileUploadFieldLoader.java +++ b/modules/gui/src/com/haulmont/cuba/gui/xml/layout/loaders/FileUploadFieldLoader.java @@ -16,78 +16,12 @@ */ package com.haulmont.cuba.gui.xml.layout.loaders; -import com.haulmont.cuba.gui.components.BoxLayout; -import com.haulmont.cuba.gui.components.Component; import com.haulmont.cuba.gui.components.FileUploadField; -import com.haulmont.cuba.gui.components.UploadField; -import org.apache.commons.lang.StringUtils; -import org.dom4j.Element; -import java.util.Arrays; -import java.util.HashSet; - -public class FileUploadFieldLoader extends AbstractComponentLoader { +public class FileUploadFieldLoader extends AbstractUploadFieldLoader { @Override public void createComponent() { resultComponent = (FileUploadField) factory.createComponent(FileUploadField.NAME); loadId(resultComponent, element); } - - @Override - public void loadComponent() { - assignFrame(resultComponent); - - loadEnable(resultComponent, element); - loadVisible(resultComponent, element); - - loadStyleName(resultComponent, element); - loadAlign(resultComponent, element); - - loadHeight(resultComponent, element); - loadWidth(resultComponent, element); - loadIcon(resultComponent, element); - - loadCaption(resultComponent, element); - loadDescription(resultComponent, element); - - loadAccept(resultComponent, element); - - loadPermittedExtensions(resultComponent, element); - - loadDropZone(resultComponent, element); - - String fileSizeLimit = element.attributeValue("fileSizeLimit"); - if (StringUtils.isNotEmpty(fileSizeLimit)) { - resultComponent.setFileSizeLimit(Long.valueOf(fileSizeLimit)); - } - } - - protected void loadAccept(FileUploadField uploadField, Element element) { - String accept = element.attributeValue("accept"); - if (StringUtils.isNotEmpty(accept)) { - uploadField.setAccept(accept); - } - } - - protected void loadPermittedExtensions(FileUploadField uploadField, Element element) { - String permittedExtensions = element.attributeValue("permittedExtensions"); - if (StringUtils.isNotEmpty(permittedExtensions)) { - uploadField.setPermittedExtensions(new HashSet<>(Arrays.asList(permittedExtensions.split("\\s*,\\s*")))); - } - } - - protected void loadDropZone(FileUploadField uploadField, Element element) { - String dropZoneId = element.attributeValue("dropZone"); - if (StringUtils.isNotEmpty(dropZoneId)) { - Component dropZone = context.getFrame().getComponent(dropZoneId); - if (dropZone instanceof BoxLayout) { - uploadField.setDropZone(new UploadField.DropZone((BoxLayout) dropZone)); - } - } - - String dropZonePrompt = element.attributeValue("dropZonePrompt"); - if (StringUtils.isNotEmpty(dropZonePrompt)) { - uploadField.setDropZonePrompt(loadResourceString(dropZonePrompt)); - } - } } \ No newline at end of file