Let the code do the talking.
Scenario: Using a listener
RenderGrid is a class responsible for drawing tables when some event strikes
public class RenderGrid { private MessageSender sender = new MessageSender(); @SuppressWarnings("unused") private MessageListener<RenderGrid> listener = new MessageListener<RenderGrid>(this){ @SuppressWarnings("unchecked") @Override public void messageRecieved(MessageEvent event) { if(event.getEventType().equals(IEventConstants.TABLE_MODEL_FETCH_EVENT)){ /* some super foo bar */ sender.fireEvent(new MessageEvent(IEventConstants.UNMASK_APP_EVENT)); } else if(event.getEventType().equals(IEventConstants.MULTI_TABLE_FETCH_EVENT)){ MultiViewModel multiViewModel = (MultiViewModel) event.getNewValue(); tableHelper.renderGrid(multiViewModel); } else if(event.getEventType().equals(IEventConstants.CATEGORY_FETCH_EVENT)){ /* more foo bar */ } } }; private TabPanel tabPanel = null; private TableHelper tableHelper = null; RenderGrid(TabPanel tabPanel){ this.tabPanel = tabPanel; this.tabPanel.setResizeTabs(false); this.tabPanel.setAnimScroll(true); this.tabPanel.setTabScroll(true); this.tabPanel.setCloseContextMenu(true); tableHelper = new TableHelper(tabPanel); }
}
|
Scenario: Using a sender
SubmitButtonListener listens to form button, and then creates a transfer-object from the form contents and passes its as an event on to the message bus
@SuppressWarnings("unchecked") public class SubmitButtonListener extends SelectionListener { private FormPanel formPanel = null; private MessageSender sender = new MessageSender(); public SubmitButtonListener(FormPanel formPanel) { String formHeader = formPanel.getHeading(); if(formHeader == null || formHeader.trim().isEmpty()){ throw new RuntimeException("Form needs to have a header, contract violation in "+this); } this.formPanel = formPanel; } @Override public void componentSelected(ComponentEvent ce) { String formHeader = formPanel.getHeading(); FormBean bean = FormBeanFactory.createFormBean(formPanel); sender.fireEvent(new MessageEvent(formHeader,null,bean)); }
}
|
No comments:
Post a Comment