package com.bexp;
import java.util.*;
import org.JWrapper.*;
import org.JWrapper.util.JCollectionWrapper;
public /*abstract*/ class JDefaultCollectionWrapper
extends JCollectionWrapper
{
protected SDApp sd_app;
protected ObjInfo obj_info;
public JDefaultCollectionWrapper(
String _name,
java.util.Collection _collection,
Class _value_class,
ObjInfo _obj_info//,
//SDApp _sd_app
) throws Exception
{
super(_name, _collection, _value_class);
obj_info = _obj_info;
sd_app=obj_info.getSDApp();//_sd_app;
}
public boolean edit(JWrapper wrp) throws Exception
{
init();
if(this.getValueByWrapper(wrp).getIsInTrash())
{ throw new Exception("This object is in Trash !"); }
boolean edit_result = sd_app.edit(this.getDetailedWrapper(wrp));
if(edit_result)
{
this.getValueByWrapper(wrp).save();
wrp.refresh();
} else
{ this.refresh(); }
return true;
}
protected List getValues() throws Exception
{
init();
EntityWrpSrc e_src = sd_app.getEntitiesMap()
.get(value_class.getPackage());
JDiscreteWrapper
chooser
= e_src.createChooserWrapper();
chooser.set_value(0);
List wrappers = sd_app.selectWrappers(chooser);
List result = new Vector(wrappers.size());
for(JWrapper wrp : wrappers)
{
///if(wrp==null) {return null;}
//return (T) chooser.getRawValue().getObjByWrapper(wrp);
JWrapper parent_wrp = wrp.getParent();
//everything should be refactored to throw/catch Throwable instead of Exception to use assertions
//assert (parent_wrp!=null) : "You have selected something wrong :) ";
if(parent_wrp==null) { throw new Exception("You have selected something wrong :) "); }
result.add((T) ((JHomeDynamicCompositeWrapper) parent_wrp).getHandleByWrapper(wrp).getObj());
}
return result;
}
//-----
public JWrapper getDetailedWrapper(JWrapper wrp) throws Exception
{
init();
T obj = this.getValueByWrapper(wrp);
return obj_info.getDefaultDetailedWrapper(obj);
}
public boolean isRegular()
{ return obj_info.isRegular(); }
public void refresh() throws Exception
{
//init();
obj_info.refresh();
super.refresh();
}
protected JWrapper wrap(T t) throws Exception
{ return obj_info.wrap(t); }
}
|