Package org.eclipse.sapphire.ui

Examples of org.eclipse.sapphire.ui.ListSelectionService$ListSelectionChangedEvent


        {
            final String msg = "DetailsSectionPart did not find " + this.property;
            throw new RuntimeException( msg );
        }
       
        final ListSelectionService listSelectionService = this.listPropertyEditorPart.service( ListSelectionService.class );
       
        final MutableReference<Element> selectedElementRef = new MutableReference<Element>();

        final Listener listSelectionServiceListener = new Listener()
        {
            @Override
            public void handle( final Event event )
            {
                final List<Element> selectedElements = listSelectionService.selection();
                final Element selectedElement = ( selectedElements.isEmpty() ? null : selectedElements.get( 0 ) );
               
                if( selectedElementRef.get() != selectedElement )
                {
                    selectedElementRef.set( selectedElement );
                   
                    final Runnable inputChangeOperation = new Runnable()
                    {
                        public void run()
                        {
                            changePage( selectedElement );
                        }
                    };
                   
                    Display.getDefault().syncExec( inputChangeOperation );
                }
            }
        };
       
        listSelectionService.attach( listSelectionServiceListener );
       
        attach
        (
            new Listener()
            {
                @Override
                public void handle( final Event event )
                {
                    if( event instanceof DisposeEvent )
                    {
                        listSelectionService.detach( listSelectionServiceListener );
                    }
                }
            }
        );
       
View Full Code Here


                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()
            {
                public void selectionChanged( final SelectionChangedEvent event )
                {
                    selectionService.select( getSelectedElements() );
                }
            }
        );
       
        final Listener selectionServiceListener = new FilteredListener<ListSelectionChangedEvent>()
        {
            @Override
            protected void handleTypedEvent( final ListSelectionChangedEvent event )
            {
                setSelectedElements( event.after() );
            }
        };

        selectionService.attach( selectionServiceListener );

        addOnDisposeOperation
        (
            new Runnable()
            {
                public void run()
                {
                    selectionService.detach( selectionServiceListener );
                   
                    if( CheckBoxListPropertyEditorPresentation.this.possibleValuesService != null )
                    {
                      CheckBoxListPropertyEditorPresentation.this.possibleValuesService.detach( CheckBoxListPropertyEditorPresentation.this.possibleValuesServiceListener );
                    }
                }
            }
        );
       
        this.tableViewer.addCheckStateListener
        (
            new ICheckStateListener()
            {
                public void checkStateChanged( final CheckStateChangedEvent event )
                {
                    final Entry entry = (Entry) event.getElement();
                   
                    entry.flip();
                    selectionService.select( getSelectedElements() );
                }
            }
        );
       
        this.table.addMouseListener
        (
            new MouseAdapter()
            {
                public void mouseDoubleClick( final MouseEvent event )
                {
                    Entry entry = null;
                   
                    for( TableItem item : CheckBoxListPropertyEditorPresentation.this.table.getItems() )
                    {
                        if( item.getBounds().contains( event.x, event.y ) )
                        {
                            entry = (Entry) item.getData();
                            break;
                        }
                    }
                   
                    if( entry != null )
                    {
                        entry.flip();
                        selectionService.select( getSelectedElements() );
                    }
                }
            }
        );
       
