public EReference getOldContainmentFeature(EObject eObject) { OldContainmentInformation oldContainmentInformation = getOldContainmentInformation().get(eObject); if (oldContainmentInformation == null) { return eObject.eContainmentFeature(); } else { return oldContainmentInformation.containmentFeature; } } /**
public EReference getOldContainmentFeature(EObject eObject) { OldContainmentInformation oldContainmentInformation = getOldContainmentInformation().get(eObject); if (oldContainmentInformation == null) { return eObject.eContainmentFeature(); } else { return oldContainmentInformation.containmentFeature; } } /**
private void reindex() { EObject parent = owner.eContainer(); if (parent != null) { EStructuralFeature feature = owner.eContainmentFeature(); @SuppressWarnings("unchecked") List<Object> list = (List<Object>)parent.eGet(feature); list.set(list.indexOf(owner), owner); } } };
protected String makeID(EObject eObject) { List<String> uriFragmentPath = new ArrayList<String>(); for (EObject container = eObject.eContainer(); container != null; container = eObject.eContainer()) { uriFragmentPath.add(((InternalEObject)container).eURIFragmentSegment(eObject.eContainmentFeature(), eObject)); eObject = container; } StringBuffer result = new StringBuffer(eObject instanceof ENamedElement ? ((ENamedElement)eObject).getName() : "_" + Integer.toString(getContents().indexOf(eObject))); for (ListIterator<String> i = uriFragmentPath.listIterator(uriFragmentPath.size()); i.hasPrevious(); ) { result.append('.'); result.append(i.previous()); } return result.toString(); } }
protected String makeID(EObject eObject) { List<String> uriFragmentPath = new ArrayList<String>(); for (EObject container = eObject.eContainer(); container != null; container = eObject.eContainer()) { uriFragmentPath.add(((InternalEObject)container).eURIFragmentSegment(eObject.eContainmentFeature(), eObject)); eObject = container; } StringBuffer result = new StringBuffer(eObject instanceof ENamedElement ? ((ENamedElement)eObject).getName() : "_" + Integer.toString(getContents().indexOf(eObject))); for (ListIterator<String> i = uriFragmentPath.listIterator(uriFragmentPath.size()); i.hasPrevious(); ) { result.append('.'); result.append(i.previous()); } return result.toString(); } }
public boolean isEObjectTransient(EObject obj) { if (obj.eContainmentFeature() == null) return false; EReference ref = obj.eContainmentFeature(); EObject cnt = obj.eContainer(); if (ref.isMany() && transSrvc.isCheckElementsIndividually(cnt, ref)) { if (transSrvc.isTransient(cnt, ref, ((List<?>) cnt.eGet(ref)).indexOf(obj))) return true; } else if (transSrvc.isTransient(cnt, ref, 0)) return true; return false; }
public void appendShortFragment(EObject obj, StringBuilder target) { EReference containmentFeature = obj.eContainmentFeature(); if (containmentFeature == null) { target.append(obj.eResource().getContents().indexOf(obj)); } else { EObject container = obj.eContainer(); appendShortFragment(container, target); target.append('.').append(container.eClass().getFeatureID(containmentFeature)); if (containmentFeature.isMany()) { List<?> list = (List<?>) container.eGet(containmentFeature); target.append('.').append(list.indexOf(obj)); } } }
protected INode doGetNode(EObject object, EStructuralFeature feature, int idx) { if (object == null) return null; if (feature == null) { INode result = NodeModelUtils.findActualNodeFor(object); if (result != null) { return result; } return doGetNode(object.eContainer(), object.eContainmentFeature(), -1); } List<INode> nodesForFeature = NodeModelUtils.findNodesForFeature(object, feature); if (nodesForFeature.isEmpty()) { return doGetNode(object, null, -1); } if (nodesForFeature.size() == 1 && idx == -1) return nodesForFeature.get(0); if (nodesForFeature.size() > idx ) { return nodesForFeature.get(idx); } return null; }
@Override public void serialize(EObject bean, JsonGenerator jg, SerializerProvider provider) throws IOException { if (!OPTION_SERIALIZE_TYPE.enabledIn(features)) { return; } EClass objectType = bean.eClass(); EReference containment = bean.eContainmentFeature(); if (isRoot(bean) || shouldSaveType(objectType, containment.getEReferenceType(), containment)) { String value = valueWriter.writeValue(bean.eClass(), provider); jg.writeFieldName(getFieldName()); serializer.serialize(value, jg, provider); } }
@Override public void serialize(EObject bean, JsonGenerator jg, SerializerProvider provider) throws IOException { if (!OPTION_SERIALIZE_TYPE.enabledIn(features)) { return; } EClass objectType = bean.eClass(); EReference containment = bean.eContainmentFeature(); if (isRoot(bean) || shouldSaveType(objectType, containment.getEReferenceType(), containment)) { String value = valueWriter.writeValue(bean.eClass(), provider); jg.writeFieldName(getFieldName()); serializer.serialize(value, jg, provider); } }
/** * If the owner and the feature aren't null, * the feature is the key of a map entry class, * and the owner is contained in a EMap, * then the map is updated to properly reflect the change to the key's hash code. * @param owner the owner of the feature. * @param feature the feature that's been updated. */ protected void updateEMap(EObject owner, EStructuralFeature feature) { if (owner != null && feature != null && "key".equals(feature.getName()) && feature.getEContainingClass().getInstanceClass() == Map.Entry.class) { EObject container = owner.eContainer(); if (container != null) { EStructuralFeature containmentFeature = owner.eContainmentFeature(); @SuppressWarnings("unchecked") List<Object> list = (List<Object>)container.eGet(containmentFeature); list.set(list.indexOf(owner), owner); } } }
/** * Replace the object in its {@link EObject#eResource containing} resource * and/or its {@link EObject#eContainer containing} object, * with the replacement object. * @param eObject the object to replace. * @param replacementEObject the replacement object. */ public static void replace(EObject eObject, EObject replacementEObject) { EObject container = eObject.eContainer(); if (container != null) { EReference feature = eObject.eContainmentFeature(); if (FeatureMapUtil.isMany(container, feature)) { @SuppressWarnings("unchecked") List<Object> list = (List<Object>)container.eGet(feature); list.set(list.indexOf(eObject), replacementEObject); } else { container.eSet(feature, replacementEObject); } } Resource resource = ((InternalEObject)eObject).eDirectResource(); if (resource != null) { List<EObject> list = resource.getContents(); list.set(list.indexOf(eObject), replacementEObject); } }
protected void writeTopAttributes(EObject top) { if (useEncodedAttributeStyle) { InternalEObject container = ((InternalEObject)top).eInternalContainer(); if (container != null) { EReference containmentReference = top.eContainmentFeature(); EReference containerReference = containmentReference.getEOpposite(); if (containerReference != null && !containerReference.isTransient()) { saveEObjectSingle(top, containerReference); } } } }
protected boolean writeTopElements(EObject top) { if (!useEncodedAttributeStyle) { InternalEObject container = ((InternalEObject)top).eInternalContainer(); if (container != null) { EReference containmentReference = top.eContainmentFeature(); EReference containerReference = containmentReference.getEOpposite(); if (containerReference != null && !containerReference.isTransient()) { saveHref(container, containerReference); return true; } } } return false; }
protected void writeTopAttributes(EObject top) { if (useEncodedAttributeStyle) { InternalEObject container = ((InternalEObject)top).eInternalContainer(); if (container != null) { EReference containmentReference = top.eContainmentFeature(); EReference containerReference = containmentReference.getEOpposite(); if (containerReference != null && !containerReference.isTransient()) { saveEObjectSingle(top, containerReference); } } } }
protected boolean writeTopElements(EObject top) { if (!useEncodedAttributeStyle) { InternalEObject container = ((InternalEObject)top).eInternalContainer(); if (container != null) { EReference containmentReference = top.eContainmentFeature(); EReference containerReference = containmentReference.getEOpposite(); if (containerReference != null && !containerReference.isTransient()) { saveHref(container, containerReference); return true; } } } return false; }
/** * This returns whether or not the domain allows the given object to be moved to * a different resource from its container. * In this implementation, an EObject is controllable if it has a container, * it is contained via a feature that allows proxy resolution, and neither it * nor its container is in a read-only resource. */ public boolean isControllable(Object object) { if (!(object instanceof EObject)) return false; EObject eObject = (EObject)object; EObject container = eObject.eContainer(); return container != null && eObject.eContainmentFeature().isResolveProxies() && !isReadOnly(eObject.eResource()) && !isReadOnly(container.eResource()); }
/** * Get the rendering index of the element * * @param parent * the parent * @param element * the element * @return the index or <code>-1</code> */ protected final int getRenderedIndex(@NonNull MUIElement parent, @NonNull MUIElement element) { EObject eElement = (EObject) element; EObject container = eElement.eContainer(); @SuppressWarnings("unchecked") List<MUIElement> list = (List<MUIElement>) container.eGet(eElement.eContainmentFeature()); int idx = 0; for (MUIElement u : list) { if (u == null) { getLogger().error("Found a null element in " + list); //$NON-NLS-1$ continue; } if (isChildRenderedAndVisible(u)) { if (u == element) { return idx; } idx++; } } return -1; }
/** * Removes the object from its {@link EObject#eResource containing} resource * and/or its {@link EObject#eContainer containing} object. * @param eObject the object to remove. */ public static void remove(EObject eObject) { InternalEObject internalEObject = (InternalEObject)eObject; EObject container = internalEObject.eInternalContainer(); if (container != null) { EReference feature = eObject.eContainmentFeature(); if (FeatureMapUtil.isMany(container, feature)) { ((EList<?>)container.eGet(feature)).remove(eObject); } else { container.eUnset(feature); } } Resource resource = internalEObject.eDirectResource(); if (resource != null) { resource.getContents().remove(eObject); } }
/** * Removes the object from its {@link EObject#eResource containing} resource * and/or its {@link EObject#eContainer containing} object. * @param eObject the object to remove. */ public static void remove(EObject eObject) { InternalEObject internalEObject = (InternalEObject)eObject; EObject container = internalEObject.eInternalContainer(); if (container != null) { EReference feature = eObject.eContainmentFeature(); if (FeatureMapUtil.isMany(container, feature)) { ((EList<?>)container.eGet(feature)).remove(eObject); } else { container.eUnset(feature); } } Resource resource = internalEObject.eDirectResource(); if (resource != null) { resource.getContents().remove(eObject); } }