All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.emf.databinding.internal.EMFMapProperty Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (c) 2008 Matthew Hall and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v20.html
 * 
 * Contributors: 
 *   Matthew Hall - initial API and implementation (bug 194734)
 *   Matthew Hall - bugs 195222, 264307, 265561
 *   Hasan Ceylan  - patch in bug 262160
 *   Tom Schindl  - port to EMF in 262160
 */
package org.eclipse.emf.databinding.internal;

import java.util.Map;

import org.eclipse.core.databinding.observable.map.MapDiff;
import org.eclipse.core.databinding.property.INativePropertyListener;
import org.eclipse.core.databinding.property.IProperty;
import org.eclipse.core.databinding.property.ISimplePropertyListener;
import org.eclipse.core.databinding.property.map.SimpleMapProperty;
import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;


/**
 * 

PROVISIONAL: This API is subject to arbitrary change, including renaming or removal.

* * @since 2.5 */ public class EMFMapProperty extends SimpleMapProperty { private EStructuralFeature eStructuralFeature; /** * @param eStructuralFeature the feature of the map. */ public EMFMapProperty(EStructuralFeature eStructuralFeature) { this.eStructuralFeature = eStructuralFeature; } /** * @return the feature */ protected EStructuralFeature getFeature() { return eStructuralFeature; } public Object getKeyType() { final EClass eType = (EClass)this.eStructuralFeature.getEType(); for (final EStructuralFeature feature : eType.getEAllStructuralFeatures()) { if (feature.getName().equals("key")) { return feature; } } return null; } public Object getValueType() { final EClass eType = (EClass)this.eStructuralFeature.getEType(); for (final EStructuralFeature feature : eType.getEAllStructuralFeatures()) { if (feature.getName().equals("value")) { return feature; } } return null; } @Override protected Map< ? , ? > doGetMap(Object source) { EObject eObj = (EObject)source; return ((EMap< ? , ? >)eObj.eGet(eStructuralFeature)).map(); } @Override protected void doSetMap(Object source, Map map, MapDiff diff) { EObject eObject = (EObject)source; eObject.eSet(eStructuralFeature, map); } @Override public INativePropertyListener adaptListener(final ISimplePropertyListener listener) { return new EMFPropertyListener.EMFMapPropertyListener() { @Override protected IProperty getOwner() { return EMFMapProperty.this; } @Override protected ISimplePropertyListener getListener() { return listener; } @Override protected EStructuralFeature getFeature() { return eStructuralFeature; } }; } @Override public String toString() { String s = EMFPropertyHelper.propertyName(eStructuralFeature) + "{:}"; //$NON-NLS-1$ s += "<" + EMFPropertyHelper.shortClassName((EStructuralFeature)getKeyType()) + ", " //$NON-NLS-1$ //$NON-NLS-2$ + EMFPropertyHelper.shortClassName((EStructuralFeature)getValueType()) + ">"; //$NON-NLS-1$ return s; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy