PackageItemSemanticEditPolicy.java
Go to the documentation of this file.
00001 package org.ros.model.ros.diagram.edit.policies;
00002 
00003 import java.util.Iterator;
00004 
00005 import org.eclipse.emf.ecore.EAnnotation;
00006 import org.eclipse.gef.commands.Command;
00007 import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
00008 import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
00009 import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
00010 import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
00011 import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
00012 import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyRequest;
00013 import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
00014 import org.eclipse.gmf.runtime.notation.Node;
00015 import org.eclipse.gmf.runtime.notation.View;
00016 import org.ros.model.ros.diagram.edit.parts.NodeEditPart;
00017 import org.ros.model.ros.diagram.edit.parts.PackagePackageContentCompartmentEditPart;
00018 import org.ros.model.ros.diagram.part.RosVisualIDRegistry;
00019 import org.ros.model.ros.diagram.providers.RosElementTypes;
00020 
00024 public class PackageItemSemanticEditPolicy extends
00025                 RosBaseItemSemanticEditPolicy {
00026 
00030         public PackageItemSemanticEditPolicy() {
00031                 super(RosElementTypes.Package_2001);
00032         }
00033 
00037         protected Command getSemanticCommand(IEditCommandRequest request) {
00038                 if (request instanceof DestroyRequest) {
00039                         return null;
00040                 }
00041                 return super.getSemanticCommand(request);
00042         }
00043 
00047         protected Command getDestroyElementCommand(DestroyElementRequest req) {
00048                 View view = (View) getHost().getModel();
00049                 CompositeTransactionalCommand cmd = new CompositeTransactionalCommand(
00050                                 getEditingDomain(), null);
00051                 cmd.setTransactionNestingEnabled(false);
00052                 EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
00053                 if (annotation == null) {
00054                         // there are indirectly referenced children, need extra commands: false
00055                         addDestroyChildNodesCommand(cmd);
00056                         addDestroyShortcutsCommand(cmd, view);
00057                         // delete host element
00058                         cmd.add(new DestroyElementCommand(req));
00059                 } else {
00060                         cmd.add(new DeleteCommand(getEditingDomain(), view));
00061                 }
00062                 return getGEFWrapper(cmd.reduce());
00063         }
00064 
00068         private void addDestroyChildNodesCommand(ICompositeCommand cmd) {
00069                 View view = (View) getHost().getModel();
00070                 for (Iterator<?> nit = view.getChildren().iterator(); nit.hasNext();) {
00071                         Node node = (Node) nit.next();
00072                         switch (RosVisualIDRegistry.getVisualID(node)) {
00073                         case PackagePackageContentCompartmentEditPart.VISUAL_ID:
00074                                 for (Iterator<?> cit = node.getChildren().iterator(); cit
00075                                                 .hasNext();) {
00076                                         Node cnode = (Node) cit.next();
00077                                         switch (RosVisualIDRegistry.getVisualID(cnode)) {
00078                                         case NodeEditPart.VISUAL_ID:
00079                                                 cmd.add(new DestroyElementCommand(
00080                                                                 new DestroyElementRequest(getEditingDomain(),
00081                                                                                 cnode.getElement(), false))); // directlyOwned: true
00082                                                 // don't need explicit deletion of cnode as parent's view deletion would clean child views as well 
00083                                                 // cmd.add(new org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand(getEditingDomain(), cnode));
00084                                                 break;
00085                                         }
00086                                 }
00087                                 break;
00088                         }
00089                 }
00090         }
00091 
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


bride_plugin_source
Author(s): Alexander Bubeck
autogenerated on Wed Aug 14 2013 10:06:09