Announcement Announcement Module
Collapse
No announcement yet.
Providing and listening for changes between views Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Providing and listening for changes between views

    Is there in Spring RCP a way to globalize providing and monitoring for changes between views?

    For example I have one master view (M) and a dependent view (D). I want that D can register itself as a listener of M.

    Is there a Proxy dispatcher service that would keep track of providers and listeners, and notify listeners when providers change?

    In Eclipse RCP this is done like this:

    the component in the master view registers itself as a provider
    PHP Code:
    getSite().setSelectionProviderklijentViewer ); 
    the dependent view registers itself as a listener
    PHP Code:
    IWorkbenchWindow window getSite().getWorkbenchWindow();
     
    window.getSelectionService().addSelectionListenerthis ); 
    the dependent view class must then implement ISelectionListener and it's method:
    PHP Code:
    public void selectionChangedIWorkbenchPart wpISelection incomingSelection ) {
          if ( 
    wp instanceof MasterView ) {
            
    // do this when a selection changes in a component of MasterView
          
    }
          else if ( 
    wp instanceof SomeOtherView ) {
            
    // do this when slection changes in a component of SomeOtherView
          
    }

    the catch is that the D view doesn't register itself directly to M view, but to a proxy dispatcher which keeps track of all.

  • #2
    and also... is there a best practise to write a Spring RCP app, so it can be extended with plugins?
    Plugins, in sense that I create a independent Java project that can hook to views and actions from the master project. In a way that the master project isn't aware of the plugin.
    Last edited by interstellar; Nov 29th, 2008, 10:02 PM.

    Comment


    • #3
      There's no support for a plugin-oriented approach (like Eclipse) yet...

      Comment


      • #4
        thanks.
        how about listening?

        Comment


        • #5
          The easiest way would be to use EventBus.

          regards,

          Peter

          Comment


          • #6
            Peter,

            Thanks. Didn't think of it. Might be a good idea to look into integrating EventBus into Spring Rich Client.

            @interstellar:

            Currently, Spring Rich Client doesn't support EventBus out of the box. However, plugging it into the code can be quite easy (subclassing AbstractView, making it an EventSubsciber for example).

            Comment


            • #7
              plugins

              I'll give it a try. Thanks.

              And about plugins.
              I found this - forum.springframework.org/showthread.php?t=10657

              Did anyone tried it? Does it work?

              Comment


              • #8
                I wouldn't subclass AbstractView to add EventBus support.

                Instead I would use the annotation support from EventBus:

                some (pseudo)code:
                Code:
                public class SomeView extends AbstractView {
                    public SomeView() {
                        AnnotationProcessor.process(this);
                    }
                
                    @EventSubscriber(eventClass=SelectionEvent.class)
                    public void selectionChanged(SelectionEvent event) {
                        // do some stuff
                    }
                }
                @Lieven: about the integration of EventBus: If Views would be first class citizens in the Spring application context (instead of being created by the ViewDescriptor), it would be possible to have an EventSubscriberAnnotationBeanPostProcessor (such as the AutowiredAnnotationBeanPostProcessor) to call the AnnotationProcessor.process method automatically when the view is created. This was one of things I was working on in Spring Desktop.

                regards,

                Peter

                Comment


                • #9
                  Sorry for the OT on plugins, I'll post it to a new thread.

                  That looks pretty elegant.

                  Comment


                  • #10
                    And spring events?

                    Originally posted by pdbruycker View Post
                    The easiest way would be to use EventBus.

                    regards,

                    Peter
                    Why not use ApplicationListener?

                    Comment


                    • #11
                      You're correct, you can also use the ApplicationListener + ApplicationEvent.

                      But in my opinion EventBus is more flexible.

                      Suppose you have two events: SelectionEvent and StatusEvent.

                      Using ApplicationListener:
                      Code:
                      public void SomeClass implements ApplicationListener {
                          public void onApplicationEvent(ApplicationEvent event) {
                              if (event instanceof SelectionEvent) {
                                  SelectionEvent selectionEvent = (SelectionEvent) event;
                                  // do something with the event
                              }
                      
                              if (event instanceof StatusEvent) {
                                  StatusEvent statusEvent = (StatusEvent) event;
                                  // do something with the event
                              }
                          }
                      }
                      Using EventBus:
                      Code:
                      public void SomeClass {
                          public SomeClass() {
                              // this could be handled by the Spring App Context
                              AnnotationProcessor.process(this);
                          }
                      
                          @EventSubscriber(eventClass=StatusEvent.class)
                          public void statusChanged(StatusEvent event) {
                              // do something with the event
                          }
                      
                          @EventSubscriber(eventClass=SelectionEvent.class)
                          public void selectionChanged(SelectionEvent event) {
                              // do something with the event
                          }
                      }
                      So, using EventBus you don't have to cast the event objects, can use any method name you want, and are free to implement your event as you wish (no subclassing, you can in fact use simple POJO's as events).

                      regards,

                      Peter

                      Comment

                      Working...
                      X