/** * A new function with a calculated name. * * @param target * @param collectionFeature * @return */ private Function newLibraryFunction( EditingDomain domain, EObject target, EReference collectionFeature) { Function createFunction = LibraryFactory.eINSTANCE.createFunction(); String newSequenceNumber = EditUtils.INSTANCE.nextSequenceNumber( domain, target, collectionFeature, LibraryPackage.Literals.COMPONENT__NAME); createFunction.setName(newSequenceNumber); return createFunction; }
public Collection<?> getNewChildDescriptors(Object object, EditingDomain editingDomain) { Collection<Object> newChildDescriptors = Lists.newArrayList(); if (object instanceof EObject) { EObject target = (EObject) object; if (target instanceof Component || target instanceof NodeType) { // Are we in the design view? (The target must have a parent // Node). Node node = StudioUtils.nodeFor(target); if (node != null) { if (target.eClass() == LibraryPackage.Literals.NODE_TYPE) { // Handled by the Node child creation has NodeType is // not visible in the Design view. } else if (target.eClass() == LibraryPackage.Literals.EQUIPMENT) { if (node.getOriginalNodeTypeRef() != null) { NodeType ntRef = node.getOriginalNodeTypeRef(); Equipment targetEq = (Equipment) target; newChildDescriptors = newEquimentDescriptorsForTargetNodeType(editingDomain, ntRef, targetEq); } else { // No descriptor, if we have no node type. } } else if (target.eClass() == LibraryPackage.Literals.FUNCTION) { // Allow creation of Function object, not from the // original type. Function function = LibraryFactory.eINSTANCE.createFunction(); Lifecycle newLC = GenericsFactory.eINSTANCE.createLifecycle(); newLC.setProposed(NonModelUtils.toXMLDate(NonModelUtils.todayAndNow())); function.setLifecycle(newLC); newChildDescriptors.add( createChildParameter(LibraryPackage.Literals.FUNCTION__FUNCTIONS, function)); } } else { if (target instanceof NodeType) { Function createFunction = newLibraryFunction( editingDomain, target, LibraryPackage.Literals.NODE_TYPE__FUNCTIONS); Equipment createEquipment = newLibraryEquipment( editingDomain, target, LibraryPackage.Literals.NODE_TYPE__EQUIPMENTS); newChildDescriptors.add( createChildParameter(LibraryPackage.Literals.NODE_TYPE__FUNCTIONS, createFunction)); newChildDescriptors.add( createChildParameter( LibraryPackage.Literals.NODE_TYPE__EQUIPMENTS, createEquipment)); } else if (target instanceof Equipment) { Equipment createEquipment = newLibraryEquipment( editingDomain, target, LibraryPackage.Literals.EQUIPMENT__EQUIPMENTS); newChildDescriptors.add( createChildParameter( LibraryPackage.Literals.EQUIPMENT__EQUIPMENTS, createEquipment)); } else if (target instanceof Function) { Function createFunction = newLibraryFunction( editingDomain, target, LibraryPackage.Literals.FUNCTION__FUNCTIONS); newChildDescriptors.add( createChildParameter(LibraryPackage.Literals.FUNCTION__FUNCTIONS, createFunction)); } } } } return newChildDescriptors; }