Package org.drools.ide.common.client.modeldriven.brl

Examples of org.drools.ide.common.client.modeldriven.brl.DSLSentence


    @Test
    public void testDSLSentence() {
        RuleModel model = new RuleModel();

        model.lhs = new IPattern[2];
        DSLSentence dsl0 = new DSLSentence();
        dsl0.setDefinition( "DSL Sentence 0" );
        dsl0.getValues().add( new DSLVariableValue( "dsl0v0" ) );
        dsl0.getValues().add( new DSLVariableValue( "dsl0v1" ) );
        model.lhs[0] = dsl0;
        DSLSentence dsl1 = new DSLSentence();
        dsl1.setDefinition( "DSL Sentence 1" );
        dsl1.getValues().add( new DSLVariableValue( "dsl1v0" ) );
        dsl1.getValues().add( new DSLVariableValue( "dsl1v1" ) );
        model.lhs[1] = dsl1;

        RuleModelCloneVisitor cloneVisitor = new RuleModelCloneVisitor();
        RuleModel clone = cloneVisitor.visitRuleModel( model );

        assertEquals( 2,
                      clone.lhs.length );

        assertNotSame( model.lhs[0],
                       clone.lhs[0] );
        assertNotNull( clone.lhs[0] );
        assertTrue( clone.lhs[0] instanceof DSLSentence );
        DSLSentence dsl0Clone = (DSLSentence) clone.lhs[0];
        assertEquals( dsl0.getDefinition(),
                      dsl0Clone.getDefinition() );

        assertEquals( 2,
                      dsl0Clone.getValues().size() );
        assertNotSame( dsl0.getValues().get( 0 ),
                       dsl0Clone.getValues().get( 0 ) );
        assertNotNull( dsl0Clone.getValues().get( 0 ) );
        assertTrue( dsl0Clone.getValues().get( 0 ) instanceof DSLVariableValue );
        DSLVariableValue dsl0v0Clone = (DSLVariableValue) dsl0Clone.getValues().get( 0 );
        assertEquals( dsl0.getValues().get( 0 ).getValue(),
                      dsl0v0Clone.getValue() );

        assertNotSame( dsl0.getValues().get( 1 ),
                       dsl0Clone.getValues().get( 1 ) );
        assertNotNull( dsl0Clone.getValues().get( 1 ) );
        assertTrue( dsl0Clone.getValues().get( 1 ) instanceof DSLVariableValue );
        DSLVariableValue dsl0v1Clone = (DSLVariableValue) dsl0Clone.getValues().get( 1 );
        assertEquals( dsl0.getValues().get( 1 ).getValue(),
                      dsl0v1Clone.getValue() );

        assertNotSame( model.lhs[1],
                       clone.lhs[1] );
        assertNotNull( clone.lhs[1] );
        assertTrue( clone.lhs[1] instanceof DSLSentence );
        DSLSentence dsl1Clone = (DSLSentence) clone.lhs[1];
        assertEquals( dsl1.getDefinition(),
                      dsl1Clone.getDefinition() );

        assertEquals( 2,
                      dsl1Clone.getValues().size() );
        assertNotSame( dsl1.getValues().get( 0 ),
                       dsl0Clone.getValues().get( 0 ) );
        assertNotNull( dsl1Clone.getValues().get( 0 ) );
        assertTrue( dsl1Clone.getValues().get( 0 ) instanceof DSLVariableValue );
        DSLVariableValue dsl1v0Clone = (DSLVariableValue) dsl1Clone.getValues().get( 0 );
        assertEquals( dsl1.getValues().get( 0 ).getValue(),
                      dsl1v0Clone.getValue() );

        assertNotSame( dsl1.getValues().get( 1 ),
                       dsl1Clone.getValues().get( 1 ) );
        assertNotNull( dsl1Clone.getValues().get( 1 ) );
        assertTrue( dsl1Clone.getValues().get( 1 ) instanceof DSLVariableValue );
        DSLVariableValue dsl1v1Clone = (DSLVariableValue) dsl1Clone.getValues().get( 1 );
        assertEquals( dsl1.getValues().get( 1 ).getValue(),
                      dsl1v1Clone.getValue() );
    }
