[jboss-svn-commits] JBL Code SVN: r12321 - labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jun 4 16:08:27 EDT 2007


Author: arhan
Date: 2007-06-04 16:08:27 -0400 (Mon, 04 Jun 2007)
New Revision: 12321

Modified:
   labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/AddNewActionDialog.java
Log:
DSLSentence support

Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/AddNewActionDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/AddNewActionDialog.java	2007-06-04 20:05:30 UTC (rev 12320)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/AddNewActionDialog.java	2007-06-04 20:08:27 UTC (rev 12321)
@@ -4,6 +4,7 @@
 import org.drools.brms.client.modeldriven.brxml.ActionAssertFact;
 import org.drools.brms.client.modeldriven.brxml.ActionAssertLogicalFact;
 import org.drools.brms.client.modeldriven.brxml.ActionSetField;
+import org.drools.brms.client.modeldriven.brxml.DSLSentence;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
@@ -21,132 +22,142 @@
  */
 public class AddNewActionDialog extends RuleDialog {
 
-    private final FormToolkit toolkit;
+	private final FormToolkit toolkit;
 
-    private RuleModeller      modeller;
+	private RuleModeller modeller;
 
-    public AddNewActionDialog(Shell parent,
-                              FormToolkit toolkit,
-                              RuleModeller modeller) {
-        super( parent,
-               "Add a new action",
-               "Pick the values from combos and confirm the selection." );
-        this.toolkit = toolkit;
-        this.modeller = modeller;
-    }
+	public AddNewActionDialog(Shell parent, FormToolkit toolkit,
+			RuleModeller modeller) {
+		super(parent, "Add a new action",
+				"Pick the values from combos and confirm the selection.");
+		this.toolkit = toolkit;
+		this.modeller = modeller;
+	}
 
-    protected Control createDialogArea(final Composite parent) {
-        Composite composite = (Composite) super.createDialogArea( parent );
-        String heading = "Choose...";
+	protected Control createDialogArea(final Composite parent) {
+		Composite composite = (Composite) super.createDialogArea(parent);
+		String heading = "Choose...";
 
-        createGlobalVariablesPart( composite,
-                                   heading );
+		createGlobalVariablesPart(composite, heading);
 
-        String[] facts = getCompletion().getFactTypes();
+		String[] facts = getCompletion().getFactTypes();
 
-        createFactAssertionPart( composite,
-                                 heading,
-                                 facts );
+		createFactAssertionPart(composite, heading, facts);
 
-        createFactLogicalAssertionPart( composite,
-                                        heading,
-                                        facts );
+		createFactLogicalAssertionPart(composite, heading, facts);
 
-        return composite;
-    }
+		createDslSentences(composite, heading);
 
-    private void createFactLogicalAssertionPart(Composite composite,
-                                                String heading,
-                                                String[] facts) {
-        toolkit.createLabel( composite,
-                             "Logically assert a new fact" );
-        final Combo factsCombo = createFactsCombo( composite,
-                                                   heading,
-                                                   facts );
-        factsCombo.addListener( SWT.Selection,
-                                new Listener() {
-                                    public void handleEvent(Event event) {
-                                        
-                                        System.out.println("HERE3333! event "+event);
-                                        
-                                        if ( factsCombo.getSelectionIndex() == 0 ) {
-                                            return;
-                                        }
+		return composite;
+	}
 
-                                        modeller.getModel().addRhsItem( new ActionAssertLogicalFact( factsCombo.getText() ) );
-                                        modeller.setDirty( true );
-                                        modeller.reloadRhs();
-                                        close();
-                                    }
-                                } );
-    }
+	private void createDslSentences(Composite composite, String heading) {
+		if (getCompletion().getDSLActions().length > 0) {
+			toolkit.createLabel(composite, "Actions");
 
-    private void createFactAssertionPart(Composite composite,
-                                         String heading,
-                                         String[] facts) {
-        toolkit.createLabel( composite,
-                             "Assert a new fact" );
-        final Combo factsCombo = createFactsCombo( composite,
-                                                   heading,
-                                                   facts );
-        factsCombo.addListener( SWT.Selection,
-                                new Listener() {
-                                    public void handleEvent(Event event) {
-                                        if ( factsCombo.getSelectionIndex() == 0 ) {
-                                            return;
-                                        }
+			final Combo dslCombo = new Combo(composite, SWT.READ_ONLY);
+			dslCombo.add(heading);
+			for (int i = 0; i < getCompletion().getDSLActions().length; i++) {
+				DSLSentence sen = (DSLSentence) getCompletion().getDSLActions()[i];
+				dslCombo.add(sen.toString());
 
-                                        modeller.getModel().addRhsItem( new ActionAssertFact( factsCombo.getText() ) );
-                                        modeller.setDirty( true );
-                                        modeller.reloadRhs();
-                                        close();
-                                    }
-                                } );
-    }
+				dslCombo.addListener(SWT.Selection, new Listener() {
+					public void handleEvent(Event event) {
+						if (dslCombo.getSelectionIndex() == 0) {
+							return;
+						}
 
-    private Combo createFactsCombo(Composite composite,
-                                   String heading,
-                                   String[] facts) {
-        Combo factsCombo = new Combo( composite,
-                                      SWT.READ_ONLY );
-        factsCombo.add( heading );
-        for ( int i = 0; i < facts.length; i++ ) {
-            factsCombo.add( facts[i] );
-        }
-        factsCombo.select( 0 );
-        return factsCombo;
-    }
+						modeller.getModel()
+								.addRhsItem(
+										(DSLSentence) getCompletion()
+												.getDSLActions()[dslCombo
+												.getSelectionIndex()]);
+						modeller.setDirty(true);
+						modeller.reloadRhs();
+						close();
+					}
+				});
+			}
+		}
+	}
 
-    private void createGlobalVariablesPart(Composite composite,
-                                           String heading) {
-        toolkit.createLabel( composite,
-                             "Set the values of a field on" );
-        final Combo globalVarsCombo = new Combo( composite,
-                                                 SWT.READ_ONLY );
-        globalVarsCombo.add( heading );
-        String[] globalVars = getCompletion().getGlobalVariables();
-        for ( int i = 0; i < globalVars.length; i++ ) {
-            globalVarsCombo.add( globalVars[i] );
-        }
-        globalVarsCombo.select( 0 );
+	private void createFactLogicalAssertionPart(Composite composite,
+			String heading, String[] facts) {
+		toolkit.createLabel(composite, "Logically assert a new fact");
+		final Combo factsCombo = createFactsCombo(composite, heading, facts);
+		factsCombo.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(Event event) {
 
-        globalVarsCombo.addListener( SWT.Selection,
-                                     new Listener() {
-                                         public void handleEvent(Event event) {
-                                             if ( globalVarsCombo.getSelectionIndex() == 0 ) {
-                                                 return;
-                                             }
+				if (factsCombo.getSelectionIndex() == 0) {
+					return;
+				}
 
-                                             modeller.getModel().addRhsItem( new ActionSetField( globalVarsCombo.getText() ) );
-                                             modeller.setDirty( true );
-                                             modeller.reloadRhs();
-                                             close();
-                                         }
-                                     } );
-    }
+				modeller.getModel().addRhsItem(
+						new ActionAssertLogicalFact(factsCombo.getText()));
+				modeller.setDirty(true);
+				modeller.reloadRhs();
+				close();
+			}
+		});
+	}
 
