[jboss-svn-commits] JBL Code SVN: r12599 - 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
Thu Jun 14 17:55:57 EDT 2007
Author: arhan
Date: 2007-06-14 17:55:56 -0400 (Thu, 14 Jun 2007)
New Revision: 12599
Modified:
labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldDialog.java
labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldWidget.java
Log:
FIX: introduced variableClass
Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldDialog.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldDialog.java 2007-06-14 21:53:48 UTC (rev 12598)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldDialog.java 2007-06-14 21:55:56 UTC (rev 12599)
@@ -1,6 +1,5 @@
package org.drools.eclipse.rulebuilder.ui;
-import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
import org.drools.brms.client.modeldriven.brxml.ActionFieldValue;
import org.drools.brms.client.modeldriven.brxml.ActionSetField;
import org.eclipse.swt.SWT;
@@ -15,61 +14,61 @@
/**
* @author Anton Arhipov
* @author Ahti Kitsik
- *
+ *
*/
public class ActionSetFieldDialog extends RuleDialog {
- private String[] fieldCompletions;
- private FormToolkit toolkit;
- private RuleModeller modeller;
- private ActionSetField field;
+ private String[] fieldCompletions;
- public ActionSetFieldDialog(FormToolkit toolkit,
- Shell parent,
- RuleModeller modeller,
- ActionSetField field,
- String[] fieldCompletions) {
- super( parent,
- "Add a field",
- "Add a field" );
+ private FormToolkit toolkit;
- this.fieldCompletions = fieldCompletions;
- this.toolkit = toolkit;
- this.modeller = modeller;
- this.field = field;
- }
+ private RuleModeller modeller;
- protected Control createDialogArea(final Composite parent) {
- Composite composite = (Composite) super.createDialogArea( parent );
- toolkit.createLabel( composite,
- "Add a field" );
+ private ActionSetField field;
- final Combo fieldsCombo = new Combo( parent,
- SWT.READ_ONLY );
- fieldsCombo.add( "Choose field..." );
- for ( int i = 0; i < fieldCompletions.length; i++ ) {
- fieldsCombo.add( fieldCompletions[i] );
- }
- fieldsCombo.select( 0 );
+ private String variableClass;
- fieldsCombo.addModifyListener( new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- if ( fieldsCombo.getSelectionIndex() == 0 ) {
- return; // no need to change anything
- }
+ public ActionSetFieldDialog(FormToolkit toolkit, Shell parent,
+ RuleModeller modeller, ActionSetField field,
+ String[] fieldCompletions, String variableClass) {
+ super(parent, "Add a field", "Add a field");
- //TODO Is Number correct?
- field.addFieldValue( new ActionFieldValue( fieldsCombo.getText(),
- "",
- SuggestionCompletionEngine.TYPE_NUMERIC ) );
+ this.fieldCompletions = fieldCompletions;
+ this.toolkit = toolkit;
+ this.modeller = modeller;
+ this.field = field;
+ this.variableClass = variableClass;
+ }
- modeller.reloadRhs();
- modeller.setDirty( true );
- close();
- }
- } );
+ protected Control createDialogArea(final Composite parent) {
+ Composite composite = (Composite) super.createDialogArea(parent);
+ toolkit.createLabel(composite, "Add a field");
- return composite;
- }
+ final Combo fieldsCombo = new Combo(parent, SWT.READ_ONLY);
+ fieldsCombo.add("Choose field...");
+ for (int i = 0; i < fieldCompletions.length; i++) {
+ fieldsCombo.add(fieldCompletions[i]);
+ }
+ fieldsCombo.select(0);
+ fieldsCombo.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ if (fieldsCombo.getSelectionIndex() == 0) {
+ return; // no need to change anything
+ }
+
+ String fieldType = modeller.getSuggestionCompletionEngine()
+ .getFieldType(variableClass, fieldsCombo.getText());
+ field.addFieldValue(new ActionFieldValue(fieldsCombo.getText(),
+ "", fieldType));
+
+ modeller.reloadRhs();
+ modeller.setDirty(true);
+ close();
+ }
+ });
+
+ return composite;
+ }
+
}
Modified: labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldWidget.java 2007-06-14 21:53:48 UTC (rev 12598)
+++ labs/jbossrules/trunk/drools-eclipse/drools-guided-editor-plugin/src/org/drools/eclipse/rulebuilder/ui/ActionSetFieldWidget.java 2007-06-14 21:55:56 UTC (rev 12599)
@@ -24,159 +24,151 @@
/**
* @author Anton Arhipov
* @author Ahti Kitsik
- *
+ *
*/
public class ActionSetFieldWidget extends Widget {
- private ActionSetField set;
+ private ActionSetField set;
- final private String[] fieldCompletions;
+ final private String[] fieldCompletions;
- private boolean isBoundFact = false;
+ private boolean isBoundFact = false;
- public ActionSetFieldWidget(FormToolkit toolkit,
- Composite parent,
- RuleModeller mod,
- RuleModel rule,
- ActionSetField set,
- int index) {
+ private String variableClass;
- super( parent,
- toolkit,
- mod,
- index );
+ public ActionSetFieldWidget(FormToolkit toolkit, Composite parent,
+ RuleModeller mod, RuleModel rule, ActionSetField set, int index) {
- this.set = set;
+ super(parent, toolkit, mod, index);
- if ( getCompletion().isGlobalVariable( set.variable ) ) {
- this.fieldCompletions = getCompletion().getFieldCompletionsForGlobalVariable( set.variable );
- } else {
- FactPattern pattern = rule.getBoundFact( set.variable );
- this.fieldCompletions = getCompletion().getFieldCompletions( pattern.factType );
- this.isBoundFact = true;
- }
+ this.set = set;
- GridLayout l = new GridLayout();
- l.numColumns = 6;
- l.marginBottom = 0;
- l.marginHeight = 0;
- l.marginLeft = 0;
- l.marginRight = 0;
- l.marginTop = 0;
- l.marginWidth = 0;
- l.verticalSpacing = 0;
- parent.setLayout( l );
+ if (getCompletion().isGlobalVariable(set.variable)) {
+ this.fieldCompletions = getCompletion()
+ .getFieldCompletionsForGlobalVariable(set.variable);
+ this.variableClass = (String) getCompletion().globalTypes
+ .get(set.variable);
+ } else {
+ FactPattern pattern = rule.getBoundFact(set.variable);
+ this.fieldCompletions = getCompletion().getFieldCompletions(
+ pattern.factType);
+ this.isBoundFact = true;
+ this.variableClass = pattern.factType;
+ }
- create();
+ GridLayout l = new GridLayout();
+ l.numColumns = 6;
+ l.marginBottom = 0;
+ l.marginHeight = 0;
+ l.marginLeft = 0;
+ l.marginRight = 0;
+ l.marginTop = 0;
+ l.marginWidth = 0;
+ l.verticalSpacing = 0;
+ parent.setLayout(l);
- }
+ create();
- private void create() {
- String modifyType = "set";
- if (this.set instanceof ActionUpdateField) {
- modifyType = "modify";
- }
-
- toolkit.createLabel( parent,
- HumanReadable.getActionDisplayName( modifyType ) + " [" + this.set.variable + "]" );
- addDeleteRHSAction();
- addMoreOptionsAction();
- addRows();
- }
+ }
- private void addRows() {
- Composite constraintComposite = toolkit.createComposite( parent );
- GridLayout constraintLayout = new GridLayout();
- constraintLayout.numColumns = 3;
- constraintComposite.setLayout( constraintLayout );
+ private void create() {
+ String modifyType = "set";
+ if (this.set instanceof ActionUpdateField) {
+ modifyType = "modify";
+ }
- for ( int i = 0; i < set.fieldValues.length; i++ ) {
- ActionFieldValue val = set.fieldValues[i];
- toolkit.createLabel( constraintComposite,
- val.field );
- valueEditor( constraintComposite,
- val );
- addRemoveFieldAction( constraintComposite,
- i );
- }
+ toolkit.createLabel(parent, HumanReadable
+ .getActionDisplayName(modifyType)
+ + " [" + this.set.variable + "]");
+ addDeleteRHSAction();
+ addMoreOptionsAction();
+ addRows();
+ }
- toolkit.paintBordersFor( constraintComposite );
- }
+ private void addRows() {
+ Composite constraintComposite = toolkit.createComposite(parent);
+ GridLayout constraintLayout = new GridLayout();
+ constraintLayout.numColumns = 3;
+ constraintComposite.setLayout(constraintLayout);
- private void addMoreOptionsAction() {
- // ImageHyperlink link = addImage(parent,
- // "icons/add_field_to_fact.gif");
- ImageHyperlink link = addImage( parent,
- "icons/new_item.gif" );
+ for (int i = 0; i < set.fieldValues.length; i++) {
+ ActionFieldValue val = set.fieldValues[i];
+ toolkit.createLabel(constraintComposite, val.field);
+ valueEditor(constraintComposite, val);
+ addRemoveFieldAction(constraintComposite, i);
+ }
- link.addHyperlinkListener( new IHyperlinkListener() {
- public void linkActivated(HyperlinkEvent e) {
- RuleDialog popup = new ActionSetFieldDialog( toolkit,
- parent.getShell(),
- getModeller(),
- set,
- fieldCompletions );
- popup.open();
+ toolkit.paintBordersFor(constraintComposite);
+ }
- }
+ private void addMoreOptionsAction() {
+ // ImageHyperlink link = addImage(parent,
+ // "icons/add_field_to_fact.gif");
+ ImageHyperlink link = addImage(parent, "icons/new_item.gif");
- public void linkEntered(HyperlinkEvent e) {
- }
+ link.addHyperlinkListener(new IHyperlinkListener() {
+ public void linkActivated(HyperlinkEvent e) {
+ RuleDialog popup = new ActionSetFieldDialog(toolkit, parent
+ .getShell(), getModeller(), set, fieldCompletions, variableClass);
+ popup.open();
- public void linkExited(HyperlinkEvent e) {
- }
- } );
- link.setToolTipText( "Add a field" );
- }
+ }
- private void addRemoveFieldAction(Composite constraintComposite,
- final int currentRow) {
- ImageHyperlink delLink = addImage( constraintComposite,
- "icons/delete_item_small.gif" );
- delLink.setToolTipText( "Remove this field action" );
- delLink.addHyperlinkListener( new IHyperlinkListener() {
- public void linkActivated(HyperlinkEvent e) {
- MessageBox dialog = new MessageBox( Display.getCurrent().getActiveShell(),
- SWT.YES | SWT.NO | SWT.ICON_WARNING );
- dialog.setMessage( "Remove this item?" );
- dialog.setText( "Remove this item?" );
- if ( dialog.open() == SWT.YES ) {
- set.removeField( currentRow );
- getModeller().setDirty( true );
- getModeller().reloadRhs();
- }
- }
+ public void linkEntered(HyperlinkEvent e) {
+ }
- public void linkEntered(HyperlinkEvent e) {
- }
+ public void linkExited(HyperlinkEvent e) {
+ }
+ });
+ link.setToolTipText("Add a field");
+ }
- public void linkExited(HyperlinkEvent e) {
- }
- } );
- }
+ private void addRemoveFieldAction(Composite constraintComposite,
+ final int currentRow) {
+ ImageHyperlink delLink = addImage(constraintComposite,
+ "icons/delete_item_small.gif");
+ delLink.setToolTipText("Remove this field action");
+ delLink.addHyperlinkListener(new IHyperlinkListener() {
+ public void linkActivated(HyperlinkEvent e) {
+ MessageBox dialog = new MessageBox(Display.getCurrent()
+ .getActiveShell(), SWT.YES | SWT.NO | SWT.ICON_WARNING);
+ dialog.setMessage("Remove this item?");
+ dialog.setText("Remove this item?");
+ if (dialog.open() == SWT.YES) {
+ set.removeField(currentRow);
+ getModeller().setDirty(true);
+ getModeller().reloadRhs();
+ }
+ }
- private void valueEditor(Composite parent,
- final ActionFieldValue val) {
- final Text box = toolkit.createText( parent,
- "" );
+ public void linkEntered(HyperlinkEvent e) {
+ }
- if ( val.value != null ) {
- box.setText( val.value );
- }
+ public void linkExited(HyperlinkEvent e) {
+ }
+ });
+ }
- box.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
+ private void valueEditor(Composite parent, final ActionFieldValue val) {
+ final Text box = toolkit.createText(parent, "");
- box.addModifyListener( new ModifyListener() {
- public void modifyText(ModifyEvent e) {
- val.value = box.getText();
- getModeller().setDirty( true );
- }
- } );
+ if (val.value != null) {
+ box.setText(val.value);
+ }
- }
+ box.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- private SuggestionCompletionEngine getCompletion() {
- return getModeller().getSuggestionCompletionEngine();
- }
+ box.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent e) {
+ val.value = box.getText();
+ getModeller().setDirty(true);
+ }
+ });
+ }
+
+ private SuggestionCompletionEngine getCompletion() {
+ return getModeller().getSuggestionCompletionEngine();
+ }
+
}
More information about the jboss-svn-commits
mailing list