Merge branch 'master' of https://git.bukova.info/repos/git/isspst
						commit
						021d73bf48
					
				@ -1,13 +1,48 @@
 | 
			
		||||
package info.bukova.isspst;
 | 
			
		||||
 | 
			
		||||
import org.jfree.util.Log;
 | 
			
		||||
 | 
			
		||||
public class BooleanUtils
 | 
			
		||||
{
 | 
			
		||||
	public static boolean isEqualByBoolean(Boolean b1, Boolean b2)
 | 
			
		||||
	private static final String TAG = BooleanUtils.class.getSimpleName();
 | 
			
		||||
 | 
			
		||||
	public static boolean isEqualByBooleanValue(Boolean b1, Boolean b2)
 | 
			
		||||
	{
 | 
			
		||||
		boolean bool1 = ((b1 == null) ? false : b1.booleanValue());
 | 
			
		||||
		boolean bool2 = ((b2 == null) ? false : b2.booleanValue());
 | 
			
		||||
		boolean equals = (bool1 == bool2);
 | 
			
		||||
		return equals;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static boolean isEqualByBoolean(Boolean b1, Boolean b2)
 | 
			
		||||
	{
 | 
			
		||||
		if ((b1 == null) && (b2 == null))
 | 
			
		||||
		{
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		else if ((b1 != null) && (b2 != null))
 | 
			
		||||
		{
 | 
			
		||||
			return (b1.booleanValue() == b2.booleanValue());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public static boolean isEqualFilterByBoolean(Boolean value, Boolean filterValue)
 | 
			
		||||
	{
 | 
			
		||||
		if (filterValue == null)
 | 
			
		||||
		{
 | 
			
		||||
			// Show all records
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (value == null)
 | 
			
		||||
		{
 | 
			
		||||
			// Fuck!!! Tri-state data (null, false, true)... We need new solution for selecting ALL data
 | 
			
		||||
			Log.warn(TAG + "\nVelky Boolean v databazi... Pozor na filtrovani.");
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return (value.booleanValue() == filterValue.booleanValue());
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,57 @@
 | 
			
		||||
package info.bukova.isspst.filters;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.StringUtils;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.zkoss.zul.Listbox;
 | 
			
		||||
import org.zkoss.zul.Listitem;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("serial")
 | 
			
		||||
public class BooleanFilterListbox extends Listbox
 | 
			
		||||
{
 | 
			
		||||
	class TristateBooleanListItem extends TristateBoolean
 | 
			
		||||
	{
 | 
			
		||||
		public TristateBooleanListItem(String text, int value)
 | 
			
		||||
		{
 | 
			
		||||
			this.setText(text);
 | 
			
		||||
			this.setValue(value);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private String text;
 | 
			
		||||
 | 
			
		||||
		public String getText()
 | 
			
		||||
		{
 | 
			
		||||
			return text;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public void setText(String text)
 | 
			
		||||
		{
 | 
			
		||||
			this.text = text;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public BooleanFilterListbox()
 | 
			
		||||
	{
 | 
			
		||||
		super();
 | 
			
		||||
 | 
			
		||||
		List<TristateBooleanListItem> list = new ArrayList<TristateBooleanListItem>();
 | 
			
		||||
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelAll"), TristateBoolean.NULL));
 | 
			
		||||
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelNo"), TristateBoolean.FALSE));
 | 
			
		||||
		list.add(new TristateBooleanListItem(StringUtils.localize("LabelYes"), TristateBoolean.TRUE));
 | 
			
		||||
 | 
			
		||||
		for (int i = 0; i < list.size(); i++)
 | 
			
		||||
		{
 | 
			
		||||
			TristateBooleanListItem triStateItem = (TristateBooleanListItem) list.get(i);
 | 
			
		||||
			this.appendItem(triStateItem.getText(), "");
 | 
			
		||||
 | 
			
		||||
			Listitem item = this.getItemAtIndex(i);
 | 
			
		||||
			item.setValue((TristateBoolean) triStateItem);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		this.setSelectedIndex(0);
 | 
			
		||||
		// this.setHflex("1");
 | 
			
		||||
		this.setMold("select");
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,87 @@
 | 
			
		||||
package info.bukova.isspst.filters;
 | 
			
		||||
 | 
			
		||||
import org.jfree.util.Log;
 | 
			
		||||
 | 
			
		||||
public class TristateBoolean
 | 
			
		||||
{
 | 
			
		||||
	private static final String TAG = TristateBoolean.class.getSimpleName();
 | 
			
		||||
 | 
			
		||||
	public static final int NULL = -1;
 | 
			
		||||
	public static final int FALSE = 0;
 | 
			
		||||
	public static final int TRUE = 1;
 | 
			
		||||
 | 
			
		||||
	public static final int getValidValue(final int value)
 | 
			
		||||
	{
 | 
			
		||||
		if ((value != TristateBoolean.NULL) && (value != TristateBoolean.FALSE) && (value != TristateBoolean.TRUE))
 | 
			
		||||
		{
 | 
			
		||||
			Log.warn(TAG + "\nBad tristate boolean value.");
 | 
			
		||||
			return TristateBoolean.NULL;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public TristateBoolean()
 | 
			
		||||
	{
 | 
			
		||||
		this.setValue(TristateBoolean.NULL);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public TristateBoolean(boolean value)
 | 
			
		||||
	{
 | 
			
		||||
		this.setValue(value ? TristateBoolean.TRUE : TristateBoolean.FALSE);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public TristateBoolean(int value)
 | 
			
		||||
	{
 | 
			
		||||
		this.setValue(value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected int value;
 | 
			
		||||
 | 
			
		||||
	public int getValue()
 | 
			
		||||
	{
 | 
			
		||||
		return value;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setValue(int value)
 | 
			
		||||
	{
 | 
			
		||||
		this.value = TristateBoolean.getValidValue(value);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Boolean getBoolean()
 | 
			
		||||
	{
 | 
			
		||||
		switch (this.value)
 | 
			
		||||
		{
 | 
			
		||||
		case TristateBoolean.FALSE:
 | 
			
		||||
			return new Boolean(false);
 | 
			
		||||
 | 
			
		||||
		case TristateBoolean.TRUE:
 | 
			
		||||
			return new Boolean(true);
 | 
			
		||||
 | 
			
		||||
		default:
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public boolean equals(Object obj)
 | 
			
		||||
	{
 | 
			
		||||
		if (obj != null)
 | 
			
		||||
		{
 | 
			
		||||
			if (obj instanceof TristateBoolean)
 | 
			
		||||
			{
 | 
			
		||||
				TristateBoolean item = (TristateBoolean) obj;
 | 
			
		||||
				int thisValue = this.getValue();
 | 
			
		||||
				int itemValue = item.getValue();
 | 
			
		||||
				return (thisValue == itemValue);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public boolean equals(int value)
 | 
			
		||||
	{
 | 
			
		||||
		return (this.getValue() == value);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,11 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8" ?>
 | 
			
		||||
<!DOCTYPE xml>
 | 
			
		||||
<language-addon>
 | 
			
		||||
	<addon-name>BooleanFilterListbox</addon-name>
 | 
			
		||||
	<language-name>xul/html</language-name>
 | 
			
		||||
	<component>
 | 
			
		||||
		<component-name>booleanfilterlistbox</component-name>
 | 
			
		||||
		<extends>listbox</extends>
 | 
			
		||||
		<component-class>info.bukova.isspst.filters.BooleanFilterListbox</component-class>
 | 
			
		||||
	</component>
 | 
			
		||||
</language-addon>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue