001: /*
002: * Copyright 2006 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.module.crud;
018:
019: import org.romaframework.aspect.view.page.CallerHandler;
020: import org.romaframework.core.binding.Bindable;
021: import org.romaframework.core.entity.ComposedEntity;
022: import org.romaframework.core.flow.ObjectContext;
023:
024: /**
025: * Helper class to resolve common CRUD tasks.
026: *
027: * @author Luca Garulli (luca.garulli@assetdata.it)
028: *
029: */
030: public class CRUDHelper {
031: /**
032: * Show the form of the class specified.
033: *
034: * @param <T>
035: * Selection form
036: * @param iClass
037: * @param iEntityInstance
038: * @return
039: */
040: public static <T extends ComposedEntity> T show(Class<T> iClass,
041: Object iEntityInstance) {
042: // GET THE FORM
043: T formObject = ObjectContext.getInstance().getObject(iClass,
044: iEntityInstance);
045:
046: // SHOW THE FORM
047: ObjectContext.getInstance().show(formObject);
048:
049: // RETURN IT TO THE CALLER TO SET ADDITIONAL INFO
050: return formObject;
051: }
052:
053: /**
054: * Show the form of the class specified.
055: *
056: * @param <T>
057: * Selection form
058: * @param iClass
059: * @param iSourceObject
060: * @param iSourceFieldName
061: * @return
062: */
063: public static <T extends Bindable> T show(Class<T> iClass,
064: Object iSourceObject, String iSourceFieldName) {
065: // GET THE FORM
066: return show(iClass, iSourceObject, iSourceFieldName, null);
067: }
068:
069: /**
070: * Show the form of the class specified.
071: *
072: * @param <T>
073: * Selection form
074: * @param iClass
075: * @param iSourceObject
076: * @param iSourceFieldName
077: * @param iCaller
078: * @return
079: */
080: public static <T extends Bindable> T show(Class<T> iClass,
081: Object iSourceObject, String iSourceFieldName,
082: Object iCaller) {
083: // GET THE FORM
084: T formObject = ObjectContext.getInstance().getObject(iClass);
085:
086: if (formObject instanceof CallerHandler && iCaller != null)
087: ((CallerHandler) formObject).setBackObject(iCaller);
088:
089: return (T) show(formObject, iSourceObject, iSourceFieldName);
090: }
091:
092: /**
093: * Show the form specified.
094: *
095: * @param iSelectObj
096: * @param iSourceObject
097: * @param iSourceFieldName
098: * @return
099: */
100: public static Bindable show(Bindable iSelectObj,
101: Object iSourceObject, String iSourceFieldName) {
102: // GET SOURCE INFO
103: iSelectObj.setSource(iSourceObject, iSourceFieldName);
104:
105: // SHOW THE FORM
106: ObjectContext.getInstance().show(iSelectObj,
107: "screen:popup:" + iSelectObj);
108:
109: // RETURN IT TO THE CALLER TO SET ADDITIONAL INFO
110: return iSelectObj;
111: }
112:
113: }
|