[jboss-svn-commits] JBL Code SVN: r31345 - labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Feb 1 13:40:44 EST 2010
Author: eaa
Date: 2010-02-01 13:40:43 -0500 (Mon, 01 Feb 2010)
New Revision: 31345
Modified:
labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
Log:
Guided Editor:
Added the posibility to move up or down an IPattern/IAction
Modified: labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java
===================================================================
--- labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java 2010-02-01 17:15:28 UTC (rev 31344)
+++ labs/jbossrules/branches/guvnor_expressionEditor3_baunax_esteban/drools-compiler/src/main/java/org/drools/guvnor/client/modeldriven/brl/RuleModel.java 2010-02-01 18:40:43 UTC (rev 31345)
@@ -1,27 +1,26 @@
package org.drools.guvnor.client.modeldriven.brl;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class RuleModel
- implements
- PortableObject {
+ implements
+ PortableObject {
/**
* This name is generally not used - the asset name or the
* file name is preferred (ie it could get out of sync with the name of the file it is in).
*/
- public String name;
- public String parentName;
- public String modelVersion = "1.0";
+ public String name;
+ public String parentName;
+ public String modelVersion = "1.0";
+ public RuleAttribute[] attributes = new RuleAttribute[0];
+ public RuleMetadata[] metadataList = new RuleMetadata[0];
+ public IPattern[] lhs = new IPattern[0];
+ public IAction[] rhs = new IAction[0];
- public RuleAttribute[] attributes = new RuleAttribute[0];
- public RuleMetadata[] metadataList = new RuleMetadata[0];
-
- public IPattern[] lhs = new IPattern[0];
- public IAction[] rhs = new IAction[0];
-
/**
* This will return the fact pattern that a variable is bound to.
*
@@ -29,14 +28,14 @@
* @return null or the FactPattern found.
*/
public FactPattern getBoundFact(final String var) {
- if ( this.lhs == null ) {
+ if (this.lhs == null) {
return null;
}
- for ( int i = 0; i < this.lhs.length; i++ ) {
+ for (int i = 0; i < this.lhs.length; i++) {
- if ( this.lhs[i] instanceof FactPattern ) {
+ if (this.lhs[i] instanceof FactPattern) {
final FactPattern p = (FactPattern) this.lhs[i];
- if ( p.boundName != null && var.equals( p.boundName ) ) {
+ if (p.boundName != null && var.equals(p.boundName)) {
return p;
}
}
@@ -45,16 +44,16 @@
}
public String getFieldConstraint(final String var) {
- if ( this.lhs == null ) {
+ if (this.lhs == null) {
return null;
}
- for ( int i = 0; i < this.lhs.length; i++ ) {
+ for (int i = 0; i < this.lhs.length; i++) {
- if ( this.lhs[i] instanceof FactPattern ) {
+ if (this.lhs[i] instanceof FactPattern) {
final FactPattern p = (FactPattern) this.lhs[i];
- for ( FieldConstraint z : p.getFieldConstraints() ) {
- return giveFieldBinding( z,
- var );
+ for (FieldConstraint z : p.getFieldConstraints()) {
+ return giveFieldBinding(z,
+ var);
}
}
@@ -63,36 +62,36 @@
}
private String giveFieldBinding(FieldConstraint f,
- String var) {
- if ( f instanceof SingleFieldConstraint ) {
+ String var) {
+ if (f instanceof SingleFieldConstraint) {
SingleFieldConstraint s = (SingleFieldConstraint) f;
- if ( s.isBound() == true && var.equals( s.fieldBinding ) ) {
+ if (s.isBound() == true && var.equals(s.fieldBinding)) {
return s.fieldType;
}
}
- if ( f instanceof CompositeFieldConstraint ) {
+ if (f instanceof CompositeFieldConstraint) {
CompositeFieldConstraint s = (CompositeFieldConstraint) f;
- for ( FieldConstraint ss : s.constraints ) {
- return giveFieldBinding( ss,
- var );
+ for (FieldConstraint ss : s.constraints) {
+ return giveFieldBinding(ss,
+ var);
}
}
return null;
}
/*
- * Get the bound fact of a rhs action
- * Fix nheron
- */
+ * Get the bound fact of a rhs action
+ * Fix nheron
+ */
public ActionInsertFact getRhsBoundFact(final String var) {
- if ( this.rhs == null ) {
+ if (this.rhs == null) {
return null;
}
- for ( int i = 0; i < this.rhs.length; i++ ) {
+ for (int i = 0; i < this.rhs.length; i++) {
- if ( this.rhs[i] instanceof ActionInsertFact ) {
+ if (this.rhs[i] instanceof ActionInsertFact) {
final ActionInsertFact p = (ActionInsertFact) this.rhs[i];
- if ( p.getBoundName() != null && var.equals( p.getBoundName() ) ) {
+ if (p.getBoundName() != null && var.equals(p.getBoundName())) {
return p;
}
}
@@ -104,17 +103,17 @@
* @return A list of bound facts (String). Or empty list if none are found.
*/
public List<String> getBoundFacts() {
- if ( this.lhs == null ) {
+ if (this.lhs == null) {
return Collections.emptyList();
}
final List<String> list = new ArrayList<String>();
- for ( int i = 0; i < this.lhs.length; i++ ) {
- if ( this.lhs[i] instanceof FactPattern ) {
+ for (int i = 0; i < this.lhs.length; i++) {
+ if (this.lhs[i] instanceof FactPattern) {
final FactPattern p = (FactPattern) this.lhs[i];
- if ( p.boundName != null ) {
- list.add( p.boundName );
+ if (p.boundName != null) {
+ list.add(p.boundName);
}
- list.addAll( getListFieldBinding( p ) );
+ list.addAll(getListFieldBinding(p));
}
}
return list;
@@ -124,27 +123,27 @@
private List<String> getListFieldBinding(FactPattern fact) {
List<String> result = new ArrayList<String>();
- for ( int j = 0; j < fact.getFieldConstraints().length; j++ ) {
+ for (int j = 0; j < fact.getFieldConstraints().length; j++) {
FieldConstraint fc = fact.getFieldConstraints()[j];
- List<String> s = giveFieldBinding( fc );
- result.addAll( s );
+ List<String> s = giveFieldBinding(fc);
+ result.addAll(s);
}
return result;
}
private List<String> giveFieldBinding(FieldConstraint f) {
List<String> result = new ArrayList<String>();
- if ( f instanceof SingleFieldConstraint ) {
+ if (f instanceof SingleFieldConstraint) {
SingleFieldConstraint s = (SingleFieldConstraint) f;
- if ( s.isBound() == true ) {
- result.add( s.fieldBinding );
+ if (s.isBound() == true) {
+ result.add(s.fieldBinding);
}
}
- if ( f instanceof CompositeFieldConstraint ) {
+ if (f instanceof CompositeFieldConstraint) {
CompositeFieldConstraint s = (CompositeFieldConstraint) f;
- for ( FieldConstraint ss : s.constraints ) {
- List<String> t = giveFieldBinding( ss );
- result.addAll( t );
+ for (FieldConstraint ss : s.constraints) {
+ List<String> t = giveFieldBinding(ss);
+ result.addAll(t);
}
}
return result;
@@ -155,15 +154,15 @@
* Fix nheron
*/
public List<String> getRhsBoundFacts() {
- if ( this.rhs == null ) {
+ if (this.rhs == null) {
return null;
}
final List<String> list = new ArrayList<String>();
- for ( int i = 0; i < this.rhs.length; i++ ) {
- if ( this.rhs[i] instanceof ActionInsertFact ) {
+ for (int i = 0; i < this.rhs.length; i++) {
+ if (this.rhs[i] instanceof ActionInsertFact) {
final ActionInsertFact p = (ActionInsertFact) this.rhs[i];
- if ( p.getBoundName() != null ) {
- list.add( p.getBoundName() );
+ if (p.getBoundName() != null) {
+ list.add(p.getBoundName());
}
}
}
@@ -180,15 +179,15 @@
final IPattern[] newList = new IPattern[this.lhs.length - 1];
int newIdx = 0;
- for ( int i = 0; i < this.lhs.length; i++ ) {
+ for (int i = 0; i < this.lhs.length; i++) {
- if ( i != idx ) {
+ if (i != idx) {
newList[newIdx] = this.lhs[i];
newIdx++;
} else {
- if ( this.lhs[i] instanceof FactPattern ) {
+ if (this.lhs[i] instanceof FactPattern) {
final FactPattern p = (FactPattern) this.lhs[i];
- if ( p.boundName != null && isBoundFactUsed( p.boundName ) ) {
+ if (p.boundName != null && isBoundFactUsed(p.boundName)) {
return false;
}
}
@@ -205,18 +204,18 @@
* @return Returns true if the specified binding is used on the RHS.
*/
public boolean isBoundFactUsed(final String binding) {
- if ( this.rhs == null ) {
+ if (this.rhs == null) {
return false;
}
- for ( int i = 0; i < this.rhs.length; i++ ) {
- if ( this.rhs[i] instanceof ActionSetField ) {
+ for (int i = 0; i < this.rhs.length; i++) {
+ if (this.rhs[i] instanceof ActionSetField) {
final ActionSetField set = (ActionSetField) this.rhs[i];
- if ( set.variable.equals( binding ) ) {
+ if (set.variable.equals(binding)) {
return true;
}
- } else if ( this.rhs[i] instanceof ActionRetractFact ) {
+ } else if (this.rhs[i] instanceof ActionRetractFact) {
final ActionRetractFact ret = (ActionRetractFact) this.rhs[i];
- if ( ret.variableName.equals( binding ) ) {
+ if (ret.variableName.equals(binding)) {
return true;
}
}
@@ -228,12 +227,12 @@
this.addLhsItem(pat, true);
}
- public void addLhsItem(final IPattern pat,boolean append) {
- this.addLhsItem(pat, append?this.lhs.length:0);
+ public void addLhsItem(final IPattern pat, boolean append) {
+ this.addLhsItem(pat, append ? this.lhs.length : 0);
}
- public void addLhsItem(final IPattern pat,int position) {
- if ( this.lhs == null ) {
+ public void addLhsItem(final IPattern pat, int position) {
+ if (this.lhs == null) {
this.lhs = new IPattern[0];
}
@@ -241,12 +240,12 @@
final IPattern[] newList = new IPattern[list.length + 1];
for (int i = 0; i < newList.length; i++) {
- if (i<position){
+ if (i < position) {
newList[i] = list[i];
- }else if (i>position){
- newList[i] = list[i-1];
- }else{
- newList[i]=pat;
+ } else if (i > position) {
+ newList[i] = list[i - 1];
+ } else {
+ newList[i] = pat;
}
}
@@ -254,17 +253,75 @@
this.lhs = newList;
}
+ public void moveLhsItemDown(int itemIndex) {
+ if (this.lhs == null) {
+ this.lhs = new IPattern[0];
+ }
+ this.moveItemDown(this.lhs, itemIndex);
+ }
+
+ public void moveLhsItemUp(int itemIndex) {
+ if (this.lhs == null) {
+ this.lhs = new IPattern[0];
+ }
+
+ this.moveItemUp(this.lhs, itemIndex);
+ }
+
+ public void moveRhsItemDown(int itemIndex) {
+ if (this.rhs == null) {
+ this.rhs = new IAction[0];
+ }
+
+ this.moveItemDown(this.rhs, itemIndex);
+ }
+
+ public void moveRhsItemUp(int itemIndex) {
+ if (this.rhs == null) {
+ this.rhs = new IAction[0];
+ }
+
+ this.moveItemUp(this.rhs, itemIndex);
+ }
+
+ public void moveItemDown(Object[] array,int itemIndex) {
+
+ for (int i = 0; i < array.length; i++) {
+ if (i == itemIndex) {
+ if (array.length > (i + 1)) {
+ Object tmp = array[i + 1];
+ array[i + 1] = array[i];
+ array[i] = tmp;
+ i++;
+ }
+ }
+ }
+ }
+
+ private void moveItemUp(Object[] array,int itemIndex){
+ if (itemIndex==0){
+ return;
+ }
+ for (int i = 0; i < array.length; i++) {
+ if (i == itemIndex) {
+ Object tmp = array[i - 1];
+ array[i - 1] = array[i];
+ array[i] = tmp;
+ }
+ }
+ }
+
public void addRhsItem(final IAction action) {
this.addRhsItem(action, true);
}
- public void addRhsItem(final IAction action,boolean append) {
- this.addRhsItem(action, append?this.rhs.length:0);
+ public void addRhsItem(final IAction action, boolean append) {
+ this.addRhsItem(action, append ? this.rhs.length : 0);
}
- public void addRhsItem(final IAction action,int position) {
- if ( this.rhs == null ) {
+ public void addRhsItem(final IAction action, int position) {
+ if (this.rhs == null) {
this.rhs = new IAction[0];
}
@@ -272,12 +329,12 @@
final IAction[] newList = new IAction[list.length + 1];
for (int i = 0; i < newList.length; i++) {
- if (i<position){
+ if (i < position) {
newList[i] = list[i];
- }else if (i>position){
- newList[i] = list[i-1];
- }else{
- newList[i]=action;
+ } else if (i > position) {
+ newList[i] = list[i - 1];
+ } else {
+ newList[i] = action;
}
}
@@ -287,9 +344,9 @@
public void removeRhsItem(final int idx) {
final IAction[] newList = new IAction[this.rhs.length - 1];
int newIdx = 0;
- for ( int i = 0; i < this.rhs.length; i++ ) {
+ for (int i = 0; i < this.rhs.length; i++) {
- if ( i != idx ) {
+ if (i != idx) {
newList[newIdx] = this.rhs[i];
newIdx++;
}
@@ -303,7 +360,7 @@
final RuleAttribute[] list = this.attributes;
final RuleAttribute[] newList = new RuleAttribute[list.length + 1];
- for ( int i = 0; i < list.length; i++ ) {
+ for (int i = 0; i < list.length; i++) {
newList[i] = list[i];
}
newList[list.length] = attribute;
@@ -315,8 +372,8 @@
public void removeAttribute(final int idx) {
final RuleAttribute[] newList = new RuleAttribute[this.attributes.length - 1];
int newIdx = 0;
- for ( int i = 0; i < this.attributes.length; i++ ) {
- if ( i != idx ) {
+ for (int i = 0; i < this.attributes.length; i++) {
+ if (i != idx) {
newList[newIdx] = this.attributes[i];
newIdx++;
}
@@ -334,7 +391,7 @@
final RuleMetadata[] newList = new RuleMetadata[this.metadataList.length + 1];
- for ( int i = 0; i < this.metadataList.length; i++ ) {
+ for (int i = 0; i < this.metadataList.length; i++) {
newList[i] = this.metadataList[i];
}
newList[this.metadataList.length] = metadata;
@@ -345,9 +402,9 @@
public void removeMetadata(final int idx) {
final RuleMetadata[] newList = new RuleMetadata[this.metadataList.length - 1];
int newIdx = 0;
- for ( int i = 0; i < this.metadataList.length; i++ ) {
+ for (int i = 0; i < this.metadataList.length; i++) {
- if ( i != idx ) {
+ if (i != idx) {
newList[newIdx] = this.metadataList[i];
newIdx++;
}
@@ -365,9 +422,9 @@
*/
public RuleMetadata getMetaData(String attributeName) {
- if ( metadataList != null && attributeName != null ) {
- for ( int i = 0; i < metadataList.length; i++ ) {
- if ( attributeName.equals( metadataList[i].attributeName ) ) {
+ if (metadataList != null && attributeName != null) {
+ for (int i = 0; i < metadataList.length; i++) {
+ if (attributeName.equals(metadataList[i].attributeName)) {
return metadataList[i];
}
}
@@ -384,13 +441,13 @@
*/
public boolean updateMetadata(final RuleMetadata target) {
- RuleMetadata metaData = getMetaData( target.attributeName );
- if ( metaData != null ) {
+ RuleMetadata metaData = getMetaData(target.attributeName);
+ if (metaData != null) {
metaData.value = target.value;
return true;
}
- addMetadata( target );
+ addMetadata(target);
return false;
}
@@ -401,40 +458,40 @@
*/
public List<String> getBoundVariablesInScope(final ISingleFieldConstraint con) {
final List<String> result = new ArrayList<String>();
- for ( int i = 0; i < this.lhs.length; i++ ) {
+ for (int i = 0; i < this.lhs.length; i++) {
final IPattern pat = this.lhs[i];
- if ( pat instanceof FactPattern ) {
+ if (pat instanceof FactPattern) {
final FactPattern fact = (FactPattern) pat;
- if ( fact.constraintList != null ) {
+ if (fact.constraintList != null) {
final FieldConstraint[] cons = fact.constraintList.constraints;
- if ( cons != null ) {
- for ( int k = 0; k < cons.length; k++ ) {
+ if (cons != null) {
+ for (int k = 0; k < cons.length; k++) {
FieldConstraint fc = cons[k];
- if ( fc instanceof SingleFieldConstraint ) {
+ if (fc instanceof SingleFieldConstraint) {
final SingleFieldConstraint c = (SingleFieldConstraint) fc;
- if ( c == con ) {
+ if (c == con) {
return result;
}
- if ( c.connectives != null ) {
- for ( int j = 0; j < c.connectives.length; j++ ) {
- if ( con == c.connectives[j] ) {
+ if (c.connectives != null) {
+ for (int j = 0; j < c.connectives.length; j++) {
+ if (con == c.connectives[j]) {
return result;
}
}
}
- if ( c.isBound() ) {
- result.add( c.fieldBinding );
+ if (c.isBound()) {
+ result.add(c.fieldBinding);
}
}
}
}
- if ( fact.isBound() ) {
- result.add( fact.boundName );
+ if (fact.isBound()) {
+ result.add(fact.boundName);
}
} else {
- if ( fact.isBound() ) {
- result.add( fact.boundName );
+ if (fact.isBound()) {
+ result.add(fact.boundName);
}
}
@@ -448,31 +505,31 @@
*/
public List<String> getAllVariables() {
List<String> result = new ArrayList<String>();
- for ( int i = 0; i < this.lhs.length; i++ ) {
+ for (int i = 0; i < this.lhs.length; i++) {
IPattern pat = this.lhs[i];
- if ( pat instanceof FactPattern ) {
+ if (pat instanceof FactPattern) {
FactPattern fact = (FactPattern) pat;
- if ( fact.isBound() ) {
- result.add( fact.boundName );
+ if (fact.isBound()) {
+ result.add(fact.boundName);
}
- for ( int j = 0; j < fact.getFieldConstraints().length; j++ ) {
+ for (int j = 0; j < fact.getFieldConstraints().length; j++) {
FieldConstraint fc = fact.getFieldConstraints()[j];
- if ( fc instanceof SingleFieldConstraint ) {
+ if (fc instanceof SingleFieldConstraint) {
SingleFieldConstraint con = (SingleFieldConstraint) fc;
- if ( con.isBound() ) {
- result.add( con.fieldBinding );
+ if (con.isBound()) {
+ result.add(con.fieldBinding);
}
}
}
}
}
- for ( int i = 0; i < this.rhs.length; i++ ) {
+ for (int i = 0; i < this.rhs.length; i++) {
IAction pat = this.rhs[i];
- if ( pat instanceof ActionInsertFact ) {
+ if (pat instanceof ActionInsertFact) {
ActionInsertFact fact = (ActionInsertFact) pat;
- if ( fact.isBound() ) {
- result.add( fact.getBoundName() );
+ if (fact.isBound()) {
+ result.add(fact.getBoundName());
}
}
}
@@ -484,7 +541,7 @@
* as well as facts.
*/
public boolean isVariableNameUsed(String s) {
- return getAllVariables().contains( s );
+ return getAllVariables().contains(s);
}
/**
@@ -492,17 +549,17 @@
*/
public boolean hasDSLSentences() {
- if ( this.lhs != null ) {
- for ( int i = 0; i < this.lhs.length; i++ ) {
- if ( lhs[i] instanceof DSLSentence ) {
+ if (this.lhs != null) {
+ for (int i = 0; i < this.lhs.length; i++) {
+ if (lhs[i] instanceof DSLSentence) {
return true;
}
}
}
- if ( this.rhs != null ) {
- for ( int i = 0; i < this.rhs.length; i++ ) {
- if ( rhs[i] instanceof DSLSentence ) {
+ if (this.rhs != null) {
+ for (int i = 0; i < this.rhs.length; i++) {
+ if (rhs[i] instanceof DSLSentence) {
return true;
}
}
@@ -510,5 +567,4 @@
return false;
}
-
}
More information about the jboss-svn-commits
mailing list