256: Workspace explorer

Task-Url: https://support.d4science.org/issues/256

Upgraded to GWT 2.7
Added size formatter
Updated css

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-explorer@117146 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-10 09:57:39 +00:00
parent 7c473a0518
commit ff0dbc8a57
8 changed files with 174 additions and 50 deletions

View File

@ -24,7 +24,7 @@
</scm>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.6.1</gwtVersion>
<gwtVersion>2.7.0</gwtVersion>
<distroDirectory>distro</distroDirectory>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>

View File

@ -202,15 +202,15 @@ public class WorkspaceExplorerController implements EventHandler {
if(!item.isFolder())
hp.add(labelMime);
hp.add(labelACL);
workspaceNavigatorService.loadSizeByItemId(item.getId(), new AsyncCallback<Long>() {
workspaceNavigatorService.getReadableSizeByItemId(item.getId(), new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Long result) {
labelSize.setText("Size: " +Util.getFormattedSize(result));
public void onSuccess(String result) {
labelSize.setText("Size: " +result);
}
});

View File

@ -6,6 +6,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter;
import org.gcube.portlets.widgets.wsexplorer.shared.WorkspaceNavigatorServiceException;
import com.google.gwt.user.client.rpc.RemoteService;
@ -13,85 +14,116 @@ import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
* The client side stub for the RPC service.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 10, 2015
*/
@RemoteServiceRelativePath("WorkspaceExplorerService")
public interface WorkspaceExplorerService extends RemoteService {
/**
* @param itemIdentifier
* @param includeItemAsParent
* @return
* @throws Exception
* Gets the breadcrumbs by item identifier.
*
* @param itemIdentifier the item identifier
* @param includeItemAsParent the include item as parent
* @return the breadcrumbs by item identifier
* @throws Exception the exception
*/
List<Item> getBreadcrumbsByItemIdentifier(String itemIdentifier,
boolean includeItemAsParent) throws Exception;
/**
* @param name
* @return
* @throws WorkspaceNavigatorServiceException
* Check name.
*
* @param name the name
* @return true, if successful
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
boolean checkName(String name) throws WorkspaceNavigatorServiceException;
/**
* @param folderId
* @param showableTypes
* @param purgeEmpyFolders
* @param filterCriteria
* @return
* @throws WorkspaceNavigatorServiceException
* Gets the folder.
*
* @param folderId the folder id
* @param showableTypes the showable types
* @param purgeEmpyFolders the purge empy folders
* @param filterCriteria the filter criteria
* @return the folder
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
Item getFolder(String folderId, List<ItemType> showableTypes,
boolean purgeEmpyFolders, FilterCriteria filterCriteria)
throws WorkspaceNavigatorServiceException;
/**
* @param showableTypes
* @param purgeEmpyFolders
* @param filterCriteria
* @return
* @throws WorkspaceNavigatorServiceException
* Gets the root.
*
* @param showableTypes the showable types
* @param purgeEmpyFolders the purge empy folders
* @param filterCriteria the filter criteria
* @return the root
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
Item getRoot(List<ItemType> showableTypes, boolean purgeEmpyFolders,
FilterCriteria filterCriteria)
throws WorkspaceNavigatorServiceException;
/**
* @param showableTypes
* @param purgeEmpyFolders
* @param filterCriteria
* @return
* @throws WorkspaceNavigatorServiceException
* Gets the my special folder.
*
* @param showableTypes the showable types
* @param purgeEmpyFolders the purge empy folders
* @param filterCriteria the filter criteria
* @return the my special folder
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
Item getMySpecialFolder(List<ItemType> showableTypes,
boolean purgeEmpyFolders, FilterCriteria filterCriteria)
throws WorkspaceNavigatorServiceException;
/**
* @param category
* @return
* @throws WorkspaceNavigatorServiceException
* Gets the item by category.
*
* @param category the category
* @return the item by category
* @throws WorkspaceNavigatorServiceException the workspace navigator service exception
*/
Item getItemByCategory(ItemCategory category)throws WorkspaceNavigatorServiceException;
/**
* @param itemId
* @return
* @throws Exception
* Gets the size by item id.
*
* @param itemId the item id
* @return the size by item id
* @throws Exception the exception
*/
Long loadSizeByItemId(String itemId) throws Exception;
Long getSizeByItemId(String itemId) throws Exception;
/**
* @param itemId
* @return
* @throws Exception
* Gets the mime type.
*
* @param itemId the item id
* @return the mime type
* @throws Exception the exception
*/
String getMimeType(String itemId) throws Exception;
/**
* @param folderId
* @return
* @throws Exception
* Gets the user acl for folder id.
*
* @param folderId the folder id
* @return the user acl for folder id
* @throws Exception the exception
*/
String getUserACLForFolderId(String folderId) throws Exception;
/**
* Gets the readable size by item id.
*
* @param id the id
* @return the readable size by item id
* @throws Exception the exception
*/
String getReadableSizeByItemId(String id) throws Exception;
}

View File

@ -9,6 +9,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -99,20 +100,39 @@ public interface WorkspaceExplorerServiceAsync {
public void getItemByCategory(ItemCategory category, AsyncCallback<Item> asyncCallback);
/**
* @param id
* @param asyncCallback
* Gets the size by item id.
*
* @param id the id
* @param asyncCallback the async callback
* @return the size by item id
*/
public void loadSizeByItemId(String id, AsyncCallback<Long> asyncCallback);
public void getSizeByItemId(String id, AsyncCallback<Long> asyncCallback);
/**
* @param id
* @param asyncCallback
* Gets the readable size by item id.
*
* @param id the id
* @param asyncCallback the async callback
* @return the readable size by item id
*/
public void getReadableSizeByItemId(String id, AsyncCallback<String> asyncCallback);
/**
* Gets the mime type.
*
* @param id the id
* @param asyncCallback the async callback
* @return the mime type
*/
public void getMimeType(String id, AsyncCallback<String> asyncCallback);
/**
* @param id
* @param asyncCallback
* Gets the user acl for folder id.
*
* @param id the id
* @param asyncCallback the async callback
* @return the user acl for folder id
*/
public void getUserACLForFolderId(String id,
AsyncCallback<String> asyncCallback);

View File

@ -31,6 +31,7 @@
margin-right: 10px;
margin-left: 5px;
width: 550px;
font-size: 12px !important;
}
.footerHP{

View File

@ -65,7 +65,7 @@ public class ItemBuilder {
}
/**
* Gets the item.
* Gets the item
*
* @param parent the parent
* @param workspaceItem the workspace item

View File

@ -1,5 +1,7 @@
package org.gcube.portlets.widgets.wsexplorer.server;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -25,6 +27,7 @@ import org.gcube.portlets.widgets.wsexplorer.shared.FilterCriteria;
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemCategory;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
import org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter;
import org.gcube.portlets.widgets.wsexplorer.shared.WorkspaceNavigatorServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -45,7 +48,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
*/
public static final Logger _log = LoggerFactory.getLogger(WorkspaceExplorerServiceImpl.class);
public static final String USERNAME_ATTRIBUTE = "username";
public static final String TEST_USER = "francesco.mangiacrapa";
public static final String TEST_USER = "test.user";
/**
@ -349,7 +352,7 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#loadSizeByItemId(java.lang.String)
*/
@Override
public Long loadSizeByItemId(String itemId) throws Exception {
public Long getSizeByItemId(String itemId) throws Exception {
_log.info("get Size By ItemId "+ itemId);
try {
@ -451,4 +454,29 @@ public class WorkspaceExplorerServiceImpl extends RemoteServiceServlet implement
return false;
}
}
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.wsexplorer.client.rpc.WorkspaceExplorerService#getFormattedSizeByItemId(java.lang.String, org.gcube.portlets.widgets.wsexplorer.shared.SizeFormatter)
*/
@Override
public String getReadableSizeByItemId(String itemId) throws Exception {
try{
_log.info("getFormattedSize ByItemId "+ itemId);
long size = getSizeByItemId(itemId);
return readableFileSize(size);
} catch (Exception e) {
_log.error("getFormattedSize By ItemId ", e);
throw new Exception(e.getMessage());
}
}
private static String readableFileSize(long size) {
if(size < 0) return "Unknown";
if(size == 0) return "Empty";
final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
}

View File

@ -0,0 +1,43 @@
/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.shared;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Jul 10, 2015
*/
public enum SizeFormatter {
KB("KB", 1024),
MB("MB", 1048576);
private long value;
private String unit;
/**
*
*/
private SizeFormatter(String unit, long value) {
this.unit = unit;
this.value = value;
}
/**
* @return the value
*/
public long getValue() {
return value;
}
/**
* @return the unit
*/
public String getUnit() {
return unit;
}
}