public class EntryPoint {
public void loadUi() {
mainLayout = uiBinder.createAndBindUi(this);
initWidget(mainLayout);
//mainContent is the panel below the navigation menu, where the controls are displayed
//There's no dependency injection, just some basic declaration of dependencies
//appMessages is a widget to display any errors related to server calls.
final ItemsDropdown itemSelect = new ItemsDropdown(labels.myItems(), appMessages, mainContent);
}
}
// from the dropdown control, we can select a summary view or select a specific item
public class ItemsDropdown {
//The i18n classes are always instantiated with GWT.create(),
//same with the services. There is no caching.
private final I18nLabels labels = GWT.create(I18nLabels.class);
private final ItemServiceAsync itemService = GWT.create(ItemService.class);
private final ApplicationMessages appMessages;
private final Panel contentPanel;
//Constructor and Table code has been removed for clarity; this is
//where we build out the table of the most recently used items;
//clicking on an item calls 'loadSpecificItem', clicking on the top
//'Items' label causes all the user's items to be loaded with
//'MyItems'
protected void loadSpecificItem(final ListItem lItem) {
final Item value = lItem.getValue();
//Most controls have not been designed with instance reusability in mind, it's safer to
//instantiate a new one.
//Clear the panel and draw the control
final ItemOverview itemOverview = new ItemOverview(appMessages);
contentPanel.clear();
contentPanel.add(ItemOveriew);
itemOverview.displayDetail(value);
}
protected void loadAllItems() {
//MyItems handles both displaying a table with all items and the detail of a single one.
//This is a Dropdown, purely UI, therefore it would be messier to do the table vs single work here.
final MyItems myItems = new MyItems(appMessages);
contentPanel.clear();
contentPanel.add(myItems);
}
}
// Displays the details of a single item.
public class ItemOverview extends Composite implements DetailDisplay<Item> {
@Override
public void displayDetail(final Item item) {
// the detail display consists of a detail, notes, a summary of other items by the same user and
final ItemDetail itemDetail = new ItemDetail(appMessages);
final NotesManager notes = new NotesManager(appMessages);
final OtherItemsByAuthor otherItems = new OtherItemsByAuthor(/*DetailDisplay<Item>*/this, appMessages);
final ItemProfile itemProfile = new ItemProfile(itemDetail, notes, otherItems, appMessages);
mainContent.clear();
mainContent.add(itemProfile);
}
}