[jboss-svn-commits] JBL Code SVN: r35841 - in labs/jbossrules/trunk: drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 2 11:35:00 EDT 2010
Author: eaa
Date: 2010-11-02 11:34:56 -0400 (Tue, 02 Nov 2010)
New Revision: 35841
Modified:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java
labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/RuleMetadata.java
Log:
GUVNOR-681: Create a new top component to display and run the Guided Editor (RuleModeller) and all the things it needs in a "standalone" way
- It is now possible to retrieve DRL and BRL source code from Standalone Guided Editor using javascript.
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorService.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -19,6 +19,7 @@
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
+import com.google.gwt.user.client.rpc.SerializationException;
/**
*
@@ -31,6 +32,9 @@
RemoteService {
- public RuleAsset[] loadRuleAssetsFromSession() throws DetailedSerializationException;
+ RuleAsset[] loadRuleAssetsFromSession() throws DetailedSerializationException;
+
+ String[] getAsstesDRL(String[] assetsUids) throws SerializationException;
+ String[] getAsstesBRL(String[] assetsUids) throws SerializationException;
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/rpc/StandaloneGuidedEditorServiceAsync.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -25,5 +25,7 @@
*/
public interface StandaloneGuidedEditorServiceAsync {
- public void loadRuleAssetsFromSession(AsyncCallback<RuleAsset[]> asyncCallback);
+ void loadRuleAssetsFromSession(AsyncCallback<RuleAsset[]> asyncCallback);
+ void getAsstesDRL(String[] assetsUids, AsyncCallback<String[]> asyncCallback);
+ void getAsstesBRL(String[] assetsUids, AsyncCallback<String[]> asyncCallback);
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -33,8 +33,17 @@
private Constants constants = GWT.create(Constants.class);
+ private MultiViewEditor editor;
+
+ private StandaloneGuidedEditorServiceAsync standaloneGuidedEditorService = GWT.create( StandaloneGuidedEditorService.class );
+
+ private String[] assetsUids;
+
public Panel getBaseLayout() {
+ //init JS hoocks
+ this.setHooks(this);
+
mainLayout = new DockLayoutPanel(Unit.EM);
final ScrollPanel mainPanel = new ScrollPanel();
@@ -43,22 +52,32 @@
//The package must exist (because we need at least a model to work with)
//To make things easier (to me), the category must exist too.
- StandaloneGuidedEditorServiceAsync standaloneGuidedEditorService = GWT.create( StandaloneGuidedEditorService.class );
-
standaloneGuidedEditorService.loadRuleAssetsFromSession(new GenericCallback<RuleAsset[]>() {
public void onSuccess(final RuleAsset[] assets) {
+ GuidedEditorManager.this.assetsUids = new String[assets.length];
+
//no assets? This is an error!
if (assets.length == 0){
Window.alert(constants.NoRulesFound());
return;
}
+
+ //we need to store the uids of each asset.
+ for (int i = 0; i < assets.length; i++) {
+ RuleAsset ruleAsset = assets[i];
+ GuidedEditorManager.this.assetsUids[i] = ruleAsset.uuid;
+ }
+ //Load SCE and create a MultiViewEditor for the assets.
+ //We take the package from the first asset (because all the assets
+ //must belong to the same package)
SuggestionCompletionCache.getInstance().loadPackage(assets[0].metaData.packageName, new Command() {
public void execute() {
LoadingPopup.close();
+ //For each asset we need to create a MultiViewRow
List<MultiViewRow> rows = new ArrayList<MultiViewRow>();
for (RuleAsset ruleAsset : assets) {
MultiViewRow row = new MultiViewRow();
@@ -68,7 +87,8 @@
rows.add(row);
}
- MultiViewEditor viewer = new MultiViewEditor(rows.toArray(new MultiViewRow[rows.size()]), new EditItemEvent() {
+ //Create the editor
+ editor = new MultiViewEditor(rows.toArray(new MultiViewRow[rows.size()]), new EditItemEvent() {
public void open(MultiViewRow[] rows) {
// TODO Auto-generated method stub
@@ -79,15 +99,109 @@
}
}, new StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider());
- mainPanel.add(viewer);
+ //Add the editor to main panel
+ mainPanel.add(editor);
}
});
}
});
-
+
return mainLayout;
}
+
+
+ /**
+ * This method should be invoked from JS using window.getEditorDRL().
+ * Returns the DRL of the assets we are editing. Because this method is
+ * asynchronous, the DRL code is passed to a callback function specified
+ * in the JS invocation.
+ */
+ public void getDRLs(){
+ if (assetsUids == null || assetsUids.length == 0){
+ returnDRL("");
+ }
+
+ standaloneGuidedEditorService.getAsstesDRL(assetsUids, new GenericCallback<String[]>() {
+ public void onSuccess(String[] drls) {
+ String result = "";
+ if (drls != null){
+ for (String drl : drls) {
+ result+=drl+"\n\n";
+ }
+ }
+
+ returnDRL(result);
+ }
+ });
+ }
+
+ /**
+ * This method should be invoked from JS using window.getEditorBRL().
+ * Returns the BRL of the assets we are editing. Because this method is
+ * asynchronous, the BRL code is passed to a callback function specified
+ * in the JS invocation.
+ */
+ public void getBRLs(){
+ if (assetsUids == null || assetsUids.length == 0){
+ returnDRL("");
+ }
+
+ standaloneGuidedEditorService.getAsstesBRL(assetsUids, new GenericCallback<String[]>() {
+
+ public void onSuccess(String[] drls) {
+ String result = "";
+ if (drls != null){
+ for (String drl : drls) {
+ result+=drl+"\n\n";
+ }
+ }
+
+ returnBRL(result);
+ }
+ });
+ }
+
+ /**
+ * Creates 2 JS functions in window object: getDRLs() and getBRLs(). These
+ * functions are used to retrieve the source code of the assets this component
+ * is handling.
+ * @param app
+ */
+ public native void setHooks(GuidedEditorManager app)/*-{
+
+ $wnd.getEditorDRL = function (callbackFunction) {
+ $wnd.guvnorGuidedEditorDRLCallbackFunction = callbackFunction;
+ app. at org.drools.guvnor.client.ruleeditor.GuidedEditorManager::getDRLs()();
+ };
+
+ $wnd.getEditorBRL = function (callbackFunction) {
+ $wnd.guvnorGuidedEditorBRLCallbackFunction = callbackFunction;
+ app. at org.drools.guvnor.client.ruleeditor.GuidedEditorManager::getBRLs()();
+ };
+
+
+ }-*/;
+
+ /**
+ * Callback method invoked from getDRLs().
+ * @param drl
+ */
+ public native void returnDRL(String drl)/*-{
+ if ($wnd.guvnorGuidedEditorDRLCallbackFunction){
+ $wnd.guvnorGuidedEditorDRLCallbackFunction(drl);
+ }
+ }-*/;
+
+ /**
+ * Callback method invoked from getDRLs().
+ * @param drl
+ */
+ public native void returnBRL(String brl)/*-{
+ if ($wnd.guvnorGuidedEditorBRLCallbackFunction){
+ $wnd.guvnorGuidedEditorBRLCallbackFunction(brl);
+ }
+ }-*/;
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -37,6 +37,7 @@
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
+import org.drools.guvnor.client.rpc.StandaloneGuidedEditorService;
import org.drools.guvnor.client.ruleeditor.toolbar.ActionToolbarButtonsConfigurationProvider;
/**
@@ -163,7 +164,7 @@
ruleViewer.setCloseCommand(new Command() {
public void execute() {
- ruleViews.remove(ruleViewer);
+ ruleViews.remove(row.uuid);
rows.remove(row);
doViews();
}
@@ -216,7 +217,7 @@
pop.show();
}
-
+
public void close() {
closeCommand.execute();
}
Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/server/StandaloneGuidedEditorServiceImplementation.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -15,6 +15,7 @@
*/
package org.drools.guvnor.server;
+import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.ArrayList;
import java.util.List;
@@ -26,6 +27,7 @@
import org.drools.guvnor.server.util.LoggingHelper;
import org.drools.ide.common.client.modeldriven.brl.RuleMetadata;
import org.drools.ide.common.client.modeldriven.brl.RuleModel;
+import org.drools.ide.common.server.util.BRLPersistence;
import org.drools.repository.RulesRepository;
import org.jboss.seam.annotations.In;
@@ -33,6 +35,8 @@
import org.drools.ide.common.server.util.BRXMLPersistence;
/**
+ * All the needed Services in order to get the Guided Editor running as standalone
+ * app.
* @author esteban.aliverti
*/
public class StandaloneGuidedEditorServiceImplementation extends RemoteServiceServlet
@@ -52,9 +56,19 @@
return RepositoryServiceServlet.getService();
}
-
+ /**
+ * To open the Guided Editor as standalone, you should be gone through
+ * GuidedEditorServlet first. This servlet put all the POST parameters into
+ * session. This method takes those parameters and load the corresponding
+ * assets.
+ * If you are passing BRLs to the Guided Editor, this method will create
+ * one asset per BRL with a unique name.
+ * @return
+ * @throws DetailedSerializationException
+ */
public RuleAsset[] loadRuleAssetsFromSession() throws DetailedSerializationException{
+ //Get the parameters from the session
HttpSession session = this.getThreadLocalRequest().getSession();
String packageName = (String)session.getAttribute(GuidedEditorServlet.GUIDED_EDITOR_SERVLET_PARAMETERS.GE_PACKAGE_PARAMETER_NAME.getParameterName());
@@ -111,6 +125,18 @@
}
+ /**
+ * Creates a new RuleAsset from a RuleModel. The name of the RuleAsset will
+ * be the original name plus a unique number.
+ * @param packageName
+ * @param categoryName
+ * @param model
+ * @param hideLHSInEditor
+ * @param hideRHSInEditor
+ * @param hideAttributesInEditor
+ * @return
+ * @throws DetailedSerializationException
+ */
private RuleAsset createRuleAssetFromRuleModel(String packageName, String categoryName, RuleModel model, Boolean hideLHSInEditor, Boolean hideRHSInEditor, Boolean hideAttributesInEditor) throws DetailedSerializationException {
try {
@@ -138,4 +164,41 @@
}
}
+
+ /**
+ * Returns the DRL source code of the given assets.
+ * @param assetsUids
+ * @return
+ * @throws SerializationException
+ */
+ public String[] getAsstesDRL(String[] assetsUids) throws SerializationException{
+
+ String[] sources = new String[assetsUids.length];
+
+ for (int i = 0; i < assetsUids.length; i++) {
+ RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUids[i]);
+ sources[i] = this.getService().buildAssetSource(ruleAsset);
+ }
+
+ return sources;
+ }
+
+ /**
+ * Returns the DRL source code of the given assets.
+ * @param assetsUids
+ * @return
+ * @throws SerializationException
+ */
+ public String[] getAsstesBRL(String[] assetsUids) throws SerializationException{
+
+ String[] sources = new String[assetsUids.length];
+
+ BRLPersistence converter = BRXMLPersistence.getInstance();
+ for (int i = 0; i < assetsUids.length; i++) {
+ RuleAsset ruleAsset = this.getService().loadRuleAsset(assetsUids[i]);
+ sources[i] = converter.marshal((RuleModel) ruleAsset.content);
+ }
+
+ return sources;
+ }
}
Modified: labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/RuleMetadata.java
===================================================================
--- labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/RuleMetadata.java 2010-11-02 15:27:33 UTC (rev 35840)
+++ labs/jbossrules/trunk/drools-ide-common/src/main/java/org/drools/ide/common/client/modeldriven/brl/RuleMetadata.java 2010-11-02 15:34:56 UTC (rev 35841)
@@ -23,7 +23,11 @@
*/
public class RuleMetadata implements PortableObject {
- public String attributeName;
+ public static String HIDE_LHS_IN_EDITOR = "HideLHSInEditor";
+ public static String HIDE_RHS_IN_EDITOR = "HideRHSInEditor";
+ public static String HIDE_ATTRIBUTES_IN_EDITOR = "HideAttributesInEditor";
+
+ public String attributeName;
public String value;
public RuleMetadata() {
More information about the jboss-svn-commits
mailing list