| //------------------------------------------------------------------------------ |
| // 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.configuration; |
| |
| import java.util.Collection; |
| import java.util.List; |
| |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.eclipse.emf.ecore.EStructuralFeature; |
| import org.eclipse.emf.edit.provider.ItemProviderAdapter; |
| import org.eclipse.epf.library.edit.IConfigurator; |
| import org.eclipse.epf.library.services.SafeUpdateController; |
| import org.eclipse.epf.library.util.LibraryUtil; |
| import org.eclipse.jface.viewers.Viewer; |
| |
| import com.ibm.uma.MethodConfiguration; |
| import com.ibm.uma.MethodElement; |
| import com.ibm.uma.MethodPackage; |
| |
| /** |
| * @author Phong Nguyen Le |
| * @author Jinhua Xi |
| * @since 1.0 |
| */ |
| public class ConfigurationFilter extends AdapterImpl implements IConfigurator { |
| |
| protected MethodConfiguration methodConfig; |
| |
| private Viewer viewer; |
| |
| public ConfigurationFilter(MethodConfiguration methodConfig, Viewer viewer) { |
| this.methodConfig = methodConfig; |
| this.viewer = viewer; |
| } |
| |
| /** |
| * @see org.eclipse.epf.library.edit.IFilter#accept(java.lang.Object) |
| */ |
| public boolean accept(Object obj) { |
| if (methodConfig == null) |
| return true; |
| |
| obj = LibraryUtil.unwrap(obj); |
| |
| if (obj instanceof MethodPackage) { |
| return methodConfig.getMethodPackageSelection().contains(obj); |
| } else if (obj instanceof MethodElement) { |
| return ConfigurationHelper.canShow((MethodElement) obj, |
| methodConfig); |
| } else if (obj instanceof ItemProviderAdapter) { |
| return true; |
| } else { |
| System.out |
| .println("Object filtered: " + (obj == null ? null : obj.toString())); //$NON-NLS-1$ |
| } |
| return false; |
| } |
| |
| public Collection getChildren(Object obj, EStructuralFeature childFeature) { |
| if (methodConfig == null) |
| return null; |
| |
| if (childFeature != null && childFeature.isMany()) { |
| if (obj instanceof MethodElement) { |
| ElementRealizer realizer = new ElementRealizer(methodConfig); |
| |
| // discard the contributors |
| realizer.setDiscardContributor(true); |
| |
| List value = ConfigurationHelper.calc0nFeatureValue( |
| (MethodElement) obj, childFeature, methodConfig, |
| realizer); |
| return value; |
| } |
| } |
| |
| return null; |
| } |
| |
| /** |
| * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification) |
| */ |
| public void notifyChanged(final Notification msg) { |
| if (viewer == null) { |
| return; |
| } |
| |
| SafeUpdateController.syncExec(new Runnable() { |
| public void run() { |
| switch (msg.getEventType()) { |
| case Notification.ADD: |
| case Notification.ADD_MANY: |
| case Notification.REMOVE: |
| case Notification.REMOVE_MANY: |
| viewer.refresh(); |
| } |
| } |
| }); |
| |
| } |
| |
| /** |
| * @see org.eclipse.epf.library.edit.IConfigurator#getMethodConfiguration() |
| */ |
| public MethodConfiguration getMethodConfiguration() { |
| return methodConfig; |
| } |
| |
| /** |
| * @see org.eclipse.epf.library.edit.IConfigurator#setMethodConfiguration(com.ibm.uma.MethodConfiguration) |
| */ |
| public void setMethodConfiguration(MethodConfiguration config) { |
| methodConfig = config; |
| } |
| |
| } |