public void addCondition( int idx, Condition cb ) { if ( isAtomic() && getLeftValuename() != null ) { /* * Copy current atomic setup... */ Condition current = new Condition( getLeftValuename(), getFunction(), getRightValuename(), getRightExact() ); current.setNegated( isNegated() ); setNegated( false ); list.add( current ); } else { // Set default operator if not on first position... if ( isComposite() && idx > 0 && cb.getOperator() == OPERATOR_NONE ) { cb.setOperator( OPERATOR_AND ); } } list.add( idx, cb ); }
@Override public String getXML() throws KettleValueException { return getXML( 0 ); }
private boolean simplify( Condition condition, Condition parent ) { // If condition is atomic // AND // if parent only contain a single child: simplify // if ( condition.isAtomic() && parent.nrConditions() == 1 ) { parent.setLeftValuename( condition.getLeftValuename() ); parent.setFunction( condition.getFunction() ); parent.setRightValuename( condition.getRightValuename() ); parent.setRightExact( condition.getRightExact() ); parent.setNegated( condition.isNegated() ^ parent.isNegated() ); parent.list.clear(); return true; } return false; }
@Override public void widgetSelected( SelectionEvent e ) { // Move the condition lower: this means create a subcondition and put the condition there in the list. // Condition down = active_condition.getCondition( cond_nr ); Condition c = new Condition(); c.setOperator( down.getOperator() ); down.setOperator( Condition.OPERATOR_NONE ); active_condition.setCondition( cond_nr, c ); c.addCondition( down ); widget.redraw(); } } );
try { String str_negated = XMLHandler.getTagValue( condnode, "negated" ); setNegated( "Y".equalsIgnoreCase( str_negated ) ); setOperator( getOperator( str_operator ) ); if ( nrconditions == 0 ) { setLeftValuename( XMLHandler.getTagValue( condnode, "leftvalue" ) ); setFunction( getFunction( XMLHandler.getTagValue( condnode, "function" ) ) ); setRightValuename( XMLHandler.getTagValue( condnode, "rightvalue" ) ); Node exactnode = XMLHandler.getSubNode( condnode, ValueMetaAndData.XML_TAG ); if ( exactnode != null ) { ValueMetaAndData exact = new ValueMetaAndData( exactnode ); setRightExact( exact ); Condition c = new Condition( subcondnode ); addCondition( c );
active_condition.negate(); setModified(); widget.redraw(); int operator = getNrOperator( screen ); EnterSelectionDialog esd = new EnterSelectionDialog( shell, Condition.getRealOperators(), BaseMessages.getString( PKG, "ConditionEditor.Operator.Label" ), BaseMessages.getString( PKG, "ConditionEditor.SelectOperator.Label" ) ); esd.setAvoidQuickSearch(); Condition selcond = active_condition.getCondition( operator ); String def = selcond.getOperatorDesc(); int defnr = esd.getSelectionNr( Const.trim( def ) ); String selection = esd.open( defnr ); if ( selection != null ) { int opnr = Condition.getOperator( selection ); active_condition.getCondition( operator ).setOperator( opnr ); setModified(); break; case AREA_FUNCTION: if ( active_condition.isAtomic() ) { esd = new EnterSelectionDialog( shell, Condition.functions, BaseMessages.getString( PKG, "ConditionEditor.SelectFunction.Label" ) ); esd.setAvoidQuickSearch(); def = active_condition.getFunctionDesc(); defnr = esd.getSelectionNr( def );
@Override public Condition getTestObject() { Condition rtn = new Condition(); rtn.setFunction( rand.nextInt( Condition.functions.length ) ); rtn.setLeftValuename( UUID.randomUUID().toString() ); rtn.setNegated( rand.nextBoolean() ); rtn.setOperator( rand.nextInt( Condition.operators.length ) ); rtn.setRightValuename( UUID.randomUUID().toString() ); return rtn; }
public String getXML( int level ) throws KettleValueException { String retval = ""; String indent1 = Const.rightPad( " ", level ); String indent2 = Const.rightPad( " ", level + 1 ); String indent3 = Const.rightPad( " ", level + 2 ); retval += indent1 + XMLHandler.openTag( XML_TAG ) + Const.CR; retval += indent2 + XMLHandler.addTagValue( "negated", isNegated() ); if ( getOperator() != OPERATOR_NONE ) { retval += indent2 + XMLHandler.addTagValue( "operator", Const.rtrim( getOperatorDesc() ) ); } if ( isAtomic() ) { retval += indent2 + XMLHandler.addTagValue( "leftvalue", getLeftValuename() ); retval += indent2 + XMLHandler.addTagValue( "function", getFunctionDesc() ); retval += indent2 + XMLHandler.addTagValue( "rightvalue", getRightValuename() ); if ( getRightExact() != null ) { retval += indent2 + getRightExact().getXML(); } } else { retval += indent2 + "<conditions>" + Const.CR; for ( int i = 0; i < nrConditions(); i++ ) { Condition c = getCondition( i ); retval += c.getXML( level + 2 ); } retval += indent3 + "</conditions>" + Const.CR; } retval += indent2 + XMLHandler.closeTag( XML_TAG ) + Const.CR; return retval; }
Condition rootCondition = new Condition(); int c = 0; for ( QueryConstraint constraint : queryConstraints ) { new FormulaMetaFunction( __FORMULA_ + c, formulaVal, ValueMetaInterface.TYPE_BOOLEAN, -1, -1, null ); Condition condition = new Condition(); condition.setLeftValuename( __FORMULA_ + c ); condition.setOperator( convertOperator( constraint.orig.getCombinationType() ) ); condition.setFunction( Condition.FUNC_EQUAL ); condition.setRightExact( new ValueMetaAndData( "dummy", true ) ); //$NON-NLS-1$ rootCondition.addCondition( condition ); c++; Condition rootCondition2 = new Condition(); new FormulaMetaFunction( "__FORMULA2_" + c, formulaVal, ValueMetaInterface.TYPE_BOOLEAN, -1, -1, null ); //$NON-NLS-1$ Condition condition = new Condition(); condition.setLeftValuename( "__FORMULA2_" + c ); //$NON-NLS-1$ condition.setOperator( convertOperator( constraint.orig.getCombinationType() ) ); condition.setFunction( Condition.FUNC_EQUAL ); condition.setRightExact( new ValueMetaAndData( "dummy", true ) ); //$NON-NLS-1$ rootCondition2.addCondition( condition ); c++;
@Override public Object clone() { Condition retval = null; retval = new Condition(); retval.negate = negate; retval.operator = operator; if ( isComposite() ) { for ( int i = 0; i < nrConditions(); i++ ) { Condition c = getCondition( i ); Condition cCopy = (Condition) c.clone(); retval.addCondition( cCopy ); } } else { retval.negate = negate; retval.left_valuename = left_valuename; retval.operator = operator; retval.right_valuename = right_valuename; retval.function = function; if ( right_exact != null ) { retval.right_exact = (ValueMetaAndData) right_exact.clone(); } else { retval.right_exact = null; } } return retval; }
public FilterRowsMeta() { super(); // allocate BaseStepMeta condition = new Condition(); }
@Override public void widgetSelected( SelectionEvent e ) { Condition c = new Condition(); c.setOperator( Condition.OPERATOR_AND ); sub.addCondition( c ); setModified(); widget.redraw(); } } );
/** * This method moves up atomic conditions if there is only one sub-condition. * * @return true if there was a simplification. */ public boolean simplify() { if ( nrConditions() == 1 ) { Condition condition = getCondition( 0 ); if ( condition.isAtomic() ) { return simplify( condition, this ); } } boolean changed = false; for ( int i = 0; i < nrConditions(); i++ ) { Condition condition = getCondition( i ); changed |= condition.simplify(); if ( i == 0 ) { condition.setOperator( OPERATOR_NONE ); } } return changed; }
final Condition sub = active_condition.getCondition( cond_nr ); if ( sub.getLeftValuename() != null ) { miAdd = new MenuItem( mPop, SWT.CASCADE ); miAdd.setText( BaseMessages.getString( PKG, "ConditionEditor.AddSubCondition.Label" ) ); @Override public void widgetSelected( SelectionEvent e ) { Condition c = new Condition(); c.setOperator( Condition.OPERATOR_AND ); sub.addCondition( c ); Node condNode = XMLHandler.getSubNode( d, "condition" ); if ( condNode != null ) { Condition c = new Condition( condNode ); active_condition.addCondition( cond_nr, c ); widget.redraw(); Node condNode = XMLHandler.getSubNode( d, "condition" ); if ( condNode != null ) { Condition c = new Condition( condNode ); active_condition.addCondition( cond_nr + 1, c ); widget.redraw(); Condition c = new Condition(); c.setOperator( down.getOperator() ); down.setOperator( Condition.OPERATOR_NONE ); MenuItem miMoveDown = new MenuItem( mPop, SWT.CASCADE ); miMoveDown.setText( BaseMessages.getString( PKG, "ConditionEditor.MoveConditionDown" ) );
if ( isAtomic() ) { if ( isNegated() ) { retval = !retval; retval = cb0.evaluate( rowMeta, r ); switch ( cb.getOperator() ) { case Condition.OPERATOR_OR: retval = retval || cb.evaluate( rowMeta, r ); break; case Condition.OPERATOR_AND: retval = retval && cb.evaluate( rowMeta, r ); break; case Condition.OPERATOR_OR_NOT: retval = retval || ( !cb.evaluate( rowMeta, r ) ); break; case Condition.OPERATOR_AND_NOT: retval = retval && ( !cb.evaluate( rowMeta, r ) ); break; case Condition.OPERATOR_XOR: retval = retval ^ cb.evaluate( rowMeta, r ); break; default: if ( isNegated() ) { retval = !retval; throw new RuntimeException( "Unexpected error evaluation condition [" + toString() + "]", e );
@Override public void widgetSelected( SelectionEvent e ) { String xml = GUIResource.getInstance().fromClipboard(); try { Document d = XMLHandler.loadXMLString( xml ); Node condNode = XMLHandler.getSubNode( d, "condition" ); if ( condNode != null ) { Condition c = new Condition( condNode ); active_condition.addCondition( cond_nr, c ); widget.redraw(); } else { new ErrorDialog( shell, BaseMessages.getString( PKG, "ConditionEditor.Error" ), BaseMessages .getString( PKG, "ConditionEditor.NoConditionFoundXML" ), new KettleXMLException( BaseMessages .getString( PKG, "ConditionEditor.NoConditionFoundXML.Exception", Const.CR + Const.CR + xml ) ) ); } } catch ( KettleXMLException ex ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "ConditionEditor.Error" ), BaseMessages .getString( PKG, "ConditionEditor.ErrorParsingCondition" ), ex ); } } } );
@Override public void widgetSelected( SelectionEvent e ) { Condition up = active_condition.getCondition( cond_nr ); active_condition.removeCondition( cond_nr ); active_condition.addCondition( cond_nr - 1, up ); widget.redraw(); } } );
private void addCondition() { Condition c = new Condition(); c.setOperator( Condition.OPERATOR_AND ); addCondition( c ); setModified(); widget.redraw(); }
@Test public void test() throws Exception { check( "SEND_FALSE_STEP", new StringGetter() { public String get() { return meta.getFalseStepname(); } } ); check( "SEND_TRUE_STEP", new StringGetter() { public String get() { return meta.getTrueStepname(); } } ); check( "CONDITION", new StringGetter() { public String get() { return meta.getConditionXML(); } }, new Condition().getXML() ); } }
public void setFilter() { if ( condition == null ) { condition = new Condition(); } RowMetaInterface f = getRowWithoutValues(); EnterConditionDialog ecd = new EnterConditionDialog( parent.getShell(), SWT.NONE, f, condition ); Condition cond = ecd.open(); if ( cond != null ) { ArrayList<Integer> tokeep = new ArrayList<Integer>(); // Apply the condition to the TableView... int nr = table.getItemCount(); for ( int i = nr - 1; i >= 0; i-- ) { RowMetaAndData r = getRow( i ); boolean keep = cond.evaluate( r.getRowMeta(), r.getData() ); if ( keep ) { tokeep.add( Integer.valueOf( i ) ); } } int[] sels = new int[tokeep.size()]; for ( int i = 0; i < sels.length; i++ ) { sels[i] = ( tokeep.get( i ) ).intValue(); } table.setSelection( sels ); } }