[jboss-svn-commits] JBL Code SVN: r32472 - in labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/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
Wed Apr 7 16:48:00 EDT 2010
Author: diegoll
Date: 2010-04-07 16:48:00 -0400 (Wed, 07 Apr 2010)
New Revision: 32472
Added:
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java
Modified:
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/EditorLauncher.java
Log:
Refactoring to allow using the RuleModeller with a widget factory
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionInsertFactWidget.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -47,11 +47,18 @@
private final String factType;
private Constants constants = GWT.create(Constants.class);
private boolean readOnly;
+ private boolean template;
public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set) {
this(mod, set, null);
}
+ public ActionInsertFactWidget(RuleModeller ruleModeller,
+ ActionInsertFact action, Boolean readOnly, boolean template) {
+ this(ruleModeller, action, readOnly);
+ this.template = template;
+ }
+
public ActionInsertFactWidget(RuleModeller mod, ActionInsertFact set,Boolean readOnly) {
super(mod);
this.model = set;
@@ -79,7 +86,7 @@
initWidget(this.layout);
}
- private void doLayout() {
+ private void doLayout() {
layout.clear();
layout.setWidget( 0, 0, getAssertLabel() );
layout.setWidget( 1, 0, new HTML(" "));
@@ -117,7 +124,7 @@
private Widget valueEditor(final ActionFieldValue val) {
SuggestionCompletionEngine completions = this.getModeller().getSuggestionCompletions();
DropDownData enums = completions.getEnums(this.factType, this.model.fieldValues, val.field);
- return new ActionValueEditor(val, enums,this.getModeller(),val.type,this.readOnly);
+ return new ActionValueEditor(val, enums,this.getModeller(),val.type,this.readOnly, isTemplate());
}
private Widget fieldSelector(final ActionFieldValue val) {
@@ -211,6 +218,10 @@
return this.readOnly;
}
+ public boolean isTemplate() {
+ return template;
+ }
+
}
\ No newline at end of file
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ActionValueEditor.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -44,20 +44,11 @@
private RuleModeller model = null;
private String variableType = null;
private boolean readOnly;
+ private boolean template;
public ActionValueEditor(final ActionFieldValue val,
final DropDownData enums, boolean readOnly) {
- this.readOnly = readOnly;
- if (val.type.equals(SuggestionCompletionEngine.TYPE_BOOLEAN)) {
- this.enums = DropDownData.create(new String[]{"true", "false"});
- } else {
- this.enums = enums;
- }
- this.root = new SimplePanel();
- this.value = val;
-
- refresh();
- initWidget(root);
+ this(val, enums, null, null, readOnly, false);
}
public ActionValueEditor(final ActionFieldValue val,
@@ -72,10 +63,15 @@
this(val, enums, model, variableType, false);
}
+ public ActionValueEditor(ActionFieldValue val, DropDownData enums,
+ RuleModeller model, String type, boolean readOnly) {
+ this(val, enums, model, type, readOnly, false);
+ }
+
public ActionValueEditor(final ActionFieldValue val,
final DropDownData enums,
RuleModeller model,
- String variableType, boolean readOnly) {
+ String variableType, boolean readOnly, boolean template) {
this.readOnly = readOnly;
@@ -88,11 +84,12 @@
this.value = val;
this.model = model;
this.variableType = variableType;
+ this.template = template;
refresh();
initWidget(root);
}
- private void refresh() {
+ private void refresh() {
root.clear();
if (enums != null && (enums.fixedList != null || enums.queryExpression != null)) {
//enum
@@ -119,6 +116,9 @@
if (value.nature == ActionFieldValue.TYPE_VARIABLE) {
Widget list = boundVariable(value);
root.add(list);
+ } else if(value.nature == ActionFieldValue.TYPE_TEMPLATE){
+ Widget box = boundTextBox(this.value);
+ root.add(box);
} else {
//formula and literal
Widget box = boundTextBox(this.value);
@@ -289,7 +289,6 @@
} else {
Image clickme = new Image("images/edit.gif");
clickme.addClickListener(new ClickListener() {
-
public void onClick(Widget w) {
showTypeChoice(w);
}
@@ -318,21 +317,22 @@
new InfoPopup(constants.Literal(),
constants.ALiteralValueMeansTheValueAsTypedInIeItsNotACalculation())));
+ if(isTemplate()){
+ Button templateButton = new Button(constants.TemplateKey(), new ClickListener() {
+ public void onClick(Widget arg0) {
+ value.nature = ActionFieldValue.TYPE_TEMPLATE;
+ value.value = " ";
+ makeDirty();
+ refresh();
+ form.hide();
+ }
+ });
+ form.addAttribute(constants.TemplateKey() + ":",
+ widgets(templateButton,
+ new InfoPopup(constants.Literal(),
+ constants.ALiteralValueMeansTheValueAsTypedInIeItsNotACalculation())));
+ }
- Button templateButton = new Button(constants.TemplateKey(), new ClickListener() {
- public void onClick(Widget arg0) {
- value.nature = ActionFieldValue.TYPE_TEMPLATE;
- value.value = " ";
- makeDirty();
- refresh();
- form.hide();
- }
- });
- form.addAttribute(constants.TemplateKey() + ":",
- widgets(templateButton,
- new InfoPopup(constants.Literal(),
- constants.ALiteralValueMeansTheValueAsTypedInIeItsNotACalculation())));
-
form.addRow(new HTML("<hr/>"));
form.addRow(new SmallLabel(constants.AdvancedSection()));
@@ -412,4 +412,8 @@
h.add(popup);
return h;
}
+
+ public boolean isTemplate(){
+ return this.template;
+ }
}
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ConstraintValueEditor.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -65,6 +65,7 @@
private Constants constants = ((Constants) GWT.create(Constants.class));
private String fieldType;
private boolean readOnly;
+ private boolean template;
/**
* @param con The constraint being edited.
@@ -75,19 +76,30 @@
RuleModeller modeller,
String valueType /* eg is numeric */,
boolean readOnly) {
+ this(pattern, fieldName, con, modeller, valueType, readOnly, false);
+ }
+
+ public ConstraintValueEditor(FactPattern pattern, String fieldName,
+ ISingleFieldConstraint con, RuleModeller modeller, String valueType,
+ boolean readOnly, boolean template) {
this.pattern = pattern;
this.fieldName = fieldName;
+ this.sce = modeller.getSuggestionCompletions();
this.constraint = con;
- this.readOnly = readOnly;
- this.sce = modeller.getSuggestionCompletions();
- valueType = sce.getFieldType(pattern.factType,
- fieldName);
+ this.panel = new SimplePanel();
+ this.model = modeller.getModel();
+ this.modeller = modeller;
+ this.template = template;
+
+ valueType = sce.getFieldType(pattern.factType, fieldName);
this.fieldType = valueType;
if (SuggestionCompletionEngine.TYPE_NUMERIC.equals(valueType)) {
this.numericValue = true;
} else {
this.numericValue = false;
}
+
+ this.readOnly = readOnly;
if (SuggestionCompletionEngine.TYPE_BOOLEAN.equals(valueType)) {
this.dropDownData = DropDownData.create(new String[]{"true", "false"}); //NON-NLS
} else {
@@ -95,17 +107,14 @@
fieldName);
}
- this.model = modeller.getModel();
- this.modeller = modeller;
-
- panel = new SimplePanel();
refreshEditor();
initWidget(panel);
}
- private void refreshEditor() {
+ private void refreshEditor() {
panel.clear();
+ Widget constraintWidget = null;
if (constraint.constraintValueType == SingleFieldConstraint.TYPE_UNDEFINED) {
Image clickme = new Image("images/edit.gif"); //NON-NLS
clickme.addClickListener(new ClickListener() {
@@ -115,15 +124,15 @@
constraint);
}
});
- panel.add(clickme);
+ constraintWidget = clickme;
} else {
switch (constraint.constraintValueType) {
case SingleFieldConstraint.TYPE_LITERAL:
if (this.dropDownData != null) {
- panel.add(new EnumDropDownLabel(this.pattern,
+ constraintWidget = new EnumDropDownLabel(this.pattern,
this.fieldName,
this.sce,
- this.constraint));
+ this.constraint);
} else if (SuggestionCompletionEngine.TYPE_DATE.equals(this.fieldType)) {
DatePickerLabel datePicker = new DatePickerLabel(constraint.value);
@@ -139,35 +148,36 @@
}
});
- panel.add(datePicker);
+ constraintWidget = datePicker;
} else {
- panel.add(new SmallLabel(this.constraint.value));
+ constraintWidget = new SmallLabel(this.constraint.value);
}
} else {
if (!this.readOnly) {
- panel.add(new DefaultLiteralEditor(this.constraint,
- this.numericValue));
+ constraintWidget = new DefaultLiteralEditor(this.constraint,
+ this.numericValue);
} else {
- panel.add(new SmallLabel(this.constraint.value));
+ constraintWidget = new SmallLabel(this.constraint.value);
}
}
break;
case SingleFieldConstraint.TYPE_RET_VALUE:
- panel.add(returnValueEditor());
+ constraintWidget = returnValueEditor();
break;
case SingleFieldConstraint.TYPE_EXPR_BUILDER:
- panel.add(expressionEditor());
+ constraintWidget = expressionEditor();
break;
case SingleFieldConstraint.TYPE_VARIABLE:
- panel.add(variableEditor());
+ constraintWidget = variableEditor();
break;
case ISingleFieldConstraint.TYPE_TEMPLATE:
- panel.add(new DefaultLiteralEditor(this.constraint, false));
+ constraintWidget = new DefaultLiteralEditor(this.constraint, false);
break;
default:
break;
}
}
+ panel.add(constraintWidget);
}
private Widget variableEditor() {
@@ -265,21 +275,21 @@
new InfoPopup(constants.LiteralValue(),
constants.LiteralValTip())));
- //only for template
- String templateKeyLabel = constants.TemplateKey();
- Button templateKeyButton = new Button(templateKeyLabel);
- templateKeyButton.addClickListener(new ClickListener() {
- public void onClick(Widget arg0) {
- con.constraintValueType = ISingleFieldConstraint.TYPE_TEMPLATE;
- doTypeChosen(form);
- }
- });
-
- form.addAttribute(templateKeyLabel + ":",
- widgets(templateKeyButton,
- new InfoPopup(templateKeyLabel,
- constants.LiteralValTip())));
- //end only for template
+ if(isTemplate()){
+ String templateKeyLabel = constants.TemplateKey();
+ Button templateKeyButton = new Button(templateKeyLabel);
+ templateKeyButton.addClickListener(new ClickListener() {
+ public void onClick(Widget arg0) {
+ con.constraintValueType = ISingleFieldConstraint.TYPE_TEMPLATE;
+ doTypeChosen(form);
+ }
+ });
+
+ form.addAttribute(templateKeyLabel + ":",
+ widgets(templateKeyButton,
+ new InfoPopup(templateKeyLabel,
+ constants.LiteralValTip())));
+ }
form.addRow(new HTML("<hr/>"));
form.addRow(new SmallLabel(constants.AdvancedOptions()));
@@ -371,4 +381,8 @@
public boolean isDirty() {
return super.isDirty();
}
+
+ public boolean isTemplate() {
+ return template;
+ }
}
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/FactPatternWidget.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -56,6 +56,7 @@
private Constants constants = ((Constants) GWT.create(Constants.class));
private String customLabel;
private boolean readOnly;
+ private boolean template;
public FactPatternWidget(RuleModeller mod, IPattern p,
boolean canBind) {
@@ -132,7 +133,13 @@
}
- /**
+ public FactPatternWidget(RuleModeller ruleModeller, IPattern pattern,
+ boolean canBind, Boolean readOnly, boolean template) {
+ this(ruleModeller, pattern, canBind, readOnly);
+ this.template = template;
+ }
+
+ /**
* Render a hierarchy of constraints, hierarchy here means constraints that may
* themselves depend on members of constraint objects. With this code, the GUI
* enables clicking rules of the form:
@@ -423,7 +430,7 @@
private Widget valueEditor(final SingleFieldConstraint c, String factType) {
//String type = this.modeller.getSuggestionCompletions().getFieldType( factType, c.fieldName );
- return new ConstraintValueEditor(pattern, c.fieldName, c, this.getModeller(), c.fieldType,this.readOnly);
+ return new ConstraintValueEditor(pattern, c.fieldName, c, this.getModeller(), c.fieldType,this.readOnly, isTemplate());
}
private Widget operatorDropDown(final SingleFieldConstraint c) {
@@ -516,4 +523,8 @@
return this.readOnly;
}
+ public boolean isTemplate() {
+ return template;
+ }
+
}
Added: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java (rev 0)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/ModellerWidgetFactory.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -0,0 +1,28 @@
+package org.drools.guvnor.client.modeldriven.ui;
+
+import org.drools.guvnor.client.modeldriven.brl.IAction;
+import org.drools.guvnor.client.modeldriven.brl.IPattern;
+
+public interface ModellerWidgetFactory {
+
+ /**
+ * Used for get widgets for RHS
+ * @param ruleModeller
+ * @param action
+ * @param readOnly
+ * @return
+ */
+ public abstract RuleModellerWidget getWidget(RuleModeller ruleModeller,
+ IAction action, Boolean readOnly);
+
+ /**
+ * Used for get widgets for LHS
+ * @param ruleModeller
+ * @param pattern
+ * @param readOnly
+ * @return
+ */
+ public abstract RuleModellerWidget getWidget(RuleModeller ruleModeller,
+ IPattern pattern, Boolean readOnly);
+
+}
\ No newline at end of file
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModeller.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -104,16 +104,19 @@
private int currentLayoutRow = 0;
private String packageName;
private RuleAsset asset;
+ private ModellerWidgetFactory widgetFactory;
- public RuleModeller(RuleAsset asset, RuleViewer viewer) {
- this(asset);
+ public RuleModeller(RuleAsset asset, RuleViewer viewer, ModellerWidgetFactory widgetFactory) {
+ this(asset, widgetFactory);
}
- public RuleModeller(RuleAsset asset) {
+ public RuleModeller(RuleAsset asset, ModellerWidgetFactory widgetFactory) {
this.asset = asset;
this.model = (RuleModel) asset.content;
this.packageName = asset.metaData.packageName;
+ this.widgetFactory = widgetFactory;
+
layout = new DirtyableFlexTable();
initWidget();
@@ -355,23 +358,7 @@
//if lockRHS() set the widget RO, otherwise let them decide.
Boolean readOnly = this.lockRHS()?true:null;
- RuleModellerWidget w = null;
- if (action instanceof ActionCallMethod) {
- w = new ActionCallMethodWidget(this, (ActionCallMethod) action,readOnly);
- } else if (action instanceof ActionSetField) {
- w = new ActionSetFieldWidget(this, (ActionSetField) action,readOnly);
- } else if (action instanceof ActionInsertFact) {
- w = new ActionInsertFactWidget(this, (ActionInsertFact) action, readOnly);
- } else if (action instanceof ActionRetractFact) {
- w = new ActionRetractFactWidget(this, (ActionRetractFact) action, readOnly);
- } else if (action instanceof DSLSentence) {
- w = new DSLSentenceWidget(this,(DSLSentence) action, readOnly);
- w.addStyleName("model-builderInner-Background"); //NON-NLS
- } else if (action instanceof FreeFormLine) {
- w = new FreeFormLineWidget(this, (FreeFormLine) action, readOnly);
- } else if (action instanceof ActionGlobalCollectionAdd) {
- w = new GlobalCollectionAddWidget(this, (ActionGlobalCollectionAdd) action, readOnly);
- }
+ RuleModellerWidget w = getWidgetFactory().getWidget(this, action, readOnly);
w.setWidth( "100%" );
widget.add(spacerWidget());
@@ -974,26 +961,8 @@
Boolean readOnly = this.lockLHS()?true:null;
IPattern pattern = model.lhs[i];
- RuleModellerWidget w = null;
- if (pattern instanceof FactPattern) {
- w = new FactPatternWidget(this, pattern, true, readOnly);
- } else if (pattern instanceof CompositeFactPattern) {
- w = new CompositeFactPatternWidget(this, (CompositeFactPattern) pattern, readOnly);
- } else if (pattern instanceof FromAccumulateCompositeFactPattern) {
- w = new FromAccumulateCompositeFactPatternWidget(this, (FromAccumulateCompositeFactPattern) pattern, readOnly);
- } else if (pattern instanceof FromCollectCompositeFactPattern) {
- w = new FromCollectCompositeFactPatternWidget(this, (FromCollectCompositeFactPattern) pattern, readOnly);
- } else if (pattern instanceof FromCompositeFactPattern) {
- w = new FromCompositeFactPatternWidget(this, (FromCompositeFactPattern) pattern, readOnly);
- } else if (pattern instanceof DSLSentence) {
- w = new DSLSentenceWidget(this,(DSLSentence) pattern, readOnly);
- } else if (pattern instanceof FreeFormLine) {
- w = new FreeFormLineWidget(this, (FreeFormLine)pattern, readOnly);
- } else if (pattern instanceof ExpressionFormLine) {
- w = new ExpressionBuilder(this, (ExpressionFormLine) pattern, readOnly);
- } else {
- throw new RuntimeException("I don't know what type of pattern it is: "+pattern);
- }
+
+ RuleModellerWidget w = getWidgetFactory().getWidget(this, pattern, readOnly);
vert.add(wrapLHSWidget(model, i, w));
vert.add(spacerWidget());
@@ -1237,4 +1206,12 @@
// } );
}
+
+ public ModellerWidgetFactory getWidgetFactory() {
+ return widgetFactory;
+ }
+
+ public void setWidgetFactory(ModellerWidgetFactory widgetFactory) {
+ this.widgetFactory = widgetFactory;
+ }
}
Added: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java (rev 0)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/RuleModellerWidgetFactory.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -0,0 +1,86 @@
+package org.drools.guvnor.client.modeldriven.ui;
+
+import org.drools.guvnor.client.modeldriven.brl.ActionCallMethod;
+import org.drools.guvnor.client.modeldriven.brl.ActionGlobalCollectionAdd;
+import org.drools.guvnor.client.modeldriven.brl.ActionInsertFact;
+import org.drools.guvnor.client.modeldriven.brl.ActionRetractFact;
+import org.drools.guvnor.client.modeldriven.brl.ActionSetField;
+import org.drools.guvnor.client.modeldriven.brl.CompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.DSLSentence;
+import org.drools.guvnor.client.modeldriven.brl.ExpressionFormLine;
+import org.drools.guvnor.client.modeldriven.brl.FactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FreeFormLine;
+import org.drools.guvnor.client.modeldriven.brl.FromAccumulateCompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FromCollectCompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.FromCompositeFactPattern;
+import org.drools.guvnor.client.modeldriven.brl.IAction;
+import org.drools.guvnor.client.modeldriven.brl.IPattern;
+
+public class RuleModellerWidgetFactory implements ModellerWidgetFactory {
+
+ /* (non-Javadoc)
+ * @see org.drools.guvnor.client.modeldriven.ui.ModellerWidgetFactory#getWidget(org.drools.guvnor.client.modeldriven.ui.RuleModeller, org.drools.guvnor.client.modeldriven.brl.IAction, boolean)
+ */
+ public RuleModellerWidget getWidget(RuleModeller ruleModeller, IAction action, Boolean readOnly){
+ if (action instanceof ActionCallMethod) {
+ return new ActionCallMethodWidget(ruleModeller, (ActionCallMethod) action, readOnly);
+ }
+ if (action instanceof ActionSetField) {
+ return new ActionSetFieldWidget(ruleModeller, (ActionSetField) action,readOnly);
+ }
+ if (action instanceof ActionInsertFact) {
+ return new ActionInsertFactWidget(ruleModeller, (ActionInsertFact) action, readOnly, isTemplate());
+ }
+ if (action instanceof ActionRetractFact) {
+ return new ActionRetractFactWidget(ruleModeller, (ActionRetractFact) action, readOnly);
+ }
+ if (action instanceof DSLSentence) {
+ RuleModellerWidget w = new DSLSentenceWidget(ruleModeller,(DSLSentence) action, readOnly);
+ w.addStyleName("model-builderInner-Background"); //NON-NLS
+ return w;
+ }
+ if (action instanceof FreeFormLine) {
+ return new FreeFormLineWidget(ruleModeller, (FreeFormLine) action, readOnly);
+ }
+ if (action instanceof ActionGlobalCollectionAdd) {
+ return new GlobalCollectionAddWidget(ruleModeller, (ActionGlobalCollectionAdd) action, readOnly);
+ }
+ throw new RuntimeException("I don't know what type of action is: " + action); //NON-NLS
+ }
+
+ /* (non-Javadoc)
+ * @see org.drools.guvnor.client.modeldriven.ui.ModellerWidgetFactory#getWidget(org.drools.guvnor.client.modeldriven.ui.RuleModeller, org.drools.guvnor.client.modeldriven.brl.IPattern, boolean)
+ */
+ public RuleModellerWidget getWidget(RuleModeller ruleModeller, IPattern pattern, Boolean readOnly){
+ if (pattern instanceof FactPattern) {
+ return new FactPatternWidget(ruleModeller, pattern, true, readOnly, isTemplate());
+ }
+ if (pattern instanceof CompositeFactPattern) {
+ return new CompositeFactPatternWidget(ruleModeller, (CompositeFactPattern) pattern, readOnly);
+ }
+ if (pattern instanceof FromAccumulateCompositeFactPattern) {
+ return new FromAccumulateCompositeFactPatternWidget(ruleModeller, (FromAccumulateCompositeFactPattern) pattern, readOnly);
+ }
+ if (pattern instanceof FromCollectCompositeFactPattern) {
+ return new FromCollectCompositeFactPatternWidget(ruleModeller, (FromCollectCompositeFactPattern) pattern, readOnly);
+ }
+ if (pattern instanceof FromCompositeFactPattern) {
+ return new FromCompositeFactPatternWidget(ruleModeller, (FromCompositeFactPattern) pattern, readOnly);
+ }
+ if (pattern instanceof DSLSentence) {
+ return new DSLSentenceWidget(ruleModeller,(DSLSentence) pattern, readOnly);
+ }
+ if (pattern instanceof FreeFormLine) {
+ return new FreeFormLineWidget(ruleModeller, (FreeFormLine)pattern, readOnly);
+ }
+ if (pattern instanceof ExpressionFormLine) {
+ return new ExpressionBuilder(ruleModeller, (ExpressionFormLine) pattern, readOnly);
+ }
+ throw new RuntimeException("I don't know what type of pattern is: "+pattern);
+
+ }
+
+ protected boolean isTemplate(){
+ return false;
+ }
+}
Added: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java (rev 0)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/modeldriven/ui/TemplateModellerWidgetFactory.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -0,0 +1,9 @@
+package org.drools.guvnor.client.modeldriven.ui;
+
+public class TemplateModellerWidgetFactory extends RuleModellerWidgetFactory {
+
+ @Override
+ protected boolean isTemplate() {
+ return true;
+ }
+}
Modified: labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/EditorLauncher.java
===================================================================
--- labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/EditorLauncher.java 2010-04-07 20:35:31 UTC (rev 32471)
+++ labs/jbossrules/branches/guvnor_rules_templates_baunax_esteban_diega/drools-guvnor/src/main/java/org/drools/guvnor/client/ruleeditor/EditorLauncher.java 2010-04-07 20:48:00 UTC (rev 32472)
@@ -27,6 +27,8 @@
import org.drools.guvnor.client.explorer.Preferences;
import org.drools.guvnor.client.factmodel.FactModelWidget;
import org.drools.guvnor.client.modeldriven.ui.RuleModeller;
+import org.drools.guvnor.client.modeldriven.ui.RuleModellerWidgetFactory;
+import org.drools.guvnor.client.modeldriven.ui.TemplateModellerWidgetFactory;
import org.drools.guvnor.client.packages.ModelAttachmentFileWidget;
import org.drools.guvnor.client.qa.ScenarioWidget;
import org.drools.guvnor.client.rpc.RuleAsset;
@@ -56,7 +58,7 @@
RulePackageSelector.currentlySelectedPackage = asset.metaData.packageName;
// depending on the format, load the appropriate editor
if (asset.metaData.format.equals(AssetFormats.BUSINESS_RULE)) {
- return new RuleModeller(asset);
+ return new RuleModeller(asset, new RuleModellerWidgetFactory());
} else if (asset.metaData.format.equals(AssetFormats.DSL_TEMPLATE_RULE)) {
return new RuleValidatorWrapper(new DSLRuleEditor(asset), asset);
} else if (asset.metaData.format.equals(AssetFormats.BPEL_PACKAGE)
@@ -91,7 +93,7 @@
} else if (asset.metaData.format.equals(AssetFormats.WORKING_SET)) {
return new WorkingSetEditor(asset);
} else if (asset.metaData.format.equals(AssetFormats.RULE_TEMPLATE)) {
- return new RuleModeller(asset);
+ return new RuleModeller(asset, new TemplateModellerWidgetFactory());
} else {
return new DefaultContentUploadEditor(asset, viewer);
}
More information about the jboss-svn-commits
mailing list