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

Examples of org.drools.ide.common.client.modeldriven.SuggestionCompletionEngine


        popup.show();

    }

    private Widget valueEditor(final ActionFieldValue val) {
        SuggestionCompletionEngine completions = this.getModeller().getSuggestionCompletions();
        String type = "";
        if ( completions.isGlobalVariable( this.model.variable ) ) {
            type = (String) completions.getGlobalVariable( this.model.variable );
        } else {
            type = this.getModeller().getModel().getLHSBindingType( this.model.variable );
            /*
             * to take in account if the using a rhs bound variable
             */
            if ( type == null ) {
                type = this.getModeller().getModel().getRHSBoundFact( this.model.variable ).factType;
            }
        }

        DropDownData enums = completions.getEnums( type,
                                                   this.model.fieldValues,
                                                   val.field );
        ActionValueEditor actionValueEditor = new ActionValueEditor( val,
                                                                     enums,
                                                                     this.getModeller(),
View Full Code Here


    @WebRemote
    @LoggedIn
    public SuggestionCompletionEngine loadSuggestionCompletionEngine(String packageName) throws SerializationException {
        //No need to check role based permission here. Package auto completion suggestion should be available to everybody.
        //serviceSecurity.checkSecurityIsPackageReadOnlyWithPackageName( packageName );
        SuggestionCompletionEngine suggestionCompletionEngine = null;
        try {
            ModuleItem packageItem = rulesRepository.loadModule( packageName );
            suggestionCompletionEngine = new SuggestionCompletionEngineLoaderInitializer().loadFor( packageItem );
        } catch ( RulesRepositoryException e ) {
            log.error( "An error occurred loadSuggestionCompletionEngine: " + e.getMessage() );
View Full Code Here

        toolkit.paintBordersFor( composite );
        return composite;
    }

    private void createSubfieldConstraintRow(final Composite composite) {
        SuggestionCompletionEngine engine = modeller.getSuggestionCompletionEngine();
        String[] fields = engine.getFieldCompletions( con.getFieldType() );
        if ( fields == null || fields.length <= 0 ) {
            return;
        }
        createLabel( composite,
                     "Add a restriction on a subfield" );
        final Combo combo = new Combo( composite,
                                       SWT.DROP_DOWN | SWT.READ_ONLY );
        combo.add( "..." );
        for ( int i = 0; i < fields.length; i++ ) {
            String field = fields[i];
            combo.add( field );
            combo.setData( field,
                           engine.getFieldType( con.getFieldType() + "." + field ) );
        }
        combo.select( 0 );

        combo.addModifyListener( new ModifyListener() {
View Full Code Here

    /**
     * Start the creation of a new SuggestionCompletionEngine
     */
    public void newCompletionEngine() {
        this.instance = new SuggestionCompletionEngine();
        this.factTypes = new HashMap<String, FIELD_CLASS_TYPE>();
        this.annotationsForType = new HashMap<String, Map<String, Map<String, String>>>();
        this.fieldsForType = new HashMap<String, String[]>();
        this.fieldTypes = new HashMap<String, String>();
        this.fieldTypesField = new HashMap<String, FieldInfo>();
View Full Code Here

        pkg += "number: Integer\n";
        pkg += "end\n";

        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();

        SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg,
                                                                        new ArrayList<JarInputStream>(),
                                                                        new ArrayList<DSLTokenizedMappingFile>(),
                                                                        new ArrayList<String>() );

        String[] accessors = engine.getFieldCompletions(
                                                         FieldAccessorsAndMutators.ACCESSOR,
                                                         "Test" );
        assertEquals( 2,
                      accessors.length );

        String[] mutators = engine.getFieldCompletions(
                                                        FieldAccessorsAndMutators.MUTATOR,
                                                        "Test" );
        assertEquals( 1,
                      mutators.length );
View Full Code Here

    public void testAccessorsAndMutatorsJavaClass() throws Exception {
        String pkg = "package org.test\n import org.drools.ide.common.client.modeldriven.SuggestionCompletionEngine2Test.Person\n";

        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();

        SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg,
                                                                        new ArrayList<JarInputStream>(),
                                                                        new ArrayList<DSLTokenizedMappingFile>(),
                                                                        new ArrayList<String>() );

        String[] accessors = engine.getFieldCompletions(
                                                         FieldAccessorsAndMutators.ACCESSOR,
                                                         "Person" );
        assertEquals( 3,
                      accessors.length );

        String[] mutators = engine.getFieldCompletions(
                                                        FieldAccessorsAndMutators.MUTATOR,
                                                        "Person" );
        assertEquals( 2,
                      mutators.length );
View Full Code Here

                                                                  throws Exception {
        String pkg = "package org.test\n import java.util.TreeMap\n";

        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();

        SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg,
                                                                        new ArrayList<JarInputStream>(),
                                                                        new ArrayList<DSLTokenizedMappingFile>(),
                                                                        new ArrayList<String>() );

        String[] accessors = engine.getFieldCompletions( FieldAccessorsAndMutators.ACCESSOR,
                                                         "TreeMap" );
        assertEquals( 2,
                      accessors.length );
        assertEquals( "this",
                      accessors[0] );
        assertEquals( "empty",
                      accessors[1] );

        String[] mutators = engine.getFieldCompletions( FieldAccessorsAndMutators.MUTATOR,
                                                        "TreeMap" );
        assertEquals( 0,
                      mutators.length );

    }
View Full Code Here

    public void testArrayList() {

        String pkg = "package org.test\n global java.util.ArrayList testList";
        SuggestionCompletionLoader loader = new SuggestionCompletionLoader();

        SuggestionCompletionEngine engine = loader.getSuggestionEngine( pkg,
                                                                        new ArrayList<JarInputStream>(),
                                                                        new ArrayList<DSLTokenizedMappingFile>(),
                                                                        new ArrayList<String>() );

        List<String> methodNames = engine.getMethodNames( "ArrayList" );

        // for ( String name : methodNames ) {
        // System.out.println( name );
        // }
View Full Code Here

        // Add jar file
        String header = "package foo \n import org.test.Person \n import org.test.Banana \n ";
        List<JarInputStream> jars = new ArrayList<JarInputStream>();
        JarInputStream jis = null;
        SuggestionCompletionEngine suggestionCompletionEngine = null;

        try {
            jis = new JarInputStream( this.getClass().getResourceAsStream(
                                                                           "/JarWithSourceFiles.jar" ) );
            jars.add( jis );
        } catch ( IOException e ) {
            fail( "Could not load jar" );
        }

        try {
            suggestionCompletionEngine = loader.getSuggestionEngine( header,
                                                                     jars,
                                                                     new ArrayList<DSLTokenizedMappingFile>() );
        } catch ( ClassFormatError e ) {
            fail( "Can not load suggestions " + e );
        }

        // Check that it throws no error and has class files inside.
        assertNotNull( jis );
        assertNotNull( suggestionCompletionEngine );
        assertEquals( 2,
                      suggestionCompletionEngine.getFactTypes().length );

        List<String> list = Arrays.asList( suggestionCompletionEngine
                .getFactTypes() );

        assertTrue( list.contains( "Person" ) );
        assertTrue( list.contains( "Banana" ) );

        assertEquals( "java.util.Collection",
                      suggestionCompletionEngine.getFieldClassName( "Person",
                                                                    "bananas" ) );
        assertEquals( SuggestionCompletionEngine.TYPE_COLLECTION,
                      suggestionCompletionEngine.getFieldType( "Person",
                                                               "bananas" ) );
        assertEquals( "Banana",
                      suggestionCompletionEngine.getParametricFieldType( "Person",
                                                                         "bananas" ) );

    }
View Full Code Here

        PackageItem pkg = repo.loadPackage( "com.billasurf.manufacturing.plant" );
        DroolsHeader.updateDroolsHeader( "import com.billasurf.Board\nimport com.billasurf.Person" + "\n\nglobal com.billasurf.Person prs",
                                                  pkg );
        pkg.checkin( "added imports" );

        SuggestionCompletionEngine eng = serv.loadSuggestionCompletionEngine( "com.billasurf.manufacturing.plant" );
        assertNotNull( eng );

        //The loader could define extra imports
        assertTrue( eng.getFactTypes().length >= 2 );
        String[] fields = (String[]) eng.getModelFields( "Board" );
        assertTrue( fields.length >= 3 );

        String[] globalVars = eng.getGlobalVariables();
        assertEquals( 1,
                      globalVars.length );
        assertEquals( "prs",
                      globalVars[0] );
        assertTrue( eng.getFieldCompletionsForGlobalVariable( "prs" ).length >= 2 );

        fields = (String[]) eng.getModelFields( "Person" );

        assertTrue( fields.length >= 2 );

    }
View Full Code Here

TOP

Related Classes of org.drools.ide.common.client.modeldriven.SuggestionCompletionEngine

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.