Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCamille Letavernier2015-05-27 15:08:05 +0000
committerCamille Letavernier2015-05-27 15:08:05 +0000
commit4b7e27032c1b1bed8cdd57e2d305ceed22882d16 (patch)
tree7e8096f81e2f159ea011d75dc821ace965c9d779 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src
parent8e17eaffa0d6b21e24a60da5e56d486f8d65f271 (diff)
downloadorg.eclipse.papyrus-4b7e27032c1b1bed8cdd57e2d305ceed22882d16.tar.gz
org.eclipse.papyrus-4b7e27032c1b1bed8cdd57e2d305ceed22882d16.tar.xz
org.eclipse.papyrus-4b7e27032c1b1bed8cdd57e2d305ceed22882d16.zip
463290: Papyrus diagram shall be expanded with new visual graphical
notation https://bugs.eclipse.org/bugs/show_bug.cgi?id=463290 - Cleanup - Improve robustness of Custom DropStrategies Change-Id: I73ea54dbc4479d78a9b1dda2520a1e81efcad24e Signed-off-by: Camille Letavernier <camille.letavernier@cea.fr>
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java11
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java133
2 files changed, 73 insertions, 71 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java
index 77d12badcf8..76766bc196a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/policy/CustomizableDropEditPolicy.java
@@ -298,9 +298,14 @@ public class CustomizableDropEditPolicy extends DragDropEditPolicy {
Map<DropStrategy, Command> matchingStrategies = new LinkedHashMap<DropStrategy, Command>();
for (DropStrategy strategy : DropStrategyManager.instance.getActiveStrategies()) {
- Command command = strategy.getCommand(request, getHost());
- if (command != null && command.canExecute()) {
- matchingStrategies.put(strategy, command);
+ try { // Strategies are provided through extension points; we can't guarantee they won't crash
+ Command command = strategy.getCommand(request, getHost());
+ if (command != null && command.canExecute()) {
+ matchingStrategies.put(strategy, command);
+ }
+ } catch (Throwable t) {
+ String message = String.format("An error occurred when trying to execute a custom Drop strategy: %s", strategy.getLabel());
+ Activator.log.error(message, t);
}
}
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 1e146170d24..79dcc714a75 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
@@ -15,13 +15,11 @@ import java.util.ArrayList;
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;
import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
@@ -36,8 +34,6 @@ import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.commands.wrappers.CommandProxyWithResult;
-import org.eclipse.papyrus.commands.wrappers.GMFtoGEFCommandWrapper;
import org.eclipse.papyrus.infra.gmfdiag.common.expansion.ChildrenListRepresentation;
import org.eclipse.papyrus.infra.gmfdiag.common.expansion.DiagramExpansionSingleton;
import org.eclipse.papyrus.infra.gmfdiag.common.expansion.DiagramExpansionsRegistry;
@@ -55,7 +51,6 @@ import org.eclipse.swt.graphics.Image;
public class ExpansionElementDropStrategy extends TransactionalDropStrategy {
private DiagramExpansionsRegistry diagramExpansionRegistry;
- private static final String DEBUG_PREFIX = "[EXPANSION_DIAGRAM]";
/**
* Constructor.
@@ -64,6 +59,7 @@ public class ExpansionElementDropStrategy extends TransactionalDropStrategy {
public ExpansionElementDropStrategy() {
this.diagramExpansionRegistry = DiagramExpansionSingleton.getInstance().getDiagramExpansionRegistry();
}
+
public String getLabel() {
return "Expansion element drag and drop";
}
@@ -87,100 +83,100 @@ public class ExpansionElementDropStrategy extends TransactionalDropStrategy {
public void setOptions(Map<String, Object> options) {
// Nothing
}
+
/**
* get the diagram type from a view.
- * @param currentView the current view
+ *
+ * @param currentView
+ * the current view
* @return the diagram type it can be also a view point
*/
protected String getDiagramType(View currentView) {
- Diagram diagram=currentView.getDiagram();
- String currentDiagramType=null;
- ViewPrototype viewPrototype=org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getPrototype(diagram);
- if(viewPrototype!=null){
- currentDiagramType=viewPrototype.getLabel();
- }
- else{
- currentDiagramType=diagram.getType();
+ Diagram diagram = currentView.getDiagram();
+ String currentDiagramType = null;
+ ViewPrototype viewPrototype = org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils.getPrototype(diagram);
+ if (viewPrototype != null) {
+ currentDiagramType = viewPrototype.getLabel();
+ } else {
+ currentDiagramType = diagram.getType();
}
return currentDiagramType;
}
+
@Override
public Command doGetCommand(Request request, final EditPart targetEditPart) {
CompositeCommand cc = new CompositeCommand(getLabel());
- if(targetEditPart instanceof GraphicalEditPart){
- IGraphicalEditPart graphicalEditPart= (IGraphicalEditPart)targetEditPart;
- String diagramType= getDiagramType(graphicalEditPart.getNotationView());
- ChildrenListRepresentation listRepresentation=diagramExpansionRegistry.mapChildreen.get(diagramType);
- //to the current diagram, a expansion is added.
- if(listRepresentation==null){
+ if (targetEditPart instanceof GraphicalEditPart) {
+ IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) targetEditPart;
+ String diagramType = getDiagramType(graphicalEditPart.getNotationView());
+ ChildrenListRepresentation listRepresentation = diagramExpansionRegistry.mapChildreen.get(diagramType);
+ // to the current diagram, a expansion is added.
+ if (listRepresentation == null) {
return null;
}
- //look for all possible children for the current target.
- List<String>childrenList=null;
- if(graphicalEditPart instanceof DiagramEditPart){
- childrenList =listRepresentation.parentChildrenRelation.get(diagramType);
+ // look for all possible children for the current target.
+ List<String> childrenList = null;
+ if (graphicalEditPart instanceof DiagramEditPart) {
+ childrenList = listRepresentation.parentChildrenRelation.get(diagramType);
+ } else {
+ childrenList = listRepresentation.parentChildrenRelation.get(graphicalEditPart.getNotationView().getType());
}
- else{
- childrenList =listRepresentation.parentChildrenRelation.get(graphicalEditPart.getNotationView().getType());
- }
-
- if(childrenList==null){
+
+ if (childrenList == null) {
return null;
}
List<EObject> sourceElements = getSourceEObjects(request);
- if(sourceElements.size()==0 ){
+ if (sourceElements.size() == 0) {
return null;
}
final List<EObject> valuesToAdd = new ArrayList<EObject>(sourceElements.size());
- //getList of accepted ElementType
- final ArrayList<ISpecializationType> acceptedElementTypes= new ArrayList<ISpecializationType>();
+ // getList of accepted ElementType
+ final ArrayList<ISpecializationType> acceptedElementTypes = new ArrayList<ISpecializationType>();
for (String posibleID : childrenList) {
- AbstractRepresentation abstractRepresentation=listRepresentation.IDMap.get(posibleID);
- if( abstractRepresentation instanceof Representation){
- String elementTypeID=((Representation)abstractRepresentation).getGraphicalElementType();
- if( elementTypeID!=null && elementTypeID!=""){
- final IElementType elementType=ElementTypeRegistry.getInstance().getType(elementTypeID);
- if( elementType instanceof ISpecializationType){
- acceptedElementTypes.add((ISpecializationType)elementType);
+ AbstractRepresentation abstractRepresentation = listRepresentation.IDMap.get(posibleID);
+ if (abstractRepresentation instanceof Representation) {
+ String elementTypeID = ((Representation) abstractRepresentation).getGraphicalElementType();
+ if (elementTypeID != null && elementTypeID != "") {
+ final IElementType elementType = ElementTypeRegistry.getInstance().getType(elementTypeID);
+ if (elementType instanceof ISpecializationType) {
+ acceptedElementTypes.add((ISpecializationType) elementType);
}
}
}
}
- Activator.log.trace(Activator.EXPANSION_TRACE,"try to drop "+ sourceElements+" inside "+graphicalEditPart.getNotationView().getType()+ " accepts "+childrenList);
+ Activator.log.trace(Activator.EXPANSION_TRACE, "try to drop " + sourceElements + " inside " + graphicalEditPart.getNotationView().getType() + " accepts " + childrenList);
// get the sub list of accepted source element that match to elementType
for (EObject sourceElement : sourceElements) {
- //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()){
+ // the source element must be a children of the container
+ if (sourceElement.eContainer() == 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();
+ 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);
+ 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++;}
- }
- else{
+ } else {
acceptedElementTypesIndex++;
}
@@ -192,20 +188,21 @@ public class ExpansionElementDropStrategy extends TransactionalDropStrategy {
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);
- Activator.log.trace(Activator.EXPANSION_TRACE,"try to drop command created for "+ sourceElement+ " "+iSpecializationType);
- Command cmd= new Command() {
+ Activator.log.trace(Activator.EXPANSION_TRACE, "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());
+ if (iSpecializationType instanceof IHintedType) {
+ ViewService.createNode(((GraphicalEditPart) targetEditPart).getNotationView(), valuesToAdd.get(0), ((IHintedType) iSpecializationType).getSemanticHint(), ((GraphicalEditPart) targetEditPart).getDiagramPreferencesHint());
}
}
};
- cc.add(new CommandProxy( cmd));
+ cc.add(new CommandProxy(cmd));
return cmd;
}

Back to the top