001: package org.romaframework.module.admin.view.domain.activesession;
002:
003: import org.romaframework.aspect.core.annotation.AnnotationConstants;
004: import org.romaframework.aspect.core.annotation.CoreClass;
005: import org.romaframework.aspect.view.ViewAspect;
006: import org.romaframework.aspect.view.ViewCallback;
007: import org.romaframework.aspect.view.ViewConstants;
008: import org.romaframework.aspect.view.annotation.ViewAction;
009: import org.romaframework.aspect.view.annotation.ViewClass;
010: import org.romaframework.aspect.view.feature.ViewElementFeatures;
011: import org.romaframework.aspect.view.page.EntityPage;
012: import org.romaframework.core.domain.message.MessageOk;
013: import org.romaframework.core.entity.EntityHelper;
014: import org.romaframework.core.exception.UserException;
015: import org.romaframework.core.flow.ObjectContext;
016: import org.romaframework.core.schema.SchemaClassResolver;
017:
018: @CoreClass(orderActions="createValue resetValueToNull save")
019: @ViewClass(entity=SessionAttributeInfo.class,render=ViewConstants.RENDER_POPUP,layout="popup")
020: public class SessionAttributeInfoInstance extends
021: EntityPage<SessionAttributeInfo> implements ViewCallback {
022: protected String type;
023: protected boolean saved;
024:
025: public SessionAttributeInfoInstance() {
026: super (null);
027: }
028:
029: public SessionAttributeInfoInstance(SessionAttributeInfo iEntity) {
030: super (iEntity);
031: }
032:
033: public void onShow() {
034: saved = entity.getName().length() > 0;
035:
036: type = entity.getType();
037: Object value = entity.getValue();
038: if (value != null) {
039: ObjectContext.getInstance().getFieldFeatures(this ,
040: ViewAspect.ASPECT_NAME, "entity.type")
041: .setAttribute(ViewElementFeatures.ENABLED,
042: Boolean.FALSE);
043: }
044: }
045:
046: public void onDispose() {
047: }
048:
049: public void createValue() {
050: if (entity.getValue() != null) {
051: ObjectContext
052: .getInstance()
053: .show(
054: new MessageOk("alert", "Alert", null,
055: "Cannot create a new object: object already existent!"));
056: return;
057: }
058:
059: if (type == null || type.length() == 0) {
060: ObjectContext
061: .getInstance()
062: .show(
063: new MessageOk(
064: "alert",
065: "Alert",
066: null,
067: "Please specify a 'Type' of object to create. 'Type' is the full class name with package."));
068: return;
069: }
070:
071: try {
072: Class cls = ObjectContext.getInstance().getComponent(
073: SchemaClassResolver.class).getEntityClass(type);
074:
075: if (cls == null)
076: cls = Class.forName(type);
077:
078: entity.setValue(EntityHelper.createObject(null, cls));
079: } catch (Exception e) {
080: throw new UserException(entity, "Error on creating object",
081: e);
082: }
083:
084: ObjectContext.getInstance().refresh(this , "entity");
085: }
086:
087: public void resetValueToNull() {
088: if (entity.getValue() == null) {
089: ObjectContext.getInstance().show(
090: new MessageOk("alert", "Alert", null,
091: "Value is already null!"));
092: return;
093: }
094: entity.setValue(null);
095:
096: ObjectContext.getInstance().refresh(this , "entity");
097: }
098:
099: @ViewAction(bind=AnnotationConstants.TRUE)
100: public void save() {
101: ObjectContext.getInstance().close(this );
102: }
103:
104: public String getType() {
105: return type;
106: }
107:
108: public void setType(String type) {
109: this.type = type;
110: }
111: }
|