2018-03-02 17:03:57 +01:00
|
|
|
package org.gcube.portlets.widgets.wsthreddssync.client.view;
|
|
|
|
|
2018-03-12 17:43:51 +01:00
|
|
|
import org.gcube.portlets.widgets.wsthreddssync.shared.GcubeScope;
|
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
// TODO: Auto-generated Javadoc
|
|
|
|
/**
|
|
|
|
* The Class FormatUtil.
|
|
|
|
*
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* Feb 16, 2018
|
|
|
|
*/
|
|
|
|
public class FormatUtil {
|
|
|
|
|
2018-03-12 17:43:51 +01:00
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
|
|
|
* Truncate a string and add an ellipsis ('...') to the end if it exceeds the
|
|
|
|
* specified length.
|
2018-03-12 17:43:51 +01:00
|
|
|
*
|
2018-03-02 17:03:57 +01:00
|
|
|
* @param value the string to truncate
|
|
|
|
* @param len the maximum length to allow before truncating
|
|
|
|
* @return the converted text
|
|
|
|
*/
|
|
|
|
public static String ellipse(String value, int len) {
|
|
|
|
if (value != null && value.length() > len) {
|
|
|
|
return value.substring(0, len - 3) + "...";
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
2018-03-12 17:43:51 +01:00
|
|
|
|
|
|
|
|
2018-03-02 17:03:57 +01:00
|
|
|
/**
|
|
|
|
* Gets the folder title.
|
|
|
|
*
|
|
|
|
* @param folderName the folder name
|
|
|
|
* @param maxSize the max size
|
|
|
|
* @return the folder title
|
|
|
|
*/
|
|
|
|
public static String getFolderTitle(String folderName, int maxSize){
|
|
|
|
String title = folderName!=null&&folderName.length()>0?folderName:"";
|
|
|
|
return FormatUtil.ellipse(title, maxSize);
|
2018-03-12 17:43:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To scope value.
|
|
|
|
*
|
|
|
|
* @param gcubeScope the gcube scope
|
|
|
|
* @return the string
|
|
|
|
*/
|
|
|
|
public static String toScopeValue(GcubeScope gcubeScope){
|
|
|
|
|
|
|
|
if(gcubeScope==null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return "("+gcubeScope.getScopeType()+") "+gcubeScope.getScopeTitle();
|
|
|
|
}
|
2018-03-02 17:03:57 +01:00
|
|
|
}
|