/******************************************************************************* | |
* <copyright> | |
* | |
* Copyright (c) 2013, 2013 SAP AG. | |
* 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: | |
* SAP AG - initial API, implementation and documentation | |
* | |
* </copyright> | |
* | |
*******************************************************************************/ | |
package org.eclipse.fmc.blockdiagram.editor.meta.features; | |
import org.eclipse.emf.common.util.EList; | |
import org.eclipse.emf.ecore.EObject; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IDeleteContext; | |
import org.eclipse.graphiti.ui.features.DefaultDeleteFeature; | |
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil; | |
import org.eclipse.fmc.mm.FMCConnection; | |
import org.eclipse.fmc.mm.FMCNode; | |
/** | |
* Feature Class for deleting the graphical representation and the business | |
* model. | |
* | |
* @author Patrick Jahnke | |
* | |
*/ | |
public class FMCNodeDeleteFeature extends DefaultDeleteFeature { | |
/** | |
* Constructor just calls the super constructor. | |
* | |
* @param fp | |
* The FeatureProvider object. | |
*/ | |
public FMCNodeDeleteFeature(IFeatureProvider fp) { | |
super(fp); | |
} | |
/** | |
* Deleting all connections before calling the delete method of the super | |
* class. | |
*/ | |
@Override | |
public void delete(IDeleteContext context) { | |
EObject bo = FMCUtil.getBO(context.getPictogramElement()); | |
if (bo instanceof FMCNode) { | |
FMCNode node = (FMCNode) FMCUtil.getBO(context | |
.getPictogramElement()); | |
deleteConnections(node.getAllConnections()); | |
} | |
super.delete(context); | |
} | |
/** | |
* Delete all given connections. | |
* | |
* @param connections | |
* List of connections. | |
*/ | |
private void deleteConnections(EList<? extends FMCConnection> connections) { | |
EObject[] toDelete = new EObject[connections.size()]; | |
int i = 0; | |
for (FMCConnection con : connections) { | |
toDelete[i++] = con; | |
} | |
deleteBusinessObjects(toDelete); | |
} | |
} |