Reality is a perception. Perceptions are not always based on facts, and are strongly influenced by illusions. Inquisitiveness is hence indispensable

Thursday, May 20, 2010

GWT: Illustrating usage of previous components

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:

Popular Posts

Labels

About Me

Well for a start, I dont' want to!. Yes I am reclusive, no I am not secretive; Candid? Yes; Aspergers? No :). My friends call me an enthusiast, my boss calls me purist, I call myself an explorer, to summarise; just an inquisitive child who didnt'learn to take things for granted. For the sake of living, I work as a S/W engineer. If you dont' know what it means, turn back right now.