workspace-explorer/src/main/java/org/gcube/portlets/widgets/wsexplorer/client/Util.java

56 lines
1.1 KiB
Java

/**
*
*/
package org.gcube.portlets.widgets.wsexplorer.client;
import org.gcube.portlets.widgets.wsexplorer.shared.ItemType;
/**
* The Class Util.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jun 18, 2015
*/
public class Util {
public static final ItemType[] FOLDERS = new ItemType[] { ItemType.ROOT,
ItemType.FOLDER };
/**
* 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;
}
}