View Full Code Here


    // Add DSL sentences
    private void addDSLSentences() {
        if ( completions.getDSLActions().length > 0 ) {

            for ( int i = 0; i < completions.getDSLActions().length; i++ ) {
                final DSLSentence sen = completions.getDSLActions()[i];
                if ( sen != null ) {
                    String sentence = sen.toString();
                    choices.addItem( sentence,
                                     "DSL" + sentence );
                    cmds.put( "DSL" + sentence,
                              new Command() {
View Full Code Here

            final Combo dslCombo = new Combo( composite,
                                              SWT.READ_ONLY );
            dslCombo.add( heading );
            for ( int i = 0; i < getCompletion().getDSLActions().length; i++ ) {
                DSLSentence sen = getCompletion().getDSLActions()[i];
                dslCombo.add( sen.toString() );
            }

            dslCombo.select( 0 );

            dslCombo.addListener( SWT.Selection,
                                  new Listener() {
                                      public void handleEvent(Event event) {
                                          if ( dslCombo.getSelectionIndex() == 0 ) {
                                              return;
                                          }

                                          DSLSentence sentence = getCompletion().getDSLActions()[dslCombo.getSelectionIndex() - 1];
                                          modeller.getModel().addRhsItem( sentence.copy() );
                                          modeller.setDirty( true );
                                          modeller.reloadRhs();
                                          close();
                                      }
                                  } );
View Full Code Here

    /**
     * Add a DSL sentence for an action.
     */
    public void addDSLActionSentence(final String definition) {
        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( definition );
        this.actionDSLSentences.add( sen );
    }
View Full Code Here

    /**
     * Add a DSL sentence for a condition.
     */
    public void addDSLConditionSentence(final String definition) {
        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( definition );
        this.conditionDSLSentences.add( sen );
    }
View Full Code Here

    private DSLSentence[] makeArray(List<DSLSentence> ls) {
        return ls.toArray( new DSLSentence[ls.size()] );
    }

    public void addDSLMapping(DSLMappingEntry entry) {
        DSLSentence sen = new DSLSentence();
        sen.setDefinition( entry.getMappingKey() );
        if ( entry.getSection() == DSLMappingEntry.CONDITION ) {
            this.conditionDSLSentences.add( sen );
        } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) {
            this.actionDSLSentences.add( sen );
        } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) {
View Full Code Here

        }
        return clone;
    }

    private DSLSentence visitDSLSentence(final DSLSentence sentence) {
        DSLSentence clone = new DSLSentence();
        clone.setDefinition( sentence.getDefinition() );
        for ( DSLVariableValue value : sentence.getValues() ) {
            clone.getValues().add( (DSLVariableValue) visit( value ) );
        }
        return clone;
    }
View Full Code Here

            final Combo dslCombo = new Combo( composite,
                                              SWT.READ_ONLY );
            dslCombo.add( "Choose..." );

            for ( int i = 0; i < getCompletion().getDSLConditions().length; i++ ) {
                DSLSentence sen = getCompletion().getDSLConditions()[i];
                dslCombo.add( sen.toString() );
            }

            dslCombo.select( 0 );

            dslCombo.addListener( SWT.Selection,
                                  new Listener() {
                                      public void handleEvent(Event event) {
                                          if ( dslCombo.getSelectionIndex() == 0 ) {
                                              return;
                                          }

                                          DSLSentence sentence = getCompletion().getDSLConditions()[dslCombo.getSelectionIndex() - 1];
                                          // TODO Handle this kind of situations with care - add* can
                                          // throw runtime exceptions
                                          modeller.getModel().addLhsItem( sentence.copy() );

                                          modeller.reloadLhs();
                                          modeller.setDirty( true );
                                          close();
                                      }
View Full Code Here

        m.addRhsItem( new ActionSetField( "q" ) );

        assertFalse( m.hasDSLSentences() );

        m.addLhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m.addRhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m = new RuleModel();

        m.addLhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

        m = new RuleModel();
        m.addRhsItem( new DSLSentence() );
        assertTrue( m.hasDSLSentences() );

    }
View Full Code Here

        m.addRhsItem( set );

        final ActionRetractFact ret = new ActionRetractFact( "p1" );
        m.addRhsItem( ret );

        final DSLSentence sen = new DSLSentence();
        sen.setDefinition( "Send an email to {administrator}" );

        m.addRhsItem( sen );
        return m;
    }
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.brl.DSLSentence

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.