Skip to content

Commit

Permalink
Refinements in the eventhings port. Created some more bridge classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tuhlmann committed Feb 22, 2011
1 parent c75ef7b commit 1d1aae1
Show file tree
Hide file tree
Showing 67 changed files with 3,717 additions and 85 deletions.
26 changes: 26 additions & 0 deletions project/build/LiftProject.scala
@@ -0,0 +1,26 @@
import sbt._

class LiftProject(info: ProjectInfo) extends DefaultWebProject(info) {
val liftVersion = "2.3-SNAPSHOT"

// uncomment the following if you want to use the snapshot repo
val scalatoolsSnapshot = ScalaToolsSnapshots

// val localMaven = "local maven" at "file:///home/dpp/.m2/repository"

// If you're using JRebel for Lift development, uncomment
// this line
// override def scanDirectories = Nil

override def libraryDependencies = Set(
"net.liftweb" %% "lift-webkit" % liftVersion % "compile->default",
"net.liftweb" %% "lift-wizard" % liftVersion % "compile->default",
"org.mortbay.jetty" % "jetty" % "6.1.22" % "test->default",
"junit" % "junit" % "4.5" % "test->default",
"ch.qos.logback" % "logback-classic" % "0.9.26",
"org.scala-tools.testing" %% "specs" % "1.6.6" % "test->default",
"com.h2database" % "h2" % "1.2.138"
) ++ super.libraryDependencies


}
4 changes: 4 additions & 0 deletions src/main/java/bootstrap/liftweb/Boot.java
Expand Up @@ -2,6 +2,10 @@


import net.liftweb.http.*;
import net.liftweb.http.Html5Properties;
import net.liftweb.http.HtmlProperties;
import net.liftweb.http.LiftRulesJ;
import net.liftweb.http.Req;
import net.liftweb.http.js.JsCmd;
import net.liftweb.http.provider.HTTPRequest;
import net.liftweb.sitemap.Menu;
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/liftweb/seventhings/lib/HelpersJ.java
@@ -1,13 +1,11 @@
package net.liftweb.seventhings.lib;

import net.liftweb.util.Helpers;
import net.liftweb.util.Helpers$;