-    public SuggestionCompletionEngine getCompletion() {
-        return modeller.getSuggestionCompletionEngine();
-    }
+	private void createFactAssertionPart(Composite composite, String heading,
+			String[] facts) {
+		toolkit.createLabel(composite, "Assert a new fact");
+		final Combo factsCombo = createFactsCombo(composite, heading, facts);
+		factsCombo.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(Event event) {
+				if (factsCombo.getSelectionIndex() == 0) {
+					return;
+				}
 
+				modeller.getModel().addRhsItem(
+						new ActionAssertFact(factsCombo.getText()));
+				modeller.setDirty(true);
+				modeller.reloadRhs();
+				close();
+			}
+		});
+	}
+
+	private Combo createFactsCombo(Composite composite, String heading,
+			String[] facts) {
+		Combo factsCombo = new Combo(composite, SWT.READ_ONLY);
+		factsCombo.add(heading);
+		for (int i = 0; i < facts.length; i++) {
+			factsCombo.add(facts[i]);
+		}
+		factsCombo.select(0);
+		return factsCombo;
+	}
+
+	private void createGlobalVariablesPart(Composite composite, String heading) {
+		toolkit.createLabel(composite, "Set the values of a field on");
+		final Combo globalVarsCombo = new Combo(composite, SWT.READ_ONLY);
+		globalVarsCombo.add(heading);
+		String[] globalVars = getCompletion().getGlobalVariables();
+		for (int i = 0; i < globalVars.length; i++) {
+			globalVarsCombo.add(globalVars[i]);
+		}
+		globalVarsCombo.select(0);
+
+		globalVarsCombo.addListener(SWT.Selection, new Listener() {
+			public void handleEvent(Event event) {
+				if (globalVarsCombo.getSelectionIndex() == 0) {
+					return;
+				}
+
+				modeller.getModel().addRhsItem(
+						new ActionSetField(globalVarsCombo.getText()));
+				modeller.setDirty(true);
+				modeller.reloadRhs();
+				close();
+			}
+		});
+	}
+
+	public SuggestionCompletionEngine getCompletion() {
+		return modeller.getSuggestionCompletionEngine();
+	}
+
 }




More information about the jboss-svn-commits mailing list