| //------------------------------------------------------------------------------ |
| // Copyright (c) 2005, 2007 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.diagramming.base.view; |
| |
| import java.util.Collection; |
| import java.util.Iterator; |
| |
| import org.eclipse.emf.common.notify.Notification; |
| import org.eclipse.emf.common.notify.impl.AdapterImpl; |
| import org.eclipse.emf.ecore.EModelElement; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| import org.eclipse.epf.diagram.core.bridge.BridgeHelper; |
| import org.eclipse.epf.diagramming.base.util.DiagramChangeListener; |
| import org.eclipse.epf.diagramming.base.util.IDiagramChangeListener; |
| import org.eclipse.epf.diagramming.base.util.UmaUmlUtil; |
| import org.eclipse.epf.library.edit.IFilter; |
| import org.eclipse.epf.library.edit.process.BSActivityItemProvider; |
| import org.eclipse.epf.library.edit.process.BreakdownElementWrapperItemProvider; |
| import org.eclipse.epf.library.edit.process.IBSItemProvider; |
| import org.eclipse.epf.library.edit.util.ProcessUtil; |
| import org.eclipse.epf.library.edit.util.Suppression; |
| import org.eclipse.epf.uma.Activity; |
| import org.eclipse.epf.uma.MethodElement; |
| import org.eclipse.epf.uma.UmaPackage; |
| import org.eclipse.gmf.runtime.notation.Diagram; |
| import org.eclipse.gmf.runtime.notation.NotationPackage; |
| import org.eclipse.uml2.uml.NamedElement; |
| |
| /** |
| * Extended implementation of {@link org.eclipse.gmf.runtime.notation.impl.DiagramImpl} |
| * to add adapters to UMA {@link MethodElement} and {@link Diagram} |
| * |
| * Not Useful , not complete. Temporary solution. Defect at time of resource load. |
| * |
| * @author Shashidhar Kannoori |
| */ |
| public class DiagramImpl extends |
| org.eclipse.gmf.runtime.notation.impl.DiagramImpl { |
| |
| Object object; |
| private boolean notificationEnabled = true; |
| private boolean readOnly = false; |
| protected IDiagramChangeListener diagramChangeListener; |
| private Activity baseAct; |
| |
| // still need to use below these |
| private Suppression suppression; |
| protected BreakdownElementWrapperItemProvider wrapper; |
| protected IFilter filter; |
| |
| public DiagramImpl() { |
| } |
| |
| /* |
| * (non-Javadoc) |
| * @see org.eclipse.gmf.runtime.notation.impl.ViewImpl#setElement(org.eclipse.emf.ecore.EObject) |
| */ |
| public void setElement(EObject newElement) { |
| super.setElement(newElement); |
| // Check for BreakdownElementWrapperItemProvider and readonly. |
| object = BridgeHelper.getMethodElementFromAnnotation((EModelElement)newElement); |
| if (object != null) { |
| Activity e = (Activity) object; |
| if (ProcessUtil.isExtendingOrLocallyContributing(e)) { |
| baseAct = (Activity) e.getVariabilityBasedOnElement(); |
| } |
| baseAct = null; |
| |
| if(diagramChangeListener ==null){ |
| diagramChangeListener = new ActivityDiagramChangeListener(e, this); |
| } |
| |
| if(diagramChangeListener != null){ |
| e.eAdapters().add(diagramChangeListener); |
| } |
| |
| if (baseAct != null) { |
| baseAct.eAdapters().add(diagramChangeListener); |
| } |
| this.eAdapters().add(new DiagramNotationChangeListener()); |
| } |
| } |
| |
| /** |
| * To set the UmaElement object can be {@link Activity} or {@link BreakdownElementWrapperItemProvider} |
| */ |
| public void setUmaElement(Object object){ |
| this.object = object; |
| } |
| |
| |
| /** |
| * |
| * @author Shashidhar Kannoori |
| * |
| */ |
| public class ActivityDiagramChangeListener extends DiagramChangeListener{ |
| public ActivityDiagramChangeListener(MethodElement e, Diagram d) { |
| super(e, d); |
| } |
| public void notifyChanged(Notification msg) { |
| if (!notificationEnabled ) |
| return; |
| notificationEnabled = false; |
| try { |
| //Object obj; |
| switch (msg.getFeatureID(Activity.class)) { |
| case UmaPackage.ACTIVITY__BREAKDOWN_ELEMENTS: |
| switch (msg.getEventType()) { |
| case Notification.ADD: |
| System.out.println("Notification Add"); |
| break; |
| case Notification.REMOVE: |
| System.out.println("Notification Removed"); |
| break; |
| case Notification.ADD_MANY: |
| System.out.println("Notification ADD_MANY"); |
| break; |
| case Notification.REMOVE_MANY: |
| System.out.println("Notification REMOVE_MANY"); |
| break; |
| case Notification.MOVE: |
| System.out.println("Notification MOVE"); |
| break; |
| } |
| break; |
| } |
| } |
| finally { |
| notificationEnabled = true; |
| } |
| super.notifyChanged(msg); |
| } |
| } |
| |
| /** |
| * |
| * @author Shashidhar Kannoori |
| * |
| */ |
| public class DiagramNotationChangeListener extends AdapterImpl{ |
| |
| public void notifyChanged(Notification msg) { |
| if (!notificationEnabled) |
| return; |
| notificationEnabled = false; |
| try { |
| //Activity act = (Activity) getObject(); |
| switch (msg.getFeatureID(Diagram.class)) { |
| case NotationPackage.DIAGRAM__PERSISTED_CHILDREN: |
| // System.out.println(".notifyChanged(): index=" + |
| // msg.getPosition()); |
| Collection collection; |
| switch (msg.getEventType()) { |
| case Notification.ADD: |
| nodeAdded(msg.getPosition(), msg |
| .getNewValue()); |
| return; |
| case Notification.REMOVE: |
| nodeRemoved(msg.getOldValue()); |
| return; |
| case Notification.ADD_MANY: |
| collection = (Collection) msg.getNewValue(); |
| for (Iterator iter = collection.iterator(); iter |
| .hasNext();) { |
| Object node = iter.next(); |
| nodeAdded(msg.getPosition(), node); |
| } |
| |
| return; |
| case Notification.REMOVE_MANY: |
| collection = (Collection) msg.getOldValue(); |
| for (Iterator iter = collection.iterator(); iter |
| .hasNext();) { |
| nodeRemoved(iter.next()); |
| } |
| return; |
| } |
| |
| } |
| } finally { |
| notificationEnabled = true; |
| } |
| } |
| } |
| |
| |
| public void nodeAdded(int position, Object object) { |
| // TODO Auto-generated method stub |
| System.out.println("Notation notification add"+object); |
| } |
| |
| public void nodeRemoved(Object object) { |
| // TODO Auto-generated method stub |
| System.out.println("Notation notification remove" + object); |
| } |
| |
| public boolean isReadOnly() { |
| return readOnly; |
| } |
| |
| public void setReadOnly(boolean readOnly) { |
| this.readOnly = readOnly; |
| } |
| |
| protected void extractChildren(ITreeItemContentProvider adapter, Object object, Collection children) { |
| // disable rollup before getting the children |
| // |
| boolean oldRolledUp = false; |
| if(adapter instanceof BSActivityItemProvider) { |
| BSActivityItemProvider itemProvider = (BSActivityItemProvider)adapter; |
| oldRolledUp = itemProvider.isRolledUp(); |
| itemProvider.basicSetRolledUp(false); |
| } |
| else if(adapter instanceof IBSItemProvider){ |
| IBSItemProvider itemProvider = (IBSItemProvider)adapter; |
| oldRolledUp = itemProvider.isRolledUp(); |
| itemProvider.setRolledUp(false); |
| } |
| |
| try { |
| // filter out the suppressed elements |
| // |
| for (Iterator iter = adapter.getChildren(object).iterator(); iter.hasNext();) { |
| Object child = iter.next(); |
| if(!getSuppression().isSuppressed(child)) { |
| children.add(child); |
| } |
| } |
| |
| // don't filter suppressed elements |
| // |
| //children.addAll(adapter.getChildren(object)); |
| } |
| finally { |
| // restore the rolled-up flag |
| // |
| if(adapter instanceof IBSItemProvider) { |
| ((IBSItemProvider)adapter).setRolledUp(oldRolledUp); |
| } |
| } |
| } |
| |
| public Suppression getSuppression() { |
| return suppression; |
| } |
| |
| public void setSuppression(Suppression suppression) { |
| this.suppression = suppression; |
| } |
| } |