| /****************************************************************************** |
| * * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) * |
| * * |
| * All rights reserved. This program and the accompanying materials * |
| * are made available under the terms of the Eclipse Public License 2.0 * |
| * which accompanies this distribution, and is available at * |
| * https://www.eclipse.org/legal/epl-2.0/ * |
| * * |
| * SPDX-License-Identifier: EPL-2.0 * |
| * * |
| *============================================================================* |
| * Initial contribution: * |
| * Loetz GmbH & Co. KG * |
| * * |
| * generated by xtext * |
| ******************************************************************************/ |
| package org.eclipse.osbp.xtext.dialogdsl.jvmmodel |
| |
| import com.vaadin.ui.VerticalLayout |
| import java.util.Locale |
| import java.util.Map |
| import javax.inject.Inject |
| import org.eclipse.e4.core.contexts.IContextFunction |
| import org.eclipse.e4.core.contexts.IEclipseContext |
| import org.eclipse.e4.ui.model.application.MApplication |
| import org.eclipse.osbp.core.api.persistence.IPersistenceService |
| import org.eclipse.osbp.dsl.common.datatypes.IDto |
| import org.eclipse.osbp.dsl.semantic.entity.LEntity |
| import org.eclipse.osbp.ecview.semantic.uimodel.UiBeanSlot |
| import org.eclipse.osbp.ecview.semantic.uimodel.UiModel |
| import org.eclipse.osbp.ecview.semantic.uimodel.UiView |
| import org.eclipse.osbp.runtime.common.filter.IDTOServiceWithMutablePersistence |
| import org.eclipse.osbp.ui.api.contextfunction.IViewEmbeddedProvider |
| import org.eclipse.osbp.ui.api.customfields.IBlobService |
| import org.eclipse.osbp.ui.api.statemachine.IDataProvider |
| import org.eclipse.osbp.ui.api.statemachine.IPeripheral |
| import org.eclipse.osbp.ui.api.statemachine.IStateMachine |
| import org.eclipse.osbp.ui.api.statemachine.IStateMachineParticipant |
| import org.eclipse.osbp.ui.api.user.IUser |
| import org.eclipse.osbp.utils.annotation.CommonUtils |
| import org.eclipse.osbp.utils.common.EntityUtils |
| import org.eclipse.osbp.xtext.action.common.IToolbarAction |
| import org.eclipse.osbp.xtext.dialogdsl.Dialog |
| import org.eclipse.osbp.xtext.dialogdsl.DialogPackage |
| import org.eclipse.osbp.xtext.dialogdsl.common.AbstractECViewDialog |
| import org.eclipse.osbp.xtext.dialogdsl.common.AbstractEmbeddedDialog |
| import org.eclipse.osbp.xtext.dialogdsl.common.AbstractUIDialog |
| import org.eclipse.osbp.xtext.dialogdsl.constants.DialogConstants |
| import org.eclipse.osbp.xtext.dialogdsl.mapper.AutowireUiFactory |
| import org.eclipse.osbp.xtext.i18n.I18NKeyGenerator |
| import org.eclipse.osbp.xtext.strategy.jvmmodel.StrategyDSLFocusingEnhancerCreator |
| import org.eclipse.xtext.common.types.JvmDeclaredType |
| import org.eclipse.xtext.common.types.JvmField |
| import org.eclipse.xtext.common.types.JvmGenericType |
| import org.eclipse.xtext.common.types.JvmOperation |
| import org.eclipse.xtext.common.types.JvmType |
| import org.eclipse.xtext.common.types.JvmTypeReference |
| import org.eclipse.xtext.common.types.JvmVisibility |
| import org.eclipse.xtext.common.types.util.RawSuperTypes |
| import org.eclipse.xtext.naming.IQualifiedNameProvider |
| import org.eclipse.xtext.util.Strings |
| import org.eclipse.xtext.xbase.jvmmodel.IJvmDeclaredTypeAcceptor |
| import org.eclipse.xtext.xbase.jvmmodel.JvmAnnotationReferenceBuilder |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypeReferenceBuilder |
| import org.eclipse.xtext.xbase.jvmmodel.JvmTypesBuilder |
| import org.osgi.service.component.annotations.Component |
| import org.slf4j.Logger |
| import org.eclipse.osbp.ui.api.customfields.IBlobConverter |
| import org.eclipse.osbp.xtext.strategy.jvmmodel.StrategyDSLLayoutingStrategyCreator |
| import org.eclipse.osbp.runtime.common.annotations.DtoUtils |
| import org.eclipse.osbp.dsl.semantic.dto.LDtoInheritedAttribute |
| |
| /** |
| * Infers a JVM model from the source model. |
| * <p> |
| * The JVM model should contain all elements that would appear in the Java code |
| * which is generated from the source model. Other models link against the JVM model rather than the source model. |
| */ |
| class DialogDslVaaclipseViewCreator { |
| |
| /** |
| * convenience API to build and initialize JVM types and their members. |
| */ |
| @Inject extension JvmTypesBuilder |
| @Inject extension DialogConstants |
| @Inject extension IQualifiedNameProvider |
| @Inject extension StrategyDSLFocusingEnhancerCreator |
| @Inject extension StrategyDSLLayoutingStrategyCreator |
| @Inject extension CommonUtils |
| |
| private JvmAnnotationReferenceBuilder _annotationTypesBuilder; |
| private JvmTypeReferenceBuilder _typeReferenceBuilder; |
| |
| def void createVaaclipseUI(DialogPackage pckg, Dialog dialog, IJvmDeclaredTypeAcceptor acceptor, |
| JvmAnnotationReferenceBuilder annotationTypesBuilder, JvmTypeReferenceBuilder typeReferenceBuilder) { |
| _annotationTypesBuilder = annotationTypesBuilder |
| _typeReferenceBuilder = typeReferenceBuilder |
| var uiViewName = getUiName(dialog) |
| if (uiViewName !== null && !uiViewName.empty) { |
| var clsName = '''«dialog.fullyQualifiedName»«VAACLIPSE_VIEW_PREFIX»''' |
| if (dialog.embedded) { |
| clsName = '''«clsName»Embedded''' |
| } |
| var cls = dialog.toClass(clsName) |
| acceptor.accept(cls, |
| [ |
| if (dialog.embedded) { |
| superTypes += _typeReferenceBuilder.typeRef(AbstractEmbeddedDialog, |
| _typeReferenceBuilder.typeRef(getMainBeanslotType(dialog))) |
| superTypes += _typeReferenceBuilder.typeRef(IViewEmbeddedProvider) |
| } else if (dialog.stateful) { |
| superTypes += _typeReferenceBuilder.typeRef(AbstractUIDialog) |
| |
| }else { |
| superTypes += _typeReferenceBuilder.typeRef(AbstractECViewDialog, |
| _typeReferenceBuilder.typeRef(getMainBeanslotType(dialog))) |
| } |
| it.toConstructor(dialog) |
| it.toFields(dialog) |
| it.toOperations(dialog, pckg) |
| ]) |
| if (dialog.embedded) { |
| // the context function class |
| var contextClassName = '''«dialog.name»«VAACLIPSE_VIEW_PREFIX»EmbeddedContextFunction''' |
| val contextCls = pckg.toClass(contextClassName) |
| val dialogClsName = clsName |
| contextCls.getSuperTypes().add(_typeReferenceBuilder.typeRef(IContextFunction)) |
| contextCls.simpleName = contextCls.simpleName.toFirstUpper |
| acceptor.accept(contextCls, |
| [ |
| var annotationRef = _annotationTypesBuilder.annotationRef(Component) |
| annotationRef.addAnnAttr(dialog, "service", _typeReferenceBuilder.typeRef(IContextFunction) as JvmTypeReference) |
| var propContent = '''«IContextFunction.SERVICE_CONTEXT_KEY»=«dialog.name.toFirstUpper»''' |
| annotationRef.addAnnAttr(dialog, "property", propContent) |
| annotations += annotationRef |
| packageName = pckg.fullyQualifiedName.toString |
| it.toContextOperations(dialog, dialogClsName) |
| ]) |
| } |
| } |
| } |
| |
| def getMainBeanslotType(Dialog dialog) { |
| if(dialog.autowire) { |
| return AutowireUiFactory.getDtoFQN(dialog.dto) |
| }else{ |
| return dialog.mainBeanSlot?.jvmType.qualifiedName |
| } |
| } |
| |
| def getUiName(Dialog dialog) { |
| if(dialog.autowire) { |
| return AutowireUiFactory.getECViewId(dialog) |
| }else{ |
| return dialog.uiView.name |
| } |
| } |
| |
| /** |
| * <p>create an injectable context function to be used by an e4 application. |
| * |
| * @param type |
| * @param dialog |
| * @param clsName |
| */ |
| def void toContextOperations(JvmGenericType type, Dialog dialog, String clsName) { |
| var JvmOperation operation |
| // compute override |
| type.members += dialog.toMethod("compute", _typeReferenceBuilder.typeRef(Object), [ |
| annotations += _annotationTypesBuilder.annotationRef(Override) |
| visibility = JvmVisibility.PUBLIC |
| parameters += dialog.toParameter("context", _typeReferenceBuilder.typeRef(IEclipseContext)) |
| parameters += dialog.toParameter("contextKey", _typeReferenceBuilder.typeRef(String)) |
| body = [append( |
| ''' |
| MApplication application = context.get(MApplication.class); |
| IEclipseContext appCtx = application.getContext(); |
| IViewEmbeddedProvider provider = ContextInjectionFactory.make(«clsName».class, appCtx); |
| appCtx.set(IViewEmbeddedProvider.class, provider); |
| return provider;''')] |
| ]) |
| } |
| |
| /** |
| * <p>build the constructors to be used by an e4 application. |
| * |
| * @param type |
| * @param dialog |
| */ |
| def void toConstructor(JvmDeclaredType type, Dialog dialog) { |
| if(dialog.embedded) { |
| type.members += dialog.toConstructor( |
| [ |
| body = [append(''' |
| super(); |
| uuid = UUID.randomUUID().toString();''')] |
| ]) |
| |
| } else { |
| type.members += dialog.toConstructor( |
| [ |
| annotations += _annotationTypesBuilder.annotationRef(Inject) |
| parameters += dialog.toParameter("parent", _typeReferenceBuilder.typeRef(VerticalLayout)) |
| parameters += dialog.toParameter("context", _typeReferenceBuilder.typeRef(IEclipseContext)) |
| parameters += dialog.toParameter("app", _typeReferenceBuilder.typeRef(MApplication)) |
| body = [append(''' |
| super(parent,context,app); |
| uuid = UUID.randomUUID().toString();''')] |
| ]) |
| } |
| } |
| |
| /** |
| * <p>build the class variables. |
| * |
| * @param type |
| * @param dialog |
| */ |
| def void toFields(JvmDeclaredType type, Dialog dialog) { |
| var JvmField field = null |
| |
| // create logger |
| field = dialog.toField("log", _typeReferenceBuilder.typeRef(Logger))[ |
| setInitializer([append('''LoggerFactory.getLogger("vaaclipseDialog")''')])] |
| field.final = true |
| field.static = true |
| type.members += field |
| } |
| |
| /** |
| * <p>build the methods. |
| * |
| * @param type |
| * @param dialog |
| * @param pckg |
| */ |
| def void toOperations(JvmDeclaredType type, Dialog dialog, DialogPackage pckg) { |
| |
| |
| // getViewId |
| type.members += dialog.toMethod("getViewId", _typeReferenceBuilder.typeRef(String), |
| [ |
| body = [append('''return "«dialog.getUiModelPackageName».«dialog.getViewName()»";''')] |
| ]) |
| |
| if(dialog.stateful) { |
| type.members += dialog.toMethod("createRenderingParams", _typeReferenceBuilder.typeRef(Map, |
| _typeReferenceBuilder.typeRef(String), |
| _typeReferenceBuilder.typeRef(Object)), |
| [ |
| parameters += dialog.toParameter("user", _typeReferenceBuilder.typeRef(IUser)) |
| parameters += dialog.toParameter("blobService", _typeReferenceBuilder.typeRef(IBlobService)) |
| body = [append('''«dialog.uiView.createRenderingParams»''')] |
| ]) |
| type.members += dialog.toMethod("localeChanged", _typeReferenceBuilder.typeRef(Void::TYPE), |
| [ |
| parameters += dialog.toParameter("locale", _typeReferenceBuilder.typeRef(Locale)) |
| body = [append('''«dialog.uiView.localeChanged»''')] |
| ]) |
| } else { |
| // getMainBeanSlot |
| val mainBeanSlot = dialog.mainBeanSlot |
| // getBaseDtoName |
| type.members += dialog.toMethod("getBaseDtoName", _typeReferenceBuilder.typeRef(String), |
| [ |
| body = [append( |
| '''return "«mainBeanSlot.jvmType.type.qualifiedName»";''')] |
| ]) |
| |
| // getBaseEntityName |
| type.members += dialog.toMethod("getBaseEntityName", _typeReferenceBuilder.typeRef(String), |
| [ |
| body = [append( |
| '''return "«EntityUtils.getQualifiedEntityNameForQualifiedDtoName(mainBeanSlot.jvmType.type.qualifiedName)»";''')] |
| ]) |
| |
| // getIdForDto |
| type.members += dialog.toMethod("getIdForDto", _typeReferenceBuilder.typeRef(Object), |
| [ |
| parameters += dialog.toParameter("savedDto", _typeReferenceBuilder.typeRef(mainBeanSlot.jvmType.qualifiedName)) |
| body = [append('''return «mainBeanSlot.idForDto»;''')] |
| ]) |
| |
| // getDataName |
| type.members += dialog.toMethod("getDataName", _typeReferenceBuilder.typeRef(String), |
| [ |
| body = [append('''return "«mainBeanSlot.jvmType.type.entityName»";''')] |
| ]) |
| |
| // getPrimaryKey |
| type.members += dialog.toMethod("getPrimaryKey", _typeReferenceBuilder.typeRef(String), |
| [ |
| body = [append('''return "«mainBeanSlot.jvmType.type.entityFQN».«EntityUtils.getDto(mainBeanSlot.jvmType.type).idAttributeName»";''')] |
| ]) |
| |
| // getDtoService |
| type.members += dialog.toMethod("getDtoService", _typeReferenceBuilder.typeRef(IDTOServiceWithMutablePersistence, |
| _typeReferenceBuilder.typeRef(mainBeanSlot.jvmType.qualifiedName)), |
| [ |
| body = [append('''return (IDTOServiceWithMutablePersistence<«mainBeanSlot.jvmType.qualifiedName»>) DtoServiceAccess |
| .getService(«mainBeanSlot.jvmType.qualifiedName».class);''')] |
| ]) |
| |
| // registerPersistenceUnit |
| type.members += dialog.toMethod("registerPersistenceUnit", _typeReferenceBuilder.typeRef(Void::TYPE), |
| [ |
| val entity = EntityUtils.getEntityFromDto(mainBeanSlot.jvmType.type) as LEntity |
| parameters += dialog.toParameter("persistenceService", _typeReferenceBuilder.typeRef(IPersistenceService)) |
| body = [append('''''')] |
| if (entity!=null){ |
| body = [append(''' |
| persistenceService.registerPersistenceUnit("«entity?.persistenceUnit»", |
| «entity?.fullyQualifiedName».class); |
| log.debug("PersistenceService registered");''')] |
| } |
| ]) |
| |
| // create createToobarHelper |
| type.members += dialog.toMethod("createToobarHelper", _typeReferenceBuilder.typeRef(IToolbarAction), |
| [ |
| body = [append('''«IF dialog.toolbar != null»return new «dialog.toolbar.fullyQualifiedName»Toolbar(uuid);«ELSE»return null;«ENDIF»''')] |
| ]) |
| |
| // create getBindingPropertyName |
| type.members += dialog.toMethod("getBindingPropertyName", _typeReferenceBuilder.typeRef(String), |
| [ |
| annotations += _annotationTypesBuilder.annotationRef(Override) |
| body = [append('''return "«I18NKeyGenerator.key(dialog.descriptionValue)»";''')] |
| ]) |
| // get number of layout columns |
| type.members += dialog.toMethod("getNumColumns", _typeReferenceBuilder.typeRef(int), |
| [ |
| annotations += _annotationTypesBuilder.annotationRef(Override) |
| body = [append('''return «dialog.numColumns»;''')] |
| ]) |
| } |
| } |
| |
| def boolean containsSuperType(JvmType type, String fqn) { |
| if(!(type instanceof JvmDeclaredType)) { |
| return false |
| } |
| |
| return new RawSuperTypes().collectNames(type).contains(fqn) |
| } |
| |
| /** |
| * |
| * @param type |
| * @return |
| */ |
| def String getEntityName(JvmType type){ |
| var entity = EntityUtils.getEntityFromDto(type) |
| return '''«entity?.name»''' |
| |
| } |
| |
| def String getEntityFQN(JvmType type){ |
| var entity = EntityUtils.getEntityFromDto(type) |
| return '''«entity?.fullyQualifiedName»''' |
| |
| } |
| |
| /** |
| * |
| * @param slot |
| * @return |
| */ |
| def String getIdForDto(UiBeanSlot slot){ |
| return '''savedDto.«slot.jvmType.getDtoIdGetter»''' |
| } |
| |
| /** |
| * Provides the name of the first found bean slot defined in the ui view |
| * |
| * @param dialog |
| * @return |
| */ |
| def UiBeanSlot getMainBeanSlot(Dialog dialog){ |
| if(dialog.autowire) { |
| // create a dummy beanslot |
| val UiBeanSlot slot = AutowireUiFactory.createBeanSlot(dialog.dto) |
| |
| // we need to resolve the proxy here, due to lack of resourceset in slot |
| val typeRef = _typeReferenceBuilder.typeRef(AutowireUiFactory.getDtoFQN(dialog.dto)) |
| slot.jvmType = typeRef |
| |
| return slot |
| }else{ |
| for (UiBeanSlot uiBeanSlot : dialog.uiView.beanSlots) { |
| return uiBeanSlot |
| } |
| } |
| } |
| |
| /** |
| * |
| * @param dialog |
| * @return |
| */ |
| def String createDtoServices(Dialog dialog) { |
| var body = '''// DTO Services (via DS)''' |
| for (UiBeanSlot uiBeanSlot : dialog.uiView.beanSlots) { |
| body = ''' |
| «body» |
| dto«uiBeanSlot.jvmType.simpleName»Service = (IDTOServiceWithMutablePersistence<«uiBeanSlot.jvmType.simpleName»>)DtoServiceAccess.getService(«uiBeanSlot.jvmType.simpleName».class); |
| ''' |
| } |
| return body |
| } |
| |
| /** |
| * <p>build the data components. |
| * |
| * @param dialog |
| * @return |
| */ |
| def String removeOldView(Dialog dialog) { |
| return ''' |
| if (viewContext != null){ |
| viewContext.dispose(); |
| } |
| if (dataArea.getComponentCount() > 0) { |
| dataArea.removeAllComponents(); |
| } |
| ''' |
| } |
| |
| /** |
| * Method to subscribe the view with the event broker to receive events due to the defined in the grammar |
| * |
| * @param dialog |
| * @param pckg |
| * @return |
| */ |
| def String subscribe(Dialog dialog, DialogPackage pckg) { |
| var body = "" |
| var idx = 0; |
| for (UiBeanSlot uiBeanSlot : dialog.uiView.beanSlots) { |
| var entity = EntityUtils.getEntityFromDto(uiBeanSlot.jvmType.type) |
| if (entity != null) { |
| idx++ |
| // Only once required. |
| if (idx == 1){ |
| body = ''' |
| «body» |
| persistenceService.registerPersistenceUnit("«entity?.persistenceUnit»", «entity?.fullyQualifiedName».class); |
| log.debug("PersistenceService registered");''' |
| } |
| } |
| } |
| |
| body = ''' |
| «body» |
| ««« StrategyHandler event subscription |
| eventBroker.subscribe(EventBrokerMsg.DIALOG_STRATEGY_CHANGED, |
| strategyEventHandler); |
| ''' |
| |
| return body |
| } |
| |
| /** |
| * Method to unsubscribe the view with the event broker to receive events due to the defined in the grammar |
| * |
| * @param dialog |
| * @return |
| */ |
| def unsubscribe(Dialog dialog) { |
| var unsubscribers = ''' |
| «IF dialog.toolbar!=null» |
| eventBroker.unsubscribe(dispatchActionHandler); |
| «ENDIF» |
| eventBroker.unsubscribe(strategyEventHandler);''' |
| return unsubscribers |
| } |
| |
| |
| /** |
| * |
| * @param jvmType |
| * @return |
| * |
| */ |
| def String getDtoIdGetter(JvmTypeReference jvmType) { |
| return getDtoIdGetter(EntityUtils.getEntityFromDto(jvmType.type)) |
| } |
| |
| /** |
| * |
| * @param entity |
| * @return |
| * |
| */ |
| def String getDtoIdGetter(LEntity entity) { |
| if (entity != null) { |
| for (attribute : entity.allAttributes) { |
| if (attribute.isId || attribute.isUuid) { |
| return '''get«Strings.toFirstUpper(attribute.name)»()''' |
| } |
| } |
| } |
| return '''getId()''' |
| } |
| |
| /** |
| * |
| * @param dialog |
| * @return |
| */ |
| def String loadBeans(Dialog dialog) { |
| var body = '''''' |
| for (UiBeanSlot uiBeanSlot : dialog.uiView.beanSlots) { |
| val simpleTypeName = uiBeanSlot.jvmType.simpleName |
| val variableName = '''newLoaded«simpleTypeName»''' |
| body = ''' |
| «body» |
| «simpleTypeName» «variableName» = null; |
| Object data = event.getProperty(org.eclipse.e4.core.di.extensions.EventUtils.DATA); |
| if (data instanceof «simpleTypeName») { |
| «variableName» = («simpleTypeName»)data; |
| } |
| else if (data instanceof EventBrokerMsg) { |
| EventBrokerMsg msg = (EventBrokerMsg)data; |
| String id = msg.getId(); |
| log.debug("load bean with id:"+id); |
| if (id!=null){ |
| try { |
| «variableName» = dto«simpleTypeName»Service.get((int)Double.parseDouble(id)); |
| } catch (NumberFormatException e) { |
| «variableName» = dto«simpleTypeName»Service.get(id); |
| } catch (NullPointerException e) { |
| «variableName» = dto«simpleTypeName»Service.get(id); |
| } |
| } |
| } |
| ecviewComponent.setValue(VIEW_ID, «variableName», params); |
| ''' |
| } |
| return body |
| } |
| |
| def String localeChanged(UiView view) { |
| var body = |
| ''' |
| if(getViewContext() != null) { |
| getViewContext().setLocale(locale); |
| }''' |
| var slots = view.beanSlots |
| for(slot:slots) { |
| if(slot.jvmType.type.containsSuperType(typeof(IStateMachineParticipant).name)) { |
| body = ''' |
| «body» |
| if(getViewContext() != null && getViewContext().getBeanSlot("«slot.name»") != null) { |
| ((IStateMachineParticipant)getViewContext().getBeanSlot("«slot.name»").getValue()).setLocale(locale); |
| }''' |
| } else if(slot.jvmType.type.containsSuperType(typeof(IStateMachine).name)) { |
| body = ''' |
| «body» |
| if(getViewContext() != null && getViewContext().getBeanSlot("«slot.name»") != null) { |
| ((IStateMachine)getViewContext().getBeanSlot("«slot.name»").getValue()).setLocale(locale); |
| }''' |
| } |
| } |
| return body |
| } |
| |
| |
| def String createRenderingParams(UiView view) { |
| var body = ''' |
| Map<String, Object> params = super.createRenderingParams(user, blobService); |
| IConfiguration config = new IConfiguration() { |
| @Override |
| public void beforeUiRendering(IContext viewContext) { |
| ''' |
| var slots = view.beanSlots |
| for(slot:slots) { |
| if(slot.jvmType.type.containsSuperType(typeof(IStateMachineParticipant).name) || |
| slot.jvmType.type.containsSuperType(typeof(IPeripheral).name) |
| ) { |
| body = ''' |
| «body» |
| IStateMachineParticipant «slot.name» = new «slot.jvmType.qualifiedName»(); |
| «slot.name».setLocale(user.getLocale()); |
| viewContext.createBeanSlot("«slot.name»", «slot.jvmType.qualifiedName».class).setValue(«slot.name»); |
| ''' |
| } else if(slot.jvmType.type.containsSuperType(typeof(IStateMachine).name)) { |
| body = ''' |
| «body» |
| IStateMachine «slot.name» = new «slot.jvmType.qualifiedName»(); |
| «slot.name».setUser(user); |
| «slot.name».setLocale(user.getLocale()); |
| viewContext.setLocale(user.getLocale()); |
| «slot.name».setDslMetadataService(getDslMetadataService()); |
| «slot.name».setThemeResourceService(getThemeResourceService()); |
| «slot.name».setReportProvider(getReportProvider()); |
| «slot.name».setEclipseContext(getEclipseContext()); |
| «slot.name».setBlobService(getBlobService()); |
| viewContext.createBeanSlot("«slot.name»", «slot.jvmType.qualifiedName».class).setValue(«slot.name»); |
| ''' |
| } else if(slot.jvmType.type.containsSuperType(typeof(IBlobConverter).name)) { |
| body = ''' |
| «body» |
| viewContext.createBeanSlot("«slot.name»", BlobConverter.class).setValue(new BlobConverter(blobService)); |
| ''' |
| } else { |
| val entity = EntityUtils.getEntityFromDto(slot.jvmType.type); |
| body = ''' |
| «body» |
| viewContext.createBeanSlot("«slot.name»", «slot.jvmType.qualifiedName».class).setValue(new «slot.jvmType.qualifiedName»()); |
| «IF entity !== null» |
| persistenceService.registerPersistenceUnit("«entity.persistenceUnit»", «EntityUtils.getQualifiedEntityNameForQualifiedDtoName(slot.jvmType.type.qualifiedName)».class); |
| «ENDIF» |
| ''' |
| } |
| } |
| body = ''' |
| «body» |
| } |
| @Override |
| public void afterUiRendering(IContext context) { |
| } |
| @Override |
| public void beforeBind(IContext context) { |
| ''' |
| body = ''' |
| «body» |
| } |
| @Override |
| public void afterBind(IContext context) { |
| ''' |
| for(slot:slots) { |
| if((slot.jvmType.type.containsSuperType(typeof(IStateMachineParticipant).name))) { |
| body = ''' |
| «body» |
| ((IStateMachineParticipant)context.getBeanSlot("«slot.name»").getValue()).init(); |
| ''' |
| if((slot.jvmType.type.containsSuperType(typeof(IDataProvider).name))) { |
| for(innerslot:slots) { |
| if((innerslot.jvmType.type.containsSuperType(typeof(IDto).name))) { |
| body = ''' |
| «body» |
| if (context.getBeanSlot("«innerslot.name»") != null) { |
| ((IDataProvider)context.getBeanSlot("«slot.name»").getValue()).addDatasource("«innerslot.name»", context.getBeanSlot("«innerslot.name»").getValueType()); |
| } |
| ''' |
| } |
| } |
| } |
| } |
| } |
| for(slot:slots) { |
| if((slot.jvmType.type.containsSuperType(typeof(IStateMachine).name))) { |
| body = ''' |
| «body» |
| ((IStateMachine)context.getBeanSlot("«slot.name»").getValue()).start(); |
| ''' |
| } |
| } |
| body = ''' |
| «body» |
| } |
| }; |
| params.put(IViewContext.PARAM_CONFIGURATION, config); |
| return params; |
| ''' |
| return body |
| } |
| |
| // HELPER METHODS |
| /** |
| * Method to set a default instance into the view context (for each defined datasource object in the uimodel) |
| */ |
| def String setBeanToViewContext(Dialog dialog) { |
| var body = '''''' |
| for (UiBeanSlot uiBeanSlot : dialog.uiView.beanSlots) { |
| body = '''«body»viewContext.setBean("«uiBeanSlot.name»",«uiBeanSlot.name»);''' |
| } |
| return body |
| } |
| |
| def String getViewName(Dialog dialog) { |
| if(dialog.autowire) { |
| return AutowireUiFactory.getECViewName(dialog); |
| } else { |
| return dialog.uiView.name |
| } |
| } |
| |
| def String getUiModelPackageName(Dialog dialog) { |
| if(dialog.autowire) { |
| return AutowireUiFactory.getECViewPackage(dialog); |
| }else{ |
| var parent = dialog.uiView.eContainer |
| while (!(parent instanceof UiModel)) { |
| parent = parent.eContainer |
| } |
| var uiModel = parent as UiModel |
| return uiModel.packageName |
| } |
| } |
| } |