Package org.eclipse.sapphire.ui.forms

Examples of org.eclipse.sapphire.ui.forms.PropertyEditorPart


        setAddActionDesired( ! this.possibleValuesService.strict() );
    }

    public Control createSourceControl( final Composite parent )
    {
        final PropertyEditorPart part = part();
       
        final Composite composite = new Composite( parent, SWT.NONE );
        composite.setLayout( glayout( 1, 0, 0 ) );
       
        // Setting the whint in the following code is a hacky workaround for the problem
        // tracked by the following JFace bug:
        //
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=215997
        //
       
        final Composite innerComposite = new Composite( composite, SWT.NONE );
        innerComposite.setLayoutData( gdwhint( gdfill(), 1 ) );
       
        final TableColumnLayout tableColumnLayout = new TableColumnLayout();
        innerComposite.setLayout( tableColumnLayout );
       
        this.sourceTableViewer = new TableViewer( innerComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI );
        this.sourceTable = this.sourceTableViewer.getTable();
       
        final boolean showHeader = part.getRenderingHint( PropertyEditorDef.HINT_SHOW_HEADER, true );
        this.sourceTable.setHeaderVisible( showHeader );
       
        final TableViewerColumn viewerColumn = new TableViewerColumn( this.sourceTableViewer, SWT.NONE );
        final TableColumn column = viewerColumn.getColumn();
        column.setText( this.memberProperty.getLabel( false, CapitalizationType.TITLE_STYLE, false ) );
View Full Code Here


    }

    @Override
    protected void createContents( final Composite parent )
    {
        final PropertyEditorPart part = part();

        final Composite mainComposite = createMainComposite( parent );
        mainComposite.setLayout( new FillLayout( SWT.HORIZONTAL ) );

        final Composite sourceTableComposite = new Composite( mainComposite, SWT.NONE );
View Full Code Here

   
    protected void createContents( final Composite parent )
    {
        // Initialize
       
        final PropertyEditorPart part = part();
        final Property property = part.property();
       
        this.memberType = property.definition().getType();
       
        final SortedSet<PropertyDef> allMemberProperties = this.memberType.properties();
       
        if( allMemberProperties.size() == 1 )
        {
            final PropertyDef prop = allMemberProperties.first();
           
            if( prop instanceof ValueProperty )
            {
                this.memberProperty = (ValueProperty) prop;
            }
            else
            {
                throw new IllegalStateException();
            }
        }
        else
        {
            throw new IllegalStateException();
        }
       
        this.possibleValuesService = property.service( PossibleValuesService.class );
       
        this.possibleValuesServiceListener = new Listener()
        {
            @Override
            public void handle( final Event event )
            {
              CheckBoxListPropertyEditorPresentation.this.tableViewer.refresh();
            }
        };
       
        this.possibleValuesService.attach( this.possibleValuesServiceListener );

        // Create Controls
       
        final Composite mainComposite = createMainComposite( parent );
        mainComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
       
        final PropertyEditorAssistDecorator decorator = createDecorator( mainComposite );
        decorator.control().setLayoutData( gdvalign( gd(), SWT.TOP ) );
       
        // Setting the whint in the following code is a hacky workaround for the problem
        // tracked by the following JFace bug:
        //
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=215997
        //
       
        final Composite tableComposite = new Composite( mainComposite, SWT.NONE );
        tableComposite.setLayoutData( gdwhint( gdfill(), 1 ) );
       
        final TableColumnLayout tableColumnLayout = new TableColumnLayout();
        tableComposite.setLayout( tableColumnLayout );
       
        this.tableViewer = CheckboxTableViewer.newCheckList( tableComposite, SWT.BORDER | SWT.FULL_SELECTION );
        this.table = this.tableViewer.getTable();
       
        final TableViewerColumn viewerColumn = new TableViewerColumn( this.tableViewer, SWT.NONE );
        final TableColumn column = viewerColumn.getColumn();
        column.setText( this.memberProperty.getLabel( false, CapitalizationType.TITLE_STYLE, false ) );
        tableColumnLayout.setColumnData( column, new ColumnWeightData( 1, 100, true ) );
       
        decorator.addEditorControl( mainComposite );
       
        suppressDashedTableEntryBorder( this.table );
       
        // Bind to Model
       
        final ColumnSortComparator comparator = new ColumnSortComparator()
        {
            @Override
            protected String convertToString( final Object obj )
            {
                return ( (Entry) obj ).value;
            }
        };
       
        final IStructuredContentProvider contentProvider = new IStructuredContentProvider()
        {
            private List<Entry> entries = new ArrayList<Entry>();
           
            public Object[] getElements( final Object input )
            {
                if( this.entries != null )
                {
                    for( Entry entry : this.entries )
                    {
                        entry.dispose();
                    }
                   
                    this.entries = null;
                }
               
                final Map<String,LinkedList<Element>> valueToElements = new HashMap<String,LinkedList<Element>>();
               
                for( final Element element : property() )
                {
                    final String value = readMemberProperty( element );
                    LinkedList<Element> elements = valueToElements.get( value );
                   
                    if( elements == null )
                    {
                        elements = new LinkedList<Element>();
                        valueToElements.put( value, elements );
                    }
                   
                    elements.add( element );
                }
               
                this.entries = new ArrayList<Entry>();
               
                Set<String> possibleValues;
               
                try
                {
                    possibleValues = CheckBoxListPropertyEditorPresentation.this.possibleValuesService.values();
                }
                catch( Exception e )
                {
                    Sapphire.service( LoggingService.class ).log( e );
                    possibleValues = SetFactory.empty();
                }

                for( String value : possibleValues )
                {
                    final Entry entry;
                    final LinkedList<Element> elements = valueToElements.get( value );
                   
                    if( elements == null )
                    {
                        entry = new Entry( value, null );
                    }
                    else
                    {
                        final Element element = elements.remove();
                       
                        if( elements.isEmpty() )
                        {
                            valueToElements.remove( value );
                        }
                       
                        entry = new Entry( value, element );
                    }
                   
                    this.entries.add( entry );
                }
               
                for( Map.Entry<String,LinkedList<Element>> entry : valueToElements.entrySet() )
                {
                    final String value = entry.getKey();
                   
                    for( Element element : entry.getValue() )
                    {
                        this.entries.add( new Entry( value, element ) );
                    }
                }
               
                return this.entries.toArray();
            }
           
            public void dispose()
            {
                for( Entry entry : this.entries )
                {
                    entry.dispose();
                }
               
                this.entries = null;
            }

            public void inputChanged( final Viewer viewer,
                                      final Object oldInput,
                                      final Object newInput )
            {
            }
        };
       
        this.tableViewer.setContentProvider( contentProvider );
       
        final ColumnLabelProvider labelProvider = new ColumnLabelProvider()
        {
            @Override
            public String getText( final Object element )
            {
                return ( (Entry) element ).label();
            }

            @Override
            public Image getImage( final Object element )
            {
                return ( (Entry) element ).image();
            }
           
            @Override
            public Color getForeground( final Object element )
            {
                return ( (Entry) element ).foreground();
            }
        };
       
        viewerColumn.setLabelProvider( labelProvider );
       
        final ICheckStateProvider checkStateProvider = new ICheckStateProvider()
        {
            public boolean isChecked( final Object element )
            {
                return ( (Entry) element ).selected();
            }
           
            public boolean isGrayed( final Object element )
            {
                return false;
            }
        };
       
        this.tableViewer.setCheckStateProvider( checkStateProvider );
       
        if( part.getRenderingHint( PropertyEditorDef.HINT_SHOW_HEADER, true ) == true )
        {
            this.table.setHeaderVisible( true );

            makeTableSortable
            (
                this.tableViewer,
                Collections.<TableColumn,Comparator<Object>>singletonMap( column, comparator ),
                CheckBoxListPropertyEditorPresentation.this.possibleValuesService.ordered() ? null : column
            );
        }
       
        final ListSelectionService selectionService = part.service( ListSelectionService.class );
       
        this.tableViewer.addSelectionChangedListener
        (
            new ISelectionChangedListener()
            {
View Full Code Here

    }
   
    protected Control createContents( final Composite parent,
                                      final boolean suppressBrowseAction )
    {
        final PropertyEditorPart part = part();
        final Value<?> property = (Value<?>) part.property();
       
        final boolean isLongString = property.definition().hasAnnotation( LongString.class );
        final boolean isDeprecated = property.definition().hasAnnotation( Deprecated.class );
        final boolean isReadOnly = ( property.definition().isReadOnly() || part.getRenderingHint( PropertyEditorDef.HINT_READ_ONLY, false ) );
        final boolean isSensitiveData = property.definition().hasAnnotation( SensitiveData.class );
       
        final SapphireActionGroup actions = getActions();
        final SapphireActionHandler jumpActionHandler = actions.getAction( ACTION_JUMP ).getFirstActiveHandler();

        final SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation( getActionPresentationManager() );
        toolBarActionsPresentation.addFilter( createFilterByActionId( ACTION_ASSIST ) );
        toolBarActionsPresentation.addFilter( createFilterByActionId( ACTION_JUMP ) );
       
        actions.addFilter
        (
            new SapphireActionHandlerFilter()
            {
                @Override
                public boolean check( final SapphireActionHandler handler )
                {
                    final String actionId = handler.getAction().getId();
                   
                    if( actionId.equals( ACTION_BROWSE ) && ( isReadOnly || suppressBrowseAction ) )
                    {
                        return false;
                    }
                   
                    return true;
                }
            }
        );
       
        final boolean isActionsToolBarNeeded = toolBarActionsPresentation.hasActions();
        final boolean isBrowseOnly = part.getRenderingHint( PropertyEditorDef.HINT_BROWSE_ONLY, false );
       
        final Composite textFieldParent = createMainComposite
        (
            parent,
            new CreateMainCompositeDelegate( part )
            {
                @Override
                public boolean canScaleVertically()
                {
                    return isLongString;
                }
            }
        );
       
        addControl( textFieldParent );

        int textFieldParentColumns = 1;
        if( isActionsToolBarNeeded ) textFieldParentColumns++;
        if( isDeprecated ) textFieldParentColumns++;
       
        textFieldParent.setLayout( glayout( textFieldParentColumns, 0, 0, 0, 0 ) );
       
        final Composite nestedComposite = new Composite( textFieldParent, SWT.NONE );
        nestedComposite.setLayoutData( isLongString ? gdfill() : gdvalign( gdhfill(), SWT.CENTER ) );
        nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
       
        addControl( nestedComposite );
       
        final PropertyEditorAssistDecorator decorator = createDecorator( nestedComposite );
       
        decorator.control().setLayoutData( gdvalign( gd(), SWT.TOP ) );
        decorator.addEditorControl( nestedComposite );
       
        final int style
            = SWT.BORDER |
              ( isLongString ? SWT.MULTI | SWT.WRAP | SWT.V_SCROLL : SWT.NONE ) |
              ( ( isReadOnly || isBrowseOnly ) ? SWT.READ_ONLY : SWT.NONE ) |
              ( isSensitiveData ? SWT.PASSWORD : SWT.NONE );
       
        this.textField = new Text( nestedComposite, style );
        this.textField.setLayoutData( gdfill() );
        decorator.addEditorControl( this.textField, true );
       
        final Serialization serialization = property.definition().getAnnotation( Serialization.class );

        final TextOverlayPainter.Controller textOverlayPainterController = new TextOverlayPainter.Controller()
        {
            @Override
            public boolean isHyperlinkEnabled()
            {
                return ( jumpActionHandler == null ? false : jumpActionHandler.isEnabled() );
            }

            @Override
            public void handleHyperlinkEvent()
            {
                if( jumpActionHandler != null )
                {
                    jumpActionHandler.execute( TextFieldPropertyEditorPresentation.this );
                }
            }

            @Override
            public String overlay()
            {
                String def = property.disposed() ? null : property.getDefaultText();
               
                if( def != null && isSensitiveData )
                {
                    final StringBuilder buf = new StringBuilder();
                   
                    for( int i = 0, n = def.length(); i < n; i++ )
                    {
                        buf.append( "\u25CF" );
                    }
                   
                    def = buf.toString();
                }
               
                if( def == null && serialization != null )
                {
                    def = serialization.primary();
                }
               
                return def;
            }
        };
           
        TextOverlayPainter.install( this.textField, textOverlayPainterController );
       
        if( isBrowseOnly || isReadOnly )
        {
            final Color bgcolor = new Color( this.textField.getDisplay(), 245, 245, 245 );
            this.textField.setBackground( bgcolor );
           
            this.textField.addDisposeListener
            (
                new DisposeListener()
                {
                    public void widgetDisposed( final DisposeEvent event )
                    {
                        bgcolor.dispose();
                    }
                }
            );
        }
       
        final List<Control> relatedControls = new ArrayList<Control>();
        this.textField.setData( RELATED_CONTROLS, relatedControls );
       
        final Listener actionHandlerListener = new Listener()
        {
            @Override
            public void handle( final Event event )
            {
                if( event instanceof PostExecuteEvent )
                {
                    if( ! TextFieldPropertyEditorPresentation.this.textField.isDisposed() )
                    {
                        TextFieldPropertyEditorPresentation.this.textField.setFocus();
                        TextFieldPropertyEditorPresentation.this.textField.setSelection( 0, TextFieldPropertyEditorPresentation.this.textField.getText().length() );
                    }
                }
            }
        };
       
        for( SapphireAction action : actions.getActions() )
        {
            if( ! action.getId().equals( ACTION_ASSIST ) )
            {
                for( SapphireActionHandler handler : action.getActiveHandlers() )
                {
                    handler.attach( actionHandlerListener );
                }
            }
        }
       
        if( isActionsToolBarNeeded )
        {
            final int alignment = ( isLongString ? SWT.VERTICAL : SWT.HORIZONTAL );
            final ToolBar toolbar = new ToolBar( textFieldParent, SWT.FLAT | alignment );
            toolbar.setLayoutData( gdvfill() );
            toolBarActionsPresentation.setToolBar( toolbar );
            toolBarActionsPresentation.render();
            addControl( toolbar );
            decorator.addEditorControl( toolbar );
            relatedControls.add( toolbar );
        }
       
        final ContentProposalService contentProposalService = property.service( ContentProposalService.class );
       
        if( contentProposalService != null )
        {
            final ContentProposalProvider contentProposalProvider = new ContentProposalProvider( contentProposalService, part );
           
            final ContentProposalAdapter contentProposalAdapter
                = new ContentProposalAdapter( this.textField, new TextContentAdapter(), contentProposalProvider, CONTENT_ASSIST_KEY_STROKE, null );
           
            contentProposalAdapter.setPropagateKeys( true );
            contentProposalAdapter.setLabelProvider( new ContentProposalLabelProvider() );
            contentProposalAdapter.setProposalAcceptanceStyle( ContentProposalAdapter.PROPOSAL_REPLACE );
        }
       
        if( isDeprecated )
        {
            final Control deprecationMarker = createDeprecationMarker( textFieldParent );
            deprecationMarker.setLayoutData( gd() );
        }
       
        this.binding = new TextFieldBinding( this, this.textField );

        this.textField.setData( DATA_BINDING, this.binding );
       
        addControl( this.textField );
       
        // Hookup property editor listeners.
       
        final List<Class<?>> listenerClasses
            = part.getRenderingHint( PropertyEditorDef.HINT_LISTENERS, Collections.<Class<?>>emptyList() );
       
        if( ! listenerClasses.isEmpty() )
        {
            final List<ValuePropertyEditorListener> listeners = new ArrayList<ValuePropertyEditorListener>();
           
View Full Code Here

   
    private PropertyEditorPart findFirstProblem( final List<SectionPart> sections )
    {
        for( SectionPart section : sections )
        {
            final PropertyEditorPart res = findFirstProblem( section );
           
            if( res != null )
            {
                return res;
            }
View Full Code Here

            }
            else if( part instanceof FormPart )
            {
                for( SapphirePart p : ( (FormPart) part ).children().visible() )
                {
                    final PropertyEditorPart result = findFirstProblem( p );
                   
                    if( result != null )
                    {
                        return result;
                    }
View Full Code Here

       
        if( nextProblemNode != null )
        {
            nextProblemNode.select();
           
            final PropertyEditorPart firstProblemPropertyEditor = findFirstProblem( nextProblemNode.getSections() );
           
            if( firstProblemPropertyEditor != null )
            {
                firstProblemPropertyEditor.setFocus();
            }
        }
       
        return null;
    }
View Full Code Here

        Map<String,String> partParams = params;
        PartDef def = definition;
       
        if( definition instanceof PropertyEditorDef )
        {
            part = new PropertyEditorPart();
        }
        else if( definition instanceof TextDef )
        {
            part = new TextPart();
        }
View Full Code Here

public final class ListSelectionServiceCondition extends ServiceCondition
{
    @Override
    public boolean applicable( final ServiceContext context )
    {
        final PropertyEditorPart propertyEditorPart = context.find( PropertyEditorPart.class );

        return ( propertyEditorPart != null && propertyEditorPart.property().definition() instanceof ListProperty );
    }
View Full Code Here

        };
    }
   
    private void addControls( final int count )
    {
        final PropertyEditorPart part = part();
        final ElementList<?> list = list();
       
        // first remove everything
        if (this.addText != null && this.addTextHyperlinkAdapter != null) {
            this.addText.removeHyperlinkListener(this.addTextHyperlinkAdapter);
        }
        for (int i = 0; i < this.textBindings.size(); i++) {
            this.textBindings.get(i).removeListener();
        }
        for (Control child : this.mainComposite.getChildren()) {
            child.dispose();
        }
        this.textBindings.clear();

        this.textComposite = new Composite( this.mainComposite, SWT.NONE );
        this.textComposite.setLayoutData( gdhspan( gdfill(), 2 ) );
        this.textComposite.setLayout( glspacing( glayout( 3, 0, 0 ), 2, 4 ) );
       
        addControl( this.textComposite );

        // add back text controls and add link
        for (int i = 0; i < count; i++) {
            final ProxyResource resource = new ProxyResource();
            final Element proxyElement = this.memberProperty.getModelElementType().instantiate(list, resource);
            resource.init(proxyElement, this.memberProperty);
            final PropertyEditorPart editor = part.getChildPropertyEditor( proxyElement, this.memberProperty );
           
            PropertyEditorAssistDecorator decorator = addDecorator(editor);

            Text text = new Text(this.textComposite, SWT.BORDER);
            text.setLayoutData( gdhindent( gdwhint( gdhfill(), 150 ), 0 ) );
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.ui.forms.PropertyEditorPart

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.