[jboss-svn-commits] JBL Code SVN: r31135 - in labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client: ruleeditor and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jan 19 09:19:03 EST 2010


Author: jervisliu
Date: 2010-01-19 09:19:02 -0500 (Tue, 19 Jan 2010)
New Revision: 31135

Modified:
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java
   labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/VersionBrowser.java
Log:
https://jira.jboss.org/jira/browse/GUVNOR-369: Creating a new rule by copying it should open it up

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java	2010-01-19 14:13:22 UTC (rev 31134)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/explorer/ExplorerViewCenterPanel.java	2010-01-19 14:19:02 UTC (rev 31135)
@@ -219,7 +219,12 @@
 					SuggestionCompletionCache.getInstance().doAction(a.metaData.packageName, new Command() {
 						public void execute() {
                             loading[0] = false;
-							RuleViewer rv = new RuleViewer(a);
+                            EditItemEvent edit = new EditItemEvent () {
+                                public void open(String key) {
+                                	openAsset(key);
+                                }
+                            };
+							RuleViewer rv = new RuleViewer(a, edit);
 							addTab(a.metaData.name, true, rv, uuid);
 							rv.setCloseCommand(new Command() {
 								public void execute() {

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java	2010-01-19 14:13:22 UTC (rev 31134)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java	2010-01-19 14:19:02 UTC (rev 31135)
@@ -21,7 +21,6 @@
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.*;
-import com.google.gwt.user.client.ui.Button;
 import com.gwtext.client.core.EventObject;
 import com.gwtext.client.util.Format;
 import com.gwtext.client.widgets.*;
@@ -61,11 +60,16 @@
     private SmallLabel savedOK;
     private Widget editor;
     private Command closeCommand;
+    private Command copyCommand;
 
     public ActionToolbar(final RuleAsset asset,
                          final CheckinAction checkin,
                          final CheckinAction archiv,
-                         final Command delete, boolean readOnly, Widget editor, Command closeCommand) {
+                         final Command delete, 
+                         boolean readOnly, 
+                         Widget editor, 
+                         Command closeCommand,
+                         Command copyCommand) {
 
         this.checkinAction = checkin;
         this.archiveAction = archiv;
@@ -73,6 +77,7 @@
         this.asset = asset;
         this.editor = editor;
         this.closeCommand = closeCommand;
+        this.copyCommand = copyCommand;
 
         this.state = new ToolbarTextItem(constants.Status() + " ");
 
@@ -92,7 +97,6 @@
         initWidget( toolbar );
     }
 
-
     /**
      * Show the saved OK message for a little while *.
      */
@@ -114,7 +118,6 @@
     }
 
     private void controls() {
-
 	    	ToolbarButton save = new ToolbarButton();
 	    	save.setText(constants.SaveChanges());
 			save.setTooltip(getTip(constants.CommitAnyChangesForThisAsset()));
@@ -152,7 +155,7 @@
         moreMenu.addItem(new Item(constants.Copy(), new BaseItemListenerAdapter() {
             @Override
             public void onClick(BaseItem baseItem, EventObject eventObject) {
-                doCopyDialog();
+            	copyCommand.execute();
             }
         }));
         moreMenu.addItem(new Item(constants.Archive(), new BaseItemListenerAdapter() {
@@ -169,14 +172,8 @@
                 showStatusChanger();            }
         }));
 
-
-
-        
-
         ToolbarMenuButton more = new ToolbarMenuButton(constants.Actions(), moreMenu);
 
-
-
         if (isValidatorTypeAsset()) {
             ToolbarButton validate = new ToolbarButton();
             validate.setText(constants.Validate());
@@ -203,7 +200,6 @@
             }
         }
 
-
         if (notCheckedInYet()) {
 
         	final ToolbarButton delete = new ToolbarButton();
@@ -221,22 +217,14 @@
     		toolbar.addButton(delete);
 
     		this.afterCheckinEvent = new Command() {
-
 				public void execute() {
 					delete.setVisible(false);
 				}
-
     		};
 
         }
 
         toolbar.addButton(more);
-
-
-
-
-
-
     }
 
     private boolean shouldShowViewSource() {
@@ -249,7 +237,6 @@
         RepositoryServiceFactory.getService().buildAssetSource( this.asset, new GenericCallback<String>() {
             public void onSuccess(String src) { showSource(src);}
         });
-
     }
 
     private void showSource(String src) {
@@ -257,15 +244,12 @@
         LoadingPopup.close();
     }
 
-
-
     private void doValidate() {
     	onSave();
         LoadingPopup.showMessage(constants.ValidatingItemPleaseWait());
         RepositoryServiceFactory.getService().buildAsset( asset, new GenericCallback<BuilderResult[]>() {
             public void onSuccess(BuilderResult[] results) {RuleValidatorWrapper.showBuilderErrors(results);}
         });
-
     }
 
     public void onSave() {
@@ -275,8 +259,6 @@
         }
     }
 
-
-
     private boolean isValidatorTypeAsset() {
        String format = asset.metaData.format;
        for(String fmt : VALIDATING_FORMATS) {
@@ -285,7 +267,6 @@
        return false;
     }
 
-
     private boolean notCheckedInYet() {
 		return asset.metaData.versionNumber == 0;
 	}
@@ -295,56 +276,9 @@
 			{
 				setText(t);
 			}
-
 		};
 	}
 
-
-
-    protected void doCopyDialog() {
-        final FormStylePopup form = new FormStylePopup("images/rule_asset.gif", constants.CopyThisItem());
-        final TextBox newName = new TextBox();
-        form.addAttribute(constants.NewName(), newName );
-
-        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( asset.uuid, asset.metaData.packageName, name,
-                                                                 new GenericCallback<String>() {
-                                                                    public void onSuccess(String data) {
-                                                                        completedCopying(newName.getText(), asset.metaData.packageName);
-                                                                        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) {
-        Window.alert( Format.format(constants.CreatedANewItemSuccess(), name, pkg) );
-
-    }
-
     /**
      * Called when user wants to checkin.
      * set closeAfter to true if it should close this whole thing after saving it.
@@ -359,11 +293,8 @@
             }
         });
         pop.show();
-
     }
 
-
-
 	/**
      * Show the stats change popup.
      */
@@ -378,14 +309,7 @@
         pop.show();
     }
 
-
-
     public static interface CheckinAction {
     	void doCheckin(String comment);
     }
-
-
-
-
-
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java	2010-01-19 14:13:22 UTC (rev 31134)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java	2010-01-19 14:19:02 UTC (rev 31135)
@@ -20,12 +20,15 @@
 import org.drools.guvnor.client.packages.SuggestionCompletionCache;
 import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
 import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.rulelist.EditItemEvent;
 import org.drools.guvnor.client.messages.Constants;
 
 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.*;
 import com.google.gwt.core.client.GWT;
+import com.gwtext.client.util.Format;
 
 /**
  * The main layout parent/controller the rule viewer.
@@ -50,17 +53,23 @@
 
     private long               lastSaved = System.currentTimeMillis();
     private Constants          constants = ((Constants) GWT.create( Constants.class ));
-
-    public RuleViewer(RuleAsset asset) {
-        this( asset,
-              false );
+    
+    private final EditItemEvent editEvent;
+    
+    /**
+     * @param historicalReadOnly true if this is a read only view for historical purposes.
+     */
+    public RuleViewer(RuleAsset asset, final EditItemEvent event) {
+        this( asset, event, false );
     }
 
     /**
      * @param historicalReadOnly true if this is a read only view for historical purposes.
      */
     public RuleViewer(RuleAsset asset,
+    		          final EditItemEvent event,
                       boolean historicalReadOnly) {
+        this.editEvent = event;    	
         this.asset = asset;
         this.readOnly = historicalReadOnly && asset.isreadonly;
 
@@ -73,16 +82,13 @@
 
         doWidgets(null);
 
-
-
         LoadingPopup.close();
     }
 
     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,
@@ -124,11 +130,19 @@
                                              doDelete();
                                          }
                                      },
-                                     readOnly, editor, new Command() {
+                                     readOnly, 
+                                     editor, 
+                                     new Command() {
                                         public void execute() {
                                             close();
                                         }
-                                    });
+                                    },
+                                    new Command() {
+                                        public void execute() {
+                                            doCopy();
+                                        }       
+                                    }
+        );
 
         //layout.add(toolbar, DockPanel.NORTH);
         layout.add( toolbar );
