blob: ca9b04e995526009f889a9728b92a2652bf4cc0a [file] [log] [blame]
//------------------------------------------------------------------------------
// Copyright (c) 2005, 2006 IBM Corporation and others.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// Contributors:
// IBM Corporation - initial implementation
//------------------------------------------------------------------------------
package org.eclipse.epf.library.edit.category;
import java.util.Iterator;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.impl.AdapterImpl;
import org.eclipse.emf.ecore.EObject;
import com.ibm.uma.MethodElement;
import com.ibm.uma.UmaPackage;
/**
* @author Phong Nguyen Le
* @since 1.0
*/
public class NameChangeListener extends AdapterImpl {
private MethodElement element;
public NameChangeListener(MethodElement e) {
element = e;
}
public MethodElement getChangeConsumer() {
return element;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
*/
public void notifyChanged(Notification msg) {
switch (msg.getFeatureID(MethodElement.class)) {
case UmaPackage.METHOD_ELEMENT__NAME:
element.setName((String) msg.getNewValue());
return;
}
}
public static void removeAdapter(EObject target, Object consumer) {
for (Iterator iter = target.eAdapters().iterator(); iter.hasNext();) {
Object adapter = (Object) iter.next();
if (adapter instanceof NameChangeListener
&& ((NameChangeListener) adapter).element == consumer) {
iter.remove();
return;
}
}
}
/**
* @param baseCategory
* @param category
* @return
*/
public static NameChangeListener getAdapter(EObject target, Object category) {
for (Iterator iter = target.eAdapters().iterator(); iter.hasNext();) {
Object adapter = (Object) iter.next();
NameChangeListener listener;
if (adapter instanceof NameChangeListener
&& (listener = (NameChangeListener) adapter).element == category) {
return listener;
}
}
return null;
}
}