@Override protected void clearExpression(Expression exp) { if (owner.eIsSet(expressionFeature)) { Command c = new SetCommand(editingService.getEditingDomain(), owner, expressionFeature, null); editingService.getEditingDomain().getCommandStack().execute(c); } }
/** * Converts the value of an EAttribute with isMany==false, the value is converted ( {@link * #convertEAttributeValue(Object, EDataType)}) and set in the correct feature in the {@link * ModelObject}. * * @param eObject the eObject from which the value is read * @param modelObject the @[link ModelObject} in which the value is to be set * @param eAttribute the EAttribute which is converted * @see #convertEAttributeValue(Object, EDataType) */ protected void convertSingleEAttribute( final EObject eObject, final ModelObject<?> modelObject, final EAttribute eAttribute) { if (!eObject.eIsSet(eAttribute)) { return; } final Object eValue = eObject.eGet(eAttribute); modelObject.eSet(eAttribute, convertEAttributeValue(eValue, eAttribute.getEAttributeType())); }
@SuppressWarnings({"unchecked", "rawtypes"}) private void updateAttrs( EClass eClass, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) { List<EAttribute> listMany = new LinkedList<EAttribute>(); List<EAttribute> list = new LinkedList<EAttribute>(); for (EAttribute eAttr : eClass.getEAllAttributes()) { if (eAttr.isMany()) { listMany.add(eAttr); } else { list.add(eAttr); } } for (EAttribute eAttr : listMany) { List<?> vList = (List<?>) eObj.eGet(eAttr); if (vList.size() == 0) { if (eRef != null && ((List<?>) eRef.eGet(eAttr)).size() > 0) { vList.addAll((List) eRef.eGet(eAttr)); } else if (eDef != null) { vList.addAll((List) eDef.eGet(eAttr)); } } } for (EAttribute eAttr : list) { Object val = eObj.eGet(eAttr); if (eAttr.isUnsettable()) { if (!eObj.eIsSet(eAttr)) { if (eRef != null && eRef.eIsSet(eAttr)) { eObj.eSet(eAttr, eRef.eGet(eAttr)); } else if (eDef != null && eDef.eIsSet(eAttr)) { eObj.eSet(eAttr, eDef.eGet(eAttr)); } } } else if (val == null) { if (eRef != null && eRef.eGet(eAttr) != null) { eObj.eSet(eAttr, eRef.eGet(eAttr)); } else if (eDef != null) { eObj.eSet(eAttr, eDef.eGet(eAttr)); } } } }
/** * Clears an EObject's feature, that is removes all objects from a many-valued feature. If the * target is single-valued, nothing is done. * * @param eObject the EObject to clear the feature for * @param feature the EStructuralFeature that shall be cleared */ protected static void clear(EObject eObject, EStructuralFeature feature) { if (eObject.eIsSet(feature)) { if (feature.isMany()) { ModelGeneratorUtil.removePerCommand( eObject, feature, (Collection<?>) eObject.eGet(feature), exceptionLog, ignoreAndLog); } else { ModelGeneratorUtil.setPerCommand(eObject, feature, null, exceptionLog, ignoreAndLog); } } }
/** Inject the expression to work with. */ public void injectData(String identity, EObject owner, EStructuralFeature feature) { this.expressionFeature = feature; this.owner = owner; this.identity = identity; buildUI(); // Disable the editor. this.setEnabled(false); if (owner.eIsSet(feature)) { this.injectData(owner.eGet(feature)); } }
/** * Returns all valid references for an EObject. This excludes container/containment references. A * reference is valid if it is neither derived nor volatile and if it is changeable and either * many-valued or not already set. * * @param eObject the EObject to get references for * @param exceptionLog the current log of exceptions * @param ignoreAndLog should exceptions be ignored and added to <code>exceptionLog</code>? * @return all valid references as a list */ public static List<EReference> getValidReferences( EObject eObject, Set<RuntimeException> exceptionLog, boolean ignoreAndLog) { List<EReference> result = new LinkedList<EReference>(); for (EReference reference : eObject.eClass().getEAllReferences()) { if (!reference.isContainer() && !reference.isContainment() && isValid(reference, eObject, exceptionLog, ignoreAndLog) && (reference.isMany() || !eObject.eIsSet(reference))) { result.add(reference); } } return result; }
/** * Sets a reference, if the upper bound allows it, using {@link ModelGeneratorUtil#setReference}. * * @param eObject the EObject to set the reference for * @param referenceClass the EClass of EObjects that shall be referenced * @param reference the EReference that shall be set * @param allEObjects all possible EObjects that can be referenced * @see ModelGeneratorUtil#setReference(EObject, EClass, EReference, Random, Set, boolean, Map) */ protected static void setReference( EObject eObject, EClass referenceClass, EReference reference, Map<EClass, List<EObject>> allEObjects) { // check if the upper bound is reached if (!ModelGeneratorUtil.isValid(reference, eObject, exceptionLog, ignoreAndLog) || (!reference.isMany() && eObject.eIsSet(reference))) { return; } ModelGeneratorUtil.setReference( eObject, referenceClass, reference, random, exceptionLog, ignoreAndLog, allEObjects); }
public static void printAttributeValues(EObject object) { EClass eClass = object.eClass(); System.out.println(eClass.getName()); for (Iterator iter = eClass.getEAllAttributes().iterator(); iter.hasNext(); ) { EAttribute attribute = (EAttribute) iter.next(); Object value = object.eGet(attribute); System.out.print(" " + attribute.getName() + ": " + value); if (object.eIsSet(attribute)) { System.out.println(); // attribute is set } else { System.out.println(" (default)"); // attribute is not set } } } // printAttributeValues
/** * Called to handle the copying of a cross reference; this adds values or sets a single value as * appropriate for the multiplicity while <b>NOT</b> omitting any bidirectional reference that * isn't in the copy map. * * @param eReference the reference to copy. * @param eObject the object from which to copy. * @param copyEObject the object to copy to. */ @Override protected void copyReference( final EReference eReference, final EObject eObject, final EObject copyEObject) { if (eObject.eIsSet(eReference)) { if (!eReference.isMany()) { Object referencedEObject = eObject.eGet(eReference, resolveProxies); if (referencedEObject != null) { Object copyReferencedEObject = get(referencedEObject); if (copyReferencedEObject == null) { if (useOriginalReferences) { // && eReference.getEOpposite() == null) copyEObject.eSet(getTarget(eReference), referencedEObject); } } } } } super.copyReference(eReference, eObject, copyEObject); }
private void writeObject(PrintWriter out, EObject object, EStructuralFeature feature) throws SerializerException { Object ref = object.eGet(feature); if (ref == null || (feature.isUnsettable() && !object.eIsSet(feature))) { EClassifier type = feature.getEType(); if (type instanceof EClass) { EStructuralFeature structuralFeature = ((EClass) type).getEStructuralFeature(WRAPPED_VALUE); if (structuralFeature != null) { String name = structuralFeature.getEType().getName(); if (name.equals(IFC_BOOLEAN) || name.equals(IFC_LOGICAL) || structuralFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()) { out.print(BOOLEAN_UNDEFINED); } else { out.print(DOLLAR); } } else { out.print(DOLLAR); } } else { if (type == EcorePackage.eINSTANCE.getEBoolean()) { out.print(BOOLEAN_UNDEFINED); } else if (feature.isMany()) { out.print("()"); } else { out.print(DOLLAR); } } } else { if (ref instanceof EObject) { writeEmbedded(out, (EObject) ref); } else if (feature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) { Object stringValue = object.eGet(object.eClass().getEStructuralFeature(feature.getName() + "AsString")); if (stringValue != null && model.isUseDoubleStrings()) { out.print(stringValue); } else { writePrimitive(out, ref); } } else { writePrimitive(out, ref); } } }
private Collection<String> getViewmapRequiredPluginIDs() { Collection<String> result = null; for (TreeIterator<EObject> contents = EcoreUtil.getAllContents(getDiagram().getAllNodes()); contents.hasNext(); ) { EObject next = contents.next(); if (next instanceof Viewmap && next.eIsSet(GMFGenPackage.eINSTANCE.getViewmap_RequiredPluginIDs())) { if (result == null) { result = new HashSet<String>(); } result.addAll(((Viewmap) next).getRequiredPluginIDs()); contents.prune(); } } if (result == null) { return Collections.emptyList(); } return result; }
/** * @param manager The menu manager responsible for the context menu * @param descriptors The menu items to be added * @param domain The editing domain of the current EObject * @param eObject The model element */ private void fillContextMenu( IMenuManager manager, Collection<?> descriptors, final EditingDomain domain, final EObject eObject) { for (final Object descriptor : descriptors) { final CommandParameter cp = (CommandParameter) descriptor; if (!CommandParameter.class.isInstance(descriptor)) { continue; } if (cp.getEReference() == null) { continue; } if (!cp.getEReference().isMany() && eObject.eIsSet(cp.getEStructuralFeature())) { continue; } else if (cp.getEReference().isMany() && cp.getEReference().getUpperBound() != -1 && cp.getEReference().getUpperBound() <= ((List<?>) eObject.eGet(cp.getEReference())).size()) { continue; } manager.add( new CreateChildAction(domain, new StructuredSelection(eObject), descriptor) { @Override public void run() { super.run(); final EReference reference = ((CommandParameter) descriptor).getEReference(); // if (!reference.isContainment()) { // domain.getCommandStack().execute( // AddCommand.create(domain, eObject.eContainer(), null, cp.getEValue())); // } domain .getCommandStack() .execute(AddCommand.create(domain, eObject, reference, cp.getEValue())); } }); } }
protected void convertContent(EObject eObject) { final Object target = objectMapping.get(eObject); final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(target); for (final EStructuralFeature eStructuralFeature : modelObject.eClass().getEAllStructuralFeatures()) { if (!eStructuralFeature.isChangeable() || eStructuralFeature.isVolatile()) { continue; } // not set, not convert if (!eStructuralFeature.isMany() && !eObject.eIsSet(eStructuralFeature)) { continue; } if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) { convertFeatureMap(eObject, modelObject, eStructuralFeature); } else if (eStructuralFeature.isMany()) { if (eStructuralFeature instanceof EAttribute) { final EAttribute eAttribute = (EAttribute) eStructuralFeature; convertManyEAttribute(eObject, modelObject, eAttribute); } else { final EReference eReference = (EReference) eStructuralFeature; if (eReference.isContainer()) { continue; } convertManyEReference(eObject, modelObject, eReference); } } else { if (eStructuralFeature instanceof EAttribute) { final EAttribute eAttribute = (EAttribute) eStructuralFeature; convertSingleEAttribute(eObject, modelObject, eAttribute); } else { final EReference eReference = (EReference) eStructuralFeature; if (eReference.isContainer()) { continue; } convertSingleEReference(eObject, modelObject, eReference); } } } }
/** * Converts the value of an EReference with isMany==false, the value is converted to an EObject * and set in the correct feature in the eObject. * * @param modelObject the modelObject from which the value is retrieved. * @param eObject the eObject in which the value is set (after it has been converted) * @param eReference the eReference which is converted */ protected void convertSingleEReference( final ModelObject<?> modelObject, final EObject eObject, final EReference eReference) { // containment/container features are always set from the // containment side if (eReference.isContainer()) { return; } if (eObject.eIsSet(eReference)) { return; } final Object value = modelObject.eGet(eReference); if (value == null) { eObject.eSet(eReference, null); } else { final InternalEObject eValue = (InternalEObject) createTarget(value); eObject.eSet(eReference, eValue); } }
/** * Return the ValidatableNode node for EObject creating any ValidatableNodes that are required to * ensure that the returned ValidatableNode is installed in the root. */ protected @NonNull ValidatableNode getValidatableNode(@NonNull EObject eObject) { ValidatableNode validatable = allValidatableNodes.get(eObject); if (validatable == null) { EObject eContainer = eObject.eContainer(); if (eContainer != null) { // ValidatableNode parentValidatableNode = getValidatableNode(eContainer); // parentValidatableNode.getChildren().add(validatable); } else if (eObject instanceof DynamicEObjectImpl) { EClass eClass = eObject.eClass(); for (EStructuralFeature eStructuralFeature : eClass.getEAllStructuralFeatures()) { String featureName = eStructuralFeature.getName(); if ((featureName != null) && featureName.startsWith( "base_") // org.eclipse.uml2.uml.Extension.METACLASS_ROLE_PREFIX) && (eStructuralFeature instanceof EReference) && eObject.eIsSet( eStructuralFeature)) { // Unset for an applicable stereotype that has not been // applied eContainer = (EObject) eObject.eGet(eStructuralFeature); break; } } } if (eContainer != null) { validatable = createValidatableNode(); ValidatableNode parentValidatableNode = getValidatableNode(eContainer); parentValidatableNode.getChildren().add(validatable); } else { RootValidatableNode rootValidatableNode = createRootValidatableNode(); rootNode.getValidatableNodes().add(rootValidatableNode); validatable = rootValidatableNode; } validatable.setEnabled(true); validatable.setLabel(validityManager.getLabel(eObject)); validatable.setConstrainedObject(eObject); allValidatableNodes.put(eObject, validatable); } return validatable; }
/** * Determines if a particular propety has been set on an eobject. * * @param eobjects The eobject. * @param property The property to check. * @return <code>true</code> if the property has been set, otherwise <code>false</code> */ public static boolean isSet(EObject eobject, String property) { EStructuralFeature feature = feature(eobject, property); return eobject.eIsSet(feature); }
/** * Updates chart element object. * * @param expected class of expected chart element. * @param name chart element name * @param eParentObj container of chart element object. * @param eObj chart element object. * @param eRef reference chart object to be used to update chart object's values. * @param eDef default chart object to be used to update chart object's values. */ public void update( EClass expected, String name, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) { if (eObj == null) { if (eRef != null) { if (eRef instanceof IChartObject) { eObj = ((IChartObject) eRef).copyInstance(); ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false); } } else if (eDef != null) { if (eDef instanceof IChartObject) { eObj = ((IChartObject) eDef).copyInstance(); ChartElementUtil.setEObjectAttribute(eParentObj, name, eObj, false); return; } } } if (eObj == null || (eRef == null && eDef == null)) { return; } // Process visible case. if (contanisVisibleElement(eObj.eClass())) { if (eObj.eIsSet(eObj.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$ { if (eObj.eGet(eObj.eClass().getEStructuralFeature("visible")) != Boolean.TRUE) // $NON-NLS-1$ { // If the visible attribute is set to false, directly return, no need // to update other attributes. return; } } else { // If eObj isn't set visible and the visible attribute of // reference object is set to false, directly return, no need to // update other attributes. if (eRef != null && eRef.eIsSet(eRef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$ { if (eRef.eGet(eRef.eClass().getEStructuralFeature("visible")) != Boolean.TRUE) // $NON-NLS-1$ { eObj.eSet(eRef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$ return; } } else if (eDef != null && eDef.eIsSet(eDef.eClass().getEStructuralFeature("visible"))) // $NON-NLS-1$ { if (eDef.eGet(eDef.eClass().getEStructuralFeature("visible")) != Boolean.TRUE) // $NON-NLS-1$ { eObj.eSet(eDef.eClass().getEStructuralFeature("visible"), Boolean.FALSE); // $NON-NLS-1$ return; } } } } EClass eClass = eObj.eClass(); // attributes updateAttrs(eClass, eParentObj, eObj, eRef, eDef); // list attributes // references for (EReference ref : eClass.getEAllReferences()) { String childName = ref.getName(); Object child = eObj.eGet(ref); Object refChild = eRef != null ? eRef.eGet(ref) : null; Object defChild = eDef != null ? eDef.eGet(ref) : null; EObject eChildParntObj = eObj; if (child == null) { if (refChild != null) { if (refChild instanceof IChartObject) { child = updateFromReference(childName, refChild, eChildParntObj); } } else if (defChild != null) { if (defChild instanceof IChartObject) { child = ((IChartObject) defChild).copyInstance(); ChartElementUtil.setEObjectAttribute(eChildParntObj, childName, child, false); continue; } } } if (child != null) { if (ref.isMany()) { int size = ((List<?>) child).size(); for (int i = 0; i < size; i++) { Object item = ((List<?>) child).get(i); Object refItem = (refChild == null || (i >= ((List<?>) refChild).size())) ? null : ((List<?>) refChild).get(i); Object defItem = (defChild == null || (i >= ((List<?>) defChild).size())) ? null : ((List<?>) defChild).get(i); update(ref, eObj, (EObject) item, (EObject) refItem, (EObject) defItem); } } else { update(ref, eObj, (EObject) child, (EObject) refChild, (EObject) defChild); } } } }