@@ -173,7 +187,6 @@
         hsp.setHeight( "100%" );
 
         layout.add(doco);
-
     }
 
     private void doMetaWidget() {
@@ -202,7 +215,6 @@
         closeCommand.execute();
     }
 
-
     void doDelete() {
         readOnly = true; //set to not cause the extra confirm popup
         RepositoryServiceFactory.getService().deleteUncheckedRule( this.asset.uuid,
@@ -310,8 +322,6 @@
                                                              } );
     }
 
-
-
     /**
      * This will only refresh the meta data widget if necessary.
      */
@@ -382,5 +392,51 @@
 
         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 );
 
+        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(asset.uuid, asset.metaData.packageName, name,
+                                                                 new GenericCallback<String>() {
+                                                                    public void onSuccess(String data) {
+                                                                        completedCopying(newName.getText(), asset.metaData.packageName, 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);
+        }
+    }
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/VersionBrowser.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/VersionBrowser.java	2010-01-19 14:13:22 UTC (rev 31134)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/VersionBrowser.java	2010-01-19 14:19:02 UTC (rev 31135)
@@ -214,7 +214,7 @@
                     }
                 });
 
-                RuleViewer viewer = new RuleViewer(asset, true);
+                RuleViewer viewer = new RuleViewer(asset, null, true);
                 viewer.setWidth( "100%" );
 
 



More information about the jboss-svn-commits mailing list