[jboss-svn-commits] JBL Code SVN: r32042 - in labs/jbossrules/branches/drools_server_camel_lucaz_baunax: drools-guvnor/src/main/java/org/drools/guvnor/client/explorer and 12 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Mar 11 14:10:26 EST 2010


Author: lucazamador
Date: 2010-03-11 14:10:25 -0500 (Thu, 11 Mar 2010)
New Revision: 32042

Added:
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ServerPanel.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/ContextProfile.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileDocEditorWidget.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileEditorWidget.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileItemGrid.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileManager.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileViewer.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/NewContextProfileWizard.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/resources/contextprofilelist.properties
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/BasePageList.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfileItem.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfilePageList.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RepositoryItem.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/resources/node_type_definitions/contextprofile_node_type.cnd
Modified:
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerLayoutManager.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerNodeConfig.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryService.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryServiceAsync.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rulelist/AssetItemGrid.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/security/Capabilities.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/RepositoryServiceServlet.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/RowLoader.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/TableDisplayHandler.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/test/java/org/drools/guvnor/server/util/TableDisplayHandlerTest.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetItem.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetPageList.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/JackrabbitRepositoryConfigurator.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RulesRepository.java
   labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/test/java/org/drools/repository/events/MockLoadEvent.java
Log:
drools-server gui on guvnor: server panel. context profile creation wizard. context profile editor

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerLayoutManager.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerLayoutManager.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerLayoutManager.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -123,6 +123,10 @@
             accordion.add(new DeploymentPanel(centertabbedPanel));
         }
 
+        if (shouldShow(Capabilities.SHOW_SERVER)) {
+        	accordion.add(new ServerPanel(centertabbedPanel));
+        }
+
         if (shouldShow(Capabilities.SHOW_ADMIN)) {
             accordion.add(new AdministrationPanel(centertabbedPanel));
         }

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerNodeConfig.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerNodeConfig.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerNodeConfig.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -119,7 +119,27 @@
 		}
 		return adminNode;
 	}
+	
+	public static TreeNode getServerStructure() {
 
+		TreeNode serverNode = new TreeNode(constants.DroolsServer());
+
+		String[][] adminStructure = new String[][] {
+				{ constants.ContextProfiles(), "images/category_small.gif", "0"},
+				{ constants.Servers(), "images/information.gif", "1" }};
+
+		for (int i = 0; i < adminStructure.length; i++) {
+
+			String[] packageData = adminStructure[i];
+			TreeNode localChildNode = new TreeNode(packageData[0]);
+			localChildNode.setAttribute("icon", packageData[1]);   //NON-NLS
+			localChildNode.setAttribute("id", packageData[2]);
+
+			serverNode.appendChild(localChildNode);
+		}
+		return serverNode;
+	}
+
 	public static TreeNode getRulesStructure () {
 		TreeNode tn = new TreeNode();
 		tn.setText(constants.AssetsTreeView());

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -12,6 +12,7 @@
 import org.drools.guvnor.client.packages.PackageEditor2;
 import org.drools.guvnor.client.packages.SnapshotView;
 import org.drools.guvnor.client.packages.SuggestionCompletionCache;
+import org.drools.guvnor.client.rpc.ContextProfile;
 import org.drools.guvnor.client.rpc.PackageConfigData;
 import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
 import org.drools.guvnor.client.rpc.RuleAsset;
@@ -22,6 +23,7 @@
 import org.drools.guvnor.client.ruleeditor.RuleViewer;
 import org.drools.guvnor.client.rulelist.EditItemEvent;
 import org.drools.guvnor.client.rulelist.QueryWidget;
+import org.drools.guvnor.client.server.ContextProfileViewer;
 
 import com.google.gwt.core.client.GWT;
 import com.google.gwt.user.client.Command;
@@ -421,4 +423,35 @@
         }
     }
 
+	public void openContextProfile(String uuid) {
+		if (!showIfOpen(uuid)) {
+            LoadingPopup.showMessage(constants.LoadingContextProfile());
+            RepositoryServiceFactory.getService().loadContextProfile(uuid,
+                                                                     new GenericCallback<ContextProfile>() {
+                                                                         public void onSuccess(final ContextProfile cp) {
+                                                                        	 EditItemEvent edit = new EditItemEvent() {
+                                                                        		 public void open(String key) {
+                                                                        			 openAsset(key);
+                                                                        		 }
+                                                                        		 public void open(MultiViewRow[] rows) {
+                                                                        			 for (MultiViewRow row : rows) {
+                                                                        				 openAsset(row.uuid);
+                                                                        			 }
+                                                                        		 }
+                                                                        	 };
+                                                                             ContextProfileViewer cpv = new ContextProfileViewer(cp, edit);
+                                                                             addTab(cp.id, true, cpv, cp.uuid);
+                                                                             cpv.setCloseCommand(new Command() {
+                                                                                 public void execute() {
+                                                                                     close(cp.uuid);
+                                                                                 }
+                                                                             });
+                                                                             LoadingPopup.close();
+                                                                         }
+                                                                     } );
+
+        }
+		
+	}
+
 }

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ServerPanel.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ServerPanel.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ServerPanel.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,110 @@
+package org.drools.guvnor.client.explorer;
+
+import org.drools.guvnor.client.common.GenericCallback;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.rpc.TableConfig;
+import org.drools.guvnor.client.ruleeditor.MultiViewRow;
+import org.drools.guvnor.client.rulelist.AssetItemGrid;
+import org.drools.guvnor.client.rulelist.AssetItemGridDataLoader;
+import org.drools.guvnor.client.rulelist.EditItemEvent;
+import org.drools.guvnor.client.server.ContextProfileItemGrid;
+import org.drools.guvnor.client.server.ContextProfileManager;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.widgets.tree.TreeNode;
+import com.gwtext.client.widgets.tree.TreePanel;
+import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
+
+/**
+ * Server Panel items
+ * 
+ * @author Lucas Amador
+ */
+public class ServerPanel extends GenericPanel {
+
+	private static Constants constants = GWT.create(Constants.class);
+
+	/** Table set up for the context profile */
+	static {
+		TableConfig conf = new TableConfig();
+		conf.headers = new String[3];
+		conf.headers[0] = constants.Name(); // "ID ";
+		conf.headers[1] = constants.SessionType(); // "Session Type ";
+		conf.headers[2] = constants.LastModified(); // "Last Modified ";
+		conf.headerTypes = new String[3];
+		conf.headerTypes[0] = "class java.lang.String";
+		conf.headerTypes[1] = "class java.lang.String";
+		conf.headerTypes[2] = "class java.util.Calendar";
+		conf.rowsPerPage = 100;
+		AssetItemGrid.registerTableConf(conf, ContextProfileItemGrid.CONTEXT_PROFILE_LIST_TABLE_ID);
+	}
+
+	public ServerPanel(ExplorerViewCenterPanel tabbedPanel) {
+		super(constants.DroolsServer(), tabbedPanel);
+		setIconCls("nav-admin"); //NON-NLS
+
+		TreePanel serverTree = basicTreeStructure(ExplorerNodeConfig.getServerStructure(), new TreePanelListenerAdapter() {
+			public void onClick(TreeNode self, EventObject e) {
+				int id = Integer.parseInt(self.getAttribute("id"));
+				switch (id) {
+				case 0:
+					if (!centertabbedPanel.showIfOpen("seredi")) { //NON-NLS
+						centertabbedPanel.addTab(constants.ContextProfiles(), true, new ContextProfileManager(centertabbedPanel), "seredi");      //NON-NLS
+					}
+					break;
+				case 1:
+					openContextProfile("serpro");
+					break;
+				}
+			}
+		});
+		serverTree.setRootVisible(false);
+
+		VerticalPanel serverPanel = new VerticalPanel();
+		serverPanel.add(serverTree);
+		serverPanel.setWidth("100%");
+		add(serverPanel);
+	}
+
+	private void openContextProfile(String id) {
+		final String key = id;
+		if (!centertabbedPanel.showIfOpen(key)) {
+			AssetItemGridDataLoader dataLoader = new AssetItemGridDataLoader() {
+				public void loadData(int skip, int numberOfRows, GenericCallback cb) {
+					RepositoryServiceFactory.getService().loadContextProfiles(key, skip, numberOfRows,ContextProfileItemGrid.CONTEXT_PROFILE_LIST_TABLE_ID, cb);
+				}
+			};
+			final ContextProfileItemGrid list = new ContextProfileItemGrid(createEditEvent(),
+																		ContextProfileItemGrid.CONTEXT_PROFILE_LIST_TABLE_ID,
+																		dataLoader,
+																		GWT.getModuleBaseURL() + "feed/category?name=" + key + "&viewUrl=" + getSelfURL());
+			centertabbedPanel.addTab(constants.ContextProfiles() + ": "+ key, true, list, key);
+		}
+	}
+
+	private EditItemEvent createEditEvent() {
+		return new EditItemEvent() {
+			public void open(String uuid) {
+				centertabbedPanel.openContextProfile(uuid);
+			}
+			public void open(MultiViewRow[] rows) {
+				for (MultiViewRow row: rows) {
+					centertabbedPanel.openContextProfile( row.uuid );
+				}
+			}
+		};
+	}
+
+	public static String getSelfURL() {
+		String selfURL = Window.Location.getHref();
+		if (selfURL.contains("#")) {
+			selfURL = selfURL.substring(0, selfURL.indexOf("#"));
+		}
+		return selfURL;
+	}
+
+}


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ServerPanel.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -2052,4 +2052,24 @@
     String Promoted();  
     
     String ItemAlreadyInGlobalArea();  
+    
+    String DroolsServer();
+    
+    String ContextProfiles();
+    
+    String Servers();
+
+	String NewContextProfile();
+
+	String NewServerConnection();
+
+	String ContextProfileName();
+
+	String SessionType();
+
+	String CreateContextProfile();
+
+	String LoadingContextProfile();
+
+	String ContextProfileLabel();
 }

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/messages/Constants.properties	2010-03-11 19:10:25 UTC (rev 32042)
@@ -979,4 +979,14 @@
 PromoteToGlobal=Promote to Global
 PromoteAreYouSure=Are you sure you want to promote this item to global area?
 Promoted=The item has been moved to global area. 
