Feature #22251 implemented - Make workspace file size field smart

This commit is contained in:
Francesco Mangiacrapa 2021-11-05 12:06:46 +01:00
parent 778e0a807e
commit e1cda838c4
7 changed files with 246 additions and 223 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/workspace-6.27.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/workspace-6.28.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
@ -22,7 +22,7 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/workspace-6.27.1-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<classpathentry kind="src" output="target/workspace-6.28.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
@ -35,5 +35,5 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/workspace-6.27.1-SNAPSHOT/WEB-INF/classes"/>
<classpathentry kind="output" path="target/workspace-6.28.0-SNAPSHOT/WEB-INF/classes"/>
</classpath>

View File

@ -1,4 +1,4 @@
eclipse.preferences.version=1
lastWarOutDir=/home/francescomangiacrapa/git/workspace/target/workspace-6.27.1-SNAPSHOT
lastWarOutDir=/home/francescomangiacrapa/git/workspace/target/workspace-6.28.0-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -18,7 +18,9 @@
<wb-module deploy-name="workspace-6.27.1-SNAPSHOT">
<wb-module deploy-name="workspace-6.28.0-SNAPSHOT">
@ -58,6 +60,7 @@
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
@ -78,6 +81,7 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/target/generated-sources/gwt"/>
@ -97,20 +101,16 @@
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<dependent-module archiveName="workspace-explorer-2.2.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/workspace-explorer/workspace-explorer">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="catalogue-util-library-1.1.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/catalogue-util-library/catalogue-util-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="ws-task-executor-widget-1.0.0.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/ws-task-executor-widget-TRUNK/ws-task-executor-widget-TRUNK">
<dependent-module archiveName="workspace-tree-widget-6.34.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/WorkspaceTree/WorkspaceTree">
<dependency-type>uses</dependency-type>
</dependent-module>
@ -132,6 +132,7 @@
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
@ -152,6 +153,7 @@
<property name="context-root" value="workspace"/>
@ -172,6 +174,7 @@
</wb-module>
@ -192,4 +195,5 @@
</project-modules>

View File

@ -4,6 +4,12 @@
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.28.0-SNAPSHOT] - 2021-11-05
#### Enhancements
* [#22251] Make workspace file size field smart
## [v6.27.1] - 2021-06-22
[#21575] Including ws-tree bug fix

View File

@ -13,7 +13,7 @@
<groupId>org.gcube.portlets.user</groupId>
<artifactId>workspace</artifactId>
<packaging>war</packaging>
<version>6.27.1</version>
<version>6.28.0-SNAPSHOT</version>
<name>gCube Workspace Portlet</name>
<description>
gCube Workspace Portlet is a web-gui to manage the gCube workspace, a collaborative area where users can exchange and organize information objects (workspace items) according to their specific needs.

View File

@ -0,0 +1,42 @@
package org.gcube.portlets.user.workspace.client.view;
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];
}
}

View File

