Formatted

Signed-off-by: asharani-murugesh <asharani.murugesh@in.bosch.com>
This commit is contained in:
asharani-murugesh
2016-02-16 09:29:17 +01:00
parent d3035ccebe
commit 1252bfe53d

View File

@@ -119,7 +119,7 @@ public class UploadLayout extends VerticalLayout {
private DragAndDropWrapper dropAreaWrapper; private DragAndDropWrapper dropAreaWrapper;
private Boolean hasDirectory = Boolean.FALSE; private Boolean hasDirectory = Boolean.FALSE;
/** /**
* Initialize the upload layout. * Initialize the upload layout.
@@ -187,58 +187,60 @@ public class UploadLayout extends VerticalLayout {
@Override @Override
public void drop(final DragAndDropEvent event) { public void drop(final DragAndDropEvent event) {
if (validate()) { if (validate()) {
((WrapperTransferable) event.getTransferable()).getDraggedComponent(); ((WrapperTransferable) event.getTransferable()).getDraggedComponent();
final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles(); final Html5File[] files = ((WrapperTransferable) event.getTransferable()).getFiles();
if (files != null) { if (files != null) {
for (final Html5File file : files) { for (final Html5File file : files) {
if (!isDirectory(file)) { if (!isDirectory(file)) {
if (!checkForDuplicate(file.getFileName())) { if (!checkForDuplicate(file.getFileName())) {
numberOfFileUploadsExpected.incrementAndGet(); numberOfFileUploadsExpected.incrementAndGet();
file.setStreamVariable(createStreamVariable(file)); file.setStreamVariable(createStreamVariable(file));
hasDirectory = Boolean.FALSE; hasDirectory = Boolean.FALSE;
} }
} else { } else {
hasDirectory = Boolean.TRUE; hasDirectory = Boolean.TRUE;
} }
} }
if (numberOfFileUploadsExpected.get() > 0) { if (numberOfFileUploadsExpected.get() > 0) {
processBtn.setEnabled(false); processBtn.setEnabled(false);
// reset before we start // reset before we start
uploadInfoWindow.uploadSessionStarted(); uploadInfoWindow.uploadSessionStarted();
} else { } else {
//If the upload is not started, it signifies all dropped files as either duplicate or directory.So display message accordingly // If the upload is not started, it signifies all
displayCompositeMessage(); // dropped files as either duplicate or directory.So
} // display message accordingly
} displayCompositeMessage();
} }
}
}
} }
} }
private static boolean isDirectory(final Html5File file) { private static boolean isDirectory(final Html5File file) {
if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) { if (Strings.isNullOrEmpty(file.getType()) && file.getFileSize() % 4096 == 0) {
return true; return true;
} }
return false; return false;
} }
private void displayCompositeMessage() {
final String duplicateMessage = getDuplicateFileValidationMessage();
final StringBuilder compositeMessage = new StringBuilder();
if (!Strings.isNullOrEmpty(duplicateMessage)) {
compositeMessage.append(duplicateMessage);
}
if (hasDirectory) {
if (compositeMessage.length() > 0) {
compositeMessage.append("<br>");
}
compositeMessage.append(i18n.get("message.no.directory.upload"));
}
if (!compositeMessage.toString().isEmpty()) {
uiNotification.displayValidationError(compositeMessage.toString());
}
}
private void displayCompositeMessage() {
final String duplicateMessage = getDuplicateFileValidationMessage();
final StringBuilder compositeMessage = new StringBuilder();
if (!Strings.isNullOrEmpty(duplicateMessage)) {
compositeMessage.append(duplicateMessage);
}
if (hasDirectory) {
if (compositeMessage.length() > 0) {
compositeMessage.append("<br>");
}
compositeMessage.append(i18n.get("message.no.directory.upload"));
}
if (!compositeMessage.toString().isEmpty()) {
uiNotification.displayValidationError(compositeMessage.toString());
}
}
private VerticalLayout createDropAreaLayout() { private VerticalLayout createDropAreaLayout() {
dropAreaLayout = new VerticalLayout(); dropAreaLayout = new VerticalLayout();
final Label dropHereLabel = new Label("Drop files to upload"); final Label dropHereLabel = new Label("Drop files to upload");
@@ -421,27 +423,26 @@ public class UploadLayout extends VerticalLayout {
displayCompositeMessage(); displayCompositeMessage();
} }
} }
private String getDuplicateFileValidationMessage() { private String getDuplicateFileValidationMessage() {
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
if (!duplicateFileNamesList.isEmpty()) { if (!duplicateFileNamesList.isEmpty()) {
final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList); final String fileNames = StringUtils.collectionToCommaDelimitedString(duplicateFileNamesList);
if (duplicateFileNamesList.size() == 1) { if (duplicateFileNamesList.size() == 1) {
message.append(i18n.get("message.no.duplicateFile") + fileNames); message.append(i18n.get("message.no.duplicateFile") + fileNames);
} else if (duplicateFileNamesList.size() > 1) { } else if (duplicateFileNamesList.size() > 1) {
message.append(i18n.get("message.no.duplicateFiles")); message.append(i18n.get("message.no.duplicateFiles"));
} }
duplicateFileNamesList.clear(); duplicateFileNamesList.clear();
} }
return message.toString(); return message.toString();
} }
public void showDuplicateMessage() {
uiNotification.displayValidationError(getDuplicateFileValidationMessage());
}
public void showDuplicateMessage() {
uiNotification.displayValidationError(getDuplicateFileValidationMessage());
}
void increaseNumberOfFileUploadsExpected() { void increaseNumberOfFileUploadsExpected() {
numberOfFileUploadsExpected.incrementAndGet(); numberOfFileUploadsExpected.incrementAndGet();
} }