Implemented feature #22251 - Make workspace file size field smart

feature_23026
Francesco Mangiacrapa 2 years ago
parent 027c05eec8
commit 0e90e12b98

@ -6,13 +6,6 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
@ -40,5 +33,12 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

@ -1,18 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="workspace-tree-widget"> <wb-module deploy-name="workspace-tree-widget">
<wb-resource deploy-path="/" source-path="/src/main/java"/> <wb-resource deploy-path="/" source-path="/src/main/java"/>
<wb-resource deploy-path="/" source-path="/src/main/resources"/> <wb-resource deploy-path="/" source-path="/src/main/resources"/>
<wb-resource deploy-path="/" source-path="/target/generated-sources/annotations"/> <wb-resource deploy-path="/" source-path="/target/generated-sources/annotations"/>
</wb-module> </wb-module>
</project-modules> </project-modules>

@ -4,6 +4,11 @@
All notable changes to this project will be documented in this file. 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). 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 ## [v6.33.1] - 2021-06-11

@ -11,7 +11,7 @@
<groupId>org.gcube.portlets.user</groupId> <groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace-tree-widget</artifactId> <artifactId>workspace-tree-widget</artifactId>
<version>6.33.1</version> <version>6.34.0-SNAPSHOT</version>
<name>gCube Workspace Tree Widget</name> <name>gCube Workspace Tree Widget</name>
<description> <description>
gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace gCube Workspace Tree Widget is a widget to navigate and interact with gCube Workspace

@ -4,7 +4,6 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.google.gwt.core.client.GWT; 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.dom.client.Element;
//import com.google.gwt.user.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_HISTORY_OF = "Accounting history of: ";
public static final String ACCOUNTING_READERS_OF = "Accounting readers 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 //USED IN HTTP GET AS PARAMETER.. THIS PARAMS ARE REPLICATED IN THE CONSTANTS OF TREE WIDGET
public static final String GET_SEARCH_PARAMETER ="search"; public static final String GET_SEARCH_PARAMETER ="search";

@ -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];
}
}

@ -4,10 +4,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer; 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.FileGridModel;
import org.gcube.portlets.user.workspace.client.model.FileModel; 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.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.client.rpc.WorkspaceSharingServiceAsync;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel; 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.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler; 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.Command;
import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Image;
@ -60,7 +59,7 @@ public class DialogGetInfo extends Dialog {
// private TextArea textAreaSharedWith = new TextArea(); // private TextArea textAreaSharedWith = new TextArea();
private Html htmlUsersWidget = new Html(); private Html htmlUsersWidget = new Html();
private Html htmlPropertiesWidget = new Html(); private Html htmlPropertiesWidget = new Html();
private final NumberFormat number = ConstantsExplorer.numberFormatterKB; //private final NumberFormat number = ConstantsExplorer.numberFormatterKB;
// private TextField<String> txtGcubeItemProperties; // private TextField<String> txtGcubeItemProperties;
private HorizontalPanel hpGcubeProperties; private HorizontalPanel hpGcubeProperties;
private DialogEditProperties editProperties = null; private DialogEditProperties editProperties = null;
@ -448,10 +447,7 @@ public class DialogGetInfo extends Dialog {
private String getFormattedSize(long value) { private String getFormattedSize(long value) {
if (value > 0) { if (value > 0) {
double kb = value / 1024; return SizeUtil.readableFileSize(value);
if (kb < 1)
kb = 1;
return number.format(kb);
} else if (value == 0) { } else if (value == 0) {
return EMPTY; return EMPTY;
} else } else

@ -5,7 +5,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.gcube.portlets.user.workspace.client.AppControllerExplorer; 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.CreateSharedFolderEvent;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent; import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.DownloadType; 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.FileGridModel;
import org.gcube.portlets.user.workspace.client.model.FileModel; 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.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.GWTWorkspaceItem;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage; import org.gcube.portlets.user.workspace.client.workspace.folder.item.GWTExternalImage;
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTImageDocument; 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.event.dom.client.LoadHandler;
import com.google.gwt.http.client.URL; import com.google.gwt.http.client.URL;
import com.google.gwt.i18n.client.DateTimeFormat; 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.UiBinder;
import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Command; import com.google.gwt.user.client.Command;
@ -79,7 +78,7 @@ public class DialogGetInfoBootstrap extends Composite {
public static final String EMPTY = "empty"; 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. * Instantiates a new dialog get info bootstrap.
@ -468,6 +467,9 @@ public class DialogGetInfoBootstrap extends Composite {
addHandlers(); addHandlers();
} }
/**
* On detach.
*/
@Override @Override
protected void onDetach() { protected void onDetach() {
super.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) { public Frame instanceFrame(String fileURL, final HTML thePreviewPlaceholder) {
//addLoading(); //addLoading();
String urlEncoded = URL.encode(fileURL); String urlEncoded = URL.encode(fileURL);
@ -618,10 +627,7 @@ public class DialogGetInfoBootstrap extends Composite {
private String getFormattedSize(long value) { private String getFormattedSize(long value) {
if (value > 0) { if (value > 0) {
double kb = value / 1024; return SizeUtil.readableFileSize(value);
if (kb < 1)
kb = 1;
return number.format(kb);
} else if (value == 0) { } else if (value == 0) {
return EMPTY; return EMPTY;
} else } else
@ -894,6 +900,7 @@ public class DialogGetInfoBootstrap extends Composite {
* Sets the placeholder. * Sets the placeholder.
* *
* @param html the html * @param html the html
* @param spinner the spinner
* @param placeholder the placeholder * @param placeholder the placeholder
*/ */
private void setPlaceholder(HTML html, boolean spinner, String 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)/*-{ public static native String showPDFPreview(String pdfURL, String divId)/*-{
var theDivContainer = "#"+divId; var theDivContainer = "#"+divId;
$wnd.PDFObject.embed(pdfURL, theDivContainer); $wnd.PDFObject.embed(pdfURL, theDivContainer);

Loading…
Cancel
Save