diff options
author | ptessier | 2015-05-11 13:09:17 +0000 |
---|---|---|
committer | ptessier | 2015-05-11 13:13:56 +0000 |
commit | 4e35e6cb9b929ce7835334b85298f70a09dd73c4 (patch) | |
tree | 32d0538f55422697d9bfce877fc4c20b8c19f768 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd | |
parent | df143fb9cc56b21c436a52861d2386822782c6d5 (diff) | |
download | org.eclipse.papyrus-4e35e6cb9b929ce7835334b85298f70a09dd73c4.tar.gz org.eclipse.papyrus-4e35e6cb9b929ce7835334b85298f70a09dd73c4.tar.xz org.eclipse.papyrus-4e35e6cb9b929ce7835334b85298f70a09dd73c4.zip |
Bug 463290 - Papyrus diagram shall be expanded with new visual graphical
notation
Add new test and refactor codes
Change-Id: Ie107bcf6bdc55f33b79d9024f5bda1c4d352da66
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd')
-rw-r--r-- | plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java index bc7175f0d1e..a603d36c7da 100644 --- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java +++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; @@ -147,38 +148,64 @@ public class ExpansionElementDropStrategy extends TransactionalDropStrategy { } // get the sub list of accepted source element that match to elementType for (EObject sourceElement : sourceElements) { - Command cmd=null; - int acceptedElementTypesIndex=0; - while (cmd==null &&acceptedElementTypesIndex<acceptedElementTypes.size()){ - final ISpecializationType iSpecializationType = acceptedElementTypes.get(acceptedElementTypesIndex); - IElementMatcher matcher=iSpecializationType.getMatcher(); - if(matcher!=null && matcher.matches(sourceElement)){ - valuesToAdd.add(sourceElement); - if(DEBUG_EXPANSION){ - Activator.log.debug(DEBUG_PREFIX+"try to drop command created for "+ sourceElement+ " "+iSpecializationType); - } - cmd= new Command() { - @Override - public void execute() { - if( iSpecializationType instanceof IHintedType){ - ViewService.createNode(((GraphicalEditPart) targetEditPart).getNotationView(),valuesToAdd.get(0), ((IHintedType)iSpecializationType).getSemanticHint(), ((GraphicalEditPart) targetEditPart).getDiagramPreferencesHint()); + //the source element must be a children of the container + if(sourceElement.eContainer().equals(graphicalEditPart.resolveSemanticElement())){ + Command cmd=null; + int acceptedElementTypesIndex=0; + while (cmd==null &&acceptedElementTypesIndex<acceptedElementTypes.size()){ + final ISpecializationType iSpecializationType = acceptedElementTypes.get(acceptedElementTypesIndex); + IElementMatcher matcher=iSpecializationType.getMatcher(); + IElementType[] superElementTypes=iSpecializationType.getSpecializedTypes(); + if( matcher==null){ + int index=superElementTypes.length-1; + while(matcher==null && index >0){ + if(superElementTypes[index] instanceof ISpecializationType){ + matcher=((ISpecializationType)superElementTypes[index]).getMatcher(); } + index--; + } + } + if(matcher!=null && matcher.matches(sourceElement)){ + cmd=addCommandDrop(targetEditPart, cc, valuesToAdd, sourceElement, iSpecializationType); + } + else if(matcher==null){ + EClass eclass=iSpecializationType.getEClass(); + if(eclass.isSuperTypeOf(sourceElement.eClass())){ + cmd=addCommandDrop(targetEditPart, cc, valuesToAdd, sourceElement, iSpecializationType); } + else{ + acceptedElementTypesIndex++;} + } + else{ + acceptedElementTypesIndex++; + } - }; - cc.add(new CommandProxy( cmd)); - } - else{ - acceptedElementTypesIndex++; } } - } } return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null; } + protected Command addCommandDrop(final EditPart targetEditPart, CompositeCommand cc, final List<EObject> valuesToAdd, EObject sourceElement, final ISpecializationType iSpecializationType) { + + valuesToAdd.add(sourceElement); + if(DEBUG_EXPANSION){ + Activator.log.debug(DEBUG_PREFIX+"try to drop command created for "+ sourceElement+ " "+iSpecializationType); + } + Command cmd= new Command() { + @Override + public void execute() { + if( iSpecializationType instanceof IHintedType){ + ViewService.createNode(((GraphicalEditPart) targetEditPart).getNotationView(),valuesToAdd.get(0), ((IHintedType)iSpecializationType).getSemanticHint(), ((GraphicalEditPart) targetEditPart).getDiagramPreferencesHint()); + } + } + + }; + cc.add(new CommandProxy( cmd)); + return cmd; + } public String getCategoryID() { |