PageRenderTime 52ms CodeModel.GetById 34ms app.highlight 11ms RepoModel.GetById 2ms app.codeStats 0ms

/razpub/src/razie/assets/BaseInventory.scala

http://razpub.googlecode.com/
Scala | 69 lines | 41 code | 8 blank | 20 comment | 11 complexity | 32f74e2d3e20988de329c6495e49c933 MD5 | raw file
 1/**
 2 * Razvan's public code. Copyright 2008 based on Apache license (share alike) see LICENSE.txt for
 3 * details. No warranty implied nor any liability assumed for this code.
 4 */
 5package razie.assets;
 6
 7import razie.base.ActionItem;
 8import com.razie.pub.base.ActionItems;
 9import razie.base.ScriptContext;
10import com.razie.pub.comms.SimpleActionToInvoke;
11import razie.draw._
12import razie.draw.widgets.NavButton;
13
14/**
15 * just a base inventory with some defaults like delete
16 * 
17 * @author razvanc
18 */
19abstract class BaseInventory extends AssetInventory {
20
21   /** default handles only delete... */
22    override def doAction(cmd : String, key : AssetKey, ctx : ScriptContext) : AnyRef = {
23      if (cmd == null || cmd.length() == 0 || cmd.equals("details")) {
24            AssetMgr.getAsset(key) match {
25               case a:Drawable => return a
26            }
27         }
28      else if (cmd.startsWith(AssetBrief.DELETE.name)) {
29         if (ctx == null || !ctx.isPopulated("confirmed")) {
30            return confirmDelete(key);
31         } else {
32            delete(key);
33            return "Ok";
34         }
35      }
36
37    return "default-no-goodnik-doAction " + cmd + ", " + key;
38   }
39
40   protected def confirmDelete(ref:AssetKey ) = {
41      val list = new DrawList();
42      list.write(new NavButton(ActionItems.WARN, ""));
43      list.write("Confirm deletion below or click BACK...");
44//      val ati = new AssetActionToInvoke(ref, AssetBrief.DELETE);
45//      ati.set("confirmed", "yes");
46//      laati.ti.ist.write(ati);
47      list;
48   }
49
50   /**
51    * destroy, deallocate and remove the asset - must implement auth&auth itself
52    * 
53    * TODO include in main inv interface as CRUD ops
54    */
55   def delete(ref:AssetKey ) : Unit = {
56      throw new UnsupportedOperationException("can't delete this " + ref);
57   }
58
59   /** queries can run in the background, they are multithreaded safe etc */
60   /** default only directs to queryAll ... */
61   override def query(criteria:QueryCriteria, env:AssetLocation , recurse:Boolean , toUse:AssetMap) : AssetMap = 
62      criteria match {
63         case AllOfType (meta) => queryAll(meta, env, recurse, toUse)
64         case _ => 
65            throw new IllegalArgumentException ("I only support AllOfType queries right now")
66      }
67
68   override def init(meta:Meta ) = { /* nothing to init */ }
69}