View Full Code Here

                    handleTableTraverseEvent( event );
                }
            }
        );
       
        final ListSelectionService selectionService = part.service( ListSelectionService.class );
       
        this.selectionProvider.addSelectionChangedListener
        (
            new ISelectionChangedListener()
            {
                public void selectionChanged( SelectionChangedEvent event )
                {
                    selectionService.select( getSelectedElements() );
                }
            }
        );
       
        setSelectedElements( selectionService.selection() );
       
        final org.eclipse.sapphire.Listener selectionServiceListener = new FilteredListener<ListSelectionChangedEvent>()
        {
            @Override
            protected void handleTypedEvent( final ListSelectionChangedEvent event )
            {
                setSelectedElements( event.after() );
            }
        };

        selectionService.attach( selectionServiceListener );

        if( ! isReadOnly )
        {
            if( this.exposeAddAction )
            {
                final SapphireAction addAction = actions.getAction( ACTION_ADD );
                final List<SapphireActionHandler> addActionHandlers = new ArrayList<SapphireActionHandler>();
               
                final org.eclipse.sapphire.Listener addActionHandlerListener = new org.eclipse.sapphire.Listener()
                {
                    @Override
                    public void handle( final org.eclipse.sapphire.Event event )
                    {
                        if( event instanceof PostExecuteEvent )
                        {
                            if( TablePropertyEditorPresentation.this.table.isDisposed() )
                            {
                                return;
                            }
                           
                            final Element newListElement = (Element) ( (PostExecuteEvent) event ).getResult();
       
                            if( newListElement != null )
                            {
                                TablePropertyEditorPresentation.this.refreshOperation.run();
                               
                                final TableRow row = findTableRow( newListElement );
                               
                                TablePropertyEditorPresentation.this.tableViewer.setSelection( new StructuredSelection( row ), true );
                               
                                if( TablePropertyEditorPresentation.this.table.isDisposed() )
                                {
                                    return;
                                }
                               
                                TablePropertyEditorPresentation.this.tableViewer.editElement( row, 0 );
                                TablePropertyEditorPresentation.this.table.notifyListeners( SWT.Selection, null );
                            }
                        }
                    }
                };
               
                final PossibleTypesService possibleTypesService = property.service( PossibleTypesService.class );

                final Runnable refreshAddActionHandlersOp = new Runnable()
                {
                    public void run()
                    {
                        addAction.removeHandlers( addActionHandlers );
                       
                        for( SapphireActionHandler addActionHandler : addActionHandlers )
                        {
                            addActionHandler.dispose();
                        }
                       
                        for( ElementType memberType : possibleTypesService.types() )
                        {
                            final SapphireActionHandler addActionHandler = new AddActionHandler( memberType );
                            addActionHandler.init( addAction, null );
                            addActionHandler.attach( addActionHandlerListener );
                            addActionHandlers.add( addActionHandler );
                            addAction.addHandler( addActionHandler );
                        }
                    }
                };
               
                refreshAddActionHandlersOp.run();
               
                final org.eclipse.sapphire.Listener possibleTypesServiceListener = new org.eclipse.sapphire.Listener()
                {
                    @Override
                    public void handle( final org.eclipse.sapphire.Event event )
                    {
                        refreshAddActionHandlersOp.run();
                    }
                };
               
                possibleTypesService.attach( possibleTypesServiceListener );
               
                addOnDisposeOperation
                (
                    new Runnable()
                    {
                        public void run()
                        {
                            addAction.removeHandlers( addActionHandlers );
                           
                            for( SapphireActionHandler addActionHandler : addActionHandlers )
                            {
                                addActionHandler.dispose();
                            }
                           
                            possibleTypesService.detach( possibleTypesServiceListener );
                        }
                    }
                );
            }
           
            if( this.exposeDeleteAction )
            {
                final SapphireAction deleteAction = actions.getAction( ACTION_DELETE );
                final SapphireActionHandler deleteActionHandler = new DeleteActionHandler();
                deleteActionHandler.init( deleteAction, null );
                deleteAction.addHandler( deleteActionHandler );
               
                addOnDisposeOperation
                (
                    new Runnable()
                    {
                        public void run()
                        {
                            deleteAction.removeHandler( deleteActionHandler );
                        }
                    }
                );
            }

            if( ! property.definition().hasAnnotation( FixedOrderList.class ) )
            {
                final SapphireAction moveUpAction = actions.getAction( ACTION_MOVE_UP );
                final SapphireActionHandler moveUpActionHandler = new MoveUpActionHandler();
                moveUpActionHandler.init( moveUpAction, null );
                moveUpAction.addHandler( moveUpActionHandler );
               
                addOnDisposeOperation
                (
                    new Runnable()
                    {
                        public void run()
                        {
                            moveUpAction.removeHandler( moveUpActionHandler );
                        }
                    }
                );
               
                final SapphireAction moveDownAction = actions.getAction( ACTION_MOVE_DOWN );
                final SapphireActionHandler moveDownActionHandler = new MoveDownActionHandler();
                moveDownActionHandler.init( moveDownAction, null );
                moveDownAction.addHandler( moveDownActionHandler );
               
                addOnDisposeOperation
                (
                    new Runnable()
                    {
                        public void run()
                        {
                            moveDownAction.removeHandler( moveDownActionHandler );
                        }
                    }
                );

                final org.eclipse.sapphire.Listener moveActionHandlerListener = new org.eclipse.sapphire.Listener()
                {
                    @Override
                    public void handle( final org.eclipse.sapphire.Event event )
                    {
                        if( event instanceof PostExecuteEvent )
                        {
                            TablePropertyEditorPresentation.this.refreshOperation.run();
                           
                            // This is a workaround for a weird problem on SWT on Windows. If modifier keys are pressed
                            // when the list is re-ordered (as in when issuing move up or move down command from the
                            // keyboard), the focused row can detached from selected row.
                           
                            final Element element = getSelectedElement();
                            final TableItem[] items = TablePropertyEditorPresentation.this.table.getItems();
                           
                            for( int i = 0; i < items.length; i++ )
                            {
                                if( items[ i ].getData() == element )
                                {
                                    TablePropertyEditorPresentation.this.table.setSelection( i );
                                    break;
                                }
                            }
                        }
                    }
                };
               
                moveUpAction.attach( moveActionHandlerListener );
                moveDownAction.attach( moveActionHandlerListener );
               
                final ElementsTransfer transfer = new ElementsTransfer( element().type().getModelElementClass().getClassLoader() );
                final Transfer[] transfers = new Transfer[] { transfer };
               
                final DragSource dragSource = new DragSource( this.table, DND.DROP_COPY | DND.DROP_MOVE );
                dragSource.setTransfer( transfers );

                final List<Element> dragElements = new ArrayList<Element>();
               
                dragSource.addDragListener
                (
                    new DragSourceListener()
                    {
                        public void dragStart( final DragSourceEvent event )
                        {
                            if( TablePropertyEditorPresentation.this.tableViewer.getComparator() == null )
                            {
                                dragElements.addAll( getSelectedElements() );
                                event.doit = true;
                            }
                            else
                            {
                                event.doit = false;
                            }
                        }
                       
                        public void dragSetData( final DragSourceEvent event )
                        {
                            event.data = dragElements;
                        }
                       
                        public void dragFinished( final DragSourceEvent event )
                        {
                            if( event.detail == DND.DROP_MOVE )
                            {
                                // When drop target is the same editor as drag source, the drop handler takes care of removing
                                // elements from their original location. The following block of code accounts for the case when
                                // dropping into another editor.
                               
                                boolean droppedIntoAnotherEditor = false;
                               
                                for( Element dragElement : dragElements )
                                {
                                    if( ! dragElement.disposed() )
                                    {
                                        droppedIntoAnotherEditor = true;
                                        break;
                                    }
                                }
                               
                                if( droppedIntoAnotherEditor )
                                {
                                    try
                                    {
                                        final Element selectionPostDelete = findSelectionPostDelete( property(), dragElements );
                                       
                                        for( Element dragElement : dragElements )
                                        {
                                            final ElementList<?> dragElementContainer = (ElementList<?>) dragElement.parent();
                                            dragElementContainer.remove( dragElement );
                                        }
                                       
                                        setSelectedElement( selectionPostDelete );
                                    }
                                    catch( Exception e )
                                    {
                                        // Log this exception unless the cause is EditFailedException. These exception
                                        // are the result of the user declining a particular action that is necessary
                                        // before the edit can happen (such as making a file writable).
                                       
                                        final EditFailedException editFailedException = EditFailedException.findAsCause( e );
                                       
                                        if( editFailedException == null )
                                        {
                                            Sapphire.service( LoggingService.class ).log( e );
                                        }
                                    }
                                }
                            }
                           
                            dragElements.clear();
                        }
                    }
                );
               
                final DropTarget target = new DropTarget( this.table, DND.DROP_COPY | DND.DROP_MOVE );
                target.setTransfer( transfers );
               
                target.addDropListener
                (
                    new DropTargetAdapter()
                    {
                        public void dragOver( final DropTargetEvent event )
                        {
                            if( event.item != null )
                            {
                                final TableItem dragOverItem = (TableItem) event.item;

                                final Point pt = dragOverItem.getDisplay().map( null, TablePropertyEditorPresentation.this.table, event.x, event.y );
                                final Rectangle bounds = dragOverItem.getBounds();
                               
                                if( pt.y < bounds.y + bounds.height / 2 )
                                {
                                    event.feedback = DND.FEEDBACK_INSERT_BEFORE;
                                }
                                else
                                {
                                    event.feedback = DND.FEEDBACK_INSERT_AFTER;
                                }
                            }
                           
                            event.feedback |= DND.FEEDBACK_SCROLL;
                        }

                        public void drop( final DropTargetEvent event )
                        {
                            if( event.data == null )
                            {
                                event.detail = DND.DROP_NONE;
                                return;
                            }
                           
                            final List<ElementData> droppedElements = (List<ElementData>) event.data;
                            final Set<ElementType> possibleTypesService = property.service( PossibleTypesService.class ).types();
                           
                            for( final ElementData droppedElement : droppedElements )
                            {
                                if( ! possibleTypesService.contains( droppedElement.type() ) )
                                {
                                    event.detail = DND.DROP_NONE;
                                    return;
                                }
                            }
                           
                            final ElementList<?> list = property();
                           
                            int position;
                           
                            if( event.item == null )
                            {
                                position = list.size();
                            }
                            else
                            {
                                final TableItem dropTargetItem = (TableItem) event.item;
                                final TableRow dropTargetRow = (TableRow) dropTargetItem.getData();
                                final Element dropTargetElement = dropTargetRow.element();
                               
                                final Point pt = TablePropertyEditorPresentation.this.table.getDisplay().map( null, TablePropertyEditorPresentation.this.table, event.x, event.y );
                                final Rectangle bounds = dropTargetItem.getBounds();
                               
                                position = list.indexOf( dropTargetElement );
                               
                                if( pt.y >= bounds.y + bounds.height / 2 )
                                {
                                    position++;
                                }
                            }
                           
                            try
                            {
                                if( event.detail == DND.DROP_MOVE )
                                {
                                    for( Element dragElement : dragElements )
                                    {
                                        final ElementList<?> dragElementContainer = (ElementList<?>) dragElement.parent();
                                       
                                        if( dragElementContainer == list && dragElementContainer.indexOf( dragElement ) < position )
                                        {
                                            position--;
                                        }
                                       
                                        dragElementContainer.remove( dragElement );
                                    }
                                }
           
                                final List<Element> newSelection = new ArrayList<Element>();
                               
                                for( final ElementData droppedElement : droppedElements )
                                {
                                    final Element insertedElement = list.insert( droppedElement.type(), position );
                                    insertedElement.copy( droppedElement );
                                   
                                    newSelection.add( insertedElement );
                                   
                                    position++;
                                }
                               
                                if( TablePropertyEditorPresentation.this.table.isDisposed() )
                                {
                                    return;
                                }
                               
                                TablePropertyEditorPresentation.this.tableViewer.refresh();
                                setSelectedElements( newSelection );
                            }
                            catch( Exception e )
                            {
                                // Log this exception unless the cause is EditFailedException. These exception
                                // are the result of the user declining a particular action that is necessary
                                // before the edit can happen (such as making a file writable).
                               
                                final EditFailedException editFailedException = EditFailedException.findAsCause( e );
                               
                                if( editFailedException == null )
                                {
                                    Sapphire.service( LoggingService.class ).log( e );
                                }
                               
                                event.detail = DND.DROP_NONE;
                            }
                        }
                    }
                );
            }
        }
       
        final boolean toolBarNeeded = toolBarActionsPresentation.hasActions();
       
        mainComposite.setLayout( glayout( ( toolBarNeeded ? 2 : 1 ), 0, 0, 0, 0 ) );
       
        if( toolBarNeeded )
        {
            final ToolBar toolbar = new ToolBar( mainComposite, SWT.FLAT | SWT.VERTICAL );
            toolbar.setLayoutData( gdvfill() );
            toolBarActionsPresentation.setToolBar( toolbar );
            toolBarActionsPresentation.render();
            addControl( toolbar );
            this.decorator.addEditorControl( toolbar );
        }
       
        if( menuActionsPresentation.hasActions() )
        {
            final Menu menu = new Menu( this.table );
            this.table.setMenu( menu );
            menuActionsPresentation.setMenu( menu );
            menuActionsPresentation.render();
        }
       
        final HyperlinkTable hyperlinkTable = new HyperlinkTable( this.table, actions );
       
        hyperlinkTable.setController
        (
            new HyperlinkTable.Controller()
            {
                @Override
                public boolean isHyperlinkEnabled( final TableItem item,
                                                   final int column )
                {
                    final SapphireActionHandler jumpHandler = getJumpHandler( item, column );
                   
                    if( jumpHandler != null )
                    {
                        return jumpHandler.isEnabled();
                    }

                    return false;
                }

                @Override
                public void handleHyperlinkEvent( final TableItem item,
                                                  final int column )
                {
                    final SapphireActionHandler jumpHandler = getJumpHandler( item, column );
                   
                    if( jumpHandler != null )
                    {
                        jumpHandler.execute( TablePropertyEditorPresentation.this );
                    }
                }
               
                private SapphireActionHandler getJumpHandler( final TableItem item,
                                                              final int column )
                {
                    final Element element = ( (TableRow) item.getData() ).element();
                    final ModelPath property = part.getChildProperties().get( column );
                    final PropertyEditorPart propertyEditor = part.getChildPropertyEditor( element, property );
                    final SapphireActionGroup actions = propertyEditor.getActions();
                    return actions.getAction( ACTION_JUMP ).getFirstActiveHandler();
                }
            }
        );
       
        suppressDashedTableEntryBorder( this.table );
       
        addControl( this.table );
       
        addOnDisposeOperation
        (
            new Runnable()
            {
                public void run()
                {
                    selectionService.detach( selectionServiceListener );
                }
            }
        );
       
        return this.table;
View Full Code Here

        public void init( final SapphireAction action,
                          final ActionHandlerDef def )
        {
            super.init( action, def );
           
            final ListSelectionService selectionService = action.getPart().service( ListSelectionService.class );
           
            final Listener selectionListener = new Listener()
            {
                @Override
                public void handle( final Event event )
                {
                    refreshEnablementState();
                }
            };
           
            selectionService.attach( selectionListener );
           
            attach
            (
                new Listener()
                {
                    @Override
                    public void handle( final Event event )
                    {
                        if( event instanceof DisposeEvent )
                        {
                            selectionService.detach( selectionListener );
                        }
                    }
                }
            );
        }
View Full Code Here

TOP

Related Classes of org.eclipse.sapphire.ui.ListSelectionService$ListSelectionChangedEvent

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.