01: /*
02: *
03: * Copyright 2007 Luca Molino (luca.molino@assetdata.it)
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.romaframework.module.users.view.domain.account;
18:
19: import org.romaframework.aspect.core.annotation.AnnotationConstants;
20: import org.romaframework.aspect.i18n.I18NAspect;
21: import org.romaframework.aspect.view.annotation.ViewField;
22: import org.romaframework.core.binding.Bindable;
23: import org.romaframework.core.domain.page.ContainerPage;
24: import org.romaframework.core.flow.ObjectContext;
25: import org.romaframework.core.schema.SchemaClass;
26: import org.romaframework.core.schema.SchemaField;
27: import org.romaframework.core.schema.SchemaManager;
28: import org.romaframework.module.crud.CRUDException;
29: import org.romaframework.module.users.view.domain.baseaccount.BaseAccountSelect;
30: import org.romaframework.module.users.view.domain.basegroup.BaseGroupSelect;
31:
32: /**
33: * @author l.molino
34: *
35: */
36: public class AccountSelect extends ContainerPage implements Bindable {
37:
38: protected Object sourceObject;
39:
40: protected SchemaField sourceField;
41:
42: public AccountSelect() {
43: innerPages.put((ObjectContext.getInstance()
44: .getComponent(I18NAspect.class))
45: .getString("AccountSelect.baseaccount.label"),
46: new BaseAccountSelect());
47: innerPages.put((ObjectContext.getInstance()
48: .getComponent(I18NAspect.class))
49: .getString("AccountSelect.basegroup.label"),
50: new BaseGroupSelect());
51: }
52:
53: @ViewField(visible=AnnotationConstants.FALSE)
54: public SchemaField getSourceField() {
55: return sourceField;
56: }
57:
58: @ViewField(visible=AnnotationConstants.FALSE)
59: public Object getSourceObject() {
60: return sourceObject;
61: }
62:
63: public void setSource(Object iSourceObject, String iSourceFieldName) {
64: BaseAccountSelect companies = (BaseAccountSelect) innerPages
65: .get((ObjectContext.getInstance()
66: .getComponent(I18NAspect.class))
67: .getString("AccountSelect.baseaccount.label"));
68: companies.setSource(iSourceObject, iSourceFieldName);
69: BaseGroupSelect individuals = (BaseGroupSelect) innerPages
70: .get((ObjectContext.getInstance()
71: .getComponent(I18NAspect.class))
72: .getString("AccountSelect.basegroup.label"));
73: individuals.setSource(iSourceObject, iSourceFieldName);
74: sourceObject = iSourceObject;
75:
76: // ASSIGN OBJECT SCHEMA FIELD
77: SchemaClass cls = ObjectContext.getInstance().getComponent(
78: SchemaManager.class).getClassInfo(
79: iSourceObject.getClass().getSimpleName());
80: sourceField = cls.getField(iSourceFieldName);
81:
82: if (sourceField == null)
83: throw new CRUDException("Cannot find field name "
84: + iSourceObject.getClass().getSimpleName() + "."
85: + iSourceFieldName + ". Check class definition");
86: }
87:
88: public void close() {
89: ObjectContext.getInstance().close(this);
90: }
91:
92: }
|