Skip to content

Commit

Permalink
Adjusted the built-in and demo screens to the new GUI component design.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Jul 1, 2015
1 parent 9be77e6 commit b75ed59
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
Expand Up @@ -23,23 +23,19 @@
import org.rapidoid.annotation.Authors; import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.plugins.DB; import org.rapidoid.plugins.DB;
import org.rapidoid.plugins.Entities;


@Authors("Nikolche Mihajlovski") @Authors("Nikolche Mihajlovski")
@Since("3.0.0") @Since("3.0.0")
public abstract class AbstractEntityScreenGeneric extends Screen { public abstract class AbstractEntityScreenGeneric extends Screen {


protected final Class<?> entityType; protected final Class<?> entityType;


protected final Object entity;

public AbstractEntityScreenGeneric(Class<?> entityType) { public AbstractEntityScreenGeneric(Class<?> entityType) {
this.entityType = entityType; this.entityType = entityType;
this.entity = Entities.create(entityType);
} }


@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T> T entity() { protected <T> T getEntityById() {
String id = ctx().pathSegment(1); String id = ctx().pathSegment(1);
Object entity = DB.getIfExists(entityType, id); Object entity = DB.getIfExists(entityType, id);


Expand All @@ -52,7 +48,7 @@ protected <T> T entity() {


@Override @Override
public String toString() { public String toString() {
return "AbstractEntityScreenGeneric [entityType=" + entityType + ", entity=" + entity + "]"; return "AbstractEntityScreenGeneric [entityType=" + entityType + "]";
} }


} }
Expand Up @@ -21,7 +21,6 @@
*/ */


import org.rapidoid.annotation.Authors; import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Session;
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.html.Tag; import org.rapidoid.html.Tag;
import org.rapidoid.plugins.DB; import org.rapidoid.plugins.DB;
Expand All @@ -32,24 +31,23 @@
@Since("2.0.0") @Since("2.0.0")
public class EditEntityScreenGeneric extends AbstractEntityScreenGeneric { public class EditEntityScreenGeneric extends AbstractEntityScreenGeneric {


@Session private Object entity;
private Object target;


public EditEntityScreenGeneric(Class<?> entityType) { public EditEntityScreenGeneric(Class<?> entityType) {
super(entityType); super(entityType);
} }


public Object content() { public Object content() {
target = entity(); this.entity = getEntityById();


Tag caption = h2("Edit " + U.capitalized(ctx().pathSegment(0).substring(4))); Tag caption = h2("Edit " + U.capitalized(ctx().pathSegment(0).substring(4)));
FormWidget form = edit(target).buttons(SAVE, CANCEL); FormWidget form = edit(entity).buttons(SAVE, CANCEL);


return mid6(caption, form); return mid6(caption, form);
} }


public void onSave() { public void onSave() {
DB.update(target); DB.update(entity);
ctx().goBack(1); ctx().goBack(1);
} }


Expand Down
Expand Up @@ -24,15 +24,19 @@
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.html.Tag; import org.rapidoid.html.Tag;
import org.rapidoid.plugins.DB; import org.rapidoid.plugins.DB;
import org.rapidoid.plugins.Entities;
import org.rapidoid.util.U; import org.rapidoid.util.U;
import org.rapidoid.widget.FormWidget; import org.rapidoid.widget.FormWidget;


@Authors("Nikolche Mihajlovski") @Authors("Nikolche Mihajlovski")
@Since("2.1.0") @Since("2.1.0")
public class NewEntityScreenGeneric extends AbstractEntityScreenGeneric { public class NewEntityScreenGeneric extends AbstractEntityScreenGeneric {


private Object entity;

public NewEntityScreenGeneric(Class<?> entityType) { public NewEntityScreenGeneric(Class<?> entityType) {
super(entityType); super(entityType);
this.entity = Entities.create(entityType);
} }


public Object content() { public Object content() {
Expand Down
Expand Up @@ -21,7 +21,6 @@
*/ */


import org.rapidoid.annotation.Authors; import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Session;
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.cls.Cls; import org.rapidoid.cls.Cls;
import org.rapidoid.html.Tag; import org.rapidoid.html.Tag;
Expand All @@ -35,21 +34,20 @@
@Since("2.0.0") @Since("2.0.0")
public class ViewEntityScreenGeneric extends AbstractEntityScreenGeneric { public class ViewEntityScreenGeneric extends AbstractEntityScreenGeneric {


private Object entity;

public ViewEntityScreenGeneric(Class<?> entityType) { public ViewEntityScreenGeneric(Class<?> entityType) {
super(entityType); super(entityType);
} }


@Session
private Object target;

public Object content() { public Object content() {
target = entity(); this.entity = getEntityById();


Tag caption = h2(U.capitalized(ctx().pathSegment(0)) + " Details").style("margin-bottom:15px;"); Tag caption = h2(U.capitalized(ctx().pathSegment(0)) + " Details").style("margin-bottom:15px;");
FormWidget details = show(target); FormWidget details = show(entity);


ButtonWidget btnEdit = Secure.canUpdate(Secure.username(), target) ? EDIT : null; ButtonWidget btnEdit = Secure.canUpdate(Secure.username(), entity) ? EDIT : null;
ButtonWidget btnDelete = Secure.canDelete(Secure.username(), target) ? DELETE : null; ButtonWidget btnDelete = Secure.canDelete(Secure.username(), entity) ? DELETE : null;


details = details.buttons(btnEdit, BACK, btnDelete); details = details.buttons(btnEdit, BACK, btnDelete);


Expand All @@ -58,7 +56,7 @@ public Object content() {


public void onEdit() { public void onEdit() {
String id = ctx().pathSegment(1); String id = ctx().pathSegment(1);
ctx().redirect("/edit" + Cls.entityName(target).toLowerCase() + "/" + id); ctx().redirect("/edit" + Cls.entityName(entity).toLowerCase() + "/" + id);
} }


public void onDelete() { public void onDelete() {
Expand Down
Expand Up @@ -23,8 +23,8 @@
import java.util.List; import java.util.List;


import org.rapidoid.annotation.Authors; import org.rapidoid.annotation.Authors;
import org.rapidoid.annotation.Local;
import org.rapidoid.annotation.Order; import org.rapidoid.annotation.Order;
import org.rapidoid.annotation.Session;
import org.rapidoid.annotation.Since; import org.rapidoid.annotation.Since;
import org.rapidoid.annotation.Transaction; import org.rapidoid.annotation.Transaction;
import org.rapidoid.app.Screen; import org.rapidoid.app.Screen;
Expand All @@ -43,16 +43,13 @@
@Since("2.0.0") @Since("2.0.0")
public class NewTaskScreen extends Screen { public class NewTaskScreen extends Screen {


@Session
private Task task = new Task(); private Task task = new Task();


@Session @Local
private List<String> comments = U.list(); private List<String> comments = U.list();


@Session
private Var<String> v = var("abc"); private Var<String> v = var("abc");


@Session
private Var<List<String>> v2 = var("v2", U.list("b", "AA")); private Var<List<String>> v2 = var("v2", U.list("b", "AA"));


public Object content() { public Object content() {
Expand Down

0 comments on commit b75ed59

Please sign in to comment.