Implementováno a sjednoceno řazení záznamů podle českých znaků.

Změnit v databázi collation z ut8_czech_ci na latin2_czech_cs!!!
Sjednocen vzhled gridů ve všech agendách.

closes #83
This commit is contained in:
2014-05-28 21:06:54 +02:00
parent 0f9d1baf94
commit 1c19625ffb
23 changed files with 590 additions and 315 deletions
@@ -0,0 +1,25 @@
package info.bukova.isspst.sort;
import org.zkoss.zul.Listheader;
@SuppressWarnings("serial")
public class CzechSortListheader extends Listheader {
@Override
public void setSort(String type) {
if (type.startsWith("auto"))
{
// czech(propertyName)
String propertyName = type.substring("auto(".length(), type.length() - 1);
this.setSortAscending(new CzechStringComparator(propertyName, true));
this.setSortDescending(new CzechStringComparator(propertyName, false));
}
else
{
// auto(propertyName)
super.setSort(type);
}
}
}
@@ -0,0 +1,115 @@
package info.bukova.isspst.sort;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.Collator;
import java.text.ParseException;
import java.text.RuleBasedCollator;
import java.util.Comparator;
public class CzechStringComparator implements Comparator<Object> {
private String m_rule;
private final String m_property;
private final boolean m_ascending;
private Method m_getter;
private Comparator<Object> m_comparator;
public CzechStringComparator(String property, boolean ascending) {
m_rule = "";
m_rule += "< A,a < Á,á < Ä,ä ";
m_rule += "< B,b ";
m_rule += "< C,c < Ć,ć < Č,č ";
m_rule += "< D,d < Ď,ď ";
m_rule += "< E,e < É,é < Ë,ë ";
m_rule += "< F,f ";
m_rule += "< G,g ";
m_rule += "< H,h ";
m_rule += "< CH,Ch,ch ";
m_rule += "< I,i < Í,í ";
m_rule += "< J,j ";
m_rule += "< K,k ";
m_rule += "< L,l < Ľ,ľ < Ĺ,ĺ ";
m_rule += "< M,m ";
m_rule += "< N,n < Ń,ń < Ň,ň ";
m_rule += "< O,o < Ó,ó < Ö,ö ";
m_rule += "< P,p ";
m_rule += "< Q,q ";
m_rule += "< R,r < Ŕ,ŕ < Ř,ř ";
m_rule += "< S,s < ß < Ś,ś < Š,š ";
m_rule += "< T,t < Ť,ť ";
m_rule += "< U,u < Ú,ú < Ů,ů < Ü,ü ";
m_rule += "< V,v ";
m_rule += "< W,w ";
m_rule += "< X,x ";
m_rule += "< Y,y < Ý,ý ";
m_rule += "< Z,z < Ź,ź < Ž,ž ";
m_property = property;
m_ascending = ascending;
}
@Override
public int compare(Object argL, Object argR) {
try {
return this.internalCompare(argL, argR);
} catch (ParseException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
private int internalCompare(Object argL, Object argR)
throws ParseException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
if (m_getter == null) {
m_getter = ReflectionTools.getGetterMethod(argL, m_property);
}
if (m_comparator == null) {
Collator c = new RuleBasedCollator(m_rule);
c.setStrength(Collator.TERTIARY);
m_comparator = c;
}
Object valL = m_getter.invoke(argL);
Object valR = m_getter.invoke(argR);
boolean isNullValL = (valL == null);
boolean isNullValR = (valR == null);
int result = 0;
if (isNullValL || isNullValR)
{
if (isNullValL && isNullValR)
{
result = 0;
}
else if (isNullValL)
{
result = -1;
}
else
{
result = 1;
}
}
else
{
result = m_comparator.compare(valL, valR);
}
return (m_ascending ? result : -result);
}
}
@@ -0,0 +1,49 @@
package info.bukova.isspst.sort;
import java.lang.reflect.Method;
public class ReflectionTools {
private static String capitalizeFirstLetter(String string)
{
String result = string.substring(0,1).toUpperCase() + string.substring(1, string.length());
return result;
}
public static String getGetterName(String propertyName)
{
String getterName = "get" + ReflectionTools.capitalizeFirstLetter(propertyName);
return getterName;
}
public static String getBoolGetterName(String propertyName)
{
String getterName = "is" + ReflectionTools.capitalizeFirstLetter(propertyName);
return getterName;
}
public static Method getGetterMethod(Object bean, String propertyName)
{
Class<?> beanClass = bean.getClass();
try
{
return beanClass.getMethod(ReflectionTools.getGetterName(propertyName));
}
catch(Throwable t)
{
// ignore
}
try
{
return beanClass.getMethod(ReflectionTools.getBoolGetterName(propertyName));
}
catch(Throwable t)
{
// ignore
}
throw new IllegalArgumentException("Not getter method found for '" + propertyName + "', bean: " + bean);
}
}