001: /*
002: * Copyright 2007 Giordano Maestro (giordano.maestro@assetdata.it)
003: *
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
006: * use this file except in compliance with the License.
007: *
008: * You may obtain a copy of the License at
009: * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
010: * or agreed to in writing, software distributed under the License is
011: * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
012: * KIND, either express or implied. See the License for the specific language
013: * governing permissions and limitations under the License.
014: */
015: package org.romaframework.module.designer.view.domain.radpage.aspect;
016:
017: import java.util.ArrayList;
018: import java.util.Arrays;
019: import java.util.Collection;
020: import java.util.HashMap;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Map.Entry;
024:
025: import org.romaframework.aspect.core.CoreAspect;
026: import org.romaframework.aspect.core.annotation.AnnotationConstants;
027: import org.romaframework.aspect.view.annotation.ViewAction;
028: import org.romaframework.aspect.view.annotation.ViewField;
029: import org.romaframework.core.domain.wrapper.OrderMemberWrapper;
030: import org.romaframework.core.schema.SchemaFeatures;
031: import org.romaframework.module.designer.DesignerHelper;
032: import org.romaframework.module.designer.domain.RadAction;
033: import org.romaframework.module.designer.domain.RadField;
034: import org.romaframework.module.designer.domain.RadMember;
035: import org.romaframework.module.designer.view.domain.FeatureListable;
036:
037: public class CoreAspectPage extends FeatureAspectPage {
038: private Collection<RadField> fields;
039: private OrderMemberWrapper<RadField> fieldsWrapper;
040: @ViewField(visible=AnnotationConstants.FALSE)
041: private Collection<RadField> orderedFields;
042: private Collection<RadAction> actions;
043: private OrderMemberWrapper<RadAction> actionsWrapper;
044: @ViewField(visible=AnnotationConstants.FALSE)
045: private Collection<RadAction> orderedActions;
046:
047: public CoreAspectPage(SchemaFeatures iActualFeature,
048: Collection<RadField> iFields, Collection<RadAction> iActions) {
049: super (CoreAspect.ASPECT_NAME, iActualFeature
050: .getFeatures(CoreAspect.ASPECT_NAME));
051: fields = iFields;
052: actions = iActions;
053: configurable = fillConfigurable(fields, actions);
054: }
055:
056: @Override
057: protected List<FeatureListable> fillConfigurable() {
058: return new ArrayList<FeatureListable>();
059: }
060:
061: protected List<FeatureListable> fillConfigurable(
062: Collection<RadField> fields, Collection<RadAction> actions) {
063: List<FeatureListable> result = new ArrayList<FeatureListable>();
064: if (actualFeature.getAttributes() != null) {
065: for (Entry<String, Object> entry : actualFeature
066: .getAttributes().entrySet()) {
067: if (entry.getKey().equals("embedded")
068: || entry.getKey().equals("useRuntimeType")) {
069: result.add(new FeatureListable(entry.getKey(),
070: DesignerHelper
071: .getBooleanWrapper((Boolean) entry
072: .getValue())));
073: } else if (entry.getKey().equals("orderFields")) {
074: if (fields != null) {
075: fieldsWrapper = new OrderMemberWrapper(fields);
076: result.add(new FeatureListable(entry.getKey(),
077: fieldsWrapper));
078: }
079: } else if (entry.getKey().equals("orderActions")) {
080: if (actions != null) {
081: actionsWrapper = new OrderMemberWrapper(actions);
082: result.add(new FeatureListable(entry.getKey(),
083: actionsWrapper));
084: }
085: }
086: }
087: }
088: return result;
089: }
090:
091: private Collection<String> fillWrapper(String iOrder,
092: Collection<? extends RadMember> iMembers) {
093: if (iOrder == null) {
094: return membersToString(iMembers);
095: } else if (iOrder.trim().equals("")) {
096: return membersToString(iMembers);
097: } else {
098: List<String> values = new ArrayList<String>();
099: values.addAll(Arrays.asList(iOrder.split("\\p{Space}++")));
100: for (RadMember member : iMembers) {
101: if (member != null
102: && !values.contains(member.toString())) {
103: values.add(member.toString());
104: }
105: }
106: return values;
107: }
108: }
109:
110: private Collection<String> membersToString(
111: Collection<? extends RadMember> iMembers) {
112: Collection<String> result = new ArrayList<String>();
113: if (iMembers != null) {
114: for (RadMember member : iMembers) {
115: if (member != null) {
116: result.add(member.toString());
117: }
118: }
119: }
120: return result;
121: }
122:
123: @Override
124: @ViewAction(visible=AnnotationConstants.FALSE)
125: public final void apply() throws Exception {
126: super .apply();
127: if (fieldsWrapper != null) {
128: orderedFields = (Collection<RadField>) fieldsWrapper
129: .getFinalValue();
130: }
131: if (actionsWrapper != null) {
132: orderedActions = (Collection<RadAction>) actionsWrapper
133: .getFinalValue();
134: }
135: }
136:
137: public Collection<RadField> getOrderedFields() {
138: return orderedFields;
139: }
140:
141: public Collection<RadAction> getOrderedActions() {
142: return orderedActions;
143: }
144:
145: @Override
146: public Map<String, Object> getDefaultValues() {
147: /***************************************************************************
148: * Init core values
149: **************************************************************************/
150: Map<String, Object> defaultCoreValues = new HashMap<String, Object>();
151: defaultCoreValues.put("embeddedType", "");
152: defaultCoreValues.put("embedded", Boolean.FALSE);
153: defaultCoreValues.put("useRuntimeType", Boolean.FALSE);
154: return defaultCoreValues;
155: }
156: }
|