Le code suivant est le texte du fichier MapLocatorHandler.egl à la fin de la leçon 11.
package handlers;
import com.ibm.egl.rui.widgets.Box;
import com.ibm.egl.rui.widgets.GridLayout;
import com.ibm.egl.rui.widgets.GridLayoutData;
import com.ibm.egl.rui.widgets.GridLayoutLib;
import com.ibm.egl.rui.widgets.HyperLink;
import com.ibm.egl.rui.widgets.TextField;
import com.ibm.egl.rui.widgets.TextLabel;
import egl.ui.rui.Event;
import dojo.widgets.DojoButton;
import interfaces.YahooLocalService;
import services.ResultSet;
import utils.dialog.DojoDialogLib;
import utils.map.GoogleMap;
import utils.map.MapMarker;
handler MapLocatorHandler type RUIhandler{initialUI =[ui],
onConstructionFunction = start,
cssFile="css/MortgageUIProject.css", title="MapLocatorHandler" }
ui GridLayout{ columns = 3, rows = 3, cellPadding = 4,
children = [ localMap, listingBox, zipButton,
zipField, zipLabel, introLabel ] };
introLabel TextLabel{
layoutData = new GridLayoutData{row = 1, column = 1, horizontalSpan = 3},
text = "Search for local mortgage businesses"};
zipLabel TextLabel{layoutData = new GridLayoutData{row = 2, column = 1},
text = "Code postal :" };
zipField TextField{layoutData = new GridLayoutData{row = 2, column = 2},
width = "100", onKeyDown ::= checkForEnter};
zipButton DojoButton{layoutData = new GridLayoutData{row = 2, column = 3},
text = "Search", onClick ::= buttonClicked };
listingBox Box{ layoutData = new GridLayoutData{ row = 3, column = 1,
verticalAlignment = GridLayoutLib.VALIGN_TOP, horizontalSpan = 2},
padding = 8, columns = 1, width = "150"};
localMap GoogleMap{layoutData = new GridLayoutData{row = 3, column = 3},
width = 400, height = 400 };
lookupService YahooLocalService{@restbinding};
function start()
end
function checkForEnter(event Event in)
if(event.ch == 13)
search();
end
end
function buttonClicked(event Event in)
search();
end
function search()
localMap.zoom = 13;
// affichage d'un marquer initial, indispensable pour afficher la carte
// (le marqueur identifie uniquement le code postal)
localMap.addMarker(new MapMarker
{address = zipField.text, description = "zipcode: " + zipField.text});
// Appel du service distant Yahoo!, transmission du code postal
call lookupService.getSearchResults("YahooDemo", zipField.text)
returning to showResults onException displayError;
end
function showResults(retResult ResultSet in)
linkListing HyperLink[0];
for(i int from 1 to retResult.result.getSize() by 1)
newLink HyperLink{padding = 4, text = retResult.result[i].title, href = "#"};
newLink.setAttribute("address",
retResult.result[i].Address + ", " + retResult.result[i].city +
", " + retResult.result[i].state);
newLink.setAttribute("title", retResult.result[i].Title);
newLink.onClick ::= mapAddress;
linkListing.appendElement(newLink);
end
listingBox.setChildren(linkListing);
end
function mapAddress(e Event in)
// Affichage du marqueur lorsque l'utilisateur clique sur le lien
businessAddress string = e.widget.getAttribute("address") as string;
businessName string = e.widget.getAttribute("title") as string;
localMap.addMarker(new MapMarker{address = businessAddress,
description = businessName} );
end
function displayError(ex AnyException in)
DojoDialogLib.showError("Yahoo Service",
"Impossible d'appeler Yahoo Local Service : " + ex.message,
null);
end
end