2015-06-24 15:16:13 +02:00
|
|
|
/**
|
2017-07-11 18:32:58 +02:00
|
|
|
*
|
2015-06-24 15:16:13 +02:00
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.wsexplorer.client;
|
|
|
|
|
2015-06-25 12:56:41 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.client.resources.old.WorkspaceLightTreeResources;
|
2018-05-21 18:45:16 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.Item;
|
2015-06-24 15:16:13 +02:00
|
|
|
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
|
|
|
|
|
2015-07-31 14:24:26 +02:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
|
|
|
import com.google.gwt.dom.client.Element;
|
2015-06-25 12:56:41 +02:00
|
|
|
import com.google.gwt.resources.client.ImageResource;
|
2015-07-31 14:24:26 +02:00
|
|
|
import com.google.gwt.user.client.ui.SimplePanel;
|
2015-06-25 12:56:41 +02:00
|
|
|
|
2015-06-24 15:16:13 +02:00
|
|
|
/**
|
|
|
|
* The Class Util.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 18, 2015
|
|
|
|
*/
|
|
|
|
public class Util {
|
2017-07-11 18:32:58 +02:00
|
|
|
|
2015-07-06 17:18:23 +02:00
|
|
|
// public static final NumberFormat numberFormatterKB = NumberFormat.getFormat("#,##0 KB;(#,##0 KB)");
|
2015-06-24 15:16:13 +02:00
|
|
|
|
2015-07-13 17:15:21 +02:00
|
|
|
public static final ItemType[] FOLDERS = new ItemType[] {ItemType.FOLDER};
|
2015-06-24 15:16:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if is folder.
|
|
|
|
*
|
|
|
|
* @param type
|
|
|
|
* the type
|
|
|
|
* @return true, if is folder
|
|
|
|
*/
|
|
|
|
public static boolean isFolder(ItemType type) {
|
|
|
|
for (ItemType folder : FOLDERS)
|
|
|
|
if (type == folder)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ellipsis.
|
|
|
|
*
|
|
|
|
* @param value
|
|
|
|
* the value
|
|
|
|
* @param lenght
|
|
|
|
* the lenght
|
|
|
|
* @param left
|
|
|
|
* the left
|
|
|
|
* @return the string
|
|
|
|
*/
|
|
|
|
public static String ellipsis(String value, int lenght, boolean left) {
|
|
|
|
if (lenght < 3)
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"The lenght have to be more than 3");
|
|
|
|
if (value.length() > lenght) {
|
|
|
|
if (left)
|
|
|
|
return "..." + value.substring(value.length() - lenght + 3);
|
|
|
|
else
|
|
|
|
return value.substring(0, lenght - 3) + "...";
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2017-07-11 18:32:58 +02:00
|
|
|
|
2015-06-25 12:56:41 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the image based on the item type.
|
|
|
|
* @param type the item type.
|
|
|
|
* @return the image.
|
|
|
|
*/
|
2018-05-21 18:45:16 +02:00
|
|
|
public static ImageResource getImage(Item item) {
|
2017-07-11 18:32:58 +02:00
|
|
|
if(item==null)
|
|
|
|
return null;
|
|
|
|
|
2015-06-25 12:56:41 +02:00
|
|
|
switch (item.getType()) {
|
2015-07-13 17:15:21 +02:00
|
|
|
// case ROOT: return WorkspaceLightTreeResources.INSTANCE.root();
|
2018-05-21 18:45:16 +02:00
|
|
|
case FOLDER:
|
|
|
|
case PRIVATE_FOLDER:
|
|
|
|
return WorkspaceLightTreeResources.INSTANCE.folder();
|
|
|
|
case SHARED_FOLDER: return WorkspaceLightTreeResources.INSTANCE.sharedFolder();
|
|
|
|
case VRE_FOLDER: return WorkspaceLightTreeResources.INSTANCE.sharedFolder();
|
2015-06-25 12:56:41 +02:00
|
|
|
case EXTERNAL_IMAGE: return WorkspaceLightTreeResources.INSTANCE.external_image();
|
|
|
|
case EXTERNAL_FILE: return WorkspaceLightTreeResources.INSTANCE.external_file();
|
|
|
|
case EXTERNAL_PDF_FILE: return WorkspaceLightTreeResources.INSTANCE.external_pdf();
|
2018-05-21 18:45:16 +02:00
|
|
|
case CSV: return WorkspaceLightTreeResources.INSTANCE.CSV();
|
2015-06-25 12:56:41 +02:00
|
|
|
case EXTERNAL_URL: return WorkspaceLightTreeResources.INSTANCE.external_url();
|
|
|
|
case REPORT_TEMPLATE: return WorkspaceLightTreeResources.INSTANCE.report_template();
|
|
|
|
case REPORT: return WorkspaceLightTreeResources.INSTANCE.report();
|
|
|
|
case QUERY: return WorkspaceLightTreeResources.INSTANCE.query();
|
2018-05-21 18:45:16 +02:00
|
|
|
case CALENDAR: return WorkspaceLightTreeResources.INSTANCE.CALENDAR();
|
|
|
|
case DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.DOC();
|
|
|
|
case PRESENTATION: return WorkspaceLightTreeResources.INSTANCE.PPT();
|
|
|
|
case SPREADSHEET: return WorkspaceLightTreeResources.INSTANCE.XLS();
|
2015-06-25 12:56:41 +02:00
|
|
|
case METADATA: return WorkspaceLightTreeResources.INSTANCE.metadata();
|
|
|
|
case PDF_DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.pdf_document();
|
|
|
|
case IMAGE_DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.image_document();
|
|
|
|
case URL_DOCUMENT: return WorkspaceLightTreeResources.INSTANCE.url_document();
|
2015-07-08 12:44:50 +02:00
|
|
|
case GCUBE_ITEM: return WorkspaceLightTreeResources.INSTANCE.gucbeItem();
|
|
|
|
case UNKNOWN_TYPE: return WorkspaceLightTreeResources.INSTANCE.unknown();
|
2015-06-25 12:56:41 +02:00
|
|
|
default: {
|
|
|
|
System.err.println("Unknown item type "+item.getType());
|
|
|
|
return WorkspaceLightTreeResources.INSTANCE.unknownType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-11 18:32:58 +02:00
|
|
|
|
2015-07-06 17:18:23 +02:00
|
|
|
/**
|
2017-07-11 18:32:58 +02:00
|
|
|
*
|
2015-07-06 17:18:23 +02:00
|
|
|
* @param value
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static String getFormattedSize(long value){
|
|
|
|
|
|
|
|
if(value>0){
|
|
|
|
double kb = value/1024;
|
|
|
|
if(kb<1)
|
|
|
|
kb=1;
|
|
|
|
// return numberFormatterKB.format(kb);
|
|
|
|
return kb+"KB";
|
|
|
|
}else if(value==0){
|
|
|
|
return "EMPTY";
|
|
|
|
}else
|
|
|
|
return "";
|
|
|
|
}
|
2017-07-11 18:32:58 +02:00
|
|
|
|
2015-07-31 14:59:50 +02:00
|
|
|
public static void adjustSize(Element el, SimplePanel panel, int offset){
|
2015-07-31 14:24:26 +02:00
|
|
|
if(el!=null){
|
|
|
|
int heigth = el.getClientHeight();
|
|
|
|
GWT.log("getClientHeight adjustSize el: "+heigth);
|
2017-07-11 18:32:58 +02:00
|
|
|
heigth = heigth-offset>100?heigth-offset:0;
|
2015-07-31 14:24:26 +02:00
|
|
|
if(heigth>0){
|
|
|
|
GWT.log("set new Explorer size: "+heigth);
|
|
|
|
panel.setHeight(heigth+"px");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-11 18:32:58 +02:00
|
|
|
|
2017-11-14 14:01:15 +01:00
|
|
|
public static native void console(String text)
|
|
|
|
/*-{
|
|
|
|
//console.log(text);
|
|
|
|
}-*/;
|
|
|
|
|
2015-06-24 15:16:13 +02:00
|
|
|
}
|