TBD. Example component (e.g. Panel with three buttons which set the visible state A,B,C) and example bean
Visible
There are different VisibleHandler available.
- ComponentCharVisibleHandler hier components are simple enumerated with a,b,c...
- ComponentEnumVisibleHandler where a enum in the backing bean defines the name of the component
TBD. Example component (e.g. Panel with three buttons which set the visible state A,B,C) and example bean
</ui:composition>
</h:body>
</html>
@Named @ViewScoped
public class HandlerEditBean extends AbstractJeeBean implements Serializable
{
final static Logger logger = LoggerFactory.getLogger(HandlerEditBean.class);
private static final long serialVersionUID = 1L;
private UiEditStatusHandler<IoFileType> eh1; public UiEditStatusHandler<IoFileType> getEh1() {return eh1;}
private UiEditStatusHandler<IoFileType> eh2; public UiEditStatusHandler<IoFileType> getEh2() {return eh2;}
private final UiEditBooleanHandler ehBool; public UiEditBooleanHandler getEhBool() {return ehBool;}
private UiEditLogicHandler eh3; public UiEditLogicHandler getEh3() {return eh3;}
private List<IoFileType> types; public List<IoFileType> getTypes() {return types;}
private final Map<IoFileType,Boolean> map1; public Map<IoFileType,Boolean> getMap1() {return map1;}
private final Map<IoFileType,Boolean> map2; public Map<IoFileType,Boolean> getMap2() {return map2;}
private final Map<IoFileType,Boolean> map3; public Map<IoFileType,Boolean> getMap3() {return map3;}
private IoFileType type;
public IoFileType getType() {return type;}
public void setType(IoFileType type) {this.type = type;}
private String txt; public String getTxt() {return txt;} public void setTxt(String txt) {this.txt = txt;}
public HandlerEditBean()
{
eh1 = new UiEditStatusHandler<>();
eh2 = new UiEditStatusHandler<>();
eh3 = new UiEditLogicHandler(UiEditLogicHandler.Type.AND);
eh3.addHandler(eh1);
eh3.addHandler(eh2);
ehBool = new UiEditBooleanHandler();
map1 = new HashMap<>();
map2 = new HashMap<>();
map3 = new HashMap<>();
}
@PostConstruct public void init()
{
super.initSecurity();
types = fUtils.allOrderedPositionVisible(IoFileType.class);
eh1.addAllow(types.get(1));
eh2.addDeny(types.get(2));
for(IoFileType t : types)
{
eh1.update(t); map1.put(t,eh1.isAllow());
eh2.update(t); map2.put(t,eh2.isAllow());
eh3.update(); map3.put(t,eh3.isAllow());
}
}
public void selectType()
{
logger.info(type.toString());
eh1.update(type);
eh2.update(type);
eh3.update();
}
public void save() {}
}
public class ComponentCharVisibleHandler
{
final static Logger logger = LoggerFactory.getLogger(ComponentCharVisibleHandler.class);
private boolean showA; public boolean isShowA() {return showA;}
private boolean showB; public boolean isShowB() {return showB;}
private final int size;
public ComponentCharVisibleHandler(int size)
{
this.size=size;
}
public void set(boolean showA)
{
if(size!=1) {warning(1);}
this.showA=showA;
}
public void set(boolean showA, boolean showB)
{
if(size!=2) {warning(1);}
this.showA=showA;
this.showB=showB;
}
private void warning(int i)
{
StringBuilder sb = new StringBuilder();
sb.append("Invalid set(..").append(i).append("..) Method");
sb.append(" does not match the defined size of ").append(size);
logger.warn(sb.toString());
}
}
public class ComponentEnumVisibleHandler<E extends Enum<E>>
{
final static Logger logger = LoggerFactory.getLogger(ComponentEnumVisibleHandler.class);
private Map<String,Boolean> visible;
public ComponentEnumVisibleHandler(Class<E> e)
{
visible = new Hashtable<String,Boolean>();
for(E v : e.getEnumConstants())
{
logger.trace("construct with "+v);
}
}
public void clear()
{
visible.clear();
}
private void verifyFalse(E e)
{
if(!visible.containsKey(e.toString())){visible.put(e.toString(), false);}
}
public void edit(E e, boolean value)
{
edit(e.toString(),value);
}
public void edit(String key , boolean value)
{
logger.trace("edit key:"+key+" value:"+value);
visible.put(key, value);
}
public Map<String, Boolean> getVisible() {return visible;}
public boolean isShow(E e)
{
verifyFalse(e);
return visible.get(e.toString());
}
public void toggle(E e)
{
verifyFalse(e);
if(visible.get(e.toString())) {edit(e,false);}
else {edit(e,true);}
}
}