| /******************************************************************************* |
| * Copyright (c) 2006 Borland Software 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: |
| * Borland Software Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.gmf.examples.mindmap.diagram.edit.policies; |
| |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| import org.eclipse.gef.commands.Command; |
| import org.eclipse.gmf.examples.mindmap.MindmapPackage; |
| import org.eclipse.gmf.examples.mindmap.diagram.providers.MindmapElementTypes; |
| import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; |
| import org.eclipse.gmf.runtime.emf.commands.core.commands.DuplicateEObjectsCommand; |
| import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; |
| import org.eclipse.gmf.runtime.emf.type.core.requests.DuplicateElementsRequest; |
| import org.eclipse.gmf.runtime.notation.View; |
| |
| /** |
| * @generated |
| */ |
| public class MapItemSemanticEditPolicy extends MindmapBaseItemSemanticEditPolicy { |
| |
| /** |
| * @generated |
| */ |
| protected Command getCreateCommand(CreateElementRequest req) { |
| if (MindmapElementTypes.Topic_1001 == req.getElementType()) { |
| if (req.getContainmentFeature() == null) { |
| req.setContainmentFeature(MindmapPackage.eINSTANCE.getMap_RootTopics()); |
| } |
| return getMSLWrapper(new CreateTopic_1001Command(req)); |
| } |
| if (MindmapElementTypes.Resource_1002 == req.getElementType()) { |
| if (req.getContainmentFeature() == null) { |
| req.setContainmentFeature(MindmapPackage.eINSTANCE.getMap_Resources()); |
| } |
| return getMSLWrapper(new CreateResource_1002Command(req)); |
| } |
| return super.getCreateCommand(req); |
| } |
| |
| /** |
| * @generated |
| */ |
| private static class CreateTopic_1001Command extends CreateElementCommand { |
| |
| /** |
| * @generated |
| */ |
| public CreateTopic_1001Command(CreateElementRequest req) { |
| super(req); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EClass getEClassToEdit() { |
| return MindmapPackage.eINSTANCE.getMap(); |
| }; |
| |
| /** |
| * @generated |
| */ |
| protected EObject getElementToEdit() { |
| EObject container = ((CreateElementRequest) getRequest()).getContainer(); |
| if (container instanceof View) { |
| container = ((View) container).getElement(); |
| } |
| return container; |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| private static class CreateResource_1002Command extends CreateElementCommand { |
| |
| /** |
| * @generated |
| */ |
| public CreateResource_1002Command(CreateElementRequest req) { |
| super(req); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected EClass getEClassToEdit() { |
| return MindmapPackage.eINSTANCE.getMap(); |
| }; |
| |
| /** |
| * @generated |
| */ |
| protected EObject getElementToEdit() { |
| EObject container = ((CreateElementRequest) getRequest()).getContainer(); |
| if (container instanceof View) { |
| container = ((View) container).getElement(); |
| } |
| return container; |
| } |
| } |
| |
| /** |
| * @generated |
| */ |
| protected Command getDuplicateCommand(DuplicateElementsRequest req) { |
| TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain(); |
| return getMSLWrapper(new DuplicateAnythingCommand(editingDomain, req)); |
| } |
| |
| /** |
| * @generated |
| */ |
| private static class DuplicateAnythingCommand extends DuplicateEObjectsCommand { |
| |
| /** |
| * @generated |
| */ |
| public DuplicateAnythingCommand(TransactionalEditingDomain editingDomain, DuplicateElementsRequest req) { |
| super(editingDomain, req.getLabel(), req.getElementsToBeDuplicated(), req.getAllDuplicatedElementsMap()); |
| } |
| } |
| } |