Package org.eclipse.sapphire

Examples of org.eclipse.sapphire.PossibleValuesService


{
  public static DirectEditManager createDirectEditorManager(GraphicalEditPart source, TextPart textPart, CellEditorLocator locator, Label label)
  {
    Value<?> property = FunctionUtil.getFunctionProperty(textPart.getLocalModelElement(),
        textPart.getContentFunction());
    PossibleValuesService possibleValuesService = property.service(PossibleValuesService.class);
    if (possibleValuesService != null)
    {
      return new ComboBoxDirectEditorManager(source, textPart, locator, label);
    }
    else
View Full Code Here


    this.nodePart = textPart.nearest(DiagramNodePart.class);
    this.pagePart = textPart.nearest(SapphireDiagramEditorPagePart.class);
    this.property = property;
    create(parent);
    this.combo = (CCombo)getControl();
    PossibleValuesService possibleValuesService = this.property.service(PossibleValuesService.class);
    Set<String> possibleValues = possibleValuesService.values();
    final String[] contentForCombo = new String[possibleValues.size()];
    possibleValues.toArray(contentForCombo);
    setItems(contentForCombo);
  }
View Full Code Here

    if (initValue == null)
    {
      initValue = this.textPart.getContent();
    }
    this.initialValue = initValue;
    PossibleValuesService possibleValuesService = this.property.service(PossibleValuesService.class);
    Set<String> possibleValues = possibleValuesService.values();
    Iterator<String> it = possibleValues.iterator();
    int index = -1;
    while (it.hasNext())
    {
      index++;
View Full Code Here

   
    @Override
    protected String browse( final Presentation context )
    {
        final Value<?> property = property();
        final PossibleValuesService possibleValuesService = property().service( PossibleValuesService.class );

        if( possibleValuesService != null )
        {
            final Collection<String> valuesList = possibleValuesService.values();
            final String[] valuesArray = valuesList.toArray( new String[ valuesList.size() ] );
           
            final ValueLabelProvider labelProvider = new ValueLabelProvider( (PropertyEditorPart) getPart(), property );
           
            final ElementListSelectionDialog dialog = new ElementListSelectionDialog( ( (FormComponentPresentation) context ).shell(), labelProvider );
View Full Code Here

            toolBarActionsPresentation.render();
            addControl( toolbar );
            decorator.addEditorControl( toolbar );
        }
       
        final PossibleValuesService possibleValuesService = property.service( PossibleValuesService.class );
        final ValueNormalizationService valueNormalizationService = property.service( ValueNormalizationService.class );
       
        final MutableReference<List<PossibleValue>> possibleValuesRef = new MutableReference<List<PossibleValue>>();
       
        final Runnable updateComboSelectionOp = new Runnable()
        {
            public void run()
            {
                if( PopUpListFieldPropertyEditorPresentation.this.updatingModel || combo.isDisposed() )
                {
                    return;
                }
               
                final String text = valueNormalizationService.normalize( property.text() );
               
                try
                {
                    PopUpListFieldPropertyEditorPresentation.this.updatingEditor = true;

                    combo.setData( DATA_DEFAULT_VALUE, property.empty() );
                   
                    if( text == null )
                    {
                        combo.deselectAll();
                        combo.setText( EMPTY_STRING );
                    }
                    else
                    {
                        final List<PossibleValue> possibleValues = possibleValuesRef.get();
                        final int possibleValuesCount = possibleValues.size();
                        int possibleValueIndex = -1;
                       
                        for( int i = 0; i < possibleValuesCount && possibleValueIndex == -1; i++ )
                        {
                            if( equal( possibleValues.get( i ).value(), text ) )
                            {
                                possibleValueIndex = i;
                            }
                        }
   
                        if( PopUpListFieldPropertyEditorPresentation.this.style == PopUpListFieldStyle.STRICT )
                        {
                            if( possibleValueIndex == -1 )
                            {
                                if( possibleValues.size() == combo.getItemCount() )
                                {
                                    combo.add( text );
                                }
                                else
                                {
                                    final String existingNonConformingValue = combo.getItem( possibleValuesCount );
                                   
                                    if( ! existingNonConformingValue.equals( text ) )
                                    {
                                        combo.setItem( possibleValuesCount, text );
                                    }
                                }
                               
                                possibleValueIndex = possibleValuesCount;
                            }
                            else if( possibleValuesCount < combo.getItemCount() )
                            {
                                combo.remove( possibleValuesCount );
                            }
                        }
                       
                        if( possibleValueIndex != -1 )
                        {
                            if( combo.getSelectionIndex() != possibleValueIndex )
                            {
                                combo.setText( EMPTY_STRING );
                                combo.select( possibleValueIndex );
                            }
                        }
                        else
                        {
                            if( ! equal( valueNormalizationService.normalize( combo.getText() ), text ) )
                            {
                                combo.deselectAll();
                                combo.setText( text );
                            }
                        }
                    }
                }
                finally
                {
                    PopUpListFieldPropertyEditorPresentation.this.updatingEditor = false;
                }
            }
        };

        final Runnable updateComboContentOp = new Runnable()
        {
            private final PossibleValue.Factory factory = PossibleValue.factory( property );
           
            public void run()
            {
                if( PopUpListFieldPropertyEditorPresentation.this.updatingModel || combo.isDisposed() )
                {
                    return;
                }
               
                try
                {
                    PopUpListFieldPropertyEditorPresentation.this.updatingEditor = true;
                   
                    final List<PossibleValue> possibleValues = this.factory.entries();
                    possibleValuesRef.set( possibleValues );
                   
                    final String[] contentForCombo = new String[ possibleValues.size() ];
                   
                    for( int i = 0, n = possibleValues.size(); i < n; i++ )
                    {
                        contentForCombo[ i ] = possibleValues.get( i ).label();
                    }
                   
                    combo.setItems( contentForCombo );
                }
                finally
                {
                    PopUpListFieldPropertyEditorPresentation.this.updatingEditor = false;
                }
               
                updateComboSelectionOp.run();
            }
        };
       
        updateComboContentOp.run();
       
        final Listener possibleValuesServiceListener = new Listener()
        {
            @Override
            public void handle( final Event event )
            {
                runOnDisplayThread( updateComboContentOp );
            }
        };
       
        possibleValuesService.attach( possibleValuesServiceListener );
       
        final Listener propertyListener = new FilteredListener<PropertyContentEvent>()
        {
            @Override
            protected void handleTypedEvent( final PropertyContentEvent event )
            {
                runOnDisplayThread( updateComboSelectionOp );
            }
        };
       
        property.attach( propertyListener );
       
        combo.addModifyListener
        (
            new ModifyListener()
            {
                public void modifyText( final ModifyEvent e )
                {
                    if( PopUpListFieldPropertyEditorPresentation.this.updatingEditor )
                    {
                        return;
                    }
                   
                    try
                    {
                        PopUpListFieldPropertyEditorPresentation.this.updatingModel = true;
                       
                        String value = null;
                       
                        final int index = combo.getSelectionIndex();
                       
                        if( index != -1 )
                        {
                            final List<PossibleValue> possible = possibleValuesRef.get();
                           
                            if( index < possible.size() )
                            {
                                value = possible.get( index ).value();
                            }
                        }
                       
                        if( value == null )
                        {
                            value = combo.getText().trim();
                        }
                       
                        if( value != null && value.length() == 0 )
                        {
                            value = null;
                        }
   
                        setPropertyValue( value );
                    }
                    finally
                    {
                        PopUpListFieldPropertyEditorPresentation.this.updatingModel = false;
                    }
                }
            }
        );
       
        if( this.style == PopUpListFieldStyle.EDITABLE )
        {
            combo.addFocusListener
            (
                new FocusAdapter()
                {
                    @Override
                    public void focusLost( final FocusEvent event )
                    {
                        // If an editable pop-up list was presenting the default value and user clears it, there is
                        // no change in the model, but we need to restore the display of the default value in the UI.
                       
                        updateComboSelectionOp.run();
                    }
                }
            );
        }
       
        addOnDisposeOperation
        (
            new Runnable()
            {
                public void run()
                {
                    possibleValuesService.detach( possibleValuesServiceListener );
                    property.detach( propertyListener );
                }
            }
        );
    }
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.PossibleValuesService

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.