[jboss-svn-commits] JBL Code SVN: r35823 - in labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor: toolbar and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Nov 1 15:19:50 EDT 2010
Author: eaa
Date: 2010-11-01 15:19:49 -0400 (Mon, 01 Nov 2010)
New Revision: 35823
Added:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbar.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbarButtonsConfigurationProvider.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/DefaultActionToolbarButtonsConfigurationProvider.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider.java
Removed:
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java
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/MultiViewEditor.java
labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.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
- Now it is possible to use an ActionToolbarButtonsConfigurationProvider implementation to define which buttons are visible in RuleModeller's ActionToolbar.
- The standalone version of Guided Editor uses StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider to configure the visible buttons.
Deleted: 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-11-01 18:57:34 UTC (rev 35822)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/ActionToolbar.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -1,406 +0,0 @@
-/*
- * Copyright 2005 JBoss Inc
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.drools.guvnor.client.ruleeditor;
-
-import java.util.Set;
-
-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.rpc.AsyncCallback;
-import com.google.gwt.user.client.ui.Composite;
-import com.google.gwt.user.client.ui.MenuBar;
-import com.google.gwt.user.client.ui.MenuItem;
-import com.google.gwt.user.client.ui.ScrollPanel;
-import com.google.gwt.user.client.ui.Widget;
-import org.drools.guvnor.client.common.*;
-import static org.drools.guvnor.client.common.AssetFormats.*;
-import org.drools.guvnor.client.messages.Constants;
-import org.drools.guvnor.client.qa.VerifierResultWidget;
-import org.drools.guvnor.client.rpc.AnalysisReport;
-import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
-import org.drools.guvnor.client.rpc.RuleAsset;
-import org.drools.guvnor.client.rpc.BuilderResult;
-import org.drools.guvnor.client.rpc.VerificationService;
-import org.drools.guvnor.client.rpc.VerificationServiceAsync;
-import org.drools.guvnor.client.explorer.ExplorerLayoutManager;
-import org.drools.guvnor.client.modeldriven.ui.RuleModelEditor;
-import org.drools.guvnor.client.modeldriven.ui.RuleModeller;
-import org.drools.guvnor.client.security.Capabilities;
-import org.drools.guvnor.client.security.CapabilitiesManager;
-import org.drools.guvnor.client.util.Format;
-import org.drools.guvnor.client.packages.PackageBuilderWidget;
-import org.drools.guvnor.client.packages.WorkingSetManager;
-
-/**
- * This contains the widgets used to action a rule asset
- * (ie checkin, change state, close window)
- * @author Michael Neale
- */
-public class ActionToolbar extends Composite {
-
- private Constants constants = GWT.create( Constants.class );
-
- static String[] VALIDATING_FORMATS = new String[]{BUSINESS_RULE, DSL_TEMPLATE_RULE, DECISION_SPREADSHEET_XLS, DRL, ENUMERATION, DECISION_TABLE_GUIDED, DRL_MODEL, DSL, FUNCTION, RULE_TEMPLATE};
-
- static String[] VERIFY_FORMATS = new String[]{BUSINESS_RULE, DECISION_SPREADSHEET_XLS, DRL, DECISION_TABLE_GUIDED, DRL_MODEL, RULE_TEMPLATE};
-
- private MenuBar toolbar = new MenuBar();
- private CheckinAction checkinAction;
- private Command archiveAction;
- private Command deleteAction;
- private MenuItem state = new MenuItem( constants.Status() + " ",
- new Command() {
- public void execute() {
- // Why can't there be a simple text menu item.
- }
- } );
- final private RuleAsset asset;
- private Command afterCheckinEvent;
- private MenuItem savedOK;
- private Widget editor;
- private Command closeCommand;
- private Command copyCommand;
- private Command promptCommand;
-
- public ActionToolbar(final RuleAsset asset,
- boolean readOnly,
- Widget editor,
- final CheckinAction checkin,
- final Command archiv,
- final Command delete,
- Command closeCommand,
- Command copyCommand,
- Command promptCommand) {
-
- this.checkinAction = checkin;
- this.archiveAction = archiv;
- this.deleteAction = delete;
- this.asset = asset;
- this.editor = editor;
- this.closeCommand = closeCommand;
- this.copyCommand = copyCommand;
- this.promptCommand = promptCommand;
-
- String status = asset.metaData.status;
-
- setState( status );
-
- if ( !readOnly && !asset.isreadonly ) {
- controls();
- }
-
- toolbar.addItem( this.state );
-
- initWidget( toolbar );
- }
-
- /**
- * Show the saved OK message for a little while *.
- */
- public void showSavedConfirmation() {
- savedOK.setVisible( true );
- Timer t = new Timer() {
- public void run() {
- savedOK.setVisible( false );
- }
- };
- t.schedule( 1500 );
- }
-
- /**
- * Sets the visible status display.
- */
- private void setState(String status) {
- state.setText( Format.format( constants.statusIs(),
- status ) );
- }
-
- private void controls() {
- MenuItem save = new MenuItem( constants.SaveChanges(),
- new Command() {
- public void execute() {
- verifyAndDoCheckinConfirm( false );
- }
- } );
-
- save.setTitle( constants.CommitAnyChangesForThisAsset() );
- toolbar.addItem( save );
-
- MenuItem saveAndClose = new MenuItem( constants.SaveAndClose(),
- new Command() {
- public void execute() {
- verifyAndDoCheckinConfirm( true );
- }
- } );
- saveAndClose.setTitle( constants.CommitAnyChangesForThisAsset() );
- toolbar.addItem( saveAndClose );
-
- savedOK = new MenuItem( constants.SavedOK(),
- new Command() {
- public void execute() {
- // Nothing here
- // TODO : MOVE THIS TEXT TO INFO AREA
- }
- } );
- savedOK.setVisible( false );
-
- toolbar.addItem( savedOK );
-
- toolbar.addSeparator();
-
- MenuBar moreMenu = new MenuBar( true );
- moreMenu.addItem( constants.Copy(),
- new Command() {
- public void execute() {
- copyCommand.execute();
- }
- } );
- moreMenu.addItem( constants.PromoteToGlobal(),
- new Command() {
- public void execute() {
- promptCommand.execute();
- }
- } );
- moreMenu.addItem( constants.Archive(),
- new Command() {
- public void execute() {
- if ( Window.confirm( constants.AreYouSureYouWantToArchiveThisItem() + "\n" + constants.ArchiveThisAssetThisWillNotPermanentlyDeleteIt() ) ) {
- archiveAction.execute();
- }
- }
- } );
-
- final MenuItem deleteItem = new MenuItem( constants.Delete(),
- new Command() {
- public void execute() {
- if ( Window.confirm( constants.DeleteAreYouSure() ) ) {
- deleteAction.execute();
- }
- }
- } );
- moreMenu.addItem( deleteItem );
- deleteItem.setTitle( constants.DeleteAssetTooltip() );
- this.afterCheckinEvent = new Command() {
- public void execute() {
- deleteItem.setVisible( true );
- }
- };
-
- if ( !notCheckedInYet() ) {
- deleteItem.setVisible( true );
- }
-
- moreMenu.addItem( constants.ChangeStatus(),
- new Command() {
- public void execute() {
- showStatusChanger();
- }
- } );
-
- if ( isValidatorTypeAsset() ) {
-
- if ( editor instanceof RuleModelEditor ) {
- toolbar.addItem( new MenuItem( constants.SelectWorkingSets(),
- new Command() {
- public void execute() {
- showWorkingSetsSelection( ((RuleModelEditor) editor).getRuleModeller() );
- }
- } ) );
- }
-
- toolbar.addItem( constants.Validate(),
- new Command() {
- public void execute() {
- doValidate();
- }
- } );
-
- if ( isVerificationTypeAsset() ) {
- toolbar.addItem( constants.Verify(),
- new Command() {
- public void execute() {
- doVerify();
- }
- } );
- }
-
- if ( shouldShowViewSource() ) {
- toolbar.addItem( constants.ViewSource(),
- new Command() {
- public void execute() {
- doViewsource();
- }
- } );
- }
- }
-
- toolbar.addItem( constants.MoreDotDot(),
- moreMenu );
- }
-
- private boolean shouldShowViewSource() {
- return CapabilitiesManager.getInstance().shouldShow( Capabilities.SHOW_PACKAGE_VIEW );
- }
-
- private void doViewsource() {
- onSave();
- LoadingPopup.showMessage( constants.CalculatingSource() );
- RepositoryServiceFactory.getService().buildAssetSource( this.asset,
- new GenericCallback<String>() {
- public void onSuccess(String src) {
- showSource( src );
- }
- } );
- }
-
- private void showSource(String src) {
- PackageBuilderWidget.showSource( src,
- this.asset.metaData.name );
- LoadingPopup.close();
- }
-
- private void doVerify() {
- onSave();
- LoadingPopup.showMessage( constants.VerifyingItemPleaseWait() );
- Set<String> activeWorkingSets = null;
- activeWorkingSets = WorkingSetManager.getInstance().getActiveAssetUUIDs( asset.metaData.packageName );
-
- VerificationServiceAsync verificationService = GWT.create( VerificationService.class );
-
- verificationService.verifyAsset( asset,
- activeWorkingSets,
- new AsyncCallback<AnalysisReport>() {
-
- public void onSuccess(AnalysisReport report) {
- LoadingPopup.close();
- final FormStylePopup form = new FormStylePopup( "images/rule_asset.gif",
- constants.VerificationReport() );
- ScrollPanel scrollPanel = new ScrollPanel( new VerifierResultWidget( report,
- false ) );
- scrollPanel.setWidth( "100%" );
- form.addRow( scrollPanel );
-
- LoadingPopup.close();
- form.show();
- }
-
- public void onFailure(Throwable arg0) {
- // TODO Auto-generated method stub
-
- }
- } );
-
- }
-
- 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() {
- if ( editor instanceof SaveEventListener ) {
- SaveEventListener el = (SaveEventListener) editor;
- el.onSave();
- }
- }
-
- private boolean isValidatorTypeAsset() {
- String format = asset.metaData.format;
- for ( String fmt : VALIDATING_FORMATS ) {
- if ( fmt.equals( format ) ) return true;
- }
- return false;
- }
-
- private boolean isVerificationTypeAsset() {
- String format = asset.metaData.format;
- for ( String fmt : VERIFY_FORMATS ) {
- if ( fmt.equals( format ) ) return true;
- }
- return false;
- }
-
- private boolean notCheckedInYet() {
- return asset.metaData.versionNumber == 0;
- }
-
- protected void verifyAndDoCheckinConfirm(final boolean closeAfter) {
- if ( editor instanceof RuleModeller ) {
- ((RuleModeller) editor).verifyRule( new Command() {
-
- public void execute() {
- if ( ((RuleModeller) editor).hasVerifierErrors() || ((RuleModeller) editor).hasVerifierWarnings() ) {
- if ( !Window.confirm( constants.theRuleHasErrorsOrWarningsDotDoYouWantToContinue() ) ) {
- return;
- }
- }
- doCheckinConfirm( closeAfter );
- }
- } );
- } else {
- doCheckinConfirm( closeAfter );
- }
- }
-
- /**
- * Called when user wants to checkin.
- * set closeAfter to true if it should close this whole thing after saving it.
- */
- protected void doCheckinConfirm(final boolean closeAfter) {
- final CheckinPopup pop = new CheckinPopup( constants.CheckInChanges() );
- pop.setCommand( new Command() {
- public void execute() {
- checkinAction.doCheckin( pop.getCheckinComment() );
- if ( afterCheckinEvent != null ) afterCheckinEvent.execute();
- if ( closeAfter ) closeCommand.execute();
- }
- } );
- pop.show();
- }
-
- /**
- * Show the stats change popup.
- */
- private void showStatusChanger() {
- final StatusChangePopup pop = new StatusChangePopup( asset.uuid,
- false );
- pop.setChangeStatusEvent( new Command() {
- public void execute() {
- setState( pop.getState() );
- }
- } );
-
- pop.show();
- }
-
- protected void showWorkingSetsSelection(RuleModeller modeller) {
- new WorkingSetSelectorPopup( modeller,
- asset ).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/GuidedEditorManager.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-01 18:57:34 UTC (rev 35822)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/GuidedEditorManager.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -19,6 +19,7 @@
import org.drools.guvnor.client.messages.Constants;
import org.drools.guvnor.client.rpc.StandaloneGuidedEditorService;
import org.drools.guvnor.client.rpc.StandaloneGuidedEditorServiceAsync;
+import org.drools.guvnor.client.ruleeditor.toolbar.StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider;
import org.drools.ide.common.client.modeldriven.brl.RuleModel;
/**
@@ -76,7 +77,7 @@
public void open(String key) {
// TODO Auto-generated method stub
}
- });
+ }, new StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider());
mainPanel.add(viewer);
}
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-01 18:57:34 UTC (rev 35822)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/MultiViewEditor.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -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.ruleeditor.toolbar.ActionToolbarButtonsConfigurationProvider;
/**
*
@@ -53,12 +54,19 @@
private final Set<MultiViewRow> rows;
private Map<String, RuleViewer> ruleViews = new HashMap<String, RuleViewer>();
private final EditItemEvent editItemEvent;
+ private ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider;
public MultiViewEditor(MultiViewRow[] rows,
EditItemEvent editItemEvent) {
+ this(rows, editItemEvent, null);
+ }
+
+ public MultiViewEditor(MultiViewRow[] rows,
+ EditItemEvent editItemEvent, ActionToolbarButtonsConfigurationProvider individualActionToolbarButtonsConfigurationProvider) {
this.editItemEvent = editItemEvent;
this.rows = new HashSet<MultiViewRow>();
this.rows.addAll(Arrays.asList(rows));
+ this.individualActionToolbarButtonsConfigurationProvider = individualActionToolbarButtonsConfigurationProvider;
VerticalPanel rootPanel = new VerticalPanel();
@@ -145,7 +153,7 @@
public void execute() {
final RuleViewer ruleViewer = new RuleViewer(asset,
- editItemEvent);
+ editItemEvent,false, individualActionToolbarButtonsConfigurationProvider);
ruleViewer.setDocoVisible(showDescription);
ruleViewer.setMetaVisible(showMetadata);
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-11-01 18:57:34 UTC (rev 35822)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/RuleViewer.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -39,10 +39,11 @@
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalPanel;
-import com.google.gwt.user.client.ui.ScrollPanel;
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 org.drools.guvnor.client.ruleeditor.toolbar.ActionToolbar;
+import org.drools.guvnor.client.ruleeditor.toolbar.ActionToolbarButtonsConfigurationProvider;
/**
* The main layout parent/controller the rule viewer.
@@ -73,6 +74,8 @@
private Constants constants = ((Constants) GWT.create( Constants.class ));
private final EditItemEvent editEvent;
+
+ private ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider;
/**
* @param historicalReadOnly true if this is a read only view for historical purposes.
@@ -81,30 +84,33 @@
final EditItemEvent event) {
this( asset,
event,
- false );
+ false, null );
}
-
- public void setDocoVisible(boolean docoVisible) {
- this.docoVisible = docoVisible;
- this.doco.setVisible( docoVisible );
+
+ /**
+ * @param historicalReadOnly true if this is a read only view for historical purposes.
+ */
+ public RuleViewer(RuleAsset asset,
+ final EditItemEvent event,
+ boolean historicalReadOnly) {
+ this (asset, event, historicalReadOnly, null);
}
- public void setMetaVisible(boolean metaVisible) {
- this.metaVisible = metaVisible;
- this.metaWidget.setVisible( metaVisible );
- }
-
/**
* @param historicalReadOnly true if this is a read only view for historical purposes.
+ * @param actionToolbarButtonsConfigurationProvider used to change the default
+ * button configuration provider.
*/
public RuleViewer(RuleAsset asset,
final EditItemEvent event,
- boolean historicalReadOnly) {
+ boolean historicalReadOnly, ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider) {
this.editEvent = event;
this.asset = asset;
this.readOnly = historicalReadOnly && asset.isreadonly;
this.layout = new VerticalPanel();
+
+ this.actionToolbarButtonsConfigurationProvider = actionToolbarButtonsConfigurationProvider;
layout.setWidth( "100%" );
layout.setHeight( "100%" );
@@ -132,7 +138,18 @@
LoadingPopup.close();
}
+
+ public void setDocoVisible(boolean docoVisible) {
+ this.docoVisible = docoVisible;
+ this.doco.setVisible( docoVisible );
+ }
+ public void setMetaVisible(boolean metaVisible) {
+ this.metaVisible = metaVisible;
+ this.metaWidget.setVisible( metaVisible );
+ }
+
+ @Override
public boolean isDirty() {
return (System.currentTimeMillis() - lastSaved) > 3600000;
}
@@ -152,6 +169,7 @@
toolbar = new ActionToolbar( asset,
readOnly,
editor,
+ actionToolbarButtonsConfigurationProvider,
checkInCommand,
new Command() {
public void execute() {
@@ -178,7 +196,7 @@
doPromptToGlobal();
}
} );
-
+
//layout.add(toolbar, DockPanel.NORTH);
layout.add( toolbar );
layout.setCellHeight( toolbar,
@@ -516,7 +534,7 @@
}
} );
- };
+ }
}
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbar.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbar.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbar.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -0,0 +1,471 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.drools.guvnor.client.ruleeditor.toolbar;
+
+import java.util.Set;
+
+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.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.MenuBar;
+import com.google.gwt.user.client.ui.MenuItem;
+import com.google.gwt.user.client.ui.ScrollPanel;
+import com.google.gwt.user.client.ui.Widget;
+import org.drools.guvnor.client.common.*;
+import org.drools.guvnor.client.messages.Constants;
+import org.drools.guvnor.client.qa.VerifierResultWidget;
+import org.drools.guvnor.client.rpc.AnalysisReport;
+import org.drools.guvnor.client.rpc.RepositoryServiceFactory;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import org.drools.guvnor.client.rpc.BuilderResult;
+import org.drools.guvnor.client.rpc.VerificationService;
+import org.drools.guvnor.client.rpc.VerificationServiceAsync;
+import org.drools.guvnor.client.modeldriven.ui.RuleModelEditor;
+import org.drools.guvnor.client.modeldriven.ui.RuleModeller;
+import org.drools.guvnor.client.util.Format;
+import org.drools.guvnor.client.packages.PackageBuilderWidget;
+import org.drools.guvnor.client.packages.WorkingSetManager;
+import org.drools.guvnor.client.ruleeditor.CheckinPopup;
+import org.drools.guvnor.client.ruleeditor.RuleValidatorWrapper;
+import org.drools.guvnor.client.ruleeditor.SaveEventListener;
+import org.drools.guvnor.client.ruleeditor.WorkingSetSelectorPopup;
+
+/**
+ * This contains the widgets used to action a rule asset
+ * (ie checkin, change state, close window)
+ * @author Michael Neale
+ */
+public class ActionToolbar extends Composite {
+
+ private Constants constants = GWT.create(Constants.class);
+ private MenuBar toolbar = new MenuBar();
+ private CheckinAction checkinAction;
+ private Command archiveAction;
+ private Command deleteAction;
+ private MenuItem state = new MenuItem(constants.Status() + " ",
+ new Command() {
+
+ public void execute() {
+ // Why can't there be a simple text menu item.
+ }
+ });
+ final private RuleAsset asset;
+ private Command afterCheckinEvent;
+ private MenuItem savedOK;
+ private Widget editor;
+ private Command closeCommand;
+ private Command copyCommand;
+ private Command promptCommand;
+ private ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider;
+
+ public ActionToolbar(final RuleAsset asset,
+ boolean readOnly,
+ Widget editor,
+ final CheckinAction checkin,
+ final Command archiv,
+ final Command delete,
+ Command closeCommand,
+ Command copyCommand,
+ Command promptCommand) {
+ this(asset, readOnly, editor, null, checkin, archiv, delete, closeCommand, copyCommand, promptCommand);
+ }
+
+ public ActionToolbar(final RuleAsset asset,
+ boolean readOnly,
+ Widget editor,
+ ActionToolbarButtonsConfigurationProvider actionToolbarButtonsConfigurationProvider,
+ final CheckinAction checkin,
+ final Command archiv,
+ final Command delete,
+ Command closeCommand,
+ Command copyCommand,
+ Command promptCommand) {
+
+ this.checkinAction = checkin;
+ this.archiveAction = archiv;
+ this.deleteAction = delete;
+ this.asset = asset;
+ this.editor = editor;
+ this.closeCommand = closeCommand;
+ this.copyCommand = copyCommand;
+ this.promptCommand = promptCommand;
+
+ //By default ActionToolbar uses a DefaultActionToolbarButtonsConfigurationProvider
+ if (actionToolbarButtonsConfigurationProvider == null){
+ this.actionToolbarButtonsConfigurationProvider = new DefaultActionToolbarButtonsConfigurationProvider(asset, editor);
+ }else{
+ this.actionToolbarButtonsConfigurationProvider = actionToolbarButtonsConfigurationProvider;
+ }
+
+ String status = asset.metaData.status;
+
+ setState(status);
+
+ if (!readOnly && !asset.isreadonly) {
+ controls();
+ }
+
+ if (this.actionToolbarButtonsConfigurationProvider.showStateLabel()){
+ toolbar.addItem(this.state);
+ }
+
+ initWidget(toolbar);
+ }
+
+ /**
+ * Show the saved OK message for a little while *.
+ */
+ public void showSavedConfirmation() {
+ savedOK.setVisible(true);
+ Timer t = new Timer() {
+
+ public void run() {
+ savedOK.setVisible(false);
+ }
+ };
+ t.schedule(1500);
+ }
+
+ /**
+ * Sets the visible status display.
+ */
+ private void setState(String status) {
+ state.setText(Format.format(constants.statusIs(),
+ status));
+ }
+
+ private void controls() {
+
+ //Save button
+ if (actionToolbarButtonsConfigurationProvider.showSaveButton()) {
+ MenuItem save = new MenuItem(constants.SaveChanges(),
+ new Command() {
+
+ public void execute() {
+ verifyAndDoCheckinConfirm(false);
+ }
+ });
+
+ save.setTitle(constants.CommitAnyChangesForThisAsset());
+ toolbar.addItem(save);
+ }
+
+ //Save and close button
+ if (actionToolbarButtonsConfigurationProvider.showSaveAndCloseButton()) {
+ MenuItem saveAndClose = new MenuItem(constants.SaveAndClose(),
+ new Command() {
+
+ public void execute() {
+ verifyAndDoCheckinConfirm(true);
+ }
+ });
+ saveAndClose.setTitle(constants.CommitAnyChangesForThisAsset());
+ toolbar.addItem(saveAndClose);
+ }
+
+
+ savedOK = new MenuItem(constants.SavedOK(),
+ new Command() {
+
+ public void execute() {
+ // Nothing here
+ // TODO : MOVE THIS TEXT TO INFO AREA
+ }
+ });
+ savedOK.setVisible(false);
+
+ toolbar.addItem(savedOK);
+
+ toolbar.addSeparator();
+
+ //Select Working Sets button
+ if (actionToolbarButtonsConfigurationProvider.showSelectWorkingSetsButton()) {
+
+ if (editor instanceof RuleModelEditor) {
+ toolbar.addItem(new MenuItem(constants.SelectWorkingSets(),
+ new Command() {
+
+ public void execute() {
+ showWorkingSetsSelection(((RuleModelEditor) editor).getRuleModeller());
+ }
+ }));
+ }
+ }
+
+ //Validate button
+ if (actionToolbarButtonsConfigurationProvider.showValidateButton()) {
+ toolbar.addItem(constants.Validate(),
+ new Command() {
+
+ public void execute() {
+ doValidate();
+ }
+ });
+ }
+
+ //Verify button
+ if (actionToolbarButtonsConfigurationProvider.showValidateButton()) {
+ toolbar.addItem(constants.Verify(),
+ new Command() {
+
+ public void execute() {
+ doVerify();
+ }
+ });
+ }
+
+ //View Source button
+ if (actionToolbarButtonsConfigurationProvider.showViewSourceButton()) {
+ toolbar.addItem(constants.ViewSource(),
+ new Command() {
+
+ public void execute() {
+ doViewsource();
+ }
+ });
+ }
+
+
+ //More.. menu
+ MenuBar moreMenu = new MenuBar(true);
+ boolean moreMenuHasChildren = false;
+ //More -> Copy button
+ if (actionToolbarButtonsConfigurationProvider.showCopyButton()) {
+ moreMenu.addItem(constants.Copy(),
+ new Command() {
+
+ public void execute() {
+ copyCommand.execute();
+ }
+ });
+ moreMenuHasChildren = true;
+ }
+
+ //More -> Promote To Global button
+ if (actionToolbarButtonsConfigurationProvider.showPromoteToGlobalButton()) {
+ moreMenu.addItem(constants.PromoteToGlobal(),
+ new Command() {
+
+ public void execute() {
+ promptCommand.execute();
+ }
+ });
+ moreMenuHasChildren = true;
+ }
+
+ //More -> Archive button
+ if (actionToolbarButtonsConfigurationProvider.showArchiveButton()) {
+ moreMenu.addItem(constants.Archive(),
+ new Command() {
+
+ public void execute() {
+ if (Window.confirm(constants.AreYouSureYouWantToArchiveThisItem() + "\n" + constants.ArchiveThisAssetThisWillNotPermanentlyDeleteIt())) {
+ archiveAction.execute();
+ }
+ }
+ });
+ moreMenuHasChildren = true;
+ }
+
+ //More -> Delete button
+ if (actionToolbarButtonsConfigurationProvider.showDeleteButton()) {
+ final MenuItem deleteItem = new MenuItem(constants.Delete(),
+ new Command() {
+
+ public void execute() {
+ if (Window.confirm(constants.DeleteAreYouSure())) {
+ deleteAction.execute();
+ }
+ }
+ });
+
+ moreMenuHasChildren = true;
+
+ moreMenu.addItem(deleteItem);
+ deleteItem.setTitle(constants.DeleteAssetTooltip());
+
+ this.afterCheckinEvent = new Command() {
+
+ public void execute() {
+ deleteItem.setVisible(true);
+ }
+ };
+
+ if (!notCheckedInYet()) {
+ deleteItem.setVisible(true);
+ }
+ }
+
+ //More -> Status Change button
+ if (actionToolbarButtonsConfigurationProvider.showChangeStatusButton()) {
+ moreMenu.addItem(constants.ChangeStatus(),
+ new Command() {
+
+ public void execute() {
+ showStatusChanger();
+ }
+ });
+ moreMenuHasChildren = true;
+ }
+
+ //only add moreMenu if it contains at least one child
+ if (moreMenuHasChildren) {
+ toolbar.addItem(constants.MoreDotDot(),
+ moreMenu);
+ }
+ }
+
+ private void doViewsource() {
+ onSave();
+ LoadingPopup.showMessage(constants.CalculatingSource());
+ RepositoryServiceFactory.getService().buildAssetSource(this.asset,
+ new GenericCallback<String>() {
+
+ public void onSuccess(String src) {
+ showSource(src);
+ }
+ });
+ }
+
+ private void showSource(String src) {
+ PackageBuilderWidget.showSource(src,
+ this.asset.metaData.name);
+ LoadingPopup.close();
+ }
+
+ private void doVerify() {
+ onSave();
+ LoadingPopup.showMessage(constants.VerifyingItemPleaseWait());
+ Set<String> activeWorkingSets = null;
+ activeWorkingSets = WorkingSetManager.getInstance().getActiveAssetUUIDs(asset.metaData.packageName);
+
+ VerificationServiceAsync verificationService = GWT.create(VerificationService.class);
+
+ verificationService.verifyAsset(asset,
+ activeWorkingSets,
+ new AsyncCallback<AnalysisReport>() {
+
+ public void onSuccess(AnalysisReport report) {
+ LoadingPopup.close();
+ final FormStylePopup form = new FormStylePopup("images/rule_asset.gif",
+ constants.VerificationReport());
+ ScrollPanel scrollPanel = new ScrollPanel(new VerifierResultWidget(report,
+ false));
+ scrollPanel.setWidth("100%");
+ form.addRow(scrollPanel);
+
+ LoadingPopup.close();
+ form.show();
+ }
+
+ public void onFailure(Throwable arg0) {
+ // TODO Auto-generated method stub
+ }
+ });
+
+ }
+
+ 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() {
+ if (editor instanceof SaveEventListener) {
+ SaveEventListener el = (SaveEventListener) editor;
+ el.onSave();
+ }
+ }
+
+ private boolean notCheckedInYet() {
+ return asset.metaData.versionNumber == 0;
+ }
+
+ protected void verifyAndDoCheckinConfirm(final boolean closeAfter) {
+ if (editor instanceof RuleModeller) {
+ ((RuleModeller) editor).verifyRule(new Command() {
+
+ public void execute() {
+ if (((RuleModeller) editor).hasVerifierErrors() || ((RuleModeller) editor).hasVerifierWarnings()) {
+ if (!Window.confirm(constants.theRuleHasErrorsOrWarningsDotDoYouWantToContinue())) {
+ return;
+ }
+ }
+ doCheckinConfirm(closeAfter);
+ }
+ });
+ } else {
+ doCheckinConfirm(closeAfter);
+ }
+ }
+
+ /**
+ * Called when user wants to checkin.
+ * set closeAfter to true if it should close this whole thing after saving it.
+ */
+ protected void doCheckinConfirm(final boolean closeAfter) {
+ final CheckinPopup pop = new CheckinPopup(constants.CheckInChanges());
+ pop.setCommand(new Command() {
+
+ public void execute() {
+ checkinAction.doCheckin(pop.getCheckinComment());
+ if (afterCheckinEvent != null) {
+ afterCheckinEvent.execute();
+ }
+ if (closeAfter) {
+ closeCommand.execute();
+ }
+ }
+ });
+ pop.show();
+ }
+
+ /**
+ * Show the stats change popup.
+ */
+ private void showStatusChanger() {
+ final StatusChangePopup pop = new StatusChangePopup(asset.uuid,
+ false);
+ pop.setChangeStatusEvent(new Command() {
+
+ public void execute() {
+ setState(pop.getState());
+ }
+ });
+
+ pop.show();
+ }
+
+ protected void showWorkingSetsSelection(RuleModeller modeller) {
+ new WorkingSetSelectorPopup(modeller,
+ asset).show();
+ }
+
+ public static interface CheckinAction {
+
+ void doCheckin(String comment);
+ }
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbarButtonsConfigurationProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbarButtonsConfigurationProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/ActionToolbarButtonsConfigurationProvider.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.guvnor.client.ruleeditor.toolbar;
+
+/**
+ * This interface is used by ActionToolbar to know which buttons should be
+ * displayed
+ * @author esteban.aliverti
+ */
+public interface ActionToolbarButtonsConfigurationProvider {
+
+ public boolean showSaveButton();
+ public boolean showSaveAndCloseButton();
+ public boolean showCopyButton();
+ public boolean showPromoteToGlobalButton();
+ public boolean showArchiveButton();
+ public boolean showDeleteButton();
+ public boolean showChangeStatusButton();
+ public boolean showSelectWorkingSetsButton();
+ public boolean showValidateButton();
+ public boolean showVerifyButton();
+ public boolean showViewSourceButton();
+ public boolean showStateLabel();
+
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/DefaultActionToolbarButtonsConfigurationProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/DefaultActionToolbarButtonsConfigurationProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/DefaultActionToolbarButtonsConfigurationProvider.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -0,0 +1,116 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.guvnor.client.ruleeditor.toolbar;
+
+import org.drools.guvnor.client.security.Capabilities;
+import org.drools.guvnor.client.security.CapabilitiesManager;
+import org.drools.guvnor.client.modeldriven.ui.RuleModelEditor;
+import com.google.gwt.user.client.ui.Widget;
+import org.drools.guvnor.client.rpc.RuleAsset;
+import static org.drools.guvnor.client.common.AssetFormats.*;
+
+/**
+ *
+ * @author esteban.aliverti
+ */
+public class DefaultActionToolbarButtonsConfigurationProvider implements ActionToolbarButtonsConfigurationProvider {
+
+ private static String[] VALIDATING_FORMATS = new String[]{BUSINESS_RULE, DSL_TEMPLATE_RULE, DECISION_SPREADSHEET_XLS, DRL, ENUMERATION, DECISION_TABLE_GUIDED, DRL_MODEL, DSL, FUNCTION, RULE_TEMPLATE};
+ private static String[] VERIFY_FORMATS = new String[]{BUSINESS_RULE, DECISION_SPREADSHEET_XLS, DRL, DECISION_TABLE_GUIDED, DRL_MODEL, RULE_TEMPLATE};
+
+ private RuleAsset asset;
+ private Widget editor;
+
+ public DefaultActionToolbarButtonsConfigurationProvider(RuleAsset asset,Widget editor) {
+ this.asset = asset;
+ this.editor = editor;
+ }
+
+ public boolean showSaveButton() {
+ return true;
+ }
+
+ public boolean showSaveAndCloseButton() {
+ return true;
+ }
+
+ public boolean showCopyButton() {
+ return true;
+ }
+
+ public boolean showPromoteToGlobalButton() {
+ return true;
+ }
+
+ public boolean showArchiveButton() {
+ return true;
+ }
+
+ public boolean showDeleteButton() {
+ return true;
+ }
+
+ public boolean showChangeStatusButton() {
+ return true;
+ }
+
+ public boolean showSelectWorkingSetsButton() {
+ return this.isValidatorTypeAsset() && editor instanceof RuleModelEditor;
+ }
+
+ public boolean showValidateButton() {
+ return this.isValidatorTypeAsset();
+ }
+
+ public boolean showVerifyButton() {
+ return this.isValidatorTypeAsset() && this.isVerificationTypeAsset();
+ }
+
+ public boolean showViewSourceButton() {
+ return shouldShowViewSource();
+ }
+
+ public boolean showStateLabel() {
+ return true;
+ }
+
+ private boolean isValidatorTypeAsset() {
+ String format = asset.metaData.format;
+ for (String fmt : VALIDATING_FORMATS) {
+ if (fmt.equals(format)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean isVerificationTypeAsset() {
+ String format = asset.metaData.format;
+ for (String fmt : VERIFY_FORMATS) {
+ if (fmt.equals(format)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean shouldShowViewSource() {
+ return CapabilitiesManager.getInstance().shouldShow(Capabilities.SHOW_PACKAGE_VIEW);
+ }
+
+
+}
Added: labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider.java
===================================================================
--- labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider.java (rev 0)
+++ labs/jbossrules/trunk/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/toolbar/StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider.java 2010-11-01 19:19:49 UTC (rev 35823)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2005 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.guvnor.client.ruleeditor.toolbar;
+
+/**
+ *
+ * @author esteban.aliverti
+ */
+public class StandaloneGuidedEditorIndividualActionToolbarButtonsConfigurationProvider implements ActionToolbarButtonsConfigurationProvider {
+
+ public boolean showSaveButton() {
+ return true;
+ }
+
+ public boolean showSaveAndCloseButton() {
+ return false;
+ }
+
+ public boolean showCopyButton() {
+ return false;
+ }
+
+ public boolean showPromoteToGlobalButton() {
+ return false;
+ }
+
+ public boolean showArchiveButton() {
+ return false;
+ }
+
+ public boolean showDeleteButton() {
+ return false;
+ }
+
+ public boolean showChangeStatusButton() {
+ return false;
+ }
+
+ public boolean showSelectWorkingSetsButton() {
+ return false;
+ }
+
+ public boolean showValidateButton() {
+ return true;
+ }
+
+ public boolean showVerifyButton() {
+ return true;
+ }
+
+ public boolean showViewSourceButton() {
+ return true;
+ }
+
+ public boolean showStateLabel() {
+ return false;
+ }
+
+}
More information about the jboss-svn-commits
mailing list