-ItemAlreadyInGlobalArea=The item is already in global area.
\ No newline at end of file
+ItemAlreadyInGlobalArea=The item is already in global area.
+DroolsServer=Drools Server
+ContextProfiles=Context Profiles
+Servers=Servers
+NewContextProfile=New Context Profile
+NewServerConnection=New Server Connection
+ContextProfileName=Name
+SessionType=SessionType
+CreateContextProfile=Create Context Profile
+LoadingContextProfile=Loading context profile...
+ContextProfileLabel=Context Profile: {0}
\ No newline at end of file

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/ContextProfile.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/ContextProfile.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/ContextProfile.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,29 @@
+package org.drools.guvnor.client.rpc;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+import java.io.Serializable;
+
+import org.drools.guvnor.client.modeldriven.brl.PortableObject;
+
+/**
+ * This is the "payload" of a context profile.
+ * Includes the meta data.
+ * 
+ * @author Lucas Amador
+ */
+public class ContextProfile implements Serializable, IsSerializable {
+
+	private static final long serialVersionUID = 1L;
+
+	public String uuid;
+	public String id;
+	public String sessionType;
+	public MetaData metaData;
+	public PortableObject content;
+
+	public long getVersionNumber() {
+		return metaData.versionNumber;
+	}
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/ContextProfile.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryService.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryService.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryService.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -21,6 +21,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.drools.guvnor.client.common.GenericCallback;
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.guvnor.client.modeldriven.testing.Scenario;
 
@@ -568,4 +569,12 @@
     public SnapshotDiffs compareSnapshots(String packageName,
                                           String firstSnapshotName,
                                           String secondSnapshotName);
+    
+    
+    public TableDataResult loadContextProfiles(String contextProfilePath, int skip, int numRows, String tableConfig) throws SerializableException;
+    
+    public String createContextProfile(String id, String sessionType);
+    
+    public ContextProfile loadContextProfile(String uuid);
+    
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryServiceAsync.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryServiceAsync.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/RepositoryServiceAsync.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -17,13 +17,11 @@
 
 
 
+import org.drools.guvnor.client.common.GenericCallback;
+
 import com.google.gwt.user.client.rpc.AsyncCallback;
 import com.google.gwt.user.client.rpc.RemoteService;
 
-import java.util.List;
-
-import org.drools.guvnor.client.common.GenericCallback;
-
 /**
 
  * This is what the remote service will implement, as a servlet.
@@ -118,6 +116,8 @@
     public void loadInbox(java.lang.String p0, AsyncCallback<org.drools.guvnor.client.rpc.TableDataResult> cb);
     public void compareSnapshots(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback<org.drools.guvnor.client.rpc.SnapshotDiffs> cb);
 
+    public void loadContextProfiles(java.lang.String p0, int p1, int p2, java.lang.String p3, AsyncCallback<org.drools.guvnor.client.rpc.TableDataResult> cb);
+    public void createContextProfile(java.lang.String p0, java.lang.String p1, AsyncCallback<java.lang.Object> cb);
+	public void loadContextProfile(java.lang.String uuid, com.google.gwt.user.client.rpc.AsyncCallback<org.drools.guvnor.client.rpc.ContextProfile> arg2);
 
-
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rulelist/AssetItemGrid.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rulelist/AssetItemGrid.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/rulelist/AssetItemGrid.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -76,21 +76,21 @@
     private static final Map<String, RecordDef>    recordDefs                  = new HashMap();
     private static final Map<String, Integer>    rowsPerPage                 = new HashMap();
 
-    private final EditItemEvent editEvent;
-    private SimplePanel         layout;
-    private Command             refresh;
+    protected final EditItemEvent editEvent;
+    protected SimplePanel         layout;
+    protected Command             refresh;
 
     /**
      * Used for tracking paging.
      */
-    private Stack<Integer>      cursorPositions             = getPositionStack();
+    protected Stack<Integer>      cursorPositions             = getPositionStack();
 
-    private int                 currentCursorPosition       = 0;
+    protected int                 currentCursorPosition       = 0;
 
     protected Store             store;
-    private GridPanel           currentGrid;
-    private static Constants constants = GWT.create(Constants.class);
-    private String feedURL;
+    protected GridPanel           currentGrid;
+    protected static Constants constants = GWT.create(Constants.class);
+    protected String feedURL;
     private Command unloadHook;
 
 
@@ -204,8 +204,7 @@
                                  }
                                  MemoryProxy proxy = new MemoryProxy( gridData );
                                  ArrayReader reader = new ArrayReader( rd );
-                                 store = new Store( proxy,
-                                                    reader );
+                                 store = new Store( proxy, reader );
                                  //currentGrid = new Grid(Ext.generateId(), "600px", "600px", store, cm);
                                  currentGrid = new GridPanel( store,
                                                               cm );
@@ -513,4 +512,9 @@
         super.onUnload();
         if (unloadHook != null) unloadHook.execute();
     }
+
+	public void setFeedURL(String feedURL) {
+		this.feedURL = feedURL;
+	}
+
 }
\ No newline at end of file

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/security/Capabilities.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/security/Capabilities.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/security/Capabilities.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -27,6 +27,7 @@
 	public static final Integer	SHOW_QA = 5; //if they have any package perms
 	public static final Integer	SHOW_DEPLOYMENT = 6; //if they are package admin??
 	public static final Integer SHOW_DEPLOYMENT_NEW = 7; //can create a new depl, rename etc...
+	public static final Integer	SHOW_SERVER = 8; //if they have any servers perms
 
 	public List<Integer> list = new ArrayList<Integer>();
 
@@ -49,6 +50,7 @@
 		cp.list.add(SHOW_QA);
 		cp.list.add(SHOW_DEPLOYMENT);
 		cp.list.add(SHOW_DEPLOYMENT_NEW);
