Web Technology and                   PracticeSME Network is a company that manages the profiles of small and medium sized ...
TABLE OF CONTENTSDesign .....................................................................................................
DESIGNIn the design section the functional and non-functional requirements of the system will be established. UMLdiagrams ...
0..*The class diagram shows that a Card object stores information about an individual Card, which are all stored inthe Car...
S E Q U E N C E D I A GR A MThis sequence diagram shows three main paths through the system. One is when the system is run...
Although there are many additional plugins available for Eclipse and the GWT, it was not necessary to implementany for thi...
WORKS CITEDACM. (2005, January/February). A Tale of Two Tutorials: A Cognitive Approach to Interactive System Design andIn...
APPENDIX AThis program requires Eclipse4 (minimum requirement is Europa version 3.3) and GWT with Cypal Studio to run.A GW...
Select Window->Preferences->Cypal Studio and set the field GWT home to the directory where the GWT wasinstalled.   Carrie ...
To import the project into Eclipse, right click on the project explorer pane and choose Import -> Import -> ExistingProjec...
Select the “archive file” check box and press browse. Select the EContact.zip file from the CD provided (it isrecommended ...
Once the file has finished importing, the run configuration needs to be set up. First, choose Run -> RunConfigurations. Ch...
To run the program, select the com.contact.EContact option from the Run menu. To maximise the user experience,maximise the...
APPENDIX BOnce the system has been set up as shown in Appendix A, the user will be shown the following screen.If the user ...
Once the user starts typing into the text box, suggestions will be made for them which they can choose.After pressing the ...
They are given the option to narrow their selection. In the example below the search has been narrowed bylocation. Thus, t...
The name of the company is a link to view more of the information stored about that company. Further workcould be done to ...
The other main area of the system is the Add A Profile section. Once the user clicks on the navigation link, theywill be s...
Carrie Hall 7179881   - 18 -
After all of the data has been correctly entered, the user will be displayed a success message and the Card will beavailab...
If the user tried to enter the same business card as one that has already entered they will be shown a message asshown bel...
APPENDIX CPrint-out of source code (the code you wrote, not the ones fully generated by the system)EC O N T A C T . GW T ....
#navigation                      {text-align:center;height:30px;}#navigation p             {margin: 0px 10px 8px 10px;disp...
C O N T A C T S ER VI C E I M PL . J AV AThis is the main server side file which reads and writes the XML documentpackage ...
* @return Document (stored as variable dom        * @throws Exception        */      private Document parseXMLFile(String ...
{                                   try {                                           // get address details                ...
}                    } else if (name.equals("Competence")) // competence node                    {                        ...
errors++;                                      } catch (NumberFormatException n) {                                        ...
String filename = cardIn.getcompanyName() + "_" + cardIn.getcounty()                           + ".xml";             try  ...
C O N T A C T S ER VI C E . J A VApackage com.contact.client;import com.google.gwt.user.client.rpc.RemoteService;public in...
EC O N T A C T . J AV AThis is the main class which shows all of the widgets displayed to the user.package com.contact.cli...
String searchString;       //Set to true if errors are found in Add a Card       boolean errors = false;       /*Variables...
}           };          // execute the service          svc.getCards(callback);      }       /*         * shows the index ...
county = new SuggestBox(createCounties());                         }           }              else if (addError.length()>0...
addError+="<p class=error>* Please enter an county</p>";                                county.setStylePrimaryName("incorr...
contactTel.setStyleName("textField");                    }                    if (contactTelTemp.trim()!="")              ...
addButton.setEnabled(true);                             add();                         }                     }            ...
public void onMouseOver(MouseOverEvent event) {                             link1.setStyleName("inline handCursor mouseHov...
final Button button = new Button("Go");               button.setSize("40", "40");               button.addStyleName("inlin...
clickHere.addClickHandler(new ClickHandler()                   {                            public void onClick(ClickEvent...
{                                      public void onClick(ClickEvent event) {                                      showRe...
xmlDownloadLink.setStyleName("gwt-Button handCursormouseHover");                      }            });               xmlDo...
{                                         if (searchString.equals("all"))                                         {       ...
panel.add(clickHere);                         }                         panel.add(new HTML("</ul>"));             }       ...
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
E-contact report
Upcoming SlideShare
Loading in...5
×

E-contact report

266

Published on

University project using the Google Web Toolkit to develop a web app for people to store their professional contacts.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
266
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "E-contact report"

  1. 1. Web Technology and PracticeSME Network is a company that manages the profiles of small and medium sized enterprises (SMEs). It aims tofacilitate the formation of virtual enterprises that consist of complementary business partners to meet theemerging customer demands. This report shows the design and implementation of a Web application that allowsthe SME’s to add their profiles into the system, and to find business partners by searching through the profilesbased on their core competence.
  2. 2. TABLE OF CONTENTSDesign ........................................................................................................................................................................................................... - 2 - Use Case Diagram ................................................................................................................................................................................ - 2 - Class Diagram ....................................................................................................................................................................................... - 2 - Package Diagram ................................................................................................................................................................................. - 3 - Sequence Diagram............................................................................................................................................................................... - 4 -Implementation......................................................................................................................................................................................... - 4 - Why use GWT and Eclipse? ......................................................................................................................................................... - 4 - Client and Server Implementation ........................................................................................................................................... - 5 - User Interface .................................................................................................................................................................................. - 5 - Use of XML ........................................................................................................................................................................................ - 5 -Works Cited ................................................................................................................................................................................................ - 6 -Appendix A .................................................................................................................................................................................................. - 7 - Installation Instructions............................................................................................................................................................... - 7 -Appendix B ................................................................................................................................................................................................ - 13 -Appendix C ................................................................................................................................................................................................ - 21 - EContact.gwt.xml ............................................................................................................................................................................... - 21 - Contact.css ........................................................................................................................................................................................... - 21 - EContact.html...................................................................................................................................................................................... - 22 - ContactServiceImpl.java .................................................................................................................................................................. - 23 - ContactService.java ........................................................................................................................................................................... - 29 - ContactServiceAsync.java ............................................................................................................................................................... - 29 - EContact.java....................................................................................................................................................................................... - 30 - CardSet.java ......................................................................................................................................................................................... - 46 - Card.java ............................................................................................................................................................................................... - 50 - cards.xml .............................................................................................................................................................................................. - 53 - Cuckoo Design_Greater manchester.xml ................................................................................................................................... - 54 - Cards.xsd .............................................................................................................................................................................................. - 55 -Appendix D................................................................................................................................................................................................ - 56 - Carrie Hall 7179881 -1-
  3. 3. DESIGNIn the design section the functional and non-functional requirements of the system will be established. UMLdiagrams will be used to give a better understanding of how the system will be built.U S E C A S E D I A GR A MUse case diagrams “define the interaction between actors and the system”, and “encapsulate a set of scenarios” 1(Sommerville, 2007). This diagram highlights the main requirements of the system which aid in the design. It willalso be used to verify that the final system fulfils all requirements.C L AS S D I A GR A MClass diagrams are widely used in software development and “describe the types of objects in the system and thevarious kinds of static relationships that exist among them” (Fowler, 2004). The following class diagram showsthat the system has 6 classes. Relationships have been drawn on the diagram where necessary to represent themultiplicity of that object. These multiplicities are: A Card must can belong to 0 or more CardSets and a CardSetcan have 0 or more Cards. A CardSet can only belong in one EContact object however, and an EContact object musthave at least one CardSet.Key: Class NameAttributesMethods1 Scenario: a sequence of steps describing an interaction between a user and a system (Fowler, 2004) Carrie Hall 7179881 -2-
  4. 4. 0..*The class diagram shows that a Card object stores information about an individual Card, which are all stored inthe CardSet. The main class is the EContact class which contains all of the graphical widgets. When the programis loaded up the client makes a request to the server asynchronously using the interface classes ContactServiceand ContactServiceAsync, which allow the user to utilize the methods of the ContactServiceImpl class. Whenloaded, this class runs the getCards() method which in turn reads in an XML file containing all of the businesscards and turning them into Card objects by using the appropriate methods. Validation is undertaken to ensurethat all of the correct details are entered for every card and only then will they be displayed to the client. This isdone by storing the number of errors. To save an XML file, the client sends a request to the server with the Cardthat they want to save and the server processes the file and stores it.P A C K A G E D I A GR A MThis package diagram shows the client and server implementations and the position of the classes within eachpackage. It clearly shows a separation of concerns between the client and server. Carrie Hall 7179881 -3-
  5. 5. S E Q U E N C E D I A GR A MThis sequence diagram shows three main paths through the system. One is when the system is run; two is the userinputting a new card, three is the user making a search. The diagram also shows how the classes interact witheach other during run-time and at which point messages are passed. IMPLEMENTATIONThis system was developed in Eclipse v3.4 using the Google Web Toolkit (GWT) and Cypal Studio. Cypal Studio isused to implement GWT features in Eclipse, such as adding new GWT modules.Why use GWT and Eclipse?Developers can spend 90% of their time working around browser quirks (Google). Therefore the GWT provides auseful solution whereby a programmer can write the code for a web application using the Java programminglanguage and the GWT compiles it into optimized JavaScript and XTHML code which works across all browsers.Using the GWT with Eclipse allows the ability to “debug and step through Java code line by line” (Google) whichmakes the testing phase more intuitive. Users of the GWT have remarked that the compiled code makes thebrowser run faster (generally due to the files being much smaller) than traditional applications and websitesmade using JavaScript (Lombardi Blueprint, 2007). Google explain this capability in the following quote: “Unlike JavaScript minifiers 2that work only at a textual level, the GWT compiler performs comprehensive static analysis and optimizations across your entire GWT codebase, often producing JavaScript that loads and executes faster than equivalent handwritten JavaScript.”2 Minification: The process of removing all unnecessary characters from source code, without changing itsfunctionality in computer programming languages and especially JavaScript (Wikipedia). Carrie Hall 7179881 -4-
  6. 6. Although there are many additional plugins available for Eclipse and the GWT, it was not necessary to implementany for this project. The aim of the project was to create a highly intuitive, lightweight application for a user to addand search business cards. After extensively searching, it was the authors decision that this would best becompleted using the standard GWT widgets3 available.Client and Server ImplementationAs shown in the UML diagrams, there is asynchronous connections to the server made by client on severaloccasions. One such occasion is on the initial load of the system. The CardSet of Cards needs to be read in from anXML file as previously mentioned, and this is done server side to reduce the load on the client machine. Inaddition, writing the XML files is done server-side. This is to overcome possible security risks of writing files to aclient machine. Furthermore, if the system were used by many client machines it would then be possible to re-usethe files by enabling multiple clients to download the same file. This system interacts with a server across the network by making a remote procedure call (RPC). GWT RPC enables the client and server to easily pass Java objects back and forth over HTTP. RPCs enables user interface logic to be ran on the client which results in “greatly improved performance, reduced bandwidth, reduced web server load, and a pleasantly fluid user experience” (Google). To invoke a service needs additional classes which have been implemented in EContact. Some of these classes are generated automatically. The diagram in Figure 1, taken from the Google website, shows the structure of an RPC call.User InterfaceFigure 1To make the system user-friendly, a clean simple approach was taken. Screenshots are available in Appendix B. Asthe project used a Google engine it was deemed appropriate to style the application similar to that found in manyof Google’s websites. Neilson proposed a list of heuristics (Heim, 2008) which should be adhered to whendesigning an effective user interface (listed in Appendix D). It can be argued that adhering to Google’s style in thisproject has achieved the “Consistency and standards”, “Recognition rather than recall” and “Aesthetic andminimalist design” heuristics.An interesting feature used in the EContact project is the GWT SuggestBox widget. Given a list of items, thisprovides an enhanced drop down search for the user when they type in the search box for a particularcompetence. For example, if the user types ‘Java’, any Card object with ‘Java’ included in the core competence willbe displayed. This will also include such items as ‘Java Programming’ and ‘C++ and Java’ (i.e. those which includethe required phrase). This is also used in the counties list when the user adds a business card.In addition, extra functionality has been added to allow the user to ‘narrow’ their selection, e.g find companies in acertain location or of a certain size which have the required competence. This adds to the rich user experience andwould be a useful feature should this application become public.Use of XMLXML is used in this project to store a list of all of the business cards so that they can be used in other systems. Thedesign of the XML was intended to be easy to read which is why a lot of the information is found in XML elementsrather than attributes. However, attributes were used to describe all of the additional information for a businesscontact (Email and Telephone number) to decrease the length of the file but not overly complicate the file for auser. An additional feature of the system was implemented, which was the ability to download individual XMLfiles for a particular contact. These files could be utilized in services such as online address books or applicationson a mobile device. Sample XML files are provided in Appendix C.3 Widget: An element of a window-based user interface, or WIMP, such as a button, scrollbar or text editing area(Astronomical Information Processing System). Carrie Hall 7179881 -5-
  7. 7. WORKS CITEDACM. (2005, January/February). A Tale of Two Tutorials: A Cognitive Approach to Interactive System Design andInteraction Design Meets Agility. Interactions Magazine , pp. 49-51.Astronomical Information Processing System. (n.d.). Glossary. Retrieved May 8, 2009, from AstronomicalInformation Processing System: http://www.astron.nl/aips++/docs/glossary/w.htmlBambury, I. (2007). GWT Widgets. Retrieved May 8, 2009, from Roughian Examples:http://examples.roughian.com/index.htmFowler, M. (2004). UML Distilled. Addison-Wesley.Google. (n.d.). Google Web Toolkit. Retrieved May 8, 2009, from Google Code: http://code.google.com/webtoolkit/Hanson, R. (2006, June 1). Trivial GWT Example. Retrieved May 8, 2009, from Robert Hansons (mostly) tech log.:http://roberthanson.blogspot.com/2006/06/trivial-gwt-example.htmlHeim, S. (2008). The Resonant Interface. Boston: Pearson Education.Lombardi Blueprint. (2007, October 16). Google Web Toolkit Blog. Retrieved May 8, 2009, from LombardiBlueprint: http://googlewebtoolkit.blogspot.com/2007/10/lombardi-blueprint-built-with-gwt.htmlSommerville, I. (2007). Software Engineering. Essex: Pearson Education Limited.Stevens, R. (2008). Task Analysis. CS2341 Lecture Notes . Manchester: University Of Manchester.Sun Microsystems. (2004, January 8). Class DocumentBuilderFactory. Retrieved April 01, 2009, fromhttp://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilderFactory.htmlTerry, H. (2001, April 30). Glossary of Terms. Retrieved April 1, 2009, from PC AI Online:http://www.pcai.com/web/glossary/pcai_j_l_glossary.htmlUK Counties List. (n.d.). Retrieved May 08, 2009, from Acorndomains Forum:http://www.acorndomains.co.uk/general-board/32622-uk-counties-list.htmlWikipedia. (n.d.). List of UK Counties. Retrieved May 08, 2009, from Wikipedia:http://en.wikipedia.org/wiki/United_KingdomWikipedia. (n.d.). Minify. Retrieved May 8, 2009, from Wikipedia: http://en.wikipedia.org/wiki/Minify Carrie Hall 7179881 -6-
  8. 8. APPENDIX AThis program requires Eclipse4 (minimum requirement is Europa version 3.3) and GWT with Cypal Studio to run.A GWT plugin for Eclipse is available which can install the GWT directly 5 , but the recommended way is todownload the GWT and extract it to a folder on the hard disk. There is no installation file to run GWT, all that isneeded is to download the Cypal Studio plugin 6 and unzip it into your eclipse “plugins” folder.On the CD you will find the files to install GWT and Cypal Studio, as well as the EContact project.Installation InstructionsUnzip the Cypal Studio plugin direct into your eclipse “plugins” folder (there are 3 files).Once Eclipse has been set up the project needs to be imported. Run Eclipse and choose a workspace for the projectto go in.4 Available at http://www.eclipse.org/downloads/5 Installation instructions are available at http://code.google.com/eclipse/docs/install-eclipse-3.4.html6 Available at http://code.google.com/p/cypal-studio/downloads/list Carrie Hall 7179881 -7-
  9. 9. Select Window->Preferences->Cypal Studio and set the field GWT home to the directory where the GWT wasinstalled. Carrie Hall 7179881 -8-
  10. 10. To import the project into Eclipse, right click on the project explorer pane and choose Import -> Import -> ExistingProject into Workspace Carrie Hall 7179881 -9-
  11. 11. Select the “archive file” check box and press browse. Select the EContact.zip file from the CD provided (it isrecommended to first copy the file from the CD to your hard drive) and press Select. Carrie Hall 7179881 - 10 -
  12. 12. Once the file has finished importing, the run configuration needs to be set up. First, choose Run -> RunConfigurations. Choose GWT Hosted Mode Application and select the EContact project and thecom.contact.EContact module. Carrie Hall 7179881 - 11 -
  13. 13. To run the program, select the com.contact.EContact option from the Run menu. To maximise the user experience,maximise the browser window. Carrie Hall 7179881 - 12 -
  14. 14. APPENDIX BOnce the system has been set up as shown in Appendix A, the user will be shown the following screen.If the user wished to search for a core competence, they would type that competence into the search box. If the‘Go’ button was pressed with no information, then the system would display the following screen to the userinforming them that they need to enter a search, or it gives them the option to view all cards. Carrie Hall 7179881 - 13 -
  15. 15. Once the user starts typing into the text box, suggestions will be made for them which they can choose.After pressing the ‘Go’ button the results are displayed to the user. These results are ordered so that allcompetences that exactly match are shown first, and all those that partially match are shown after. In thefollowing example there is one exact match and one partial match. The crucial information only is shown to theuser at this stage, which is the name of the company and the location and size. Carrie Hall 7179881 - 14 -
  16. 16. They are given the option to narrow their selection. In the example below the search has been narrowed bylocation. Thus, the system now only shows the Cards which match the criteria which is Java competences inMerseyside. The size of the company is either small or medium. This is done by checking the value that the usergave when asked the amount of people in their company. This was done so that in the future extra options (suchas large or multi-national) could be used. The definition of how many people make a small company could changebut very little of the code would need to be changed. This is a fundamental principle in Software Engineering. Carrie Hall 7179881 - 15 -
  17. 17. The name of the company is a link to view more of the information stored about that company. Further workcould be done to this page to include the Google Maps API showing the company location and image uploadswhich would allow the company to upload their logo. In addition, a summary of the company could also be given. Carrie Hall 7179881 - 16 -
  18. 18. The other main area of the system is the Add A Profile section. Once the user clicks on the navigation link, theywill be shown the following screen. As previously mentioned, it is important that all data is validated before goinginto the XML document, thus greatly reducing the risk that there will be problem loading the information again.The following form checks that all fields are not null, and that the number of staff and the telephone number areonly numbers. Examples are shown of the validation. Carrie Hall 7179881 - 17 -
  19. 19. Carrie Hall 7179881 - 18 -
  20. 20. After all of the data has been correctly entered, the user will be displayed a success message and the Card will beavailable to view. Carrie Hall 7179881 - 19 -
  21. 21. If the user tried to enter the same business card as one that has already entered they will be shown a message asshown below. A Card is deemed to be already existing if the combination of company name, town and county havealready been entered. In the example below the user has tried to enter Hislop Flowers after it has beensuccessfully added. The final area of the system is the Help section which is shown below. Carrie Hall 7179881 - 20 -
  22. 22. APPENDIX CPrint-out of source code (the code you wrote, not the ones fully generated by the system)EC O N T A C T . GW T . X MLThis XML file is used to enable Eclipse to use GWT libraries. It also tells the browser which Java file to load.<?xml version="1.0" encoding="UTF-8" standalone="no" ?><module> <inherits name="com.google.gwt.user.User" /> <inherits name="com.google.gwt.user.theme.standard.Standard" /> <entry-point class="com.contact.client.EContact" />CONTACT.CSS <servlet path="/EContact" class="com.contact.server.ContactServiceImpl" /></module>This is the stylesheet for the XHTML used in the browser.body {font-family:"Georgia"; font-size:11px;}h3 {font-size:1.5em;}h5 {color:#1155b4;font-size:1.1em;padding:0;margin:0; text-decoration:underline;}h4 {padding:0;margin:0;font-size:16px;color:#ccc;}h2 {padding:10px 0 5px 0;margin:0;font-size:15px;}h1 {padding:0;margin:0;font-size:42px;}#search {float:right;height:80px; text-align:right;border-bottom:1px solid #ccc;}gwt-PushButton {margin:0 0 0 0 !important;height:40px;width:40px; padding:7px !important;}span.search {font-size:14px;}ul {display:inline;}li {display:inline;text-decoration:none;bullet-type:none;}.html-face {margin:0 !important;padding:8px;}.livesearch {font-style:bold;color:#0048FF;}.location {color:#488000;font-size:smaller;}.narrow {width:750px;background-color:#c7d8a9 !important; border-top:1px solid #a4b388; border-bottom:1px solid #a4b388;height:5px; margin:5px 0 5px 0;}.links {text-decoration:none; text-decoration:underline;color:#455d18;}.search {float:center;height:40px;padding:7px !important;}.largefield {font-size:1.5em; color:#4a4a4a !important;width:300px; border: 1px solid #ccc;}.incorrectField {font-size:15px;height:35px;padding:8px !important; width:300px;border: 1px solid #ff0000;}.textField {font-size:15px;height:35px;padding:8px !important; width:300px;border: 1px solid #ccc;}.gwt-SuggestBox {font-size:15px;height:35px;padding:8px !important; width:300px;border: 1px solid #ccc;}.gwt-TextBox {font-size:15px;height:35px;padding:8px !important; width:300px;border: 1px solid #ccc;}p.error {margin:2px 0 0 5px;color:#ff0000;}#container {width:800px;text-align:left;}#header {text-align:center;padding:20px 0px 10px 0px;}gwt-HTML {margin-left: 20px !important;}#search {vertical-align:middle;padding-top:20px; text-align:center;} Carrie Hall 7179881 - 21 -#search div {vertical-align:middle;}
  23. 23. #navigation {text-align:center;height:30px;}#navigation p {margin: 0px 10px 8px 10px;display:inline;}#main {float:left;padding:20px 0 20px 20px;width:800px; min-height:300px;}#header, #footer,#search, #navigation {width:800px;}#footer {float:left;background-color:#ccc;text-align:center; font-size:12px;color:#0c0c0c;margin-bottom:10px;}#footer p {margin:15px 0 15px 0;}.searchText {display:inline;margin: 0 10px 0 0;padding: 0 0 12px 0;}.inline {display:inline; padding:0 0 0 10px;}.normalCursor {cursor: default;}.handCursor {cursor: pointer;}.mouseHover {color:#2e371d;}.narrowedItem {color:#b4571f;}.removeitem {color:#864117;text-decoration:line-through;}.searchButton {background:#85c441 !important;border:0 !important; padding-top:3px !important;font-weight:bold !important; color:fff !important;vertical-align:top;}.searchButtonHover {background:#7bb43d !important;}.gwt-TreeEC O N T A C T . H T ML.gwt-TreeItem-selected {background: none !important;color:#ff0000; text-style:underline;}This is the HTML document which the GWT code is written to. The navigation links are written to the navigationdiv, the search items to the search div and the content to the main div. The main div gets written to by multiplemethods e.g. when the Home link is pressed it outputs some information and when the Add A Profile button is linkit displays the form. It would have been possible to have different ‘div’ containers for each but this approachminimises the amount of HTML written at any one time thus increasing the speed.<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link type="text/css" rel="stylesheet" href="contact.css"> <title>E-Contact</title> <script type="text/javascript" language="javascript" src="com.contact.EContact.nocache.js"></script></head><body> <div align="center"> <div id="container"> <div id=header> <img src="logo.gif" alt="logo"> </div> <div id=navigation> </div> <div id=search> </div> <div id=main> </div> <div id=footer> <p>Created by Carrie Hall &copy; 2009</p> </div> <iframe src="javascript:" id="__gwt_historyFrame" style="position: absolute; width: 0; height: 0; border:0"></iframe> </div> </div></body></html> Carrie Hall 7179881 - 22 -
  24. 24. C O N T A C T S ER VI C E I M PL . J AV AThis is the main server side file which reads and writes the XML documentpackage com.contact.server;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.PrintStream;import java.util.Iterator;import javax.xml.parsers.DocumentBuilder;import javax.xml.parsers.DocumentBuilderFactory;import javax.xml.parsers.ParserConfigurationException;import org.w3c.dom.DOMException;import org.w3c.dom.Document;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;import org.w3c.dom.NodeList;import org.xml.sax.SAXException;import com.contact.client.Card;import com.contact.client.CardSet;import com.contact.client.ContactService;import com.google.gwt.user.server.rpc.RemoteServiceServlet;public class ContactServiceImpl extends RemoteServiceServlet implements ContactService { private static final long serialVersionUID = 1420573242265861311L; Document dom; // structure of document CardSet cardSet; // the cardset to create from the XML document int errors; //stores the number of errors //to store each card value before it is made into a card String Name = ""; String Address = ""; String Town = ""; String County = ""; String Size = ""; int SizeInt; String Competence = ""; String Contact = ""; String ContactTel = ""; String ContactEmail = ""; public CardSet getCards() { cardSet = new CardSet(); //make new card set errors = 0; dom = parseXMLFile("cards.xml"); // makes DocumentBuilderFactory analyseElements(dom, ""); // recursive method if (errors > 0) //errors found { //make new card set cardSet = new CardSet(); } return cardSet; } /** * Private method to create a DocumentBuilderFactory * Carrie Hall 7179881 - 23 - * @param xmlfile
  25. 25. * @return Document (stored as variable dom * @throws Exception */ private Document parseXMLFile(String xmlfile) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse(xmlfile); return dom; } catch (ParserConfigurationException pce) { errors++; } catch (SAXException se) { errors++; } catch (IOException ioe) { errors++; } return null; } /** * recursive method which creates CardSet object * * @param node at which element is on * @param indent */ void analyseElements(Node node, String indent) { String name = node.getNodeName(); // gets name NodeList children = node.getChildNodes(); // gets children //go through all nodes switch (node.getNodeType()) { case Node.DOCUMENT_NODE: analyse(children, indent + " "); break; case Node.ELEMENT_NODE: if (name.equals("Cards")) // Cards node { analyse(children, indent + " "); //keep searching throughchildren } else if (name.equals("Card")) // Card node { analyse(children, indent + " ");//keep searching throughchildren } else if (name.equals("Name")) // Name node { if (children.item(0) != null) // must have a text node { try { // get name details Name = children.item(0).getNodeValue().trim(); } catch (DOMException e) { errors++; } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else if (name.equals("Address")) // address node { Carrie Hall 7179881 - 24 - if (children.item(0) != null) // must have a text node
  26. 26. { try { // get address details Address = children.item(0).getNodeValue().trim(); } catch (DOMException e) { errors++; } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else if (name.equals("Town")) // town node { if (children.item(0) != null) // must have a text node { try { // get town details Town = children.item(0).getNodeValue().trim(); } catch (DOMException e) { errors++; } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else if (name.equals("County")) // county node { if (children.item(0) != null) // must have a text node { try { // get county details County = children.item(0).getNodeValue().trim(); } catch (DOMException e) { errors++; } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else if (name.equals("Size")) // size node { if (children.item(0) != null) // must have a text node { try { // get size details Size = children.item(0).getNodeValue().trim(); SizeInt = Integer.parseInt(Size); } catch (DOMException e) { errors++; } catch (NumberFormatException n) { errors++; } analyse(children, indent + " "); } else // incorrect xml {Carrie Hall 7179881 - 25 - errors++;
  27. 27. } } else if (name.equals("Competence")) // competence node { if (children.item(0) != null) // must have a text node { try { // get competence details Competence =children.item(0).getNodeValue().trim(); } catch (DOMException e) { errors++; } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else if (name.equals("Contact")) // contact node { if (children.item(0) != null) // must have a text node { try { // get contact details Contact = children.item(0).getNodeValue().trim(); NamedNodeMap attributes = node.getAttributes(); //gets // attributes // checks if it is missing attribute tel if (attributes.getNamedItem("tel") != null) { try { // gets value of name attribute ContactTel =attributes.getNamedItem("tel") .getNodeValue().toString(); } catch (DOMException e) // no value for telattribute { errors++; } } else // no attribute for tel { errors++; } if (attributes.getNamedItem("email") != null) { try { // gets value of email attribute ContactEmail =attributes.getNamedItem("email") .getNodeValue().toString(); } catch (DOMException e) // no value foremail attribute { errors++; } } else // no attribute for name { errors++; } Carrie Hall 7179881 - 26 - } catch (DOMException e) {
  28. 28. errors++; } catch (NumberFormatException n) { errors++; } if (errors == 0) { cardSet.addCard(new Card(Name, Address, Town,County, Integer.parseInt(Size), Competence, ContactEmail, Contact, ContactTel)); } analyse(children, indent + " "); } else // incorrect xml { errors++; } } else // incorrect xml { errors++; } break; default: break; } } /* Recursive method to read the XML file */ public void analyse(NodeList children, String indent) { for (int i = 0; i < children.getLength(); i++) { analyseElements(children.item(i), indent); } } public void saveCards(CardSet cardSet) { // open the file to write PrintStream os = null; try { os = new PrintStream(new FileOutputStream(new File("cards.xml"))); } catch (FileNotFoundException e) { e.printStackTrace(); } // header information os.println("<?xml version="1.0"?>"); // Cards is the root element os.println("<Cards " + "xmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" " + "xsi:schemaLocation="http://www.w3schools.com cards.xsd">"); // print the cardset Iterator<?> i = cardSet.getCards().iterator(); while (i.hasNext()) { Card temp = (Card) i.next(); os.print(temp.toXML()); } // end root element os.println("</Cards>"); os.flush(); os.close(); } public void saveCard(Card cardIn) { // open the file to write Carrie Hall 7179881 - 27 - PrintStream os = null;
  29. 29. String filename = cardIn.getcompanyName() + "_" + cardIn.getcounty() + ".xml"; try { os = new PrintStream(new FileOutputStream(new File(filename))); } catch (FileNotFoundException e) { e.printStackTrace(); } // header information os.println("<?xml version="1.0"?>"); // print the quiz os.println("<Cards " + "xmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3schools.com cards.xsd">"); os.print(cardIn.toXML()); os.println("</Cards>"); // end root element os.flush(); os.close(); }} Carrie Hall 7179881 - 28 -
  30. 30. C O N T A C T S ER VI C E . J A VApackage com.contact.client;import com.google.gwt.user.client.rpc.RemoteService;public interface ContactService extends RemoteService { public void saveCards(CardSet cardSet); public void saveCard(Card card); public CardSet getCards();C O N T A C T S ER VI C E A SY N C . J AV A}package com.contact.client;import com.google.gwt.user.client.rpc.AsyncCallback;public interface ContactServiceAsync { public void saveCards(CardSet cardSet, AsyncCallback<?> callback); public void saveCard(Card card, AsyncCallback<?> callback); public void getCards(AsyncCallback<CardSet> callback);} Carrie Hall 7179881 - 29 -
  31. 31. EC O N T A C T . J AV AThis is the main class which shows all of the widgets displayed to the user.package com.contact.client;import java.util.ArrayList;import java.util.Iterator;import com.google.gwt.core.client.EntryPoint;import com.google.gwt.core.client.GWT;import com.google.gwt.event.dom.client.ClickEvent;import com.google.gwt.event.dom.client.ClickHandler;import com.google.gwt.event.dom.client.MouseOutEvent;import com.google.gwt.event.dom.client.MouseOutHandler;import com.google.gwt.event.dom.client.MouseOverEvent;import com.google.gwt.event.dom.client.MouseOverHandler;import com.google.gwt.user.client.Window;import com.google.gwt.user.client.rpc.AsyncCallback;import com.google.gwt.user.client.rpc.ServiceDefTarget;import com.google.gwt.user.client.ui.Button;import com.google.gwt.user.client.ui.Grid;import com.google.gwt.user.client.ui.HTML;import com.google.gwt.user.client.ui.Label;import com.google.gwt.user.client.ui.MultiWordSuggestOracle;import com.google.gwt.user.client.ui.DisclosurePanel;import com.google.gwt.user.client.ui.FlowPanel;import com.google.gwt.user.client.ui.SuggestBox;import com.google.gwt.user.client.ui.TextBox;import com.google.gwt.user.client.ui.RootPanel;public class EContact implements EntryPoint{ //to store a card Card c = null; //Search box SuggestBox searchBox; //Items for the Add Business form TextBox companyName = new TextBox(); TextBox address = new TextBox(); TextBox town = new TextBox(); SuggestBox county; TextBox numberOfStaff = new TextBox(); SuggestBox coreCompetence; TextBox contactName = new TextBox(); TextBox contactTel = new TextBox(); TextBox contactEmail = new TextBox(); Label companyNameLabel = new Label("Company Name"); Label addressLabel = new Label("Address"); Label townLabel = new Label("Town"); Label countyLabel = new Label("County"); Label numberOfStaffLabel = new Label("Number Of Staff"); Label coreCompetenceLabel = new Label("Core Competence"); Label contactNameLabel = new Label("Contact Name"); Label contactTelLabel = new Label("Contact Telephone"); Label contactEmailLabel = new Label("Contact Email"); Button addButton; //Indicates the problem that occured when adding card, e.g missing value String addError = ""; //Changes to true if card is added. Used to display success message boolean addSuccess = false; //Indicates the problem that occured when adding card, e.g missing value String searchError = ""; Carrie Hall 7179881 - 30 - //String that the user searched for
  32. 32. String searchString; //Set to true if errors are found in Add a Card boolean errors = false; /*Variables for the Search*/ boolean narrowByLocation = false; //set to TRUE if user has narrowed by Location boolean narrowBySize = false; //set to TRUE if user has narrowed by BusinessSize String narrowByLocationRes = ""; String narrowBySizeRes = ""; //stores the list of cards CardSet cardSet; //stores a list of cards matching criteria, ie when searched for an item or narrowedsearch ArrayList<Card> cardsMatchingCriteria; //to store the content of the main area HTML contents = new HTML(""); //to store connection to server AsyncCallback<CardSet> callback; ContactServiceAsync svc; //to store connection to server AsyncCallback<Card> callbackCard; /* * Main method ran when program loads * @see com.google.gwt.core.client.EntryPoint#onModuleLoad() */ public void onModuleLoad() { //makes new cardSet cardSet = new CardSet(); // define the service to call svc = (ContactServiceAsync) GWT.create(ContactService.class); ServiceDefTarget endpoint = (ServiceDefTarget) svc; endpoint.setServiceEntryPoint("/EContact"); // define a handler for what to do when the // service returns a result callback = new AsyncCallback<CardSet>() { public void onSuccess (CardSet result) { //errors may have been found when reading XML if (result.equals(null)) { //make new cardset cardSet = new CardSet(); } else //no errors { cardSet = (CardSet) result; //save result } showHome(); //show the content addLinks(); //show the navigation showSearch(); //show the search } public void onFailure (Throwable ex) { Window.alert(ex.toString()); Carrie Hall 7179881 - 31 -
  33. 33. } }; // execute the service svc.getCards(callback); } /* * shows the index page */ private void showHome() { RootPanel.get("main").clear(); //wipes the main content //ensures that the success message will not show when the user next clickson add a card addSuccess=false; //add index content contents = new HTML("<p>SME Network manages the profiles of small and mediumsize enterprises (SMEs).</p>" +"<p>We aim to facilitate the formation of virtual enterprises that consist ofcomplementary business partners to meet the emerging customer demands.</p>" +"<p>E-Contact is a system that allows you to find business partners by searchingthrough the profiles on our website.</p><br/><br/><br/><br/><br/><br/>"); RootPanel.get("main").add(contents); } /* * Shows the add profile page */ private void add() { RootPanel.get("main").clear(); //wipes the main content if (addError.length()==0) //no errors { if (addSuccess) //no errors and add successful { //show message HTML successMessage = new HTML("<p class=error>* Successfullyadded business card</p>"); RootPanel.get("main").add(successMessage); //will not show message again addSuccess = false; //jumps the window to the top so message can be seen clearly Window.scrollTo(0, 0); //sets text boxes to blank companyName.setText(""); address.setText(""); town.setText(""); numberOfStaff.setText(""); contactName.setText(""); contactTel.setText(""); contactEmail.setText(""); coreCompetence = new SuggestBox(createCompetences()); county = new SuggestBox(createCounties()); addError=""; } else //no errors but add not successful, implies that user has neveradded a profile { //sets error to blank addError=""; //styles the boxes to default companyName.setStylePrimaryName("textField"); address.setStylePrimaryName("textField"); town.setStylePrimaryName("textField"); numberOfStaff.setStylePrimaryName("textField"); contactName.setStylePrimaryName("textField"); contactTel.setStylePrimaryName("textField"); contactEmail.setStylePrimaryName("textField"); Carrie Hall 7179881 - 32 - coreCompetence = new SuggestBox(createCompetences());
  34. 34. county = new SuggestBox(createCounties()); } } else if (addError.length()>0) //errors found { //show error and jump to top HTML addErrorHTML = new HTML(addError); Window.scrollTo(0, 0); RootPanel.get("main").add(addErrorHTML); addError=""; } //show add button with click events addButton = new Button("Add"); addButton.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { //disable button until verification is complete so that userdoes not press more than once addButton.setEnabled(false); errors = false; //gets entered values String companyNameTemp = companyName.getText(); String addressTemp = address.getText(); String townTemp = town.getText(); String countyTemp = county.getText(); String numberOfStaffTemp = numberOfStaff.getText(); String coreCompetenceTemp = coreCompetence.getText(); String contactNameTemp = contactName.getText(); String contactTelTemp = contactTel.getText(); String contactEmailTemp = contactEmail.getText(); //checks for null values. sets errors to true if found and addsmessage to a string which //will be outputted to user. Sets the style so that boxes arehighlighted if incorrect if (companyNameTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a company name</p>"; companyName.setStylePrimaryName("incorrectField"); } else { companyName.setStylePrimaryName("textField"); } if (addressTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter an address</p>"; address.setStylePrimaryName("incorrectField"); } else { address.setStylePrimaryName("textField"); } if (townTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter an town</p>"; town.setStylePrimaryName("incorrectField"); } else { town.setStylePrimaryName("textField"); } if (countyTemp.trim()=="") { Carrie Hall 7179881 - 33 - errors = true;
  35. 35. addError+="<p class=error>* Please enter an county</p>"; county.setStylePrimaryName("incorrectField"); } else { county.setStylePrimaryName("textField"); } if (numberOfStaffTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a number ofstaff</p>"; numberOfStaff.setStylePrimaryName("incorrectField"); } else { numberOfStaff.setStylePrimaryName("textField"); } if (numberOfStaffTemp.trim()!="") { boolean passes = true; try //checks for only a number entered { Integer.parseInt(numberOfStaffTemp); } catch (NumberFormatException e) { passes = false; errors = true; addError+="<p class=error>* Please enter a number forthe staff field</p>"; numberOfStaff.setStyleName("incorrectField"); } if (passes) { numberOfStaff.setStyleName("textField"); } } if (coreCompetenceTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a corecompetence</p>"; coreCompetence.setStylePrimaryName("incorrectField"); } else { coreCompetence.setStylePrimaryName("textField"); } if (contactNameTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a contact name</p>"; contactName.setStyleName("incorrectField"); } else { contactName.setStyleName("textField"); } if (contactTelTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a contacttelephone</p>"; contactTel.setStyleName("incorrectField"); } else Carrie Hall 7179881 - 34 - {
  36. 36. contactTel.setStyleName("textField"); } if (contactTelTemp.trim()!="") { boolean passes = true; try { //checks for long number entered. Integer will not belarge enough for a phone number Long.parseLong(contactTelTemp); } catch (NumberFormatException e) { passes = false; errors = true; addError+="<p class=error>* Please enter a number forthe phone number</p>"; contactTel.setStyleName("incorrectField"); } if (passes) { contactTel.setStyleName("textField"); } } if (contactEmailTemp.trim()=="") { errors = true; addError+="<p class=error>* Please enter a contactemail</p>"; contactEmail.setStyleName("incorrectField"); } else { contactEmail.setStyleName("textField"); } //no errors if (!errors) { //removes error string addError = ""; addButton.setEnabled(true); //enables button //makes new card Card tempCard = newCard(companyNameTemp,addressTemp,townTemp,countyTemp,Integer.parseInt(numberOfStaffTemp),coreCompetenceTemp,contactEmailTemp,contactNameTemp,contactTelTemp); //tries to add card boolean added = cardSet.addCard(tempCard); if (added) //success { //write new xml file with that card included svc.saveCards(cardSet, callback); //clears the search and enters it again to refresh listof companies RootPanel.get("search").clear(); showSearch(); addSuccess = true; } else //card exists { addError+="<p class=error>* A card for this company inthis location already exists</p>"; } add(); //recursive, calls this method again to redisplay (anddisplay errors if needed) } else if (errors) { Carrie Hall 7179881 - 35 - //enables button and reloads method
  37. 37. addButton.setEnabled(true); add(); } } }); //makes new grid to put text fields in. similar to html table layout Grid grid = new Grid(12, 2); grid.getCellFormatter().setWidth(0, 0, "150px"); grid.setWidget(0, 0, companyNameLabel); grid.setWidget(0, 1, companyName); grid.setWidget(1, 0, addressLabel); grid.setWidget(1, 1, address); grid.setWidget(2, 0, townLabel); grid.setWidget(2, 1, town); grid.setWidget(3, 0, countyLabel); grid.setWidget(3, 1, county); grid.setWidget(4, 0, numberOfStaffLabel); grid.setWidget(4, 1, numberOfStaff); grid.setWidget(5, 0, coreCompetenceLabel); grid.setWidget(5, 1, coreCompetence); grid.setWidget(7, 0, contactNameLabel); grid.setWidget(7, 1, contactName); grid.setWidget(8, 0, contactTelLabel); grid.setWidget(8, 1, contactTel); grid.setWidget(9, 0, contactEmailLabel); grid.setWidget(9, 1, contactEmail); grid.setWidget(11, 1, addButton); //adds to main panel RootPanel.get("main").add(grid); } /* * Shows help */ private void help() { addSuccess=false; RootPanel.get("main").clear(); contents = new HTML("<p>To search, simply enter the competence that you wishto look for in the search box</p>" + "<p>If you wish to narrow your search, click on one of thelocations or a size that you want to only search by</p>" + "<img src=narrowed1.png alt=narrow/>" + "<p>To remove the narrowing simply click on the orange linkwhich shows you what you have narrowed by</p>" + "<img src=narrowed.png alt=narrow/>" + "<p>Adding a business card is easy, just click on the link,fill in all the details and press ADD</p>"); RootPanel.get("main").add(contents); } /* * Shows Navigation */ private void addLinks() { //NAVIGATION final HTML link1 = new HTML("<p>Home</p>"); link1.addStyleName("inline"); link1.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { showHome(); } }); link1.addMouseOverHandler(new MouseOverHandler() Carrie Hall 7179881 - 36 - {
  38. 38. public void onMouseOver(MouseOverEvent event) { link1.setStyleName("inline handCursor mouseHover"); } }); link1.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { link1.setStyleName("inline normalCursor"); } }); final HTML link2 = new HTML("<p>Add A Profile</p>"); link2.addStyleName("inline"); link2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { add(); } }); link2.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { link2.setStyleName("inline handCursor mouseHover"); } }); link2.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { link2.setStyleName("inline normalCursor"); } }); final HTML link3 = new HTML("<p>Help</p>"); link3.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { help(); } }); link3.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { link3.setStyleName("inline handCursor mouseHover"); } }); link3.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { link3.setStyleName("inline normalCursor"); } }); link3.addStyleName("inline"); //add links RootPanel.get("navigation").add(link1); RootPanel.get("navigation").add(link2); RootPanel.get("navigation").add(link3); } /* * Shows search box */ private void showSearch() { //label for search Label livesearch = new Label("Search"); livesearch.addStyleName("searchText"); //search box searchBox = new SuggestBox(createCompetences());Carrie Hall 7179881 - 37 - //search button
  39. 39. final Button button = new Button("Go"); button.setSize("40", "40"); button.addStyleName("inline searchButton"); button.addMouseOverHandler(new MouseOverHandler(){ public void onMouseOver(MouseOverEvent event) { button.addStyleName("searchButtonHover"); } }); button.addMouseOutHandler(new MouseOutHandler(){ public void onMouseOut(MouseOutEvent event) { button.setStyleName("gwt-Button inline searchButton"); } }); //if button clicked button.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { //disable button button.setEnabled(false); //removes narrow functions if they were on narrowByLocation = false; narrowBySize = false; narrowByLocationRes = ""; narrowBySizeRes = ""; //trims white space searchString = searchBox.getText().trim(); //check for null if (searchString=="") { button.setEnabled(true); searchError="<p>Please enter a search term</p>"; searchResults(); //shows results } else { searchError=""; //no error //get cards matching search cardsMatchingCriteria =cardSet.getCardsByCompetence(searchString); button.setEnabled(true); //enable button searchResults(); //get results } } }); searchBox.setStylePrimaryName("inline largefield search"); RootPanel.get("search").add(livesearch); RootPanel.get("search").add(searchBox); RootPanel.get("search").add(button); } /* * Shows results */ private void searchResults() { RootPanel.get("main").clear(); //clears main content //errors found if (searchError.length()>0) { Window.scrollTo(0, 0); //jump to top //show error RootPanel.get("main").add(new HTML(searchError)); //show link to view all cards final HTML clickHere = new HTML("Click here to view all businesscards"); Carrie Hall 7179881 - 38 - clickHere.addStyleName("links");
  40. 40. clickHere.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { searchError=""; searchString = "all"; cardsMatchingCriteria = cardSet.getCards(); searchResults(); } }); clickHere.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { clickHere.setStyleName("links handCursor mouseHover"); } }); clickHere.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { clickHere.setStyleName("links normalCursor"); } }); RootPanel.get("main").add(clickHere); } if (searchError.length()==0) //no errors { String resultsMsg = ""; //shows what user searched for String youSearchedForMsg = "<span>You searched for <strong>" +searchString + ".</strong></span>" ; if (cardsMatchingCriteria.size()==0) { resultsMsg = "<br/><span><strong>0</strong> resultsfound.</span>"; } else if (cardsMatchingCriteria.size()==1) { resultsMsg = "<br/><span><strong>" +cardsMatchingCriteria.size() + "</strong> result found.</span>"; } else if (cardsMatchingCriteria.size()>1) { resultsMsg = "<br/><span><strong>" +cardsMatchingCriteria.size() + "</strong> results found.</span>"; } RootPanel.get("main").add(new HTML(youSearchedForMsg)); //shows narrowing capabilities showNarrowing(); RootPanel.get("main").add(new HTML(resultsMsg)); RootPanel.get("main").add(new HTML("<br />")); //loops through matching cards to display Iterator<Card> i = cardsMatchingCriteria.iterator(); while (i.hasNext()) { final Card tempCard = i.next(); //shows title final HTML title = newHTML("<h5>"+tempCard.getcompanyName()+"<h5>"); //shows competence and size final HTML about = new HTML("<span>" +tempCard.getcoreCompetence() + ", " + tempCard.getSize().toLowerCase() +"company</span>"); //shows location final HTML location = new HTML("<span class=location>" +tempCard.getcounty() + "</span><br /><br />"); Carrie Hall 7179881 - 39 - title.addClickHandler(new ClickHandler()
  41. 41. { public void onClick(ClickEvent event) { showResult(tempCard); } }); title.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { title.setStyleName("handCursor mouseHover"); } }); title.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { title.setStyleName("normalCursor"); } }); RootPanel.get("main").add(title); RootPanel.get("main").add(about); RootPanel.get("main").add(location); } } } /* * Shows a single page with details of the chosen card */ private void showResult(Card tempCard) { c = tempCard; RootPanel.get("main").clear(); //shows link back to results. final Label back = new Label("< Back to results"); back.addStyleName("links"); back.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { searchResults(); } }); back.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { back.setStyleName("links handCursor mouseHover"); } }); back.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { back.setStyleName("links normalCursor"); } }); //information to display HTML title = new HTML("<h3>"+ tempCard.getcompanyName() + "</h3>"); HTML addLabel = new HTML("<h2>Address Details:</h2>"); HTML address = new HTML(tempCard.getaddress() + "<br />"+tempCard.gettown()+ "<br />"+ tempCard.getcounty() + "</p>"); HTML contLabel = new HTML("<h2>Contact Details:</h2>"); HTML contact = new HTML(tempCard.getcontactName() + "<br />"); HTML contacttel = new HTML("Tel: " + tempCard.getcontactTel()+ "<br />"); HTML contactemail = new HTML("Email: " + tempCard.getcontactEmail() + "<br/><br /><br /><br />"); //button to download file final Button xmlDownloadLink = new Button("Download to XML"); xmlDownloadLink.addMouseOverHandler(new MouseOverHandler() { Carrie Hall 7179881 - 40 - public void onMouseOver(MouseOverEvent event) {
  42. 42. xmlDownloadLink.setStyleName("gwt-Button handCursormouseHover"); } }); xmlDownloadLink.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { xmlDownloadLink.setStyleName("gwt-Button normalCursor"); } }); xmlDownloadLink.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { svc.saveCard(c, callback); } }); RootPanel.get("main").add(back); RootPanel.get("main").add(title); RootPanel.get("main").add(addLabel); RootPanel.get("main").add(address); RootPanel.get("main").add(contLabel); RootPanel.get("main").add(contact); RootPanel.get("main").add(contacttel); RootPanel.get("main").add(contactemail); RootPanel.get("main").add(xmlDownloadLink); } /*Shows links to narrow files */ private void showNarrowing() { //panel to hold option. It is a disclosure panel meaning that the user canshow it or hide it. //open by default final DisclosurePanel DiscPanel = new DisclosurePanel("Narrow options"); //slide transition is animated DiscPanel.setAnimationEnabled(true); DiscPanel.setOpen(true); FlowPanel panel = new FlowPanel(); panel.setStyleName("narrow"); //has already been narrowed by location so needs to show what its narrowed by if (narrowByLocation) { panel.add(new HTML("<span>Narrow by location:</span><ul>")); final HTML clickHere = new HTML("<li>" + narrowByLocationRes +"</li>"); clickHere.addStyleName("narrowedItem"); clickHere.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { narrowByLocation=false; narrowByLocationRes = ""; if (!narrowBySize) { if (searchString.equals("all")) { cardsMatchingCriteria = cardSet.getCards(); } else { cardsMatchingCriteria =cardSet.getCardsByCompetence(searchString); } } Carrie Hall 7179881 - 41 - else
  43. 43. { if (searchString.equals("all")) { cardsMatchingCriteria = cardSet.getCards(); } else { cardsMatchingCriteria =cardSet.getCardsByCompetence(searchString); } cardsMatchingCriteria =cardSet.narrowBySizes(cardsMatchingCriteria, narrowBySizeRes); } searchResults(); } }); clickHere.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { clickHere.setStyleName("removeitem handCursor"); } }); clickHere.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { clickHere.setStyleName("narrowedItem normalCursor"); } }); panel.add(clickHere); panel.add(new HTML("</ul>")); } //not narrowed so needs to show all locations if (!narrowByLocation){ panel.add(new HTML("<span>Narrow by location:</span><ul>")); //gets all locations when passed a card set Iterator<?> i =cardSet.getCardLocations(cardsMatchingCriteria).iterator(); while (i.hasNext()) { final String temp = i.next().toString(); final HTML clickHere = new HTML("<li>" + temp + "</li>"); clickHere.addStyleName("inline links"); clickHere.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { narrowByLocation=true; narrowByLocationRes = temp; cardsMatchingCriteria =cardSet.narrowByLocation(cardsMatchingCriteria, temp); searchResults(); } }); clickHere.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { clickHere.setStyleName("inline links handCursormouseHover"); } }); clickHere.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { clickHere.setStyleName("inline linksnormalCursor"); } Carrie Hall 7179881 - 42 - });
  44. 44. panel.add(clickHere); } panel.add(new HTML("</ul>")); } //already narrowed by size if (narrowBySize){ panel.add(new HTML("<br/><span>Narrow by size:</span><ul>")); final HTML clickHere = new HTML("<li>" + narrowBySizeRes + "</li>"); clickHere.addStyleName("narrowedItem"); clickHere.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { narrowBySize=false; narrowBySizeRes = ""; if (!narrowByLocation) { if (searchString.equals("all")) { cardsMatchingCriteria = cardSet.getCards(); } else { cardsMatchingCriteria =cardSet.getCardsByCompetence(searchString); } } else { if (searchString.equals("all")) { cardsMatchingCriteria = cardSet.getCards(); } else { cardsMatchingCriteria =cardSet.getCardsByCompetence(searchString); } cardsMatchingCriteria =cardSet.narrowByLocation(cardsMatchingCriteria, narrowByLocationRes); } searchResults(); } }); clickHere.addMouseOverHandler(new MouseOverHandler() { public void onMouseOver(MouseOverEvent event) { clickHere.setStyleName("removeitem handCursor"); } }); clickHere.addMouseOutHandler(new MouseOutHandler() { public void onMouseOut(MouseOutEvent event) { clickHere.setStyleName("narrowedItem normalCursor"); } }); panel.add(clickHere); panel.add(new HTML("</ul>")); } //not narrowed by sizes if (!narrowBySize) { panel.add(new HTML("<br/><span>Narrow by size:</span><ul>")); Iterator<?> i = cardSet.getSizes(cardsMatchingCriteria).iterator(); while (i.hasNext()) { Carrie Hall 7179881 - 43 - final String temp = i.next().toString();

×