Package org.eclipse.sapphire

Examples of org.eclipse.sapphire.Element


    {
        A result = service( MasterConversionService.class ).convert( this, adapterType );

        if( result == null )
        {
            final Element element = getLocalModelElement();
           
            if( element != null )
            {
                result = element.adapt( adapterType );
            }
        }
   
        if( result == null && this.parent != null )
        {
View Full Code Here


            final SapphirePart part = ( (PartFunctionContext) context ).part();
            final MasterDetailsEditorPagePart page = part.nearest( MasterDetailsEditorPagePart.class );
           
            if( page != null )
            {
                final Element element = part.getLocalModelElement();
               
                if( element instanceof Item )
                {
                    final Item item = (Item) element;
                    final MasterDetailsEditorPageState state = page.state();
   
                    return new FunctionResult( this, context )
                    {
                        private Listener listener;
                       
                        @Override
                        protected void init()
                        {
                            this.listener = new FilteredListener<PropertyContentEvent>()
                            {
                                @Override
                                protected void handleTypedEvent( final PropertyContentEvent event )
                                {
                                    refresh();
                                }
                            };
                           
                            state.attach( this.listener, MasterDetailsEditorPageState.PROP_ATTRIBUTES.name() + "/*" );
                            element.property( Item.PROP_MANUFACTURER ).attach( this.listener );
                        }
   
                        @Override
                        protected Object evaluate()
                        {
                            final boolean color = state.getAttribute( ShowManufacturerColorActionHandler.ATTRIBUTE, false );
                           
                            if( color )
                            {
                                final String manufacturer = item.getManufacturer().content();
                                final int hashCode = ( manufacturer == null ? 0 : manufacturer.hashCode() );
                                final int index = abs( hashCode ) % IMAGES.length;
                               
                                return IMAGES[ index ];
                            }
                            else
                            {
                                return IMAGE_GENERIC;
                            }
                        }
   
                        @Override
                        public void dispose()
                        {
                            super.dispose();
                           
                            if( this.listener != null )
                            {
                                state.detach( this.listener, MasterDetailsEditorPageState.PROP_ATTRIBUTES.name() + "/*" );
                               
                                if( ! element.disposed() )
                                {
                                    element.property( Item.PROP_MANUFACTURER ).detach( this.listener );
                                }
                               
                                this.listener = null;
                            }
                        }
View Full Code Here

        @Override
        protected Map<String,String> fillTracingInfo( Map<String,String> info )
        {
            super.fillTracingInfo( info );
           
            final Element element = this.part.getLocalModelElement();
            info.put( "part", this.part.getClass().getName() + '(' + System.identityHashCode( this.part ) + ')' );
            info.put( "element", element.type().getQualifiedName() + '(' + System.identityHashCode( element ) + ')' );
           
            return info;
        }
View Full Code Here

               
                if( resource != null )
                {
                    try
                    {
                        final Element element = type.instantiate( resource );
                       
                        try
                        {
                            element.initialize();
                            resource.save();
                        }
                        finally
                        {
                            element.dispose();
                        }
                    }
                    catch( ResourceStoreException e )
                    {
                        return Status.createErrorStatus( e );
View Full Code Here

    public void init( final SapphireAction action,
                      final ActionHandlerDef def )
    {
        super.init( action, def );
       
        final Element element = getModelElement();
       
        final Listener listener = new FilteredListener<PropertyContentEvent>()
        {
            @Override
            protected void handleTypedEvent( final PropertyContentEvent event )
            {
                refreshEnablementState();
            }
        };
       
        element.property( IAttendee.PROP_IN_CONTACT_REPOSITORY ).attach( listener );
       
        refreshEnablementState();
       
        attach
        (
            new FilteredListener<DisposeEvent>()
            {
                @Override
                protected void handleTypedEvent( final DisposeEvent event )
                {
                    element.property( IAttendee.PROP_IN_CONTACT_REPOSITORY ).detach( listener );
                }
            }
        );
    }
View Full Code Here

    @Override
    protected Object run( final Presentation context )
    {
        final ISapphirePart part = getPart();
        final CalendarEditor editor = part.nearest( CalendarEditor.class );
        final Element modelElement = part.getModelElement();
       
        ContactDetailsJumpHandler.jump( editor, modelElement );
       
        return null;
    }
View Full Code Here

    {
        final SectionDef section = context( SectionDef.class );
       
        if( section.parent() != null )
        {
            final Element parent = section.parent().element();
           
            if( parent instanceof MasterDetailsContentNodeDef )
            {
                this.node = (MasterDetailsContentNodeDef) parent;
               
View Full Code Here

    }

    @Override
    public ImageData convert( final String string )
    {
        final Element element = context( Element.class );
        final Context ctxt = element.adapt( Context.class );
       
        InputStream stream = null;
       
        if( string != null && ! string.contains( "/" ) )
        {
            final ISapphireUiDef sdef = element.nearest( ISapphireUiDef.class );
           
            if( sdef != null )
            {
                for( IPackageReference p : sdef.getImportedPackages() )
                {
View Full Code Here

            {
                obj = type.cast( this.part );
            }
            else if( Element.class.isAssignableFrom( type ) )
            {
                final Element element = this.part.getLocalModelElement();
               
                if( element != null )
                {
                    if( type == Element.class )
                    {
                        obj = type.cast( element );
                    }
                    else
                    {
                        obj = element.nearest( type );
                    }
                }
            }
        }
       
View Full Code Here

                            {
                                masterCheckBox.getDisplay().asyncExec( this );
                                return;
                            }
                           
                            final Element subModelElement = ( (ElementHandle<?>) property ).content();
                           
                            masterCheckBox.setSelection( subModelElement != null );
                            masterCheckBox.setEnabled( property.enabled() );
                        }
                    };
                           
                    masterCheckBox.addSelectionListener
                    (
                        new SelectionAdapter()
                        {
                            @Override
                            public void widgetSelected( final SelectionEvent event )
                            {
                                try
                                {
                                    final ElementHandle<?> handle = (ElementHandle<?>) property;
                                   
                                    if( masterCheckBox.getSelection() == true )
                                    {
                                        handle.content( true );
                                    }
                                    else
                                    {
                                        handle.clear();
                                    }
                                }
                                catch( Exception e )
                                {
                                    // Note that the EditFailedException is ignored here because the user has already
                                    // been notified and likely has taken action that led to the exception (such as
                                    // declining to make a file writable).
                                   
                                    final EditFailedException editFailedException = EditFailedException.findAsCause( e );
                                   
                                    if( editFailedException == null )
                                    {
                                        Sapphire.service( LoggingService.class ).log( e );
                                    }
                                }
                            }
                        }
                    );
                }
                else
                {
                    typeSelectorComposite.setLayout( glspacing( glayout( 3, 0, 0 ), 2 ) );
                   
                    if( showLabel )
                    {
                        final Label label = new Label( typeSelectorComposite, SWT.NONE );
                        label.setLayoutData( gdhindent( gd(), 9 ) );
                        label.setText( part.label( CapitalizationType.FIRST_WORD_ONLY, true ) + ":" );
                       
                        attachPartListener
                        (
                            new FilteredListener<LabelChangedEvent>()
                            {
                                @Override
                                protected void handleTypedEvent( final LabelChangedEvent event )
                                {
                                    label.setText( part.label( CapitalizationType.FIRST_WORD_ONLY, true ) + ":" );
                                    layout();
                                }
                            }
                        );
                    }
                   
                    final PropertyEditorAssistDecorator decorator = new PropertyEditorAssistDecorator( part, property, typeSelectorComposite );
                    decorator.control().setLayoutData( gdhindent( gdvalign( gd(), ( style == Style.DROP_DOWN_LIST ? SWT.TOP : SWT.CENTER ) ), ( showLabel ? 3 : 0 ) ) );
                   
                    if( style == Style.RADIO_BUTTONS )
                    {
                        final RadioButtonsGroup radioButtonsGroup = new RadioButtonsGroup( typeSelectorComposite, false );
                        radioButtonsGroup.setLayoutData( gdhfill() );
                       
                        final Map<ElementType,Button> typeToButton = new HashMap<ElementType,Button>();
                        final Map<Button,ElementType> buttonToType = new HashMap<Button,ElementType>();
                       
                        for( final ElementType type : allPossibleTypes )
                        {
                            final String label = type.getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false );
                            final Button button = radioButtonsGroup.addRadioButton( label );
                            typeToButton.put( type, button );
                            buttonToType.put( button, type );
                            decorator.addEditorControl( button );
                            actionPresentationKeyboard.attach( button );
                            attachHelp( button, property );
                        }
                       
                        final Button noneButton = radioButtonsGroup.addRadioButton( noneSelection.text() );
                        noneButton.setVisible( false );
                        decorator.addEditorControl( noneButton );
                        actionPresentationKeyboard.attach( noneButton );
                        attachHelp( noneButton, property );
                       
                        updateUserInterfaceOp = new Runnable()
                        {
                            public void run()
                            {
                                if( Display.getCurrent() == null )
                                {
                                    radioButtonsGroup.getDisplay().asyncExec( this );
                                    return;
                                }
                               
                                final Element subModelElement = ( (ElementHandle<?>) property ).content();
                                final Button button;
                               
                                if( subModelElement == null )
                                {
                                    button = noneButton;
                                    noneButton.setVisible( true );
                                }
                                else
                                {
                                    button = typeToButton.get( subModelElement.type() );
                                    noneButton.setVisible( false );
                                }
                               
                                if( radioButtonsGroup.getSelection() != button )
                                {
                                    radioButtonsGroup.setSelection( button );
                                }
                               
                                radioButtonsGroup.setEnabled( property.enabled() );
                            }
                        };
                               
                        radioButtonsGroup.addSelectionListener
                        (
                            new SelectionAdapter()
                            {
                                @Override
                                public void widgetSelected( final SelectionEvent event )
                                {
                                    try
                                    {
                                        final ElementHandle<?> handle = (ElementHandle<?>) property;
                                        final Button button = radioButtonsGroup.getSelection();
                                       
                                        if( button == noneButton )
                                        {
                                            handle.clear();
                                        }
                                        else
                                        {
                                            final ElementType type = buttonToType.get( button );
                                            handle.content( true, type );
                                        }
                                    }
                                    catch( Exception e )
                                    {
                                        // Note that the EditFailedException is ignored here because the user has already
                                        // been notified and likely has taken action that led to the exception (such as
                                        // declining to make a file writable).
                                       
                                        final EditFailedException editFailedException = EditFailedException.findAsCause( e );
                                       
                                        if( editFailedException == null )
                                        {
                                            Sapphire.service( LoggingService.class ).log( e );
                                        }
                                    }
                                }
                            }
                        );
                    }
                    else if( style == Style.DROP_DOWN_LIST )
                    {
                        final Combo combo = new Combo( typeSelectorComposite, SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY );
                        combo.setLayoutData( gdhfill() );
                        decorator.addEditorControl( combo );
                        actionPresentationKeyboard.attach( combo );
                        attachHelp( combo, property );
                       
                        final Map<ElementType,Integer> typeToIndex = new HashMap<ElementType,Integer>();
                        final Map<Integer,ElementType> indexToType = new HashMap<Integer,ElementType>();
                       
                        int index = 0;
                       
                        for( ElementType type : allPossibleTypes )
                        {
                            final String label = type.getLabel( true, CapitalizationType.FIRST_WORD_ONLY, false );
                            combo.add( label );
                            typeToIndex.put( type, index );
                            indexToType.put( index, type );
                           
                            index++;
                        }
                       
                        updateUserInterfaceOp = new Runnable()
                        {
                            public void run()
                            {
                                if( Display.getCurrent() == null )
                                {
                                    combo.getDisplay().asyncExec( this );
                                    return;
                                }
                               
                                final Element subModelElement = ( (ElementHandle<?>) property ).content();
                                final int index;
                               
                                if( subModelElement == null )
                                {
                                    index = -1;
                                }
                                else
                                {
                                    index = typeToIndex.get( subModelElement.type() );
                                }
                               
                                if( combo.getSelectionIndex() != index )
                                {
                                    if( index == -1 )
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.Element

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.