Package org.eclipse.sapphire.modeling.el

Examples of org.eclipse.sapphire.modeling.el.Function


    {
        if( property != null )
        {
            final MasterVersionCompatibilityService service = property.service( MasterVersionCompatibilityService.class );
           
            final Function function = new Function()
            {
                @Override
                public String name()
                {
                    return "VersionCompatible";
                }

                @Override
                public FunctionResult evaluate( final FunctionContext context )
                {
                    return new FunctionResult( this, context )
                    {
                        private Listener serviceListener;
                        private Listener propertyListener;
                       
                        @Override
                        protected void init()
                        {
                            this.serviceListener = new Listener()
                            {
                                @Override
                                public void handle( final Event event )
                                {
                                    refresh();
                                }
                            };
                           
                            service.attach( this.serviceListener );
                           
                            this.propertyListener = new FilteredListener<PropertyContentEvent>()
                            {
                                @Override
                                protected void handleTypedEvent( final PropertyContentEvent event )
                                {
                                    refresh();
                                }
                            };
                           
                            if( property.definition() instanceof ImpliedElementProperty )
                            {
                                property.element().attach( this.propertyListener, property.name() + "/*" );
                            }
                            else
                            {
                                property.element().attach( this.propertyListener, property.name() );
                            }
                        }

                        @Override
                        protected Object evaluate()
                        {
                            return service.compatible() || ! property.empty();
                        }
                       
                        @Override
                        public void dispose()
                        {
                            super.dispose();
                           
                            service.detach( this.serviceListener );

                            if( property.definition() instanceof ImpliedElementProperty )
                            {
                                property.element().detach( this.propertyListener, property.name() + "/*" );
                            }
                            else
                            {
                                property.element().detach( this.propertyListener, property.name() );
                            }
                        }
                    };
                }
            };
           
            function.init();
           
            return function;
        }
       
        return null;
View Full Code Here


       
        if( def != null )
        {
            this.id = def.getId().content();
           
            final Function labelFunction = FailSafeFunction.create( def.getLabel().content(), Literal.create( String.class ) );
           
            this.labelFunctionResult = labelFunction.evaluate( this.functionContext );
           
            this.labelFunctionResult.attach
            (
                new Listener()
                {
                    @Override
                    public void handle( final Event event )
                    {
                        broadcast( new LabelChangedEvent() );
                    }
                }
            );
           
            final Function toolTipFunction = FailSafeFunction.create( def.getToolTip().content(), Literal.create( String.class ) );

            this.toolTipFunctionResult = toolTipFunction.evaluate( this.functionContext );

            this.toolTipFunctionResult.attach
            (
                new Listener()
                {
                    @Override
                    public void handle( final Event event )
                    {
                        broadcast( new ToolTipChangedEvent() );
                    }
                }
            );

            this.description = def.getDescription().content();
           
            for( ImageReference image : def.getImages() )
            {
                final Function imageFunction = FailSafeFunction.create( image.getImage().content(), Literal.create( ImageData.class ) );
                final FunctionResult imageFunctionResult = imageFunction.evaluate( this.functionContext );
                final ImageData data = (ImageData) imageFunctionResult.value();
               
                if( data != null )
                {
                    this.images.add( data );
View Full Code Here

            public FunctionResult property( final Object element,
                                            final String name )
            {
                if( element == this && name.equalsIgnoreCase( "handlers" ) )
                {
                    final Function f = new Function()
                    {
                        @Override
                        public String name()
                        {
                            return "ReadProperty";
                        }
                       
                        @Override
                        public FunctionResult evaluate( final FunctionContext context )
                        {
                            return new FunctionResult( this, context )
                            {
                                private Listener listener;
                               
                                @Override
                                protected void init()
                                {
                                    super.init();
                                   
                                    this.listener = new Listener()
                                    {
                                        @Override
                                        public void handle( final Event event )
                                        {
                                            if( event instanceof HandlersChangedEvent )
                                            {
                                                refresh();
                                            }
                                        }
                                    };
                                   
                                    SapphireAction.this.attach( this.listener );
                                }

                                @Override
                                protected Object evaluate()
                                {
                                    return getActiveHandlers();
                                }

                                @Override
                                public void dispose()
                                {
                                    super.dispose();
                                    SapphireAction.this.detach( this.listener );
                                }
                            };
                        }
                    };
                   
                    f.init();
                   
                    return f.evaluate( this );
                }
                else if( element instanceof SapphireActionHandler && name.equalsIgnoreCase( "label" ) )
                {
                    return Literal.create( ( (SapphireActionHandler) element ).getLabel() ).evaluate( this );
                }
View Full Code Here

{
    @Test
   
    public void testAndFunction()
    {
        Function function;
       
        function = AndFunction.create();
        assertNull( function );
       
        function = AndFunction.create( Literal.TRUE );
View Full Code Here

   
    @Test

    public void testOrFunction()
    {
        Function function;
       
        function = OrFunction.create();
        assertNull( function );
       
        function = OrFunction.create( Literal.TRUE );
View Full Code Here

            return this.signature;
        }

        public Function create()
        {
            Function function = null;

            if( ! this.functionInstantiationFailed )
            {
                try
                {
                    function = this.functionClass.newInstance();
                    function.initSignature( this.signature );
                }
                catch( Exception e )
                {
                    Sapphire.service( LoggingService.class ).log( e );
                    function = null;
View Full Code Here

    @Override
    protected void initFileExtensionsService()
    {
        final FileExtensions fileExtensionsAnnotation = context( PropertyDef.class ).getAnnotation( FileExtensions.class );
       
        Function function = null;
       
        try
        {
            function = ExpressionLanguageParser.parse( fileExtensionsAnnotation.expr() );
        }
        catch( Exception e )
        {
            Sapphire.service( LoggingService.class ).log( e );
            function = null;
        }
       
        if( function != null )
        {
            function = FailSafeFunction.create( function, Literal.create( List.class ), Literal.create( Collections.emptyList() ) );
           
            this.functionResult = function.evaluate( new ModelElementFunctionContext( context( Element.class ) ) );
           
            this.functionResult.attach
            (
                new Listener()
                {
View Full Code Here

   
    protected FunctionResult getNodeReferenceFunction(final DiagramNodePart nodePart,
                                                final Value<Function> function,
                                                LocalizationService ls)
    {
        Function f = null;
        FunctionResult fr = null;
       
        if( function != null )
        {
            f = function.content();
        }
       
        if( f != null )
        {
           
            f = FailSafeFunction.create( f, Literal.create( String.class ) );
            fr = f.evaluate( new ModelElementFunctionContext( nodePart.getLocalModelElement(), ls ));
        }
        return fr;
    }
View Full Code Here

  }
   
  @Override
    protected Function initVisibleWhenFunction()
    {
    final Function function = new Function()
        {
            @Override
            public String name()
            {
                return "ValidationMarkerVisibleWhen";
            }

      @Override
      public FunctionResult evaluate(FunctionContext context)
      {       
            return new FunctionResult( this, context )
            {
          private Listener validationListener;
         
                    @Override
                    protected void init()
                    {
                        this.validationListener = new FilteredListener<ValidationMarkerContentEvent>()
                        {
                          @Override
                            protected void handleTypedEvent( ValidationMarkerContentEvent event )
                            {
                            refresh();
                            }
                        };
                     
                        ValidationMarkerPart.this.attach(this.validationListener);
                    }
                   
                @Override
                protected Object evaluate()
                {
                  Status status = content(); //getLocalModelElement().validation();
                  return !status.ok();
                }

                @Override
                    public void dispose()
                    {
                        super.dispose();
                       
                        ValidationMarkerPart.this.detach(this.validationListener);
                    }
               
            };
      }
        };
        function.init();
        return function;
   
View Full Code Here

    private FunctionResult functionResult;
   
    @Override
    protected void initRequiredConstraintService()
    {
        Function function;
       
        final Required annotation = context( PropertyDef.class ).getAnnotation( Required.class );
       
        if( annotation == null )
        {
            function = Literal.FALSE;
        }
        else
        {
            final String expr = annotation.value().trim();
           
            if( expr.length() == 0 )
            {
                function = Literal.TRUE;
            }
            else
            {
                try
                {
                    function = ExpressionLanguageParser.parse( expr );
                    function = FailSafeFunction.create( function, Boolean.class, false );
                }
                catch( Exception e )
                {
                    Sapphire.service( LoggingService.class ).log( e );
                    function = Literal.FALSE;
                }
            }
        }

        final ModelElementFunctionContext context = new ModelElementFunctionContext( context( Element.class ) );
       
        this.functionResult = function.evaluate( context );
       
        final Listener listener = new Listener()
        {
            @Override
            public void handle( final Event event )
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.modeling.el.Function

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.