events and listeners between classes

Hi:

I created two different classes for two different layouts, which are “called” from the application class.

In one of the layouts
(ie.- layout1)
I have another class for a compound button.

Now, what I want to do is that whenever I click one of the buttons in the compound button class
(ie.- button 1)
, a property of a component in layout2
(ie.- a checkbox status)
changes.

How should I build the events and listeners to achieve this?

please help, I’ve been stuck with this for days!!!

regards, and thank you very much

In the first layout/composite, hold a reference to the second one. In the sond layout/composite, have a “setStatus()” or something similar that sets the property value. Then, in the first layout, have a Button.ClickListener for the button, which uses the stored reference to call the setter.

That’s a rather direct approach where the first layout must know which method to call. You could also use a more generic event-listener pattern for that.

For example, in the Gas Diary example app, the class
FillEditor.java
defines a custom close listener:

238	    FillEditorListener listener = null;
239	   
240	    void close(boolean ok) { // Fire the event
241	        if (listener != null)
242	            listener.close(ok);
243	    }
244	   
245	    public void setListener(FillEditorListener listener) {
246	        this.listener = listener;
247	    }
248	   
249	    public interface FillEditorListener extends Serializable {
250	        public void close(boolean ok);
251	    }

It is then used in the
CarView.java
class:

145            FillEditor editor = new FillEditor((GasDiaryApplication) getApplication(), fillItem, prevayler);
146	        editor.setWidth("100%");
147	        fillEditPanel.addComponent(editor);
148	       
149	        editor.setListener(new FillEditor.FillEditorListener() {
150	            private static final long serialVersionUID = 2957209882098038339L;
151	
152	            public void close(boolean ok) {
153	                if (ok) {
154	                    if (fill == null) {
155	                        // Fill doesn't exist - create new
156	                        try {
157	                            prevayler.execute(new NewFill(user, car, fillItem.getBean()));
158	                            fillContainer.addBean(fillItem.getBean());
159	                        } catch (Exception e) {
160	                            e.printStackTrace();
161	                        }
162	                    } else {
163	                        // Fill exists - update it
164	                        try {
165	                            prevayler.execute(new UpdateFill(user, car, fill, fillItem.getBean()));
166	                        } catch (Exception e) {
167	                            e.printStackTrace();
168	                        }
169	                    }
170	                }
171	                for (int i=0; i<car.getFills().size(); i++)
172	                    System.out.println("Fill: " + car.getFills().get(i).getDate());
173	               
174	                fillEditPanel.setVisible(false);
175	            }
176	        });

Thanks!!!