i am still at the path to get an deeper understanding of design of
"large-scale"-gwt applications. first some way points were set
(https://groups.google.com/forum/#!topic/google-web-toolkit/f20FbM04usU/discussion).
Now i implemented my only use-case obeying to "MVP Part
2"<http://code.google.com/webtoolkit/articles/mvp-architecture-2.html>.
(My use case: an UI Element to choose an administrative unit (federal Land,
county, community). There is an "Service" delivering all administrative
units as a (special linked) list consisting of "AdminUnit"s -- my DTO (id,
name, level, list<children AdminUnit>)) On implementing it some (general)
question arose regarding some "MVP-Part2"-details.
1st: What the "3rd party" is for? The Example introduces "column
definition". My understanding of it is an abstraction of DTO
("Contact(Details)"). So someone could use the view/presenter interfaces to
deliver UI's for different DTO's - is this correct? So if i want to deliver
an UI for an handling a special DTO this abstraction isn't needed, is it?
2nd: Regarding the delegation of user interactions to presenter (e.g.
"onAddButtonClicked(ClickEvent) ... presenter.onAddButtonClicked). But this
delegation isn't required by the viewer interface. But without
firing/delegating events the ContactsView will be useless?! Only the
definition of presenter interface could imply the need of some events. What
about adding the "on.." methods also to viewer's interface? Or is there
another way (a mvp-part2-way) to specify an interface that requires
implementing classes to provide some events -- probably some self made
/special kind of event ("hashandlers" is bad isn't it?)
to make that post even longer i'll add the source code of my current
implementation of the single use case mentioned above. i asked you if i
understood at least something about mvp (part 2). (at the moment i did not
use uibinder(probably later) and "third party" - abstraction(probably
never)). since i am a gwt-noob, every hint tip implementing with gwt is
appreciated. thx in advance. now let the code talk.
Au:"AdministrativeUnit"
the viewer interface:
"
public interface AuSelectorView extends IsWidget, HasHandlers{
interface Presenter extends AdminUnitSelectedEventHandler{
}
void setPresenter(Presenter presenter);
void setFedLands(ArrayList<AdminUnit> fedLands);
void setCounties(ArrayList<AdminUnit> counties);
void setCommunities(ArrayList<AdminUnit> communities);
void clearFedLand();
void clearCounty();
void clearCommunity();
void activateForm();
void fireAuSelected(AdminUnitSelectedEvent ev);
}
"
it's implementation:
"
public class AdminUnitFormView extends DockLayoutPanel implements
AuSelectorView {
private static final String TEXT_FIELD_WIDTH = "4.5cm";
private static final String FORM_HEIGHT = "3cm";
TextBox fedLandTB = new TextBox();
TextBox countyTB = new TextBox();
TextBox communityTB = new TextBox();
AuSuggestOracle fedLandOracle = new AuSuggestOracle();
SuggestBox fedLand = new SuggestBox(fedLandOracle, fedLandTB);
AuSuggestOracle countyOracle = new AuSuggestOracle();
SuggestBox county = new SuggestBox(countyOracle, countyTB);
AuSuggestOracle communityOracle = new AuSuggestOracle();
SuggestBox community = new SuggestBox(communityOracle, communityTB);
Label loading = new Label("Lade Länder, Kreise, Gemeinden...");
private AuSelectorView.Presenter presenter;
public AdminUnitFormView() {
super(Unit.CM);
Grid form = new Grid(3, 2);
form.setBorderWidth(0);
form.setHeight(FORM_HEIGHT);
Label fedLandL = new Label("Bundesland");
Label countyL = new Label("Kreis");
Label communityL = new Label("Gemeinde");
this.addSouth(loading, 1);
fedLandTB.setWidth(TEXT_FIELD_WIDTH);
countyTB.setWidth(TEXT_FIELD_WIDTH);
communityTB.setWidth(TEXT_FIELD_WIDTH);
fedLandTB.setEnabled(false);
countyTB.setEnabled(false);
communityTB.setEnabled(false);
form.setWidget(0, 0, fedLandL);
form.setWidget(0, 1, fedLand);
form.setWidget(1, 0, countyL);
form.setWidget(1, 1, county);
form.setWidget(2, 0, communityL);
form.setWidget(2, 1, community);
this.add(form);
bind();
}
private void bind() {
county.addSelectionHandler(new OnSelection());
fedLand.addSelectionHandler(new OnSelection());
community.addSelectionHandler(new OnSelection());
}
private class OnSelection implements SelectionHandler<Suggestion> {
@Override
public void onSelection(SelectionEvent<Suggestion> event) {
AdminUnit au = ((AuMultiWordSuggestion)
event.getSelectedItem()).getAdminUnit();
fireAuSelected(new AdminUnitSelectedEvent(au));
}
}
@Override
public void activateForm() {
fedLandTB.setEnabled(true);
countyTB.setEnabled(true);
communityTB.setEnabled(true);
loading.setVisible(false);
}
@Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
private ArrayList<AuMultiWordSuggestion>
createSuggestList(ArrayList<AdminUnit> aus) {
ArrayList<AuMultiWordSuggestion> results = new
ArrayList<AuMultiWordSuggestion>();
for (AdminUnit au : aus) {
results.add(new AuMultiWordSuggestion(au));
}
return results;
}
@Override
public void setFedLands(ArrayList<AdminUnit> fedLands) {
fedLandOracle.setNew(createSuggestList(fedLands));
}
@Override
public void setCounties(ArrayList<AdminUnit> counties) {
countyOracle.setNew(createSuggestList(counties));
}
@Override
public void setCommunities(ArrayList<AdminUnit> communities) {
communityOracle.setNew(createSuggestList(communities));
}
@Override
public void clearFedLand() {
fedLandTB.setText("");
}
@Override
public void clearCounty() {
countyTB.setText("");
}
@Override
public void clearCommunity() {
communityTB.setText("");
}
@Override
public void fireAuSelected(AdminUnitSelectedEvent ev) {
presenter.onAdminUnitSelected(ev);
}
}
"
the presenter:
"
public class AdminUnitFormPresenter implements AuSelectorView.Presenter,
AdminUnitsLoadedHandler, IsWidget, HasHandlers {
AdminUnits adminUnits = null;
private final AuSelectorView view;
private AdminUnit selectedAu;
private SimpleEventBus eventBus;
public AdminUnitFormPresenter(AuSelectorView auView, SimpleEventBus
eventBus) {
this.eventBus = eventBus;
view = auView;
view.setPresenter(this);
adminUnits = new AdminUnits(this.eventBus);
eventBus.addHandler(AdminUnitsLoadedEvent.TYPE, this);
}
private void updateCommunities() {
view.clearCommunity();
view.setCommunities(selectedAu.getChildren());
}
private void updateCountiesAndCommunities() {
view.clearCounty();
view.clearCommunity();
ArrayList<AdminUnit> allCounties = selectedAu.getChildren();
view.setCounties(allCounties);
ArrayList<AdminUnit> communities = new ArrayList<AdminUnit>();
for (AdminUnit adminUnit : allCounties) {
communities.addAll(adminUnit.getChildren());
}
view.setCommunities(communities);
}
@Override
public void onAdminUnitsLoaded(AdminUnitsLoadedEvent event) {
view.setFedLands(adminUnits.getFedLands());
view.setCounties(adminUnits.getCounties());
view.setCommunities(adminUnits.getCommunities());
view.activateForm();
}
@Override
public Widget asWidget() {
return view.asWidget();
}
@Override
public void fireEvent(GwtEvent<?> event) {
eventBus.fireEvent(event);
}
@Override
public void onAdminUnitSelected(AdminUnitSelectedEvent event) {
selectedAu = event.getAdminUnit();
if (selectedAu.getLevel() == AULevel.Land) {
updateCountiesAndCommunities();
} else if (selectedAu.getLevel() == AULevel.County) {
updateCommunities();
}
fireEvent(new AdminUnitSelectedEvent(selectedAu));
}
}
"
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.