Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » GlazedLists & EMF(Javabeans is gone...)
GlazedLists & EMF [message #901791] Tue, 14 August 2012 15:21 Go to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
Hello,

until now i was using my homebrewn javabean observerpattern;
now i changed to EMF which uses its own patterns;
so when i try to run my old code for nattable,
it runs into an exception which tells:
Couldn't find listener methods for formTest.TestObject

which is pretty simple due the fact that there is no more bean support due EMF.

so, do i still need the glazedlists for internal sorting, grouping etc, or are those lists only for updating the data (which emf does now)?
or does anyone know how i can add the needed features to my EMF classes without much of a hassle...

Thanks in Advance
lumo
Re: GlazedLists & EMF [message #901794 is a reply to message #901791] Tue, 14 August 2012 15:28 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Hi,

GlazedLists support is an extension to NatTable core. So you can use GlazedLists for sorting, filtering and trees but you don't have to if you find another way. My first steps with NatTable didn't use GlazedLists while I've found out that using them make sorting and filtering much easier. Also the tree functionality is based on GlazedLists.

Dependent on which features of the NatTable you are using it can be quite easy to remove the GlazedLists dependencies. If you are using trees it could become quite difficult.

Greez,
Dirk
Re: GlazedLists & EMF [message #902732 is a reply to message #901794] Mon, 20 August 2012 07:52 Go to previous messageGo to next message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
after looking through my code, i'd say i need the glazedlists.
and in the meantime i worked out how to transform the notifications from emf to the needed updates for the lists.
it was tricky but still worth the work.

edit: fixed all problems, now also accessing subobjects is working with EMF FeaturePaths! Very Happy

[Updated on: Mon, 20 August 2012 08:19]

Report message to a moderator

Re: GlazedLists & EMF [message #904017 is a reply to message #902732] Mon, 20 August 2012 11:21 Go to previous messageGo to next message
Martin Jacob is currently offline Martin JacobFriend
Messages: 191
Registered: July 2009
Senior Member
Hi Ludwig,

I am also using an EMF model and want to display the properties in NatTable. How did you transform
the notifications between EMF model and NatTable?

Martin

Ludwig Moser wrote, On 20.08.2012 09:52:
> after looking through my code, i'd say i need the glazedlists.
> and in the meantime i worked out how to transform the notifications from emf to the needed updates
> for the lists.
> it was tricky but still worth the work.
>
> my only problem i got left is when the object displayed is not an attribute of the main object
> rather than a subobject on the object with an attribute i want to gain...
Re: GlazedLists & EMF [message #912915 is a reply to message #904017] Fri, 14 September 2012 11:47 Go to previous message
Ludwig Moser is currently offline Ludwig MoserFriend
Messages: 476
Registered: July 2009
Senior Member
late reply, sorry

i defined an interface:
 * <copyright>
package lumo.ecore.emf;

import java.beans.PropertyChangeEvent;

/**
 * <!-- begin-user-doc -->
 * A representation of the model object '<em><b>Java Bean Support</b></em>'.
 * <!-- end-user-doc -->
 *
 * <p>
 * The following features are supported:
 * <ul>
 *   <li>{@link formTest.JavaBeanSupport#getListeners <em>Listeners</em>}</li>
 * </ul>
 * </p>
 *
 * @see formTest.FormTestPackage#getJavaBeanSupport()
 * @model
 * @generated
 */
public interface JavaBeanSupport extends EObject {
	/**
	 * Returns the value of the '<em><b>Listeners</b></em>' attribute list.
	 * The list contents are of type {@link java.beans.PropertyChangeListener}.
	 * <!-- begin-user-doc -->
	 * <p>
	 * If the meaning of the '<em>Listeners</em>' attribute list isn't clear,
	 * there really should be more of a description here...
	 * </p>
	 * <!-- end-user-doc -->
	 * @return the value of the '<em>Listeners</em>' attribute list.
	 * @see formTest.FormTestPackage#getJavaBeanSupport_Listeners()
	 * @model dataType="formTest.PropertyChangeListener"
	 * @generated
	 */
	EList<PropertyChangeListener> getListeners();

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @model listenerDataType="formTest.PropertyChangeListener"
	 * @generated
	 */
	void addPropertyChangeListener(PropertyChangeListener listener);

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @model listenerDataType="formTest.PropertyChangeListener"
	 * @generated
	 */
	void removePropertyChangeListener(PropertyChangeListener listener);

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @model evtDataType="formTest.PropertyChangeEvent"
	 * @generated
	 */
	void propertyChange(PropertyChangeEvent evt);

} // JavaBeanSupport



and then implemented it:
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;

import lumo.ecore.emf.JavaBeanSupport;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EDataTypeUniqueEList;

import formTest.FormTestPackage;

/**
 * <!-- begin-user-doc --> An implementation of the model object '
 * <em><b>Java Bean Support</b></em>'. <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 * <li>{@link formTest.impl.JavaBeanSupportImpl#getListeners <em>Listeners</em>}
 * </li>
 * </ul>
 * </p>
 * 
 * @generated
 */
public class JavaBeanSupportImpl extends EObjectImpl implements JavaBeanSupport {

	/**
	 * The cached value of the '{@link #getListeners() <em>Listeners</em>}'
	 * attribute list. <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @see #getListeners()
	 * @generated
	 * @ordered
	 */
	protected EList<PropertyChangeListener> listeners;
	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	Adapter adapter = new AdapterImpl() {
		public void notifyChanged(Notification n) {
			System.out
					.println("Notfication received from the data model. Data model has changed!!!");

			System.out.println("n.getFeature().getClass().getSimpleName() = "
					+ n.getFeature().getClass().getSimpleName());
			EStructuralFeature feature = (EStructuralFeature) n.getFeature();
			if (feature == null) {
				return;
			}
			String propertyName = feature.getName();
			// System.out.println("n.getFeature(): "+attr.getName());
			PropertyChangeEvent evt = new PropertyChangeEvent(n.getNotifier(),
					propertyName, n.getOldValue(), n.getNewValue());
			getBean().propertyChange(evt);
		}
	};

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public JavaBeanSupportImpl() {
		super();
	}

	protected JavaBeanSupport getBean() {
		return this;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return FormTestPackage.Literals.JAVA_BEAN_SUPPORT;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public EList<PropertyChangeListener> getListeners() {
		if (listeners == null) {
			listeners = new EDataTypeUniqueEList<PropertyChangeListener>(
					PropertyChangeListener.class, this,
					FormTestPackage.JAVA_BEAN_SUPPORT__LISTENERS);
		}
		return listeners;
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		getListeners().add(listener);
		eAdapters().add(adapter);
		// throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated NOT
	 */
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		getListeners().remove(listener);
		eAdapters().remove(adapter);
		// throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	public void propertyChange(PropertyChangeEvent evt) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case FormTestPackage.JAVA_BEAN_SUPPORT__LISTENERS:
			return getListeners();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case FormTestPackage.JAVA_BEAN_SUPPORT__LISTENERS:
			getListeners().clear();
			getListeners().addAll(
					(Collection<? extends PropertyChangeListener>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case FormTestPackage.JAVA_BEAN_SUPPORT__LISTENERS:
			getListeners().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case FormTestPackage.JAVA_BEAN_SUPPORT__LISTENERS:
			return listeners != null && !listeners.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc -->
	 * 
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy())
			return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (listeners: ");
		result.append(listeners);
		result.append(')');
		return result.toString();
	}

} // JavaBeanSupportImpl


there is some unneeded console log but it should work
let me know if it helped

EDIT: referring to this forum post this solution is not perfect. (but hey, its one!)
http://www.eclipse.org/forums/index.php/m/902757/#msg_902757

[Updated on: Fri, 14 September 2012 11:53]

Report message to a moderator

Previous Topic:TreeNatTableExample - single selection on expand/collapse image doesn't work
Next Topic:IDataProvider
Goto Forum:
  


Current Time: Fri Apr 26 07:28:49 GMT 2024

Powered by FUDForum. Page generated in 0.03223 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top