PL-8909 Add support for UploadField inside DataGrid editor

This commit is contained in:
Gleb Gorelov 2017-04-18 18:22:44 +04:00
parent 30caa625cc
commit 63a84c8bd5
5 changed files with 146 additions and 4 deletions

View File

@ -775,4 +775,31 @@ public class DesktopFileUploadField extends DesktopAbstractUploadField<CubaFileU
afterValueClearListeners.remove(listener);
}
}
@Override
public void commit() {
// do nothing
}
@Override
public void discard() {
// do nothing
}
@Override
public boolean isBuffered() {
// do nothing
return false;
}
@Override
public void setBuffered(boolean buffered) {
// do nothing
}
@Override
public boolean isModified() {
// do nothing
return false;
}
}

View File

@ -28,6 +28,7 @@ import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesMetaPropert
import com.haulmont.cuba.core.app.dynamicattributes.DynamicAttributesUtils;
import com.haulmont.cuba.core.app.dynamicattributes.PropertyType;
import com.haulmont.cuba.core.entity.CategoryAttribute;
import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.core.global.AppBeans;
import com.haulmont.cuba.core.global.Messages;
import com.haulmont.cuba.core.global.MetadataTools;
@ -94,6 +95,9 @@ public class DataGridEditorFieldFactoryImpl implements DataGridEditorFieldFactor
} else if (mppRange.isClass()) {
MetaProperty metaProperty = mpp.getMetaProperty();
Class<?> javaType = metaProperty.getJavaType();
if (FileDescriptor.class.isAssignableFrom(javaType)) {
return createFileUploadField(datasource, property);
}
if (!Collection.class.isAssignableFrom(javaType)) {
return createEntityField(datasource, property, mpp);
}
@ -114,6 +118,25 @@ public class DataGridEditorFieldFactoryImpl implements DataGridEditorFieldFactor
throw new UnsupportedOperationException(exceptionMessage);
}
protected Field createFileUploadField(Datasource datasource, String property) {
FileUploadField fileUploadField = (FileUploadField) componentsFactory.createComponent(FileUploadField.NAME);
fileUploadField.setMode(FileUploadField.FileStoragePutMode.IMMEDIATE);
fileUploadField.setUploadButtonCaption(null);
fileUploadField.setUploadButtonDescription(messages.getMainMessage("upload.submit"));
fileUploadField.setUploadButtonIcon("icons/upload.png");
fileUploadField.setClearButtonCaption(null);
fileUploadField.setClearButtonDescription(messages.getMainMessage("upload.clear"));
fileUploadField.setClearButtonIcon("icons/remove.png");
fileUploadField.setShowFileName(true);
fileUploadField.setShowClearButton(true);
fileUploadField.setDatasource(datasource, property);
return fileUploadField;
}
protected Field createUuidField(Datasource datasource, String property) {
MaskedField maskedField = componentsFactory.createComponent(MaskedField.class);
maskedField.setDatasource(datasource, property);

View File

@ -22,7 +22,7 @@ import javax.annotation.Nullable;
import java.io.InputStream;
import java.util.UUID;
public interface FileUploadField extends UploadField, Field, Component.Focusable {
public interface FileUploadField extends UploadField, Field, Component.Focusable, Component.Buffered {
String NAME = "upload";
/**

View File

@ -680,4 +680,29 @@ public class WebFileUploadField extends WebAbstractUploadField<CubaFileUploadWra
public void setTabIndex(int tabIndex) {
component.setTabIndex(tabIndex);
}
@Override
public void commit() {
super.commit();
}
@Override
public void discard() {
super.discard();
}
@Override
public boolean isBuffered() {
return super.isBuffered();
}
@Override
public void setBuffered(boolean buffered) {
super.setBuffered(buffered);
}
@Override
public boolean isModified() {
return super.isModified();
}
}

View File

@ -105,6 +105,9 @@
.#{$primary-stylename}-editor-cells > div {
.c-maskedfield,
.c-maskedfield-focus,
.c-fileupload .v-button,
.c-fileupload-clear.v-button,
.v-button.c-pickerfield-button,
.v-textfield.c-pickerfield-text:focus {
border: none;
border-radius: 0;
@ -117,12 +120,76 @@
}
.v-button.c-pickerfield-button {
border: none;
border-left: valo-border($color: $v-textfield-background-color, $border: $v-textfield-border, $strength: 0.5);
background: transparent;
@include box-shadow(none);
}
.v-filterselect-button:active:after,
.c-datefield [class*="button"]:active:after,
.c-pickerfield-layout>.v-button:last-child {
border-radius: 0;
}
.c-fileupload-container {
.v-spacing {
display: none;
}
.c-fileupload .v-button,
.c-fileupload-clear.v-button {
border-left: valo-border($color: $v-textfield-background-color, $border: $v-textfield-border, $strength: 0.5);
color: mix($v-textfield-background-color, valo-font-color($v-textfield-background-color));
&:hover {
color: valo-font-color($background-color);
}
&:after,
&:hover:after {
background: transparent;
}
&:focus:after {
border-color: transparent;
@include box-shadow(none);
}
&:active:after,
&:active:hover:after {
@if type-of($v-textfield-background-color) == color {
@include valo-button-active-style($v-textfield-background-color);
}
top: 0;
right: 0;
bottom: 0;
left: 0;
}
}
.c-fileupload .v-button-focus {
&:after {
border-color: transparent;
@include box-shadow(none);
}
}
.c-fileupload {
&:hover .v-button {
color: valo-font-color($background-color);
}
&:active,
&:active:hover {
.v-button:after {
@if type-of($v-textfield-background-color) == color {
@include valo-button-active-style($v-textfield-background-color);
}
}
}
}
}
.c-datefield [class*="button"] {
border: none;
border-right: valo-border($color: $v-textfield-background-color, $border: $v-textfield-border, $strength: 0.5);