diff options
author | Sebastien Gabel | 2016-07-19 12:19:17 +0000 |
---|---|---|
committer | Sebastien Gabel | 2016-07-19 12:19:17 +0000 |
commit | 68f29daa4d3427f79f12524790fd71f8431486bc (patch) | |
tree | 1f445061ff97251e61d54f01ba6bacd66a433491 /plugins | |
parent | 9a2376f7d2cafbfcc11d83f5d6eed537ab72bd5a (diff) | |
download | org.eclipse.papyrus-68f29daa4d3427f79f12524790fd71f8431486bc.tar.gz org.eclipse.papyrus-68f29daa4d3427f79f12524790fd71f8431486bc.tar.xz org.eclipse.papyrus-68f29daa4d3427f79f12524790fd71f8431486bc.zip |
Bug 497400: [Diagrams] NPEs in several drop policies
Command's label was set before the nullity test.
Change-Id: I815cd400f65e4cd1988b608c5741513cdc2d9fb6
Signed-off-by: Sebastien Gabel <sebastien.gabel@esterel-technologies.com>
Diffstat (limited to 'plugins')
9 files changed, 651 insertions, 647 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeDropEditPolicy.java index c701ee1e58b..fb551b1d6aa 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeDropEditPolicy.java @@ -1,155 +1,155 @@ -/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-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.requests.DropObjectsRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
-import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.PortDropHelper;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.Port;
-
-/**
- * <pre>
- * Customization of the DND edit policy for BlockPropertyComposite that enables
- * type modification, or creation of new Port and FlowPort by a drop on target.
- * </pre>
- */
-public class CustomBlockPropertyCompositeDropEditPolicy extends CustomDragDropEditPolicy {
-
- /** Default constructor */
- public CustomBlockPropertyCompositeDropEditPolicy() {
- super();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Set<String> getSpecificDropBehaviorTypes() {
- Set<String> specificDropBehaviorTypes = super.getSpecificDropBehaviorTypes();
-
- specificDropBehaviorTypes.add(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID);
- specificDropBehaviorTypes.add(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID);
-
- return specificDropBehaviorTypes;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected ICommand getSpecificDropCommand(DropObjectsRequest dropRequest, EObject droppedEObject, String nodeType, String edgeType) {
- if ((UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID.equals(nodeType)) || (SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID.equals(nodeType))) {
- PortDropHelper portDropHelper = new PortDropHelper(getEditingDomain());
- return portDropHelper.getDropPortOnPart((Port) droppedEObject, dropRequest.getLocation().getCopy(), (GraphicalEditPart) getHost());
- }
-
- return super.getSpecificDropCommand(dropRequest, droppedEObject, nodeType, edgeType);
- }
-
- /**
- * {@inheritedDoc}.
- */
- @Override
- public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
- TypeDropHelper helper = new TypeDropHelper(getEditingDomain());
-
- // Single drop management possible drop action list can be proposed
- if (dropRequest.getObjects().size() == 1) {
-
- // List of available drop commands
- final List<Command> commandChoice = new ArrayList<Command>();
-
- // 1. Try to set the target element type with dropped object
- Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost());
- if ((dropAsSetType != null) && (dropAsSetType.canExecute())) {
- commandChoice.add(dropAsSetType);
- }
-
- // 2. Try to create a Port typed by the dropped object
- Command dropAsTypedPort = helper.getDropAsTypedPortOnPart(dropRequest, (GraphicalEditPart) getHost());
- if ((dropAsTypedPort != null) && (dropAsTypedPort.canExecute())) {
- commandChoice.add(dropAsTypedPort);
- }
-
- // 3. Try to create a FlowPort (In - Out - InOut) typed by the dropped object
- Command dropAsTypedFlowPort_In = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT);
- if ((dropAsTypedFlowPort_In != null) && (dropAsTypedFlowPort_In.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_In);
- }
- Command dropAsTypedFlowPort_Out = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_IN);
- if ((dropAsTypedFlowPort_Out != null) && (dropAsTypedFlowPort_Out.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_Out);
- }
- Command dropAsTypedFlowPort_InOut = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_OUT);
- if ((dropAsTypedFlowPort_InOut != null) && (dropAsTypedFlowPort_InOut.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_InOut);
- }
-
- // Same behavior for 4 & 5
- // // 4. Build command to drop Port and FlowPort
- // PortDropHelper portDropHelper = new PortDropHelper(getEditingDomain());
- // Command dropPortOnPart = portDropHelper.getDropPortOnPart(dropRequest, (GraphicalEditPart)getHost());
- // if ((dropPortOnPart != null) && (dropPortOnPart.canExecute())) {
- // commandChoice.add(dropPortOnPart);
- // }
-
- // 5. Build default drop command (show view of the dropped object)
- Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
- defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
- if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
- commandChoice.add(defaultDropCommand);
- }
-
- // Prepare the selection command (if several command are available) or return the drop command
- if (commandChoice.size() > 1) {
- RunnableWithResult<ICommand> runnable;
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
-
- public void run() {
- setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
- }
- });
-
- ICommand selectCommand = runnable.getResult();
-
- return new ICommandProxy(selectCommand);
- } else if (commandChoice.size() == 1) {
- return commandChoice.get(0);
- }
-
- // else (command choice is empty)
- return UnexecutableCommand.INSTANCE;
-
- }
-
- return super.getDropObjectsCommand(dropRequest);
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2016 CEA LIST, Esterel Technologies SAS and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +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.requests.DropObjectsRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLGraphicalTypes; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.PortDropHelper; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper; +import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; +import org.eclipse.papyrus.uml.diagram.common.utils.UMLGraphicalTypes; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.eclipse.uml2.uml.Port; + +/** + * <pre> + * Customization of the DND edit policy for BlockPropertyComposite that enables + * type modification, or creation of new Port and FlowPort by a drop on target. + * </pre> + */ +public class CustomBlockPropertyCompositeDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public CustomBlockPropertyCompositeDropEditPolicy() { + super(); + } + + /** + * {@inheritDoc} + */ + @Override + protected Set<String> getSpecificDropBehaviorTypes() { + Set<String> specificDropBehaviorTypes = super.getSpecificDropBehaviorTypes(); + + specificDropBehaviorTypes.add(UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID); + specificDropBehaviorTypes.add(SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID); + + return specificDropBehaviorTypes; + } + + /** + * {@inheritDoc} + */ + @Override + protected ICommand getSpecificDropCommand(DropObjectsRequest dropRequest, EObject droppedEObject, String nodeType, String edgeType) { + if ((UMLGraphicalTypes.SHAPE_UML_PORT_AS_AFFIXED_ID.equals(nodeType)) || (SysMLGraphicalTypes.SHAPE_SYSML_FLOWPORT_AS_AFFIXED_ID.equals(nodeType))) { + PortDropHelper portDropHelper = new PortDropHelper(getEditingDomain()); + return portDropHelper.getDropPortOnPart((Port) droppedEObject, dropRequest.getLocation().getCopy(), (GraphicalEditPart) getHost()); + } + + return super.getSpecificDropCommand(dropRequest, droppedEObject, nodeType, edgeType); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + TypeDropHelper helper = new TypeDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if (dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Try to set the target element type with dropped object + Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost()); + if ((dropAsSetType != null) && (dropAsSetType.canExecute())) { + commandChoice.add(dropAsSetType); + } + + // 2. Try to create a Port typed by the dropped object + Command dropAsTypedPort = helper.getDropAsTypedPortOnPart(dropRequest, (GraphicalEditPart) getHost()); + if ((dropAsTypedPort != null) && (dropAsTypedPort.canExecute())) { + commandChoice.add(dropAsTypedPort); + } + + // 3. Try to create a FlowPort (In - Out - InOut) typed by the dropped object + Command dropAsTypedFlowPort_In = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT); + if ((dropAsTypedFlowPort_In != null) && (dropAsTypedFlowPort_In.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_In); + } + Command dropAsTypedFlowPort_Out = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_IN); + if ((dropAsTypedFlowPort_Out != null) && (dropAsTypedFlowPort_Out.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_Out); + } + Command dropAsTypedFlowPort_InOut = helper.getDropAsTypedFlowPortOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_OUT); + if ((dropAsTypedFlowPort_InOut != null) && (dropAsTypedFlowPort_InOut.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_InOut); + } + + // Same behavior for 4 & 5 + // // 4. Build command to drop Port and FlowPort + // PortDropHelper portDropHelper = new PortDropHelper(getEditingDomain()); + // Command dropPortOnPart = portDropHelper.getDropPortOnPart(dropRequest, (GraphicalEditPart)getHost()); + // if ((dropPortOnPart != null) && (dropPortOnPart.canExecute())) { + // commandChoice.add(dropPortOnPart); + // } + + // 5. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if (commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + } else if (commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java index 483432d0f21..3be3b13723c 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java @@ -1,139 +1,139 @@ -/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-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.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.BlockDropHelper;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.PartDropHelper;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <pre>
- * Customization of the DND edit policy for BlockPropertyComposite that enables
- * type modification, or creation of new Port and FlowPort by a drop on target.
- * </pre>
- */
-public class CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy extends CustomDragDropEditPolicy {
-
- /** Default constructor */
- public CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy() {
- super();
- }
-
- /**
- * {@inheritedDoc}.
- */
- @Override
- public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
-
- BlockDropHelper helper = new BlockDropHelper(getEditingDomain());
-
- // Single drop management possible drop action list can be proposed
- if (dropRequest.getObjects().size() == 1) {
-
- // List of available drop commands
- final List<Command> commandChoice = new ArrayList<Command>();
-
- // 1. Build command to drop BlockProperty
- PartDropHelper partDropHelper = new PartDropHelper(getEditingDomain());
- Command dropPartOnPart = partDropHelper.getDropPartOnPart(dropRequest, (GraphicalEditPart) getHost());
- if ((dropPartOnPart != null) && (dropPartOnPart.canExecute())) {
- commandChoice.add(dropPartOnPart);
- }
-
- // 2. Try to create a Part typed by the dropped object
- Command dropAsTypedPart = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.PART_PROPERTY);
- if ((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) {
- commandChoice.add(dropAsTypedPart);
- }
-
- // 3. Try to create a Reference typed by the dropped object
- Command dropAsTypedReference = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.REFERENCE_PROPERTY);
- if ((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) {
- commandChoice.add(dropAsTypedReference);
- }
-
- // 4. Try to create an ActorPart typed by the dropped object
- Command dropAsTypedActorPart = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY);
- if ((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) {
- commandChoice.add(dropAsTypedActorPart);
- }
-
- // 5. Try to create a Value typed by the dropped object
- Command dropAsTypedValue = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.VALUE_PROPERTY);
- if ((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) {
- commandChoice.add(dropAsTypedValue);
- }
-
- // 6. Try to create a Property typed by the dropped object
- Command dropAsTypedProperty = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), UMLElementTypes.PROPERTY);
- if ((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) {
- commandChoice.add(dropAsTypedProperty);
- }
-
- // 7. Build default drop command (show view of the dropped object)
- Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
- defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
- if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
- commandChoice.add(defaultDropCommand);
- }
-
- // Prepare the selection command (if several command are available) or return the drop command
- if (commandChoice.size() > 1) {
- RunnableWithResult<ICommand> runnable;
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
-
- public void run() {
- setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
- }
- });
-
- ICommand selectCommand = runnable.getResult();
-
- return new ICommandProxy(selectCommand);
- } else if (commandChoice.size() == 1) {
- return commandChoice.get(0);
- }
-
- // else (command choice is empty)
- return UnexecutableCommand.INSTANCE;
-
- }
-
- return super.getDropObjectsCommand(dropRequest);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected View getReferenceViewForConnectorEnd() {
- return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd());
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2016 CEA LIST, Esterel Technologies SAS and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +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.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.BlockDropHelper; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.PartDropHelper; +import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; +import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * <pre> + * Customization of the DND edit policy for BlockPropertyComposite that enables + * type modification, or creation of new Port and FlowPort by a drop on target. + * </pre> + */ +public class CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy() { + super(); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + + BlockDropHelper helper = new BlockDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if (dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Build command to drop BlockProperty + PartDropHelper partDropHelper = new PartDropHelper(getEditingDomain()); + Command dropPartOnPart = partDropHelper.getDropPartOnPart(dropRequest, (GraphicalEditPart) getHost()); + if ((dropPartOnPart != null) && (dropPartOnPart.canExecute())) { + commandChoice.add(dropPartOnPart); + } + + // 2. Try to create a Part typed by the dropped object + Command dropAsTypedPart = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.PART_PROPERTY); + if ((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) { + commandChoice.add(dropAsTypedPart); + } + + // 3. Try to create a Reference typed by the dropped object + Command dropAsTypedReference = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.REFERENCE_PROPERTY); + if ((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) { + commandChoice.add(dropAsTypedReference); + } + + // 4. Try to create an ActorPart typed by the dropped object + Command dropAsTypedActorPart = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY); + if ((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) { + commandChoice.add(dropAsTypedActorPart); + } + + // 5. Try to create a Value typed by the dropped object + Command dropAsTypedValue = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.VALUE_PROPERTY); + if ((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) { + commandChoice.add(dropAsTypedValue); + } + + // 6. Try to create a Property typed by the dropped object + Command dropAsTypedProperty = helper.getDropAsStructureItemOnPart(dropRequest, (GraphicalEditPart) getHost(), UMLElementTypes.PROPERTY); + if ((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) { + commandChoice.add(dropAsTypedProperty); + } + + // 7. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if (commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + } else if (commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } + + /** + * {@inheritDoc} + */ + @Override + protected View getReferenceViewForConnectorEnd() { + return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd()); + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/EncapsulatedClassifierDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/EncapsulatedClassifierDropEditPolicy.java index b3a3d743049..29acc513d95 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/EncapsulatedClassifierDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/EncapsulatedClassifierDropEditPolicy.java @@ -1,111 +1,111 @@ -/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-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.requests.DropObjectsRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <pre>
- * Customization of the DND edit policy for the EncapsulatedClassifier, that enables the direct
- * creation of typed Port or FlowPort by dragging types over diagram figure.
- * </pre>
- */
-public class EncapsulatedClassifierDropEditPolicy extends CustomDragDropEditPolicy {
-
- /** Default constructor */
- public EncapsulatedClassifierDropEditPolicy() {
- super();
- }
-
- /**
- * {@inheritedDoc}.
- */
- @Override
- public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
-
- TypeDropHelper helper = new TypeDropHelper(getEditingDomain());
-
- // Single drop management possible drop action list can be proposed
- if (dropRequest.getObjects().size() == 1) {
-
- // List of available drop commands
- final List<Command> commandChoice = new ArrayList<Command>();
-
- // 1. Try to create a Port typed by the dropped object
- Command dropAsTypedPort = helper.getDropAsTypedPort(dropRequest, (GraphicalEditPart) getHost());
- if ((dropAsTypedPort != null) && (dropAsTypedPort.canExecute())) {
- commandChoice.add(dropAsTypedPort);
- }
-
- // 2. Try to create a FlowPort (In - Out - InOut) typed by the dropped object
- Command dropAsTypedFlowPort_In = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT);
- if ((dropAsTypedFlowPort_In != null) && (dropAsTypedFlowPort_In.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_In);
- }
- Command dropAsTypedFlowPort_Out = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_IN);
- if ((dropAsTypedFlowPort_Out != null) && (dropAsTypedFlowPort_Out.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_Out);
- }
- Command dropAsTypedFlowPort_InOut = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_OUT);
- if ((dropAsTypedFlowPort_InOut != null) && (dropAsTypedFlowPort_InOut.canExecute())) {
- commandChoice.add(dropAsTypedFlowPort_InOut);
- }
-
- // 3. Build default drop command (show view of the dropped object)
- Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
- defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
- if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
- commandChoice.add(defaultDropCommand);
- }
-
- // Prepare the selection command (if several command are available) or return the drop command
- if (commandChoice.size() > 1) {
- RunnableWithResult<ICommand> runnable;
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
-
- public void run() {
- setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
- }
- });
-
- ICommand selectCommand = runnable.getResult();
-
- return new ICommandProxy(selectCommand);
-
- } else if (commandChoice.size() == 1) {
- return commandChoice.get(0);
- }
-
- // else (command choice is empty)
- return UnexecutableCommand.INSTANCE;
-
- }
-
- return super.getDropObjectsCommand(dropRequest);
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2016 CEA LIST, Esterel Technologies SAS and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +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.requests.DropObjectsRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper; +import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * <pre> + * Customization of the DND edit policy for the EncapsulatedClassifier, that enables the direct + * creation of typed Port or FlowPort by dragging types over diagram figure. + * </pre> + */ +public class EncapsulatedClassifierDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public EncapsulatedClassifierDropEditPolicy() { + super(); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + + TypeDropHelper helper = new TypeDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if (dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Try to create a Port typed by the dropped object + Command dropAsTypedPort = helper.getDropAsTypedPort(dropRequest, (GraphicalEditPart) getHost()); + if ((dropAsTypedPort != null) && (dropAsTypedPort.canExecute())) { + commandChoice.add(dropAsTypedPort); + } + + // 2. Try to create a FlowPort (In - Out - InOut) typed by the dropped object + Command dropAsTypedFlowPort_In = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT); + if ((dropAsTypedFlowPort_In != null) && (dropAsTypedFlowPort_In.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_In); + } + Command dropAsTypedFlowPort_Out = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_IN); + if ((dropAsTypedFlowPort_Out != null) && (dropAsTypedFlowPort_Out.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_Out); + } + Command dropAsTypedFlowPort_InOut = helper.getDropAsTypedFlowPort(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.FLOW_PORT_OUT); + if ((dropAsTypedFlowPort_InOut != null) && (dropAsTypedFlowPort_InOut.canExecute())) { + commandChoice.add(dropAsTypedFlowPort_InOut); + } + + // 3. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if (commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + + } else if (commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/StructureClassifierDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/StructureClassifierDropEditPolicy.java index f9b86223667..5cc31f8aba1 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/StructureClassifierDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/StructureClassifierDropEditPolicy.java @@ -1,132 +1,132 @@ -/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-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.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.BlockDropHelper;
-import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
-import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <pre>
- * Customization of the DND edit policy for the StructureClassifier compartments, that enables the direct
- * creation of typed Part, Reference, Value, ActorPart or Property by dragging types in a Block structure compartment.
- * </pre>
- */
-public class StructureClassifierDropEditPolicy extends CustomDragDropEditPolicy {
-
- /** Default constructor */
- public StructureClassifierDropEditPolicy() {
- super();
- }
-
- /**
- * {@inheritedDoc}.
- */
- @Override
- public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
-
- BlockDropHelper helper = new BlockDropHelper(getEditingDomain());
-
- // Single drop management possible drop action list can be proposed
- if (dropRequest.getObjects().size() == 1) {
-
- // List of available drop commands
- final List<Command> commandChoice = new ArrayList<Command>();
-
- // 1. Try to create a Part typed by the dropped object
- Command dropAsTypedPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.PART_PROPERTY);
- if ((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) {
- commandChoice.add(dropAsTypedPart);
- }
-
- // 2. Try to create a Reference typed by the dropped object
- Command dropAsTypedReference = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.REFERENCE_PROPERTY);
- if ((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) {
- commandChoice.add(dropAsTypedReference);
- }
-
- // 3. Try to create an ActorPart typed by the dropped object
- Command dropAsTypedActorPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY);
- if ((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) {
- commandChoice.add(dropAsTypedActorPart);
- }
-
- // 4. Try to create a Value typed by the dropped object
- Command dropAsTypedValue = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.VALUE_PROPERTY);
- if ((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) {
- commandChoice.add(dropAsTypedValue);
- }
-
- // 5. Try to create a Property typed by the dropped object
- Command dropAsTypedProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), UMLElementTypes.PROPERTY);
- if ((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) {
- commandChoice.add(dropAsTypedProperty);
- }
-
- // 6. Build default drop command (show view of the dropped object)
- Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
- defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
- if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
- commandChoice.add(defaultDropCommand);
- }
-
- // Prepare the selection command (if several command are available) or return the drop command
- if (commandChoice.size() > 1) {
- RunnableWithResult<ICommand> runnable;
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
-
- public void run() {
- setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
- }
- });
-
- ICommand selectCommand = runnable.getResult();
-
- return new ICommandProxy(selectCommand);
-
- } else if (commandChoice.size() == 1) {
- return commandChoice.get(0);
- }
-
- // else (command choice is empty)
- return UnexecutableCommand.INSTANCE;
-
- }
-
- return super.getDropObjectsCommand(dropRequest);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected View getReferenceViewForConnectorEnd() {
- return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd());
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2016 CEA LIST, Esterel Technologies SAS and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +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.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.BlockDropHelper; +import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes; +import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * <pre> + * Customization of the DND edit policy for the StructureClassifier compartments, that enables the direct + * creation of typed Part, Reference, Value, ActorPart or Property by dragging types in a Block structure compartment. + * </pre> + */ +public class StructureClassifierDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public StructureClassifierDropEditPolicy() { + super(); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + + BlockDropHelper helper = new BlockDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if (dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Try to create a Part typed by the dropped object + Command dropAsTypedPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.PART_PROPERTY); + if ((dropAsTypedPart != null) && (dropAsTypedPart.canExecute())) { + commandChoice.add(dropAsTypedPart); + } + + // 2. Try to create a Reference typed by the dropped object + Command dropAsTypedReference = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.REFERENCE_PROPERTY); + if ((dropAsTypedReference != null) && (dropAsTypedReference.canExecute())) { + commandChoice.add(dropAsTypedReference); + } + + // 3. Try to create an ActorPart typed by the dropped object + Command dropAsTypedActorPart = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.ACTOR_PART_PROPERTY); + if ((dropAsTypedActorPart != null) && (dropAsTypedActorPart.canExecute())) { + commandChoice.add(dropAsTypedActorPart); + } + + // 4. Try to create a Value typed by the dropped object + Command dropAsTypedValue = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), SysMLElementTypes.VALUE_PROPERTY); + if ((dropAsTypedValue != null) && (dropAsTypedValue.canExecute())) { + commandChoice.add(dropAsTypedValue); + } + + // 5. Try to create a Property typed by the dropped object + Command dropAsTypedProperty = helper.getDropAsStructureItem(dropRequest, (GraphicalEditPart) getHost(), UMLElementTypes.PROPERTY); + if ((dropAsTypedProperty != null) && (dropAsTypedProperty.canExecute())) { + commandChoice.add(dropAsTypedProperty); + } + + // 6. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if (commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + + } else if (commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } + + /** + * {@inheritDoc} + */ + @Override + protected View getReferenceViewForConnectorEnd() { + return ViewUtil.getContainerView(super.getReferenceViewForConnectorEnd()); + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/TypedElementDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/TypedElementDropEditPolicy.java index d6e29cb8e40..3bebb6a8502 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/TypedElementDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/TypedElementDropEditPolicy.java @@ -1,94 +1,94 @@ -/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-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.requests.DropObjectsRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand;
-import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.PlatformUI;
-
-/**
- * <pre>
- * Customization of the DND edit policy for TypedElement (Port, Part, Reference, FlowPort), that enables
- * type modification by a drop on target.
- * </pre>
- */
-public class TypedElementDropEditPolicy extends CustomDragDropEditPolicy {
-
- /** Default constructor */
- public TypedElementDropEditPolicy() {
- super();
- }
-
- /**
- * {@inheritedDoc}.
- */
- @Override
- public Command getDropObjectsCommand(DropObjectsRequest dropRequest) {
- TypeDropHelper helper = new TypeDropHelper(getEditingDomain());
-
- // Single drop management possible drop action list can be proposed
- if (dropRequest.getObjects().size() == 1) {
-
- // List of available drop commands
- final List<Command> commandChoice = new ArrayList<Command>();
-
- // 1. Try to set the target element type with dropped object
- Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost());
- if ((dropAsSetType != null) && (dropAsSetType.canExecute())) {
- commandChoice.add(dropAsSetType);
- }
-
- // 3. Build default drop command (show view of the dropped object)
- Command defaultDropCommand = super.getDropObjectsCommand(dropRequest);
- defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)");
- if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) {
- commandChoice.add(defaultDropCommand);
- }
-
- // Prepare the selection command (if several command are available) or return the drop command
- if (commandChoice.size() > 1) {
- RunnableWithResult<ICommand> runnable;
- Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() {
-
- public void run() {
- setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice));
- }
- });
-
- ICommand selectCommand = runnable.getResult();
-
- return new ICommandProxy(selectCommand);
- } else if (commandChoice.size() == 1) {
- return commandChoice.get(0);
- }
-
- // else (command choice is empty)
- return UnexecutableCommand.INSTANCE;
-
- }
-
- return super.getDropObjectsCommand(dropRequest);
- }
-}
+/***************************************************************************** + * Copyright (c) 2011, 2016 CEA LIST, Esterel Technologies SAS and others. + * + * 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: + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 + * + *****************************************************************************/ +package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.transaction.RunnableWithResult; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +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.requests.DropObjectsRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.commands.SelectAndExecuteCommand; +import org.eclipse.papyrus.sysml.diagram.internalblock.utils.TypeDropHelper; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; + +/** + * <pre> + * Customization of the DND edit policy for TypedElement (Port, Part, Reference, FlowPort), that enables + * type modification by a drop on target. + * </pre> + */ +public class TypedElementDropEditPolicy extends CustomDragDropEditPolicy { + + /** Default constructor */ + public TypedElementDropEditPolicy() { + super(); + } + + /** + * {@inheritedDoc}. + */ + @Override + public Command getDropObjectsCommand(DropObjectsRequest dropRequest) { + TypeDropHelper helper = new TypeDropHelper(getEditingDomain()); + + // Single drop management possible drop action list can be proposed + if (dropRequest.getObjects().size() == 1) { + + // List of available drop commands + final List<Command> commandChoice = new ArrayList<Command>(); + + // 1. Try to set the target element type with dropped object + Command dropAsSetType = helper.getDropAsTypedElementType(dropRequest, (GraphicalEditPart) getHost()); + if ((dropAsSetType != null) && (dropAsSetType.canExecute())) { + commandChoice.add(dropAsSetType); + } + + // 3. Build default drop command (show view of the dropped object) + Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); + if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); + commandChoice.add(defaultDropCommand); + } + + // Prepare the selection command (if several command are available) or return the drop command + if (commandChoice.size() > 1) { + RunnableWithResult<ICommand> runnable; + Display.getDefault().syncExec(runnable = new RunnableWithResult.Impl<ICommand>() { + + public void run() { + setResult(new SelectAndExecuteCommand("Select drop action for ", PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), commandChoice)); + } + }); + + ICommand selectCommand = runnable.getResult(); + + return new ICommandProxy(selectCommand); + } else if (commandChoice.size() == 1) { + return commandChoice.get(0); + } + + // else (command choice is empty) + return UnexecutableCommand.INSTANCE; + + } + + return super.getDropObjectsCommand(dropRequest); + } +} diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockCompositeDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockCompositeDropEditPolicy.java index 3d350cadf70..8e553b2e2fc 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockCompositeDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockCompositeDropEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2013, 2016 CEA LIST, Esterel Technologies SAS and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,8 +7,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Régis CHEVREL: chevrel.regis <at> gmail.com - * CEA LIST - Initial API and implementation + * Régis CHEVREL: chevrel.regis <at> gmail.com + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 * *****************************************************************************/ package org.eclipse.papyrus.sysml.diagram.parametric.policies; @@ -96,8 +97,8 @@ public class CustomBlockCompositeDropEditPolicy extends CustomDragDropEditPolicy // 2. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); - defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); commandChoice.add(defaultDropCommand); } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyCompositeDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyCompositeDropEditPolicy.java index 0f4522e9c93..ea8909b4942 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyCompositeDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyCompositeDropEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2013, 2016 CEA LIST, Esterel Technologies SAS and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,8 +7,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Régis CHEVREL: chevrel.regis <at> gmail.com - * CEA LIST - Initial API and implementation + * Régis CHEVREL: chevrel.regis <at> gmail.com + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 * *****************************************************************************/ package org.eclipse.papyrus.sysml.diagram.parametric.policies; @@ -96,8 +97,8 @@ public class CustomBlockPropertyCompositeDropEditPolicy extends CustomDragDropEd // 2. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); - defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); commandChoice.add(defaultDropCommand); } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java index ec32b28b181..9692542fc86 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2013, 2016 CEA LIST, Esterel Technologies SAS and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,8 +7,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Régis CHEVREL: chevrel.regis <at> gmail.com - * CEA LIST - Initial API and implementation + * Régis CHEVREL: chevrel.regis <at> gmail.com + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 * *****************************************************************************/ package org.eclipse.papyrus.sysml.diagram.parametric.policies; @@ -105,8 +106,8 @@ public class CustomBlockPropertyStructureCompartmentEditPartDropEditPolicy exten // 8. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); - defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); commandChoice.add(defaultDropCommand); } diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/StructureClassifierDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/StructureClassifierDropEditPolicy.java index 1447625bec9..2fda6946d81 100644 --- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/StructureClassifierDropEditPolicy.java +++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.parametric/src/org/eclipse/papyrus/sysml/diagram/parametric/policies/StructureClassifierDropEditPolicy.java @@ -1,5 +1,5 @@ /***************************************************************************** - * Copyright (c) 2013 CEA LIST. + * Copyright (c) 2013, 2016 CEA LIST, Esterel Technologies SAS and others. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -7,8 +7,9 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Régis CHEVREL: chevrel.regis <at> gmail.com - * CEA LIST - Initial API and implementation + * Régis CHEVREL: chevrel.regis <at> gmail.com + * CEA LIST - Initial API and implementation + * Alain Le Guennec (Esterel Technologies SAS) - bug 497400 * *****************************************************************************/ package org.eclipse.papyrus.sysml.diagram.parametric.policies; @@ -97,8 +98,8 @@ public class StructureClassifierDropEditPolicy extends CustomDragDropEditPolicy // 7. Build default drop command (show view of the dropped object) Command defaultDropCommand = super.getDropObjectsCommand(dropRequest); - defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); if ((defaultDropCommand != null) && (defaultDropCommand.canExecute())) { + defaultDropCommand.setLabel("Default drop (Show dropped object in diagram)"); commandChoice.add(defaultDropCommand); } |