mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-03 03:38:33 +08:00
PL-7421 Extract duplicated code from FileMultiUploadFieldLoader and FileUploadFieldLoader
This commit is contained in:
parent
b37f256a99
commit
632d7caf0d
@ -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<T extends UploadField> extends AbstractComponentLoader<T> {
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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<FileMultiUploadField> {
|
||||
public class FileMultiUploadFieldLoader extends AbstractUploadFieldLoader<FileMultiUploadField> {
|
||||
@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));
|
||||
}
|
||||
}
|
||||
}
|
@ -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<FileUploadField> {
|
||||
public class FileUploadFieldLoader extends AbstractUploadFieldLoader<FileUploadField> {
|
||||
@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));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user