private Collection<Object> newEquimentDescriptorsForTargetNodeType( EditingDomain domain, NodeType nodeType, Equipment targetEq) { // find the object from the ref and return all possible // creation references. // TODO, possibly optimize, by filtering non Equipments. Collection<Object> newChildDescriptors = Lists.newArrayList(); TreeIterator<EObject> it = nodeType.eAllContents(); while (it.hasNext()) { EObject next = it.next(); if (next.eClass() == LibraryPackage.Literals.EQUIPMENT) { // Match on equipmentcode. Equipment eq = (Equipment) next; if (eq.getEquipmentCode().equals(targetEq.getEquipmentCode())) { // get children and build descriptors. EList<EObject> directContent = next.eContents(); for (EObject targetChild : directContent) { if (targetChild instanceof Equipment) { Equipment eqCopy = (Equipment) EcoreUtil.copy(targetChild); // Set the name as a sequence. String newSequenceNumber = EditUtils.INSTANCE.nextSequenceNumber( domain, targetEq, LibraryPackage.Literals.EQUIPMENT__EQUIPMENTS, LibraryPackage.Literals.COMPONENT__NAME); eqCopy.setName(newSequenceNumber); Lifecycle newLC = GenericsFactory.eINSTANCE.createLifecycle(); newLC.setProposed(NonModelUtils.toXMLDate(NonModelUtils.todayAndNow())); eqCopy.setLifecycle(newLC); newChildDescriptors.add( createChildParameter(LibraryPackage.Literals.EQUIPMENT__EQUIPMENTS, eqCopy)); } } } } } return newChildDescriptors; }
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; }