| //------------------------------------------------------------------------------ |
| // 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.process; |
| |
| import java.util.Collection; |
| import java.util.Collections; |
| import java.util.Iterator; |
| import java.util.List; |
| |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.util.EList; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.edit.command.CopyCommand.Helper; |
| import org.eclipse.emf.edit.domain.EditingDomain; |
| import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| import org.eclipse.emf.edit.provider.ItemProviderAdapter; |
| import org.eclipse.emf.edit.provider.ViewerNotification; |
| import org.eclipse.epf.library.edit.command.IActionManager; |
| import org.eclipse.epf.library.edit.process.command.WorkProductDescriptorCreateCopyCommand; |
| import org.eclipse.epf.library.edit.util.ProcessUtil; |
| import org.eclipse.epf.library.edit.util.TngUtil; |
| |
| import com.ibm.uma.Activity; |
| import com.ibm.uma.Artifact; |
| import com.ibm.uma.BreakdownElement; |
| import com.ibm.uma.Deliverable; |
| import com.ibm.uma.UmaPackage; |
| import com.ibm.uma.WorkProduct; |
| import com.ibm.uma.WorkProductDescriptor; |
| |
| /** |
| * @author Phong Nguyen Le |
| * @since 1.0 |
| */ |
| public class WorkProductDescriptorItemProvider extends DescriptorItemProvider { |
| |
| protected Activity activity; |
| |
| /** |
| * @param adapterFactory |
| */ |
| public WorkProductDescriptorItemProvider(AdapterFactory adapterFactory, |
| ItemProviderAdapter delegateItemProvider) { |
| super(adapterFactory, delegateItemProvider); |
| } |
| |
| public Activity getActivity(Object object) { |
| for (Object parent = getParent(object); parent != null;) { |
| if (parent instanceof Activity) |
| return (Activity) parent; |
| AdapterFactory aFactory = TngUtil |
| .getBestAdapterFactory(adapterFactory); |
| ItemProviderAdapter adapter = (ItemProviderAdapter) aFactory.adapt( |
| parent, ITreeItemContentProvider.class); |
| parent = adapter.getParent(parent); |
| } |
| return null; |
| } |
| |
| private Object getDescriptor(Object parentDescriptor, Artifact artifact) { |
| Activity activity = getActivity(parentDescriptor); |
| if (activity == null) |
| return null; |
| List list = activity.getBreakdownElements(); |
| int size = list.size(); |
| for (int i = 0; i < size; i++) { |
| Object obj = list.get(i); |
| if ((obj instanceof WorkProductDescriptor) |
| && (artifact == ((WorkProductDescriptor) obj) |
| .getWorkProduct())) { |
| return obj; |
| } |
| } |
| return null; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildrenFeatures(java.lang.Object) |
| */ |
| public Collection getChildrenFeatures(Object object) { |
| // if (childrenFeatures == null) |
| // { |
| // childrenFeatures = new ArrayList(); |
| // childrenFeatures.add(UmaPackage.eINSTANCE.getWorkProductDescriptor_DeliverableParts()); |
| // } |
| // return childrenFeatures; |
| |
| return Collections.EMPTY_LIST; |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see org.eclipse.emf.edit.provider.ItemProviderAdapter#getChildren(java.lang.Object) |
| */ |
| public Collection getChildren(Object object) { |
| WorkProductDescriptor wpDesc = (WorkProductDescriptor) object; |
| Collection children = super.getChildren(object); |
| |
| // add deliverable parts |
| // |
| for (Iterator iter = wpDesc.getDeliverableParts().iterator(); iter |
| .hasNext();) { |
| WorkProductDescriptor desc = (WorkProductDescriptor) iter.next(); |
| if (desc.getSuperActivities().isEmpty()) { |
| children.add(desc); |
| } |
| } |
| |
| // FIXME: change to support filter |
| if (wpDesc.getWorkProduct() instanceof Artifact) { |
| Artifact artifact = (Artifact) wpDesc.getWorkProduct(); |
| List list = artifact.getContainedArtifacts(); |
| for (int i = 0; i < list.size(); i++) { |
| Object descriptor = getDescriptor(object, (Artifact) list |
| .get(i)); |
| if (descriptor != null) { |
| children.add(descriptor); |
| } |
| } |
| } |
| |
| // set parent |
| // |
| AdapterFactory aFactory = TngUtil.getBestAdapterFactory(adapterFactory); |
| |
| for (Iterator iter = children.iterator(); iter.hasNext();) { |
| IBSItemProvider adapter = (IBSItemProvider) aFactory.adapt(iter |
| .next(), ITreeItemContentProvider.class); |
| adapter.setParent(object); |
| } |
| |
| return children; |
| } |
| |
| public void notifyChanged(Notification notification) { |
| switch (notification.getFeatureID(WorkProductDescriptor.class)) { |
| case UmaPackage.WORK_PRODUCT_DESCRIPTOR__ACTIVITY_ENTRY_STATE: |
| case UmaPackage.WORK_PRODUCT_DESCRIPTOR__ACTIVITY_EXIT_STATE: |
| fireNotifyChanged(new ViewerNotification(notification, notification |
| .getNotifier(), false, true)); |
| return; |
| case UmaPackage.WORK_PRODUCT_DESCRIPTOR__DELIVERABLE_PARTS: |
| List elements = ProcessUtil.getAffectedElements(notification, null); |
| int eventType = notification.getEventType(); |
| boolean refresh = false; |
| for (Iterator iter = elements.iterator(); iter.hasNext();) { |
| BreakdownElement e = (BreakdownElement) iter.next(); |
| if (eventType == Notification.ADD |
| || eventType == Notification.ADD_MANY) { |
| ProcessUtil.addToContainer(e, this, false); |
| } |
| if (!e.getSuperActivities().isEmpty()) { |
| fireNotifyChanged(new ViewerNotification(notification, e, |
| false, true)); |
| } else { |
| refresh = true; |
| } |
| } |
| |
| if (refresh) { |
| fireNotifyChanged(new ViewerNotification(notification, |
| notification.getNotifier(), true, false)); |
| } |
| |
| return; |
| case UmaPackage.DESCRIBABLE_ELEMENT__PRESENTATION_NAME: |
| WorkProductDescriptor wpd = (WorkProductDescriptor) notification |
| .getNotifier(); |
| fireNotifyChanged(new ViewerNotification(notification, wpd, false, |
| true)); |
| if (wpd.getWorkProduct() instanceof Deliverable) { |
| for (Iterator iter = wpd.getDeliverableParts().iterator(); iter |
| .hasNext();) { |
| Object descriptor = iter.next(); |
| fireNotifyChanged(new ViewerNotification(notification, |
| descriptor, false, true)); |
| } |
| } |
| return; |
| } |
| |
| super.notifyChanged(notification); |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.process.IBSItemProvider#setAttribute(java.lang.Object, |
| * java.lang.String, java.lang.String) |
| */ |
| public void setAttribute(Object object, String prop, String txt) { |
| WorkProductDescriptor wpd = (WorkProductDescriptor) object; |
| |
| if (prop == IBSItemProvider.COL_ENTRY_STATE) { |
| wpd.setActivityEntryState(txt); |
| } else if (prop == IBSItemProvider.COL_EXIT_STATE) { |
| wpd.setActivityExitState(txt); |
| } else { |
| super.setAttribute(object, prop, txt); |
| } |
| } |
| |
| // private boolean isTopLevelArtifactInActivity(Activity activity, Object |
| // obj) |
| // { |
| // AdapterFactory aFactory = TngUtil.getBestAdapterFactory(adapterFactory); |
| // |
| // BSActivityItemProvider adapter = (BSActivityItemProvider) |
| // aFactory.adapt(activity, ITreeItemContentProvider.class); |
| // Collection children = adapter.getChildren(activity); |
| // if (children.contains(obj)) |
| // { |
| // //System.out.println("child - " + obj); |
| // return true; |
| // } |
| // return false; |
| // } |
| |
| public Collection getEClasses() { |
| return ProcessUtil.getPBSEclasses(); |
| } |
| |
| public void moveUp(Object obj, IActionManager actionMgr) { |
| Object parent = this.getParent(obj); |
| if ((parent != null) && (parent instanceof Activity)) { |
| TngUtil.moveUp((Activity) parent, obj, getEClasses(), actionMgr); |
| } |
| if ((parent != null) && (parent instanceof WorkProductDescriptor)) { |
| WorkProduct wp = ((WorkProductDescriptor) parent).getWorkProduct(); |
| if (wp instanceof Artifact) { |
| Artifact artifact = (Artifact) wp; |
| List list = artifact.getContainedArtifacts(); |
| WorkProduct objWP = ((WorkProductDescriptor) obj) |
| .getWorkProduct(); |
| |
| int location = 0; |
| // List newList = new ArrayList(); |
| for (int i = 0; i < list.size(); i++) { |
| if (objWP.equals(list.get(i))) { |
| location = i; |
| break; |
| } |
| } |
| |
| ((EList) artifact.getContainedArtifacts()).move(location, |
| location - 1); |
| } |
| |
| Activity activity = this.getActivity(obj); |
| TngUtil.moveUp(activity, obj, getEClasses(), actionMgr); |
| } |
| } |
| |
| public void moveDown(Object obj, IActionManager actionMgr) { |
| Object parent = this.getParent(obj); |
| if ((parent != null) && (parent instanceof Activity)) { |
| TngUtil.moveDown((Activity) parent, obj, getEClasses(), actionMgr); |
| } |
| if ((parent != null) && (parent instanceof WorkProductDescriptor)) { |
| WorkProduct wp = ((WorkProductDescriptor) parent).getWorkProduct(); |
| if (wp instanceof Artifact) { |
| Artifact artifact = (Artifact) wp; |
| List list = artifact.getContainedArtifacts(); |
| WorkProduct objWP = ((WorkProductDescriptor) obj) |
| .getWorkProduct(); |
| |
| int location = 0; |
| // List newList = new ArrayList(); |
| for (int i = 0; i < list.size(); i++) { |
| if (objWP.equals(list.get(i))) { |
| location = i; |
| break; |
| } |
| } |
| |
| ((EList) artifact.getContainedArtifacts()).move(location, |
| location + 1); |
| } |
| |
| Activity activity = this.getActivity(obj); |
| TngUtil.moveDown(activity, obj, getEClasses(), actionMgr); |
| } |
| } |
| |
| /* |
| * (non-Javadoc) |
| * |
| * @see com.ibm.library.edit.process.BreakdownElementItemProvider#createCreateCopyCommand(org.eclipse.emf.edit.domain.EditingDomain, |
| * org.eclipse.emf.ecore.EObject, |
| * org.eclipse.emf.edit.command.CopyCommand.Helper) |
| */ |
| protected Command createCreateCopyCommand(EditingDomain domain, |
| EObject owner, Helper helper) { |
| return new WorkProductDescriptorCreateCopyCommand(domain, owner, helper); |
| } |
| |
| } |