diff --git a/.classpath b/.classpath index 3ccf7fb..2e1f66e 100644 --- a/.classpath +++ b/.classpath @@ -6,13 +6,6 @@ - - - - - - - @@ -40,5 +33,12 @@ + + + + + + + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 05307a1..bb0a1c9 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -1,18 +1,42 @@ - + + + + + - + + + + + - + + + + + - + + + + + - + + + + + - + + + + + diff --git a/CHANGELOG.md b/CHANGELOG.md index df96093..ba48482 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v6.34.0-SNAPSHOT] - 2021-11-05 + +#### Enhancements + +* [#22251] Make workspace file size field smart ## [v6.33.1] - 2021-06-11 diff --git a/pom.xml b/pom.xml index 7c7d6ff..4f89557 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ org.gcube.portlets.user workspace-tree-widget - 6.33.1 + 6.34.0-SNAPSHOT gCube Workspace Tree Widget gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index 5dee0b2..f3a078f 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.Map; import com.google.gwt.core.client.GWT; -import com.google.gwt.i18n.client.NumberFormat; //import com.google.gwt.dom.client.Element; //import com.google.gwt.user.client.Element; @@ -217,7 +216,7 @@ public static enum WS_UPLOAD_TYPE {File, Archive}; public static final String ACCOUNTING_HISTORY_OF = "Accounting history of: "; public static final String ACCOUNTING_READERS_OF = "Accounting readers of: "; - public static final NumberFormat numberFormatterKB = NumberFormat.getFormat("#,##0 KB;(#,##0 KB)"); + //public static final NumberFormat numberFormatterKB = NumberFormat.getFormat("#,##0 KB;(#,##0 KB)"); //USED IN HTTP GET AS PARAMETER.. THIS PARAMS ARE REPLICATED IN THE CONSTANTS OF TREE WIDGET public static final String GET_SEARCH_PARAMETER ="search"; diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/util/SizeUtil.java b/src/main/java/org/gcube/portlets/user/workspace/client/util/SizeUtil.java new file mode 100644 index 0000000..053df0f --- /dev/null +++ b/src/main/java/org/gcube/portlets/user/workspace/client/util/SizeUtil.java @@ -0,0 +1,42 @@ +package org.gcube.portlets.user.workspace.client.util; + +import com.google.gwt.core.client.GWT; +import com.google.gwt.i18n.client.NumberFormat; + +/** + * The Class SizeUtil. + * + * @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it + * + * Nov 5, 2021 + */ +public class SizeUtil { + + public static final NumberFormat numberFormat = NumberFormat.getFormat("#,##0.#"); + + /** + * Readable file size. + * + * @param size the size + * @return the string + */ + public static String readableFileSize(long size) { + GWT.log("Converting size: "+size); + // -1 should be the size of a folder + if (size == -1) + return ""; + // in some cases the size returned by SHUB is negative, + // so reporting as 1B to user + if (size < 0) + return "1 byte"; + + if (size == 0) + return "0 byte"; + + final String[] units = new String[] { "bytes", "kB", "MB", "GB", "TB" }; + int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); + + return numberFormat.format(size / Math.pow(1024, digitGroups)) +" " +units[digitGroups]; + + } +} diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java index d943cb3..50841d4 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfo.java @@ -4,10 +4,10 @@ import java.util.Date; import java.util.List; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; -import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.model.FileGridModel; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.resources.Resources; +import org.gcube.portlets.user.workspace.client.util.SizeUtil; import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync; import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; @@ -26,7 +26,6 @@ import com.extjs.gxt.ui.client.widget.layout.FormLayout; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.user.client.Command; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Image; @@ -60,7 +59,7 @@ public class DialogGetInfo extends Dialog { // private TextArea textAreaSharedWith = new TextArea(); private Html htmlUsersWidget = new Html(); private Html htmlPropertiesWidget = new Html(); - private final NumberFormat number = ConstantsExplorer.numberFormatterKB; + //private final NumberFormat number = ConstantsExplorer.numberFormatterKB; // private TextField txtGcubeItemProperties; private HorizontalPanel hpGcubeProperties; private DialogEditProperties editProperties = null; @@ -448,10 +447,7 @@ public class DialogGetInfo extends Dialog { private String getFormattedSize(long value) { if (value > 0) { - double kb = value / 1024; - if (kb < 1) - kb = 1; - return number.format(kb); + return SizeUtil.readableFileSize(value); } else if (value == 0) { return EMPTY; } else diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.java b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.java index a454f6c..b6c1bd0 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/view/windows/DialogGetInfoBootstrap.java @@ -5,7 +5,6 @@ import java.util.List; import java.util.Map; import org.gcube.portlets.user.workspace.client.AppControllerExplorer; -import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.event.CreateSharedFolderEvent; import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent; import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.DownloadType; @@ -13,6 +12,7 @@ import org.gcube.portlets.user.workspace.client.interfaces.GXTFolderItemTypeEnum import org.gcube.portlets.user.workspace.client.model.FileGridModel; import org.gcube.portlets.user.workspace.client.model.FileModel; import org.gcube.portlets.user.workspace.client.resources.Resources; +import org.gcube.portlets.user.workspace.client.util.SizeUtil; import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem; import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage; import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument; @@ -37,7 +37,6 @@ import com.google.gwt.event.dom.client.LoadEvent; import com.google.gwt.event.dom.client.LoadHandler; import com.google.gwt.http.client.URL; import com.google.gwt.i18n.client.DateTimeFormat; -import com.google.gwt.i18n.client.NumberFormat; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.user.client.Command; @@ -79,7 +78,7 @@ public class DialogGetInfoBootstrap extends Composite { public static final String EMPTY = "empty"; - private final NumberFormat number = ConstantsExplorer.numberFormatterKB; + //private final NumberFormat number = ConstantsExplorer.numberFormatterKB; /** * Instantiates a new dialog get info bootstrap. @@ -468,6 +467,9 @@ public class DialogGetInfoBootstrap extends Composite { addHandlers(); } + /** + * On detach. + */ @Override protected void onDetach() { super.onDetach(); @@ -482,6 +484,13 @@ public class DialogGetInfoBootstrap extends Composite { } } + /** + * Instance frame. + * + * @param fileURL the file URL + * @param thePreviewPlaceholder the the preview placeholder + * @return the frame + */ public Frame instanceFrame(String fileURL, final HTML thePreviewPlaceholder) { //addLoading(); String urlEncoded = URL.encode(fileURL); @@ -618,10 +627,7 @@ public class DialogGetInfoBootstrap extends Composite { private String getFormattedSize(long value) { if (value > 0) { - double kb = value / 1024; - if (kb < 1) - kb = 1; - return number.format(kb); + return SizeUtil.readableFileSize(value); } else if (value == 0) { return EMPTY; } else @@ -894,6 +900,7 @@ public class DialogGetInfoBootstrap extends Composite { * Sets the placeholder. * * @param html the html + * @param spinner the spinner * @param placeholder the placeholder */ private void setPlaceholder(HTML html, boolean spinner, String placeholder) { @@ -916,6 +923,13 @@ public class DialogGetInfoBootstrap extends Composite { } + /** + * Show PDF preview. + * + * @param pdfURL the pdf URL + * @param divId the div id + * @return the string + */ public static native String showPDFPreview(String pdfURL, String divId)/*-{ var theDivContainer = "#"+divId; $wnd.PDFObject.embed(pdfURL, theDivContainer);