001: /*
002: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: *
007: * You may obtain a copy of the License at
008: * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
009: * or agreed to in writing, software distributed under the License is
010: * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
011: * KIND, either express or implied. See the License for the specific language
012: * governing permissions and limitations under the License.
013: */
014: package org.romaframework.module.designer.view.domain;
015:
016: import java.util.ArrayList;
017: import java.util.Collection;
018: import java.util.Collections;
019:
020: import org.romaframework.aspect.core.annotation.AnnotationConstants;
021: import org.romaframework.aspect.core.annotation.CoreClass;
022: import org.romaframework.aspect.view.ViewAspect;
023: import org.romaframework.aspect.view.ViewCallback;
024: import org.romaframework.aspect.view.annotation.ViewAction;
025: import org.romaframework.aspect.view.annotation.ViewField;
026: import org.romaframework.aspect.view.feature.ViewElementFeatures;
027: import org.romaframework.core.config.Refreshable;
028: import org.romaframework.core.config.RomaApplicationContext;
029: import org.romaframework.core.domain.message.MessageOk;
030: import org.romaframework.core.flow.ObjectContext;
031: import org.romaframework.core.schema.SchemaClass;
032: import org.romaframework.core.schema.SchemaManager;
033: import org.romaframework.core.serializer.RomaSerializationException;
034: import org.romaframework.core.validation.CustomValidation;
035: import org.romaframework.core.validation.ValidationException;
036: import org.romaframework.module.designer.domain.RadClass;
037: import org.romaframework.module.designer.view.domain.radpage.ClassAspectsPage;
038: import org.romaframework.module.designer.view.domain.radpage.RootClassAspectsPage;
039:
040: /**
041: * GUI to manage domain entities.
042: *
043: * @author Luca Garulli (luca.garulli@assetdata.it)
044: */
045: @CoreClass(orderFields="entity availableClassNames functions",orderActions="save edit preview")
046: public class SchemaViewInstance implements CustomValidation,
047: ViewCallback, Refreshable {
048: @ViewField(selectionField="selectedAvailableClassName",enabled=AnnotationConstants.FALSE)
049: protected ArrayList<String> availableClassNames;
050: protected SchemaClass selectedAvailableClass;
051: protected String search;
052: protected boolean applicationDomainOnly = true;
053:
054: public SchemaViewInstance() {
055: loadClasses();
056: }
057:
058: /**
059: * Load all the classes in the schema manager
060: *
061: */
062: private void loadClasses() {
063: selectedAvailableClass = null;
064: // search = "";
065:
066: SchemaManager schemaMgr = ObjectContext.getInstance()
067: .getComponent(SchemaManager.class);
068: Collection<SchemaClass> infos = schemaMgr.getAllClassesInfo();
069: availableClassNames = new ArrayList<String>();
070: if (!isApplicationDomainOnly()) {
071: for (SchemaClass cls : infos) {
072: availableClassNames.add(cls.getName());
073: }
074: } else {
075: for (SchemaClass cls : infos) {
076: String packageApp = RomaApplicationContext
077: .getInstance().getApplicationPackage();
078: String classPackage = cls.getClazz().getPackage()
079: .getName();
080: if (classPackage.startsWith(packageApp)) {
081: availableClassNames.add(cls.getName());
082: }
083: }
084: }
085: Collections.sort(availableClassNames);
086: ObjectContext.getInstance()
087: .refresh(this , "availableClassNames");
088:
089: }
090:
091: public void onShow() {
092: loadClasses();
093: }
094:
095: /**
096: * Load a class given the name.
097: *
098: */
099: public void load() {
100: try {
101: ObjectContext.getInstance().getComponent(
102: SchemaManager.class).getClassInfo(search);
103: setSelectedAvailableClassName(search);
104: loadClasses();
105: ObjectContext.getInstance().refresh(this ,
106: "availableClassNames");
107: ObjectContext.getInstance().show(
108: new MessageOk("", "", null,
109: "The Class is now available in list!"));
110:
111: //setSelectedAvailableClassName(search);
112: //edit();
113:
114: //
115:
116: } catch (Exception e) {
117: ObjectContext.getInstance().show(
118: new MessageOk("", "", null, "Class not found"));
119: }
120: }
121:
122: public void setSelectedAvailableClassName(String iSelection) {
123: ObjectContext.getInstance().setActionFeature(this ,
124: ViewAspect.ASPECT_NAME, "preview",
125: ViewElementFeatures.VISIBLE, iSelection != null);
126: selectedAvailableClass = ObjectContext.getInstance()
127: .getComponent(SchemaManager.class).getClassInfo(
128: iSelection.toString());
129: ObjectContext.getInstance()
130: .refresh(this , "availableClassNames");
131:
132: search = iSelection.toString();
133: ObjectContext.getInstance().refresh(this , "search");
134: }
135:
136: @ViewField(visible=AnnotationConstants.FALSE)
137: public String getSelectedAvailableClassName() {
138: if (selectedAvailableClass != null) {
139: return selectedAvailableClass.getName();
140: }
141: return null;
142: }
143:
144: public void validate() throws ValidationException {
145: }
146:
147: public ArrayList<String> getAvailableClassNames() {
148: return availableClassNames;
149: }
150:
151: public void setAvailableClassNames(
152: ArrayList<String> availableClassNames) {
153: this .availableClassNames = availableClassNames;
154: }
155:
156: public void edit() throws RomaSerializationException {
157: if (selectedAvailableClass == null)
158: return;
159:
160: RadClass clazz;
161: try {
162: clazz = new RadClass(selectedAvailableClass);
163: } catch (CloneNotSupportedException e) {
164: throw new RuntimeException(e.getMessage(), e);
165: }
166: ClassAspectsPage pageToShow = new RootClassAspectsPage(clazz);
167: pageToShow.setBackObject(this );
168: ObjectContext.getInstance().show(pageToShow);
169: }
170:
171: public void onDispose() {
172: }
173:
174: public String getSearch() {
175: return search;
176: }
177:
178: public void setSearch(String search) {
179: this .search = search;
180: }
181:
182: @ViewAction(visible=AnnotationConstants.FALSE)
183: public void refresh() {
184: loadClasses();
185: ObjectContext.getInstance()
186: .refresh(this , "availableClassNames");
187: ObjectContext.getInstance().refresh(this , "search");
188: }
189:
190: @ViewAction(visible=AnnotationConstants.FALSE)
191: public void clean() {
192: loadClasses();
193: selectedAvailableClass = null;
194: search = null;
195:
196: ObjectContext.getInstance().refresh(this ,
197: "selectedAvailableClassNames");
198: ObjectContext.getInstance()
199: .refresh(this , "availableClassNames");
200: ObjectContext.getInstance().refresh(this , "search");
201: }
202:
203: public boolean isApplicationDomainOnly() {
204: return applicationDomainOnly;
205: }
206:
207: public void setApplicationDomainOnly(boolean applicationDomainOnly) {
208: this.applicationDomainOnly = applicationDomainOnly;
209: loadClasses();
210: ObjectContext.getInstance().show(this);
211: }
212:
213: }
|