在第 11 课之后已为 MapLocatorHandler.egl 完成的代码

以下代码是完成第 11 课之后 MapLocatorHandler.egl 文件中的文本。
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 = "Zip code:"};

   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;

      // show an initial marker, as necessary to display the map at all
      // (the marker identifies only the zip code)
      localMap.addMarker(new MapMarker
         {address = zipField.text, description = "zipcode:  " + zipField.text});

      // Call the remote Yahoo! service, passing the zip code
      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)

      // Show the marker when the user clicks the link
      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", 
                              "Cannot invoke Yahoo Local Service: " + ex.message, 
                              null);
   end
end

反馈