public class HelpersJ {

private final static Helpers$ j = Helpers$.MODULE$;
private final static HelpersJBridge j = new HelpersJBridge();

public final static Helpers$ j() {
public final static HelpersJBridge j() {
return j;
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/liftweb/seventhings/lib/ListJ.java
@@ -1,11 +1,20 @@
package net.liftweb.seventhings.lib;

import scala.collection.Seq;
import scala.collection.mutable.ListBuffer;

public class ListJ {

public static Seq Nil() {
return scala.collection.immutable.Nil$.MODULE$;
}

public static Seq toSeq(Object... obj) {
ListBuffer buf = new ListBuffer();
for (Object o : obj) {
buf.$plus$eq(o);
}
return buf.toSeq();
}

}
79 changes: 79 additions & 0 deletions src/main/java/net/liftweb/seventhings/lib/Matcher.java
@@ -0,0 +1,79 @@
package net.liftweb.seventhings.lib;

import scala.PartialFunction;

import java.util.List;
import java.util.Collections;
import java.util.Arrays;

interface MatchClause<T> {
public boolean test (T subject);
public Object apply(T subject);
}

interface F0V { //extends PartialFunction<Void, Object> {
public Object apply();
}


class Matcher<T> {

private final List<MatchClause<T>> matchers;

public static <T> Matcher<T> matcher(MatchClause<T>... matchers) {
return new Matcher<T>(matchers);
}

public Matcher(MatchClause<T>... matchers) {
this.matchers = Collections.unmodifiableList(Arrays.asList(matchers));
}

public F0V match(final T subject) {
return new F0V() {
public Object apply() {
for(MatchClause<T> matcher: matchers) {
if(matcher.test(subject)) {
return matcher.apply(subject);
}
}
return null; // TODO should return Empty
}
};
}

}

/*
class liftjmatch {
public static void main(String[] args) {
final MatchClause<Object> mString = new MatchClause<Object>() {
public boolean test(Object x) { return x instanceof String; }
public void apply(Object x) { System.out.println("String: " + x); }
};
final MatchClause<Object> mInteger = new MatchClause<Object>() {
public boolean test(Object x) { return x instanceof Integer; }
public void apply(Object x) { System.out.println("Integer: " + x); }
};
final MatchClause<Object> mOther = new MatchClause<Object>() {
public boolean test(Object x) { return true; }
public void apply(Object x) { System.out.println("Other: " + x); }
};
Matcher<Object> m = Matcher.matcher(
mString,
mInteger,
mOther
);
m.match("Hello World").apply();
m.match(1).apply();
}
}
*/

15 changes: 4 additions & 11 deletions src/main/java/net/liftweb/seventhings/snippet/LongTime.java
@@ -1,5 +1,7 @@
package net.liftweb.seventhings.snippet;

import net.liftweb.http.SHtmlJ;
import net.liftweb.seventhings.lib.HelpersJ;
import net.liftweb.util.Css;
import net.liftweb.util.Helpers;
import scala.Function1;
Expand All @@ -14,23 +16,14 @@
*/
public class LongTime {

SecureRandom _random = new SecureRandom();

long randomLong(long mod) {
synchronized (_random) {
return Math.abs(_random.nextLong()) % mod;
}
}

public Function1<NodeSeq, NodeSeq> render() {

// capture the start time
//Date start = HelpersJ.j().now();
Date start = new Date();
Date start = HelpersJ.j().now();

// sleep for up to 15 seconds
try {
Thread.sleep(randomLong(15000));
Thread.sleep(HelpersJ.j().randomLong(15000));
} catch (InterruptedException IGNORE) {
}

Expand Down
82 changes: 82 additions & 0 deletions src/main/java/net/liftweb/seventhings/snippet/MyWizard.java
@@ -0,0 +1,82 @@
package net.liftweb.seventhings.snippet;

import net.liftweb.http.AbstractScreen;
import net.liftweb.http.SJ;
import net.liftweb.http.js.JsCmd;
import net.liftweb.http.js.jquery.JqJsCmds;
import net.liftweb.seventhings.lib.JqJsCmdsJ;
import net.liftweb.seventhings.lib.ListJ;
import net.liftweb.seventhings.lib.WizardJ;
import net.liftweb.util.Func;
import net.liftweb.util.Func0;
import net.liftweb.wizard.Wizard;

/**
* An example of a wizard in Lift
*/
public class MyWizard extends WizardJ {

private MyWizardScala wizardScala = new MyWizardScala();

private final MyWizardScala.ParentNameScreen parentName;
private final MyWizardScala.FavoritePetScreen favoritePet;
private final MyWizardScala.NameAndAgeScreen nameAndAge;

public MyWizard() {
parentName = wizardScala.getParentName();
favoritePet = wizardScala.getFavoritePet();
nameAndAge = wizardScala.getNameAndAge();
}

public JsCmd calcAjaxOnDone() {
return JqJsCmdsJ.j().unblock();
}

// define the first screen

// We ask the parent's name if the person is under 18
// private WizardJ.ScreenJ parentNameObj = new WizardJ.ScreenJ() {
// String parentName = fieldj(SJ.j().$qmark("Mom or Dad's name"), ListJ.toSeq(
// valMinLen(Func.lift(new Func0<Integer>() {
// public Integer apply() {
// return 2;
// }
// }), Func.lift(new Func0<String>() {
// public String apply() {
// return SJ.j().$qmark("Name Too Short");
// }
// })),
// valMaxLen(Func.lift(new Func0<Integer>() {
// public Integer apply() {
// return 40;
// }
// }), Func.lift(new Func0<String>() {
// public String apply() {
// return SJ.j().$qmark("Name Too Long");
// }
// }))));
// };


// we ask for the favorite pet
// private WizardJ.Screen favoritePet = new WizardJ.Screen() {
// String petName = AbstractScreen.field(SJ.j().$qmark("Pet's name", "",
// AbstractScreen.valMinLen(2, SJ.j().$qmark("Name Too Short")),
// AbstractScreen.valMaxLen(40, SJ.j().$qmark("Name Too Long"))));
// };




// // what to do on completion of the wizard
// public void finish() {
// SJ.j().notice("Thank you for registering your pet: " +
// favoritePet.petName() +
// " your age * 3: " + nameAndAge.age() * 3);
// }

public void finish() {
wizardScala.finish();
}

}
66 changes: 0 additions & 66 deletions src/main/java/net/liftweb/seventhings/snippet/MyWizardJava.java

This file was deleted.

0 comments on commit 1d1aae1

Please sign in to comment.