/******************************************************************************* | |
* <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.features; | |
import org.eclipse.graphiti.features.IFeatureProvider; | |
import org.eclipse.graphiti.features.context.IRemoveContext; | |
import org.eclipse.graphiti.features.impl.DefaultRemoveFeature; | |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; | |
import org.eclipse.graphiti.mm.pictograms.PictogramElement; | |
import org.eclipse.graphiti.mm.pictograms.Shape; | |
/** | |
* This Remove feature removes all connections including those that are pointing | |
* to/from child shapes. | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public class DeepRemoveFeature extends DefaultRemoveFeature { | |
/** | |
* Main constructor. | |
* | |
* @param featureProvider | |
* The feature provider. | |
*/ | |
public DeepRemoveFeature(IFeatureProvider featureProvider) { | |
super(featureProvider); | |
} | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.impl.DefaultRemoveFeature#preRemove(org | |
* .eclipse.graphiti.features.context.IRemoveContext) | |
*/ | |
@Override | |
public void preRemove(IRemoveContext context) { | |
PictogramElement pe = context.getPictogramElement(); | |
if (pe instanceof ContainerShape) { | |
removeConnectionsFromAllChildren((ContainerShape) pe); | |
} | |
super.postRemove(context); | |
} | |
/** | |
* Removes connections from all the children of the container. | |
* | |
* @param container | |
* The container shape to remove the children from. | |
*/ | |
private void removeConnectionsFromAllChildren(ContainerShape container) { | |
for (Shape shape : (container.getChildren())) { | |
removeAllConnections(shape); | |
if (shape instanceof ContainerShape) { | |
removeConnectionsFromAllChildren((ContainerShape) shape); | |
} | |
} | |
} | |
} |