Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorptessier2015-04-09 08:48:30 +0000
committerptessier2015-04-17 06:59:48 +0000
commit2b2849fb2e843937dfe705e9a8b5bd547d18a6de (patch)
tree47e4bfefeef48429a4d8242be0dd969b5c38ec33 /plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src
parent2e1b77941b550ada44eb34a005aab451eec08e4f (diff)
downloadorg.eclipse.papyrus-2b2849fb2e843937dfe705e9a8b5bd547d18a6de.tar.gz
org.eclipse.papyrus-2b2849fb2e843937dfe705e9a8b5bd547d18a6de.tar.xz
org.eclipse.papyrus-2b2849fb2e843937dfe705e9a8b5bd547d18a6de.zip
Bug 463290 - Papyrus diagram shall be expanded with new visual graphical
notation create the first version of interpretors Change-Id: I206b42116762524eef531fe09b18dd7fae2bbed6
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/strategy/ExpansionElementDropStrategy.java187
1 files changed, 187 insertions, 0 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
new file mode 100644
index 00000000000..3d592e268e9
--- /dev/null
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.dnd/src/org/eclipse/papyrus/infra/gmfdiag/dnd/strategy/ExpansionElementDropStrategy.java
@@ -0,0 +1,187 @@
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.dnd.strategy;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Platform;
+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;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+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.DiagramExpansionsRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.expansionmodel.AbstractRepresentation;
+import org.eclipse.papyrus.infra.gmfdiag.common.expansionmodel.Representation;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.swt.graphics.Image;
+
+/**
+
+ *
+ */
+public class ExpansionElementDropStrategy extends TransactionalDropStrategy {
+
+ private DiagramExpansionsRegistry diagramExpansionRegistry;
+ private static final boolean DEBUG_EXPANSION = "true".equalsIgnoreCase(Platform.getDebugOption(
+ "org.eclipse.papyrus.infra.gmfdiag.common/debug/expansion"));
+
+ /**
+ * Constructor.
+ *
+ */
+ public ExpansionElementDropStrategy() {
+ this.diagramExpansionRegistry = new DiagramExpansionsRegistry();
+ }
+ public String getLabel() {
+ return "Expansion element drag and drop";
+ }
+
+ public String getID() {
+ return "org.eclipse.papyrus.infra.gmfdiag.dnd.expansiondropsteategy";
+ }
+
+ public String getDescription() {
+ return "This strategy is used to allow dropping of expansion of elements in extended diagrams.";
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public int getPriority() {
+ return 0;
+ }
+
+ public void setOptions(Map<String, Object> options) {
+ // Nothing
+ }
+ /**
+ * get the diagram type from a 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();
+ }
+ 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){
+ return null;
+ }
+ //look for all possible children for the current target.
+ List<String>childrenList =listRepresentation.parentChildrenRelation.get(graphicalEditPart.getNotationView().getType());
+ if(childrenList==null){
+ return null;
+ }
+ List<EObject> sourceElements = getSourceEObjects(request);
+ 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>();
+
+
+ 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);
+ }
+ }
+ }
+ }
+ if(DEBUG_EXPANSION){
+ System.out.println("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) {
+ Command cmd=null;
+ int acceptedElementTypesIndex=0;
+ while (cmd==null &&acceptedElementTypesIndex<acceptedElementTypes.size()){
+ final ISpecializationType iSpecializationType = acceptedElementTypes.get(acceptedElementTypesIndex);
+ IElementMatcher matcher=iSpecializationType.getMatcher();
+ if( matcher.matches(sourceElement)){
+ valuesToAdd.add(sourceElement);
+ if(DEBUG_EXPANSION){
+ System.out.println("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());
+ }
+ }
+
+ };
+ cc.add(new CommandProxy( cmd));
+ }
+ else{
+ acceptedElementTypesIndex++;
+ }
+
+ }
+
+ }
+ }
+
+ return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null;
+ }
+
+
+ public String getCategoryID() {
+ return "org.eclipse.papyrus.infra.gmfdiag.dnd.expansiondropsteategy";
+ }
+
+ public String getCategoryLabel() {
+ return "Expansion element drag and drop";
+ }
+}

Back to the top