Author: simoneg
Date: Tue Nov 17 21:01:17 2009
New Revision: 881511

URL: http://svn.apache.org/viewvc?rev=881511&view=rev
Log:
LABS-155 : list crud with display and edit functions

Added:
    
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/ListCrudComplete.java
Modified:
    
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AbstractListCrud.java

Modified: 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AbstractListCrud.java
URL: 
http://svn.apache.org/viewvc/labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AbstractListCrud.java?rev=881511&r1=881510&r2=881511&view=diff
==============================================================================
--- 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AbstractListCrud.java
 (original)
+++ 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/AbstractListCrud.java
 Tue Nov 17 21:01:17 2009
@@ -44,7 +44,9 @@
                }
                ShowList sl = new ShowList(property.getCollectionClass(), 
(Collection)bean.handler().getValue(propertyName), listlink);
                sl.addAction(new FormAction("Delete", "doDelete"));
-               sl.compoundWith(handleNew().do_default(), CompoundType.AFTER);
+               if (isOverridden(AbstractListCrud.class, "handleNew")) {
+                       sl.compoundWith(handleNew().do_default(), 
CompoundType.AFTER);                  
+               }
                if (isOverridden(AbstractListCrud.class, "doNewSub")) {
                        sl.compoundWith(new StringHtmlProducer("<a 
href=\"newSub\">" + new LocalizableString("Add new {0}", 
property.getCollectionClass().getSimpleName()) + "</a>"), CompoundType.AFTER);
                }
@@ -66,7 +68,9 @@
                return doShow();
        }
        
-       public abstract SmartForm handleNew();
+       public SmartForm handleNew() {
+               return null;
+       }
 
        
        protected boolean isOverridden(Class<?> me, String methodName, 
Class<?>... params) {

Added: 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/ListCrudComplete.java
URL: 
http://svn.apache.org/viewvc/labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/ListCrudComplete.java?rev=881511&view=auto
==============================================================================
--- 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/ListCrudComplete.java
 (added)
+++ 
labs/magma/trunk/website-administration/src/main/java/org/apache/magma/website/admin/ListCrudComplete.java
 Tue Nov 17 21:01:17 2009
@@ -0,0 +1,67 @@
+package org.apache.magma.website.admin;
+
+import org.apache.magma.basics.LocalizableString;
+import org.apache.magma.basics.MagmaException;
+import org.apache.magma.beans.MagmaBeanSupport;
+import org.apache.magma.website.CompoundType;
+import org.apache.magma.website.HtmlProducer;
+import org.apache.magma.website.beansview.ShowBean;
+import org.apache.magma.website.beansview.SmartForm;
+import org.apache.magma.website.producers.StringHtmlProducer;
+import org.apache.magma.website.utils.LinkHelper;
+
+public class ListCrudComplete<SubBean extends MagmaBeanSupport> extends 
AbstractListCrud<SubBean> {
+
+       protected String[] editLayers = ALL_LAYERS;
+       protected String[] showLayers = ALL_LAYERS;     
+       protected Class<SubBean> myclass;
+       
+       public ListCrudComplete(MagmaBeanSupport bean, String propertyName) {
+               super(bean, propertyName);
+               myclass = property.getCollectionClass();
+       }
+
+       @Override
+       public HtmlProducer doShow() {
+               HtmlProducer ret = super.doShow();
+               ret.compoundWith(new StringHtmlProducer("<a 
href=\"newSubComplete\">" + new LocalizableString("Add new {0}", 
property.getCollectionClass().getSimpleName()) + "</a>"), CompoundType.AFTER);
+               return ret;
+       }
+       
+       public HtmlProducer doShowSub(SubBean bean) {
+               HtmlProducer ret = new ShowBean(bean, showLayers);
+               ret.compoundWith(
+                               new StringHtmlProducer("<h1>" + new 
LocalizableString("Display " +  myclass.getSimpleName()).toString() + "</h1>")
+                               , CompoundType.HEAD);
+               ret.compoundWith(
+                               new StringHtmlProducer("<a href=\"" + 
LinkHelper.makeLink("handleEdit", bean) + "\">" + new 
LocalizableString("Modify").toString() + "</a>")
+                               , CompoundType.FOOT);
+               return ret;             
+       };
+       
+       public SmartForm handleNewSubComplete() {
+               SubBean bean = null;
+               try {
+                       bean = (SubBean) myclass().newInstance();
+               } catch (Exception e) {
+                       throw new MagmaException(e, "Error instantiating bean 
of class {0}", myclass);
+               }
+               HtmlProducer header = new StringHtmlProducer("<h1>" + new 
LocalizableString("New " +  myclass.getSimpleName()).toString() + "</h1>");
+               return new SmartForm(bean, "hiddenSave", 
header).setLayers(editLayers);         
+       }
+
+       public HtmlProducer hiddenSave(SubBean sub) {
+               new Database().save(sub);
+               Collection<SubBean> coll = (Collection<SubBean>) 
bean.handler().getValue(propertyName);
+               coll.add(sub);
+               new Database().save(bean);
+               return doShow();
+       }
+       
+       public SmartForm handleEdit(SubBean bean) {             
+               HtmlProducer header = new StringHtmlProducer("<h1>" + new 
LocalizableString("Modify " +  myclass.getSimpleName()).toString() + "</h1>");
+               return new SmartForm(bean, "hiddenSave", 
header).setLayers(editLayers);         
+       }
+       
+       
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to