| /********************************************************************* |
| * Copyright (c) 2005, 2019 SAP SE |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * Contributors: |
| * SAP SE - initial API, implementation and documentation |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| **********************************************************************/ |
| package org.eclipse.graphiti.examples.tutorial.features; |
| |
| import org.eclipse.emf.ecore.EClass; |
| import org.eclipse.graphiti.features.IFeatureProvider; |
| import org.eclipse.graphiti.features.context.IMoveShapeContext; |
| import org.eclipse.graphiti.features.impl.DefaultMoveShapeFeature; |
| import org.eclipse.graphiti.mm.pictograms.Shape; |
| |
| public class TutorialMoveEClassFeature extends DefaultMoveShapeFeature { |
| |
| public TutorialMoveEClassFeature(IFeatureProvider fp) { |
| super(fp); |
| } |
| |
| @Override |
| public boolean canMoveShape(IMoveShapeContext context) { |
| boolean canMove = super.canMoveShape(context); |
| |
| // perform further check only if move allowed by default feature |
| if (canMove) { |
| // don't allow move if the class name has the length of 1 |
| Shape shape = context.getShape(); |
| Object bo = getBusinessObjectForPictogramElement(shape); |
| if (bo instanceof EClass) { |
| EClass c = (EClass) bo; |
| if (c.getName() != null && c.getName().length() == 1) { |
| canMove = false; |
| } |
| } |
| } |
| return canMove; |
| } |
| } |