Permalink
Browse files

updates. getting to hibernate functionality. Adding Command structure.

  • Loading branch information...
1 parent 468deb7 commit 765143a825abe62aa2451f37b347b4c612de68a3 @jdwyah committed Feb 12, 2008
Showing with 1,782 additions and 182 deletions.
  1. +15 −0 .freemarker-ide.xml
  2. +6 −0 .pydevproject
  3. +256 −0 .settings/org.eclipse.jdt.core.prefs
  4. +4 −0 .settings/org.eclipse.jdt.ui.prefs
  5. +9 −3 pom.xml
  6. +3 −0 src/main/java/com/apress/progwt/Interactive.gwt.xml
  7. +38 −3 src/main/java/com/apress/progwt/client/college/CollegeBoundApp.java
  8. +130 −0 src/main/java/com/apress/progwt/client/college/SchoolCompleteOracle.java
  9. +123 −0 src/main/java/com/apress/progwt/client/college/SchoolCompleter.java
  10. +32 −0 src/main/java/com/apress/progwt/client/college/TopicCache.java
  11. +30 −0 src/main/java/com/apress/progwt/client/college/gui/AppCheckboxWidget.java
  12. +56 −0 src/main/java/com/apress/progwt/client/college/gui/CollegeEntry.java
  13. +9 −0 src/main/java/com/apress/progwt/client/college/gui/CompleteListener.java
  14. +78 −0 src/main/java/com/apress/progwt/client/college/gui/MyPage.java
  15. +17 −0 src/main/java/com/apress/progwt/client/domain/ApplicationCheckbox.java
  16. +48 −0 src/main/java/com/apress/progwt/client/domain/ApplicationCheckboxValue.java
  17. +29 −0 src/main/java/com/apress/progwt/client/domain/ApplicationProcess.java
  18. +11 −0 src/main/java/com/apress/progwt/client/domain/ApplicationStatus.java
  19. +5 −0 src/main/java/com/apress/progwt/client/domain/Loadable.java
  20. +4 −1 src/main/java/com/apress/progwt/client/domain/School.java
  21. +18 −0 src/main/java/com/apress/progwt/client/domain/SchoolAndAppProcess.java
  22. +59 −45 src/main/java/com/apress/progwt/client/domain/User.java
  23. +49 −0 src/main/java/com/apress/progwt/client/domain/commands/AbstractCommand.java
  24. +22 −0 src/main/java/com/apress/progwt/client/domain/commands/SaveSchoolRankCommand.java
  25. +23 −0 src/main/java/com/apress/progwt/client/domain/generated/AbstractApplicationCheckbox.java
  26. +42 −0 src/main/java/com/apress/progwt/client/domain/generated/AbstractApplicationProcess.java
  27. +40 −0 src/main/java/com/apress/progwt/client/domain/generated/AbstractSchoolAndAppProcess.java
  28. +10 −5 src/main/java/com/apress/progwt/client/domain/generated/AbstractUser.java
  29. +7 −1 src/main/java/com/apress/progwt/client/exception/BusinessException.java
  30. +7 −1 src/main/java/com/apress/progwt/client/exception/InfrastructureException.java
  31. +12 −7 src/main/java/com/apress/progwt/client/exception/SiteException.java
  32. +21 −0 src/main/java/com/apress/progwt/client/rpc/EZCallback.java
  33. +14 −0 src/main/java/com/apress/progwt/client/service/remote/GWTSchoolService.java
  34. +13 −0 src/main/java/com/apress/progwt/client/service/remote/GWTSchoolServiceAsync.java
  35. +1 −9 src/main/java/com/apress/progwt/public/CollegeApp.html
  36. +0 −7 src/main/java/com/apress/progwt/public/SampleApp.html
  37. +25 −0 src/main/java/com/apress/progwt/public/css/gwtstyles.css
  38. +7 −0 src/main/java/com/apress/progwt/server/dao/SchoolDAO.java
  39. +28 −1 src/main/java/com/apress/progwt/server/dao/hibernate/SchoolDAOHibernateImpl.java
  40. +6 −0 src/main/java/com/apress/progwt/server/service/SchoolService.java
  41. +29 −0 src/main/java/com/apress/progwt/server/service/gwt/GWTSchoolServiceImpl.java
  42. +81 −0 src/main/java/com/apress/progwt/server/service/impl/SchoolServiceImpl.java
  43. +83 −0 src/main/java/com/apress/progwt/server/util/EnumUserType.java
  44. +17 −0 src/main/resources/com/apress/progwt/client/domain/ApplicationProcess.hbm.xml
  45. +18 −0 src/main/resources/com/apress/progwt/client/domain/SchoolAndAppProcess.hbm.xml
  46. +8 −3 src/main/resources/com/apress/progwt/client/domain/User.hbm.xml
  47. +3 −1 src/main/webapp/WEB-INF/applicationContext-hibernate.xml
  48. +6 −0 src/main/webapp/WEB-INF/applicationContext.xml
  49. +2 −1 src/main/webapp/WEB-INF/dispatcher-servlet.xml
  50. +1 −2 src/main/webapp/WEB-INF/freemarker/calculator.ftl
  51. +0 −1 src/main/webapp/WEB-INF/freemarker/common.ftl
  52. +44 −0 src/main/webapp/WEB-INF/freemarker/secure/myList.ftl
  53. +19 −8 src/test/java/com/apress/progwt/server/dao/hibernate/SchoolDAOHibernateImplTest.java
  54. +74 −83 src/test/java/com/apress/progwt/server/dao/hibernate/UserDAOHibernateImplTest.java
  55. +33 −0 src/test/java/com/apress/progwt/server/service/impl/SchoolServiceImplTest.java
  56. +57 −0 src/test/java/com/apress/progwt/server/service/impl/ServiceTestWithTransaction.java