+		cp.list.add(SHOW_SERVER);
         cp.prefs = prefs;
 
 		return cp;

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileDocEditorWidget.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileDocEditorWidget.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileDocEditorWidget.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,61 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.common.DirtyableComposite;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.rpc.ContextProfile;
+import org.drools.guvnor.client.rpc.MetaData;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.ui.ChangeListener;
+import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.gwtext.client.widgets.Panel;
+
+public class ContextProfileDocEditorWidget extends DirtyableComposite {
+
+	private TextArea text;
+	private Constants constants = ((Constants) GWT.create(Constants.class));
+
+	public ContextProfileDocEditorWidget(final ContextProfile contextProfile) {
+		MetaData data = contextProfile.metaData;
+		text = new TextArea();
+		text.setWidth( "100%" );
+		text.setVisibleLines( 5 );
+		text.setStyleName( "rule-viewer-Documentation" ); //NON-NLS
+		text.setTitle(constants.RuleDocHint());
+		
+		Panel p = new Panel();
+		p.setCollapsible( true );
+		p.setTitle( constants.Description() + ":" );
+		p.setBodyBorder(false);
+
+		if (data.description == null || data.description.equals("") || data.description.equals("<documentation>")) {
+			p.setCollapsed(true);
+		}
+		p.add(text);
+
+		final VerticalPanel vp = new VerticalPanel();
+		vp.add(p);
+
+		vp.setWidth("100%");
+
+		loadData(data);
+
+		initWidget(vp);
+	}
+
+	private void loadData(final MetaData data) {
+		text.setText(data.description);
+		text.addChangeListener( new ChangeListener() {
+			public void onChange(Widget w) {
+				data.description = text.getText();
+				makeDirty();
+			}
+		});
+		if (data.description == null || "".equals(data.description )) {
+			text.setText(constants.documentationDefault());
+		}
+	}
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileDocEditorWidget.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileEditorWidget.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileEditorWidget.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileEditorWidget.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,66 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.common.DirtyableComposite;
+import org.drools.guvnor.client.rpc.ContextProfile;
+
+import com.google.gwt.user.client.ui.ChangeListener;
+import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
+import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * Default Context Profile editor
+ * @author Lucas Amador
+ */
+public class ContextProfileEditorWidget extends DirtyableComposite {
+
+	private TextArea              text;
+	private ContextProfile contextProfile;
+
+	public ContextProfileEditorWidget(ContextProfile cp, ContextProfileViewer v) {
+		this(cp);
+	}
+
+	public ContextProfileEditorWidget(ContextProfile cp) {
+		this(cp, -1);
+	}
+
+	public ContextProfileEditorWidget(ContextProfile cp, int visibleLines) {
+		this.contextProfile = cp;
+
+		this.text = new TextArea();
+		this.text.setWidth( "100%" );
+		this.text.setVisibleLines((visibleLines == -1) ?  16 : visibleLines );
+		this.text.setText( cp.id + "\n" + cp.sessionType );
+
+		this.text.getElement().setAttribute("spellcheck", "false");    //NON-NLS
+		this.text.setStyleName("default-text-Area"); //NON-NLS
+
+		this.text.addChangeListener(new ChangeListener() {
+			public void onChange(Widget w) {
+				makeDirty();
+			}
+		});
+
+		this.text.addKeyboardListener(new KeyboardListenerAdapter() {
+			public void onKeyDown(Widget arg0, char arg1, int arg2) {
+				if (arg1 == KEY_TAB) {
+					int pos = text.getCursorPos();
+					insertText("\t");
+					text.setCursorPos(pos + 1);
+					text.cancelKey();
+					text.setFocus(true);
+				}
+			}
+		});
+		initWidget(text);
+	}
+
+	void insertText(String ins) {
+		int i = text.getCursorPos();
+		String left = text.getText().substring(0, i);
+		String right = text.getText().substring(i, text.getText().length());
+		text.setText(left + ins + right);
+	}
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileEditorWidget.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileItemGrid.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileItemGrid.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileItemGrid.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,20 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.rulelist.AssetItemGrid;
+import org.drools.guvnor.client.rulelist.AssetItemGridDataLoader;
+import org.drools.guvnor.client.rulelist.EditItemEvent;
+
+public class ContextProfileItemGrid extends AssetItemGrid {
+
+	public static final String  CONTEXT_PROFILE_LIST_TABLE_ID          = "contextprofilelist";
+
+	public ContextProfileItemGrid(EditItemEvent event, String tableConfig, AssetItemGridDataLoader source) {
+		super(event, tableConfig, source);
+	}
+
+	public ContextProfileItemGrid(EditItemEvent event, String tableConfig, AssetItemGridDataLoader source, String feedURL) {
+		super(event, tableConfig, source);
+		setFeedURL(feedURL);
+	}
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileItemGrid.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileManager.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileManager.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileManager.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,86 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.common.GenericCallback;
+import org.drools.guvnor.client.common.PrettyFormLayout;
+import org.drools.guvnor.client.explorer.ExplorerViewCenterPanel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.rpc.TableDataResult;
+import org.drools.guvnor.client.ruleeditor.MultiViewRow;
+import org.drools.guvnor.client.rulelist.AssetItemGridDataLoader;
+import org.drools.guvnor.client.rulelist.EditItemEvent;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.gwtext.client.core.EventObject;
+import com.gwtext.client.widgets.Button;
+import com.gwtext.client.widgets.Toolbar;
+import com.gwtext.client.widgets.ToolbarButton;
+import com.gwtext.client.widgets.event.ButtonListenerAdapter;
+
+/**
+ * @author Lucas Amador
+ */
+
+public class ContextProfileManager extends Composite {
+
+	private ContextProfileItemGrid grid;
+    private Constants constants = GWT.create(Constants.class);
+
+    public ContextProfileManager(final ExplorerViewCenterPanel tab) {
+
+        PrettyFormLayout pf = new PrettyFormLayout();
+
+        VerticalPanel header = new VerticalPanel();
+        header.add(new HTML(constants.ContextProfiles()));
+
+        pf.addHeader("images/backup_large.png", header); //NON-NLS
+
+        EditItemEvent edit = new EditItemEvent () {
+            public void open(String key) {
+            	tab.openContextProfile(key);
+            }
+
+            public void open(MultiViewRow[] rows) {
+                for (MultiViewRow row : rows) {
+                    tab.openContextProfile(row.uuid);
+                }
+            }
+        };
+        AssetItemGridDataLoader dataLoader = new AssetItemGridDataLoader() {
+			public void loadData(int skip, int numberOfRows, GenericCallback<TableDataResult> cb) {
+				RepositoryServiceFactory.getService().loadContextProfiles("CHECK", skip, numberOfRows, ContextProfileItemGrid.CONTEXT_PROFILE_LIST_TABLE_ID, cb);
+			}
+		};
+        
+        grid = new ContextProfileItemGrid(edit, ContextProfileItemGrid.CONTEXT_PROFILE_LIST_TABLE_ID, dataLoader);
+
+        Toolbar tb = new Toolbar();
+        final ToolbarButton restoreAsset = new ToolbarButton();
+        restoreAsset.setText(constants.CreateContextProfile());
+        tb.addButton(restoreAsset);
+        restoreAsset.addListener(new ButtonListenerAdapter() {
+        	public void onClick(Button button, EventObject e) {
+        		NewContextProfileWizard wizard = new NewContextProfileWizard(tab, new Command() {
+                    public void execute() {
+                        // Show the Context Profile tab. REFRESH
+                    	System.out.println("EXECUTED");
+                    }
+                });
+                wizard.show();
+        	};
+        });
+
+        pf.startSection(constants.ContextProfiles());
+        pf.addRow(tb);
+
+        pf.addRow(grid);
+        pf.endSection();
+        
+        initWidget( pf );
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileManager.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileViewer.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileViewer.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileViewer.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,472 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.common.AssetFormats;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.GenericCallback;
+import org.drools.guvnor.client.common.LoadingPopup;
+import org.drools.guvnor.client.common.RulePackageSelector;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.packages.SuggestionCompletionCache;
+import org.drools.guvnor.client.rpc.ContextProfile;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.ruleeditor.ActionToolbar;
+import org.drools.guvnor.client.ruleeditor.GuvnorEditor;
+import org.drools.guvnor.client.ruleeditor.MetaDataWidget;
+import org.drools.guvnor.client.ruleeditor.NewAssetWizard;
+import org.drools.guvnor.client.ruleeditor.RuleDocumentWidget;
+import org.drools.guvnor.client.ruleeditor.SaveEventListener;
+import org.drools.guvnor.client.rulelist.EditItemEvent;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+import com.gwtext.client.util.Format;
+
+/**
+ *
+ * @author Lucas Amador
+ */
+public class ContextProfileViewer extends GuvnorEditor {
+
+    private Command closeCommand;
+    public Command checkedInCommand;
+    public ActionToolbar.CheckinAction checkInCommand;
+    protected ContextProfile contextProfile;
+
+    private boolean readOnly;
+
+    private boolean metaVisible = true;
+    private boolean docoVisible = true;
+    private MetaDataWidget metaWidget;
+    private ContextProfileDocEditorWidget doc;
+    private Widget editor;
+    
+    private ActionToolbar toolbar;
+    private VerticalPanel layout;
+    private HorizontalPanel hsp;
+
+    private long lastSaved = System.currentTimeMillis();
+    private Constants constants = ((Constants) GWT.create(Constants.class));
+
+    private final EditItemEvent editEvent;
+
+    public ContextProfileViewer(ContextProfile cp, final EditItemEvent event) {
+        this(cp, event, false);
+    }
+
+    public ContextProfileViewer(ContextProfile cp, final EditItemEvent event, boolean historicalReadOnly) {
+        this.editEvent = event;
+        this.contextProfile = cp;
+        this.readOnly = historicalReadOnly;
+        
+        this.editor = new ContextProfileEditorWidget(cp, this);
+
+        this.layout = new VerticalPanel();
+
+        layout.setWidth("100%");
+        layout.setHeight("100%");
+
+        this.checkInCommand = new ActionToolbar.CheckinAction() {
+            public void doCheckin(String comment) {
+                if (editor instanceof SaveEventListener) {
+                    ((SaveEventListener) editor).onSave();
+                }
+                performCheckIn( comment );
+                if (editor instanceof SaveEventListener) {
+                    ((SaveEventListener) editor).onAfterSave();
+                }
+                if (checkedInCommand != null) {
+                    checkedInCommand.execute();
+                }
+                lastSaved = System.currentTimeMillis();
+                resetDirty();
+            }
+        };
+
+        initWidget(layout);
+        doWidgets(null);
+        LoadingPopup.close();
+    }
+
+    public void setDocoVisible(boolean docoVisible) {
+        this.docoVisible = docoVisible;
+        this.doc.setVisible( docoVisible );
+    }
+
+    public void setMetaVisible(boolean metaVisible) {
+        this.metaVisible = metaVisible;
+        this.metaWidget.setVisible( metaVisible );
+    }
+
+    public boolean isDirty() {
+        return (System.currentTimeMillis() - lastSaved) > 3600000;
+    }
+
+    /**
+     * This will actually load up the data (this is called by the callback)
+     * when we get the data back from the server,
+     * also determines what widgets to load up).
+     */
+    private void doWidgets(Widget messageWidget) {
+        layout.clear();
+
+//        toolbar = new ActionToolbar( asset,
+//                                     readOnly,
+//                                     editor,                                     
+//                                     checkInCommand,
+//                                     new ActionToolbar.CheckinAction() {
+//                                         public void doCheckin(String comment) {
+//                                             doArchive( comment );
+//                                         }
+//                                     },
+//                                     new Command() {
+//                                         public void execute() {
+//                                             doDelete();
+//                                         }
+//                                     },
+//                                     new Command() {
+//                                         public void execute() {
+//                                             close();
+//                                         }
+//                                     },
+//                                     new Command() {
+//                                         public void execute() {
+//                                             doCopy();
+//                                         }
+//                                     }, 
+//                                     new Command() {
+//                                         public void execute() {
+//                                             doPromptToGlobal();
+//                                         }
+//                                     });
+
+//        layout.add( toolbar );
+//        layout.setCellHeight( toolbar,
+//                              "30px" );
+//        layout.setCellHorizontalAlignment( toolbar,
+//                                           HasHorizontalAlignment.ALIGN_LEFT );
+//        layout.setCellWidth( toolbar,
+//                             "100%" );
+
+        if (messageWidget != null) {
+            layout.add(messageWidget);
+        }
+
+        doMetaWidget();
+
+        hsp = new HorizontalPanel();
+
+        layout.add(hsp);
+
+        // the bottom documentation widget
+        doc = new ContextProfileDocEditorWidget(contextProfile);
+        doc.setVisible(docoVisible);
+
+        VerticalPanel vert = new VerticalPanel();
+        vert.add(editor);
+        editor.setHeight("100%");
+        vert.setWidth("100%");
+        vert.setHeight("100%");
+
+        hsp.add(vert);
+        hsp.add(metaWidget);
+        hsp.setCellWidth(metaWidget, "25%");
+        hsp.setHeight("100%");
+
+        layout.add(doc);
+        
+    }
+
+    private void doMetaWidget() {
+        metaWidget = new MetaDataWidget(this.contextProfile.metaData,
+                                        readOnly,
+                                        this.contextProfile.uuid,
+                                        new Command() {
+                                        	public void execute() {
+                                        		refreshMetaWidgetOnly();
+                                            }
+                                        },
+                                        new Command() {
+                                            public void execute() {
+                                                refreshDataAndView();
+                                            }
+                                        });
+        metaWidget.setVisible(metaVisible);
+    }
+
+    protected boolean hasDirty() {
+        //not sure how to implement this now.
+        return false;
+    }
+
+    /** closes itself */
+    private void close() {
+        closeCommand.execute();
+    }
+
+    void doDelete() {
+        readOnly = true; //set to not cause the extra confirm popup
+        RepositoryServiceFactory.getService().deleteUncheckedRule( this.contextProfile.uuid,
+                                                                   this.contextProfile.metaData.packageName,
+                                                                   new GenericCallback() {
+                                                                       public void onSuccess(Object o) {
+                                                                           close();
+                                                                       }
+                                                                   } );
+    }
+
+    /**
+     * This responds to the checkin command.
+     */
+
+    private void doArchive(String comment) {
+        this.readOnly = true; //set to read only to not bother with the close warning
+//        this.contextProfile.archived = true;
+        this.performCheckIn( comment );
+        this.closeCommand.execute();
+    }
+
+    private void performCheckIn(String comment) {
+        this.contextProfile.metaData.checkinComment = comment;
+        final boolean[] saved = {false};
+        Timer t = new Timer() {
+            public void run() {
+                if ( !saved[0] ) LoadingPopup.showMessage( constants.SavingPleaseWait() );
+            }
+        };
+        t.schedule( 500 );
+
+//        RepositoryServiceFactory.getService().checkinVersion( this.contextProfile,
+//                                                              new GenericCallback<String>() {
+//
+//                                                                  public void onSuccess(String uuid) {
+//                                                                      if ( uuid == null ) {
+//                                                                          ErrorPopup.showMessage( constants.FailedToCheckInTheItemPleaseContactYourSystemAdministrator() );
+//                                                                          return;
+//                                                                      }
+//
+//                                                                      if ( uuid.startsWith( "ERR" ) ) { //NON-NLS
+//                                                                          ErrorPopup.showMessage( uuid.substring( 5 ) );
+//                                                                          return;
+//                                                                      }
+//
+//                                                                      flushSuggestionCompletionCache();
+//
+//                                                                      if ( editor instanceof DirtyableComposite ) {
+//                                                                          ((DirtyableComposite) editor).resetDirty();
+//                                                                      }
+//
+//                                                                      doco.resetDirty();
+//
+//                                                                      // No need to refresh if we are archiving
+//                                                                      if ( contextProfile.archived ) {
+//                                                                          LoadingPopup.close();
+//                                                                      } else {
+//                                                                          refreshMetaWidgetOnly( false );
+//                                                                      }
+//                                                                      LoadingPopup.close();
+//                                                                      saved[0] = true;
+//
+//                                                                      toolbar.showSavedConfirmation();
+//                                                                  }
+//                                                              } );
+    }
+
+    /**
+     * In some cases we will want to flush the package dependency stuff for suggestion completions.
+     * The user will still need to reload the asset editor though.
+     */
+    public void flushSuggestionCompletionCache() {
+        if ( AssetFormats.isPackageDependency( this.contextProfile.metaData.format ) ) {
+            LoadingPopup.showMessage( constants.RefreshingContentAssistance() );
+            SuggestionCompletionCache.getInstance().refreshPackage( this.contextProfile.metaData.packageName,
+                                                                    new Command() {
+                                                                        public void execute() {
+                                                                            LoadingPopup.close();
+                                                                        }
+                                                                    } );
+        }
+    }
+
+    /**
+     * This will reload the contents from the database, and refresh the widgets.
+     */
+    public void refreshDataAndView() {
+        refreshDataAndView( null );
+    }
+
+    public void refreshDataAndView(final Widget messageWidget) {
+        LoadingPopup.showMessage( constants.RefreshingItem() );
+//        RepositoryServiceFactory.getService().loadRuleAsset( contextProfile.uuid,
+//                                                             new GenericCallback<RuleAsset>() {
+//                                                                 public void onSuccess(RuleAsset asset_) {
+//                                                                     contextProfile = asset_;
+//                                                                     doWidgets( messageWidget );
+//                                                                     LoadingPopup.close();
+//                                                                 }
+//                                                             } );
+    }
+
+    /**
+     * This will only refresh the meta data widget if necessary.
+     */
+    public void refreshMetaWidgetOnly() {
+        refreshMetaWidgetOnly( true );
+    }
+
+    private void refreshMetaWidgetOnly(final boolean showBusy) {
+        if ( showBusy ) LoadingPopup.showMessage( constants.RefreshingItem() );
+        RepositoryServiceFactory.getService().loadRuleAsset( contextProfile.uuid,
+                                                             new GenericCallback<RuleAsset>() {
+                                                                 public void onSuccess(RuleAsset asset_) {
+                                                                     contextProfile.metaData = asset_.metaData;
+                                                                     hsp.remove( metaWidget );
+                                                                     doMetaWidget();
+                                                                     hsp.add( metaWidget );
+                                                                     hsp.setCellWidth( metaWidget,
+                                                                                       "25%" );
+                                                                     if ( showBusy ) LoadingPopup.close();
+                                                                 }
+                                                             } );
+    }
+
+    /**
+     * This needs to be called to allow the opened viewer to close itself.
+     * @param c
+     */
+    public void setCloseCommand(Command c) {
+        this.closeCommand = c;
+    }
+
+    /**
+     * This is called when this viewer saves something.
+     * @param c
+     */
+    public void setCheckedInCommand(Command c) {
+        this.checkedInCommand = c;
+    }
+
+    /**
+     * Called when user wants to close, but there is "dirtyness".
+     */
+    protected void doCloseUnsavedWarning() {
+        final FormStylePopup pop = new FormStylePopup( "images/warning-large.png", //NON-NLS
+                                                       constants.WARNINGUnCommittedChanges() );
+        Button dis = new Button( constants.Discard() );
+        Button can = new Button( constants.Cancel() );
+        HorizontalPanel hor = new HorizontalPanel();
+
+        hor.add( dis );
+        hor.add( can );
+
+        pop.addRow( new HTML( constants.AreYouSureYouWantToDiscardChanges() ) );
+        pop.addRow( hor );
+
+        dis.addClickListener( new ClickListener() {
+            public void onClick(Widget w) {
+                closeCommand.execute();
+                pop.hide();
+            }
+        } );
+
+        can.addClickListener( new ClickListener() {
+            public void onClick(Widget w) {
+                pop.hide();
+            }
+        } );
+
+        pop.show();
+    }
+
+    private void doCopy() {
+        final FormStylePopup form = new FormStylePopup( "images/rule_asset.gif",
+                                                        constants.CopyThisItem() );
+        final TextBox newName = new TextBox();
+        form.addAttribute( constants.NewName(),
+                           newName );
+        final RulePackageSelector sel = new RulePackageSelector();
+        form.addAttribute( constants.NewPackage(), sel );
+        
+        Button ok = new Button( constants.CreateCopy() );
+        ok.addClickListener( new ClickListener() {
+            public void onClick(Widget w) {
+                if ( newName.getText() == null || newName.getText().equals( "" ) ) {
+                    Window.alert( constants.AssetNameMustNotBeEmpty() );
+                    return;
+                }
+                String name = newName.getText().trim();
+                if ( !NewAssetWizard.validatePathPerJSR170( name ) ) {
+                    return;
+                }
+                RepositoryServiceFactory.getService().copyAsset( contextProfile.uuid,
+                		                                         sel.getSelectedPackage(),
+                                                                 name,
+                                                                 new GenericCallback<String>() {
+                                                                     public void onSuccess(String data) {
+                                                                         completedCopying( newName.getText(),
+                                                                        		           sel.getSelectedPackage(),
+                                                                                           data );
+                                                                         form.hide();
+                                                                     }
+
+                                                                     @Override
+                                                                     public void onFailure(Throwable t) {
+                                                                         if ( t.getMessage().indexOf( "ItemExistsException" ) > -1 ) { //NON-NLS
+                                                                             Window.alert( constants.ThatNameIsInUsePleaseTryAnother() );
+                                                                         } else {
+                                                                             super.onFailure( t );
+                                                                         }
+                                                                     }
+                                                                 } );
+            }
+        } );
+        form.addAttribute( "",
+                           ok );
+
+        //form.setPopupPosition((DirtyableComposite.getWidth() - form.getOffsetWidth()) / 2, 100);
+        form.show();
+    }
+
+    private void completedCopying(String name,
+                                  String pkg,
+                                  String newAssetUUID) {
+        Window.alert( Format.format( constants.CreatedANewItemSuccess(),
+                                     name,
+                                     pkg ) );
+        if ( editEvent != null ) {
+            editEvent.open( newAssetUUID );
+        }
+    }
+    
+    private void doPromptToGlobal() {
+        if (contextProfile.metaData.packageName.equals("globalArea")) {
+            Window.alert( constants.ItemAlreadyInGlobalArea() );
+            return;
+        }
+        if (Window.confirm(constants.PromoteAreYouSure()) ) {
+            RepositoryServiceFactory.getService().promoteAssetToGlobalArea(contextProfile.uuid,
+                    new GenericCallback<String>() {
+                        public void onSuccess(String data) {
+                            Window.alert(constants.Promoted());
+                            refreshMetaWidgetOnly();
+                        }
+
+                        @Override
+                        public void onFailure(Throwable t) {                           
+                            super.onFailure( t );
+                        }
+                    } );
+
+} ;
+ 	
+    }
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/ContextProfileViewer.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/NewContextProfileWizard.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/NewContextProfileWizard.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/NewContextProfileWizard.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,77 @@
+package org.drools.guvnor.client.server;
+
+import org.drools.guvnor.client.common.FormStyleLayout;
+import org.drools.guvnor.client.common.FormStylePopup;
+import org.drools.guvnor.client.common.GenericCallback;
+import org.drools.guvnor.client.explorer.ExplorerViewCenterPanel;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.ruleeditor.NewAssetWizard;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.ClickListener;
+import com.google.gwt.user.client.ui.ListBox;
+import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * The wizard used to create a new context profile
+ *
+ * @author Lucas Amador
+ */
+public class NewContextProfileWizard extends FormStylePopup {
+
+	private TextBox idTextBox;
+	private final FormStyleLayout newContextProfileLayout = new FormStyleLayout();
+	private ListBox sessionTypeListBox;
+	private static Constants constants = ((Constants) GWT.create(Constants.class));
+
+    public NewContextProfileWizard(final ExplorerViewCenterPanel tab, final Command afterCreatedEvent) {
+        super("images/new_wiz.gif", constants.NewContextProfile()); //NON-NLS
+        idTextBox = new TextBox();
+
+        sessionTypeListBox = new ListBox();
+        sessionTypeListBox.addItem("Stateless");
+        sessionTypeListBox.addItem("Stateful");
+        sessionTypeListBox.setSelectedIndex(0);
+
+        newContextProfileLayout.addAttribute(constants.ContextProfileName(), idTextBox);
+        newContextProfileLayout.addAttribute(constants.SessionType(), sessionTypeListBox);
+
+        idTextBox.setTitle(constants.PackageNameTip());
+
+        VerticalPanel ab = new VerticalPanel();
+        addAttribute("", ab);
+
+        addRow(newContextProfileLayout);
+
+        Button create = new Button(constants.CreateContextProfile());
+        create.addClickListener(new ClickListener() {
+            public void onClick(Widget w) {
+            	if (!NewAssetWizard.validatePathPerJSR170(idTextBox.getText())) {
+            		return;
+            	}
+				RepositoryServiceFactory.getService().createContextProfile(idTextBox.getText(),
+																			sessionTypeListBox.getItemText(sessionTypeListBox.getSelectedIndex()),
+																			new GenericCallback<Object>() {
+															            		public void onSuccess(Object data) {
+															            			String key = (String) data;
+															            			tab.openContextProfile(key);
+															            			hide();
+															            		}
+															            		@Override
+															            		public void onFailure(Throwable t) {
+															            			super.onFailure(t);
+															            		}
+															            	});
+            }
+        } );
+
+        newContextProfileLayout.addAttribute("", create);
+
+    }
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/client/server/NewContextProfileWizard.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/RepositoryServiceServlet.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/RepositoryServiceServlet.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/RepositoryServiceServlet.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -1,23 +1,23 @@
 package org.drools.guvnor.server;
 
-import com.google.gwt.user.client.rpc.SerializableException;
-import com.google.gwt.user.server.rpc.RemoteServiceServlet;
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.log4j.Logger;
-import org.drools.guvnor.client.rpc.*;
+import org.drools.guvnor.client.rpc.ContextProfile;
+import org.drools.guvnor.client.rpc.RepositoryService;
+import org.drools.guvnor.server.repository.MailboxService;
+import org.drools.guvnor.server.repository.RepositoryStartupService;
 import org.drools.guvnor.server.util.LoggingHelper;
 import org.drools.guvnor.server.util.TestEnvironmentSessionHelper;
-import org.drools.guvnor.server.repository.MailboxService;
-import org.drools.guvnor.server.repository.RepositoryStartupService;
 import org.drools.repository.RulesRepository;
 import org.drools.repository.RulesRepositoryException;
 import org.jboss.seam.Component;
 import org.jboss.seam.contexts.Contexts;
 import org.jboss.seam.security.AuthorizationException;
 
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
+import com.google.gwt.user.server.rpc.RemoteServiceServlet;
 
 /**
  * GWT RPC service endpoint for Repository service. A place to hang some exception handling mainly.
@@ -333,7 +333,14 @@
     public org.drools.guvnor.client.rpc.SnapshotDiffs compareSnapshots(java.lang.String p0, java.lang.String p1, java.lang.String p2)  {
          return getService().compareSnapshots( p0,  p1,  p2);
     }
+    public org.drools.guvnor.client.rpc.TableDataResult loadContextProfiles(java.lang.String p0, int p1, int p2, java.lang.String p3) throws com.google.gwt.user.client.rpc.SerializableException {
+    	return getService().loadContextProfiles( p0,  p1,  p2,  p3);
+    }
+	public String createContextProfile(String p0, String p1) {
+		return getService().createContextProfile(p0, p1);
+	}
+	public ContextProfile loadContextProfile(String p0) {
+		return getService().loadContextProfile(p0);
+	}
 
-
-
 }

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/ServiceImplementation.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+import static org.drools.guvnor.server.util.ClassicDRLImporter.getRuleName;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -54,11 +56,34 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.compiler.DrlParser;
 import org.drools.compiler.DroolsParserException;
+import org.drools.core.util.DroolsStreamUtils;
 import org.drools.guvnor.client.common.AssetFormats;
 import org.drools.guvnor.client.common.Inbox;
 import org.drools.guvnor.client.modeldriven.SuggestionCompletionEngine;
 import org.drools.guvnor.client.modeldriven.testing.Scenario;
-import org.drools.guvnor.client.rpc.*;
+import org.drools.guvnor.client.rpc.AnalysisReport;
+import org.drools.guvnor.client.rpc.BuilderResult;
+import org.drools.guvnor.client.rpc.BulkTestRunResult;
+import org.drools.guvnor.client.rpc.ContextProfile;
+import org.drools.guvnor.client.rpc.DetailedSerializableException;
+import org.drools.guvnor.client.rpc.DiscussionRecord;
+import org.drools.guvnor.client.rpc.LogEntry;
+import org.drools.guvnor.client.rpc.MetaData;
+import org.drools.guvnor.client.rpc.MetaDataQuery;
+import org.drools.guvnor.client.rpc.PackageConfigData;
+import org.drools.guvnor.client.rpc.PushResponse;
+import org.drools.guvnor.client.rpc.RepositoryService;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.rpc.ScenarioResultSummary;
+import org.drools.guvnor.client.rpc.ScenarioRunResult;
+import org.drools.guvnor.client.rpc.SingleScenarioResult;
+import org.drools.guvnor.client.rpc.SnapshotDiff;
+import org.drools.guvnor.client.rpc.SnapshotDiffs;
+import org.drools.guvnor.client.rpc.SnapshotInfo;
+import org.drools.guvnor.client.rpc.TableConfig;
+import org.drools.guvnor.client.rpc.TableDataResult;
+import org.drools.guvnor.client.rpc.TableDataRow;
+import org.drools.guvnor.client.rpc.ValidatedResponse;
 import org.drools.guvnor.server.builder.AuditLogReporter;
 import org.drools.guvnor.server.builder.BRMSPackageBuilder;
 import org.drools.guvnor.server.builder.ContentAssemblyError;
@@ -68,6 +93,8 @@
 import org.drools.guvnor.server.contenthandler.IRuleAsset;
 import org.drools.guvnor.server.contenthandler.IValidating;
 import org.drools.guvnor.server.contenthandler.ModelContentHandler;
+import org.drools.guvnor.server.repository.MailboxService;
+import org.drools.guvnor.server.repository.UserInbox;
 import org.drools.guvnor.server.security.AdminType;
 import org.drools.guvnor.server.security.CategoryPathType;
 import org.drools.guvnor.server.security.PackageNameType;
@@ -77,14 +104,11 @@
 import org.drools.guvnor.server.util.AssetFormatHelper;
 import org.drools.guvnor.server.util.AssetLockManager;
 import org.drools.guvnor.server.util.BRMSSuggestionCompletionLoader;
+import org.drools.guvnor.server.util.Discussion;
 import org.drools.guvnor.server.util.LoggingHelper;
 import org.drools.guvnor.server.util.MetaDataMapper;
 import org.drools.guvnor.server.util.TableDisplayHandler;
 import org.drools.guvnor.server.util.VerifierRunner;
-import org.drools.guvnor.server.util.Discussion;
-import static org.drools.guvnor.server.util.ClassicDRLImporter.*;
-import org.drools.guvnor.server.repository.UserInbox;
-import org.drools.guvnor.server.repository.MailboxService;
 import org.drools.lang.descr.PackageDescr;
 import org.drools.lang.descr.TypeDeclarationDescr;
 import org.drools.repository.AssetHistoryIterator;
@@ -92,6 +116,8 @@
 import org.drools.repository.AssetItemIterator;
 import org.drools.repository.AssetPageList;
 import org.drools.repository.CategoryItem;
+import org.drools.repository.ContextProfileItem;
+import org.drools.repository.ContextProfilePageList;
 import org.drools.repository.PackageItem;
 import org.drools.repository.PackageIterator;
 import org.drools.repository.RepositoryFilter;
@@ -106,7 +132,6 @@
 import org.drools.runtime.rule.ConsequenceException;
 import org.drools.testframework.RuleCoverageListener;
 import org.drools.testframework.ScenarioRunner;
-import org.drools.core.util.DroolsStreamUtils;
 import org.jboss.seam.annotations.AutoCreate;
 import org.jboss.seam.annotations.In;
 import org.jboss.seam.annotations.Name;
@@ -620,6 +645,14 @@
 
     }
 
+    MetaData populateMetaData(ContextProfileItem item) {
+        MetaData meta = populateMetaData( (VersionableItem) item );
+        meta.dateEffective = calendarToDate( item.getDateEffective() );
+        meta.dateExpired = calendarToDate( item.getDateExpired() );
+        return meta;
+
+    }
+
     private Date calendarToDate(Calendar createdDate) {
         if ( createdDate == null ) return null;
         return createdDate.getTime();
@@ -2753,4 +2786,42 @@
         diffs.diffs = list.toArray( new SnapshotDiff[list.size()] );
         return diffs;
     }
+
+    public TableDataResult loadContextProfiles(String contextProfilePath, int skip, int numRows, String tableConfig) throws SerializableException {
+    	// First check the user has permission to access this contextProfilePath.
+    	if ( Contexts.isSessionContextActive() ) {
+    		if ( !Identity.instance().hasPermission(new CategoryPathType(contextProfilePath), RoleTypes.ANALYST_READ)) {
+    			TableDisplayHandler handler = new TableDisplayHandler(tableConfig);
+    			return handler.loadRuleListTable( new ContextProfilePageList());
+    		}
+    	}
+
+    	ContextProfilePageList list = repository.findContextProfiles(numRows);
+    	TableDisplayHandler handler = new TableDisplayHandler(tableConfig, ContextProfileItem.class);
+    	// log.debug("time for load: " + (System.currentTimeMillis() - time) );
+    	return handler.loadRuleListTable(list);
+    }
+
+    public String createContextProfile(String id, String sessionType) {
+    	log.info( "USER:" + getCurrentUserName() + " CREATING context profile [" + id + "]" );
+    	ContextProfileItem item = repository.createContextProfile(id, sessionType);
+    	return item.getUUID();
+    }
+
+    public ContextProfile loadContextProfile(String uuid) {
+    	log.info( "USER:" + getCurrentUserName() + " LOADING context profile [" + uuid + "]" );
+
+    	long time = System.currentTimeMillis();
+
+    	ContextProfileItem item = repository.loadContextProfileByUUID(uuid);
+    	ContextProfile profile = new ContextProfile();
+    	profile.uuid = uuid;
+    	profile.id = item.getID();
+    	profile.sessionType = item.getSessionType();
+    	profile.metaData = populateMetaData(item);
+
+    	log.debug( ". Load time taken for context profile: " + (System.currentTimeMillis() - time) );
+
+    	return profile;
+    }
 }

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/RowLoader.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/RowLoader.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/RowLoader.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -5,19 +5,16 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
 import java.util.StringTokenizer;
 
-import org.drools.repository.AssetItem;
+import org.drools.repository.RepositoryItem;
 import org.drools.repository.RulesRepositoryException;
 
 public class RowLoader {
 
-
-    private static SimpleDateFormat DF = new SimpleDateFormat("yyyy-MM-dd");
     private String[] headers;
     private String[] headerTypes;
     List             extractors;
@@ -31,7 +28,7 @@
     }
 
 
-    public String[] getRow(AssetItem item) {
+    public String[] getRow(RepositoryItem item) {
         String[] row = new String[headers.length];
         for ( int i = 0; i < row.length; i++ ) {
             Method meth = (Method) extractors.get( i );
@@ -60,7 +57,7 @@
     }
 
 
-    public RowLoader(String resourcename) {
+    public RowLoader(String resourcename, Class<?> classType) {
 
         InputStream in = RowLoader.class.getResourceAsStream( "/" + resourcename + ".properties" );
         BufferedReader reader = new BufferedReader( new InputStreamReader( in ) );
@@ -79,8 +76,7 @@
                     String method = tok.nextToken();
                     fields.add( field );
 
-                    final Method meth = AssetItem.class.getMethod( method,
-                                                                   new Class[]{} );
+                    final Method meth = classType.getMethod( method, new Class[]{} );
 
                     extractors.add( meth );
 

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/TableDisplayHandler.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/TableDisplayHandler.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/java/org/drools/guvnor/server/util/TableDisplayHandler.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -28,6 +28,8 @@
 import org.drools.repository.AssetItem;
 import org.drools.repository.AssetItemIterator;
 import org.drools.repository.AssetPageList;
+import org.drools.repository.ContextProfileItem;
+import org.drools.repository.ContextProfilePageList;
 
 import com.google.gwt.user.client.rpc.SerializableException;
 
@@ -44,7 +46,7 @@
 	/** how many rows we show on a grid page */
 
     private static final int ROWS_PER_PAGE = 40;
-	private RowLoader          ASSET_LIST;
+	private RowLoader          ROW_LOADER_LIST;
 
 
     /**
@@ -55,8 +57,12 @@
      */
 
     public TableDisplayHandler(String tableconfig) {
-        ASSET_LIST = new RowLoader( tableconfig );
+        ROW_LOADER_LIST = new RowLoader( tableconfig , AssetItem.class);
     }
+    
+    public TableDisplayHandler(String tableconfig, Class<?> classType) {
+        ROW_LOADER_LIST = new RowLoader( tableconfig , classType);
+    }
 
     public TableDataResult loadRuleListTable(AssetPageList list) throws SerializableException {
         List<TableDataRow> data = loadRows(list.assets.iterator(), -1);
@@ -134,7 +140,7 @@
 
             row.id = r.getUUID();
             row.format = r.getFormat();
-            row.values = ASSET_LIST.getRow( r );
+            row.values = ROW_LOADER_LIST.getRow( r );
             data.add( row );
             if ( numRows != -1 ) {
                 if ( data.size() == numRows ) {
@@ -144,7 +150,27 @@
         }
 		return data;
 	}
+	
+	private List<TableDataRow> loadContextProfileRows(Iterator<ContextProfileItem> it, int numRows) {
+		List<TableDataRow> data = new ArrayList<TableDataRow>();
 
+        for ( Iterator<ContextProfileItem> iter = it; iter.hasNext(); ) {
+        	ContextProfileItem item = (ContextProfileItem) iter.next();
+            TableDataRow row = new TableDataRow();
+
+            row.id = item.getUUID();
+            row.format = item.getFormat();
+            row.values = ROW_LOADER_LIST.getRow( item );
+            data.add( row );
+            if ( numRows != -1 ) {
+                if ( data.size() == numRows ) {
+                    break;
+                }
+            }
+        }
+		return data;
+	}
+
     public String formatDate(Calendar cal) {
         DateFormat localFormat = DateFormat.getDateInstance();
 
@@ -154,9 +180,18 @@
     public TableConfig loadTableConfig() {
         final TableConfig config = new TableConfig();
 
-        config.headers = ASSET_LIST.getHeaders();
-        config.headerTypes = ASSET_LIST.getHeaderTypes();
+        config.headers = ROW_LOADER_LIST.getHeaders();
+        config.headerTypes = ROW_LOADER_LIST.getHeaderTypes();
         config.rowsPerPage = ROWS_PER_PAGE;
         return config;
     }
+
+	public TableDataResult loadRuleListTable(ContextProfilePageList list) {
+		List<TableDataRow> data = loadContextProfileRows(list.contextProfiles.iterator(), -1);
+        TableDataResult result = new TableDataResult();
+        result.data = (TableDataRow[]) data.toArray( new TableDataRow[data.size()] );
+        result.currentPosition  = list.currentPosition;
+        result.hasNext = list.hasNext;
+        return result;
+	}
 }

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/resources/contextprofilelist.properties
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/resources/contextprofilelist.properties	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/resources/contextprofilelist.properties	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,19 @@
+#
+# This is the configuration for the context profiles list table.
+# It can access any field on the ContextProfileItem object by the method name.
+# It will intelligently convert types as appropriate.
+#
+# If you wish to customise, you can put your own properties ahead of the
+# repository on the classpath.
+#
+# @author Lucas Amador
+#
+
+#these must stay the same.
+Name=getName
+Session Type=getSessionType
+LastModified=getLastModified
+
+#you can modify the following...
+#Status=getStateDescription
+#Categories=getCategorySummary


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/main/resources/contextprofilelist.properties
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/test/java/org/drools/guvnor/server/util/TableDisplayHandlerTest.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/test/java/org/drools/guvnor/server/util/TableDisplayHandlerTest.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-guvnor/src/test/java/org/drools/guvnor/server/util/TableDisplayHandlerTest.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -19,13 +19,15 @@
 
 import java.lang.reflect.Method;
 
+import org.drools.repository.AssetItem;
+
 import junit.framework.TestCase;
 
 public class TableDisplayHandlerTest extends TestCase {
 
     public void testRowLoaders() throws Exception {
 
-        RowLoader loader = new RowLoader("rulelist");
+        RowLoader loader = new RowLoader("rulelist", AssetItem.class);
 
         assertEquals(5, loader.getHeaders().length);
         String[] headers = loader.getHeaders();

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetItem.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetItem.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetItem.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -20,7 +20,7 @@
  * 
  * @author btruitt
  */
-public class AssetItem extends CategorisableItem {
+public class AssetItem extends CategorisableItem implements RepositoryItem {
 	private Logger log = Logger.getLogger(AssetItem.class);
 	/**
 	 * The name of the rule node type

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetPageList.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetPageList.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/AssetPageList.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -10,11 +10,9 @@
  *
  * @author Michael Neale
  */
-public class AssetPageList {
+public class AssetPageList extends BasePageList {
 
 	public final List<AssetItem> assets;
-	public final boolean hasNext;
-	public long currentPosition;
 
 	public AssetPageList(List<AssetItem> categories, RangeIterator it) {
 		this.assets = categories;

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/BasePageList.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/BasePageList.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/BasePageList.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,8 @@
+package org.drools.repository;
+
+public abstract class BasePageList {
+	
+	public boolean hasNext;
+	public long currentPosition;
+
+}


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/BasePageList.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfileItem.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfileItem.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfileItem.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,600 @@
+package org.drools.repository;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.Iterator;
+
+import javax.jcr.Node;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The ContextProfileItem class is used to abstract away the details of the underlying JCR
+ * repository. It is used to pass information about rules stored in the
+ * repository.
+ * 
+ * @author Lucas Amador
+ */
+public class ContextProfileItem extends CategorisableItem implements RepositoryItem {
+	private Logger log = Logger.getLogger(ContextProfileItem.class);
+	/**
+	 * The name of the rule node type
+	 */
+	public static final String CONTEXT_PROFILE_NODE_TYPE_NAME = "drools:contextProfileNodeType";
+
+	public static final String CONTENT_PROPERTY_ID = "drools:id";
+	
+	public static final String CONTENT_PROPERTY_SESSION_TYPE = "drools:sessionType";
+
+	public static final String CONTENT_PROPERTY_CONTENT = "drools:content";
+	
+	public static final String CONTENT_PROPERTY_BINARY_NAME = "drools:binaryContent";
+	public static final String CONTENT_PROPERTY_ATTACHMENT_FILENAME = "drools:attachmentFileName";
+
+	/**
+	 * The name of the date effective property on the rule node type
+	 */
+	public static final String DATE_EFFECTIVE_PROPERTY_NAME = "drools:dateEffective";
+
+	public static final String DISABLED_PROPERTY_NAME = "drools:disabled";
+
+	/**
+	 * The name of the date expired property on the rule node type
+	 */
+	public static final String DATE_EXPIRED_PROPERTY_NAME = "drools:dateExpired";
+
+	/**
+	 * Constructs a ContextProfileItem object, setting its node attribute to the specified
+	 * node.
+	 * 
+	 * @param rulesRepository
+	 *            the rulesRepository that instantiated this object
+	 * @param node
+	 *            the node in the repository that this RuleItem corresponds to
+	 * @throws RulesRepositoryException
+	 */
+	public ContextProfileItem(RulesRepository rulesRepository, Node node)
+			throws RulesRepositoryException {
+		super(rulesRepository, node);
+		try {
+			// make sure this node is a rule node
+			if (!(this.node.getPrimaryNodeType().getName().equals(
+					CONTEXT_PROFILE_NODE_TYPE_NAME) || isHistoricalVersion())) {
+				String message = this.node.getName()
+						+ " is not a node of type " + CONTEXT_PROFILE_NODE_TYPE_NAME
+						+ " nor nt:version. It is a node of type: "
+						+ this.node.getPrimaryNodeType().getName();
+				log.error(message);
+				throw new RulesRepositoryException(message);
+			}
+		} catch (Exception e) {
+			log.error("Caught exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	public ContextProfileItem() {
+		super(null, null);
+	}
+	
+	/**
+	 * Returns the context profile ID
+	 */
+	public String getID() throws RulesRepositoryException {
+		try {
+			Node ruleNode = getVersionContentNode();
+			if (ruleNode.hasProperty(CONTENT_PROPERTY_ID)) {
+				Property data = ruleNode.getProperty(CONTENT_PROPERTY_ID);
+				return data.getValue().getString();
+
+			} else {
+				return "";
+			}
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+	
+	/**
+	 * Returns the Session Type
+	 */
+	public String getSessionType() throws RulesRepositoryException {
+		try {
+			Node ruleNode = getVersionContentNode();
+			if (ruleNode.hasProperty(CONTENT_PROPERTY_SESSION_TYPE)) {
+				Property data = ruleNode.getProperty(CONTENT_PROPERTY_SESSION_TYPE);
+				return data.getValue().getString();
+			} else {
+				return "";
+			}
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * returns the string contents of the rule node. If this is a binary asset,
+	 * this will return null (use getBinaryContent instead).
+	 */
+	public String getContent() throws RulesRepositoryException {
+		return getContent(false);
+	}
+
+	/**
+	 * Only for use in the StorageEventManager, for passing the fromRepo
+	 * parameter
+	 * 
+	 * returns the string contents of the rule node. If this is a binary asset,
+	 * this will return null (use getBinaryContent instead).
+	 */
+	public String getContent(Boolean fromRepo) throws RulesRepositoryException {
+		try {
+
+//			 TODO: Add Event Manager feature to ContextProfileItem
+//			if (StorageEventManager.hasLoadEvent() && !fromRepo) {
+//				return IOUtils.toString(StorageEventManager.getLoadEvent()
+//						.loadContent(this));
+//			}
+
+			if (isBinary()) {
+				return new String(this.getBinaryContentAsBytes());
+			}
+			Node ruleNode = getVersionContentNode();
+			if (ruleNode.hasProperty(CONTENT_PROPERTY_CONTENT)) {
+				Property data = ruleNode.getProperty(CONTENT_PROPERTY_CONTENT);
+				return data.getValue().getString();
+
+			} else {
+				return "";
+			}
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * returns the number of bytes of the content.
+	 */
+	public long getContentLength() {
+		try {
+			Node ruleNode = getVersionContentNode();
+			if (ruleNode.hasProperty(CONTENT_PROPERTY_BINARY_NAME)) {
+				Property data = ruleNode
+						.getProperty(CONTENT_PROPERTY_BINARY_NAME);
+				return data.getLength();
+			} else {
+				if (ruleNode.hasProperty(CONTENT_PROPERTY_CONTENT)) {
+					Property data = ruleNode.getProperty(CONTENT_PROPERTY_CONTENT);
+					return data.getLength();
+				} else {
+					return 0;
+				}
+			}
+		} catch (RepositoryException e) {
+			log.error(e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * True if this is a binary asset (or has binary content).
+	 */
+	public boolean isBinary() {
+		try {
+			Node ruleNode = getVersionContentNode();
+			return ruleNode.hasProperty(CONTENT_PROPERTY_BINARY_NAME);
+		} catch (RepositoryException e) {
+			log.error(e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * If this asset contains binary data, this is how you return it. Otherwise
+	 * it will return null.
+	 */
+	public InputStream getBinaryContentAttachment() {
+		try {
+//			 TODO: Add Event Manager feature to ContextProfileItem
+//			if (StorageEventManager.hasLoadEvent()) {
+//				return StorageEventManager.getLoadEvent().loadContent(this);
+//			}
+			Node ruleNode = getVersionContentNode();
+			if (ruleNode.hasProperty(CONTENT_PROPERTY_BINARY_NAME)) {
+				Property data = ruleNode
+						.getProperty(CONTENT_PROPERTY_BINARY_NAME);
+				return data.getStream();
+			} else {
+				if (ruleNode.hasProperty(CONTENT_PROPERTY_CONTENT)) {
+					Property data = ruleNode.getProperty(CONTENT_PROPERTY_CONTENT);
+					return data.getStream();
+				}
+				return null;
+			}
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/** Get the name of the "file" attachment, if one is set. Null otherwise */
+	public String getBinaryContentAttachmentFileName() {
+		return getStringProperty(CONTENT_PROPERTY_ATTACHMENT_FILENAME);
+	}
+
+	/**
+	 * This is a convenience method for returning the binary data as a byte
+	 * array.
+	 */
+	public byte[] getBinaryContentAsBytes() {
+		try {
+			Node ruleNode = getVersionContentNode();
+//			 TODO: Add Event Manager feature to ContextProfileItem
+//			if (StorageEventManager.hasLoadEvent()) {
+//				return IOUtils.toByteArray(StorageEventManager.getLoadEvent()
+//						.loadContent(this));
+//			}
+			if (isBinary()) {
+				Property data = ruleNode
+						.getProperty(CONTENT_PROPERTY_BINARY_NAME);
+				InputStream in = data.getStream();
+
+				// Create the byte array to hold the data
+				byte[] bytes = new byte[(int) data.getLength()];
+
+				// Read in the bytes
+				int offset = 0;
+				int numRead = 0;
+				while (offset < bytes.length
+						&& (numRead = in.read(bytes, offset, bytes.length
+								- offset)) >= 0) {
+					offset += numRead;
+				}
+
+				// Ensure all the bytes have been read in
+				if (offset < bytes.length) {
+					throw new RulesRepositoryException(
+							"Could not completely read asset " + getName());
+				}
+
+				// Close the input stream and return bytes
+				in.close();
+				return bytes;
+			} else {
+				return getContent().getBytes();
+			}
+		} catch (Exception e) {
+			log.error(e);
+			if (e instanceof RuntimeException)
+				throw (RuntimeException) e;
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * @return the date the rule becomes effective
+	 * @throws RulesRepositoryException
+	 */
+	public Calendar getDateEffective() throws RulesRepositoryException {
+		try {
+			Node ruleNode = getVersionContentNode();
+
+			Property dateEffectiveProperty = ruleNode
+					.getProperty(DATE_EFFECTIVE_PROPERTY_NAME);
+			return dateEffectiveProperty.getDate();
+		} catch (PathNotFoundException e) {
+			// doesn't have this property
+			return null;
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * @return if this rule is disabled
+	 * @throws RulesRepositoryException
+	 */
+	public boolean getDisabled() throws RulesRepositoryException {
+		try {
+			Node ruleNode = getVersionContentNode();
+
+			Property disabled = ruleNode.getProperty(DISABLED_PROPERTY_NAME);
+			return disabled.getBoolean();
+		} catch (PathNotFoundException e) {
+			// doesn't have this property
+			return false;
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * Creates a new version of this object's rule node, updating the effective
+	 * date for the rule node.
+	 * 
+	 * @param newDateEffective
+	 *            the new effective date for the rule
+	 * @throws RulesRepositoryException
+	 */
+	public void updateDateEffective(Calendar newDateEffective)
+			throws RulesRepositoryException {
+		checkIsUpdateable();
+		checkout();
+		try {
+			this.node.setProperty(DATE_EFFECTIVE_PROPERTY_NAME,
+					newDateEffective);
+		} catch (RepositoryException e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * Creates a new version of this object's rule node, updating the disable
+	 * value for the rule node.
+	 * 
+	 * @param disabled
+	 *            is this rule disabled
+	 * @throws RulesRepositoryException
+	 */
+	public void updateDisabled(boolean disabled)
+			throws RulesRepositoryException {
+		checkIsUpdateable();
+		checkout();
+		try {
+			this.node.setProperty(DISABLED_PROPERTY_NAME, disabled);
+		} catch (RepositoryException e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * @return the date the rule becomes expired
+	 * @throws RulesRepositoryException
+	 */
+	public Calendar getDateExpired() throws RulesRepositoryException {
+		try {
+			Node ruleNode = getVersionContentNode();
+
+			Property dateExpiredProperty = ruleNode
+					.getProperty(DATE_EXPIRED_PROPERTY_NAME);
+			return dateExpiredProperty.getDate();
+		} catch (PathNotFoundException e) {
+			// doesn't have this property
+			return null;
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * Creates a new version of this object's rule node, updating the expired
+	 * date for the rule node.
+	 * 
+	 * @param newDateExpired
+	 *            the new expired date for the rule
+	 * @throws RulesRepositoryException
+	 */
+	public void updateDateExpired(Calendar newDateExpired)
+			throws RulesRepositoryException {
+		checkout();
+
+		try {
+			this.node.setProperty(DATE_EXPIRED_PROPERTY_NAME, newDateExpired);
+		} catch (Exception e) {
+			log.error("Caught Exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * This will update the asset's content (checking it out if it is not
+	 * already). This will not save the session or create a new version of the
+	 * node (this has to be done seperately, as several properties may change as
+	 * part of one edit). This is only used if the asset is a textual asset. For
+	 * binary, use the updateBinaryContent method instead.
+	 */
+	public ContextProfileItem updateContent(String newRuleContent)
+			throws RulesRepositoryException {
+		checkout();
+		try {
+			if (this.isBinary()) {
+				this.updateBinaryContentAttachment(new ByteArrayInputStream(
+						newRuleContent.getBytes()));
+			}
+			this.node.setProperty(CONTENT_PROPERTY_CONTENT, newRuleContent);
+			return this;
+		} catch (RepositoryException e) {
+			log.error("Unable to update the asset content", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * If the asset is a binary asset, then use this to update the content (do
+	 * NOT use text).
+	 */
+	public ContextProfileItem updateBinaryContentAttachment(InputStream data) {
+		checkout();
+		try {
+			this.node.setProperty(CONTENT_PROPERTY_BINARY_NAME, data);
+			return this;
+		} catch (RepositoryException e) {
+			log.error("Unable to update the assets binary content", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * Optionally set the filename to be associated with the binary content.
+	 */
+	public void updateBinaryContentAttachmentFileName(String name) {
+		updateStringProperty(name, CONTENT_PROPERTY_ATTACHMENT_FILENAME);
+	}
+
+	/**
+	 * This updates a user defined property (not one of the intrinsic ones).
+	 */
+	public void updateUserProperty(String propertyName, String value) {
+		if (propertyName.startsWith("drools:")) {
+			throw new IllegalArgumentException(
+					"Can only set the pre defined fields using the appropriate methods.");
+		}
+		updateStringProperty(value, propertyName);
+
+	}
+
+	/**
+	 * Nicely formats the information contained by the node that this object
+	 * encapsulates
+	 */
+	public String toString() {
+		try {
+			StringBuffer returnString = new StringBuffer();
+			returnString.append("Content of rule item named '" + this.getName()
+					+ "':\n");
+			returnString.append("Content: " + this.getContent() + "\n");
+			returnString.append("------\n");
+
+			returnString.append("Archived: " + this.isArchived() + "\n");
+			returnString.append("------\n");
+
+			returnString.append("Date Effective: " + this.getDateEffective()
+					+ "\n");
+			returnString
+					.append("Date Expired: " + this.getDateExpired() + "\n");
+			returnString.append("------\n");
+
+			returnString.append("Rule state: ");
+			StateItem stateItem = this.getState();
+			if (stateItem != null) {
+				returnString.append(this.getState().getName() + "\n");
+			} else {
+				returnString.append("NO STATE SET FOR THIS NODE\n");
+			}
+			returnString.append("------\n");
+
+			returnString.append("Rule tags:\n");
+			for (Iterator it = this.getCategories().iterator(); it.hasNext();) {
+				CategoryItem currentTag = (CategoryItem) it.next();
+				returnString.append(currentTag.getName() + "\n");
+			}
+			returnString.append("--------------\n");
+			return returnString.toString();
+		} catch (Exception e) {
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	public VersionableItem getPrecedingVersion()
+			throws RulesRepositoryException {
+		try {
+			Node precedingVersionNode = this.getPrecedingVersionNode();
+			if (precedingVersionNode != null) {
+				return new ContextProfileItem(this.rulesRepository, precedingVersionNode);
+			} else {
+				return null;
+			}
+		} catch (Exception e) {
+			log.error("Caught exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	public VersionableItem getSucceedingVersion()
+			throws RulesRepositoryException {
+		try {
+			Node succeedingVersionNode = this.getSucceedingVersionNode();
+			if (succeedingVersionNode != null) {
+				return new ContextProfileItem(this.rulesRepository,
+						succeedingVersionNode);
+			} else {
+				return null;
+			}
+		} catch (Exception e) {
+			log.error("Caught exception", e);
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * @return A property value (for a user defined property).
+	 */
+	public String getUserProperty(String property) {
+		return getStringProperty(property);
+	}
+
+	/**
+	 * This will remove the item. The repository will need to be saved for this
+	 * to take effect. Typically the package that contains this should be
+	 * versioned before removing this, to make it easy to roll back.
+	 */
+	public void remove() {
+
+//		 TODO: Add Event Manager feature to ContextProfileItem
+//		if (StorageEventManager.hasSaveEvent()) {
+//			StorageEventManager.getSaveEvent().onAssetDelete(this);
+//		}
+
+		checkIsUpdateable();
+		if (this.getDateExpired() != null) {
+			if (Calendar.getInstance().before(this.getDateExpired())) {
+				throw new RulesRepositoryException(
+						"Can't delete an item before its expiry date.");
+			}
+		}
+		try {
+			this.node.remove();
+		} catch (RepositoryException e) {
+			throw new RulesRepositoryException(e);
+		}
+	}
+
+	/**
+	 * 
+	 * @return An iterator over the nodes history.
+	 */
+	public AssetHistoryIterator getHistory() {
+		return new AssetHistoryIterator(this.rulesRepository, this.node);
+	}
+
+	/**
+	 * This converts a "filename" to an asset name.
+	 * 
+	 * File name is foo.drl -> ["foo", "drl"]
+	 * 
+	 * @param fileName
+	 * @return
+	 */
+	public static String[] getAssetNameFromFileName(String fileName) {
+
+		String[] r = new String[] { "", "" };
+		if (!fileName.contains(".")) {
+			r[0] = fileName;
+		} else if (fileName.endsWith(".bpel.jar")) {
+			r[0] = fileName.substring(0, fileName.lastIndexOf(".bpel.jar"));
+			r[1] = "bpel.jar";
+		} else if (fileName.endsWith(".model.drl")) {
+			r[0] = fileName.substring(0, fileName.lastIndexOf(".model.drl"));
+			r[1] = "model.drl";
+		} else {
+			r[0] = fileName.substring(0, fileName.lastIndexOf("."));
+			r[1] = fileName.substring(fileName.lastIndexOf(".") + 1);
+
+		}
+		return r;
+
+	}
+
+}
\ No newline at end of file


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfileItem.java
___________________________________________________________________
Name: svn:eol-style
   + native

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfilePageList.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfilePageList.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfilePageList.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,29 @@
+package org.drools.repository;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.RangeIterator;
+
+/**
+ * Used for holding a page of context profile data.
+ *
+ * @author Lucas Amador
+ */
+public class ContextProfilePageList extends BasePageList {
+
+	public final List<ContextProfileItem> contextProfiles;
+
+	public ContextProfilePageList(List<ContextProfileItem> contextProfiles, RangeIterator it) {
+		this.contextProfiles = contextProfiles;
+		this.hasNext = it.hasNext();
+		this.currentPosition = it.getPosition();
+	}
+
+	public ContextProfilePageList() {
+		hasNext = false;
+		currentPosition = 0;
+		contextProfiles = new ArrayList<ContextProfileItem>();
+	}
+
+}


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/ContextProfilePageList.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/JackrabbitRepositoryConfigurator.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/JackrabbitRepositoryConfigurator.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/JackrabbitRepositoryConfigurator.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -70,6 +70,7 @@
                 this.registerNodeTypesFromCndFile("/node_type_definitions/rule_node_type.cnd", ws);
                 this.registerNodeTypesFromCndFile("/node_type_definitions/rulepackage_node_type.cnd", ws);
              
+                this.registerNodeTypesFromCndFile("/node_type_definitions/contextprofile_node_type.cnd", ws);
             }
             
             // Setup the rule repository node
@@ -104,6 +105,9 @@
             //and we need the "Draft" state
             RulesRepository.addNodeIfNew( repositoryNode.getNode( RulesRepository.STATE_AREA ), StateItem.DRAFT_STATE_NAME, StateItem.STATE_NODE_TYPE_NAME );
             
+            //Setup the Context Profile area                
+            RulesRepository.addNodeIfNew(repositoryNode, RulesRepository.CONTEXT_PROFILE_AREA, "nt:folder");
+            
             session.save();                        
         }
         catch(Exception e) {

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RepositoryItem.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RepositoryItem.java	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RepositoryItem.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,5 @@
+package org.drools.repository;
+
+public interface RepositoryItem {
+
+}


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RepositoryItem.java
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RulesRepository.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RulesRepository.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/java/org/drools/repository/RulesRepository.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -1,6 +1,10 @@
 package org.drools.repository;
 
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Iterator;
@@ -10,14 +14,23 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
-import javax.jcr.*;
+import javax.jcr.ImportUUIDBehavior;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.PathNotFoundException;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryResult;
-import javax.jcr.version.Version;
 
 import org.apache.log4j.Logger;
+import org.drools.repository.events.StorageEventManager;
 import org.drools.repository.migration.MigrateDroolsPackage;
-import org.drools.repository.events.StorageEventManager;
 
 /**
  * RulesRepository is the class that defines the bahavior for the JBoss Rules
@@ -83,7 +96,12 @@
      * The name of the rules repository within the JCR repository
      */
     public final static String  RULES_REPOSITORY_NAME = "drools:repository";
-
+    
+    /**
+     * The name of the contextprofile area of the repository 
+     */
+    public final static String  CONTEXT_PROFILE_AREA     = "drools:contextprofile_area";
+    
     private Session             session;
 
     static boolean              initialized           = false;
@@ -1461,13 +1479,94 @@
 
     }
 
+    /**
+     * Find all the context profiles created
+     * @param seekArchivedContextProfile
+     * @param skip
+     * @param numRowsToReturn
+     * @param filter
+     * @return
+     */
+    public ContextProfilePageList findContextProfiles(int numRowsToReturn) {
+    	Node folderNode = this.getAreaNode( CONTEXT_PROFILE_AREA );
+    	List<ContextProfileItem> results = new ArrayList<ContextProfileItem>();
+    	int rows = 0;
+    	try {
+    		NodeIterator nodeIterator = folderNode.getNodes();
+    		while (nodeIterator.hasNext() && (numRowsToReturn == -1 || rows < numRowsToReturn)) {
+    			Node node = nodeIterator.nextNode();
+    			ContextProfileItem cpi = new ContextProfileItem(this, node);
+    			results.add(cpi);
+    			rows++;
+    		}
+    		return new ContextProfilePageList(results, nodeIterator);
+    	} catch (RepositoryException e) {
+    		throw new RulesRepositoryException(e);
+    	}
+    }
+
+    /**
+     * Create basic context profile
+     * @param id context profile id
+     * @param sessionType stateful/stateless session
+     * @return The stored context profile item info
+     * @throws RulesRepositoryException
+     */
+    public ContextProfileItem createContextProfile(String id, String sessionType) throws RulesRepositoryException {
+    	Node folderNode = this.getAreaNode(CONTEXT_PROFILE_AREA);
+
+    	try {
+    		// create the node - see section 6.7.22.6 of the spec
+    		Node contextProfileNode = folderNode.addNode(id, ContextProfileItem.CONTEXT_PROFILE_NODE_TYPE_NAME);
+
+    		contextProfileNode.setProperty(ContextProfileItem.CONTENT_PROPERTY_ID, id);
+    		contextProfileNode.setProperty(ContextProfileItem.CONTENT_PROPERTY_SESSION_TYPE, sessionType);
+    		contextProfileNode.setProperty(ContextProfileItem.DESCRIPTION_PROPERTY_NAME, "");
+    		contextProfileNode.setProperty(ContextProfileItem.TITLE_PROPERTY_NAME, id);
+    		contextProfileNode.setProperty(ContextProfileItem.FORMAT_PROPERTY_NAME, "CP");
+    		contextProfileNode.setProperty(ContextProfileItem.CREATOR_PROPERTY_NAME, this.session.getUserID());
+
+    		Calendar lastModified = Calendar.getInstance();
+    		contextProfileNode.setProperty(ContextProfileItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
+
+    		ContextProfileItem item = new ContextProfileItem(this, contextProfileNode);
+    		item.checkin("Initial");
+
+    		return item;
+    	}
+    	catch (ItemExistsException e) {
+    		throw new RulesRepositoryException("A Context Profile name must be unique.", e);
+    	}
+    	catch (RepositoryException e) {
+    		log.error("Error when creating a new context profile", e);
+    		throw new RulesRepositoryException(e);
+    	}
+    }
+
+    /**
+     * Loads a context profile by its UUID
+     */
+    public ContextProfileItem loadContextProfileByUUID(String uuid) {
+    	try {
+    		Node contextProfileNode = this.session.getNodeByUUID(uuid);
+    		return new ContextProfileItem(this, contextProfileNode);
+    	} catch (ItemNotFoundException e) {
+    		log.warn(e);
+    		throw new RulesRepositoryException("That item does not exist.");
+    	}catch (RepositoryException e) {
+    		log.error("Unable to load a context profile by UUID.", e);
+    		throw new RulesRepositoryException( e );
+    	}
+    }
+
     @Override
     protected void finalize() throws Throwable {
-        //shouldn't rely on this... but
-        try {
-            this.logout();
-        } catch ( Exception e ) {
-            log.error( "Finalizer error: " + e.getMessage() );
-        }
+    	//shouldn't rely on this... but
+    	try {
+    		this.logout();
+    	} catch ( Exception e ) {
+    		log.error( "Finalizer error: " + e.getMessage() );
+    	}
     }
+
 }
\ No newline at end of file

Added: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/resources/node_type_definitions/contextprofile_node_type.cnd
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/resources/node_type_definitions/contextprofile_node_type.cnd	                        (rev 0)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/resources/node_type_definitions/contextprofile_node_type.cnd	2010-03-11 19:10:25 UTC (rev 32042)
@@ -0,0 +1,37 @@
+/*  The node type definition for the rule node type.  
+    See http://jackrabbit.apache.org/doc/nodetype/cnd.html for an explanation
+*/
+
+// The namespace declaration
+<drools = 'http://www.jboss.org/drools-repository/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+
+// Node type name
+[drools:contextProfileNodeType]
+
+// Supertypes
+> 'drools:versionableNodeType'
+
+// Properties:
+- drools:id (string)
+  mandatory
+- drools:sessionType (string)
+  mandatory
+- drools:content (string)
+- drools:binaryContent (binary)
+- drools:attachmentFileName (string)
+//- drools:archive (boolean) = 'false' mandatory autocreated
+
+// use this to capture fields which are not known ahead of time 
+- * (undefined)
+
+- drools:dateEffective (date)
+
+- drools:dateExpired (date)
+  
+//for taxonomies/asset classification  
+//- drools:categoryReference (reference)
+//  multiple 
+//  copy
+//  < 'drools:categoryNodeType'  


Property changes on: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/main/resources/node_type_definitions/contextprofile_node_type.cnd
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/test/java/org/drools/repository/events/MockLoadEvent.java
===================================================================
--- labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/test/java/org/drools/repository/events/MockLoadEvent.java	2010-03-11 18:52:32 UTC (rev 32041)
+++ labs/jbossrules/branches/drools_server_camel_lucaz_baunax/drools-repository/src/test/java/org/drools/repository/events/MockLoadEvent.java	2010-03-11 19:10:25 UTC (rev 32042)
@@ -1,10 +1,10 @@
 package org.drools.repository.events;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
 import org.drools.repository.AssetItem;
 
-import java.io.InputStream;
-import java.io.ByteArrayInputStream;
-
 /**
  * @author Michael Neale
  */



More information about the jboss-svn-commits mailing list