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