[nbusers] Lookup Topcomponent

  • From: "ebaumann" < >
  • To:
  • Subject: [nbusers] Lookup Topcomponent
  • Date: Tue, 04 Dec 2012 03:50:49 -0500

The global Lookup is connected to the currently (one) selected TopComponent. 
Maybe that the EventBus (http://eventbus.org/) solves your problem. Via 
annatations you can do that:


Code:

public final class MyContext {
    
    private final Object source;
    private final String text;

    public MyContext(Object source, String text) {
        this.source = source;
        this.text = text;
    }

    public Object getSource() {
        return source;
    }

    public String getText() {
        return text;
    }
}

public final MyTopComponentA extends TopComponent {
    ...
    private void textButtonClicked() {
        EventBus.publish(new MyContext(this, textField.getText());
    }
}

public final MyTopComponentB extends TopComponent {

    public MyTopComponentB() {
        AnnotationProcessor.process(this);
    }

    @EventSubscriber(eventClass=MyContext.class)
    public void handleMyContext(MyContext context) {
        textField.setText(context.getText());
    }
}

public final MyTopComponentC extends TopComponent {

    public MyTopComponentC() {
        AnnotationProcessor.process(this);
    }

    @EventSubscriber(eventClass=MyContext.class)
    public void handleMyContext(MyContext context) {
        textField.setText(context.getText());
    }
}




In short: With the EventBus' publish-method you send messages, the method's 
argument is an object with all context information you need. Every class 
interested into that special context registers it's instances as event 
listener to the EventBus via AnnotationProcessor.process(). On an event 
(EventBus.publish()) the @EventSubscriber(eventClass=...) annotated method of 
the listener will be called by the EventBus.






[nbusers] Lookup Topcomponent

Eric55 11/30/2012

[nbusers] Re: Lookup Topcomponent

Benno Markiewicz 12/01/2012

[nbusers] Lookup Topcomponent

Eric55 12/03/2012

[nbusers] Lookup Topcomponent

ebaumann 12/04/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close