View
@@ -0,0 +1,15 @@
+<config>
+ <context-values>
+ <resource path="src/main/webapp/WEB-INF/freemarker/index.ftl">
+ <value key="frontPage" object-class="com.apress.progwt.server.domain.FrontPageData"/>
+ </resource>
+ <resource path="src/main/webapp/WEB-INF/freemarker/college.ftl">
+ <value key="school" object-class="com.apress.progwt.client.domain.School"/>
+ </resource>
+ <resource path="src/main/webapp/WEB-INF/freemarker/user.ftl">
+ <value key="user" object-class="com.apress.progwt.client.domain.User"/>
+ </resource>
+ </context-values>
+ <macro-library>
+ </macro-library>
+</config>
View
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.4</pydev_property>
+</pydev_project>

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,4 @@
+#Sun Oct 14 11:33:19 EDT 2007
+eclipse.preferences.version=1
+formatter_profile=_Apress Settings
+formatter_settings_version=11
View
12 pom.xml
@@ -87,20 +87,26 @@
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-user</artifactId>
- <version>1.5.0.build1481</version>
+ <version>1.5.0.build1491</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-dev-windows</artifactId>
- <version>1.5.0.build1481</version>
+ <version>1.5.0.build1491</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google</groupId>
<artifactId>gwt-servlet</artifactId>
- <version>1.5.0.build1481</version>
+ <version>1.5.0.build1491</version>
</dependency>
+ <dependency>
+ <groupId>com.google</groupId>
+ <artifactId>gwt-dragdrop</artifactId>
+ <version>1.2.5</version>
+ </dependency>
+
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
@@ -6,9 +6,12 @@
<inherits name="com.google.gwt.i18n.I18N" />
<inherits name="com.google.gwt.json.JSON" />
+ <inherits name='com.allen_sauer.gwt.dragdrop.DragAndDrop'/>
+
<!-- Specify the app entry point class. -->
<entry-point class='com.apress.progwt.client.Interactive' />
+
<stylesheet src="css/gwtstyles.css" />
@@ -1,14 +1,24 @@
package com.apress.progwt.client.college;
-import com.apress.progwt.client.calculator.Calculator;
+import com.apress.progwt.client.Interactive;
+import com.apress.progwt.client.college.gui.MyPage;
+import com.apress.progwt.client.domain.User;
+import com.apress.progwt.client.service.remote.GWTSchoolService;
+import com.apress.progwt.client.service.remote.GWTSchoolServiceAsync;
+import com.apress.progwt.client.service.remote.GWTUserService;
+import com.apress.progwt.client.service.remote.GWTUserServiceAsync;
import com.apress.progwt.client.util.Logger;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
public class CollegeBoundApp {
public static final String MAIN_DIV = "slot1";
+ private GWTSchoolServiceAsync schoolService;
+ private GWTUserServiceAsync userService;
private void loadGUI(Widget widget) {
RootPanel.get("loading").setVisible(false);
@@ -28,11 +38,36 @@ public CollegeBoundApp() {
}
private void setMeUp() {
- loadGUI(new Calculator());
+ loadGUI(new MyPage(this, new User()));
}
- private void initServices() {
+ protected void initServices() {
+ schoolService = (GWTSchoolServiceAsync) GWT
+ .create(GWTSchoolService.class);
+ ServiceDefTarget endpoint = (ServiceDefTarget) schoolService;
+
+ String pre = Interactive.getRelativeURL("service/");
+
+ endpoint.setServiceEntryPoint(pre + "schoolService");
+
+ userService = (GWTUserServiceAsync) GWT
+ .create(GWTUserService.class);
+ ServiceDefTarget endpointUser = (ServiceDefTarget) userService;
+ endpointUser.setServiceEntryPoint(pre + "userService");
+
+ if (schoolService == null || userService == null) {
+ Logger.error("Service was null.");
+ }
+
+ }
+
+ public GWTSchoolServiceAsync getSchoolService() {
+ return schoolService;
+ }
+
+ public GWTUserServiceAsync getUserService() {
+ return userService;
}
protected void error(Exception e) {
@@ -0,0 +1,130 @@
+package com.apress.progwt.client.college;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.apress.progwt.client.domain.School;
+import com.apress.progwt.client.rpc.EZCallback;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.SuggestOracle;
+
+public class SchoolCompleteOracle extends SuggestOracle {
+
+ protected class SchoolSuggestion implements Suggestion {
+ private final School value;
+ private String query;
+
+ public SchoolSuggestion(School school, String query) {
+ this.value = school;
+ this.query = query;
+ }
+
+ public String getDisplayString() {
+
+ return highlight(value.getName(), query);
+
+ }
+
+ /**
+ * odd. can't return the TI, since .toString() is called on it and
+ * that is put in the box. worse, there's no way to call
+ * suggestBox, getSelectedValue()
+ */
+ public Object getValue() {
+ System.out.println("get value " + value);
+ return value.getName();
+ }
+
+ public String getReplacementString() {
+ System.out.println("get replacementString " + value);
+ return value.getName();
+ }
+ }
+
+ private TopicCache serviceCache;
+
+ public SchoolCompleteOracle(TopicCache topicCache) {
+ this.serviceCache = topicCache;
+ }
+
+ @Override
+ public void requestSuggestions(final Request request,
+ final Callback callback) {
+
+ getSchoolsForString(request.getQuery(),
+ new EZCallback<List<School>>() {
+
+ public void onSuccess(List<School> results) {
+
+ List<SchoolSuggestion> suggestions = new ArrayList<SchoolSuggestion>();
+
+ for (School school : results) {
+ suggestions.add(new SchoolSuggestion(school,
+ request.getQuery()));
+ }
+ callback.onSuggestionsReady(request,
+ new Response(suggestions));
+ }
+
+ });
+ }
+
+ public void getSchoolsForString(String queryString,
+ AsyncCallback<List<School>> callback) {
+ serviceCache.match(queryString, callback);
+ }
+
+ @Override
+ public boolean isDisplayStringHTML() {
+ return true;
+ }
+
+ private static HTML convertMe = new HTML();
+ private static final char WHITESPACE_CHAR = ' ';
+
+ private String escapeText(String escapeMe) {
+ convertMe.setText(escapeMe);
+ String escaped = convertMe.getHTML();
+ return escaped;
+ }
+
+ /**
+ * Simpler than the Google MultiWordSuggest highlighter in that it
+ * will only highlight the first occurrence
+ *
+ * @param candidate
+ * @param query
+ * @return
+ */
+ private String highlight(String candidate, String query) {
+
+ int index = 0;
+ int cursor = 0;
+
+ // Create strong search string.
+ StringBuffer accum = new StringBuffer();
+
+ query = query.toLowerCase();
+
+ index = candidate.toLowerCase().indexOf(query, index);
+
+ if (index == -1) {
+ accum.append(escapeText(candidate));
+ } else {
+ int endIndex = index + query.length();
+ String part1 = escapeText(candidate.substring(cursor, index));
+ String part2 = escapeText(candidate
+ .substring(index, endIndex));
+ cursor = endIndex;
+ accum.append(part1).append("<strong>").append(part2).append(
+ "</strong>");
+ }
+
+ // Finish creating the formatted string.
+ String end = candidate.substring(cursor);
+ accum.append(escapeText(end));
+
+ return accum.toString();
+ }
+}
@@ -0,0 +1,123 @@
+package com.apress.progwt.client.college;
+
+import java.util.List;
+
+import com.apress.progwt.client.college.gui.CompleteListener;
+import com.apress.progwt.client.domain.School;
+import com.apress.progwt.client.rpc.EZCallback;
+import com.google.gwt.user.client.Command;
+import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.user.client.Timer;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
+import com.google.gwt.user.client.ui.SuggestBox;
+import com.google.gwt.user.client.ui.SuggestionEvent;
+import com.google.gwt.user.client.ui.SuggestionHandler;
+import com.google.gwt.user.client.ui.Widget;
+
+public class SchoolCompleter extends Composite {
+
+ private TopicCache topicService;
+ private SchoolCompleteOracle oracle;
+ private CompleteListener completeListener;
+ private SuggestBox suggestBox;
+
+ private Timer keyboardEnterTimer;
+
+ public SchoolCompleter(TopicCache topicService) {
+ super();
+ this.topicService = topicService;
+ if (oracle == null) {
+ oracle = new SchoolCompleteOracle(topicService);
+ }
+ suggestBox = new SuggestBox(oracle);
+
+ initWidget(suggestBox);
+ }
+
+ public void setCompleteListener(CompleteListener completeListener) {
+
+ this.completeListener = completeListener;
+ suggestBox.addEventHandler(new SuggestionHandler() {
+
+ public void onSuggestionSelected(SuggestionEvent event) {
+ System.out.println("On Suggestion Selected! "
+ + event.getSelectedSuggestion()
+ .getReplacementString());
+
+ // Important, this prevents duplications
+ if (keyboardEnterTimer != null) {
+ keyboardEnterTimer.cancel();
+ }
+
+ complete(event.getSelectedSuggestion()
+ .getReplacementString());
+ }
+ });
+
+ suggestBox.addKeyboardListener(new KeyboardListenerAdapter() {
+ // @Override
+ public void onKeyPress(Widget sender, char keyCode,
+ int modifiers) {
+ if (keyCode == KEY_ENTER) {
+
+ keyboardEnterTimer = new Timer() {
+ // @Override
+ public void run() {
+ complete(suggestBox.getText());
+ }
+ };
+ keyboardEnterTimer.schedule(400);
+ }
+ }
+ });
+
+ }
+
+ /**
+ * public so we can call this at any time
+ */
+ public void complete() {
+ complete(suggestBox.getText());
+ }
+
+ /**
+ * Careful to prevent dupes, one from enter key keyboard listener, one
+ * from the enter key selecting a suggestion. We need the keyboard
+ * listener because we want the enter key to add the current text when
+ * there's no suggestion.
+ *
+ * @param completeStr
+ */
+ private void complete(final String completeStr) {
+
+ System.out.println("TopicCompleter:" + completeStr + " ");
+
+ oracle.getSchoolsForString(completeStr,
+ new EZCallback<List<School>>() {
+
+ public void onSuccess(List<School> result) {
+ completeListener.completed(result.get(0));
+ suggestBox.setText("");
+ }
+ });
+
+ }
+
+ public void setText(String string) {
+ suggestBox.setText(string);
+ }
+
+ public String getText() {
+ return suggestBox.getText();
+ }
+
+ public void setFocus(final boolean b) {
+ DeferredCommand.addCommand(new Command() {
+ public void execute() {
+ suggestBox.setFocus(b);
+ }
+ });
+
+ }
+}
Oops, something went wrong.

0 comments on commit 765143a

Please sign in to comment.