/** * Overridden to return the type arguments of the generic type of the adapted {@link * TypedElement}. * * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object) */ @Override public Collection<?> getChildren(Object object) { TypedElement typedElement; Collection<Object> result = null; // cast the typed element typedElement = (TypedElement) object; // check if the typed element has a generic type and that one is a // ComplexGenericType if (typedElement.getGenericType() != null && typedElement.getGenericType() instanceof ComplexGenericType) { ComplexGenericType genericType = (ComplexGenericType) typedElement.getGenericType(); // check if the generic type has type arguments if (!genericType.getTypeArgument().isEmpty()) { // add the type arguments to the list of children result = new ArrayList<Object>(genericType.getTypeArgument()); result.addAll(super.getChildren(object)); } } return result == null ? super.getChildren(object) : result; }
/** * @see org.eclipse.emf.edit.provider.ItemPropertyDescriptor#setPropertyValue(java.lang.Object, * java.lang.Object) */ @Override public void setPropertyValue(Object object, Object value) { TypedElement typedElement = (TypedElement) object; // the value can either be a type parameter ... if (value instanceof TypeParameter) { TypeParameter typeParameter = (TypeParameter) value; // create a new generic type for type parameters and set its // referenced type parameter ParameterGenericType genericType = PivotModelFactory.eINSTANCE.createParameterGenericType(); genericType.setTypeParameter(typeParameter); setGenericType(typedElement, genericType); } // ... or a normal type else if (value instanceof Type) { Type type = (Type) value; // check if the type has any type parameters if (!type.getOwnedTypeParameter().isEmpty()) { // create a new complex generic type and set the given type // as a reference ComplexGenericType genericType = PivotModelFactory.eINSTANCE.createComplexGenericType(); genericType.setUnboundType(type); // append type arguments for each type parameter for (int i = 0, size = type.getOwnedTypeParameter().size(); i < size; i++) { genericType.getTypeArgument().add(PivotModelFactory.eINSTANCE.createTypeArgument()); } setGenericType(typedElement, genericType); } // just a normal type without type parameters else { // remove any previously created generic types setGenericType(typedElement, null); super.setPropertyValue(object, value); } } }