@Override public EObject createFeature(Resource resource, EClass eClass) { // what kind of object should we create? Property or DataStore? if (eClass == null) { if (ModelUtil.findNearestAncestor(object, new Class[] {Process.class, Event.class}) != null) // nearest ancestor is a Process or Event, so new object will be a Property eClass = Bpmn2Package.eINSTANCE.getProperty(); else if (ModelUtil.findNearestAncestor(object, new Class[] {DocumentRoot.class}) != null) eClass = Bpmn2Package.eINSTANCE.getDataStore(); } if (eClass != null) { return Bpmn2ModelerFactory.create(resource, eClass); } return null; }
@SuppressWarnings("unchecked") @Override protected void internalSet( DataAssociation association, EStructuralFeature feature, Object value, int index) { EObject container = null; EStructuralFeature containerFeature = null; if (value instanceof Property) { if (((Property) value).eContainer() == null) { // this Property isn't owned by anything yet - figure out who the owner is container = ModelUtil.findNearestAncestor(association, new Class[] {Activity.class}); if (container == null) container = ModelUtil.findNearestAncestor(association, new Class[] {Event.class}); if (container == null) container = ModelUtil.findNearestAncestor(association, new Class[] {Process.class}); containerFeature = container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$ } } else if (value instanceof DataStore) { if (((DataStore) value).eContainer() == null) { // this DataStore isn't owned by anything yet - figure out who the owner is container = ModelUtil.findNearestAncestor(association, new Class[] {DocumentRoot.class}); containerFeature = container.eClass().getEStructuralFeature("dataStore"); // $NON-NLS-1$ } } else if (value instanceof String) { // first check if a property with this name already exists Hashtable<String, Object> choices = getChoiceOfValues(); Property property = (Property) choices.get(value); if (property == null) { // need to create a new one! DiagramEditor editor = ModelUtil.getEditor(object); ModelEnablements modelEnablement = (ModelEnablements) editor.getAdapter(ModelEnablements.class); // find nearest element that can contain a Property and create one container = association; for (; ; ) { container = ModelUtil.findNearestAncestor( container, new Class[] {Activity.class, Event.class, Process.class}); if (container == null) return; containerFeature = container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$ if (modelEnablement.isEnabled(container.eClass(), containerFeature)) break; } containerFeature = container.eClass().getEStructuralFeature("properties"); // $NON-NLS-1$ property = Bpmn2ModelerFactory.create(Property.class); ExtendedPropertiesAdapter adapter = ExtendedPropertiesAdapter.adapt(property); adapter.getObjectDescriptor().setTextValue((String) value); } value = property; } final EObject c = container; final EStructuralFeature cf = containerFeature; final ItemAwareElement v = (ItemAwareElement) value; if (feature == Bpmn2Package.eINSTANCE.getDataAssociation_SourceRef()) { setSourceRef(association, v, c, cf); } else { setTargetRef(association, v, c, cf); } }