package com.bexp;
import java.util.concurrent.*;
import java.util.*;
import org.JWrapper.*;
import com.bexp.ejb.*;
/**
* This class is pure behaviour, no data.
* Should it have a reference to JWrapper instance?
*/
public class ObjInfo
{
protected static ObjInfo singleton; // do we need it?
//protected JDynamicCompositeWrapper hdcwrp;
//protected
protected SDApp sd_app;
public ObjInfo(SDApp _sd_app)
{
sd_app = _sd_app;
}
String name = "item";
public ObjInfo(SDApp _sd_app, String _name)
{
sd_app = _sd_app;
name=_name;
}
public SDApp getSDApp()
{ return sd_app; }
@Deprecated
public static ObjInfo getDefaultObjInfo(SDApp _sd_app)
{
if(singleton==null) { singleton = new ObjInfo(_sd_app); }
return singleton;
}
public boolean isRegular()
{ return true; }
public void refresh() throws Exception
{ /*nothing*/ }
public JSimpleCompositeWrapper getDefaultShortWrapper(T obj) throws Exception
{
final T obj_static_copy = obj;
JSimpleCompositeWrapper wObj = this.getDefaultWrapper(obj);
final JSimpleCompositeWrapper wObj_static_copy =wObj;
wObj.getUserFunctions().put("print",
new UserFunction("Print contents",wObj)
{
public void act()
{
for(JWrapper wrp : getWrapper().getChildren())
System.out.println(wrp);
}
});
wObj.getUserFunctions().put("clone",
new UserFunction("Clone this object",wObj)
{
/* This should be more wise than simply .copy() 'cause it could yeild problems
* with relations !*/
Obj OBJ = obj_static_copy;
public void act() throws Exception
{
T new_obj = (T) OBJ.clone();
Object pk = new_obj.getPK();
if(sd_app.edit(getDefaultDetailedWrapper(new_obj)))
{ new_obj.save(); }
else{ OBJ.getHome().delete(pk); }
}
});
return wObj;
}
public JSimpleCompositeWrapper getDefaultDetailedWrapper(T obj) throws Exception
{
final T OBJ = obj;
if(obj==null) { throw new Exception("ObjInfo::getDefaultDetailedWrapper(): argument is null!"); }
JSimpleCompositeWrapper wObj = this.getDefaultWrapper(obj);
//some details here if differs
UserFunction
Save = new UserFunction("Save",wObj)
{
T OBJECT=OBJ;
public void act() throws Exception
{
OBJECT.save();
this.getWrapper().getAdditionalInfo().put(SavedTag.class,new SavedTag());
}
};
Map functions = wObj.getUserFunctions();
//functions.clear(); // I cannot divise anything wisier than this now :-\
functions.put("save",Save);
JScalarWrapper wRP
= new JScalarWrapper("Created By",
new JBeanAccessAdapter(obj,"Creator",false));
JScalarWrapper wOwner
= new JScalarWrapper("Owner",
new JBeanAccessAdapter(obj,"Owner"));
wObj.add(wRP);
wObj.add(wOwner);
/*
Set history = (Set)obj.getHistory();
if(history!=null)
wObj.add( (new JSimpleCompositeWrapper("History")).add(0,
new com.bexp.JDefaultCollectionWrapper
("History",new CopyOnWriteArraySet(history),
com.bexp.ejb.HistoryItem.SDObj.class,
new ObjInfo(sd_app))//<-should be updated somehow
{
protected com.bexp.ejb.HistoryItem.SDObj getValue() throws Exception
{
if(true)
{ throw new Exception("History is automated, you cannot add new item here."); }
return null;
}
public void remove_child(JWrapper wrp) throws Exception
{
if(true)
{ throw new Exception("You cannot remove history line"); }
}
public boolean isCreateAllowed()
{ return false; }
public boolean isDeleteAllowed()
{ return false; }
}
));
*/
wObj.add( (new JSimpleCompositeWrapper("History")).add(0,
new com.bexp.JObjHandleCollectionWrapper
("History",obj.getHistoryItems(),
com.bexp.ejb.HistoryItem.SDObj.class,
new ObjInfo(sd_app,"History Item"))//<-should be updated somehow
{
protected List> getValues() throws Exception
{
if(true)
{ throw new Exception("History is automated, you cannot add new item here."); }
return null;
}
public void remove_child(JWrapper wrp) throws Exception
{
if(true)
{ throw new Exception("You cannot remove history line"); }
}
public boolean isCreateAllowed()
{ return false; }
public boolean isDeleteAllowed()
{ return false; }
}
));
return wObj;
}
public JSimpleCompositeWrapper getDefaultWrapper(T obj) throws Exception
{
final T obj_static_copy = obj;
JSimpleCompositeWrapper wObj =
new JSimpleCompositeWrapper(name);
final JSimpleCompositeWrapper wObj_static_copy =wObj;
JScalarWrapper wPK =
new JScalarWrapper