@ -5,7 +5,6 @@ import java.util.Arrays;
import java.util.List;
import org.gcube.portlets.user.workspace.client.AppController;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
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.ImagePreviewEvent;
@ -18,6 +17,7 @@ import org.gcube.portlets.user.workspace.client.gridevent.StoreGridChangedEvent;
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.GroupingStoreModel;
import org.gcube.portlets.user.workspace.client.view.SizeUtil;
import com.extjs.gxt.ui.client.Style.SelectionMode;
import com.extjs.gxt.ui.client.data.ModelData;
@ -50,10 +50,8 @@ import com.extjs.gxt.ui.client.widget.grid.filters.StringFilter;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.NumberFormat;
import com.google.gwt.user.client.Random;
/**
* The Class GxtGridFilterGroupPanel.
*
@ -63,13 +61,11 @@ import com.google.gwt.user.client.Random;
public class GxtGridFilterGroupPanel extends LayoutContainer {
private ContentPanel cp = new ContentPanel();
// private ListStore<FileModel> store = ListStoreModel.getInstance().getStore();
private GroupingStore<FileGridModel> store = GroupingStoreModel.getInstance().getStore();
private FileGridModel currentItemSelected = null;
private FileModel currentFolderView = null;
private GroupingView view = new GroupingView();
private boolean groupingEnabled = false;
private NumberFormat number = ConstantsExplorer.numberFormatterKB;
private final Grid<FileGridModel> grid;
private ColumnModel cm = null;
@ -87,15 +83,13 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
ColumnConfig type = new ColumnConfig(FileGridModel.TYPE, FileGridModel.TYPE, 60);
ColumnConfig lastUpdate = new ColumnConfig(FileGridModel.LASTMODIFIED, "Last Update", 90);
lastUpdate.setDateTimeFormat(DateTimeFormat.getFormat("dd MMM hh:mm aaa yyyy"));
ColumnConfig category = new ColumnConfig(FileModel.HUMAN_REDABLE_CATEGORY, FileModel.HUMAN_REDABLE_CATEGORY, 100);
ColumnConfig category = new ColumnConfig(FileModel.HUMAN_REDABLE_CATEGORY, FileModel.HUMAN_REDABLE_CATEGORY,
100);
ColumnConfig size = new ColumnConfig(FileGridModel.SIZE, FileGridModel.SIZE, 45);
ColumnConfig ownerFullName = new ColumnConfig(FileGridModel.OWNERFULLNAME, FileGridModel.OWNER, 90);
size.setEditor(new CellEditor(new NumberField()));
if (group)
cm = new ColumnModel(Arrays.asList(icon, name, ownerFullName, type, lastUpdate, size, category));
else
@ -122,30 +116,28 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
GridCellRenderer<FileGridModel> folderRender = new GridCellRenderer<FileGridModel>() {
@Override
public String render(FileGridModel model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<FileGridModel> store, Grid<FileGridModel> grid) {
public String render(FileGridModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<FileGridModel> store, Grid<FileGridModel> grid) {
String val = model.get(property);
if (val == null || val.isEmpty())
return "";
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' >" + val + "</span>";
return "<span qtitle='" + columnModel.getColumnById(property).getHeader() + "' qtip='" + val + "' >"
+ val + "</span>";
}
};
GridCellRenderer<FileGridModel> kbRender = new GridCellRenderer<FileGridModel>() {
@Override
public String render(FileGridModel model, String property, ColumnData config,
int rowIndex, int colIndex, ListStore<FileGridModel> store, Grid<FileGridModel> grid) {
public String render(FileGridModel model, String property, ColumnData config, int rowIndex, int colIndex,
ListStore<FileGridModel> store, Grid<FileGridModel> grid) {
long value = (Long) model.get(property);
//
if (value != -1) {
double kb = value/1024;
if(kb<1)
kb=1;
return "<span>" + number.format(kb) + "</span>";
String theSize = SizeUtil.readableFileSize(value);
return "<span>" + theSize + "</span>";
}
return "";
}
};
@ -153,8 +145,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
size.setRenderer(kbRender);
type.setRenderer(folderRender);
//setAlphanumericStoreSorter(grid);
GridFilters filters = new GridFilters();
filters.setLocal(true);
@ -195,8 +185,7 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
isMultiselection = true;
AppController.getEventBus().fireEvent(new GridElementSelectedEvent(target, isMultiselection));
}
else{
} else {
currentItemSelected = null;
AppController.getEventBus().fireEvent(new GridElementUnSelectedEvent());
}
@ -204,7 +193,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
}
});
grid.addListener(Events.RowDoubleClick, new Listener<BaseEvent>() {
@Override
@ -215,18 +203,17 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
if (fileModel != null)
fireEventByFileModelType(fileModel);
// if(fileModel.isDirectory())
// AppController.getEventBus().fireEvent(new DoubleClickElementSelectedEvent(fileModel));
// AppController.getEventBus().fireEvent(new
// DoubleClickElementSelectedEvent(fileModel));
}
});
grid.setContextMenu(null); // add context menu null - ignore browse event right click
grid.addListener(Events.OnContextMenu, new Listener<GridEvent<FileGridModel>>() {
@Override
public void handleEvent(GridEvent<FileGridModel> be)
{
public void handleEvent(GridEvent<FileGridModel> be) {
if (be.isRightClick()) {
@ -241,8 +228,10 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
for (FileGridModel fileGridModel : selection) {
selected.add(fileGridModel);
}
//List<FileGridModel> selectedItems = grid.getSelectionModel().getSelectedItems();
AppController.getEventBus().fireEvent(new OpenContextMenuTreeEvent(selected, be.getClientX(), be.getClientY()));
// List<FileGridModel> selectedItems =
// grid.getSelectionModel().getSelectedItems();
AppController.getEventBus()
.fireEvent(new OpenContextMenuTreeEvent(selected, be.getClientX(), be.getClientY()));
}
}
}
@ -297,7 +286,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
return;
}
switch (target.getGXTFolderItemType()) {
case EXTERNAL_IMAGE:
@ -311,7 +299,8 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
case URL_DOCUMENT:
case EXTERNAL_RESOURCE_LINK:
AppController.getEventBus().fireEvent(new FileDownloadEvent(target.getIdentifier(), target.getName(), DownloadType.SHOW, target.isDirectory() || target.isVreFolder(), null));
AppController.getEventBus().fireEvent(new FileDownloadEvent(target.getIdentifier(), target.getName(),
DownloadType.SHOW, target.isDirectory() || target.isVreFolder(), null));
break;
case EXTERNAL_URL:
AppController.getEventBus().fireEvent(new ShowUrlEvent(target));
@ -327,7 +316,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
}
/**
* Reset store.
*/
@ -335,7 +323,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
store.removeAll();
}
/**
* Update store.
*
@ -347,7 +334,8 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
resetStore();
if (result != null && result.size() > 0) {
for (FileGridModel file : result) {
//GWT.log("File: "+file.getName() + " has sync: "+file.getSynchedThreddsStatus());
// GWT.log("File: "+file.getName() + " has sync:
// "+file.getSynchedThreddsStatus());
file.setIcon();
}
store.add(result);
@ -356,7 +344,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
return false;
}
/**
* Adds the to store.
*
@ -427,16 +414,12 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
Record record = store.getRecord(fileTarget);
store.remove((FileGridModel) record.getModel());
return true;
}
else
} else
System.out.println("Delete Error: file target with " + identifier + " identifier not exist in store");
return false;
}
/**
* Gets the current folder view.
*
@ -446,7 +429,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
return currentFolderView;
}
/**
* Sets the current folder view.
*
@ -456,7 +438,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
this.currentFolderView = currentFolderView;
}
/**
* Rename item.//
*
@ -479,11 +460,9 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
return true;
}
}
else
} else
System.out.println("Record Error: file target not exist in store");
}
else
} else
System.out.println("Rename Error: file target is null");
return false;
@ -521,7 +500,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
return false;
}
/**
* Gets the store.
*
@ -532,8 +510,8 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
}
/**
* Sets the border as on search.
*percentulae in java
* Sets the border as on search. percentulae in java
*
* @param bool the new border as on search
*/
public void setBorderAsOnSearch(boolean bool) {
@ -542,8 +520,7 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
if (bool) {
this.cp.getElement("body").getStyle().setBorderColor("#32CD32");
}
else
} else
this.cp.getElement("body").getStyle().setBorderColor("#99BBE8");
}
@ -605,10 +582,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
*/
public void refreshSize(String width, String height) {
// if(this.isRendered()){
// GWT.log("refresh size grid "+height);
// this.setHeight(height);
// }
GWT.log("refresh size grid " + width + "; heigth: " + height);
this.setSize(width, height);
cp.setSize(width, height);
@ -632,8 +605,6 @@ public class GxtGridFilterGroupPanel extends LayoutContainer {
col.setWidth(percent);
}
}
//cp.layout(true);
//this.layout(true);
}
}