[Registry-dev] svn commit r16594 - in trunk/registry/modules/webapps/src/main: java/org/wso2/registry/web java/org/wso2/registry/web/utils webapp/admin webapp/admin/ajax webapp/admin/css webapp/admin/images webapp/admin/js

svn at wso2.org svn at wso2.org
Tue May 6 22:46:37 PDT 2008


Author: chanaka
Date: Tue May  6 22:46:17 2008
New Revision: 16594

Log:

1 - Implemented the new lifecycle thing in to UI
* Need comments on this.
* I think it has to be modified.

Added:
   trunk/registry/modules/webapps/src/main/webapp/admin/images/noatunstop.png   (contents, props changed)
Modified:
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/LifecycleUtil.java
   trunk/registry/modules/webapps/src/main/webapp/admin/ajax/lifecycle_list.jsp
   trunk/registry/modules/webapps/src/main/webapp/admin/css/main.css
   trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
   trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java	Tue May  6 22:46:17 2008
@@ -250,10 +250,10 @@
                     forwardToResources(request, response, path);
                 }
 
-            }else if (command.equals("/addLifeCycle")) {
+            }else if (command.equals("/addAspect")) {
 
                 try {
-                    LifecycleUtil.addLifeCycle(request, response);
+                    LifecycleUtil.addAspect(request, response);
                 } catch (Exception e) {
                     // todo: implement a general AJAX error segment
                     setErrorMessage(request, e.getMessage());

Modified: trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/LifecycleUtil.java
==============================================================================
--- trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/LifecycleUtil.java	(original)
+++ trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/LifecycleUtil.java	Tue May  6 22:46:17 2008
@@ -2,31 +2,82 @@
 
 import org.wso2.registry.Registry;
 import org.wso2.registry.RegistryException;
-import org.wso2.registry.ResourceImpl;
+import org.wso2.registry.Resource;
+import org.wso2.registry.Aspect;
+import org.wso2.registry.jdbc.handlers.RequestContext;
 import org.wso2.registry.web.UIConstants;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.util.*;
 
 /**
  * TODO: JavaDoc
  */
 public class LifecycleUtil {
-    public static void addLifeCycle(HttpServletRequest request, HttpServletResponse response)
+    public static class SimpleLifecycle extends Aspect {
+        public static final String STATE_PROP = "SimpleLifecycle.state";
+        public static final String INIT = "init";
+        public static final String FINAL = "final";
+
+        public static final String ACTION = "transition";
+
+        public void associate(Resource resource, Registry registry) throws RegistryException {
+            resource.setProperty(STATE_PROP, INIT);
+        }
+
+        public void transition(RequestContext context, String action) throws RegistryException {
+            if (!ACTION.equals(action)) {
+                throw new RegistryException("Wrong action");
+            }
+
+            Resource r = context.getResource();
+            String state = r.getProperty(STATE_PROP);
+            if (state == null) {
+                throw new RegistryException("No state property");
+            }
+
+            if (!INIT.equals(state)) {
+                throw new RegistryException("Invalid state '" + state + "'");
+            }
+
+            r.setProperty(STATE_PROP, FINAL);
+        }
+
+        static String [] actions = new String [] { ACTION };
+
+        public String [] getAvailableActions(RequestContext context) {
+            Resource r = context.getResource();
+            String state = r.getProperty(STATE_PROP);
+            if (INIT.equals(state)) return actions;
+            return null;
+        }
+    }
+    public static void addAspect(HttpServletRequest request, HttpServletResponse response)
             throws ServletException, IOException {
         try {
             String resourcePath = request.getParameter("resourcePath");
-            String lifecycleText = request.getParameter("lifecycle");
+            String aspectText = request.getParameter("aspect");
             Registry registry = CommonUtil.getUserRegistry(request);
+            List<String> aspectList = new ArrayList();
+            Map<String, String[]> lifecycles = new HashMap<String, String[]>();
+
 
-            ResourceImpl resourceImpl = new ResourceImpl();
-            //resourceImpl.addLifecycle(lifecycleText);
+            registry.addAspect(aspectText,new SimpleLifecycle());
+            registry.associateAspect(resourcePath,aspectText);
+            Resource resource = registry.get(resourcePath);
+            aspectList = resource.getAspects();
+            registry.put(resourcePath,resource);
+
+            for(String asp:aspectList){
+                String[] actions=registry.getAspectActions(resourcePath,asp);
+                lifecycles.put(asp,actions);
+            }
 
-            //List<String> lifecycles = resourceImpl.getLifecycles();
+            request.getSession().setAttribute(UIConstants.AJAX_LIFECYCLE_LIST, lifecycles);
 
-            //request.getSession().setAttribute(UIConstants.AJAX_LIFECYCLE_LIST, lifecycles);
         } catch (RegistryException e) {
             request.getSession().setAttribute(UIConstants.ERROR_MESSAGE, e.getMessage());
         }

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/ajax/lifecycle_list.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/ajax/lifecycle_list.jsp	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/ajax/lifecycle_list.jsp	Tue May  6 22:46:17 2008
@@ -1,5 +1,6 @@
 <%@ page import="org.wso2.registry.web.UIConstants" %>
 <%@ page import="org.wso2.registry.web.actions.ResourceDetailsAction" %>
+<%@ page import="java.util.HashMap" %>
 <%@ page import="java.util.Iterator" %>
 <%@ page import="java.util.Map" %>
 <%
@@ -14,27 +15,45 @@
 --%>
 <%@ page contentType="text/html;charset=UTF-8" language="java" %>
 
-Assigned so far<br />
-<%
-    Map<String,String[]> availableActions = details.getAvailableActions();
-    Iterator<String> iLifecycles = availableActions.keySet().iterator();
-    while (iLifecycles.hasNext()) {
-        String lifecycle = iLifecycles.next();
-%>
-<div class="lifecycle">
-    <h3><%=lifecycle%></h3>
-    <%
-        String [] actions = availableActions.get(lifecycle);
-        for (String action : actions) {
-            String actionURL = "/wso2registry" + details.getPath() +
-                    ";lifecycle[" + lifecycle + "]:" + action;
-    %>
-    <form action="<%=actionURL%>" method="POST">
-        <input type="submit" name="<%=action%>">
-    </form>
-    <%
-        }
-    %>
-</div>
+ <br/>
+        <h3>Available Aspects</h3>
+        <ul class="aspectList">
+        <%
+             Object lifeCycleObj = request.getSession().getAttribute(UIConstants.AJAX_LIFECYCLE_LIST);
+
+            if(lifeCycleObj instanceof Map) {
+                Map<String, String[]> availableActions = (Map<String, String[]>)lifeCycleObj;
+                Iterator<String> iLifecycles = availableActions.keySet().iterator();
+                for (int k=1;iLifecycles.hasNext();k++) {
+                    String lifecycle = iLifecycles.next();
+        %>
+
+             <li><h4><%=lifecycle%></h4>
+                <table cellpadding="0" cellspacing="0" border="0" width="100%" class="data-table">
+                    <tr><th colspan="2"><h4>Available Actions</h4></th></tr>
+
+            <%
+                String[] actions = availableActions.get(lifecycle);
+                for (String action : actions) {
+                    String actionURL = "/wso2registry" + details.getPath() +
+                            ";aspect[" + lifecycle + "]:" + action;
+            %>
+                   <tr>
+                       <td><%=action%> </td>
+                       <td>
+                           <form action="<%=actionURL%>" method="POST">
+                            <input type="submit" name="<%=action%>" value="Invoke Action">
+                            </form>
+                       </td>
+                   </tr>
+
+            <%
+                }
+            %>
+                   </table>
+            </li>
+
+        <% }} %>
+        </ul>
 
-<% } %>
+    <!-- END lifecycle listing box -->

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/css/main.css
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/css/main.css	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/css/main.css	Tue May  6 22:46:17 2008
@@ -322,7 +322,7 @@
 .box2-head{
 background-position:0px;
 height:35px;
-background-color:#E2F0D0;    
+background-color:#E2F0D0;
 }
 .box2-mid{
 padding-left:25px;
@@ -572,7 +572,7 @@
 margin-bottom:10px;
 }
 .toolBarTable{
-display:inline; 
+display:inline;
 width:100px;
 *width:60px;
 }
@@ -683,7 +683,7 @@
 }
 .versionsToolBar{
 padding:3px;
-border:solid 1px #cccccc; 
+border:solid 1px #cccccc;
 background-color:#e2f0d0;
 margin-top:3px;
 margin-bottom:3px;
@@ -753,7 +753,7 @@
 .validationErrorForSearch{
 position:absolute;
 right:20px;
-top:100px; 
+top:100px;
 width:350px;
 text-align:center;
 }
@@ -761,3 +761,14 @@
 color:red;
 font-size:10px;
 }
+.aspectList{
+padding-left:10px;
+}
+.aspectList li{
+list-style-image:url(../images/noatunstop.png);
+margin-bottom:10px;
+}
+.aspectList h4{
+line-height:20px;
+font-size:12px;
+}

Added: trunk/registry/modules/webapps/src/main/webapp/admin/images/noatunstop.png
==============================================================================
Binary file. No diff available.

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js	Tue May  6 22:46:17 2008
@@ -189,11 +189,12 @@
     	return false;
     }
 }
-function addLifecycle(resourcePath){
-    var lifecycleElement = document.getElementById('lifecycle');
-    var lifecycle = lifecycleElement.value;
-    lifecycleElement.value = '';
-    new Ajax.Updater('lifecycleList', '/wso2registry/system/addLifecycle', { method: 'post', parameters: {lifecycle: lifecycle, resourcePath: resourcePath} });
+function addAspect(resourcePath){
+    var aspectElement = document.getElementById('lifecycle');
+    var aspect =aspectElement.options[aspectElement.selectedIndex].value;
+    alert(aspect);
+
+    new Ajax.Updater('aspectList', '/wso2registry/system/addAspect', { method: 'post', parameters: {aspect: aspect, resourcePath: resourcePath} });
 }
 function showHideCommon(divxName){
     divx=document.getElementById(divxName);

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp	(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp	Tue May  6 22:46:17 2008
@@ -886,48 +886,63 @@
     <!-- Lifecycle add box -->
     <div id="add-lifecycle-div" style="display:none;padding-bottom:10px;">
 
-        <h3>Assign New Lifecycle</h3>
+        <h3>Assign New Aspect</h3>
 
         <form onsubmit="return addLifecycle('<%=details.getPath()%>');">
-            <input type="text" id="lifecycle" name="lifecycle" style="width:99%"/>
+            <select id="lifecycle" name="lifecycle" style="width:98%">
+                <option>firstAction</option>
+                <option>2ndAction</option>
+            </select>
+
 
             <div style="margin-top:10px;"><input type="button" class="button" value="Add"
-                                                 onclick="addLifecycle('<%=details.getPath()%>');showHideCommon('add-lifecycle-div');"/>
+                                                 onclick="addAspect('<%=details.getPath()%>');showHideCommon('add-lifecycle-div');"/>
                 <input type="button" class="button" value="Cancel" onclick="showHideCommon('add-lifecycle-div');"/>
             </div>
         </form>
+
         <!-- Lifecycle add box ends -->
 
     </div>
-
-
     <!-- START lifecycle listing box -->
-    <div id="lifecycleList">
+    <div id="aspectList">
         <br/>
+        <h3>Available Aspects</h3>
+        <ul class="aspectList">
         <%
             Map<String, String[]> availableActions = details.getAvailableActions();
             Iterator<String> iLifecycles = availableActions.keySet().iterator();
-            while (iLifecycles.hasNext()) {
+            for (int k=1;iLifecycles.hasNext();k++) {
                 String lifecycle = iLifecycles.next();
         %>
-        <div class="aspects">
-            <h3><%=lifecycle%>
-            </h3>
+
+             <li><h4><%=lifecycle%></h4>
+                <table cellpadding="0" cellspacing="0" border="0" width="100%" class="data-table">
+                    <tr><th colspan="2"><h4>Available Actions</h4></th></tr>
+
             <%
                 String[] actions = availableActions.get(lifecycle);
                 for (String action : actions) {
                     String actionURL = "/wso2registry" + details.getPath() +
                             ";aspect[" + lifecycle + "]:" + action;
             %>
-            <form action="<%=actionURL%>" method="POST">
-                <input type="submit" name="<%=action%>">
-            </form>
+                   <tr>
+                       <td><%=action%> </td>
+                       <td>
+                           <form action="<%=actionURL%>" method="POST">
+                            <input type="submit" name="<%=action%>" value="Invoke Action">
+                            </form>
+                       </td>
+                   </tr>
+
             <%
                 }
             %>
-        </div>
+                   </table>
+            </li>
 
         <% } %>
+        </ul>
     </div>
 
     <!-- END lifecycle listing box -->



More information about the Registry-dev mailing list