Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util')
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentDeleteHelper.java323
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java1203
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DestructionOccurrenceUtil.java71
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/EventHelper.java234
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/HighlightUtil.java272
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionOperatorKindCompatibleMapping.java40
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionUseUtil.java49
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java138
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java170
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineMessageCreateHelper.java263
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineModelChildrenHelper.java90
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineResizeHelper.java106
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LoopOperatorUtil.java53
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageStyleElementFactory.java56
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/NotificationHelper.java74
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationMoveHelper.java1126
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OperandBoundsComputeHelper.java837
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/PreferencesModelElementFactory.java14
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/ReconnectMessageHelper.java182
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectOrCreateDialog.java647
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceDeleteHelper.java371
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceLinkMappingHelper.java126
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceRequestConstant.java54
-rw-r--r--deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java1713
24 files changed, 0 insertions, 8212 deletions
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentDeleteHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentDeleteHelper.java
deleted file mode 100644
index 5ca5564929a..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CombinedFragmentDeleteHelper.java
+++ /dev/null
@@ -1,323 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.menus.PopupMenu;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.EditHelperContext;
-import org.eclipse.gmf.runtime.emf.type.core.IClientContext;
-import org.eclipse.gmf.runtime.emf.type.core.commands.EditElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.AbstractEditCommandRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Shape;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionInteractionCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.ISharedImages;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
-
-public class CombinedFragmentDeleteHelper {
-
- public static class EditRequest extends AbstractEditCommandRequest {
-
- /** element to edit */
- private Element elementToEdit;
-
- public EditRequest(TransactionalEditingDomain editingDomain, Element elementToEdit) {
- super(editingDomain);
- this.elementToEdit = elementToEdit;
- }
-
- public Object getEditHelperContext() {
- IClientContext context = getClientContext();
-
- if(context == null) {
- return getElementToEdit();
- } else {
- return new EditHelperContext(getElementToEdit(), context);
- }
- }
-
- public Element getElementToEdit() {
- return elementToEdit;
- }
- }
-
- public static class MoveOperandFragmentsCommand extends EditElementCommand {
-
- private InteractionFragment parent;
-
- private EList<InteractionFragment> fragmentsToMove;
-
- private InteractionOperand sourceOperand;
-
- private CombinedFragment combinedFragment;
-
- private CombinedFragmentEditPart host;
-
- public MoveOperandFragmentsCommand(CombinedFragmentEditPart host, CombinedFragment cf, InteractionOperand op, EditRequest editRequest) {
- super(null, editRequest.getElementToEdit(), editRequest);
- InteractionOperand enclosingOp = cf.getEnclosingOperand();
- if(enclosingOp != null) {
- Element owner = enclosingOp.getOwner();
- if(owner instanceof CombinedFragment) {
- this.parent = enclosingOp;
- }
- } else {
- Element owner = cf.getOwner();
- if(owner instanceof Interaction) {
- this.parent = (InteractionFragment)owner;
- }
- }
- this.host = host;
- this.sourceOperand = op;
- this.combinedFragment = cf;
- fragmentsToMove = op.getFragments();
- }
-
- public boolean canExecute() {
- return (sourceOperand != null && combinedFragment != null);
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- if(parent != null && !fragmentsToMove.isEmpty()) {
- List<CombinedFragmentEditPart> parts = collectCombinedFragmentParts();
- if(parent instanceof InteractionOperand) {
- ((InteractionOperand)parent).getFragments().addAll(fragmentsToMove);
- moveToOperandPart((InteractionOperandEditPart)host.getParent(), parts);
- } else if(parent instanceof Interaction) {
- ((Interaction)parent).getFragments().addAll(fragmentsToMove);
- moveToInteractionPart((InteractionInteractionCompartmentEditPart)host.getParent(), parts);
- }
- }
- sourceOperand.getFragments().clear();
- return CommandResult.newOKCommandResult();
- }
-
- private void moveToOperandPart(GraphicalEditPart op, List<CombinedFragmentEditPart> keepParts) {
- if(!keepParts.isEmpty()) {
- Rectangle parentBounds = getAbsoluteBounds((AbstractGraphicalEditPart)op.getParent());
- for(CombinedFragmentEditPart cef : keepParts) {
- View view = cef.getNotationView();
- op.getNotationView().getPersistedChildren().add(view);
-
- Bounds bounds = (Bounds)((Shape)cef.getNotationView()).getLayoutConstraint();
- Rectangle absolute = getAbsoluteBounds(cef);
- bounds.setX(absolute.x() - parentBounds.x());
- bounds.setY(absolute.y() - parentBounds.y());
- }
- }
- }
-
- private void moveToInteractionPart(GraphicalEditPart op, List<CombinedFragmentEditPart> keepParts) {
- if(!keepParts.isEmpty()) {
- Rectangle b = getAbsoluteBounds(op);
- for(CombinedFragmentEditPart cef : keepParts) {
- View view = cef.getNotationView();
- op.getNotationView().getPersistedChildren().add(view);
- Bounds bounds = (Bounds)((Shape)cef.getNotationView()).getLayoutConstraint();
-
- Rectangle absolute = getAbsoluteBounds(cef);
- absolute.performTranslate(-b.x, -b.y);
-
- bounds.setX(absolute.x() - 5);
- bounds.setY(absolute.y() - 6);
- }
- }
- }
-
- private List<CombinedFragmentEditPart> collectCombinedFragmentParts() {
- List<CombinedFragmentEditPart> parts = new ArrayList<CombinedFragmentEditPart>();
- for(InteractionFragment f : fragmentsToMove) {
- if(f instanceof CombinedFragment) {
- EditPart p = findEditPartByModel(host, f);
- if(p instanceof CombinedFragmentEditPart)
- parts.add((CombinedFragmentEditPart)p);
- }
- }
- return parts;
- }
- }
-
- static public class SelectLabelProvider extends org.eclipse.jface.viewers.LabelProvider {
-
- public String getText(Object object) {
- return object.toString();
- }
-
- public Image getImage(Object object) {
- return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_ETOOL_DELETE);
- }
- }
-
- public static class SelectAndDeleteCommand extends PopupMenuCommand {
-
- private String choice;
-
- private CompositeTransactionalCommand deletaAllCommand;
-
- private CompositeTransactionalCommand keepCommand;
-
- private String[] labels;
-
- public SelectAndDeleteCommand(CompositeTransactionalCommand deletaAllCommand, CompositeTransactionalCommand keepCommand, String[] labels) {
- super("prompt for delete", Display.getCurrent().getActiveShell());
- PopupMenu popupMenu = new PopupMenu(Arrays.asList(labels), new SelectLabelProvider());
- setPopupMenu(popupMenu);
- this.labels = labels;
- this.deletaAllCommand = deletaAllCommand;
- this.keepCommand = keepCommand;
- }
-
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, org.eclipse.core.runtime.IAdaptable info) throws ExecutionException {
- CommandResult cmdResult = super.doExecuteWithResult(progressMonitor, info);
- if(!cmdResult.getStatus().isOK()) {
- return cmdResult;
- }
- this.choice = cmdResult.getReturnValue().toString();
- if(choice.contains(labels[0])) {
- deletaAllCommand.execute(progressMonitor, info);
- return deletaAllCommand.getCommandResult();
- } else {
- keepCommand.execute(progressMonitor, info);
- return keepCommand.getCommandResult();
- }
- }
-
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- if(choice.contains(labels[0])) {
- deletaAllCommand.undo(progressMonitor, info);
- return deletaAllCommand.getCommandResult();
- } else {
- keepCommand.undo(progressMonitor, info);
- return keepCommand.getCommandResult();
- }
- }
-
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- if(choice.contains(labels[0])) {
- deletaAllCommand.redo(progressMonitor, info);
- return deletaAllCommand.getCommandResult();
- } else {
- keepCommand.redo(progressMonitor, info);
- return keepCommand.getCommandResult();
- }
- }
- }
-
- static class DeleteCombinedFragmentCommand extends AbstractTransactionalCommand {
-
- private IElementEditService provider;
-
- private DestroyElementRequest req;
-
- public DeleteCombinedFragmentCommand(TransactionalEditingDomain domain, IElementEditService provider, DestroyElementRequest req) {
- super(domain, null, null);
- this.provider = provider;
- this.req = req;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- ICommand deleteCommand = provider.getEditCommand(req);
- try {
- deleteCommand.execute(monitor, info);
- } catch (ExecutionException e) {
- e.printStackTrace();
- }
- return CommandResult.newOKCommandResult();
- }
- }
-
-
- public static ICommand createDestroyElementCommand(CombinedFragment cf, TransactionalEditingDomain transactionalEditingDomain, IElementEditService provider, DestroyElementRequest req, ICommand deleteCommand, CombinedFragmentEditPart host) {
- CompositeTransactionalCommand deleteAll = new CompositeTransactionalCommand(transactionalEditingDomain, null);
- deleteAll.add(deleteCommand);
-
- CompositeTransactionalCommand deleteCfOnly = new CompositeTransactionalCommand(transactionalEditingDomain, null);
- {
- // remove children from operands and append to parent combined fragment
- for(InteractionOperand op : cf.getOperands()) {
- deleteCfOnly.add(new MoveOperandFragmentsCommand(host, cf, op, new EditRequest(transactionalEditingDomain, cf)));
- }
-
- deleteCfOnly.add(new DeleteCombinedFragmentCommand(transactionalEditingDomain, provider, req));
- }
- return new SelectAndDeleteCommand(deleteAll, deleteCfOnly, new String[]{ "Delete all", "Keep contents" });
- }
-
- public static ICommand createDeleteViewCommand(CombinedFragment cf, TransactionalEditingDomain transactionalEditingDomain, CombinedFragmentEditPart host) {
- CompositeTransactionalCommand deleteAll = new CompositeTransactionalCommand(transactionalEditingDomain, null);
- {
- // Get the elements associated with the CF
- List<Element> elements = SequenceUtil.getCombinedFragmentAssociatedElement(cf);
- // Create the delete view commands
- SequenceDeleteHelper.deleteView(deleteAll, elements, transactionalEditingDomain);
- }
-
- CompositeTransactionalCommand deleteCfOnly = new CompositeTransactionalCommand(transactionalEditingDomain, null);
- {
- // remove children from operands and append to parent combined fragment
- for(InteractionOperand op : cf.getOperands()) {
- deleteCfOnly.add(new MoveOperandFragmentsCommand(host, cf, op, new EditRequest(transactionalEditingDomain, cf)));
- }
-
- // delete operands from combined fragment
- for(Element element : cf.getOperands()) {
- SequenceDeleteHelper.deleteView(deleteCfOnly, element, transactionalEditingDomain);
- }
- }
- return new SelectAndDeleteCommand(deleteAll, deleteCfOnly, new String[]{ "Hide all", "Keep contents" });
- }
-
- static Rectangle getAbsoluteBounds(AbstractGraphicalEditPart part) {
- Rectangle b = part.getFigure().getBounds().getCopy();
- part.getFigure().translateToAbsolute(b);
- return b;
- }
-
- public static EditPart findEditPartByModel(EditPart part, EObject m) {
- List children = part.getChildren();
- if(children != null && children.size() > 0) {
- for(Object o : children) {
- EditPart p = (EditPart)o;
-
- Object model = p.getModel();
- if(model != null && model instanceof View && m.equals(((View)model).getElement()))
- return p;
-
- EditPart res = findEditPartByModel(p, m);
- if(res != null)
- return res;
- }
- }
- return null;
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java
deleted file mode 100644
index d46c58acc6f..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/CommandHelper.java
+++ /dev/null
@@ -1,1203 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.emf.common.command.CommandStack;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
-import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.emf.transaction.Transaction;
-import org.eclipse.emf.transaction.TransactionalCommandStack;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
-import org.eclipse.emf.transaction.impl.TransactionalCommandStackImpl;
-import org.eclipse.gef.EditDomain;
-import org.eclipse.gef.Tool;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.core.editor.CoreMultiDiagramEditor;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.uml.diagram.common.util.MessageDirection;
-import org.eclipse.papyrus.uml.diagram.sequence.part.Messages;
-import org.eclipse.papyrus.uml.diagram.sequence.part.UMLDiagramEditorPlugin;
-import org.eclipse.papyrus.uml.diagram.sequence.part.UMLPaletteFactory.AspectUnspecifiedTypeConnectionToolEx;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.ElementInitializers;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.uml2.uml.ActionExecutionSpecification;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.ConnectableElement;
-import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Event;
-import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.Gate;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
-import org.eclipse.uml2.uml.InteractionOperatorKind;
-import org.eclipse.uml2.uml.InteractionUse;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.MessageSort;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Signal;
-import org.eclipse.uml2.uml.StateInvariant;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A helper class for the command.
- *
- */
-public class CommandHelper {
-
-
- /**
- * Title for dialog of no referenced interaction error
- */
- private static final String NO_REFERENCED_INTERACTION_DIALOG_TITLE = "No referenced interaction"; //$NON-NLS-1$
-
- /**
- * Message for dialog of no referenced interaction error
- */
- private static final String NO_REFERENCED_INTERACTION_DIALOG_MSG = "Couldn't had message if there isn't referenced interaction"; //$NON-NLS-1$
-
- /**
- * Message for wrong gate container type error
- */
- private static final String WRONG_GATE_CONTAINER_TYPE_ERROR_MSG = "Wrong element UML type for create a gate"; //$NON-NLS-1$
-
- /**
- * Title for dialog of choose actual gate
- */
- private static final String CHOOSE_GATE_DIALOG_TITLE = "Actual gates of the interaction use"; //$NON-NLS-1$
-
- /**
- * Message for dialog of choose actual gate
- */
- private static final String CHOOSE_GATE_DIALOG_MSG = "Choose the gate to attach the message"; //$NON-NLS-1$
-
-
-
- /**
- * Create a message on the given interaction. It only creates the message and not its messages end.
- *
- * @param interaction
- * the containing interaction
- * @param messageSort
- * the messageSort.
- * @return the created message
- */
- public static Message doCreateMessage(Interaction interaction, MessageSort messageSort, NamedElement signature) {
- Message message = interaction.createMessage(null);
-
- // Set the interaction that will contain the message
- message.setInteraction(interaction);
-
- // Set MessageSort
- message.setMessageSort(messageSort);
-
- String prefix = "";
-
- if(signature != null) {
- prefix = signature.getName() + "_";
- }
-
- ElementInitializers.init_NamedElement(message, prefix);
-
- if(signature != null) {
- message.setSignature(signature);
- }
-
- return message;
- }
-
- /**
- * Create message occurence specification
- *
- * @param interaction
- * The interaction
- * @param event
- * The event to attach
- * @return The message occurence specification
- */
- public static MessageOccurrenceSpecification doCreateMessageOccurrence(InteractionFragment fragment, Event event, Lifeline lifeline) {
-
- // Create the MOS
- MessageOccurrenceSpecification mos = UMLFactory.eINSTANCE.createMessageOccurrenceSpecification();
-
- // Configure the MOS
- doConfigureOccurenceSpecification(mos, event, fragment, lifeline);
-
- return mos;
- }
-
-
- /**
- * Create an ExecutionOccurrenceSpecification
- *
- * @param es
- * the ExecutionSpecification associated with this ExecutionOccurrenceSpecification.
- * @param event
- * the event associated with this OccurrenceSpecification. It must be of type ExecutionEvent.
- * @param fragment
- * the fragment enclosing this OccurenceSpecifcation. It must be an Interaction or an Operand.
- * @return the Execution Occurrence Specification
- */
- public static ExecutionOccurrenceSpecification doCreateExecutionOccurenceSpecification(ExecutionSpecification es, InteractionFragment fragment, Lifeline lifeline) {
-
- // Create the ExecutionOccurrenceSpecification
- ExecutionOccurrenceSpecification eos = UMLFactory.eINSTANCE.createExecutionOccurrenceSpecification();
-
- // Configure the EOS.
- // The event is an ExecutionEvent
- doConfigureOccurenceSpecification(eos, null, fragment, lifeline);
-
- // Set the executionSpecification of the ExecutionOccurrenceSpecification
- eos.setExecution(es);
-
- return eos;
- }
-
- /**
- * Configure an OccurrenceSpecification
- *
- * @param os
- * the occurrenceSpecification to configure
- * @param event
- * the event to associated with the {@link OccurrenceSpecification}
- * @param fragment
- * the fragment containing the {@link OccurrenceSpecification}. It can be an {@link Interaction} or an {@link InteractionOperand}
- * @param lifeline
- * the covered lifeline
- */
- private static void doConfigureOccurenceSpecification(OccurrenceSpecification os, Event event, InteractionFragment fragment, Lifeline lifeline) {
-
- // Set the Container of the OccurrenceSpecification
- if(fragment instanceof Interaction) {
- os.setEnclosingInteraction((Interaction)fragment);
- } else if(fragment instanceof InteractionOperand) {
- os.setEnclosingOperand((InteractionOperand)fragment);
- }
-
- // Set the covered lifeline
- os.getCovereds().add(lifeline);
-
- // Set the event of the OccurrenceSpecification
- //now it doesn't exist
- //os.setEvent(event);
-
- }
-
- /**
- * Attach an Interaction on a Lifeline
- *
- * @param lifeline
- * The lifeline
- * @param fragment
- * The interaction fragment
- */
- public static void setSingleCovered(Lifeline lifeline, InteractionFragment fragment) {
- if(!fragment.getCovereds().contains(lifeline)) {
- fragment.getCovereds().add(lifeline);
- }
- }
-
-
-
- /**
- * Get the signature of the message. Opens a dialog box to select a signature.
- *
- * @param model
- * The model
- * @param source
- * The source of the message
- * @param target
- * The target of the message
- * @return null, if cancel has been pressed. An empty list if the null Element has been
- * selected, or a list with the selected element.
- */
- public static List<NamedElement> getSignature(Element model, Element source, Element target) {
- return getSignature(model, source, target, null);
- }
-
- /**
- * Get the signature of the message. Opens a dialog box to select a signature. Inputs depends on
- * the messageSort, if any.
- *
- * @param model
- * The model
- * @param source
- * The source of the message
- * @param target
- * The target of the message
- * @param messageSort
- * true if message sort is set
- * @return null, if cancel has been pressed. An empty list if the null Element has been
- * selected, or a list with the selected element.
- */
- public static List<NamedElement> getSignature(Element model, Element source, Element target, MessageSort messageSort) {
-
- // element where to look for parents
- Element parentsOwner = target;
-
- // default values
- // used for asynch message where messageSort = null
- boolean useOperations = true;
- boolean useSignals = true;
-
- // according to the type of the message
- // choose which types we should care of
- if(MessageSort.SYNCH_CALL_LITERAL.equals(messageSort)) {
- useSignals = false;
- } else if(MessageSort.CREATE_MESSAGE_LITERAL.equals(messageSort) || MessageSort.DELETE_MESSAGE_LITERAL.equals(messageSort)) {
- useOperations = false;
- } else if(MessageSort.REPLY_LITERAL.equals(messageSort)) {
- parentsOwner = source;
- useSignals = false;
- }
-
- LinkedHashMap<EClass, List<EObject>> mapTypesPossibleParents = new LinkedHashMap<EClass, List<EObject>>();
-
- if(useSignals) {
- mapTypesPossibleParents.put(UMLPackage.eINSTANCE.getSignal(), new LinkedList<EObject>());
- }
- if(useOperations) {
- mapTypesPossibleParents.put(UMLPackage.eINSTANCE.getOperation(), new LinkedList<EObject>());
- }
-
- // add the parents we can find
- boolean existingParent = false;
- List<Type> types = new ArrayList<Type>();
- if(parentsOwner instanceof InteractionFragment) {
- EList<Lifeline> lifelines = ((InteractionFragment)parentsOwner).getCovereds();
- for(Lifeline l : lifelines) {
- if(l.getRepresents() != null && l.getRepresents().getType() != null) {
- types.add(l.getRepresents().getType());
- }
- boolean result = addParentsFromLifeline(l, mapTypesPossibleParents);
- if(result) {
- existingParent = true;
- }
- }
- } else if(parentsOwner instanceof Lifeline) {
- Lifeline l = (Lifeline)parentsOwner;
- if(l.getRepresents() != null && l.getRepresents().getType() != null) {
- types.add(l.getRepresents().getType());
- }
- existingParent = addParentsFromLifeline(l, mapTypesPossibleParents);
- }
-
-
- // if no parent available => no signature
- if(!existingParent) {
- return new ArrayList<NamedElement>();
- }
-
- Set<EObject> existingElements = getExistingElementsFromParents(mapTypesPossibleParents);
-
- // fix bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=383420, remove connection feedbacks before opening dialog
- clearConnectionFeedback();
-
- TransactionalEditingDomain editingDomain;
- try {
- editingDomain = ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(model);
- } catch (ServiceException ex) {
- UMLDiagramEditorPlugin.log.error(ex);
- return Collections.<NamedElement> emptyList();
- }
-
- // Open the selection dialog
- SelectOrCreateDialog dialog = new SelectOrCreateDialog(Display.getCurrent().getActiveShell(), Messages.CommandHelper_CreateMessage, createTypeLabelProvider(), new AdapterFactoryLabelProvider(UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()), editingDomain, existingElements, mapTypesPossibleParents, types);
-
- // Get the selected result
- if(dialog.open() == Window.OK) {
- // list to return
- List<NamedElement> returnElements = new ArrayList<NamedElement>();
- EObject element = dialog.getSelected();
- if(element instanceof NamedElement) {
-
- returnElements.add((NamedElement)element);
- return returnElements;
- }
- return returnElements;
- }
-
- return null;
- }
-
- private static void clearConnectionFeedback() {
- AspectUnspecifiedTypeConnectionToolEx conTool = null;
- IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- if(editor instanceof CoreMultiDiagramEditor) {
- editor = ((CoreMultiDiagramEditor)editor).getActiveEditor();
- if(editor instanceof DiagramEditor) {
- DiagramEditor de = (DiagramEditor)editor;
- DiagramEditPart diagramEP = de.getDiagramEditPart();
- EditDomain domain = diagramEP.getRoot().getViewer().getEditDomain();
- Tool tool = domain.getActiveTool();
- if(tool instanceof AspectUnspecifiedTypeConnectionToolEx) {
- conTool = (AspectUnspecifiedTypeConnectionToolEx)tool;
- conTool.clearConnectionFeedback();
- }
- }
- }
- }
-
- /**
- * find the existing elements from the possible parents
- *
- * @param mapTypesPossibleParents
- * map of list containing the possible parents
- * @return
- */
- private static Set<EObject> getExistingElementsFromParents(Map<EClass, List<EObject>> mapTypesPossibleParents) {
- // find the existing elements using the parents we just found
- Set<EObject> existingElements = new HashSet<EObject>();
- for(EClass eClass : mapTypesPossibleParents.keySet()) {
- List<EObject> parents = mapTypesPossibleParents.get(eClass);
- for(EObject parent : parents) {
- if(parent instanceof Classifier) {
- existingElements.addAll(((Classifier)parent).getAllOperations());
-
- // add operations from port
- EList<Property> attrs = ((Classifier)parent).getAllAttributes();
- for(Property p : attrs) {
- if(p instanceof Port && p.getType() instanceof Classifier) {
- existingElements.addAll(((Classifier)p.getType()).getAllOperations());
- }
- }
-
- } else if(parent instanceof Package) {
- EList<Element> ownedElements = ((Package)parent).allOwnedElements();
- for(Element e : ownedElements) {
- if(e instanceof Signal) {
- existingElements.add(e);
- }
- }
- }
- }
- }
- return existingElements;
- }
-
- /**
- * Create a specific label provider for types
- * which remove everything after the first space
- *
- * @return the label provider
- */
- private static AdapterFactoryLabelProvider createTypeLabelProvider() {
- AdapterFactoryLabelProvider typeLabelProvider = new AdapterFactoryLabelProvider(UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory()) {
-
- @Override
- public String getText(Object object) {
- // remove the supertypes from the label
- // => keep only the first word
- String text = super.getText(object);
- int index = text.indexOf(" "); //$NON-NLS-1$
- if(index != -1) {
- text = text.substring(0, index);
- }
- return text;
- }
- };
- return typeLabelProvider;
- }
-
- /**
- * add to the map the possible parents (classes, packages)
- * founded "in" the lifeline
- *
- * @param l
- * The lifeline where to look for possible parents
- * @param mapTypesPossibleParents
- * The map where to store this parents
- * @return true if at least one parent was added
- */
- private static boolean addParentsFromLifeline(Lifeline l, Map<EClass, List<EObject>> mapTypesPossibleParents) {
- ConnectableElement e = l.getRepresents();
-
- boolean existingParent = false;
-
- // If there is no connectable element (ie : lifeline doesn't have a represents property yet)
- if(e == null) {
- return false;
- }
-
- Type type = e.getType();
- if(type == null) {
- return false;
- }
-
- // the classes are related to operation
- List<EObject> possibleClassifier = mapTypesPossibleParents.get(UMLPackage.eINSTANCE.getOperation());
- if(possibleClassifier != null) {
- if(type instanceof Classifier) {
- Classifier classifier = (Classifier)type;
- possibleClassifier.add(classifier);
-
- // add the supertypes of the class
- possibleClassifier.addAll(classifier.allParents());
- existingParent = true;
- }
- }
-
- // and the packages to signal
- List<EObject> possiblePackages = mapTypesPossibleParents.get(UMLPackage.eINSTANCE.getSignal());
- if(possiblePackages != null && type.getPackage() != null) {
- Package package_ = type.getPackage();
- possiblePackages.add(package_);
- // add the owners of the package
- possiblePackages.addAll(package_.allOwningPackages());
- existingParent = true;
- }
-
- return existingParent;
- }
-
- /**
- * Get the signature of the message. Opens a dialog box to select a signature. Inputs depends on
- * the messageSort, if any.
- *
- * @param availableProperties
- * list of available properties
- * @return null, if cancel has been pressed. An empty list if the null Element has been
- * selected, or a list with the selected element.
- */
- public static Property getProperties(List<Property> availableProperties) {
-
- ILabelProvider labelProvider = new AdapterFactoryLabelProvider(UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getCurrent().getActiveShell(), labelProvider);
- dialog.setTitle("Property Selection"); //$NON-NLS-1$
- dialog.setMessage("Select a property (* = any string, ? = any char):"); //$NON-NLS-1$
-
- if(availableProperties == null || availableProperties.isEmpty()) {
- return null;
- }
-
- dialog.setElements(availableProperties.toArray());
-
- Property element = null;
- int dialogResult = dialog.open();
- if(dialogResult == Window.OK) {
- if(!"".equals(dialog.getFirstResult())) { //$NON-NLS-1$
- element = (Property)dialog.getFirstResult();
- }
- }
- return element;
- }
-
- /**
- * Execute a EMF command without history (cancelation usage)
- *
- * @param editingDomain
- * The editing domain
- * @param command
- * The command
- */
- public static void executeCommandWithoutHistory(EditingDomain editingDomain, org.eclipse.emf.common.command.Command command) {
- try {
- CommandStack commandStack = editingDomain.getCommandStack();
- if(commandStack instanceof TransactionalCommandStack) {
- ((TransactionalCommandStack)commandStack).execute(command, Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE));
- } else {
- commandStack.execute(command);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (RollbackException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Execute a EMF command without history
- *
- * @param editingDomain
- * The editing domain
- * @param command
- * The command
- * @param flag
- */
- public static void executeCommandWithoutHistory(EditingDomain editingDomain, org.eclipse.emf.common.command.Command command, boolean flag) {
- TransactionalCommandStackImpl stack = new TransactionalCommandStackImpl();
- stack.setEditingDomain((InternalTransactionalEditingDomain)editingDomain);
- try {
- stack.execute(command, Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE));
- } catch (InterruptedException e) {
- e.printStackTrace();
- } catch (RollbackException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Retrieve the Lifeline associated with an ExecutionSpecification.
- * According to the UML Specification, an ExecutionSpecification must have a start and a finish.
- *
- * In Papyrus, an ExecutionSpecification may not have a start and finish.
- * To handle this specific case, we return the first lifeline that the ES covered.
- *
- * @param es
- * the targeted execution specification
- * @return the associated lifeline, or null if the ES has no start, no finish, no covered lifelines.
- */
- public static Lifeline getExecutionSpecificationLifeline(ExecutionSpecification es) {
- Lifeline lifeline = null;
- if(es.getStart() != null) {
- lifeline = es.getStart().getCovereds().get(0);
- } else if(es.getFinish() != null) {
- lifeline = es.getFinish().getCovereds().get(0);
- }
-
- if(lifeline == null) {
- if(!es.getCovereds().isEmpty()) {
- lifeline = es.getCovereds().get(0);
- }
- }
- return lifeline;
- }
-
- /**
- * Create an DestructionEvent and an occurrenceSpecification bounds to the lifeline
- *
- * @param destructionEvent
- * the destructionEvent
- * @param lifeline
- * the lifeline associated with the destructionEvent
- * @param modelContainer
- * the container of the occurrenceSpecification that will bound the lifeline and the destructionEvent.
- * @return
- */
- // public static DestructionEvent doCreateDestructionEvent(Lifeline lifeline, Object modelContainer) {
- //
- // // Get the nearest package
- // Package pack = lifeline.getNearestPackage();
- //
- // EClass destructionEventEClass = UMLPackage.eINSTANCE.getDestructionEvent();
- // // Add the destructionEvent to the Package
- // DestructionEvent destructionEvent = (DestructionEvent)pack.createPackagedElement(ElementInitializers.getNextNumberedName(pack.getOwnedElements(), destructionEventEClass.getName()), destructionEventEClass);
- //
- // // Create an occurrenceSpecification
- // Element element = createElement(modelContainer, UMLPackage.eINSTANCE.getOccurrenceSpecification());
- // OccurrenceSpecification os = null;
- // if(element instanceof OccurrenceSpecification) {
- // os = (OccurrenceSpecification)element;
- // doConfigureOccurenceSpecification(os, destructionEvent, (InteractionFragment)modelContainer, lifeline);
- // }
- //
- // return destructionEvent;
- // }
-
- /**
- * Create an DestructionOccurrenceSpecification bounds to the lifeline
- *
- * @param lifeline
- * the lifeline associated with the destructionEvent
- * @param modelContainer
- * the container of the occurrenceSpecification that will bound the lifeline and the destructionEvent.
- * @return
- */
- public static DestructionOccurrenceSpecification doCreateDestructionOccurrenceSpecification(Lifeline lifeline, Object modelContainer) {
-
- // Get the nearest package
- Package pack = lifeline.getNearestPackage();
-
- // Create an occurrenceSpecification
- Element element = createElement(modelContainer, UMLPackage.eINSTANCE.getDestructionOccurrenceSpecification());
- DestructionOccurrenceSpecification os = null;
- if(element instanceof DestructionOccurrenceSpecification) {
- os = (DestructionOccurrenceSpecification)element;
- doConfigureOccurenceSpecification(os, null, (InteractionFragment)modelContainer, lifeline);
- }
-
- return os;
- }
-
-
-
-
-
- /**
- * Create an StateInvariant
- *
- * @param lifeline
- * the lifeline on which the stateInvariant is created (or which is covered by the StateInvariant).
- * @param modelContainer
- * the model container
- * @return the created stateInvariant or null
- */
- public static StateInvariant doCreateStateInvariant(Lifeline lifeline, Object modelContainer) {
- StateInvariant stateInvariant = null;
-
- Element element = createElement(modelContainer, UMLPackage.eINSTANCE.getStateInvariant());
-
- if(element instanceof StateInvariant) {
- stateInvariant = (StateInvariant)element;
- // Get the covered lifeline
- stateInvariant.getCovereds().add(lifeline);
-
- // Create the associated invariant
- stateInvariant.createInvariant("");
- }
-
- return stateInvariant;
- }
-
- private static Element createElement(Object modelContainer, EClass eClass) {
-
- // Get the enclosing interaction fragment
- if(modelContainer instanceof InteractionOperand) {
- InteractionOperand interactionOperand = (InteractionOperand)modelContainer;
- // Create the ES
- return interactionOperand.createFragment(ElementInitializers.getNextNumberedName(interactionOperand.getFragments(), eClass.getName()), eClass);
- } else if(modelContainer instanceof Interaction) {
- Interaction interaction = (Interaction)modelContainer;
- // Create the ES
- return interaction.createFragment(ElementInitializers.getNextNumberedName(interaction.getFragments(), eClass.getName()), eClass);
- }
- return null;
- }
-
-
- /**
- * Create a CombinedFragment and its associated interaction Operand
- *
- * @param modelContainer
- * the container of the CF. It could be an InteractionOperand or an Interaction.
- * @param operatorKind
- * the operatorKind of the combinedFragment
- * @return the created CombinedFragment or null
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public static CombinedFragment doCreateCombinedFragment(Object modelContainer, InteractionOperatorKind operatorKind, Collection coveredLifelines) {
- CombinedFragment combinedFragment = null;
-
- Element element = createElement(modelContainer, UMLPackage.eINSTANCE.getCombinedFragment());
- if(element instanceof CombinedFragment) {
- combinedFragment = (CombinedFragment)element;
- combinedFragment.getCovereds().addAll(coveredLifelines);
-
- // Set the operator kind
- combinedFragment.setInteractionOperator(operatorKind);
-
- // Create the operand
- createCoRegionInteractionOperand(combinedFragment);
- }
- return combinedFragment;
- }
-
- /**
- * Create a CoRegion element :
- * a CombinedFragment with InteractionOperator set to 'Parallel'
- *
- * @param modelContainer
- * the parent element of the CoRegion
- * @param coveredLifeline
- * the lifeline on which the CoRegion is created
- * @return the created CoRegion or null
- */
- public static CombinedFragment doCreateCoRegion(Object modelContainer, Lifeline coveredLifeline) {
-
- // Create a Parallel CombinedFragment
- Element element = createElement(modelContainer, UMLPackage.eINSTANCE.getCombinedFragment());
- if(element instanceof CombinedFragment) {
- CombinedFragment combinedFragment = (CombinedFragment)element;
- combinedFragment = (CombinedFragment)element;
- combinedFragment.getCovereds().add(coveredLifeline);
-
- // Set the operator kind
- combinedFragment.setInteractionOperator(InteractionOperatorKind.PAR_LITERAL);
-
- return combinedFragment;
- }
- return null;
- }
-
-
- /**
- * Create an ExecutionSpecification. It also creates the start and finish ExecutionOccurenceSpecification of the ExecutionSpecification, and their
- * corresponding events.
- *
- * @param es
- * the executionSpecification to create.
- * @param lifeline
- * the lifeline covered by the ExecutionSpecification.
- * @return the created executionSpecification
- */
- public static ExecutionSpecification doCreateExecutionSpecification(ExecutionSpecification es, Lifeline lifeline, Object modelContainer) {
- InteractionFragment interactionFragment = null;
- // Get the enclosing interaction fragment
- if(modelContainer instanceof InteractionOperand) {
- InteractionOperand interactionOperand = (InteractionOperand)modelContainer;
- interactionFragment = interactionOperand;
- } else {
- Interaction interaction = lifeline.getInteraction();
- interactionFragment = interaction;
- }
-
- // Create events
- org.eclipse.uml2.uml.Package eventContainer = interactionFragment.getNearestPackage();
-
- // ExecutionEvent startingExecutionEvent = EventHelper.doCreateExecutionEvent(eventContainer);
- // ExecutionEvent finishingExecutionEvent = EventHelper.doCreateExecutionEvent(eventContainer);
-
- // Create fragments in the correct order : start OccurenceSpecification, ExecutionSpecification, finish OccurenceSpecification
- // start
- ExecutionOccurrenceSpecification start = CommandHelper.doCreateExecutionOccurenceSpecification(null, interactionFragment, lifeline);
-
- // Create the ExecutionSpecification
- if(modelContainer instanceof InteractionOperand) {
- InteractionOperand interactionOperand = (InteractionOperand)modelContainer;
- // Create the ES
- es = (ExecutionSpecification)interactionOperand.createFragment(null, es.eClass());
- } else {
- Interaction interaction = lifeline.getInteraction();
- // Create the ES
- es = (ExecutionSpecification)interaction.createFragment(null, es.eClass());
- }
-
- // finish
- ExecutionOccurrenceSpecification finish = CommandHelper.doCreateExecutionOccurenceSpecification(es, interactionFragment, lifeline);
-
- // Get the covered lifeline
- es.getCovereds().add(lifeline);
-
- // Set the start and the finish ExecutionOccurrenceSpecification
- es.setStart(start);
- es.setFinish(finish);
- start.setExecution(es);
-
- // Init the name of the ES and its EOS
- initExecutionSpecificationName(es);
-
- return es;
- }
-
-
- private static void initExecutionSpecificationName(ExecutionSpecification es) {
-
- String body = ""; //$NON-NLS-1$
- if(es instanceof ActionExecutionSpecification) {
- body = "ActionExecSpec"; //$NON-NLS-1$
- } else {
- body = "BehaviorExecSpec"; //$NON-NLS-1$
- }
- // Init the name
- ElementInitializers.init_NamedElement(es, "", body, ""); //$NON-NLS-1$ //$NON-NLS-2$
-
- // Init the name of the related executionOccurrenceSpecification
- ElementInitializers.init_NamedElement(es.getStart(), "", es.getName(), "Start"); //$NON-NLS-1$ //$NON-NLS-2$
- ElementInitializers.init_NamedElement(es.getFinish(), "", es.getName(), "Finish"); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-
- /**
- * Create a MessageEnd
- *
- * @param interaction
- * fragment
- * The Interaction fragment
- * @param callEvent
- * The call event
- * @param element
- * The element
- * @param direction
- * The message direction
- * @return A MessageOccurrenceSpecification if element is ExecutionSpecification or Lifeline. A
- * Gate if element is Interaction or CombinedFragment or InteractionUse
- */
- public static MessageEnd createMessageEnd(InteractionFragment interactionFragment, Event event, Element element, MessageDirection direction) {
- MessageEnd endMsg = null;
- if(element instanceof Lifeline) {
- endMsg = doCreateMessageOccurrence(interactionFragment, event, (Lifeline)element);
- } else if(element instanceof ExecutionSpecification) {
- Lifeline lifeline = getExecutionSpecificationLifeline((ExecutionSpecification)element);
- endMsg = doCreateMessageOccurrence(interactionFragment, event, lifeline);
- } else if(element instanceof Interaction || element instanceof CombinedFragment || element instanceof InteractionUse) {
- endMsg = doCreateGate(element, direction);
- }
- return endMsg;
- }
-
- /**
- * Create gate if element is a Interaction, a Combined Fragment or a Interaction Use
- *
- * @param element
- * The element
- * @param direction
- * The message direction
- * @return The gate
- * @throws IllegalArgumentException
- * if the element is not a right element type
- */
- public static Gate doCreateGate(Element element, MessageDirection direction) {
- Gate gate = null;
-
- if(element instanceof Interaction) {
- gate = ((Interaction)element).createFormalGate(null);
- } else if(element instanceof CombinedFragment) {
- CombinedFragment combinedFragment = (CombinedFragment)element;
- EList<Gate> cfragmentGates = combinedFragment.getCfragmentGates();
- if(cfragmentGates.isEmpty()) {
- gate = ((CombinedFragment)element).createCfragmentGate(null);
- } else {
- // remove connection feedbacks before opening dialog
- clearConnectionFeedback();
-
- Shell shell = Display.getCurrent().getActiveShell();
- ILabelProvider labelProvider = new AdapterFactoryLabelProvider(UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
- dialog.setTitle("Gates of the CombinedFragment has");
- dialog.setMessage(CHOOSE_GATE_DIALOG_MSG);
- dialog.setMultipleSelection(false);
-
- List<Gate> gates = new ArrayList<Gate>();
- for(Gate actualGate : cfragmentGates) {
- gates.add(actualGate);
- }
-
- dialog.setElements(gates.toArray());
- if(dialog.open() == Window.OK) {
- gate = (Gate)dialog.getFirstResult();
- } else { // cancel button
- throw new OperationCanceledException();
- }
- }
- } else if(element instanceof InteractionUse) {
- Shell shell = Display.getCurrent().getActiveShell();
- InteractionUse interactionUse = (InteractionUse)element;
-
- if(interactionUse.getRefersTo() == null) {
- MessageDialog.openError(shell, NO_REFERENCED_INTERACTION_DIALOG_TITLE, NO_REFERENCED_INTERACTION_DIALOG_MSG);
- return null;
- }
-
- ILabelProvider labelProvider = new AdapterFactoryLabelProvider(UMLDiagramEditorPlugin.getInstance().getItemProvidersAdapterFactory());
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, labelProvider);
- dialog.setTitle(CHOOSE_GATE_DIALOG_TITLE);
- dialog.setMessage(CHOOSE_GATE_DIALOG_MSG);
- dialog.setMultipleSelection(false);
-
- List<Gate> gates = new ArrayList<Gate>();
- for(Gate actualGate : ((InteractionUse)element).getActualGates()) {
- if(actualGate.getName().startsWith(direction.getName())) {
- gates.add(actualGate);
- }
- }
- dialog.setElements(gates.toArray());
- if(dialog.open() == Window.OK) {
- gate = (Gate)dialog.getFirstResult();
- }
- } else {
- throw new IllegalArgumentException(WRONG_GATE_CONTAINER_TYPE_ERROR_MSG);
- }
-
- if(gate != null) {
- ElementInitializers.init_NamedElement(gate, direction.toString().toLowerCase() + "_"); //$NON-NLS-1$
- }
-
- return gate;
- }
-
- /**
- * Creates a message and manage the creation of a message from/to a CoRegion
- *
- * @param interaction
- * the interaction containing the message.
- * @param messageSort
- * the messageSort of the message, it can be null
- * @param source
- * the source of the message, it can be null
- * @param target
- * the target of the message, it can be null
- * @param params
- * a map of params. It must at least contain the source and target container;
- * @return the created message.
- */
- public static Message doCreateMessage(Interaction interaction, MessageSort messageSort, Element source, Element target, Map<Object, Object> params) {
- InteractionFragment sourceContainer = (InteractionFragment)params.get(SequenceRequestConstant.SOURCE_MODEL_CONTAINER);
- InteractionFragment targetContainer = (InteractionFragment)params.get(SequenceRequestConstant.TARGET_MODEL_CONTAINER);
-
- Lifeline lifeline = (Lifeline)params.get(SequenceRequestConstant.LIFELINE_GRAPHICAL_CONTAINER);
- if(lifeline != null) {
- if(source instanceof CombinedFragment) {
- CombinedFragment cf = (CombinedFragment)source;
-
- if(InteractionOperatorKind.PAR_LITERAL.equals(cf.getInteractionOperator())) {
- InteractionOperand interactionOperand = getCoRegionInteractionOperand(cf);
- sourceContainer = interactionOperand;
- targetContainer = interactionOperand;
- source = lifeline;
- if(target instanceof Lifeline) {
- addCoveredLifelineToCombinedFragment((Lifeline)target, cf);
- }
- }
- } else if(target instanceof CombinedFragment) {
- CombinedFragment cf = (CombinedFragment)target;
- if(InteractionOperatorKind.PAR_LITERAL.equals(cf.getInteractionOperator())) {
- InteractionOperand interactionOperand = getCoRegionInteractionOperand(cf);
- sourceContainer = interactionOperand;
- targetContainer = interactionOperand;
- target = lifeline;
- if(source instanceof Lifeline) {
- addCoveredLifelineToCombinedFragment((Lifeline)source, cf);
- }
- }
- }
- }
- return doCreateMessage(interaction, messageSort, source, target, sourceContainer, targetContainer);
- }
-
- private static void addCoveredLifelineToCombinedFragment(Lifeline coveredLifeline, CombinedFragment cf) {
- cf.getCovereds().add(coveredLifeline);
-
- for(InteractionOperand io : cf.getOperands()) {
- io.getCovereds().add(coveredLifeline);
- }
- }
-
- /**
- * Get the interactionOperand where the occurrenceSpecification will be created
- */
- public static InteractionOperand getCoRegionInteractionOperand(CombinedFragment cf) {
- InteractionOperand interactionOperand = null;
-
- // Search in the existing operands if there are any operand without fragments.
- for(InteractionOperand existingOperand : cf.getOperands()) {
- if(existingOperand.getFragments().isEmpty()) {
- interactionOperand = existingOperand;
- break;
- }
- }
-
- // If the operand is still null, we create a new operand in the combinedFragment.
- if(interactionOperand == null) {
- interactionOperand = createCoRegionInteractionOperand(cf);
- }
- return interactionOperand;
- }
-
- private static InteractionOperand createCoRegionInteractionOperand(CombinedFragment cf) {
- InteractionOperand interactionOperand = cf.createOperand("");
- interactionOperand.getCovereds().addAll(cf.getCovereds());
- interactionOperand.setName(ElementInitializers.getNextNumberedName(cf.getOperands(), interactionOperand.eClass().getName()));
- return interactionOperand;
- }
-
- /**
- * Create a message. It also creates its message end, their corresponding events and updates the signature of the message.
- *
- * @param container
- * the interaction containing the message.
- * @param messageSort
- * the messageSort of the message, it can be null
- * @param source
- * the source of the message, it can be null
- * @param target
- * the target of the message, it can be null
- * @return the created message
- */
- public static Message doCreateMessage(Interaction container, MessageSort messageSort, Element source, Element target, InteractionFragment sourceContainer, InteractionFragment targetContainer) {
- return doCreateMessage(container, messageSort, source, target, sourceContainer, targetContainer, null, null);
- }
-
- /**
- * Create a message. It also creates its message end (if not provided), their corresponding events and updates the signature of the message.
- *
- * @param container
- * the interaction containing the message.
- * @param messageSort
- * the messageSort of the message, it can be null
- * @param source
- * the source of the message, it can be null
- * @param target
- * the target of the message, it can be null
- * @param sendMessageEnd
- * the existing Send MessageEnd of the message
- * @param receiveMessageEnd
- * the existing Receive MessageEnd of the message
- * @return the created message
- */
- public static Message doCreateMessage(Interaction container, MessageSort messageSort, Element source, Element target, InteractionFragment sourceContainer, InteractionFragment targetContainer, MessageEnd sendMessageEnd, MessageEnd receiveMessageEnd) {
-
- List<NamedElement> signatures = getSignature(container.getModel(), source, target, messageSort);
-
- // If signatures == null, means the user click on cancel button during selection --> Cancel the whole process of creation
- if(signatures == null) {
- return null;
- }
-
- NamedElement signature = null;
- if(!signatures.isEmpty()) {
- signature = signatures.get(0);
- }
-
- // Get the correct MessageSort
- messageSort = getMessageSort(signature, messageSort);
-
- // Create the message
- Message message = doCreateMessage(container, messageSort, signature);
-
- // Create the two message ends
- if(sendMessageEnd == null && source != null) {
- sendMessageEnd = createMessageEnd(sourceContainer, EventHelper.doCreateSendEvent(messageSort, container, signature), source, MessageDirection.OUT);
- }
- if(receiveMessageEnd == null && target != null) {
- receiveMessageEnd = createMessageEnd(targetContainer, EventHelper.doCreateReceiveEvent(messageSort, container, signature), target, MessageDirection.IN);
- }
-
- // Update the messages end with the message
- if(sendMessageEnd != null) {
- sendMessageEnd.setMessage(message);
- ElementInitializers.init_NamedElement(sendMessageEnd, "", message.getName(), "Send"); //$NON-NLS-1$ //$NON-NLS-2$
- // Update the message with the messages end
- message.setSendEvent(sendMessageEnd);
- }
- if(receiveMessageEnd != null) {
- receiveMessageEnd.setMessage(message);
- ElementInitializers.init_NamedElement(receiveMessageEnd, "", message.getName(), "Recv"); //$NON-NLS-1$ //$NON-NLS-2$
- // Update the message with the messages end
- message.setReceiveEvent(receiveMessageEnd);
- }
-
- return message;
- }
-
-
- /**
- * Get the messageSort of a message if it doesn't exist yet depending of the messageSignature.
- * If no messageSort exists, and if the signature is null, then return a MessageSort.ASYNCH_CALL_LITERAL
- *
- * @param signature
- * the signature of the message or null
- * @param messageSort
- * a messageSort or null
- * @return the messageSort
- */
- private static MessageSort getMessageSort(NamedElement signature, MessageSort messageSort) {
- if(messageSort == null) {
- if(signature instanceof Signal) {
- return MessageSort.ASYNCH_SIGNAL_LITERAL;
- } else {
- return MessageSort.ASYNCH_CALL_LITERAL;
- }
- }
- return messageSort;
- }
-
- /**
- * A method to validate that both source and target of a request have valid container for the creation of a message.
- *
- * @param request
- * the request
- * @return false if the container of the source or the target is null and if the two container are not equals
- */
- public static boolean hasValidContainer(IEditCommandRequest request) {
- Object srcEndContainer = request.getParameter(SequenceRequestConstant.SOURCE_MODEL_CONTAINER);
- Object tgtEndContainer = request.getParameter(SequenceRequestConstant.TARGET_MODEL_CONTAINER);
- if(srcEndContainer == null || tgtEndContainer == null) {
- return false;
- }
-
- /*
- * Message cannot cross InteractionFragment.
- * Either the two message ends are contained into the same InteractionFragment,
- * or one is a gate and the other is in the InteractionFragment containing the gate's CF,
- * or one is a gate and the other is a gate in a CF containing the first gate's CF.
- */
- // into the same InteractionFragment
- if(srcEndContainer.equals(tgtEndContainer)) {
- return true;
- }
- // one is a gate
- if(request instanceof CreateRelationshipRequest) {
- EObject src = ((CreateRelationshipRequest)request).getSource();
- EObject tgt = ((CreateRelationshipRequest)request).getTarget();
- if(!(src instanceof Lifeline)) {
- // send is a gate
- if(src instanceof InteractionOperand) {
- // consider the containing CF
- src = src.eContainer();
- }
- if(src instanceof InteractionFragment) {
- // check whether container of gate is in the target's fragment container
- if(tgtEndContainer instanceof Interaction) {
- if(((Interaction)tgtEndContainer).getFragments().contains(src)) {
- return true;
- }
- }
- if(tgtEndContainer instanceof InteractionOperand) {
- if(((InteractionOperand)tgtEndContainer).getFragments().contains(src)) {
- return true;
- }
- }
- }
- }
- if(!(tgt instanceof Lifeline)) {
- // receive is a gate
- if(tgt instanceof InteractionOperand) {
- // consider the containing CF
- tgt = tgt.eContainer();
- }
- if(tgt instanceof InteractionFragment) {
- // check whether container of gate is in the source's fragment container
- if(srcEndContainer instanceof Interaction && ((Interaction)srcEndContainer).getFragments().contains(tgt)) {
- return true;
- }
- if(srcEndContainer instanceof InteractionOperand && ((InteractionOperand)srcEndContainer).getFragments().contains(tgt)) {
- return true;
- }
- }
- }
- }
- return false;
- }
-
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DestructionOccurrenceUtil.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DestructionOccurrenceUtil.java
deleted file mode 100644
index 0cc381e0c1a..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/DestructionOccurrenceUtil.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Soyatec - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageSort;
-
-
-public class DestructionOccurrenceUtil {
- public static void reorderDestructionOccurrence(List<InteractionFragment> reorderedFragments) {
- int size = reorderedFragments.size();
- List<InteractionFragment> destructionOccurrenceList = new ArrayList<InteractionFragment>(size);
- for(int i = 0; i < size; i++) {
- InteractionFragment o = reorderedFragments.get(i);
- if(o instanceof DestructionOccurrenceSpecification){
- destructionOccurrenceList.add(o);
- }
- }
-
- reorderedFragments.removeAll(destructionOccurrenceList);
- reorderedFragments.addAll(destructionOccurrenceList);
- }
-
- public static void constraintDestructionOccurrence(Message mess, List<InteractionFragment> constraint) {
- if(mess.getMessageSort() != MessageSort.DELETE_MESSAGE_LITERAL)
- return;
- addDestructionOccurrenceConstraint(mess.getReceiveEvent(), constraint);
- addDestructionOccurrenceConstraint(mess.getSendEvent(), constraint);
- }
-
- public static void addDestructionOccurrenceConstraint(MessageEnd end, List<InteractionFragment> constraint) {
- if(end instanceof InteractionFragment){
- InteractionFragment frag = (InteractionFragment) end;
- if(frag.getCovereds().size() > 0){
- Lifeline lifeline = ((InteractionFragment)frag).getCovereds().get(0);
- DestructionOccurrenceSpecification d = findDestructionOccurrence(lifeline);
- if(d != null)
- constraint.add(d);
- }
- }
- }
-
- public static DestructionOccurrenceSpecification findDestructionOccurrence(Lifeline lifeline) {
- EList<InteractionFragment> list = lifeline.getCoveredBys();
- for(InteractionFragment f : list)
- if(f instanceof DestructionOccurrenceSpecification){
- return (DestructionOccurrenceSpecification)f;
- }
-
- return null;
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/EventHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/EventHelper.java
deleted file mode 100644
index b84370f89f1..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/EventHelper.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 Atos Origin.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.ElementInitializers;
-import org.eclipse.uml2.uml.CallEvent;
-import org.eclipse.uml2.uml.Event;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.MessageSort;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Operation;
-import org.eclipse.uml2.uml.Package;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * An utility class to create event elements.
- *
- */
-public class EventHelper {
-
- /**
- * Create an event
- *
- * @param eventContainer
- * the container
- * @return the event
- */
- public static Event doCreateEvent(Package eventContainer, EClass eClass) {
- Event event = (Event)eventContainer.createPackagedElement(null, eClass);
- ElementInitializers.init_NamedElement(event);
- return event;
- }
-
- /**
- * Create an event
- *
- * @param eventContainer
- * the container
- * @return the event
- */
- public static CallEvent doCreateCallEvent(Package eventContainer, Operation operation) {
- CallEvent event = (CallEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getCallEvent());
- event.setOperation(operation);
- return event;
- }
-
-
- /**
- * Create a SendOperation event and initializes its name
- *
- * @param eventContainer
- * the container
- * @param operation
- * the operation of the event. Can't be null
- * @return the sendOperation event
- */
- // Does not exist anymore in UML 2.4
- // public static SendOperationEvent doCreateSendOperationEvent(Package eventContainer, Operation operation) {
- // SendOperationEvent sendOperationEvent = (SendOperationEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getSendOperationEvent());
- // sendOperationEvent.setOperation(operation);
- // return sendOperationEvent;
- // }
-
- /**
- * Create a ReceiveOperation event and initializes its name
- *
- * @param eventContainer
- * the container
- * @param operation
- * the operation of the event. Can't be null
- * @return the receiveOperation event
- */
- // Does not exist anymore in UML 2.4
- // public static ReceiveOperationEvent doCreateReceiveOperationEvent(Package eventContainer, Operation operation) {
- // ReceiveOperationEvent receiveOperationEvent = (ReceiveOperationEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getReceiveOperationEvent());
- // receiveOperationEvent.setOperation(operation);
- // return receiveOperationEvent;
- // }
-
- /**
- * Create a send signal event and initializes its name
- *
- * @param eventContainer
- * the container
- * @param signal
- * the signal of the event. Can't be null
- * @return the send signal event
- */
- // Does not exist anymore in UML 2.4
- // public static SendSignalEvent doCreateSendSignalEvent(Package eventContainer, Signal signal) {
- // SendSignalEvent sendSignalEvent = (SendSignalEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getSendSignalEvent());
- // sendSignalEvent.setSignal(signal);
- // return sendSignalEvent;
- // }
-
- /**
- * Create a ReceiveSignal event and initializes its name
- *
- * @param eventContainer
- * the container
- * @param signal
- * the signal of the event. Can't be null
- * @return the ReceiveSignal event
- */
- // Does not exist anymore in UML 2.4
- // public static ReceiveSignalEvent doCreateReceiveSignalEvent(Package eventContainer, Signal signal) {
- // ReceiveSignalEvent receiveSignalEvent = (ReceiveSignalEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getReceiveSignalEvent());
- // receiveSignalEvent.setSignal(signal);
- // return receiveSignalEvent;
- // }
-
- // Does not exist anymore in UML 2.4
- // /**
- // * Create a receive signal event
- // *
- // * @param eventContainer
- // * the container
- // * @return the receive signal event
- // */
- // public static CreationEvent doCreateCreationEvent(Package eventContainer) {
- // return (CreationEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getCreationEvent());
- // }
- //
- // /**
- // * Create a destruction event
- // *
- // * @param eventContainer
- // * the container
- // * @return the destruction event
- // */
- // public static DestructionEvent doCreateDestructionEvent(Package eventContainer) {
- // return (DestructionEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getDestructionEvent());
- // }
- //
- // /**
- // * Create an execution event
- // *
- // * @param eventContainer
- // * the container
- // * @return the executionEvent
- // */
- // public static ExecutionEvent doCreateExecutionEvent(Package eventContainer) {
- // return (ExecutionEvent)doCreateEvent(eventContainer, UMLPackage.eINSTANCE.getExecutionEvent());
- // }
-
-
- /**
- * Create a receive event in the package containing the interaction
- * If the messageSort is ASYNCH_SIGNAL, it creates a ReceiveSignalEvent
- * If the messageSort is ASYNCH_CALL or SYNCH_CALL or REPLY_LITERAL, it creates a ReceiveOperationEvent
- * If the messageSort is CREATE_MESSAGE, it creates a CreationEvent.
- * If the messageSort is DELETE_MESSAGE, it creates a DestructionEvent.
- *
- * @param messageSort
- * the messageSort
- * @param interaction
- * the interaction
- * @param signature
- * the signature of the message
- * @return the created receive event or null
- */
- public static Event doCreateReceiveEvent(MessageSort messageSort, Interaction interaction, NamedElement signature) {
- Package eventContainer = interaction.getNearestPackage();
- Event event = null;
-
- switch(messageSort) {
- case ASYNCH_SIGNAL_LITERAL:
- //event = doCreateReceiveSignalEvent(eventContainer, (Signal)signature);
- break;
- case ASYNCH_CALL_LITERAL:
- case SYNCH_CALL_LITERAL:
- case REPLY_LITERAL:
- //event = doCreateReceiveOperationEvent(eventContainer, (Operation)signature);
- break;
- case CREATE_MESSAGE_LITERAL:
- //event = doCreateCreationEvent(eventContainer);
- break;
- case DELETE_MESSAGE_LITERAL:
- //event = doCreateDestructionEvent(eventContainer);
- break;
- default:
- break;
-
- }
- return event;
- }
-
- /**
- * Create a sending event in the package containing the interaction.
- * If the messageSort is ASYNCH_SIGNAL, CREATE_MESSAGE, DELETE_MESSAGE, it creates a SendSignalEvent
- * If the messageSort is ASYNCH_CALL, SYNCH_CALL, REPLY_LITERAL, it creates a SendOperationEvent.
- *
- * @param messageSort
- * the messageSort
- * @param interaction
- * the interaction
- * @param signature
- * the signature of the message
- * @return the created send event or null
- */
- public static Event doCreateSendEvent(MessageSort messageSort, Interaction interaction, NamedElement signature) {
- Package eventContainer = interaction.getNearestPackage();
- Event event = null;
- switch(messageSort) {
- case ASYNCH_SIGNAL_LITERAL:
- case CREATE_MESSAGE_LITERAL:
- case DELETE_MESSAGE_LITERAL:
- //event = doCreateSendSignalEvent(eventContainer, (Signal)signature);
- break;
- case ASYNCH_CALL_LITERAL:
- case SYNCH_CALL_LITERAL:
- case REPLY_LITERAL:
- //event = doCreateSendOperationEvent(eventContainer, (Operation)signature);
- break;
- default:
- break;
-
- }
- return event;
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/HighlightUtil.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/HighlightUtil.java
deleted file mode 100644
index ccde9d88e8e..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/HighlightUtil.java
+++ /dev/null
@@ -1,272 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eclipse.draw2d.Border;
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.Polyline;
-import org.eclipse.draw2d.RectangleFigure;
-import org.eclipse.draw2d.Shape;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.requests.CreateRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.AbstractExecutionSpecificationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CommentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ConstraintEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.swt.graphics.Color;
-
-
-public class HighlightUtil {
-
- private static class FigureState {
-
- private Color bgColor;
-
- private Color fgColor;
-
- private int lineWidth;
-
- public FigureState(Color bgColor, Color fgColor, int lineWidth) {
- this.bgColor = bgColor;
- this.fgColor = fgColor;
- this.lineWidth = lineWidth;
- }
- }
-
- public static final Color COVER_COLOR = ColorConstants.cyan;
-
- public static final Color TARGET_COLOR = ColorConstants.cyan;
-
- public static final Color SOURCE_COLOR = ColorConstants.cyan;
-
- static Map<LifelineEditPart, Rectangle> lifelines;
-
- static List<LifelineEditPart> highlightLifelines = new ArrayList<LifelineEditPart>();
-
- static Map<EditPart, FigureState> feedbackStates = new HashMap<EditPart, HighlightUtil.FigureState>();
-
- public static Map<LifelineEditPart, Rectangle> collectAllLifelines(EditPart part) {
- Map<LifelineEditPart, Rectangle> lifelines = new HashMap<LifelineEditPart, Rectangle>();
- Set<Entry<Object, EditPart>> allEditPartEntries = part.getViewer().getEditPartRegistry().entrySet();
- for(Entry<Object, EditPart> epEntry : allEditPartEntries) {
- EditPart ep = epEntry.getValue();
- if(!(ep instanceof LifelineEditPart))
- continue;
-
- LifelineEditPart lp = (LifelineEditPart)ep;
- IFigure figure = lp.getFigure();
- Rectangle childBounds = figure.getBounds().getCopy();
- figure.translateToAbsolute(childBounds);
- Rectangle centralLineBounds = new Rectangle(childBounds.x() + childBounds.width() / 2, childBounds.y(), 1, childBounds.height());
-
- lifelines.put(lp, centralLineBounds);
- }
- return lifelines;
- }
-
- public static void eraseSizeOnDropFeedback(Request request, EditPart host) {
- for(LifelineEditPart lp : highlightLifelines) {
- FigureState s = feedbackStates.get(lp);
- if(s == null)
- continue;
-
- RectangleFigure rect = lp.getPrimaryShape().getFigureLifelineNameContainerFigure();
- rect.setBackgroundColor(s.bgColor);
- rect.setFill(true);
- }
-
- lifelines = null;
- highlightLifelines = new ArrayList<LifelineEditPart>();
- }
-
- public static void showSizeOnDropFeedback(CreateRequest request, EditPart host, IFigure feedback, Rectangle bounds) {
- if(lifelines == null) {
- lifelines = collectAllLifelines(host);
- highlightLifelines = new ArrayList<LifelineEditPart>();
- }
-
- List<LifelineEditPart> addLifelines = new ArrayList<LifelineEditPart>();
- List<LifelineEditPart> removeLifelines = new ArrayList<LifelineEditPart>();
-
- Iterator<Entry<LifelineEditPart, Rectangle>> it = lifelines.entrySet().iterator();
- while(it.hasNext()) {
- Entry<LifelineEditPart, Rectangle> en = it.next();
-
- if(bounds.intersects(en.getValue())) {
- if(!highlightLifelines.contains(en.getKey()))
- addLifelines.add(en.getKey());
- } else {
- if(highlightLifelines.contains(en.getKey()))
- removeLifelines.add(en.getKey());
- }
- }
-
- highlightLifelines.removeAll(removeLifelines);
- highlightLifelines.addAll(addLifelines);
-
- // highlight lifeline inside
- for(LifelineEditPart lp : addLifelines) {
- RectangleFigure rect = lp.getPrimaryShape().getFigureLifelineNameContainerFigure();
- feedbackStates.put(lp, new FigureState(rect.getBackgroundColor(), rect.getForegroundColor(), rect.getLineWidth()));
- rect.setBackgroundColor(COVER_COLOR);
- rect.setFill(true);
- }
-
- // restore lifeline outside
- for(LifelineEditPart lp : removeLifelines) {
- FigureState s = feedbackStates.get(lp);
- if(s == null)
- continue;
-
- RectangleFigure rect = lp.getPrimaryShape().getFigureLifelineNameContainerFigure();
- rect.setBackgroundColor(s.bgColor);
- rect.setFill(true);
- }
- }
-
- private Map<Object, FigureState> figureState = new HashMap<Object, FigureState>();
-
- /**
- * Maybe this value can be managed by preferences.
- */
- private Color getHighlightBackground() {
- return null;
- }
-
- /**
- * Maybe this value can be managed by preferences.
- */
- private int getHighlightBorderWidth() {
- return 2;
- }
-
- private List<IFigure> getHighlightFigures(EditPart host) {
- List<IFigure> figures = new ArrayList<IFigure>();
- if(host instanceof LifelineEditPart) {
- LifelineEditPart part = (LifelineEditPart)host;
- figures.add(part.getPrimaryShape().getFigureLifelineNameContainerFigure());
- figures.add(part.getPrimaryShape().getFigureLifelineDotLineFigure());
- } else if(host instanceof AbstractExecutionSpecificationEditPart) {
- figures.add(((AbstractExecutionSpecificationEditPart)host).getPrimaryShape());
- } else if(host instanceof CombinedFragmentEditPart) {
- figures.add(((CombinedFragmentEditPart)host).getPrimaryShape());
- } else if(host instanceof InteractionOperandEditPart) {
- InteractionOperandEditPart op = (InteractionOperandEditPart)host;
- CombinedFragmentEditPart cep = (CombinedFragmentEditPart)op.getParent().getParent();
- figures.add(cep.getPrimaryShape());
- } else if(host instanceof CommentEditPart) {
- figures.add(((CommentEditPart)host).getPrimaryShape());
- } else if(host instanceof ConstraintEditPart) {
- figures.add(((ConstraintEditPart)host).getPrimaryShape());
- } else if(host instanceof IPapyrusEditPart) {
- figures.add(((IPapyrusEditPart)host).getPrimaryShape());
- }
- return figures;
- }
-
- /**
- * Maybe this value can be managed by preferences.
- */
- private Color getHighlightForeground() {
- return null;
- }
-
- public void highlight(EditPart host) {
- List<IFigure> highlightFigures = getHighlightFigures(host);
- if(highlightFigures.isEmpty()) {
- return;
- }
-
- Color background = getHighlightBackground();
- Color foreground = getHighlightForeground();
- int lineWidth = getHighlightBorderWidth();
- for(IFigure figure : highlightFigures) {
- saveIfNotExist(figure, figure);
- updateFigure(figure, background, foreground, lineWidth);
- }
- }
-
- protected void saveIfNotExist(Object host, IFigure fig) {
- if(!figureState.containsKey(host)) {
- int lineWidth = 1;
- Border border = fig.getBorder();
- if(border instanceof LineBorder) {
- lineWidth = ((LineBorder)border).getWidth();
- } else if(fig instanceof Shape) {
- lineWidth = ((Shape)fig).getLineWidth();
- }
- figureState.put(host, new FigureState(fig.getBackgroundColor(), fig.getForegroundColor(), lineWidth));
- }
- }
-
- public void unhighlight() {
- if(figureState == null || figureState.isEmpty()) {
- return;
- }
- Set<Entry<Object, FigureState>> entrySet = figureState.entrySet();
- for(Entry<Object, FigureState> entry : entrySet) {
- Object key = entry.getKey();
- FigureState value = entry.getValue();
- if(key instanceof IFigure) {
- IFigure fig = (IFigure)key;
- updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
- } else if(key instanceof EditPart) {
- List<IFigure> figures = getHighlightFigures((EditPart)key);
- for(IFigure fig : figures) {
- updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
- }
- }
- }
- figureState.clear();
- }
-
- public void unhighlight(EditPart host) {
- List<IFigure> highlightFigures = getHighlightFigures(host);
- if(highlightFigures.isEmpty()) {
- return;
- }
- for(IFigure figure : highlightFigures) {
- FigureState s = figureState.remove(figure);
- if(s == null) {
- continue;
- }
- updateFigure(figure, s.bgColor, s.fgColor, s.lineWidth);
- }
- }
-
- private void updateFigure(IFigure fig, Color bgColor, Color fgColor, int lineWidth) {
- if(fig == null) {
- return;
- }
- if(lineWidth > 0) {
- Border border = fig.getBorder();
- if(border != null && border instanceof LineBorder) {
- ((LineBorder)border).setWidth(lineWidth);
- } else if(fig instanceof Shape) {
- ((Shape)fig).setLineWidth(lineWidth);
- } else if(fig instanceof Polyline) {
- ((Polyline)fig).setLineWidth(lineWidth);
- }
- }
- if(bgColor != null) {
- fig.setBackgroundColor(bgColor);
- }
- if(fgColor != null) {
- fig.setForegroundColor(fgColor);
- }
- fig.repaint();
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionOperatorKindCompatibleMapping.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionOperatorKindCompatibleMapping.java
deleted file mode 100644
index 859b6776e16..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionOperatorKindCompatibleMapping.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.uml2.uml.InteractionOperatorKind;
-
-public class InteractionOperatorKindCompatibleMapping {
- /**
- * Set the true if the kind of InteractionOperator supports multi operand
- */
- private static final Map<InteractionOperatorKind, Boolean> map = new HashMap<InteractionOperatorKind, Boolean>();
-
- static {
- map.put(InteractionOperatorKind.SEQ_LITERAL, true);
- map.put(InteractionOperatorKind.ALT_LITERAL, true);
- map.put(InteractionOperatorKind.OPT_LITERAL, false);
- map.put(InteractionOperatorKind.BREAK_LITERAL, false);
- map.put(InteractionOperatorKind.PAR_LITERAL, true);
- map.put(InteractionOperatorKind.STRICT_LITERAL, true);
- map.put(InteractionOperatorKind.LOOP_LITERAL, false);
- map.put(InteractionOperatorKind.CRITICAL_LITERAL, true);
- map.put(InteractionOperatorKind.NEG_LITERAL, false);
- map.put(InteractionOperatorKind.ASSERT_LITERAL, true);
- map.put(InteractionOperatorKind.IGNORE_LITERAL, true);
- map.put(InteractionOperatorKind.CONSIDER_LITERAL, true);
- }
-
- /**
- * Check if the InteractionOperator supports multi operand
- *
- * @param kind
- * @return
- */
- public static boolean supportMultiOperand(InteractionOperatorKind kind) {
- Boolean multiOperandSupport = map.get(kind);
- return multiOperandSupport == null ? false : multiOperandSupport;
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionUseUtil.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionUseUtil.java
deleted file mode 100644
index 44278c7d059..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/InteractionUseUtil.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.sasheditor.contentprovider.IPageManager;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.uml2.uml.Interaction;
-
-
-public class InteractionUseUtil {
-
- public static Diagram findDiagram(View view, Interaction refInteraction) {
- Diagram diagram = view.getDiagram();
- EList<EObject> list = diagram.eResource().getContents();
- for(EObject o : list) {
- if(o instanceof Diagram) {
- Diagram ref = (Diagram)o;
- if(refInteraction.equals(ref.getElement())) {
- return ref;
- }
- }
- }
-
- return null;
- }
-
- public static void openDiagram(Diagram diag) {
- IPageManager pageMngr;
- try {
- pageMngr = ServiceUtilsForEObject.getInstance().getIPageManager(diag);
- } catch (Exception e) {
- return;
- }
- if(pageMngr != null) {
- if(pageMngr.allPages().contains(diag)) {
- /**
- * Close the diagram if it was already open
- */
- if(pageMngr.isOpen(diag)) {
- pageMngr.selectPage(diag);
- } else {
- pageMngr.openPage(diag);
- }
- }
- }
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java
deleted file mode 100644
index 98a310bc186..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineCoveredByUpdater.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Soyatec - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.RemoveCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionFragmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * This class updates the property CoveredBy of Lifeline when a Lifeline gets created, moved/resize and also the resize of moving of each CombinedFragment
- *
- * @author yyang
- *
- */
-public class LifelineCoveredByUpdater {
- protected GraphicalEditPart context;
- protected Map<LifelineEditPart, Rectangle> lifelines = new HashMap<LifelineEditPart, Rectangle>();
- protected HashMap<InteractionFragmentEditPart, Rectangle> interactionFragments = new HashMap<InteractionFragmentEditPart, Rectangle>();
-
- protected List<InteractionFragment> coveredByLifelinesToAdd = new ArrayList<InteractionFragment>();
- protected List<InteractionFragment> coveredByLifelinesToRemove = new ArrayList<InteractionFragment>();
-
- protected TransactionalEditingDomain editingDomain;
-
- public LifelineCoveredByUpdater() {
- }
-
- protected void init() {
- editingDomain = this.context.getEditingDomain();
- GraphicalEditPart parent = context;
- while (true) {
- EditPart editPart = parent.getParent();
- if (editPart instanceof GraphicalEditPart) {
- parent = (GraphicalEditPart) editPart;
- } else {
- break;
- }
- }
- childrenCollect(parent);
- }
-
- private void childrenCollect(GraphicalEditPart editPart) {
- if (editPart instanceof LifelineEditPart) {
- IFigure figure = editPart.getFigure();
- Rectangle childBounds = figure.getBounds().getCopy();
- figure.translateToAbsolute(childBounds);
- Rectangle centralLineBounds = new Rectangle(
- childBounds.x() + childBounds.width() / 2,
- childBounds.y(), 1, childBounds.height());
-
- lifelines.put((LifelineEditPart)editPart, centralLineBounds);
- }
- if (editPart instanceof InteractionFragmentEditPart) {
- IFigure figure = editPart.getFigure();
- Rectangle childBounds = figure.getBounds().getCopy();
- figure.translateToAbsolute(childBounds);
- interactionFragments.put((InteractionFragmentEditPart)editPart, childBounds);
- }
- for (Object child : editPart.getChildren()) {
- if (child instanceof GraphicalEditPart) {
- childrenCollect((GraphicalEditPart)child);
- }
- }
- }
-
- public void update(GraphicalEditPart context) {
- this.context = context;
- this.init();
-
- for (Map.Entry<LifelineEditPart, Rectangle> entry : lifelines.entrySet()) {
- LifelineEditPart editPart = entry.getKey();
- Rectangle childBounds = entry.getValue();
- updateLifeline(editPart, childBounds);
- }
- }
-
- public void updateLifeline(LifelineEditPart lifelineEditpart, Rectangle rect) {
- Lifeline lifeline = (Lifeline) lifelineEditpart.resolveSemanticElement();
- EList<InteractionFragment> coveredByLifelines = lifeline
- .getCoveredBys();
-
- coveredByLifelinesToAdd.clear();
- coveredByLifelinesToRemove.clear();
-
- for (Map.Entry<InteractionFragmentEditPart, Rectangle> entry : interactionFragments.entrySet()) {
- InteractionFragmentEditPart editPart = entry.getKey();
- Rectangle childBounds = entry.getValue();
- InteractionFragment interactionFragment = (InteractionFragment) editPart
- .resolveSemanticElement();
- if (rect.intersects(childBounds)) {
- if (!coveredByLifelines.contains(interactionFragment)) {
- coveredByLifelinesToAdd.add(interactionFragment);
- }
- } else if (coveredByLifelines.contains(interactionFragment)) {
- coveredByLifelinesToRemove.add(interactionFragment);
- }
- }
-
- if (!coveredByLifelinesToAdd.isEmpty()) {
- CommandHelper.executeCommandWithoutHistory(editingDomain,
- AddCommand.create(editingDomain, lifeline,
- UMLPackage.eINSTANCE.getLifeline_CoveredBy(),
- coveredByLifelinesToAdd), true);
- }
- if (!coveredByLifelinesToRemove.isEmpty()) {
- CommandHelper.executeCommandWithoutHistory(editingDomain,
- RemoveCommand.create(editingDomain, lifeline,
- UMLPackage.eINSTANCE.getLifeline_CoveredBy(),
- coveredByLifelinesToRemove), true);
- }
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java
deleted file mode 100644
index f2910a79850..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineLabelHelper.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.IMaskManagedLabelEditPolicy;
-import org.eclipse.papyrus.uml.diagram.common.helper.StereotypedElementLabelHelper;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineNameEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.preferences.LifelinePreferencePage;
-import org.eclipse.uml2.uml.ConnectableElement;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Type;
-
-
-public class LifelineLabelHelper extends StereotypedElementLabelHelper {
-
- /**
- * singelton instance
- */
- private static LifelineLabelHelper labelHelper;
-
- /**
- * Returns the singleton instance of this class
- *
- * @return the singleton instance.
- */
- public static LifelineLabelHelper getInstance() {
- if(labelHelper == null) {
- labelHelper = new LifelineLabelHelper();
- }
- return labelHelper;
- }
-
- /** Map for masks */
- protected final Map<Integer, String> masks = new HashMap<Integer, String>(7);
-
- /**
- * Creates a new Operation label helper.
- */
- protected LifelineLabelHelper() {
- // initialize the map
- masks.put(LifelinePreferencePage.SHOW_REPRESENT_NAME, "Show represent name");
- masks.put(LifelinePreferencePage.SHOW_REPRESENT_TYPE, "Show represent type");
- masks.put(LifelinePreferencePage.SHOW_UNDEFINED_TYPE, "Always show undefined type");
- masks.put(LifelinePreferencePage.SHOW_LIFELINE_NAME, "Always show lifeline name");
- }
-
-
- /**
- * Returns the mask name given the value of the mask
- *
- * @return the mask name or <code>null</code> if no masks has been found
- */
- public String getMaskLabel(int value) {
- return masks.get(value);
- }
-
- /**
- * Returns the collection of mask names
- *
- * @return the collection of mask names
- */
- public Collection<String> getMaskLabels() {
- return masks.values();
- }
-
- /**
- * Returns the map of masks used to display
- *
- * @return the map of masks used to display
- */
- public Map<Integer, String> getMasks() {
- return masks;
- }
-
- /**
- * Returns the collection of mask values
- *
- * @return the collection of mask values
- */
- public Set<Integer> getMaskValues() {
- return masks.keySet();
- }
-
- /**
- * {@inheritDoc}
- */
- public Lifeline getUMLElement(GraphicalEditPart editPart) {
- return (Lifeline)((View)editPart.getModel()).getElement();
- }
-
- protected String elementLabel(GraphicalEditPart editPart) {
- if(editPart instanceof LifelineNameEditPart)
- editPart = (GraphicalEditPart)editPart.getParent();
- int displayValue = LifelinePreferencePage.DEFAULT_LABEL_DISPLAY;
-
- IMaskManagedLabelEditPolicy policy = (IMaskManagedLabelEditPolicy)editPart.getEditPolicy(IMaskManagedLabelEditPolicy.MASK_MANAGED_LABEL_EDIT_POLICY);
- if(policy != null) {
- displayValue = policy.getCurrentDisplayValue();
- }
- return getCustomLabel(getUMLElement(editPart), displayValue);
- }
-
- private static final String UNAMED = "<Unnamed>";
- private static final String UNDEFINED = "<Undefined>";
-
- //https://bugs.eclipse.org/bugs/show_bug.cgi?id=383722
- private String getCustomLabel(Lifeline lifeline, int displayValue) {
- StringBuilder sb = new StringBuilder();
- appendName(lifeline, displayValue, sb);
- boolean displayType = isCheck(displayValue , LifelinePreferencePage.SHOW_REPRESENT_TYPE );
- if( lifeline.getRepresents() == null || isCheck(displayValue , LifelinePreferencePage.SHOW_LIFELINE_NAME ) ){
- displayType = false;
- }
- if(displayType){
- // handle represent type label
- appendType(lifeline, displayValue, sb);
- }
- return sb.toString();
- }
-
-
- protected void appendName(Lifeline lifeline, int displayValue, StringBuilder sb) {
- ConnectableElement element = lifeline.getRepresents();
- String lifelineName = lifeline.getName();
- if( element == null || isCheck(displayValue , LifelinePreferencePage.SHOW_LIFELINE_NAME ) ){
- appendString(sb, lifelineName, UNAMED);
- return;
- }else{
- // represents is not null
- if(isCheck(displayValue , LifelinePreferencePage.SHOW_REPRESENT_NAME )){
- appendString(sb, element.getName(), UNAMED);
- }
- // if neither <1> or <2> are checked, show lifeline name (or <unnamed> when the lifeline has no name)
- else if(!isCheck(displayValue , LifelinePreferencePage.SHOW_REPRESENT_TYPE ))
- appendString(sb, lifelineName, UNAMED);
- }
- }
-
- protected void appendType(Lifeline lifeline, int displayValue, StringBuilder sb) {
- ConnectableElement element = lifeline.getRepresents();
- if(element == null)
- return;
-
- Type type = element.getType();
- if(isCheck(displayValue , LifelinePreferencePage.SHOW_REPRESENT_TYPE )){
- if(type == null ){
- if(isCheck(displayValue , LifelinePreferencePage.SHOW_UNDEFINED_TYPE ))
- sb.append(":").append(UNDEFINED);
- }else{
- appendString(sb.append(":") , type.getName(), UNAMED);
- }
- }
- }
-
- private static boolean isCheck(int value, int mask){
- return (value & mask) != 0;
- }
-
- private void appendString(StringBuilder sb, String str, String defaultValue) {
- if(str != null)
- sb.append(str);
- else
- sb.append(defaultValue);
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineMessageCreateHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineMessageCreateHelper.java
deleted file mode 100644
index e28f20055ff..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineMessageCreateHelper.java
+++ /dev/null
@@ -1,263 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Soyatec - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.DropRequest;
-import org.eclipse.gef.requests.GroupRequest;
-import org.eclipse.gef.requests.ReconnectRequest;
-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.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ComponentEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Shape;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.runtime.notation.impl.ShapeImpl;
-import org.eclipse.papyrus.uml.diagram.common.draw2d.anchors.LifelineAnchor;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message4EditPart;
-
-public class LifelineMessageCreateHelper {
-
- public static class ComponentEditPolicyEx extends ComponentEditPolicy {
-
- @Override
- protected Command createDeleteViewCommand(GroupRequest deleteRequest) {
- Command command = super.createDeleteViewCommand(deleteRequest);
- if(command != null && getHost() instanceof LifelineEditPart)
- command = restoreLifelineOnDelete(command, (LifelineEditPart)getHost());
- return command;
- }
- }
-
- public static ConnectionAnchor getCreateMessageAnchor(LifelineEditPart part, Request request, Point location) {
- IFigure fig = part.getPrimaryShape().getFigureLifelineNameContainerFigure();
- fig.translateToRelative(location);
- if(fig.containsPoint(location)) {// move to header
- return new LifelineAnchor(part.getPrimaryShape().getFigureLifelineNameContainerFigure());
- }
- // move to dash line
- return getTargetConnectionAnchor(part, request);
- }
-
- static ConnectionAnchor getTargetConnectionAnchor(LifelineEditPart part, Request request) {
- if (request instanceof ReconnectRequest) {
- if (((DropRequest) request).getLocation() == null) {
- return part.getNodeFigure().getTargetConnectionAnchorAt(null);
- }
- Point pt = ((DropRequest) request).getLocation().getCopy();
- return part.getNodeFigure().getTargetConnectionAnchorAt(pt);
- }
- else if (request instanceof DropRequest){
- return part.getNodeFigure().getTargetConnectionAnchorAt(
- ((DropRequest) request).getLocation());
- }
- return part.getNodeFigure().getTargetConnectionAnchorAt(null);
- }
-
- //when a create message is deleted, move its target lifelines up
- public static Command restoreLifelineOnMessageDelete(Command commands, EditPart editPart){
- if(editPart instanceof Message4EditPart) {
- Message4EditPart part = (Message4EditPart)editPart;
- if(part.getTarget() instanceof LifelineEditPart && LifelineMessageCreateHelper.getIncomingMessageCreate(part.getTarget()).size() == 1){
- LifelineEditPart target = (LifelineEditPart)part.getTarget();
- if(target.getModel() instanceof Shape){
- Shape view = (ShapeImpl) target.getModel();
- if(view.getLayoutConstraint() instanceof Bounds){
- Bounds bounds = (Bounds) view.getLayoutConstraint();
- ICommand boundsCommand = new SetBoundsCommand(
- target.getEditingDomain(),
- DiagramUIMessages.SetLocationCommand_Label_Resize,
- new EObjectAdapter(view), new Point(bounds.getX(),SequenceUtil.LIFELINE_VERTICAL_OFFSET));
- commands = commands.chain(new ICommandProxy(boundsCommand));
- int dy = SequenceUtil.LIFELINE_VERTICAL_OFFSET - bounds.getY();
- commands = moveCascadeLifeline(target, commands, dy);
- }
- }
- }
- }
- return commands;
- }
-
- // when a lifleine is deleted, move its created lifelines up
- public static Command restoreLifelineOnDelete(Command command, LifelineEditPart part) {
- List list = part.getSourceConnections();
- if(list != null && list.size() > 0) {
- for(Object l : list)
- if(l instanceof Message4EditPart) {
- EditPart target = ((Message4EditPart)l).getTarget();
- if(target instanceof LifelineEditPart && getIncomingMessageCreate(target).size() == 1) {
- LifelineEditPart lp = (LifelineEditPart)target;
- Rectangle bounds = lp.getPrimaryShape().getBounds();
- Point location = new Point(bounds.x, SequenceUtil.LIFELINE_VERTICAL_OFFSET);
- int dy = location.y - bounds.y;
- ICommand boundsCommand = new SetBoundsCommand(lp.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(lp.getNotationView()), location);
- command = command.chain(new ICommandProxy(boundsCommand));
- command = moveCascadeLifeline(lp, command, dy);
- }
- }
- }
- return command;
- }
-
- public static boolean hasMessageCreate(GraphicalEditPart sourceEditPart, EditPart targetEditPart) {
- List list = sourceEditPart.getSourceConnections();
- for(Object o : list)
- if(o instanceof Message4EditPart && targetEditPart.equals(((Message4EditPart)o).getTarget())){
- return true;
- }
- return false;
- }
-
- public static boolean hasIncomingMessageCreate(EditPart target) {
- return getIncomingMessageCreate(target).size() > 0;
- }
-
- public static List getIncomingMessageCreate(EditPart target) {
- List create = new ArrayList();
- if(target instanceof LifelineEditPart) {
- List list = ((LifelineEditPart)target).getTargetConnections();
- if(list != null && list.size() > 0) {
- for(Object l : list)
- if(l instanceof Message4EditPart) {
- create.add(l);
- }
- }
- }
- return create;
- }
-
- public static boolean canReconnectMessageCreate(ReconnectRequest request){
- Message4EditPart connPart = (Message4EditPart)request.getConnectionEditPart();
- if(request.isMovingStartAnchor()){ // reconnect source
- if( hasMessageCreate( (GraphicalEditPart)request.getTarget(), (GraphicalEditPart)connPart.getTarget()))
- return false;
- }else{ // reconnect target
- if( hasMessageCreate((GraphicalEditPart)connPart.getSource(), request.getTarget()))
- return false;
- }
- return true;
- }
-
- public static Command reconnectMessageCreateTarget(ReconnectRequest request, Command command) {
- LifelineEditPart oldTarget = (LifelineEditPart)request.getConnectionEditPart().getTarget();
- LifelineEditPart source = (LifelineEditPart)request.getConnectionEditPart().getSource();
- LifelineEditPart newTarget = (LifelineEditPart)request.getTarget();
- // move up the original connection target lifeline, it has only one create message, which will be removed
- if(getIncomingMessageCreate(oldTarget).size() == 1) {
- Rectangle bounds = oldTarget.getPrimaryShape().getBounds();
- Point location = new Point(bounds.x, SequenceUtil.LIFELINE_VERTICAL_OFFSET);
- int dy = location.y - bounds.y;
- ICommand boundsCommand = new SetBoundsCommand(oldTarget.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(oldTarget.getNotationView()), location);
- command = command.chain(new ICommandProxy(boundsCommand));
- command = moveCascadeLifeline(oldTarget, command, dy);
- }
-
- //move down the new connection target lifeline
- command = moveLifelineDown(command, newTarget, request.getLocation().getCopy());
- return command;
- }
-
- public static Command moveLifelineDown(Command command, LifelineEditPart part, Point sourcePointCopy) {
- IFigure fig = part.getFigure();
- Rectangle bounds = fig.getBounds().getCopy();
- fig.translateToAbsolute(bounds);
- int height = part.getPrimaryShape().getFigureLifelineNameContainerFigure().getBounds().height;
- Point location = new Point(bounds.x, Math.max(bounds.y, sourcePointCopy.y() - height / 2));
-
- View targetView = part.getNotationView();
- if(location.y != bounds.y) {
- int dy = location.y - bounds.y;
- fig.translateToRelative(location);
- fig.translateToParent(location);
-
- ICommand boundsCommand = new SetBoundsCommand(part.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(targetView), location);
- command = command.chain(new ICommandProxy(boundsCommand));
- command = moveCascadeLifeline(part, command, dy);
- }
-
- return command;
- }
-
- // move all lifelines which has incoming create link from part
- public static Command moveCascadeLifeline(LifelineEditPart part, Command command, int dy) {
- List list = part.getSourceConnections();
- if(list != null && list.size() > 0) {
- for(Object l : list)
- if(l instanceof Message4EditPart) {
- EditPart target = ((Message4EditPart)l).getTarget();
- if(target instanceof LifelineEditPart) {
- LifelineEditPart lp = (LifelineEditPart)target;
- Rectangle bounds = lp.getFigure().getBounds().getCopy();
- View targetView = lp.getNotationView();
- Point location = bounds.getLocation().getCopy().translate(0, dy);
- Command boundsCommand = new ICommandProxy(new SetBoundsCommand(part.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter(targetView), location));
- // Take care of the order of commands, to make sure target is always bellow the source.
- if(dy < 0){ // move up
- command = command == null? boundsCommand: command.chain(boundsCommand);
- command = moveCascadeLifeline(lp, command, dy);
- }else{ // move down
- command = moveCascadeLifeline(lp, command, dy);
- command = command == null? boundsCommand: command.chain(boundsCommand);
- }
- }
- }
- }
- return command;
- }
-
- public static boolean canMoveLifelineVertical(LifelineEditPart child, Rectangle newBounds) {
- int halfHeight = child.getPrimaryShape().getFigureLifelineNameContainerFigure().getBounds().height / 2;
- // check outgoing links
- List list = child.getSourceConnections();
- if(list != null && list.size() > 0) {
- for(Object l : list)
- if(l instanceof Message4EditPart && ((Message4EditPart)l).getTarget() instanceof LifelineEditPart) {
- LifelineEditPart lowPart = (LifelineEditPart)((Message4EditPart)l).getTarget();
- Rectangle outBounds = lowPart.getFigure().getBounds();
- if(outBounds.y - newBounds.y < halfHeight)
- return false;
- }
- }
- // check incoming links
- list = child.getTargetConnections();
- if(list != null && list.size() > 0) {
- for(Object l : list)
- if(l instanceof Message4EditPart && ((Message4EditPart)l).getSource() instanceof LifelineEditPart) {
- LifelineEditPart highPart = (LifelineEditPart)((Message4EditPart)l).getSource();
- Rectangle inBounds = highPart.getFigure().getBounds();
- if(newBounds.y - inBounds.y < halfHeight)
- return false;
-
- if(newBounds.y > inBounds.getBottom().y - halfHeight)
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineModelChildrenHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineModelChildrenHelper.java
deleted file mode 100644
index 6e4b1b9be65..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineModelChildrenHelper.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-
-
-public class LifelineModelChildrenHelper {
-
- /**
- * Try to fixed the bug about display ExecutionSpecifications(ES).
- *
- * At some times, the child ES would be displayed under the parent ES.
- *
- * Fixed to sort them with bounds in model before creating.
- */
- public static List<View> getModelChildren(View lifeline) {
- if(lifeline == null) {
- return Collections.emptyList();
- }
- @SuppressWarnings("unchecked")
- List<View> children = new ArrayList<View>(lifeline.getVisibleChildren());
- sortChildren(children);
- return children;
- }
-
- private static void sortChildren(List<View> children) {
- Collections.sort(children, new Comparator<Object>() {
-
- public int compare(Object o1, Object o2) {
- if(!(o1 instanceof View && o2 instanceof View)) {
- return 0;
- }
- View v1 = (View)o1;
- View v2 = (View)o2;
- EObject e1 = ViewUtil.resolveSemanticElement(v1);
- EObject e2 = ViewUtil.resolveSemanticElement(v2);
- if(!(e1 instanceof ExecutionSpecification && e2 instanceof ExecutionSpecification)) {
- return 0;
- }
- Rectangle r1 = getViewBounds(v1);
- Rectangle r2 = getViewBounds(v2);
- if(r1 == null || r2 == null) {
- return 0;
- }
- if(r1.width <= 0) {
- r1.width = 16;
- }
- if(r2.width <= 0) {
- r2.width = 16;
- }
-
- if((r1.x < r2.x) || r1.right() < r2.right()) {
- return -1;
- }
- return 1;
- }
- });
- }
-
- private static Rectangle getViewBounds(View view) {
- if(view == null) {
- return null;
- }
- Integer x = getFeatureValue(view, NotationPackage.eINSTANCE.getLocation_X());
- Integer y = getFeatureValue(view, NotationPackage.eINSTANCE.getLocation_Y());
- Integer width = getFeatureValue(view, NotationPackage.eINSTANCE.getSize_Width());
- Integer height = getFeatureValue(view, NotationPackage.eINSTANCE.getSize_Height());
- if(x == null && y == null && width == null && height == null) {
- return null;
- }
- return new Rectangle(x == null ? 0 : x.intValue(), y == null ? 0 : y.intValue(), width == null ? -1 : width.intValue(), height == null ? -1 : height.intValue());
- }
-
- private static Integer getFeatureValue(View view, EStructuralFeature feature) {
- if(view == null || feature == null) {
- return null;
- }
- return (Integer)ViewUtil.getPropertyValue(view, feature, feature.getEContainingClass());
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineResizeHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineResizeHelper.java
deleted file mode 100644
index a7728f520b2..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LifelineResizeHelper.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Soyatec - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.ecore.EModelElement;
-import org.eclipse.emf.ecore.EcoreFactory;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-
-
-public class LifelineResizeHelper {
-
- private static final String MANUAL_LABEL_SIZE = "manual.label.size";
- private static final String CUSTOM_EXTENSION_INFO = "CustomExtensionInfo";
-
- public static boolean isManualSize(LifelineEditPart lp){
- View view = lp.getNotationView();
- EAnnotation oldAnnotation = view.getEAnnotation(CUSTOM_EXTENSION_INFO);
- if(oldAnnotation != null) {
- String val = oldAnnotation.getDetails().get(MANUAL_LABEL_SIZE);
- return "true".equalsIgnoreCase(val);
- }
- return false;
- }
-
- public static ICommand createManualLabelSizeCommand(TransactionalEditingDomain domain, IAdaptable adapter){
- return new ManualLabelSizeCommand(domain, adapter, CUSTOM_EXTENSION_INFO);
- }
-
- public static ICommand createManualLabelSizeCommand(LifelineEditPart lifelineEP){
- return new ManualLabelSizeCommand(lifelineEP.getEditingDomain(), lifelineEP.getNotationView(), CUSTOM_EXTENSION_INFO);
- }
-
- public static class ManualLabelSizeCommand extends AbstractTransactionalCommand {
-
- public EModelElement getObject() {
- if(object != null)
- return object;
- if(adapter != null){
- return (View)adapter.getAdapter(View.class);
- }
- return null;
- }
-
- /** The object. */
- private EModelElement object;
-
- /** The e annotation name. */
- private String eAnnotationName;
-
- private IAdaptable adapter;
-
- public ManualLabelSizeCommand(TransactionalEditingDomain domain, EModelElement object, String eannotationName) {
- super(domain,"manual size", null);
- this.object = object;
- this.eAnnotationName = eannotationName;
- }
-
- public ManualLabelSizeCommand(TransactionalEditingDomain domain, IAdaptable adapter, String eannotationName) {
- super(domain,"manual size", null);
- this.adapter = adapter;
- this.eAnnotationName = eannotationName;
- }
-
- protected EAnnotation createEAnnotation() {
- EAnnotation eannotation = EcoreFactory.eINSTANCE.createEAnnotation();
- eannotation.setSource(eAnnotationName);
- return eannotation;
- }
-
- protected void attachEannotation(EAnnotation annotation, EModelElement object) {
- object.getEAnnotations().add(annotation);
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- EAnnotation oldAnnotation = getObject().getEAnnotation(eAnnotationName);
- if(oldAnnotation == null) {
- oldAnnotation = createEAnnotation();
- attachEannotation(oldAnnotation, getObject());
- }
- oldAnnotation.getDetails().put(MANUAL_LABEL_SIZE, "true");
- return CommandResult.newOKCommandResult();
- }
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LoopOperatorUtil.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LoopOperatorUtil.java
deleted file mode 100644
index f29e528dc37..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/LoopOperatorUtil.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.papyrus.uml.service.types.utils.InteractionConstraintUtil;
-import org.eclipse.uml2.uml.InteractionConstraint;
-
-/**
- * Loop operand could have iteration bounds which may include a lower and an upper number of iterations of the loop. Textual syntax of the loop is:
- * loop-operand ::= loop [ '(' min-int [ ',' max-int ] ')' ]
- * min-int ::= non-negative-integer
- * max-int ::= positive-integer | '*'
- *
- * 1. If loop has no bounds specified, it means potentially infinite loop with zero as lower bound and infinite upper bound..
- * 2. If only min-int is specified, it means that upper bound is equal to the lower bound, and loop will be executed exactly the specified
- * number of times.
- * 3. If max-int is specified, it should be greater than or equal to min-int. Loop will iterate minimum the min-int number of times and at
- * most the max-int number of times.
- *
- * @author Jin Liu (jin.liu@soyatec.com)
- */
-public class LoopOperatorUtil {
-
- public static String getLoopCondition(InteractionConstraint guard) {
- if(guard == null) {
- return null;
- }
- Integer minint = InteractionConstraintUtil.getMinintValue(guard);
- Integer maxint = InteractionConstraintUtil.getMaxintValue(guard);
-
- if(minint == null && maxint == null) {
- return "";
- }
- if(minint != null && maxint == null && minint.intValue() == 0) {
- maxint = Integer.MAX_VALUE;
- }
- if(minint == null) {
- minint = Integer.valueOf(0);
- }
- StringBuffer buf = new StringBuffer("(");
- buf.append(minint.intValue());
- if(maxint != null) {
- if(maxint.intValue() != minint.intValue()) {
- buf.append(", ");
- if(Integer.MAX_VALUE == maxint) {
- buf.append("*");
- } else {
- buf.append(maxint);
- }
- }
- }
- buf.append(")");
- return new String(buf);
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageStyleElementFactory.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageStyleElementFactory.java
deleted file mode 100644
index 80f89be9a51..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/MessageStyleElementFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.core.databinding.observable.IObservable;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.Style;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-import org.eclipse.papyrus.uml.tools.databinding.PapyrusObservableValue;
-import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
-import org.eclipse.papyrus.views.properties.modelelement.AbstractModelElement;
-import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
-import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory;
-
-
-public class MessageStyleElementFactory implements ModelElementFactory {
-
- public ModelElement createFromSource(Object sourceElement, DataContextElement context) {
- View view = NotationHelper.findView(sourceElement);
- if(view != null && view instanceof Edge) {
- return new MessageStyleModelElement((Edge)view, context);
- }
- return null;
- }
-
- static class MessageStyleModelElement extends AbstractModelElement {
-
- protected DataContextElement context;
-
- private Edge source;
-
- public MessageStyleModelElement(Edge source, DataContextElement context) {
- this.context = context;
- this.source = source;
- }
-
- @Override
- protected IObservable doGetObservable(String propertyPath) {
- EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(source);
- Style style = null;
- if(context.getName().equals("LineStyle")) {
- style = source.getStyle(NotationPackage.Literals.LINE_STYLE);
- } else if(context.getName().equals("FontStyle")) {
- style = source.getStyle(NotationPackage.Literals.FONT_STYLE);
- }
- if(style != null) {
- EStructuralFeature feature = style.eClass().getEStructuralFeature(propertyPath);
- return new PapyrusObservableValue(style, feature, domain);
- }
- return null;
- }
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/NotificationHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/NotificationHelper.java
deleted file mode 100644
index 116a4cdaf9a..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/NotificationHelper.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 Atos Origin.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.papyrus.uml.diagram.common.providers.UIAdapterImpl;
-
-public class NotificationHelper {
-
- private UIAdapterImpl modelListener;
-
- private List<Notifier> listeners = new ArrayList<Notifier>();
-
- public NotificationHelper(UIAdapterImpl modelListener) {
- this.modelListener = modelListener;
- }
-
- /**
- * Add listener on a element
- *
- * @param element
- * The object to listen
- */
- public void listenObject(Notifier element) {
- // Only listen the object if it isn't yet listened
- if(element != null && !element.eAdapters().contains(modelListener)) {
- element.eAdapters().add(modelListener);
- listeners.add(element);
- }
- }
-
- /**
- * Remove listener on a element
- *
- * @param element
- * The object to unlisten
- */
- public void unlistenObject(Notifier element) {
- // Only listen the object if it isn't yet listened
- if(element != null && element.eAdapters().contains(modelListener)) {
- element.eAdapters().remove(modelListener);
- }
- listeners.remove(element);
- }
-
- /**
- * Remove all listeners
- */
- public void unlistenAll() {
- if(listeners.size() > 0) {
- for(Notifier listener : listeners) {
- if(listener != null && listener.eAdapters().contains(modelListener)) {
- listener.eAdapters().remove(modelListener);
- }
- }
- listeners.clear();
- }
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationMoveHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationMoveHelper.java
deleted file mode 100644
index c08af5a6d40..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OccurrenceSpecificationMoveHelper.java
+++ /dev/null
@@ -1,1126 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.requests.ReconnectRequest;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-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.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.figures.BorderedNodeFigure;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.gmf.runtime.notation.impl.ConnectorImpl;
-import org.eclipse.papyrus.uml.diagram.common.helper.InteractionFragmentHelper;
-import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ObservationLinkEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.TimeObservationLabelEditPart;
-import org.eclipse.uml2.common.util.CacheAdapter;
-import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
-import org.eclipse.uml2.uml.DurationConstraint;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.GeneralOrdering;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.IntervalConstraint;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-import org.eclipse.uml2.uml.TimeConstraint;
-import org.eclipse.uml2.uml.TimeObservation;
-
-/**
- * This Helper must be used for performing move/reconnect operations which modify the location of an OccurrenceSpecification.
- *
- * @author vhemery
- */
-public class OccurrenceSpecificationMoveHelper {
-
- /**
- * Get the complete command to move or reconnect all edit parts attached to one or two occurrence specification(s).
- *
- * @param movedOccurrenceSpecification1
- * first moved occurrence specification
- * @param movedOccurrenceSpecification2
- * second moved occurrence specification (or null)
- * @param yLocation1
- * y location where first occurrence specification is moved
- * @param yLocation2
- * y location where second occurrence specification is moved (or -1)
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param notToMoveEditParts
- * list of edit parts which must not be moved in the created command
- * @return command to move all edit parts linked to the occurrence specifications or null
- */
- public static Command getMoveOccurrenceSpecificationsCommand(OccurrenceSpecification movedOccurrenceSpecification1, OccurrenceSpecification movedOccurrenceSpecification2, int yLocation1, int yLocation2, LifelineEditPart lifelinePart, List<EditPart> notToMoveEditParts) {
- // the global command which shall be completed and returned
- CompoundCommand globalCmd = new CompoundCommand();
- // move the corresponding execution specification if necessary
- Command command = getMoveExecutionSpecificationCommand(movedOccurrenceSpecification1, movedOccurrenceSpecification2, yLocation1, yLocation2, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- // reconnect the corresponding message(s) if necessary
- if(movedOccurrenceSpecification1 instanceof MessageOccurrenceSpecification) {
- command = getReconnectMessageCommand(movedOccurrenceSpecification1, yLocation1, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- }
- if(movedOccurrenceSpecification2 instanceof MessageOccurrenceSpecification) {
- command = getReconnectMessageCommand(movedOccurrenceSpecification2, yLocation2, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- }
- // move the corresponding time/duration constraints/observations if necessary
- command = getMoveTimeElementsCommand(movedOccurrenceSpecification1, movedOccurrenceSpecification2, yLocation1, yLocation2, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- // reconnect the corresponding general ordering(s) if necessary
- command = getReconnectGeneralOrderingCommand(movedOccurrenceSpecification1, yLocation1, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- if(movedOccurrenceSpecification2 != null) {
- command = getReconnectGeneralOrderingCommand(movedOccurrenceSpecification2, yLocation2, lifelinePart, notToMoveEditParts);
- if(command != null) {
- globalCmd.add(command);
- }
- }
- // return null rather than an empty non executable command
- if(globalCmd.isEmpty()) {
- return null;
- }
- return globalCmd;
- }
-
- /**
- * Get the command to reconnect general ordering attached to a moved occurrence specification
- *
- * @param movedOccurrenceSpecification
- * moving occurrence specification
- * @param yLocation
- * y location where occurrence specification is moved
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param notToMoveEditParts
- * list of edit parts which must not be moved in the created command
- * @return command to reconnect general ordering edit parts linked to the occurrence specification or null
- */
- private static Command getReconnectGeneralOrderingCommand(OccurrenceSpecification movedOccurrenceSpecification, int yLocation, LifelineEditPart lifelinePart, List<EditPart> notToMoveEditParts) {
- // the global command which shall be completed and returned
- CompoundCommand command = new CompoundCommand();
- Point referencePoint = getReferencePoint(lifelinePart, movedOccurrenceSpecification, yLocation);
- EditPart childToReconnectTo = SequenceUtil.findPartToReconnectTo(lifelinePart, referencePoint);
- // if referencePoint is on a moved part, it must be translated with the location delta of this part
- if(!notToMoveEditParts.isEmpty() && childToReconnectTo != lifelinePart) {
- Point oldLoc = SequenceUtil.findLocationOfEvent(lifelinePart, movedOccurrenceSpecification);
- referencePoint.y = oldLoc.y;
- }
- // reconnect general ordering from the event
- for(GeneralOrdering go : movedOccurrenceSpecification.getToAfters()) {
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(go);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the general ordering part must start or finish on the lifeline (with the event)
- if(part instanceof ConnectionEditPart && !notToMoveEditParts.contains(part)) {
- Request reconnectRequest = makeReconnectRequest((ConnectionEditPart)part, true, referencePoint, childToReconnectTo);
- Command reconnect = childToReconnectTo.getCommand(reconnectRequest);
- if(reconnect.canExecute()) {
- command.add(reconnect);
- }
- }
- }
- }
- }
- // reconnect general ordering to the event
- for(GeneralOrdering go : movedOccurrenceSpecification.getToBefores()) {
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(go);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the general ordering part must start or finish on the lifeline (with the event)
- if(part instanceof ConnectionEditPart && !notToMoveEditParts.contains(part)) {
- Request reconnectRequest = makeReconnectRequest((ConnectionEditPart)part, false, referencePoint, childToReconnectTo);
- Command reconnect = childToReconnectTo.getCommand(reconnectRequest);
- if(reconnect.canExecute()) {
- command.add(reconnect);
- }
- }
- }
- }
- }
- // return null rather than an empty non executable command
- if(command.isEmpty()) {
- return null;
- }
- return command;
- }
-
- /**
- * Get the command to reconnect message attached to a moved occurrence specification
- *
- * @param movedOccurrenceSpecification
- * moving occurrence specification
- * @param yLocation
- * y location where occurrence specification is moved
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param notToMoveEditParts
- * list of edit parts which must not be moved in the created command
- * @return command to reconnect message edit part linked to the occurrence specification or null
- */
- private static Command getReconnectMessageCommand(OccurrenceSpecification movedOccurrenceSpecification, int yLocation, LifelineEditPart lifelinePart, List<EditPart> notToMoveEditParts) {
- // the global command which shall be completed and returned
- CompoundCommand command = new CompoundCommand();
- if(movedOccurrenceSpecification instanceof MessageOccurrenceSpecification) {
- Point referencePoint = getReferencePoint(lifelinePart, movedOccurrenceSpecification, yLocation);
- EditPart childToReconnectTo = SequenceUtil.findPartToReconnectTo(lifelinePart, referencePoint);
- // reconnect message from the event
- Message message = ((MessageOccurrenceSpecification)movedOccurrenceSpecification).getMessage();
- if(message != null && movedOccurrenceSpecification.equals(message.getSendEvent())) {
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(message);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the message part must start or finish on the lifeline (with the event)
- if(part instanceof ConnectionEditPart && !notToMoveEditParts.contains(part)) {
- Request reconnectRequest = makeReconnectRequest((ConnectionEditPart)part, true, referencePoint, childToReconnectTo);
- Command reconnect = childToReconnectTo.getCommand(reconnectRequest);
- command.add(reconnect);
- // update enclosing interaction fragment
- Command updateIFrag = SequenceUtil.createUpdateEnclosingInteractionCommand((MessageOccurrenceSpecification)movedOccurrenceSpecification, referencePoint, lifelinePart);
- if(updateIFrag != null && updateIFrag.canExecute()) {
- command.add(updateIFrag);
- }
- }
- }
- }
- }
- // reconnect message to the event
- if(message != null && movedOccurrenceSpecification.equals(message.getReceiveEvent())) {
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(message);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the message part must start or finish on the lifeline (with the event)
- if(part instanceof ConnectionEditPart && !notToMoveEditParts.contains(part)) {
- Request reconnectRequest = makeReconnectRequest((ConnectionEditPart)part, false, referencePoint, childToReconnectTo);
- Command reconnect = childToReconnectTo.getCommand(reconnectRequest);
- command.add(reconnect);
- // update enclosing interaction fragment
- Command updateIFrag = SequenceUtil.createUpdateEnclosingInteractionCommand((MessageOccurrenceSpecification)movedOccurrenceSpecification, referencePoint, lifelinePart);
- if(updateIFrag != null && updateIFrag.canExecute()) {
- command.add(updateIFrag);
- }
- }
- }
- }
- }
- }
-
- // return null rather than an empty non executable command
- if(command.isEmpty()) {
- return null;
- }
- return command;
- }
-
- /**
- * Get the command to move time/duration observations/constraints attached to a moved occurrence specification
- *
- * @param movedOccurrenceSpecification1
- * first moved occurrence specification
- * @param movedOccurrenceSpecification2
- * second moved occurrence specification (or null)
- * @param yLocation1
- * y location where first occurrence specification is moved
- * @param yLocation2
- * y location where second occurrence specification is moved (or -1)
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param notToMoveEditParts
- * list of edit parts which must not be moved in the created command
- * @return command to move time edit parts linked to the occurrence specification or null
- */
- private static Command getMoveTimeElementsCommand(OccurrenceSpecification movedOccurrenceSpecification1, OccurrenceSpecification movedOccurrenceSpecification2, int yLocation1, int yLocation2, LifelineEditPart lifelinePart, List<EditPart> notToMoveEditParts) {
- // the global command which shall be completed and returned
- CompoundCommand globalCmd = new CompoundCommand();
- IFigure lifelineFigure = lifelinePart.getFigure();
- // relocate each linked time element contained within the lifeline part
- for(Object lifelineChild : lifelinePart.getChildren()) {
- if(lifelineChild instanceof IBorderItemEditPart && !notToMoveEditParts.contains(lifelineChild)) {
- final IBorderItemEditPart timePart = (IBorderItemEditPart)lifelineChild;
- Command cmd = getMoveSingleTimeRelatedElementCommand(timePart, movedOccurrenceSpecification1, movedOccurrenceSpecification2, yLocation1, yLocation2, lifelinePart);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- }
-
- // relocate each observation linked time element
- for(Object targetConnection : lifelinePart.getTargetConnections()){
- if(targetConnection instanceof ObservationLinkEditPart){
- Command cmd = getMoveSingleTimeRelatedElementCommand((ObservationLinkEditPart)targetConnection, movedOccurrenceSpecification1, movedOccurrenceSpecification2, yLocation1, yLocation2, lifelinePart);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- }
-
- // refresh layout commands :
- // one before the commands for the undo and one after for classic execution
- if(!globalCmd.isEmpty() && lifelineFigure instanceof BorderedNodeFigure) {
- Command relayout = getReLayoutCmd((BorderedNodeFigure)lifelineFigure, false);
- Command relayoutUndo = getReLayoutCmd((BorderedNodeFigure)lifelineFigure, true);
- if(relayout != null && relayoutUndo != null) {
- CompoundCommand commandWithRelayout = new CompoundCommand();
- commandWithRelayout.add(relayoutUndo);
- commandWithRelayout.add(globalCmd);
- commandWithRelayout.add(relayout);
- return commandWithRelayout;
- }
- }
- // return null rather than an empty non executable command
- if(globalCmd.isEmpty()) {
- return null;
- }
- return globalCmd;
- }
-
- private static Command getMoveSingleTimeRelatedElementCommand(
- final ObservationLinkEditPart targetConnection,
- final OccurrenceSpecification movedOccurrenceSpecification1,
- final OccurrenceSpecification movedOccurrenceSpecification2,
- final int yLocation1, final int yLocation2,final LifelineEditPart lifelinePart) {
-
- AbstractTransactionalCommand updateTargetAnchorCommand = new AbstractTransactionalCommand(((IGraphicalEditPart) targetConnection).getEditingDomain(),"update target anchor",null) {
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
- IAdaptable info) throws ExecutionException {
-
- // both bounds may have changed
- Point referencePoint1 = getReferencePoint(lifelinePart, movedOccurrenceSpecification1, yLocation1);
- Point referencePoint2 = getReferencePoint(lifelinePart, movedOccurrenceSpecification2, yLocation2);
-
- int position1 = PositionConstants.NONE;
- int position2 = PositionConstants.NONE;
- TimeObservationLabelEditPart tolEP = (TimeObservationLabelEditPart)targetConnection.getSource();
- if(tolEP == null){
- return CommandResult.newCancelledCommandResult();
- }
-
- if(movedOccurrenceSpecification1 != null) {
- position1 = SequenceUtil.positionWhereEventIsLinkedToPart(movedOccurrenceSpecification1, tolEP);
- }
- if(movedOccurrenceSpecification2 != null) {
- position2 = SequenceUtil.positionWhereEventIsLinkedToPart(movedOccurrenceSpecification2, tolEP);
- }
- ConnectionAnchor targetAnchor = null;
- if(position1 == PositionConstants.CENTER){
- targetAnchor = lifelinePart.getNodeFigure().getSourceConnectionAnchorAt(referencePoint1);
- }else if(position2 == PositionConstants.CENTER){
- targetAnchor = lifelinePart.getNodeFigure().getSourceConnectionAnchorAt(referencePoint2);
- }
-
- if(targetAnchor!= null){
- String newTargetTerminal = lifelinePart.mapConnectionAnchorToTerminal(targetAnchor);
- ConnectorImpl c = (ConnectorImpl)targetConnection.getModel();
- if (newTargetTerminal != null) {
- if (newTargetTerminal.length() == 0)
- c.setTargetAnchor(null);
- else {
- IdentityAnchor a = (IdentityAnchor) c.getTargetAnchor();
- if (a == null)
- a = NotationFactory.eINSTANCE.createIdentityAnchor();
- a.setId(newTargetTerminal);
- c.setTargetAnchor(a);
- }
- }
-
- }
-
- return CommandResult.newOKCommandResult();
- }
- };
-
-
- // return the resize command
- ICommandProxy resize = new ICommandProxy(updateTargetAnchorCommand);
- return resize;
- }
-
- /**
- * Get a command to move the time related element's edit part
- *
- * @param timePart
- * time related element's edit part to move
- * @param movedOccurrenceSpecification1
- * first moved occurrence specification
- * @param movedOccurrenceSpecification2
- * second moved occurrence specification (or null)
- * @param yLocation1
- * y location where first occurrence specification is moved
- * @param yLocation2
- * y location where second occurrence specification is moved (or -1)
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @return
- */
- private static Command getMoveSingleTimeRelatedElementCommand(IBorderItemEditPart timePart, OccurrenceSpecification movedOccurrenceSpecification1, OccurrenceSpecification movedOccurrenceSpecification2, int yLocation1, int yLocation2, LifelineEditPart lifelinePart) {
- IFigure lifelineFigure = lifelinePart.getFigure();
- // get positions where edit part is attached to events
- int position1 = PositionConstants.NONE;
- int position2 = PositionConstants.NONE;
- if(movedOccurrenceSpecification1 != null) {
- position1 = SequenceUtil.positionWhereEventIsLinkedToPart(movedOccurrenceSpecification1, timePart);
- }
- if(movedOccurrenceSpecification2 != null) {
- position2 = SequenceUtil.positionWhereEventIsLinkedToPart(movedOccurrenceSpecification2, timePart);
- }
- // move necessary bounds
- Rectangle newBounds = null;
- if(position1 != PositionConstants.NONE && position2 != PositionConstants.NONE) {
- // both bounds may have changed
- Point referencePoint1 = getReferencePoint(lifelinePart, movedOccurrenceSpecification1, yLocation1);
- Point referencePoint2 = getReferencePoint(lifelinePart, movedOccurrenceSpecification2, yLocation2);
- makeRelativeToLifeline(referencePoint1, lifelinePart, false);
- makeRelativeToLifeline(referencePoint2, lifelinePart, false);
- // Get old bounds information by consulting old figure
- int oldY = timePart.getFigure().getBounds().getLocation().y - lifelineFigure.getBounds().getLocation().y;
- int oldHeight = timePart.getFigure().getSize().height;
- // Compute new bounds of the time element
- if(position1 == PositionConstants.CENTER || position2 == PositionConstants.CENTER) {
- // should not happen, except if both events are merged at the same location
- newBounds = new Rectangle(referencePoint1.x, referencePoint1.y - oldHeight / 2, -1, oldHeight);
- } else {
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position1 == PositionConstants.TOP) {
- top = referencePoint1.y;
- } else if(position1 == PositionConstants.BOTTOM) {
- bottom = referencePoint1.y;
- }
- if(position2 == PositionConstants.TOP) {
- top = referencePoint2.y;
- } else if(position2 == PositionConstants.BOTTOM) {
- bottom = referencePoint2.y;
- }
- // top and bottom may have been inverted during the move.
- // restore x position, fix time duration always move to east
- int viewX = (Integer) ViewUtil.getPropertyValue((View) timePart.getModel(), NotationPackage.eINSTANCE
- .getLocation_X(), NotationPackage.eINSTANCE.getLocation_X().getEContainingClass());
-
- newBounds = new Rectangle(viewX, Math.min(top, bottom), -1, Math.abs(bottom - top));
-// newBounds = new Rectangle(referencePoint1.x, Math.min(top, bottom), -1, Math.abs(bottom - top));
- }
- } else if(position1 != PositionConstants.NONE) {
- Point referencePoint1 = getReferencePoint(lifelinePart, movedOccurrenceSpecification1, yLocation1);
- makeRelativeToLifeline(referencePoint1, lifelinePart, false);
- // Get old bounds information by consulting old figure
- int oldY = timePart.getFigure().getBounds().getLocation().y - lifelineFigure.getBounds().getLocation().y;
- int oldHeight = timePart.getFigure().getSize().height;
- // Compute new bounds of the time element
- if(position1 == PositionConstants.CENTER) {
- newBounds = new Rectangle(referencePoint1.x, referencePoint1.y - oldHeight / 2, -1, oldHeight);
- } else {
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position1 == PositionConstants.TOP) {
- top = referencePoint1.y;
- } else if(position1 == PositionConstants.BOTTOM) {
- bottom = referencePoint1.y;
- }
- // top and bottom may have been inverted during the move.
- newBounds = new Rectangle(referencePoint1.x, Math.min(top, bottom), -1, Math.abs(bottom - top));
- }
- } else if(position2 != PositionConstants.NONE) {
- Point referencePoint2 = getReferencePoint(lifelinePart, movedOccurrenceSpecification2, yLocation2);
- makeRelativeToLifeline(referencePoint2, lifelinePart, false);
- // Get old bounds information by consulting old figure
- int oldY = timePart.getFigure().getBounds().getLocation().y - lifelineFigure.getBounds().getLocation().y;
- int oldHeight = timePart.getFigure().getSize().height;
- // Compute new bounds of the time element
- if(position2 == PositionConstants.CENTER) {
- newBounds = new Rectangle(referencePoint2.x, referencePoint2.y - oldHeight / 2, -1, oldHeight);
- } else {
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position2 == PositionConstants.TOP) {
- top = referencePoint2.y;
- } else if(position2 == PositionConstants.BOTTOM) {
- bottom = referencePoint2.y;
- }
- // top and bottom may have been inverted during the move.
- newBounds = new Rectangle(referencePoint2.x, Math.min(top, bottom), -1, Math.abs(bottom - top));
- }
- }
- if(newBounds != null) {
- TransactionalEditingDomain editingDomain = timePart.getEditingDomain();
- // return the resize command
- ICommandProxy resize = new ICommandProxy(new SetBoundsCommand(editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter((View)timePart.getModel()), newBounds));
- return resize;
- }
- return null;
- }
-
- /**
- * Make an absolute point relative to a lifeline figure.
- *
- * @param absolutePoint
- * the absolute point to translate
- * @param lifelinePart
- * the containing lifeline edit part
- */
- private static void makeRelativeToLifeline(Point absolutePoint, LifelineEditPart lifelinePart, boolean relativeToContentPane) {
- IFigure figure;
- if(relativeToContentPane) {
- figure = lifelinePart.getContentPane();
- } else {
- figure = lifelinePart.getFigure();
- }
- figure.translateToRelative(absolutePoint);
- absolutePoint.translate(figure.getBounds().getLocation().getNegated());
- }
-
- /**
- * Get the command to move execution specification(s) attached to moved occurrence specification(s)
- *
- * @param movedOccurrenceSpecification1
- * first moved occurrence specification
- * @param movedOccurrenceSpecification2
- * second moved occurrence specification (or null)
- * @param yLocation1
- * y location where first occurrence specification is moved
- * @param yLocation2
- * y location where second occurrence specification is moved (or -1)
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param notToMoveEditParts
- * list of edit parts which must not be moved in the created command
- * @return command to move execution specification edit part linked to the occurrence specification or null
- */
- private static Command getMoveExecutionSpecificationCommand(OccurrenceSpecification movedOccurrenceSpecification1, OccurrenceSpecification movedOccurrenceSpecification2, int yLocation1, int yLocation2, LifelineEditPart lifelinePart, List<EditPart> notToMoveEditParts) {
- // the global command which shall be completed and returned
- CompoundCommand globalCmd = new CompoundCommand();
- // execution(s) linked to the event must be resized
- EditPart node1 = null;
- if(movedOccurrenceSpecification1 != null) {
- node1 = SequenceUtil.getLinkedEditPart(lifelinePart, movedOccurrenceSpecification1);
- }
- EditPart node2 = null;
- if(movedOccurrenceSpecification2 != null) {
- node2 = SequenceUtil.getLinkedEditPart(lifelinePart, movedOccurrenceSpecification2);
- }
- if(node1 instanceof GraphicalEditPart && !notToMoveEditParts.contains(node1)) {
- Command cmd = getMoveSingleExecutionSpecificationCommand((GraphicalEditPart)node1, movedOccurrenceSpecification1, movedOccurrenceSpecification2, yLocation1, yLocation2, lifelinePart);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- if(node2 != node1 && node2 instanceof GraphicalEditPart && !notToMoveEditParts.contains(node2)) {
- Command cmd = getMoveSingleExecutionSpecificationCommand((GraphicalEditPart)node2, movedOccurrenceSpecification2, null, yLocation2, -1, lifelinePart);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- // return null rather than an empty non executable command
- if(globalCmd.isEmpty()) {
- return null;
- }
- return globalCmd;
- }
-
- /**
- * Get the command to move an execution specification attached to moved occurrence specification(s)
- *
- * @param executionSpecificationPart
- * the execution specification edit part to move
- * @param movedOccurrenceSpecification1
- * first moved occurrence specification
- * @param movedOccurrenceSpecification2
- * second moved occurrence specification (or null)
- * @param yLocation1
- * y location where first occurrence specification is moved
- * @param yLocation2
- * y location where second occurrence specification is moved (or -1)
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @return command to move the execution specification edit part or null
- */
- private static Command getMoveSingleExecutionSpecificationCommand(GraphicalEditPart executionSpecificationPart, OccurrenceSpecification movedOccurrenceSpecification1, OccurrenceSpecification movedOccurrenceSpecification2, int yLocation1, int yLocation2, LifelineEditPart lifelinePart) {
- // execution linked to the event must be resized
- EObject execution = executionSpecificationPart.resolveSemanticElement();
- if(execution instanceof ExecutionSpecification) {
- // finish or start events of the execution have been moved
- // get positions where execution edit part is attached to events
- int position1 = PositionConstants.NONE;
- int position2 = PositionConstants.NONE;
- OccurrenceSpecification start = ((ExecutionSpecification)execution).getStart();
- OccurrenceSpecification finish = ((ExecutionSpecification)execution).getFinish();
- if(start != null && start.equals(movedOccurrenceSpecification1)) {
- position1 = PositionConstants.TOP;
- } else if(finish != null && finish.equals(movedOccurrenceSpecification1)) {
- position1 = PositionConstants.BOTTOM;
- }
- if(start != null && start.equals(movedOccurrenceSpecification2)) {
- position2 = PositionConstants.TOP;
- } else if(finish != null && finish.equals(movedOccurrenceSpecification2)) {
- position2 = PositionConstants.BOTTOM;
- }
- // move necessary bounds
- Rectangle newBounds = null;
- int heighDelta = 0;
- if(position1 != PositionConstants.NONE && position2 != PositionConstants.NONE) {
- // both bounds have changed
- Point referencePoint1 = getReferencePoint(lifelinePart, movedOccurrenceSpecification1, yLocation1);
- Point referencePoint2 = getReferencePoint(lifelinePart, movedOccurrenceSpecification2, yLocation2);
- makeRelativeToLifeline(referencePoint1, lifelinePart, true);
- makeRelativeToLifeline(referencePoint2, lifelinePart, true);
- // Get old bounds information by consulting old figure
- Rectangle esBounds = SequenceUtil.getAbsoluteBounds(executionSpecificationPart);
- Point esLoc = esBounds.getLocation();
- makeRelativeToLifeline(esLoc, lifelinePart, true);
- esBounds.setLocation(esLoc);
- int oldX = esBounds.x;
- int oldY = esBounds.y;
- int oldWidth = esBounds.width;
- int oldHeight = esBounds.height;
- // Compute new bounds of the time element
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position1 == PositionConstants.TOP) {
- top = referencePoint1.y;
- } else if(position1 == PositionConstants.BOTTOM) {
- bottom = referencePoint1.y;
- }
- if(position2 == PositionConstants.TOP) {
- top = referencePoint2.y;
- } else if(position2 == PositionConstants.BOTTOM) {
- bottom = referencePoint2.y;
- }
- // top and bottom may have been inverted during the move.
- newBounds = new Rectangle(oldX, Math.min(top, bottom), oldWidth, Math.abs(bottom - top));
- } else if(position1 != PositionConstants.NONE) {
- Point referencePoint1 = getReferencePoint(lifelinePart, movedOccurrenceSpecification1, yLocation1);
- makeRelativeToLifeline(referencePoint1, lifelinePart, true);
- // Get old bounds information by consulting old figure
- Rectangle esBounds = SequenceUtil.getAbsoluteBounds(executionSpecificationPart);
- Point esLoc = esBounds.getLocation();
- makeRelativeToLifeline(esLoc, lifelinePart, true);
- esBounds.setLocation(esLoc);
- int oldX = esBounds.x;
- int oldY = esBounds.y;
- int oldWidth = esBounds.width;
- int oldHeight = esBounds.height;
- // Compute new bounds of the time element
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position1 == PositionConstants.TOP) {
- top = referencePoint1.y;
- } else if(position1 == PositionConstants.BOTTOM) {
- bottom = referencePoint1.y;
- }
- // top and bottom may have been inverted during the move.
- newBounds = new Rectangle(oldX, Math.min(top, bottom), oldWidth, Math.abs(bottom - top));
- } else if(position2 != PositionConstants.NONE) {
- Point referencePoint2 = getReferencePoint(lifelinePart, movedOccurrenceSpecification2, yLocation2);
- makeRelativeToLifeline(referencePoint2, lifelinePart, true);
- // Get old bounds information by consulting old figure
- Rectangle esBounds = SequenceUtil.getAbsoluteBounds(executionSpecificationPart);
- Point esLoc = esBounds.getLocation();
- makeRelativeToLifeline(esLoc, lifelinePart, true);
- esBounds.setLocation(esLoc);
- int oldX = esBounds.x;
- int oldY = esBounds.y;
- int oldWidth = esBounds.width;
- int oldHeight = esBounds.height;
- // Compute new bounds of the time element
- int top = oldY;
- int bottom = oldY + oldHeight;
- // bound is based on two events. Recompute it according to moved event(s).
- if(position2 == PositionConstants.TOP) {
- top = referencePoint2.y;
- } else if(position2 == PositionConstants.BOTTOM) {
- bottom = referencePoint2.y;
- }
- // top and bottom may have been inverted during the move.
- newBounds = new Rectangle(oldX, Math.min(top, bottom), oldWidth, Math.abs(bottom - top));
- }
- if(newBounds != null) {
- // adjust bounds for execution specification
- newBounds.height -= heighDelta;
- TransactionalEditingDomain editingDomain = executionSpecificationPart.getEditingDomain();
- // return the resize command
- ICommandProxy resize = new ICommandProxy(new SetBoundsCommand(editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, new EObjectAdapter((View)executionSpecificationPart.getModel()), newBounds));
- return resize;
- }
- }
- return null;
- }
-
- /**
- * Get the reference point to reconnect or resize edit parts at the given y location
- *
- * @param lifelinePart
- * lifeline edit part containing the moved element
- * @param movedOccurrenceSpecification
- * the moving occurrence specification which a reference point is searched for
- * @param yLocation
- * y location
- * @return reference point on the lifeline
- */
- private static Point getReferencePoint(LifelineEditPart lifelinePart, OccurrenceSpecification movedOccurrenceSpecification, int yLocation) {
- Point referencePoint = SequenceUtil.findLocationOfEvent(lifelinePart, movedOccurrenceSpecification);
- if(referencePoint == null) {
- referencePoint = lifelinePart.getFigure().getBounds().getCenter().getCopy();
- }
- referencePoint.y = yLocation;
- return referencePoint;
- }
-
- /**
- * Chain the commands to move associated parts when a connection end is reconnected.
- *
- * @param command
- * existing reconnection command
- * @param request
- * the reconnection request
- * @param connectableNode
- * the node edit part connected to the moved connection
- * @return the completed command
- */
- public static Command completeReconnectConnectionCommand(Command command, ReconnectRequest request, INodeEditPart connectableNode) {
- if(chainEffectIsDisabled(request)) {
- return command;
- }
- CompoundCommand globalCmd = new CompoundCommand();
- globalCmd.add(command);
- List<EditPart> notToMoveEditParts = new ArrayList<EditPart>(1);
- notToMoveEditParts.add(request.getConnectionEditPart());
- // move time related elements linked with the event
- LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(connectableNode);
- MessageEnd event = getMessageEndFromReconnectMessage(request);
- if(event instanceof OccurrenceSpecification) {
- Command cmd = getMoveOccurrenceSpecificationsCommand((OccurrenceSpecification)event, null, request.getLocation().y, -1, lifelinePart, notToMoveEditParts);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- OccurrenceSpecification event2 = getOccurrenceSpecificationFromReconnectGeneralOrdering(request);
- if(event2 instanceof OccurrenceSpecification) {
- Command cmd = getMoveOccurrenceSpecificationsCommand((OccurrenceSpecification)event2, null, request.getLocation().y, -1, lifelinePart, notToMoveEditParts);
- if(cmd != null) {
- globalCmd.add(cmd);
- }
- }
- return globalCmd;
- }
-
- /**
- * Check if moving chain effect has been disabled to avoid an infinite loop.
- *
- * @param request
- * the request wich initiated the move
- * @return true if no additional command must be performed.
- */
- private static boolean chainEffectIsDisabled(Request request) {
- Object doNotToMoveEditParts = request.getExtendedData().get(SequenceRequestConstant.DO_NOT_MOVE_EDIT_PARTS);
- return Boolean.TRUE.equals(doNotToMoveEditParts);
- }
-
- /**
- * Complete a command to move time/duration constraints/observation which are linked to the moved edit part
- *
- * @param compoundCmd
- * existing command to complete
- * @param executionSpecificationEP
- * the moved edit part representing an execution specification
- * @param newBounds
- * the new part's bounds (relative to the figure's parent)
- * @param request
- * the change bounds request which originated this move
- * @return the updated parameter compoundCmd for convenience
- */
- public static CompoundCommand completeMoveExecutionSpecificationCommand(CompoundCommand compoundCmd, ShapeNodeEditPart executionSpecificationEP, Rectangle newBounds, ChangeBoundsRequest request) {
- if(chainEffectIsDisabled(request)) {
- return compoundCmd;
- }
- // Move events delimiting the ExecutionSpecification
- EObject execSpec = executionSpecificationEP.resolveSemanticElement();
- if(execSpec instanceof ExecutionSpecification) {
- LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(executionSpecificationEP);
- // first, get absolute bounds
- newBounds = newBounds.getCopy();
- IFigure parentFig = executionSpecificationEP.getFigure().getParent();
- parentFig.translateToAbsolute(newBounds);
- newBounds.translate(parentFig.getBounds().getLocation());
-
- // move start and finish events
- OccurrenceSpecification start = ((ExecutionSpecification)execSpec).getStart();
- int startY = newBounds.getTop().y;
- OccurrenceSpecification finish = ((ExecutionSpecification)execSpec).getFinish();
- int finishY = newBounds.getBottom().y;
- List<EditPart> notToMoveEditParts = new ArrayList<EditPart>(1);
- notToMoveEditParts.add(executionSpecificationEP);
- Command cmd = getMoveOccurrenceSpecificationsCommand(start, finish, startY, finishY, lifelinePart, notToMoveEditParts);
- if(cmd != null) {
- compoundCmd.add(cmd);
- }
-
- if(request.getSizeDelta().height == 0) {
- // move time elements for events between start and finish
- InteractionFragment nextOccSpec = InteractionFragmentHelper.findNextFragment(start, start.eContainer());
- while(nextOccSpec != null && nextOccSpec != finish) {
- Point occSpecLocation = SequenceUtil.findLocationOfEvent(lifelinePart, nextOccSpec);
- if(nextOccSpec instanceof OccurrenceSpecification && occSpecLocation != null) {
- int occSpecY = occSpecLocation.y + request.getMoveDelta().y;
- cmd = getMoveTimeElementsCommand((OccurrenceSpecification)nextOccSpec, null, occSpecY, -1, lifelinePart, notToMoveEditParts);
- if(cmd != null) {
- compoundCmd.add(cmd);
- }
- }
- nextOccSpec = InteractionFragmentHelper.findNextFragment(nextOccSpec, start.eContainer());
- }
- }
- }
- return compoundCmd;
- }
-
- /**
- * Prepare a request which is supposed to move a time/duration constraints/observation edit part.
- * The request will be updated if some operations are forbidden.
- *
- * @param request
- * the move request
- * @param movedTimePart
- * the moved time/duration constraints/observation edit part.
- */
- public static void prepareTimeRelatedElementMoveRequest(ChangeBoundsRequest request, IBorderItemEditPart movedTimePart) {
- // Erase the y move if element can not be moved on y axe
- if(!canTimeElementPartBeYMoved(movedTimePart)) {
- request.getMoveDelta().y = 0;
- }
- }
-
- /**
- * Complete the command to move an edit part representing a time/duration constraints/observation.
- *
- * @param moveCommand
- * the move command to complete with chaining
- * @param request
- * the request which initiated the move
- * @param hostFigure
- * figure which is being moved
- * @param hostEditPart
- * edit part which is being moved
- * @return the complete command.
- */
- public static Command completeMoveTimeRelatedElementCommand(Command moveCommand, ChangeBoundsRequest request, EditPart hostEditPart, IFigure hostFigure) {
- if(chainEffectIsDisabled(request)) {
- return moveCommand;
- }
- Rectangle bounds = request.getTransformedRectangle(hostFigure.getBounds());
- hostFigure.getParent().translateToAbsolute(bounds);
- LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(hostEditPart);
- if(lifelinePart != null && hostEditPart instanceof IBorderItemEditPart) {
- IBorderItemEditPart timeElementEditPart = (IBorderItemEditPart)hostEditPart;
- EObject timeElement = timeElementEditPart.resolveSemanticElement();
- OccurrenceSpecification occSpec1 = null;
- int yLocation1 = -1;
- OccurrenceSpecification occSpec2 = null;
- int yLocation2 = -1;
- // find occurrence specifications of the time element
- if(timeElement instanceof TimeConstraint) {
- Iterator<Element> it = ((TimeConstraint)timeElement).getConstrainedElements().iterator();
- while(it.hasNext() && occSpec1 == null) {
- Element elem = it.next();
- if(elem instanceof OccurrenceSpecification) {
- int position1 = whereEventIsLinked((OccurrenceSpecification)elem, timeElementEditPart);
- if(position1 != PositionConstants.NONE) {
- occSpec1 = (OccurrenceSpecification)elem;
- yLocation1 = getLocation(bounds, position1).y;
- }
- }
- }
- } else if(timeElement instanceof TimeObservation) {
- NamedElement event = ((TimeObservation)timeElement).getEvent();
- if(event instanceof OccurrenceSpecification) {
- int position1 = whereEventIsLinked((OccurrenceSpecification)event, timeElementEditPart);
- if(position1 != PositionConstants.NONE) {
- occSpec1 = (OccurrenceSpecification)event;
- yLocation1 = getLocation(bounds, position1).y;
- }
- }
- } else if(timeElement instanceof DurationConstraint) {
- Iterator<Element> it = ((DurationConstraint)timeElement).getConstrainedElements().iterator();
- while(it.hasNext() && (occSpec1 == null || occSpec2 == null)) {
- Element elem = it.next();
- if(elem instanceof OccurrenceSpecification && occSpec1 != null) {
- int position2 = whereEventIsLinked((OccurrenceSpecification)elem, timeElementEditPart);
- if(position2 != PositionConstants.NONE) {
- occSpec2 = (OccurrenceSpecification)elem;
- yLocation2 = getLocation(bounds, position2).y;
- }
- } else if(elem instanceof OccurrenceSpecification) {
- int position1 = whereEventIsLinked((OccurrenceSpecification)elem, timeElementEditPart);
- if(position1 != PositionConstants.NONE) {
- occSpec1 = (OccurrenceSpecification)elem;
- yLocation1 = getLocation(bounds, position1).y;
- }
- }
- }
- }
- if(occSpec1 != null) {
- List<EditPart> notToMoveEditParts = Collections.singletonList(hostEditPart);
- Command cmd = getMoveOccurrenceSpecificationsCommand(occSpec1, occSpec2, yLocation1, yLocation2, lifelinePart, notToMoveEditParts);
- if(cmd != null) {
- return moveCommand.chain(cmd);
- }
- }
- }
- return null;
- }
-
- /**
- * Make the request to reconnect the connection
- *
- * @param connection
- * connection part
- * @param isSource
- * true if the source must be reconnect, false for target
- * @param location
- * the location where to reconnect
- * @param partToReconnectTo
- * the part which the connection must be reconnected to (or null if unknown or of no importance)
- * @return the reconnection request
- */
- @SuppressWarnings("unchecked")
- private static ReconnectRequest makeReconnectRequest(ConnectionEditPart connection, boolean isSource, Point location, EditPart partToReconnectTo) {
- // Obtain the target edit part
- EditPart targetEP = partToReconnectTo;
- String type;
- if(isSource) {
- type = RequestConstants.REQ_RECONNECT_SOURCE;
- if(targetEP == null) {
- targetEP = connection.getSource();
- }
- } else {
- type = RequestConstants.REQ_RECONNECT_TARGET;
- if(targetEP == null) {
- targetEP = connection.getTarget();
- }
- }
-
- // Create and set the properties of the request
- ReconnectRequest reconnReq = new ReconnectRequest();
- reconnReq.setConnectionEditPart(connection);
- reconnReq.setLocation(location);
- reconnReq.setTargetEditPart(targetEP);
- reconnReq.setType(type);
- // add a parameter to bypass the move impact to avoid infinite loop
- reconnReq.getExtendedData().put(SequenceRequestConstant.DO_NOT_MOVE_EDIT_PARTS, true);
-
- // Return the request
- return reconnReq;
- }
-
- /**
- * Get the location on the bounds
- *
- * @param bounds
- * the rectangle bounds
- * @param position
- * one of {@link PositionConstants#TOP}, {@link PositionConstants#CENTER}, {@link PositionConstants#BOTTOM}
- * @return the point at the given position or null if position is incorrect
- */
- private static Point getLocation(Rectangle bounds, int position) {
- if(position == PositionConstants.TOP) {
- return bounds.getTop();
- } else if(position == PositionConstants.CENTER) {
- return bounds.getCenter();
- } else if(position == PositionConstants.BOTTOM) {
- return bounds.getBottom();
- }
- return null;
- }
-
- /**
- * The position of the host where the event is linked
- *
- * @param event
- * the occurrence specification
- * @param hostEditPart
- * the host edit part which is linked to the occurrence specification
- * @return one of {@link PositionConstants#TOP}, {@link PositionConstants#CENTER}, {@link PositionConstants#BOTTOM},
- * {@link PositionConstants#NONE}
- */
- private static int whereEventIsLinked(OccurrenceSpecification event, EditPart hostEditPart) {
- if(hostEditPart instanceof IBorderItemEditPart) {
- return SequenceUtil.positionWhereEventIsLinkedToPart(event, (IBorderItemEditPart)hostEditPart);
- }
- return PositionConstants.NONE;
- }
-
- /**
- * Get the occurrence specification which correspond to the moved general ordering end
- *
- * @param request
- * the general odering reconnection request
- * @return moved OccurrenceSpecification or null
- */
- private static OccurrenceSpecification getOccurrenceSpecificationFromReconnectGeneralOrdering(ReconnectRequest request) {
- if(request.getConnectionEditPart() instanceof ConnectionEditPart) {
- EObject generalOrdering = ((ConnectionEditPart)request.getConnectionEditPart()).resolveSemanticElement();
- if(generalOrdering instanceof GeneralOrdering) {
- if(RequestConstants.REQ_RECONNECT_SOURCE.equals(request.getType())) {
- return ((GeneralOrdering)generalOrdering).getBefore();
- } else if(RequestConstants.REQ_RECONNECT_TARGET.equals(request.getType())) {
- return ((GeneralOrdering)generalOrdering).getAfter();
- }
- }
- }
- return null;
- }
-
- /**
- * Get the message end which correspond to the moved message end
- *
- * @param request
- * the message reconnection request
- * @return moved MessageEnd or null
- */
- private static MessageEnd getMessageEndFromReconnectMessage(ReconnectRequest request) {
- if(request.getConnectionEditPart() instanceof ConnectionEditPart) {
- EObject message = ((ConnectionEditPart)request.getConnectionEditPart()).resolveSemanticElement();
- if(message instanceof Message) {
- if(RequestConstants.REQ_RECONNECT_SOURCE.equals(request.getType())) {
- return ((Message)message).getSendEvent();
- } else if(RequestConstants.REQ_RECONNECT_TARGET.equals(request.getType())) {
- return ((Message)message).getReceiveEvent();
- }
- }
- }
- return null;
- }
-
- /**
- * Know whether this time element part can be moved within the lifeline or not.
- * Parts linked with a destruction event can not be moved since the destruction event is always at the end.
- *
- * @param timeElementPart
- * the part representing a time/duration constraint/observation
- * @return true if the part can be moved
- */
- public static boolean canTimeElementPartBeYMoved(IBorderItemEditPart timeElementPart) {
- EObject timeElement = timeElementPart.resolveSemanticElement();
- List<? extends Element> occurrences = Collections.emptyList();
- if(timeElement instanceof TimeObservation) {
- NamedElement occurence = ((TimeObservation)timeElement).getEvent();
- occurrences = Collections.singletonList(occurence);
- } else if(timeElement instanceof TimeConstraint || timeElement instanceof DurationConstraint) {
- occurrences = ((IntervalConstraint)timeElement).getConstrainedElements();
- }
- // check whether one of the time occurrences correspond to a DestructionEvent
- for(Element occurrence : occurrences) {
- if(occurrence instanceof DestructionOccurrenceSpecification) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Get a command which refreshes the bordered layout of the node.
- *
- * @param node
- * the node figure with bordered items (including time-related parts)
- * @param onUndo
- * if true the relayout will be done on undo only, if false it will be done on classic execute only
- * @return the refresh command
- */
- private static Command getReLayoutCmd(BorderedNodeFigure node, boolean onUndo) {
- // relayout the border container figure so that time elements are refreshed
- final IFigure container = node.getBorderItemContainer();
-
- if(onUndo) {
- return new Command() {
-
- @Override
- public void undo() {
- container.getLayoutManager().layout(container);
- }
- };
- } else {
- return new Command() {
-
- @Override
- public void execute() {
- container.getLayoutManager().layout(container);
- }
- };
- }
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OperandBoundsComputeHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OperandBoundsComputeHelper.java
deleted file mode 100644
index f52c251d9f0..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/OperandBoundsComputeHelper.java
+++ /dev/null
@@ -1,837 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.core.command.ICompositeCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.Shape;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentCombinedFragmentCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionInteractionCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.part.UMLVisualIDRegistry;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
-
-public class OperandBoundsComputeHelper {
-
- /**
- * Default height of Interaction Operand
- */
- public static final int DEFAULT_INTERACTION_OPERAND_HEIGHT = 61;
-
- public static final int MIN_INTERACTION_OPERAND_HEIGHT = 10;
- /**
- * Default width of Interaction Operand
- */
- public static final int DEFAULT_INTERACTION_OPERAND_WIDTH = 210;
- /**
- * Border width of CombinedFragmentFigure
- */
- public static final int COMBINED_FRAGMENT_FIGURE_BORDER = 1;
-
- /**
- * Find first Interaction Operand EditpPart of CombinedFragmentCombinedFragmentCompartmentEditPart
- * @param compartEP
- * @return InteractionOperandEditPart
- */
- public static InteractionOperandEditPart findFirstIOEP(
- CombinedFragmentCombinedFragmentCompartmentEditPart compartEP) {
- InteractionOperandEditPart firstIOEP = null;
- List children = compartEP.getChildren();
- for (int i = 0; i < children.size(); i++) {
- if (children.get(i) instanceof InteractionOperandEditPart) {
- firstIOEP = (InteractionOperandEditPart) children.get(i);
- break;
- }
- }
- return firstIOEP;
- }
-
- /**
- * Find Last Interaction Operand EditpPart of CombinedFragmentCombinedFragmentCompartmentEditPart
- * @param compartEP
- * @return InteractionOperandEditPart
- */
- public static InteractionOperandEditPart findLastIOEP(
- CombinedFragmentCombinedFragmentCompartmentEditPart compartEP) {
- InteractionOperandEditPart lastIOEP = null;
- List children = compartEP.getChildren();
- for (int i = children.size() - 1; i >= 0; i--) {
- if (children.get(i) instanceof InteractionOperandEditPart) {
- lastIOEP = (InteractionOperandEditPart) children.get(i);
- break;
- }
- }
- return lastIOEP;
- }
-
- /**
- * Find Previous Interaction Operand EditpPart of current given InteractionOperandEditPart
- * @param compartEP
- * @param currentIOEP
- * @return InteractionOperandEditPart
- */
- public static InteractionOperandEditPart findPreviousIOEP(
- CombinedFragmentCombinedFragmentCompartmentEditPart compartEP,
- InteractionOperandEditPart currentIOEP) {
- InteractionOperandEditPart previousIOEP = null;
- List children = compartEP.getChildren();
- for (int i = 0; i < children.size() - 1; i++) {
- if (children.get(i) instanceof InteractionOperandEditPart) {
- if (children.get(i) == currentIOEP) {
- break;
- } else {
- previousIOEP = (InteractionOperandEditPart) children.get(i);
- }
- }
- }
- return previousIOEP;
- }
-
- /**
- * Find Latter Interaction Operand EditpPart of current given InteractionOperandEditPart
- * @param compartEP
- * @param currentIOEP
- * @return InteractionOperandEditPart
- */
- public static InteractionOperandEditPart findLatterIOEP(
- CombinedFragmentCombinedFragmentCompartmentEditPart compartEP,
- InteractionOperandEditPart currentIOEP) {
- InteractionOperandEditPart latterIOEP = null;
- List children = compartEP.getChildren();
- for (int i = children.size() - 1; i > 0; i--) {
- if (children.get(i) instanceof InteractionOperandEditPart) {
- if (children.get(i) == currentIOEP) {
- break;
- } else {
- latterIOEP = (InteractionOperandEditPart) children.get(i);
- }
- }
- }
- return latterIOEP;
- }
-
- /**
- * Update EditPart bounds using new rect
- * @param parent
- * @param rect
- */
- public static void updateEditPartBounds(GraphicalEditPart editpart,
- final Rectangle rect) {
- if (editpart.getModel() instanceof Node) {
- Node node = (Node) editpart.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds bounds = (Bounds) node.getLayoutConstraint();
- updateBounds(bounds, rect, editpart.getEditingDomain());
- }
- }
- }
-
- /**
- * Update EditPart bounds using new rect
- * @param parent
- * @param rect
- */
- public static ICommand createUpdateEditPartBoundsCommand(
- final GraphicalEditPart editpart, final Rectangle rect) {
- ICommand cmd = new AbstractTransactionalCommand(
- editpart.getEditingDomain(),
- "Update Operand Bounds", null) {
- @Override
- protected CommandResult doExecuteWithResult(
- IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- if (editpart.getModel() instanceof Node) {
- Node node = (Node) editpart.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds bounds = (Bounds) node.getLayoutConstraint();
- fillBounds(bounds, rect);
- }
- }
- return CommandResult.newOKCommandResult();
- }
- };
- return cmd;
- }
-
- /**
- * Create command for updating Interaction Operand EditpPart bounds after the CombinedFragment to be created.
- * @param editPart
- * @param request
- * @return ICommand
- */
- public static ICommand createUpdateCFAndIOBoundsForCFCreationCommand(final EditPart editPart, final CreateViewRequest request) {
- if (!(editPart instanceof GraphicalEditPart)) {
- return null;
- }
- GraphicalEditPart graphicalEditPart= (GraphicalEditPart)editPart;
- ICommand cmd = new AbstractTransactionalCommand(graphicalEditPart.getEditingDomain(),"Create update operand bounds command",null) {
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
- IAdaptable info) throws ExecutionException {
- OperandBoundsComputeHelper.updateCFAndIOBoundsForCFCreation(
- (GraphicalEditPart) editPart, request);
- return CommandResult.newOKCommandResult();
- }
- };
- return cmd;
- }
-
- /**
- * Update Interaction Operand EditpPart bounds after the CombinedFragment to be created.
- * @param parent
- * @param request
- * @param selectionRect
- */
- private static void updateCFAndIOBoundsForCFCreation(GraphicalEditPart parent, CreateViewRequest request) {
- Object subEditPart = null;
- if (parent instanceof InteractionInteractionCompartmentEditPart) {
- InteractionInteractionCompartmentEditPart interactionInteractionCompartmentEditPart = (InteractionInteractionCompartmentEditPart) parent;
- subEditPart = interactionInteractionCompartmentEditPart
- .getChildren().get(
- interactionInteractionCompartmentEditPart
- .getChildren().size() - 1);
-
- }else if (parent instanceof InteractionOperandEditPart) {
- InteractionOperandEditPart interactionOperandEditPart = (InteractionOperandEditPart) parent;
- subEditPart = interactionOperandEditPart
- .getChildren().get(
- interactionOperandEditPart
- .getChildren().size() - 1);
- }
- if (subEditPart != null
- && subEditPart instanceof CombinedFragmentEditPart) {
- CombinedFragmentEditPart combinedFragmentEditPart = (CombinedFragmentEditPart) subEditPart;
- // set bounds for CombinedFragmentEditPart
- Rectangle cfEPAbsoluteRect = null;
- int labelContainerHeight = computeCombinedFragementHeaderHeight(combinedFragmentEditPart);
- Shape cfEPShape = (Shape) combinedFragmentEditPart.getModel();
- if (cfEPShape.getLayoutConstraint() instanceof Bounds) {
- if(request.getSize() == null){
- Dimension cfEPDefaultSize = new Dimension();
- cfEPDefaultSize.setWidth(DEFAULT_INTERACTION_OPERAND_WIDTH+COMBINED_FRAGMENT_FIGURE_BORDER*2);
- cfEPDefaultSize.setHeight(DEFAULT_INTERACTION_OPERAND_HEIGHT+labelContainerHeight+COMBINED_FRAGMENT_FIGURE_BORDER*2);
- cfEPAbsoluteRect = new Rectangle(request.getLocation(),cfEPDefaultSize);
- }else{
- cfEPAbsoluteRect = new Rectangle(request.getLocation(),request.getSize());
- }
- Rectangle cfEPRelativeRect = cfEPAbsoluteRect.getCopy();
- combinedFragmentEditPart.getFigure().translateToRelative(cfEPRelativeRect);
- Bounds cfEPBounds = (Bounds) cfEPShape.getLayoutConstraint();
- fillBounds(cfEPBounds,cfEPRelativeRect);
- }
-
- // set bounds for new added Operand
- InteractionOperandEditPart lastOperand = OperandBoundsComputeHelper
- .findLastIOEP((CombinedFragmentCombinedFragmentCompartmentEditPart) combinedFragmentEditPart.getChildBySemanticHint(UMLVisualIDRegistry
- .getType(CombinedFragmentCombinedFragmentCompartmentEditPart.VISUAL_ID)));
- Shape shape = (Shape) lastOperand.getModel();
- if (shape.getLayoutConstraint() instanceof Bounds) {
- Bounds bounds = (Bounds) shape.getLayoutConstraint();
- Rectangle rect = new Rectangle(bounds.getX(), bounds.getY(),
- cfEPAbsoluteRect.width()-COMBINED_FRAGMENT_FIGURE_BORDER*2, cfEPAbsoluteRect.height()
- - labelContainerHeight-COMBINED_FRAGMENT_FIGURE_BORDER*2);
- fillBounds(bounds,rect);
- }
- }
- }
-
- /**
- * Create command for updating Interaction Operand EditpPart bounds after CombinedFragment to be resized.
- * @param compoundCmd
- * @param request
- * @param combinedFragmentEditPart
- * @return Command
- */
- public static Command createUpdateIOBoundsForCFResizeCommand(
- CompoundCommand compoundCmd, final ChangeBoundsRequest request,
- CombinedFragmentEditPart combinedFragmentEditPart) {
- if (combinedFragmentEditPart.getChildren().size() > 0
- && combinedFragmentEditPart.getChildren().get(0) instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
- CombinedFragmentCombinedFragmentCompartmentEditPart compartment = (CombinedFragmentCombinedFragmentCompartmentEditPart) combinedFragmentEditPart
- .getChildren().get(0);
- CombinedFragment cf = (CombinedFragment) ((CombinedFragmentEditPart) combinedFragmentEditPart)
- .resolveSemanticElement();
- InteractionOperandEditPart targetIOEP = null;
- if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
- targetIOEP = findFirstIOEP(compartment);
- } else if ((request.getResizeDirection() & PositionConstants.SOUTH) != 0) {
- targetIOEP = findLastIOEP(compartment);
- }
- updateIOBoundsForCFResize(
- request,
- compoundCmd,
- compartment.getChildren(),
- cf,
- targetIOEP != null ? (InteractionOperand) targetIOEP
- .resolveSemanticElement() : null,
- request.getSizeDelta(), request.getResizeDirection());
- }
- return compoundCmd;
- }
-
- /**
- * Update Interaction Operand EditpPart bounds after CombinedFragment to be resized.
- * @param request
- * @param compoundCmd
- * @param combinedFragmentChildrenEditParts
- * @param cf
- * @param targetOperand
- * @param sizeDelta
- * @param direction
- */
- private static void updateIOBoundsForCFResize(final ChangeBoundsRequest request,
- CompoundCommand compoundCmd,
- List<EditPart> combinedFragmentChildrenEditParts,
- CombinedFragment cf, InteractionOperand targetOperand,
- final Dimension sizeDelta, int direction) {
- InteractionOperandEditPart targetOperandEditPart = findTargetOperandEditPart(
- cf, targetOperand, combinedFragmentChildrenEditParts);
- for (EditPart ep : combinedFragmentChildrenEditParts) {
- if (ep instanceof InteractionOperandEditPart) {
- InteractionOperandEditPart ioEP = (InteractionOperandEditPart) ep;
- Object ioEPModel = ioEP.getModel();
- if (ioEPModel instanceof Shape) {
- Shape ioEPShape = (Shape) ioEPModel;
- if (ioEPShape.getLayoutConstraint() instanceof Bounds) {
- final Bounds ioEPOriginalBounds = (Bounds) ioEPShape
- .getLayoutConstraint();
- ICommand cmd = new UpdateIOBoundsForCFResizeCommand(
- ioEP.getEditingDomain(),
- "Update operand bounds interaction command",
- ioEPOriginalBounds, request, sizeDelta,
- ioEP == targetOperandEditPart, direction);
- compoundCmd.add(new ICommandProxy(cmd));
- }
- }
- }
- }
-
- }
-
- /**
- * Update bounds using new rect
- * @param bounds
- * @param rect
- * @param transactionalEditingDomain
- */
- public static void updateBounds(final Bounds bounds, final Rectangle rect,
- TransactionalEditingDomain transactionalEditingDomain) {
- if (bounds != null) {
- final Rectangle originalBounds = new Rectangle();
- originalBounds.setX(bounds.getX());
- originalBounds.setY(bounds.getY());
- originalBounds.setWidth(bounds.getWidth());
- originalBounds.setHeight(bounds.getHeight());
- AbstractCommand cmd = new AbstractCommand() {
- public boolean canExecute() {
- return true;
- }
-
- public void execute() {
- exec(rect);
- }
-
- public void redo() {
- execute();
- }
-
- public void undo(){
- exec(originalBounds);
- }
-
- public void exec(Rectangle rect){
- fillBounds(bounds,rect);
- }
-
- public boolean canUndo() {
- return true;
- }
- };
- CommandHelper.executeCommandWithoutHistory(
- transactionalEditingDomain, cmd,true);
- }
- }
-
- /**
- * Get InteractionOperandEditPart from its model object InteractionOperand.
- * @param cf
- * @param targetOperand
- * @param combinedFragmentChildrenEditParts
- * @return InteractionOperandEditPart
- */
- public static InteractionOperandEditPart findTargetOperandEditPart(CombinedFragment cf,
- InteractionOperand targetOperand,
- List<EditPart> combinedFragmentChildrenEditParts) {
- if(targetOperand == null)
- return null;
- for(EditPart ep : combinedFragmentChildrenEditParts) {
- if(ep instanceof InteractionOperandEditPart) {
- InteractionOperandEditPart ioEP = (InteractionOperandEditPart)ep;
- InteractionOperand io = (InteractionOperand)ioEP.resolveSemanticElement();
- if(cf.getOperands().contains(io)) {
- if(targetOperand.equals(io)) {
- return ioEP;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Get graphical edit part bounds
- * @param editPart
- * @return
- */
- public static Bounds getEditPartBounds(GraphicalEditPart editPart){
- if (editPart.getModel() instanceof Node) {
- Node node = (Node) editPart.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds bounds = (Bounds) node.getLayoutConstraint();
- return bounds;
- }
- }
- return null;
- }
-
- /**
- * Fill data from Bounds to Rectangle
- * @param source
- * @return Rectangle
- */
- public static Rectangle fillRectangle(Bounds source) {
- if (source == null) {
- return null;
- }
- Rectangle target = new Rectangle();
- target.setX(source.getX());
- target.setY(source.getY());
- target.setWidth(source.getWidth());
- target.setHeight(source.getHeight());
- return target;
- }
-
- /**
- * Fill data from Rectangle to Bounds
- * @param bounds
- * @param source
- * @return Bounds
- */
- public static Bounds fillBounds(Bounds bounds,Rectangle source) {
- if (bounds == null || source == null) {
- return null;
- }
- bounds.setX(source.x());
- bounds.setY(source.y());
- bounds.setWidth(source.width());
- bounds.setHeight(source.height());
- return bounds;
- }
-
- /**
- * Get interaction operand bounds
- * @param operandEP
- * @return Bounds
- */
- public static Bounds getInteractionOperandEPBounds(GraphicalEditPart operandEP){
- Object lastChildModel = operandEP.getModel();
- if (lastChildModel instanceof Shape) {
- Shape lastOperandShape = (Shape) lastChildModel;
- if (lastOperandShape.getLayoutConstraint() instanceof Bounds) {
- return (Bounds)lastOperandShape.getLayoutConstraint();
- }
- }
- return null;
- }
-
- /**
- * Create interaction operand resize command
- * @param currentIOEP
- * @param heightDelta
- * @param compartEP
- * @param direction
- * @return
- */
- public static Command createIOEPResizeCommand(
- InteractionOperandEditPart currentIOEP, int heightDelta,
- CombinedFragmentCombinedFragmentCompartmentEditPart compartEP,
- int direction) {
- Bounds currentIOEPBounds = OperandBoundsComputeHelper
- .getEditPartBounds(currentIOEP);
- if (currentIOEPBounds == null) {
- return null;
- }
- InteractionOperandEditPart targetIOEP = null;
- if ((direction & PositionConstants.NORTH) != 0) {
- targetIOEP = OperandBoundsComputeHelper.findPreviousIOEP(compartEP,
- currentIOEP);
- } else if ((direction & PositionConstants.SOUTH) != 0) {
- targetIOEP = OperandBoundsComputeHelper.findLatterIOEP(compartEP,
- currentIOEP);
- }
-
- CompositeCommand compositeCommand = new CompositeCommand(
- "Resize Operand");
- // if last operand
- if(targetIOEP == null){
- if (heightDelta < 0) {
- if (currentIOEPBounds.getHeight() - Math.abs(heightDelta) < OperandBoundsComputeHelper.MIN_INTERACTION_OPERAND_HEIGHT) {
- return null;
- }
- }
- Rectangle currentIOEPRect = OperandBoundsComputeHelper
- .fillRectangle(currentIOEPBounds);
- currentIOEPRect.setHeight(currentIOEPBounds.getHeight() + heightDelta);
- ICommand currentIOEPCommand = OperandBoundsComputeHelper
- .createUpdateEditPartBoundsCommand(currentIOEP, currentIOEPRect);
- compositeCommand.add(currentIOEPCommand);
- // auto update CombinedFragmentEditPart bounds after resize the last operand
- if(compartEP.getParent() instanceof CombinedFragmentEditPart){
- CombinedFragmentEditPart parent = (CombinedFragmentEditPart) compartEP.getParent();
- if (parent.getModel() instanceof Node) {
- Node node = (Node) parent.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds containerBounds = (Bounds) node
- .getLayoutConstraint();
- Dimension preferredSize = parent.getFigure().getPreferredSize();
- int width = containerBounds.getWidth()!=-1? containerBounds.getWidth() : preferredSize.width();
- int height = containerBounds.getHeight()!=-1? containerBounds.getHeight() : preferredSize.height();
- height = height + heightDelta;
- Rectangle containerRect = new Rectangle(containerBounds.getX(),containerBounds.getY(),width,height);
- compositeCommand.add(OperandBoundsComputeHelper.createUpdateEditPartBoundsCommand(parent, containerRect));
- }
- }
- }
- }else{
- Bounds targetIOEPBounds = OperandBoundsComputeHelper
- .getEditPartBounds(targetIOEP);
- if (targetIOEPBounds == null) {
- return null;
- }
- if (heightDelta > 0) {
- if (targetIOEPBounds.getHeight() - heightDelta < OperandBoundsComputeHelper.MIN_INTERACTION_OPERAND_HEIGHT) {
- return null;
- }
- } else {
- if (currentIOEPBounds.getHeight() - Math.abs(heightDelta) < OperandBoundsComputeHelper.MIN_INTERACTION_OPERAND_HEIGHT) {
- return null;
- }
- }
- Rectangle targetIOEPRect = OperandBoundsComputeHelper
- .fillRectangle(targetIOEPBounds);
- Rectangle currentIOEPRect = OperandBoundsComputeHelper
- .fillRectangle(currentIOEPBounds);
- targetIOEPRect.setHeight(targetIOEPBounds.getHeight() - heightDelta);
- currentIOEPRect.setHeight(currentIOEPBounds.getHeight() + heightDelta);
- if ((direction & PositionConstants.NORTH) != 0) {
- currentIOEPRect.setY(currentIOEPRect.y() - heightDelta);
- }else if ((direction & PositionConstants.SOUTH) != 0) {
- targetIOEPRect.setY(targetIOEPRect.y() + heightDelta);
- }
-
- ICommand previousIOEPCommand = OperandBoundsComputeHelper
- .createUpdateEditPartBoundsCommand(targetIOEP, targetIOEPRect);
- ICommand currentIOEPCommand = OperandBoundsComputeHelper
- .createUpdateEditPartBoundsCommand(currentIOEP, currentIOEPRect);
-
- compositeCommand.add(previousIOEPCommand);
- compositeCommand.add(currentIOEPCommand);
- }
-
- return new ICommandProxy(compositeCommand);
- }
-
- /**
- * Compute CombinedFragement's header height
- * @param combinedFragmentEditPart
- * @return int
- */
- public static int computeCombinedFragementHeaderHeight(
- CombinedFragmentEditPart combinedFragmentEditPart) {
- int headerHeight = 0;
- IFigure labelContainer = combinedFragmentEditPart.getPrimaryShape().getHeaderLabel().getParent();
- if(labelContainer!=null){
- headerHeight = labelContainer.getPreferredSize().height();
- }
- return headerHeight;
- }
-
- /**
- * Check if operation resizing on CombinedFragment is allowed
- * @param request
- * @param child
- * @return boolean
- */
- public static boolean checkRedistrictOnCFResize(ChangeBoundsRequest request,
- EditPart child) {
- if(child instanceof CombinedFragmentEditPart){
- if ((request.getResizeDirection() & PositionConstants.NORTH_SOUTH) != 0) {
- CombinedFragmentEditPart combinedFragmentEditPart = (CombinedFragmentEditPart)child;
- if (combinedFragmentEditPart.getChildren().size() > 0
- && combinedFragmentEditPart.getChildren()
- .get(0) instanceof CombinedFragmentCombinedFragmentCompartmentEditPart) {
- CombinedFragmentCombinedFragmentCompartmentEditPart compartment = (CombinedFragmentCombinedFragmentCompartmentEditPart) combinedFragmentEditPart
- .getChildren().get(0);
- List<EditPart> combinedFragmentChildrenEditParts = compartment
- .getChildren();
- CombinedFragment cf = (CombinedFragment) ((CombinedFragmentEditPart) combinedFragmentEditPart)
- .resolveSemanticElement();
- InteractionOperand targetOperand = null;
- if ((request.getResizeDirection() & PositionConstants.NORTH) != 0) {
- targetOperand = cf.getOperands().get(0);
- } else if ((request.getResizeDirection() & PositionConstants.SOUTH) != 0) {
- targetOperand = cf.getOperands().get(
- cf.getOperands().size() - 1);
- }
- InteractionOperandEditPart targetOperandEditPart = OperandBoundsComputeHelper.findTargetOperandEditPart(
- cf, targetOperand, combinedFragmentChildrenEditParts);
- int heightDelta = request.getSizeDelta().height();
- if(targetOperandEditPart!=null && heightDelta<0){
- int height = targetOperandEditPart.getFigure().getBounds().height();
- if(height-Math.abs(heightDelta) < OperandBoundsComputeHelper.MIN_INTERACTION_OPERAND_HEIGHT){
- return false;
- }
- }
- }
- }
- }
- return true;
- }
-
- /**
- * Add command for updating adjacent interaction operand bounds after deleting a interaction operand
- * @param editPart
- * @param cmd
- */
- public static void addUpdateBoundsCommandForOperandDelelete(EditPart editPart,ICompositeCommand cmd) {
- if(editPart instanceof InteractionOperandEditPart){
- if(editPart.getParent() instanceof CombinedFragmentCombinedFragmentCompartmentEditPart){
- CombinedFragmentCombinedFragmentCompartmentEditPart compartment = (CombinedFragmentCombinedFragmentCompartmentEditPart)editPart.getParent();
- if(compartment.getParent() instanceof CombinedFragmentEditPart){
- List<EditPart> combinedFragmentChildrenEditParts = compartment
- .getChildren();
- InteractionOperandEditPart previousIOEP = null;
- InteractionOperandEditPart latterIOEP = null;
- boolean isFirstOperand = false;
-
- InteractionOperandEditPart currentioEP = (InteractionOperandEditPart)editPart;
- final Rectangle currentioEPBounds = currentioEP.getFigure().getBounds();
-
- for(int i = 0;i<combinedFragmentChildrenEditParts.size();i++) {
- EditPart ep = combinedFragmentChildrenEditParts.get(i);
- if(ep instanceof InteractionOperandEditPart) {
- InteractionOperandEditPart ioEP = (InteractionOperandEditPart)ep;
- if(currentioEP == ioEP){
- if(previousIOEP!=null){
- Object previousIOEPModel = previousIOEP.getModel();
- if (previousIOEPModel instanceof Shape) {
- Shape previousIOEPShape = (Shape) previousIOEPModel;
- if (previousIOEPShape.getLayoutConstraint() instanceof Bounds) {
- final Bounds previousIOEPOriginalBounds = (Bounds) previousIOEPShape.getLayoutConstraint();
- ICommand command = new AbstractTransactionalCommand(previousIOEP.getEditingDomain(),"Merge operand bounds command",null){
- @Override
- protected CommandResult doExecuteWithResult(
- IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
- previousIOEPOriginalBounds.setHeight(previousIOEPOriginalBounds.getHeight() + currentioEPBounds.height());
- return CommandResult.newOKCommandResult();
- }
- };
- cmd.add(command);
- }
- }
- break;
- }else{
- isFirstOperand = true;
- continue;
- }
- }else{
- previousIOEP = ioEP;
- }
- if(isFirstOperand){
- latterIOEP = ioEP;
- break;
- }
- }
- }
- if(isFirstOperand && latterIOEP!=null){
- Object latterIOEPModel = latterIOEP.getModel();
- if (latterIOEPModel instanceof Shape) {
- Shape latterIOEPShape = (Shape) latterIOEPModel;
- if (latterIOEPShape.getLayoutConstraint() instanceof Bounds) {
- final Bounds latterIOEPOriginalBounds = (Bounds) latterIOEPShape.getLayoutConstraint();
- ICommand command = new AbstractTransactionalCommand(previousIOEP.getEditingDomain(),"Merge operand bounds command",null){
- @Override
- protected CommandResult doExecuteWithResult(
- IProgressMonitor monitor,
- IAdaptable info)
- throws ExecutionException {
- latterIOEPOriginalBounds.setY(0);
- latterIOEPOriginalBounds.setHeight(latterIOEPOriginalBounds.getHeight() + currentioEPBounds.height());
- return CommandResult.newOKCommandResult();
- }
- };
- cmd.add(command);
- }
- }
- }
- }
- }
- }
-
- }
-
- /**
- * Add update InteractionOperand bounds command after IO is created
- * @param compartment
- * @param request
- * @param command
- */
- public static void addUpdateBoundsForIOCreationCommand(
- CombinedFragmentCombinedFragmentCompartmentEditPart compartment, ViewDescriptor viewDescriptor,
- CompositeCommand command) {
- List children = compartment.getChildren();
- if (children != null && children.size() > 0) {
- InteractionOperandEditPart lastOperandEP = OperandBoundsComputeHelper.findLastIOEP(compartment);
- // update bounds
- if (lastOperandEP != null) {
- Bounds lastOperandBounds = OperandBoundsComputeHelper.getInteractionOperandEPBounds(lastOperandEP);
- if (lastOperandBounds!= null) {
- Rectangle rect = new Rectangle(
- lastOperandBounds.getX(),
- lastOperandBounds.getY()+lastOperandBounds.getHeight(), lastOperandBounds.getWidth(), OperandBoundsComputeHelper.DEFAULT_INTERACTION_OPERAND_HEIGHT);
- // auto update CombinedFragmentEditPart bounds after added new operand
- if(compartment.getParent() instanceof CombinedFragmentEditPart){
- CombinedFragmentEditPart parent = (CombinedFragmentEditPart) compartment
- .getParent();
- if (parent.getModel() instanceof Node) {
- Node node = (Node) parent.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds containerBounds = (Bounds) node.getLayoutConstraint();
- Dimension preferredSize = parent.getFigure().getPreferredSize();
- int width = containerBounds.getWidth()!=-1? containerBounds.getWidth() : preferredSize.width();
- int height = containerBounds.getHeight()!=-1? containerBounds.getHeight() : preferredSize.height();
- height = height + OperandBoundsComputeHelper.DEFAULT_INTERACTION_OPERAND_HEIGHT;
- View shapeView = (View) parent.getModel();
- ICommand setParentBoundsCmd = new SetBoundsCommand(compartment.getEditingDomain(),
- DiagramUIMessages.SetLocationCommand_Label_Resize,
- new EObjectAdapter(shapeView), new Rectangle(containerBounds.getX(),containerBounds.getY(),width,height));
- command.add(setParentBoundsCmd);
- }
- }
- }
- command.add(new SetBoundsCommand(compartment.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, viewDescriptor, rect));
- }
- }
- }else{ // first add operand
- if(compartment.getParent() instanceof CombinedFragmentEditPart){
- CombinedFragmentEditPart parent = (CombinedFragmentEditPart) compartment
- .getParent();
- if (parent.getModel() instanceof Node) {
- Node node = (Node) parent.getModel();
- if (node.getLayoutConstraint() instanceof Bounds) {
- Bounds containerBounds = (Bounds) node.getLayoutConstraint();
- Dimension preferredSize = parent.getFigure().getPreferredSize();
- int width = containerBounds.getWidth()!=-1? containerBounds.getWidth() : preferredSize.width();
- int height = containerBounds.getHeight()!=-1? containerBounds.getHeight() : preferredSize.height();
- height = height - computeCombinedFragementHeaderHeight(parent);
- command.add(new SetBoundsCommand(compartment.getEditingDomain(), DiagramUIMessages.SetLocationCommand_Label_Resize, viewDescriptor, new Rectangle(0,0,width-COMBINED_FRAGMENT_FIGURE_BORDER*2,height-COMBINED_FRAGMENT_FIGURE_BORDER*2)));
- }
- }
- }
- }
- }
-
- /**
- * Check if it is a combined fragment.
- *
- * @param hint
- * the semantic hint
- * @return
- */
- public static boolean isDerivedCombinedFragment(String hint) {
- if(((IHintedType)UMLElementTypes.CombinedFragment_3004).getSemanticHint().equals(hint)) {
- return true;
- }
- if(((IHintedType)UMLElementTypes.ConsiderIgnoreFragment_3007).getSemanticHint().equals(hint)) {
- return true;
- }
- return false;
- }
-
- /**
- * Command class for updating Interaction Operand EditpPart bounds after CombinedFragment to be resized.
- *
- */
- private static final class UpdateIOBoundsForCFResizeCommand extends
- AbstractTransactionalCommand {
- private final Bounds ioEPOriginalBounds;
- private final ChangeBoundsRequest request;
- private final Dimension sizeDelta;
- private boolean updateHeight = false;
- private int direction;
-
- private UpdateIOBoundsForCFResizeCommand(TransactionalEditingDomain domain,
- String label, Bounds ioEPOriginalBounds,
- ChangeBoundsRequest request, Dimension sizeDelta,
- boolean updateHeight, int direction) {
- super(domain, label, null);
- this.ioEPOriginalBounds = ioEPOriginalBounds;
- this.request = request;
- this.sizeDelta = sizeDelta;
- this.updateHeight = updateHeight;
- this.direction = direction;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor,
- IAdaptable info) throws ExecutionException {
- if (updateHeight) {
- ioEPOriginalBounds.setHeight(ioEPOriginalBounds.getHeight()
- + sizeDelta.height());
- } else if ((direction & PositionConstants.NORTH) != 0) {
- ioEPOriginalBounds.setY(ioEPOriginalBounds.getY()
- + sizeDelta.height());
- }
- if ((request.getResizeDirection() & PositionConstants.EAST_WEST) != 0) {
- ioEPOriginalBounds.setWidth(ioEPOriginalBounds.getWidth()
- + sizeDelta.width());
- }
-
- return CommandResult.newOKCommandResult();
- }
-
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/PreferencesModelElementFactory.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/PreferencesModelElementFactory.java
deleted file mode 100644
index 298a508db92..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/PreferencesModelElementFactory.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-import org.eclipse.papyrus.views.properties.contexts.DataContextElement;
-import org.eclipse.papyrus.views.properties.modelelement.ModelElement;
-import org.eclipse.papyrus.views.properties.modelelement.ModelElementFactory;
-import org.eclipse.papyrus.views.properties.modelelement.PreferencesModelElement;
-
-
-public class PreferencesModelElementFactory implements ModelElementFactory {
-
- public ModelElement createFromSource(Object sourceElement, DataContextElement context) {
- return new PreferencesModelElement(context);
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/ReconnectMessageHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/ReconnectMessageHelper.java
deleted file mode 100644
index 5eeb317ca74..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/ReconnectMessageHelper.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.Gate;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
-import org.eclipse.uml2.uml.InteractionOperatorKind;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.MessageSort;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-
-/**
- * An helper class to reconnect message.
- * TODO : finish the implementation of this class
- */
-public class ReconnectMessageHelper {
-
- /**
- * Update Message :
- * - Update its signature
- *
- * @param message
- */
- public static void updateMessage(Message message) {
- // TODO Auto-generated method stub
-
- }
-
- /**
- * Update the message end :
- *
- * @param messageEnd
- * @param oldElement
- * @param newElement
- */
- public static void updateMessageEnd(MessageEnd messageEnd, Element oldElement, Element newElement) {
- if(messageEnd instanceof MessageOccurrenceSpecification) {
- updateMos((MessageOccurrenceSpecification)messageEnd, oldElement, newElement);
- } else if(messageEnd instanceof Gate) {
- updateGate((Gate)messageEnd, oldElement, newElement);
- }
- }
-
- public static void updateGate(Gate messageEnd, Element oldElement, Element newElement) {
- // TODO Auto-generated method stub
-
- }
-
- public static void updateMos(MessageOccurrenceSpecification messageEnd, Element oldElement, Element newElement) {
- if(newElement instanceof Lifeline && !(oldElement instanceof CombinedFragment && InteractionOperatorKind.PAR_LITERAL.equals(((CombinedFragment)oldElement).getInteractionOperator()))) {
- updateOccurenceSpecification(messageEnd, (Lifeline)newElement);
- } else if(newElement instanceof ExecutionSpecification && !(oldElement instanceof CombinedFragment && InteractionOperatorKind.PAR_LITERAL.equals(((CombinedFragment)oldElement).getInteractionOperator()))) {
- Lifeline lifeline = CommandHelper.getExecutionSpecificationLifeline((ExecutionSpecification)newElement);
- if(lifeline != null) {
- updateOccurenceSpecification(messageEnd, lifeline);
- }
- } else if(newElement instanceof CombinedFragment && InteractionOperatorKind.PAR_LITERAL.equals(((CombinedFragment)newElement).getInteractionOperator())) {
- // handle reorient on coregion
- CombinedFragment cf = (CombinedFragment)newElement;
- InteractionOperand io = CommandHelper.getCoRegionInteractionOperand(cf);
- messageEnd.setEnclosingOperand(io);
-
- // try to find and put in the operand the other mos of the message
- MessageEnd messageEnd2 = findSecondMessageEnd(messageEnd);
-
- if(messageEnd2 instanceof MessageOccurrenceSpecification) {
- ((MessageOccurrenceSpecification)messageEnd2).setEnclosingOperand(io);
- }
- // update interaction operands covered lifelines
- updateCoveredLifelinesOfCoregionOperand(cf);
- } else if(oldElement instanceof CombinedFragment && InteractionOperatorKind.PAR_LITERAL.equals(((CombinedFragment)oldElement).getInteractionOperator())) {
- // handle reorient from coregion
- CombinedFragment cf = (CombinedFragment)oldElement;
- Element backInteraction = cf.getOwner();
-
- SequenceUtil.setEnclosingInteraction(messageEnd, backInteraction, true);
-
- MessageEnd messageEnd2 = findSecondMessageEnd(messageEnd);
- if(messageEnd2 instanceof MessageOccurrenceSpecification) {
- SequenceUtil.setEnclosingInteraction((MessageOccurrenceSpecification)messageEnd2, backInteraction, true);
- }
- // update interaction operands covered lifelines
- updateCoveredLifelinesOfCoregionOperand(cf);
- }
- }
-
- public static MessageEnd findSecondMessageEnd(MessageEnd messageEnd) {
- Message msg = messageEnd.getMessage();
-
- MessageEnd messageEnd2 = null;
- if(msg != null) {
- if(messageEnd.equals(msg.getSendEvent())) {
- messageEnd2 = msg.getReceiveEvent();
- } else {
- messageEnd2 = msg.getSendEvent();
- }
- }
- return messageEnd2;
- }
-
-
- /**
- * OccurrenceSpecification cover a unique lifeline.
- *
- * @param os
- * the occurrence specification to update
- * @param newLifeline
- * the new lifeline covered by the OS
- */
- public static void updateOccurenceSpecification(OccurrenceSpecification os, Lifeline newLifeline) {
-
- // An occurrence specification covers a unique lifeline
- os.getCovereds().clear();
- os.getCovereds().add(newLifeline);
- }
-
- /**
- * Update the list of lifelines covered by the Interaction Operands of a coregion.
- * These are the lifelines covered by all contained Message Occurrence Specifications.
- *
- * @param coregion
- * the coregion to update operands
- */
- public static void updateCoveredLifelinesOfCoregionOperand(CombinedFragment coregion) {
- coregion.getCovereds().clear();
- for(InteractionOperand operand : coregion.getOperands()) {
- operand.getCovereds().clear();
- for(InteractionFragment fragment : operand.getFragments()) {
- if(fragment instanceof MessageOccurrenceSpecification) {
- operand.getCovereds().addAll(fragment.getCovereds());
- coregion.getCovereds().addAll(fragment.getCovereds());
- }
- }
- }
- }
-
- /**
- * It seems that OCL constraints can not hold everything about reconnecting messages.
- *
- * @param message
- * @param newTarget
- */
- public static boolean canReorientTarget(Message message, Element newTarget) {
- if(message == null || newTarget == null) {
- return false;
- }
- MessageSort messageSort = message.getMessageSort();
- if(MessageSort.SYNCH_CALL_LITERAL == messageSort) {
- return newTarget instanceof ExecutionSpecification;
- }
- return true;
- }
-
- public static boolean canReorientSource(Message message, Element newSource) {
- if(message == null || newSource == null) {
- return false;
- }
- MessageSort messageSort = message.getMessageSort();
- if(MessageSort.SYNCH_CALL_LITERAL == messageSort) {
- return newSource instanceof ExecutionSpecification;
- }
- return true;
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectOrCreateDialog.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectOrCreateDialog.java
deleted file mode 100644
index 3d68a6f0024..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SelectOrCreateDialog.java
+++ /dev/null
@@ -1,647 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.viewers.ComboViewer;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.uml.diagram.sequence.part.Messages;
-import org.eclipse.papyrus.uml.diagram.sequence.providers.UMLElementTypes;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-import org.eclipse.ui.forms.FormDialog;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.NamedElement;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Reception;
-import org.eclipse.uml2.uml.Signal;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.UMLFactory;
-
-/**
- * This class provides a generic dialog to select or create an element.
- */
-public class SelectOrCreateDialog extends FormDialog {
-
- private EObject selectedElement = null;
-
- private EClass selectedType = null;
-
- private String selectedName = null;
-
- private EObject selectedParent = null;
-
- private Collection<EObject> existingElements;
-
- private LinkedHashMap<EClass, List<EObject>> mapTypesPossibleParents;
-
- private Button nothingRadio;
-
- private Button selectionRadio;
-
- private Text selectionText;
-
- private Button selectionButton;
-
- private Button creationRadio;
-
- private Text creationNameText;
-
- private ComboViewer typeComboViewer = null;
-
- private Combo creationTypeCombo = null;
-
- private Button creationParentButton;
-
- private Text creationParentText;
-
- private String title;
-
- private ILabelProvider typeLabelProvider;
-
- private ILabelProvider elementLabelProvider;
-
- private final TransactionalEditingDomain transactionalEditingDomain;
-
- private Button filterSignalButton;
-
- private List<Type> types;
-
- /**
- *
- * @param shell
- * parent shell
- * @param title
- * The title of the dialog
- * @param typeLabelProvider
- * The label provider to generate type label
- * @param elementLabelProvider
- * The label provider to generate elements label
- * @param transactionalEditingDomain
- * The domain where to create the element if necessary.
- * @param existingElements
- * The list of existing elements that can be selected.
- * @param mapTypesPossibleParents
- * The map of possible types for the element
- * and the possible parents where the element
- * can be created.
- * @param types
- */
- public SelectOrCreateDialog(Shell shell, String title, ILabelProvider typeLabelProvider, ILabelProvider elementLabelProvider, TransactionalEditingDomain transactionalEditingDomain, Collection<EObject> existingElements, LinkedHashMap<EClass, List<EObject>> mapTypesPossibleParents, List<Type> types) {
- super(shell);
- this.typeLabelProvider = typeLabelProvider;
- this.elementLabelProvider = elementLabelProvider;
- this.existingElements = existingElements;
- this.mapTypesPossibleParents = mapTypesPossibleParents;
- this.title = title;
- this.transactionalEditingDomain = transactionalEditingDomain;
- this.types = types;
- }
-
- /**
- * Adds buttons to this dialog's button bar.
- *
- * @param parent
- * the button bar composite
- */
- @Override
- protected void createButtonsForButtonBar(Composite parent) {
- super.createButtonsForButtonBar(parent);
- refreshOkButton();
- }
-
- /**
- * Create the form to :
- *
- * - ask the user to select or create an element.
- *
- * - decide whether the action is synchronous.
- *
- * @see org.eclipse.ui.forms.FormDialog#createFormContent(org.eclipse.ui.forms.IManagedForm)
- */
- @Override
- protected void createFormContent(IManagedForm pForm) {
- ScrolledForm scrolledForm = pForm.getForm();
- scrolledForm.setText(title);
-
- FormToolkit toolkit = pForm.getToolkit();
- Composite parent = scrolledForm.getBody();
- parent.setLayout(new GridLayout());
-
- // Create the selection section
- createSelectionSection(scrolledForm.getBody(), toolkit);
- // Create the creation section
- createCreationSection(scrolledForm.getBody(), toolkit);
-
-
- // Create the nothing section
- createNothingSection(scrolledForm.getBody(), toolkit);
-
-
- refreshSectionsEnable(selectionRadio);
- hookListeners();
-
- // name is set after listeners, since we count on listener to update it properly
- setName(null);
-
- scrolledForm.reflow(true);
- }
-
- private void createNothingSection(Composite pParent, FormToolkit pToolkit) {
- // create the section
- Section lSection = pToolkit.createSection(pParent, Section.EXPANDED | Section.TITLE_BAR);
- lSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
-
- ScrolledForm lInsideScrolledForm = pToolkit.createScrolledForm(lSection);
- lInsideScrolledForm.setExpandHorizontal(true);
- lInsideScrolledForm.setExpandVertical(true);
- Composite lBody = lInsideScrolledForm.getBody();
-
- lBody.setLayout(new GridLayout(1, false));
-
- // content of the section
- nothingRadio = pToolkit.createButton(lBody, Messages.SelectOrCreateDialog_NothingLabel, SWT.RADIO);
- nothingRadio.setSelection(true);
- nothingRadio.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
-
- lInsideScrolledForm.reflow(true);
- lSection.setClient(lInsideScrolledForm);
- }
-
- /**
- * Create the section to ask the user to select or create an element.
- *
- * @param pParent
- * the section's parent widget
- * @param pToolkit
- * the form toolkit
- */
- private void createSelectionSection(Composite pParent, FormToolkit pToolkit) {
- // create the section
- Section lSection = pToolkit.createSection(pParent, Section.EXPANDED | Section.TITLE_BAR);
- lSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
-
- ScrolledForm lInsideScrolledForm = pToolkit.createScrolledForm(lSection);
- lInsideScrolledForm.setExpandHorizontal(true);
- lInsideScrolledForm.setExpandVertical(true);
- Composite lBody = lInsideScrolledForm.getBody();
-
- lBody.setLayout(new GridLayout(3, false));
-
- // content of the section
- selectionRadio = pToolkit.createButton(lBody, Messages.SelectOrCreateDialog_SelectLabel, SWT.RADIO);
- selectionRadio.setSelection(true);
- selectionRadio.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
-
- selectionText = pToolkit.createText(lBody, "", SWT.BORDER | SWT.READ_ONLY); //$NON-NLS-1$
- selectionText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- selectionButton = pToolkit.createButton(lBody, "...", SWT.FLAT); //$NON-NLS-1$
-
- // find the first non null eobject and use its associated image
- if(existingElements != null) {
- Iterator<EObject> it = existingElements.iterator();
- while(it.hasNext()) {
- EObject next = it.next();
- if(next != null) {
- selectionButton.setImage(UMLElementTypes.getImage(next.eClass()));
- break;
- }
- }
- }
-
- selectionButton.setLayoutData(new GridData(SWT.NONE));
-
- filterSignalButton = pToolkit.createButton(lBody, "filter out all signals which are not receivable", SWT.CHECK);
-
- lInsideScrolledForm.reflow(true);
- lSection.setClient(lInsideScrolledForm);
- }
-
- /**
- * Create the section to ask the user to select or create an element.
- *
- * @param pParent
- * the section's parent widget
- * @param pToolkit
- * the form toolkit
- */
- private void createCreationSection(Composite pParent, FormToolkit pToolkit) {
- // create the section
- Section lSection = pToolkit.createSection(pParent, Section.EXPANDED | Section.TITLE_BAR);
- lSection.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
-
- ScrolledForm lInsideScrolledForm = pToolkit.createScrolledForm(lSection);
- lInsideScrolledForm.setExpandHorizontal(true);
- lInsideScrolledForm.setExpandVertical(true);
- Composite lBody = lInsideScrolledForm.getBody();
-
- lBody.setLayout(new GridLayout(3, false));
-
- // content of the section
- creationRadio = pToolkit.createButton(lBody, Messages.SelectOrCreateDialog_CreateLabel, SWT.RADIO);
- creationRadio.setSelection(false);
- creationRadio.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
-
- EClass defaultType = null;
- Set<EClass> possibleTypes = mapTypesPossibleParents.keySet();
-
- // only create the type selection buttons if more than one type
- // is possible
- if(possibleTypes.size() == 1) {
- defaultType = (EClass)possibleTypes.toArray()[0];
- } else {
- pToolkit.createLabel(lBody, Messages.SelectOrCreateDialog_TypeLabel, SWT.NONE);
- creationTypeCombo = new Combo(lBody, SWT.DROP_DOWN | SWT.READ_ONLY);
- typeComboViewer = new ComboViewer(creationTypeCombo);
- pToolkit.adapt(creationTypeCombo);
- creationTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
- typeComboViewer.setLabelProvider(typeLabelProvider);
- typeComboViewer.add(possibleTypes.toArray());
- if(possibleTypes.size() > 1) {
- // initialize selection
- defaultType = (EClass)possibleTypes.toArray()[0];
- typeComboViewer.setSelection(new StructuredSelection(defaultType));
- }
- }
-
- pToolkit.createLabel(lBody, Messages.SelectOrCreateDialog_NameLabel, SWT.NONE);
- creationNameText = pToolkit.createText(lBody, "", SWT.BORDER); //$NON-NLS-1$
- creationNameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
-
- pToolkit.createLabel(lBody, Messages.SelectOrCreateDialog_OwnerLabel + ":", SWT.NONE); //$NON-NLS-1$
- creationParentText = pToolkit.createText(lBody, elementLabelProvider.getText(selectedParent), SWT.BORDER | SWT.READ_ONLY);
- creationParentText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
- creationParentButton = pToolkit.createButton(lBody, "...", SWT.FLAT); //$NON-NLS-1$
- creationParentButton.setLayoutData(new GridData(SWT.NONE));
-
- setType(defaultType);
-
- lInsideScrolledForm.reflow(true);
- lSection.setClient(lInsideScrolledForm);
- }
-
- /**
- * Add listeners to widgets
- */
- private void hookListeners() {
- // listener to choose active section
- SelectionListener radioListener = new SelectionAdapter() {
-
- /**
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
- refreshSectionsEnable(e.getSource());
- refreshOkButton();
- }
- };
- selectionRadio.addSelectionListener(radioListener);
- creationRadio.addSelectionListener(radioListener);
- nothingRadio.addSelectionListener(radioListener);
-
- // listener to select existing element
- SelectionListener selectBtnListener = new SelectionAdapter() {
-
- /**
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleSelectElement();
- }
- };
- selectionButton.addSelectionListener(selectBtnListener);
-
- if(creationTypeCombo != null && typeComboViewer != null) {
- // listener to select invocation type
- ModifyListener lTypeListener = new ModifyListener() {
-
- /**
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void modifyText(ModifyEvent e) {
- ISelection sel = typeComboViewer.getSelection();
- if(sel instanceof StructuredSelection) {
- Object type = ((StructuredSelection)sel).getFirstElement();
- if(type instanceof EClass) {
- setType((EClass)type);
- } else {
- setType(null);
- }
- // reset name
- setName(null);
- }
- }
- };
- creationTypeCombo.addModifyListener(lTypeListener);
- }
-
- // listener to invocation element name
- ModifyListener lNameListener = new ModifyListener() {
-
- /**
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void modifyText(ModifyEvent e) {
- selectedName = creationNameText.getText();
- refreshOkButton();
- }
- };
- creationNameText.addModifyListener(lNameListener);
-
- // listener to select new element parent
- SelectionListener selectParentBtnListener = new SelectionAdapter() {
-
- /**
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- @Override
- public void widgetSelected(SelectionEvent e) {
- handleSelectParent();
- }
- };
- creationParentButton.addSelectionListener(selectParentBtnListener);
- }
-
- /**
- * Refresh the OK button activation
- */
- private void refreshOkButton() {
- Button okButton = getButton(IDialogConstants.OK_ID);
- if(okButton != null && !okButton.isDisposed()) {
- if(selectionRadio.getSelection()) {
- okButton.setEnabled(selectedElement != null);
- } else if(nothingRadio.getSelection()) {
- okButton.setEnabled(true);
- } else {
- okButton.setEnabled(selectedType != null && selectedParent != null && selectedName != null && !"".equals(selectedName)); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * Add the created element to its selected parent
- */
- protected void addElementInParent(EObject selectedParent, EObject createdElement) {
- // Let the command find the relation on its own.
- Command addCmd = AddCommand.create(transactionalEditingDomain, selectedParent, null, Collections.singleton(createdElement));
- if(addCmd.canExecute()) {
- addCmd.execute();
- }
- }
-
- /**
- * Set correctly the element, by creating it if needed.
- * Then, notifies that the ok button of this dialog has been pressed.
- *
- * @see org.eclipse.jface.dialogs.Dialog#okPressed()
- *
- */
- @Override
- protected void okPressed() {
- // create element if needed
- if(creationRadio.getSelection()) {
- selectedElement = UMLFactory.eINSTANCE.create(selectedType);
- if(selectedElement instanceof NamedElement) {
- ((NamedElement)selectedElement).setName(selectedName);
- }
- addElementInParent(selectedParent, selectedElement);
- } else if(nothingRadio.getSelection()) {
- selectedElement = null;
- }
- super.okPressed();
- }
-
- /**
- * Open the dialog to choose the existing element to select
- *
- */
- private void handleSelectElement() {
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), elementLabelProvider);
- dialog.setMessage(Messages.SelectOrCreateDialog_SelectLabel);
- dialog.setMultipleSelection(false);
- dialog.setElements(filterElements(existingElements));
- if(dialog.open() == Window.OK) {
- setElementSelection((EObject)dialog.getFirstResult());
- }
- }
-
- private Set<Signal> getAllSignals(List<Type> types){
- Set<Signal> accept = new HashSet<Signal>();
- Set<Classifier> collected = new HashSet<Classifier>();
- for(Type t: types)
- if(t instanceof Classifier){
- Classifier c = (Classifier)t;
- collectSignals(c, accept, collected);
- }
-
- return accept;
- }
-
- protected void collectSignals(Classifier c, Set<Signal> accept, Set<Classifier> collected) {
- if(collected.contains(c))
- return;
- collected.add(c);
- if(c instanceof org.eclipse.uml2.uml.Class){
- EList<Reception> receptions = ((org.eclipse.uml2.uml.Class)c).getOwnedReceptions();
- for(Reception r : receptions)
- accept.add(r.getSignal());
- }
-
- EList<Property> attrs = c.getAllAttributes();
- for(Property p : attrs)
- if(p.getType() instanceof Signal){
- accept.add((Signal)p.getType());
- }else if(p.getType() instanceof Classifier){
- collectSignals((Classifier)p.getType(), accept, collected);
- }
- }
-
- private Object[] filterElements(Collection<EObject> elements) {
- if(!filterSignalButton.getSelection() || types == null || types.isEmpty())
- return elements.toArray(new EObject[elements.size()]);
-
- Set<Signal> accept = getAllSignals(types);
-
- List<EObject> result = new ArrayList<EObject>();
- for(EObject o:elements)
- if(!(o instanceof Signal))
- result.add(o);
- else if( accept.contains(o))
- result.add(o);
- return result.toArray(new EObject[result.size()]);
- }
-
- /**
- * Open the dialog to choose the parent of element to create
- *
- */
- private void handleSelectParent() {
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), elementLabelProvider);
- dialog.setMessage(Messages.SelectOrCreateDialog_OwnerLabel);
- dialog.setMultipleSelection(false);
- List<EObject> possibleParents = mapTypesPossibleParents.get(selectedType);
- if(possibleParents != null) {
- dialog.setElements(possibleParents.toArray());
- }
- if(dialog.open() == Window.OK) {
- setParent((EObject)dialog.getFirstResult());
- }
- }
-
- /**
- * Define the object in which element will be created (if creation mode is chosen)
- *
- * @param parent
- * the selected parent
- */
- private void setParent(EObject parent) {
- selectedParent = parent;
- if(selectedParent instanceof NamedElement) {
- creationParentText.setText(elementLabelProvider.getText(selectedParent));
- creationParentButton.setImage(UMLElementTypes.getImage(parent.eClass()));
- } else {
- creationParentText.setText(""); //$NON-NLS-1$
- }
- refreshOkButton();
- }
-
- /**
- * Define the name of the object that will be created by the action
- *
- * @param name
- * the name of the element
- */
- private void setName(String name) {
- selectedName = name;
- if(name != null) {
- creationNameText.setText(name);
- } else {
- creationNameText.setText(""); //$NON-NLS-1$
- }
- refreshOkButton();
- }
-
- /**
- * Define the type of the object that will be created by the action
- *
- * @param type
- * the type of the element
- */
- private void setType(EClass type) {
- selectedType = type;
- List<EObject> possibleParents = mapTypesPossibleParents.get(type);
- if(possibleParents != null && possibleParents.size() > 0) {
- setParent(possibleParents.get(0));
- } else {
- setParent(null);
- }
- refreshOkButton();
- }
-
- /**
- * Define the object that will be returned by the action (if selection mode is chosen)
- *
- * @param element
- * the selected element
- */
- private void setElementSelection(EObject element) {
- selectedElement = element;
- if(selectedElement instanceof NamedElement) {
- selectionText.setText(elementLabelProvider.getText(selectedElement));
- } else {
- selectionText.setText(""); //$NON-NLS-1$
- }
- refreshOkButton();
- }
-
- /**
- * Refresh the enabled and disabled elements in various sections
- *
- */
- private void refreshSectionsEnable(Object radioObject) {
- boolean nothingSelected = false;
- boolean selectionSelected = false;
- boolean creationSelected = false;
- if(selectionRadio.equals(radioObject)) {
- selectionSelected = true;
- } else if(creationRadio.equals(radioObject)) {
- creationSelected = true;
- } else {
- nothingSelected = true;
- }
-
- // Selection widgets
- selectionRadio.setSelection(selectionSelected);
- selectionText.setEnabled(selectionSelected);
- selectionButton.setEnabled(selectionSelected);
-
- // Creation widgets
- creationRadio.setSelection(creationSelected);
- if(creationTypeCombo != null) {
- creationTypeCombo.setEnabled(creationSelected);
- }
- creationNameText.setEnabled(creationSelected);
- creationParentText.setEnabled(creationSelected);
- creationParentButton.setEnabled(creationSelected);
-
- // Nothing widgets
- nothingRadio.setSelection(nothingSelected);
- }
-
- /**
- * Get the object that have been selected or created.
- *
- * @return the object to use.
- */
- public EObject getSelected() {
- return selectedElement;
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceDeleteHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceDeleteHelper.java
deleted file mode 100644
index 11be8bbe97e..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceDeleteHelper.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.DestroyElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ObservationLinkEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.TimeObservationLabelEditPart;
-import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-import org.eclipse.uml2.uml.TimeObservation;
-
-/**
- * An Helper to get deleting command for the sequence diagram elements.
- */
-
-public class SequenceDeleteHelper {
-
- /**
- * Complete an ICommand which destroys an DestructionEvent element to also destroy dependent time/duration constraint/observation linked with
- * these ends
- *
- * @param deleteViewsCmd
- * the command to complete
- * @param editingDomain
- * the editing domain
- * @param destructionEventPart
- * the execution specification edit part on which the request is called
- * @return the deletion command deleteViewsCmd for convenience
- */
- public static CompoundCommand completeDeleteDestructionOccurenceViewCommand(CompoundCommand deleteViewsCmd, TransactionalEditingDomain editingDomain, EditPart destructionEventPart) {
- if(destructionEventPart instanceof IGraphicalEditPart) {
- EObject obj = ((IGraphicalEditPart)destructionEventPart).resolveSemanticElement();
-
- if(obj instanceof DestructionOccurrenceSpecification) {
- LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(destructionEventPart);
- if(lifelinePart != null) {
- for(Object lifelineChild : lifelinePart.getChildren()) {
- if(lifelineChild instanceof IBorderItemEditPart) {
- final IBorderItemEditPart timePart = (IBorderItemEditPart)lifelineChild;
- //At most one destruction event. Only parts linked to it can not move for now.
- boolean isNotLinked = OccurrenceSpecificationMoveHelper.canTimeElementPartBeYMoved(timePart);
- if(!isNotLinked) {
- // time part is linked, delete the view
- Command deleteTimeViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View)timePart.getModel()));
- deleteViewsCmd.add(deleteTimeViewCommand);
- }
- }
- }
- }
- }
- }
- return deleteViewsCmd;
- }
-
- /**
- * Complete an ICommand which destroys an ExecutionSpecification element to also destroy dependent finish and start events and time/duration
- * constraint/observation linked with these ends
- *
- * @param deleteViewsCmd
- * the command to complete
- * @param editingDomain
- * the editing domain
- * @param executionPart
- * the execution specification edit part on which the request is called
- * @return the deletion command deleteViewsCmd for convenience
- */
- public static CompoundCommand completeDeleteMessageViewCommand(CompoundCommand deleteViewsCmd, TransactionalEditingDomain editingDomain, EditPart messagePart) {
- if(messagePart instanceof IGraphicalEditPart) {
- EObject obj = ((IGraphicalEditPart)messagePart).resolveSemanticElement();
- if(obj instanceof Message) {
- Message message = (Message)obj;
- LifelineEditPart srcLifelinePart = SequenceUtil.getParentLifelinePart(((ConnectionNodeEditPart)messagePart).getSource());
- MessageEnd send = message.getSendEvent();
- addDeleteRelatedTimePartsToCommand(deleteViewsCmd, editingDomain, srcLifelinePart, send);
-
- LifelineEditPart tgtLifelinePart = SequenceUtil.getParentLifelinePart(((ConnectionNodeEditPart)messagePart).getTarget());
- MessageEnd receive = message.getReceiveEvent();
- addDeleteRelatedTimePartsToCommand(deleteViewsCmd, editingDomain, tgtLifelinePart, receive);
-
- // also delete time observation links which are related to message end
- if (send instanceof OccurrenceSpecification) {
- addDeleteRelatedTimeObservationLinkCommand(deleteViewsCmd, editingDomain,(OccurrenceSpecification) send, srcLifelinePart,false);
- }
- if (receive instanceof OccurrenceSpecification) {
- addDeleteRelatedTimeObservationLinkCommand(deleteViewsCmd, editingDomain,(OccurrenceSpecification) receive, tgtLifelinePart,false);
- }
- }
- }
- return deleteViewsCmd;
- }
-
- private static void addDeleteRelatedTimePartsToCommand(CompoundCommand deleteViewsCmd, TransactionalEditingDomain editingDomain, LifelineEditPart lifelineEP, MessageEnd messageEnd) {
- if(lifelineEP != null && messageEnd instanceof OccurrenceSpecification) {
- for(Object lifelineChild : lifelineEP.getChildren()) {
- if(lifelineChild instanceof IBorderItemEditPart) {
- final IBorderItemEditPart timePart = (IBorderItemEditPart)lifelineChild;
- int positionForEvent = SequenceUtil.positionWhereEventIsLinkedToPart((OccurrenceSpecification)messageEnd, timePart);
- if(positionForEvent != PositionConstants.NONE) {
- // time part is linked, delete the view
- Command deleteTimeViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View)timePart.getModel()));
- deleteViewsCmd.add(deleteTimeViewCommand);
- }
- }
- }
- }
- }
-
- /**
- * Complete an ICommand which destroys an ExecutionSpecification element to also destroy dependent finish and start events and time/duration
- * constraint/observation linked with these ends
- *
- * @param deleteViewsCmd
- * the command to complete
- * @param editingDomain
- * the editing domain
- * @param executionPart
- * the execution specification edit part on which the request is called
- * @return the deletion command deleteViewsCmd for convenience
- */
- public static CompoundCommand completeDeleteExecutionSpecificationViewCommand(CompoundCommand deleteViewsCmd, TransactionalEditingDomain editingDomain, EditPart executionPart) {
- if(executionPart instanceof IGraphicalEditPart) {
- EObject obj = ((IGraphicalEditPart)executionPart).resolveSemanticElement();
-
- if(obj instanceof ExecutionSpecification) {
- ExecutionSpecification execution = (ExecutionSpecification)obj;
- LifelineEditPart lifelinePart = SequenceUtil.getParentLifelinePart(executionPart);
- if(lifelinePart != null) {
- for(Object lifelineChild : lifelinePart.getChildren()) {
- if(lifelineChild instanceof IBorderItemEditPart) {
- final IBorderItemEditPart timePart = (IBorderItemEditPart)lifelineChild;
- OccurrenceSpecification start = execution.getStart();
- OccurrenceSpecification finish = execution.getStart();
- int positionForStart = SequenceUtil.positionWhereEventIsLinkedToPart(start, timePart);
- int positionForFinish = SequenceUtil.positionWhereEventIsLinkedToPart(finish, timePart);
- if(positionForStart != PositionConstants.NONE || positionForFinish != PositionConstants.NONE) {
- // time part is linked, delete the view
- Command deleteTimeViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View)timePart.getModel()));
- deleteViewsCmd.add(deleteTimeViewCommand);
- }
- }
- }
-
- // delete each observation linked time element
- for(Object targetConnection : lifelinePart.getTargetConnections()){
- if(targetConnection instanceof ObservationLinkEditPart){
- ObservationLinkEditPart observationLinkEditPart = (ObservationLinkEditPart)targetConnection;
- TimeObservationLabelEditPart source = (TimeObservationLabelEditPart)observationLinkEditPart.getSource();
- OccurrenceSpecification start = execution.getStart();
- OccurrenceSpecification finish = execution.getFinish();
- int positionForStart = SequenceUtil.positionWhereEventIsLinkedToPart(start, source);
- int positionForFinish = SequenceUtil.positionWhereEventIsLinkedToPart(finish, source);
- if(positionForStart != PositionConstants.NONE) {
- // time part is linked, delete the view
- //Command deleteTimeViewCommand = new ICommandProxy(new DeleteCommand(editingDomain, (View)source.getModel()));
- //deleteViewsCmd.add(deleteTimeViewCommand);
- addDeleteRelatedTimeObservationLinkCommand(deleteViewsCmd,
- editingDomain, start, lifelinePart,false);
- }
- if(positionForFinish != PositionConstants.NONE) {
- addDeleteRelatedTimeObservationLinkCommand(deleteViewsCmd,
- editingDomain, finish, lifelinePart,false);
- }
- }
- }
- }
- }
- }
- return deleteViewsCmd;
- }
-
- /**
- * Delete the views associated with a list of elements.
- *
- * @param cmd
- * the CompositeTransactionalCommand
- * @param element
- * the list of model elements
- * @param editingDomain
- * the editing domain to use.
- */
- public static void deleteView(CompositeTransactionalCommand cmd, List<Element> elements, TransactionalEditingDomain editingDomain) {
- for(Element element : elements) {
- deleteView(cmd, element, editingDomain);
- }
- }
-
- /**
- * Delete the views associated with an element.
- *
- * @param cmd
- * the CompositeTransactionalCommand
- * @param element
- * the model element referenced by the views
- * @param editingDomain
- * the editing domain to use.
- */
- public static void deleteView(CompositeTransactionalCommand cmd, Element element, TransactionalEditingDomain editingDomain) {
- // Destroy its views
- @SuppressWarnings("rawtypes")
- List views = DiagramEditPartsUtil.getEObjectViews(element);
- for(Object object : views) {
- if(object instanceof View) {
- cmd.add(new DeleteCommand(editingDomain, (View)object));
- }
- }
- }
-
- /**
- * Add complete delete message command
- * @param req
- * @param editPart
- * @return Command
- */
- public static Command completeDeleteMessageCommand(DestroyElementRequest req,EditPart editPart) {
- EObject selectedEObject = req.getElementToDestroy();
- IElementEditService provider = ElementEditServiceUtils
- .getCommandProvider(selectedEObject);
- if (provider != null) {
- // Retrieve delete command from the Element Edit service
- ICommand deleteCommand = provider.getEditCommand(req);
- if (deleteCommand != null) {
- CompositeCommand command = new CompositeCommand(
- deleteCommand.getLabel());
- command.add(deleteCommand);
- Message message = (Message) selectedEObject;
- MessageEnd receiveEvent = message.getReceiveEvent();
- if (receiveEvent != null) {
- DestroyElementRequest myReq = new DestroyElementRequest(
- req.getEditingDomain(), receiveEvent, false);
- command.add(new DestroyElementCommand(myReq));
- }
- MessageEnd sendEvent = message.getSendEvent();
- if (sendEvent != null) {
- DestroyElementRequest myReq = new DestroyElementRequest(
- req.getEditingDomain(), sendEvent, false);
- command.add(new DestroyElementCommand(myReq));
- }
-
- addDeleteMessageRelatedTimeObservationLinkCommand(req.getEditingDomain(), editPart, command,
- receiveEvent,true);
- addDeleteMessageRelatedTimeObservationLinkCommand(req.getEditingDomain(), editPart, command,
- sendEvent,true);
-
- return new ICommandProxy(command);
- }
- }
-
- return UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Add delete message related time observation link command
- * @param editingDomain
- * @param editPart
- * @param command
- * @param messageEnd
- * @param deleteRelatedEvent
- */
- public static void addDeleteMessageRelatedTimeObservationLinkCommand(
- TransactionalEditingDomain editingDomain, EditPart editPart,
- CompositeCommand command, MessageEnd messageEnd,boolean deleteRelatedEvent) {
- //Bug fix: messageEnd maybe a Gate instance.
- if(messageEnd != null && messageEnd instanceof OccurrenceSpecification){
- OccurrenceSpecification occurrenceSpecification = (OccurrenceSpecification) messageEnd;
- EList<Lifeline> receiveCovereds = occurrenceSpecification.getCovereds();
- CompoundCommand CompoundCommand = new CompoundCommand();
- CompoundCommand.add(new ICommandProxy(command));
- LifelineEditPart srcLifelinePart = (LifelineEditPart) SequenceUtil.getEditPart(editPart,receiveCovereds.get(0), LifelineEditPart.class);
- addDeleteRelatedTimeObservationLinkCommand(CompoundCommand, editingDomain, occurrenceSpecification, srcLifelinePart,deleteRelatedEvent);
- }
- }
-
- /**
- * Add command for deleting time observation link which related to occurence specification
- * @param deleteViewsCmd
- * @param editingDomain
- * @param os
- * @param srcLifelinePart
- * @param deleteRelatedEvent
- */
- private static void addDeleteRelatedTimeObservationLinkCommand(
- CompoundCommand deleteViewsCmd,
- TransactionalEditingDomain editingDomain, OccurrenceSpecification os,
- LifelineEditPart srcLifelinePart,boolean deleteRelatedEvent) {
- List<OccurrenceSpecification> oss = new ArrayList<OccurrenceSpecification>();
- oss.add(os);
- addDeleteRelatedTimeObservationLinkCommand(deleteViewsCmd, editingDomain,srcLifelinePart, oss,deleteRelatedEvent);
- }
-
- /**
- * Add command for deleting time observation link which related to occurence specification
- * @param deleteViewsCmd
- * @param editingDomain
- * @param srcLifelinePart
- * @param oss
- * @param deleteRelatedEvent
- */
- public static void addDeleteRelatedTimeObservationLinkCommand(
- CompoundCommand deleteViewsCmd,
- TransactionalEditingDomain editingDomain,LifelineEditPart srcLifelinePart,List<OccurrenceSpecification> oss,boolean deleteRelatedEvent) {
- List<TimeObservationLabelEditPart> timeObservationEditParts = SequenceUtil.findOccurenceSpecificationRelatedTimeObservationPart(srcLifelinePart,oss);
- for (final TimeObservationLabelEditPart timeObservationEditPart : timeObservationEditParts) {
- View view = (View) timeObservationEditPart.getModel();
- EList sourceEdges = view.getSourceEdges();
- for (Object sourceEdge : sourceEdges) {
- Command deleteTimeViewCommand = new ICommandProxy(
- new DeleteCommand(editingDomain, (View) sourceEdge));
- deleteViewsCmd.add(deleteTimeViewCommand);
- }
- if(deleteRelatedEvent){
- deleteViewsCmd.add(new ICommandProxy(new AbstractTransactionalCommand(editingDomain,"Remove TimeObservation related event",null){
- @Override
- protected CommandResult doExecuteWithResult(
- IProgressMonitor monitor, IAdaptable info)
- throws ExecutionException {
- TimeObservation timeObservation = (TimeObservation)(timeObservationEditPart.resolveSemanticElement());
- timeObservation.setEvent(null);
- return CommandResult.newOKCommandResult();
- }
- }));
- }
- }
- }
-
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceLinkMappingHelper.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceLinkMappingHelper.java
deleted file mode 100644
index 0e239e232aa..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceLinkMappingHelper.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-
-import org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper;
-import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper;
-import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonSourceUMLSwitch;
-import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper.CommonTargetUMLSwitch;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.Gate;
-import org.eclipse.uml2.uml.GeneralOrdering;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-
-/**
- * A link mapping helper used for dNd.
- *
- * See {@link CustomDiagramDragDropEditPolicy}
- */
-public class SequenceLinkMappingHelper implements ILinkMappingHelper {
-
- /**
- * SingletonHolder is loaded at the first execution of getInstance() method
- */
- private static class SingletonHolder {
-
- private final static SequenceLinkMappingHelper instance = new SequenceLinkMappingHelper();
- }
-
- /**
- * Gets the single instance of ClassLinkMappingHelper.
- *
- * @return single instance of ClassLinkMappingHelper
- */
- public static SequenceLinkMappingHelper getInstance() {
- return SingletonHolder.instance;
- }
-
- /**
- * private constructor
- */
- private SequenceLinkMappingHelper() {
- // do nothing
- }
-
- /**
- * {@inheritDoc}
- */
- public Collection<?> getSource(Element link) {
- return LinkMappingHelper.getSource(link, new CommonSourceUMLSwitch() {
-
- public java.util.Collection<?> caseMessage(org.eclipse.uml2.uml.Message object) {
- if(object.getSendEvent() != null) {
- MessageEnd messageEnd = object.getSendEvent();
- if(messageEnd instanceof MessageOccurrenceSpecification) {
- return ((MessageOccurrenceSpecification)messageEnd).getCovereds();
- } else if(messageEnd instanceof Gate) {
- ArrayList<Element> sources = new ArrayList<Element>();
- sources.add(((Gate)messageEnd).getOwner());
- return sources;
- }
- } else {
- return Collections.singletonList(object.getInteraction());
- }
- return Collections.EMPTY_LIST;
- };
-
- public Collection<?> caseGeneralOrdering(GeneralOrdering object) {
- if(object.getBefore() != null) {
- OccurrenceSpecification before = object.getBefore();
- return before.getCovereds();
- }
- return Collections.EMPTY_LIST;
- }
- });
- }
-
- /**
- * {@inheritDoc}
- */
- public Collection<?> getTarget(Element link) {
- return LinkMappingHelper.getTarget(link, new CommonTargetUMLSwitch() {
-
- public java.util.Collection<?> caseMessage(org.eclipse.uml2.uml.Message object) {
- if(object.getReceiveEvent() != null) {
- MessageEnd messageEnd = (MessageEnd)object.getReceiveEvent();
- if(messageEnd instanceof MessageOccurrenceSpecification) {
- return ((MessageOccurrenceSpecification)messageEnd).getCovereds();
- } else if(messageEnd instanceof Gate) {
- ArrayList<Element> sources = new ArrayList<Element>();
- sources.add(((Gate)messageEnd).getOwner());
- return sources;
- }
- } else {
- return Collections.singletonList(object.getInteraction());
- }
- return Collections.EMPTY_LIST;
- };
-
- public Collection<?> caseGeneralOrdering(GeneralOrdering object) {
- if(object.getAfter() != null) {
- OccurrenceSpecification after = object.getAfter();
- return after.getCovereds();
- }
- return Collections.EMPTY_LIST;
- }
-
- });
- }
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceRequestConstant.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceRequestConstant.java
deleted file mode 100644
index 52fa63e7408..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceRequestConstant.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-/**
- * Constants used in the sequence diagram
- */
-public interface SequenceRequestConstant {
-
- /** A constant representing the container of an interactionFragment. It can be an Interaction or an InteractionOperand */
- public static final String INTERACTIONFRAGMENT_CONTAINER = "InteractionFragment Container"; //$NON-NLS-1$
-
- /** key for a set of covered InteractionFragment which needs to be moved inside a new container. */
- public static final String COVERED_INTERACTIONFRAGMENTS = "Covered InteractionFragments"; //$NON-NLS-1$
-
- public static final String SOURCE_MODEL_CONTAINER = "Source model container"; //$NON-NLS-1$
-
- public static final String TARGET_MODEL_CONTAINER = "Target model container"; //$NON-NLS-1$
-
- /** A key used in the creation of a CORegion to identify the lifeline graphically containing the CoRegion */
- public static final String LIFELINE_GRAPHICAL_CONTAINER = "Lifeline graphical container"; //$NON-NLS-1$
-
- /** The occurrence specification(s) which are the nearest from a creation request */
- public static final String NEAREST_OCCURRENCE_SPECIFICATION = "Nearest occurrence specification"; //$NON-NLS-1$
-
- /** The location of the occurrence specification which is the nearest from a creation request */
- public static final String OCCURRENCE_SPECIFICATION_LOCATION = "Nearest occurrence specification location"; //$NON-NLS-1$
-
- /** The occurrence specification(s) which are the nearest from a creation request (2nd end of creation) */
- public static final String NEAREST_OCCURRENCE_SPECIFICATION_2 = "Nearest occurrence specification (end)"; //$NON-NLS-1$
-
- /** The location of the occurrence specification which is the nearest from a creation request (2nd end of creation) */
- public static final String OCCURRENCE_SPECIFICATION_LOCATION_2 = "Nearest occurrence specification location (end)"; //$NON-NLS-1$
-
- /** Tag signifying that the edit parts must not be moved when an occurrence specification is moved (to avoid loop in chain effects) */
- public static final String DO_NOT_MOVE_EDIT_PARTS = "Do not move these edit parts"; //$NON-NLS-1$
-
- /** The location of the connection start creation request */
- public static final String SOURCE_LOCATION_DATA = "Location of connection source point"; //$NON-NLS-1$
-
- /** update connectable element reference */
- public static final String CONNECTABLE_ELEMENT = "Connectable Element"; //$NON-NLS-1$
-}
diff --git a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java b/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java
deleted file mode 100644
index 734e61a2ac8..00000000000
--- a/deprecated/org.eclipse.papyrus.uml.diagram.sequence_initial-kepler/custom-src/org/eclipse/papyrus/uml/diagram/sequence/util/SequenceUtil.java
+++ /dev/null
@@ -1,1713 +0,0 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- * Camille Letavernier (camille.letavernier@cea.fr) - Loosen the MessageSortChange restriction
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.sequence.util;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.AbstractPointListShape;
-import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-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.ConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.Anchor;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
-import org.eclipse.gmf.runtime.notation.LayoutConstraint;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.papyrus.uml.diagram.common.helper.DurationConstraintHelper;
-import org.eclipse.papyrus.uml.diagram.common.helper.InteractionFragmentHelper;
-import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ActionExecutionSpecificationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.BehaviorExecutionSpecificationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragment2EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.CombinedFragmentEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ContinuationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DestructionOccurrenceSpecificationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.DurationObservationEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionOperandEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.InteractionUseEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.LifelineEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message2EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message3EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message4EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message5EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message6EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.Message7EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageAsyncAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageCreateAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageDeleteAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageFoundAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageLostAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName2EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName3EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName4EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName5EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName6EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageName7EditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageNameEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageReplyAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.MessageSyncAppliedStereotypeEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.ObservationLinkEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.StateInvariantEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.parts.TimeObservationLabelEditPart;
-import org.eclipse.papyrus.uml.diagram.sequence.edit.policies.ObservationLinkPolicy;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.common.util.CacheAdapter;
-import org.eclipse.uml2.uml.CombinedFragment;
-import org.eclipse.uml2.uml.Continuation;
-import org.eclipse.uml2.uml.DestructionOccurrenceSpecification;
-import org.eclipse.uml2.uml.DurationConstraint;
-import org.eclipse.uml2.uml.Element;
-import org.eclipse.uml2.uml.ExecutionOccurrenceSpecification;
-import org.eclipse.uml2.uml.ExecutionSpecification;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.InteractionFragment;
-import org.eclipse.uml2.uml.InteractionOperand;
-import org.eclipse.uml2.uml.InteractionOperatorKind;
-import org.eclipse.uml2.uml.InteractionUse;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Message;
-import org.eclipse.uml2.uml.MessageEnd;
-import org.eclipse.uml2.uml.MessageOccurrenceSpecification;
-import org.eclipse.uml2.uml.MessageSort;
-import org.eclipse.uml2.uml.OccurrenceSpecification;
-import org.eclipse.uml2.uml.StateInvariant;
-import org.eclipse.uml2.uml.TimeConstraint;
-import org.eclipse.uml2.uml.TimeObservation;
-import org.eclipse.uml2.uml.UMLPackage;
-
-
-public class SequenceUtil {
-
- private static final double MAXIMAL_DISTANCE_FROM_EVENT = 10;
-
- /**
- * Request type of observation link
- */
- public static final String OBSERVATION_LINK_TYPE = "observation link"; //$NON-NLS-1$
-
- public static final String OBSERVATION_LINK_REQUEST_START = "observation connection start"; //$NON-NLS-1$
-
- public static final String OBSERVATION_LINK_REQUEST_END = "observation connection end"; //$NON-NLS-1$
-
- public static final String OBSERVATION_LINK_REQUEST_RECONNECT_SOURCE = "observation reconnect source"; //$NON-NLS-1$
-
- public static final String OBSERVATION_LINK_REQUEST_RECONNECT_TARGET = "observation reconnect target"; //$NON-NLS-1$
-
- /**
- * Default vertical offset of lifeline
- */
- public static final int LIFELINE_VERTICAL_OFFSET = 10;
-
- /**
- * Title for dialog of block message sort modification error
- */
- private static final String BLOCK_SORT_MODIFICATION_TITLE = "Forbidden action"; //$NON-NLS-1$
-
- /**
- * Message for dialog of block message sort modification error
- */
- private static final String BLOCK_SORT_MODIFICATION_MSG = "It's impossible to change the message sort."; //$NON-NLS-1$
-
- /**
- * Find the container interaction fragment at the given location.
- * The elements are drawn under the lifeline, but their model container is an interaction.
- * It can be of type Interaction or InteractionOperand.
- *
- * @param location
- * the location
- * @return the interaction or null
- */
- public static InteractionFragment findInteractionFragmentContainerAt(Point location, EditPart hostEditPart) {
- Rectangle bounds = new Rectangle();
- bounds.setLocation(location);
- return findInteractionFragmentContainerAt(bounds, hostEditPart);
- }
-
- /**
- * Find the container interaction fragment for the given bounds.
- * The elements are drawn under the lifeline, but their model container is an interaction.
- * It can be of type Interaction or InteractionOperand.
- *
- * @param bounds
- * the bounds
- * @param hostEditPart
- * any adit part in the corresponding diagram
- * @return the interaction or null
- */
- @SuppressWarnings("unchecked")
- public static InteractionFragment findInteractionFragmentContainerAt(Rectangle bounds, EditPart hostEditPart) {
-
- if(hostEditPart == null) {
- return null;
- }
-
- InteractionFragment container = null;
- Set<InteractionFragment> coveredInteractions = new HashSet<InteractionFragment>();
- Set<CombinedFragment> coveredCF = new HashSet<CombinedFragment>();
-
- Set<Entry<Object, EditPart>> allEditPartEntries = hostEditPart.getViewer().getEditPartRegistry().entrySet();
- for(Entry<Object, EditPart> epEntry : allEditPartEntries) {
- EditPart ep = epEntry.getValue();
-
- if(ep instanceof ShapeEditPart) {
- ShapeEditPart sep = (ShapeEditPart)ep;
- EObject eObject = sep.resolveSemanticElement();
-
- if(eObject instanceof Interaction || eObject instanceof InteractionOperand) {
-
- Rectangle figureBounds = getAbsoluteBounds(sep);
-
- if(figureBounds.contains(bounds)) {
- coveredInteractions.add((InteractionFragment)eObject);
- }
- } else if(eObject instanceof CombinedFragment) {
- // handle case when the figure is located in the CF header as if it were in the first Interaction Operand
- Rectangle figureBounds = getAbsoluteBounds(sep);
- if(figureBounds.contains(bounds)) {
- coveredCF.add((CombinedFragment)eObject);
- }
- }
- }
- }
-
- // inspect coveredCF to ensure at least on child operand is in coveredInteractions list
- for(CombinedFragment cf : coveredCF) {
- List<InteractionOperand> operands = cf.getOperands();
- if(operands.size() > 0 && Collections.disjoint(operands, coveredInteractions)) {
- // bounds are in the header, add the first operand
- coveredInteractions.add(operands.get(0));
- }
- }
-
- // for each interaction verify if its children list does not contain an other covered interaction
- // if it doesn't we have found the top-level interaction
- for(InteractionFragment ift : coveredInteractions) {
- boolean subiftFounded = false;
- if(ift instanceof Interaction) {
- for(InteractionFragment subift : ((Interaction)ift).getFragments()) {
- if(subift instanceof CombinedFragment) {
- for(InteractionOperand io : ((CombinedFragment)subift).getOperands()) {
- if(coveredInteractions.contains(io)) {
- subiftFounded = true;
- }
- }
- }
- }
- }
- if(!subiftFounded && ift instanceof InteractionOperand) {
- for(InteractionFragment subift : ((InteractionOperand)ift).getFragments()) {
- if(subift instanceof CombinedFragment) {
- for(InteractionOperand io : ((CombinedFragment)subift).getOperands()) {
- if(coveredInteractions.contains(io)) {
- subiftFounded = true;
- }
- }
- }
- }
- }
- if(!subiftFounded) {
- container = ift;
- break;
- }
- }
-
- return container;
- }
-
- /**
- * Find the location on the lifeline of an interaction fragment
- *
- * @param lifelineEditPart
- * the lifeline edit part
- * @param fragment
- * the searched interaction fragment
- * @return the absolute location or null if not found
- */
- public static Point findLocationOfEvent(LifelineEditPart lifelineEditPart, InteractionFragment fragment) {
- if(lifelineEditPart == null) {
- return null;
- }
- // Search for corresponding node edit part out of the lifeline.
- if(fragment instanceof CombinedFragment || fragment instanceof Continuation || fragment instanceof InteractionOperand || fragment instanceof InteractionUse || fragment instanceof Interaction) {
- List<View> views = DiagramEditPartsUtil.findViews(fragment, lifelineEditPart.getViewer());
- for(View view : views) {
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelineEditPart);
- boolean isCombinedFragment = part instanceof CombinedFragmentEditPart || part instanceof CombinedFragment2EditPart;
- boolean isContinuation = part instanceof ContinuationEditPart;
- boolean isInteractionOperand = part instanceof InteractionOperandEditPart;
- boolean isInteractionUse = part instanceof InteractionUseEditPart;
- boolean isInteraction = part instanceof InteractionEditPart;
- if(isCombinedFragment || isContinuation || isInteractionOperand || isInteractionUse || isInteraction) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)part);
- return bounds.getTop();
- }
- }
- } else {
- // search on graphical children of the lifeline
- List<?> children = lifelineEditPart.getChildren();
- for(Object child : children) {
- // check destruction event
- if(child instanceof DestructionOccurrenceSpecificationEditPart) {
- EObject destructionOccurence = ((GraphicalEditPart)child).resolveSemanticElement();
- EObject lifeline = lifelineEditPart.resolveSemanticElement();
- if(destructionOccurence instanceof DestructionOccurrenceSpecification && lifeline instanceof Lifeline && fragment instanceof DestructionOccurrenceSpecification) {
- DestructionOccurrenceSpecification destEvent = ((DestructionOccurrenceSpecification)fragment);
- if(destEvent != null && destEvent.equals(destructionOccurence)) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- return bounds.getCenter();
- }
- }
- }
- // check in children executions
- if(child instanceof ActionExecutionSpecificationEditPart || child instanceof BehaviorExecutionSpecificationEditPart) {
- if(fragment instanceof ExecutionSpecification) {
- // check the execution
- EObject element = ((GraphicalEditPart)child).resolveSemanticElement();
- if(element instanceof ExecutionSpecification) {
- if(fragment.equals(element)) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- return bounds.getTop();
- }
- }
- } else if(fragment instanceof ExecutionOccurrenceSpecification) {
- // check start and finish events of the execution
- EObject element = ((GraphicalEditPart)child).resolveSemanticElement();
- if(element instanceof ExecutionSpecification) {
- if(fragment.equals(((ExecutionSpecification)element).getStart())) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- return bounds.getTop();
- } else if(fragment.equals(((ExecutionSpecification)element).getFinish())) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- return bounds.getBottom();
- }
- }
- } else if(fragment instanceof MessageOccurrenceSpecification) {
- // check messages to and from the execution
- Point loc = findLocationOfMessageOccurrence((GraphicalEditPart)child, (MessageOccurrenceSpecification)fragment);
- if(loc != null) {
- return loc;
- }
- }
- }
- // check in children StateInvariant
- if(child instanceof StateInvariantEditPart) {
- if(fragment instanceof StateInvariant) {
- // check the StateInvariant
- EObject element = ((GraphicalEditPart)child).resolveSemanticElement();
- if(element instanceof StateInvariant) {
- if(fragment.equals(element)) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- return bounds.getTop();
- }
- }
- } else if(fragment instanceof MessageOccurrenceSpecification) {
- // check messages to and from the execution
- Point loc = findLocationOfMessageOccurrence((GraphicalEditPart)child, (MessageOccurrenceSpecification)fragment);
- if(loc != null) {
- return loc;
- }
- }
- }
- }
- if(fragment instanceof MessageOccurrenceSpecification) {
- // check messages to and from the lifeline
- Point loc = findLocationOfMessageOccurrence(lifelineEditPart, (MessageOccurrenceSpecification)fragment);
- if(loc != null) {
- return loc;
- }
- }
- }
- // If we found nothing, this may be a sync message receive
- if(fragment instanceof MessageOccurrenceSpecification) {
- boolean isSync = ((MessageOccurrenceSpecification)fragment).getMessage() != null && MessageSort.SYNCH_CALL_LITERAL.equals(((MessageOccurrenceSpecification)fragment).getMessage().getMessageSort());
- if(isSync) {
- // sync message should trigger an execution specification start. Find and return the corresponding start.
- EObject container = fragment.eContainer();
- EObject lifeline = lifelineEditPart.resolveSemanticElement();
- InteractionFragment nextFragment = InteractionFragmentHelper.findNextFragment(fragment, container);
- while(nextFragment != null && nextFragment.getCovereds().contains(lifeline)) {
- if(nextFragment.getCovereds().contains(lifeline)) {
- // Found next event of lifeline. Check if it really is a start.
- if(nextFragment instanceof ExecutionOccurrenceSpecification) {
- ExecutionSpecification exe = ((ExecutionOccurrenceSpecification)nextFragment).getExecution();
- if(exe != null && EcoreUtil.equals(exe.getStart(), nextFragment)) {
- // return location of the start.
- return findLocationOfEvent(lifelineEditPart, nextFragment);
- }
- }
- break;
- } else {
- nextFragment = InteractionFragmentHelper.findNextFragment(nextFragment, container);
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Get the bounds of an edit part
- *
- * @param part
- * edit part to find bounds
- * @return part's bounds in absolute coordinates
- */
- public static Rectangle getAbsoluteBounds(IGraphicalEditPart part) {
- // take bounds from figure
- Rectangle bounds = part.getFigure().getBounds().getCopy();
-
- if(part.getNotationView() instanceof Node) {
- // rather update with up to date model bounds
- Node node = (Node)part.getNotationView();
- LayoutConstraint cst = node.getLayoutConstraint();
- if(cst instanceof Bounds) {
- Bounds b = (Bounds)cst;
- Point parentLoc = part.getFigure().getParent().getBounds().getLocation();
- if(b.getX() > 0) {
- bounds.x = b.getX() + parentLoc.x;
- }
- if(b.getY() > 0) {
- bounds.y = b.getY() + parentLoc.y;
- }
- if(b.getHeight() != -1) {
- bounds.height = b.getHeight();
- }
- if(b.getWidth() != -1) {
- bounds.width = b.getWidth();
- }
- }
- }
-
- part.getFigure().getParent().translateToAbsolute(bounds);
- return bounds;
- }
-
- /**
- * Get the extremity of a connection edit part
- *
- * @param connection
- * the connection edit part to find extremity
- * @param isStart
- * true to find the start, false for the end
- * @return connection's extremity in absolute coordinates or null
- */
- public static Point getAbsoluteEdgeExtremity(ConnectionNodeEditPart connection, boolean isStart) {
- Connection msgFigure = connection.getConnectionFigure();
- if(connection.getNotationView() instanceof Edge) {
- // rather take up to date model information
- Edge edge = (Edge)connection.getNotationView();
- Anchor idAnchor = null;
- ConnectionAnchor conAnchor = null;
- Object part = null;
- if(isStart && connection.getSource() instanceof IGraphicalEditPart) {
- View linkedFigure = edge.getSource();
- // connection.getSource() may be not up to date, get part for linkedFigure
- part = connection.getSource().getViewer().getEditPartRegistry().get(linkedFigure);
- idAnchor = edge.getSourceAnchor();
- conAnchor = msgFigure.getSourceAnchor();
- } else if(!isStart && connection.getTarget() instanceof IGraphicalEditPart) {
- View linkedFigure = edge.getTarget();
- // connection.getTarget() may be not up to date, get part for linkedFigure
- part = connection.getTarget().getViewer().getEditPartRegistry().get(linkedFigure);
- idAnchor = edge.getTargetAnchor();
- conAnchor = msgFigure.getTargetAnchor();
- }
- if(part instanceof IGraphicalEditPart && idAnchor instanceof IdentityAnchor && conAnchor != null) {
- // take up to date bounds of the linked part in case it is moved
- Rectangle linkedPartBounds = getAbsoluteBounds((IGraphicalEditPart)part);
-
- IFigure anchorOwningFigure = conAnchor.getOwner();
- IFigure partFigure = ((IGraphicalEditPart)part).getFigure();
- Dimension delta = anchorOwningFigure.getBounds().getLocation().getDifference(partFigure.getBounds().getLocation());
- // get position from anchor id
- String oldTerminal = ((IdentityAnchor)idAnchor).getId();
- PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(oldTerminal);
- int xPos = linkedPartBounds.x + delta.width + (int)Math.round(anchorOwningFigure.getBounds().width * pp.preciseX);
- int yPos = linkedPartBounds.y + delta.height + (int)Math.round(anchorOwningFigure.getBounds().height * pp.preciseY);
- return new Point(xPos, yPos);
- }
- }
- // can not get from model, rely on figure
- if(msgFigure instanceof AbstractPointListShape) {
- Point extremity;
- if(isStart) {
- // start event of the message
- extremity = ((AbstractPointListShape)msgFigure).getStart().getCopy();
- } else {
- // finish event of the message
- extremity = ((AbstractPointListShape)msgFigure).getEnd().getCopy();
- }
- msgFigure.getParent().translateToAbsolute(extremity);
- return extremity;
- }
- return null;
- }
-
- /**
- * Find the location on a node of a message occurrence specification
- *
- * @param nodeEditPart
- * the node edit part which to check incoming and outgoing messages
- * @param event
- * the message occurrence specification
- * @return the absolute location or null
- */
- public static Point findLocationOfMessageOccurrence(GraphicalEditPart nodeEditPart, MessageOccurrenceSpecification event) {
- // messages to the node
- List<?> targetConnections = nodeEditPart.getTargetConnections();
- for(Object conn : targetConnections) {
- if(conn instanceof ConnectionNodeEditPart) {
- EObject element = ((ConnectionNodeEditPart)conn).resolveSemanticElement();
- if(element instanceof Message && event.equals(((Message)element).getReceiveEvent())) {
- // finish event of the message
- IFigure figure = ((ConnectionNodeEditPart)conn).getFigure();
- if(figure instanceof AbstractPointListShape) {
- return getAbsoluteEdgeExtremity((ConnectionNodeEditPart)conn, false);
- }
- }
- }
- }
- // messages from the node
- List<?> sourceConnections = nodeEditPart.getSourceConnections();
- for(Object conn : sourceConnections) {
- if(conn instanceof ConnectionNodeEditPart) {
- EObject element = ((ConnectionNodeEditPart)conn).resolveSemanticElement();
- if(element instanceof Message && event.equals(((Message)element).getSendEvent())) {
- // start event of the message
- IFigure figure = ((ConnectionNodeEditPart)conn).getFigure();
- if(figure instanceof AbstractPointListShape) {
- return getAbsoluteEdgeExtremity((ConnectionNodeEditPart)conn, true);
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Find the location on a node of a execution occurrence specification
- *
- * @param nodeEditPart
- * the node edit part which to check incoming and outgoing messages
- * @param event
- * the execution occurrence specification
- * @return the absolute location or null
- */
- public static Point findLocationOfExecutionOccurrence(GraphicalEditPart nodeEditPart, ExecutionOccurrenceSpecification event) {
- // child to the node
- List<?> children = nodeEditPart.getChildren();
- for(Object child : children) {
- if(child instanceof ActionExecutionSpecificationEditPart) {
- EObject element = ((ActionExecutionSpecificationEditPart)child).resolveSemanticElement();
- if(element != null && element instanceof ExecutionSpecification) {
- IFigure figure = ((ActionExecutionSpecificationEditPart)child).getFigure();
- Rectangle copy = figure.getBounds().getCopy();
- figure.translateToAbsolute(copy);
- if(event.equals(((ExecutionSpecification)element).getStart())){
- return copy.getTop();
- }else if(event.equals(((ExecutionSpecification)element).getFinish())){
- return copy.getBottom();
- }
- }
- }else if(child instanceof BehaviorExecutionSpecificationEditPart) {
- EObject element = ((BehaviorExecutionSpecificationEditPart)child).resolveSemanticElement();
- if(element != null && element instanceof ExecutionSpecification) {
- IFigure figure = ((BehaviorExecutionSpecificationEditPart)child).getFigure();
- Rectangle copy = figure.getBounds().getCopy();
- figure.translateToAbsolute(copy);
- if(event.equals(((ExecutionSpecification)element).getStart())){
- return copy.getTop();
- }else if(event.equals(((ExecutionSpecification)element).getFinish())){
- return copy.getBottom();
- }
- }
- }
- }
-
- return null;
- }
-
- /**
- * Find the occurrence specification covering the lifeline near the given location.
- * If none is close enough, null is returned.
- *
- * @param location
- * the location
- * @param lifelineEditPart
- * the Lifeline edit part
- * @return an entry with the nearest OccurrenceSpecification(s) and its corresponding location or null if none is close enough
- */
- public static Entry<Point, List<OccurrenceSpecification>> findNearestEvent(Point location, LifelineEditPart lifelineEditPart) {
- if(lifelineEditPart == null) {
- return null;
- }
- // Map referencing children occurrences by their location on the lifeline.
- Map<Point, List<OccurrenceSpecification>> occurrences = new HashMap<Point, List<OccurrenceSpecification>>();
- // graphical children of the lifeline
- List<?> children = lifelineEditPart.getChildren();
- for(Object child : children) {
- // children executions
- if(child instanceof ActionExecutionSpecificationEditPart || child instanceof BehaviorExecutionSpecificationEditPart) {
- EObject element = ((GraphicalEditPart)child).resolveSemanticElement();
- if(element instanceof ExecutionSpecification) {
- // find start and finish events of the execution
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- if(!occurrences.containsKey(bounds.getTop())) {
- // there should be at most 2 occurrences (with starting message)
- occurrences.put(bounds.getTop(), new ArrayList<OccurrenceSpecification>(2));
- }
- occurrences.get(bounds.getTop()).add(((ExecutionSpecification)element).getStart());
- if(!occurrences.containsKey(bounds.getBottom())) {
- occurrences.put(bounds.getBottom(), new ArrayList<OccurrenceSpecification>(1));
- }
- occurrences.get(bounds.getBottom()).add(((ExecutionSpecification)element).getFinish());
- // messages to and from the execution
- completeOccurrencesMapWithMessages((GraphicalEditPart)child, occurrences);
- }
- }
- // destruction event
- if(child instanceof DestructionOccurrenceSpecificationEditPart) {
- EObject destructionOccurence = ((GraphicalEditPart)child).resolveSemanticElement();
- EObject lifeline = lifelineEditPart.resolveSemanticElement();
- if(destructionOccurence instanceof DestructionOccurrenceSpecification && lifeline instanceof Lifeline) {
- for(InteractionFragment occurence : ((Lifeline)lifeline).getCoveredBys()) {
- if(occurence instanceof DestructionOccurrenceSpecification) {
- DestructionOccurrenceSpecification currentOccurence = ((DestructionOccurrenceSpecification)occurence);
- if(destructionOccurence.equals(currentOccurence)) {
- Rectangle bounds = getAbsoluteBounds((GraphicalEditPart)child);
- if(!occurrences.containsKey(bounds.getCenter())) {
- occurrences.put(bounds.getCenter(), new ArrayList<OccurrenceSpecification>(2));
- }
- occurrences.get(bounds.getCenter()).add((OccurrenceSpecification)occurence);
- break;
- }
- }
- }
- }
- }
- }
- // messages to and from the lifeline
- completeOccurrencesMapWithMessages(lifelineEditPart, occurrences);
-
- // Find the nearest object within acceptable distance
- double smallerDistance = MAXIMAL_DISTANCE_FROM_EVENT;
- Entry<Point, List<OccurrenceSpecification>> nearestObject = null;
- for(Entry<Point, List<OccurrenceSpecification>> entry : occurrences.entrySet()) {
- double distance = location.getDistance(entry.getKey());
- if(distance < smallerDistance) {
- smallerDistance = distance;
- nearestObject = entry;
- } else if(distance == smallerDistance && nearestObject != null) {
- // two events at the exact same distance.
- // Keep both so the best one can be used
- if(entry.getValue() instanceof MessageOccurrenceSpecification) {
- nearestObject.getValue().addAll(entry.getValue());
- }
- }
- }
-
- return nearestObject;
- }
-
- /**
- * Complete the map of occurrences and their location, by taking in account messages from and to the node edit part
- *
- * @param nodeEditPart
- * part to consider message around
- * @param occurrencesMap
- * the map to complete
- */
- private static void completeOccurrencesMapWithMessages(GraphicalEditPart nodeEditPart, Map<Point, List<OccurrenceSpecification>> occurrencesMap) {
- // messages to the node
- List<?> targetConnections = nodeEditPart.getTargetConnections();
- for(Object conn : targetConnections) {
- if(conn instanceof ConnectionNodeEditPart) {
- EObject element = ((ConnectionNodeEditPart)conn).resolveSemanticElement();
- if(element instanceof Message && ((Message)element).getReceiveEvent() instanceof MessageOccurrenceSpecification) {
- // finish events of the message
- IFigure figure = ((ConnectionNodeEditPart)conn).getFigure();
- if(figure instanceof AbstractPointListShape) {
- Point end = getAbsoluteEdgeExtremity((ConnectionNodeEditPart)conn, false);
- if(!occurrencesMap.containsKey(end)) {
- occurrencesMap.put(end, new ArrayList<OccurrenceSpecification>(1));
- }
- occurrencesMap.get(end).add((MessageOccurrenceSpecification)((Message)element).getReceiveEvent());
- }
- }
- }
- }
- // messages from the node
- List<?> sourceConnections = nodeEditPart.getSourceConnections();
- for(Object conn : sourceConnections) {
- if(conn instanceof ConnectionNodeEditPart) {
- EObject element = ((ConnectionNodeEditPart)conn).resolveSemanticElement();
- if(element instanceof Message && ((Message)element).getSendEvent() instanceof MessageOccurrenceSpecification) {
- // start events of the message
- IFigure figure = ((ConnectionNodeEditPart)conn).getFigure();
- if(figure instanceof AbstractPointListShape) {
- Point start = getAbsoluteEdgeExtremity((ConnectionNodeEditPart)conn, true);
- if(!occurrencesMap.containsKey(start)) {
- occurrencesMap.put(start, new ArrayList<OccurrenceSpecification>(1));
- }
- occurrencesMap.get(start).add((MessageOccurrenceSpecification)((Message)element).getSendEvent());
- }
- }
- }
- }
- }
-
- /**
- * The position of the part where the event is linked
- *
- * @param occSpec
- * the occurrence specification
- * @param timeElementPart
- * the part representing time element (duration/time constraint/observation)
- * @return one of {@link PositionConstants#TOP}, {@link PositionConstants#CENTER}, {@link PositionConstants#BOTTOM},
- * {@link PositionConstants#NONE}
- */
- public static int positionWhereEventIsLinkedToPart(OccurrenceSpecification occSpec, IBorderItemEditPart timeElementPart) {
- EObject timeElement = timeElementPart.resolveSemanticElement();
- if(timeElement instanceof TimeObservation) {
- if(occSpec.equals(((TimeObservation)timeElement).getEvent())) {
- return PositionConstants.CENTER;
- } else {
- return PositionConstants.NONE;
- }
- } else if(timeElement instanceof TimeConstraint) {
- if(((TimeConstraint)timeElement).getConstrainedElements().contains(occSpec)) {
- return PositionConstants.CENTER;
- } else {
- return PositionConstants.NONE;
- }
- } else if(timeElement instanceof DurationConstraint) {
- if(((DurationConstraint)timeElement).getConstrainedElements().contains(occSpec)) {
- List<Element> events = ((DurationConstraint)timeElement).getConstrainedElements();
- LifelineEditPart lifelinePart = getParentLifelinePart(timeElementPart);
- if(lifelinePart != null && events.size() >= 2) {
- OccurrenceSpecification otherEvent = null;
- if(!occSpec.equals(events.get(0)) && events.get(0) instanceof OccurrenceSpecification) {
- otherEvent = (OccurrenceSpecification)events.get(0);
- } else if(!occSpec.equals(events.get(1)) && events.get(1) instanceof OccurrenceSpecification) {
- otherEvent = (OccurrenceSpecification)events.get(1);
- }
- if(otherEvent != null) {
- Point otherLoc = findLocationOfEvent(lifelinePart, otherEvent);
- Point thisLoc = findLocationOfEvent(lifelinePart, occSpec);
- if(otherLoc != null && thisLoc != null) {
- if(otherLoc.y > thisLoc.y) {
- return PositionConstants.TOP;
- } else {
- return PositionConstants.BOTTOM;
- }
- }
- }
- }
- } else {
- return PositionConstants.NONE;
- }
- }
- return PositionConstants.NONE;
- }
-
- /**
- * Return the lifeline edit part containing this part (directly or indirectly)
- *
- * @param nodeEditPart
- * the contained edit part or itself
- * @return lifeline edit part or null
- */
- public static LifelineEditPart getParentLifelinePart(EditPart nodeEditPart) {
- EditPart parent = nodeEditPart;
- while(parent != null) {
- if(parent instanceof LifelineEditPart) {
- return (LifelineEditPart)parent;
- } else {
- parent = parent.getParent();
- }
- }
- return null;
- }
-
- /**
- * Get the edit part (message, execution, or destruction event) which starts or finishes with the event on the given lifeline part
- *
- * @param lifelinePart
- * the lifeline edit part on which the event is located
- * @param event
- * the event
- * @return the edit part of which an end is defined by event on the lifelinePart edit part
- */
- public static EditPart getLinkedEditPart(EditPart lifelinePart, OccurrenceSpecification event) {
- if(event instanceof MessageOccurrenceSpecification) {
- // get parts representing the message linked with the event
- Message message = ((MessageOccurrenceSpecification)event).getMessage();
- if(message == null) {
- return null;
- }
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(message);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the message part must start or finish on the lifeline (with the event)
- if(part instanceof ConnectionEditPart) {
- EditPart lifelineChild = null;
- if(event.equals(message.getSendEvent())) {
- lifelineChild = ((ConnectionEditPart)part).getSource();
- } else if(event.equals(message.getReceiveEvent())) {
- lifelineChild = ((ConnectionEditPart)part).getTarget();
- }
- LifelineEditPart parentLifeline = getParentLifelinePart(lifelineChild);
- if(lifelinePart.equals(parentLifeline)) {
- return part;
- }
- }
- }
- }
- } else if(event instanceof ExecutionOccurrenceSpecification) {
- // get parts representing the execution linked with the event
- ExecutionSpecification execution = ((ExecutionOccurrenceSpecification)event).getExecution();
- if(execution == null) {
- return null;
- }
- Collection<Setting> settings = CacheAdapter.INSTANCE.getNonNavigableInverseReferences(execution);
- for(Setting ref : settings) {
- if(NotationPackage.eINSTANCE.getView_Element().equals(ref.getEStructuralFeature())) {
- View view = (View)ref.getEObject();
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelinePart);
- // the execution part must be on the lifeline
- EditPart lifelineChild = part;
- LifelineEditPart parentLifeline = getParentLifelinePart(lifelineChild);
- if(lifelinePart.equals(parentLifeline)) {
- return part;
- }
- }
- }
- } else {
- // get parts representing the destruction event linked with the event
- for(Object lifelineChild : lifelinePart.getChildren()) {
- if(lifelineChild instanceof DestructionOccurrenceSpecificationEditPart) {
- EObject destr = ((DestructionOccurrenceSpecificationEditPart)lifelineChild).resolveSemanticElement();
- if(destr instanceof DestructionOccurrenceSpecification && destr.equals(event)) {
- return (EditPart)lifelineChild;
- }
- }
- }
- }
- return null;
- }
-
- /**
- * Get the object safely casted as a list of OccurrenceSpecification
- *
- * @param occurrenceSpecificationList
- * the object which is supposed to be a list of OccurrenceSpecification
- */
- public static List<OccurrenceSpecification> getAsOccSpecList(Object occurrenceSpecificationList) {
- if(occurrenceSpecificationList instanceof List<?>) {
- List<?> list = (List<?>)occurrenceSpecificationList;
- if(!list.isEmpty()) {
- List<OccurrenceSpecification> newList = new ArrayList<OccurrenceSpecification>(list.size());
- for(Object elt : list) {
- if(elt instanceof OccurrenceSpecification) {
- newList.add((OccurrenceSpecification)elt);
- }
- }
- return newList;
- }
- }
- return Collections.emptyList();
- }
-
- /**
- * Get the pair of OccurrenceSpecification which a duration constraint or observation should be created between
- *
- * @param occ1List
- * the list of occurrences at the same time, among which the first one must be chosen
- * @param occ2List
- * the list of occurrences at the same time, among which the second one must be chosen
- * @return size two array of OccurrenceSpecification which can be linked or null
- */
- public static OccurrenceSpecification[] getPairOfCorrespondingOccSpec(List<OccurrenceSpecification> occ1List, List<OccurrenceSpecification> occ2List) {
- // check for occurrences linked by a message
- for(OccurrenceSpecification occ1 : occ1List) {
- for(OccurrenceSpecification occ2 : occ2List) {
- if(DurationConstraintHelper.endsOfSameMessage(occ1, occ2)) {
- // we must link occurrences of a message
- return new OccurrenceSpecification[]{ occ1, occ2 };
- }
- }
- }
- // check for occurrences on a same lifeline
- for(OccurrenceSpecification occ1 : occ1List) {
- if(occ1 instanceof MessageOccurrenceSpecification) {
- Message mess = ((MessageOccurrenceSpecification)occ1).getMessage();
- if(mess.getReceiveEvent().equals(occ1) && MessageSort.SYNCH_CALL_LITERAL.equals(mess.getMessageSort())) {
- // filter receive event, we prefer the corresponding start event at the same location
- continue;
- }
- }
- for(OccurrenceSpecification occ2 : occ2List) {
- if(occ2 instanceof MessageOccurrenceSpecification) {
- Message mess = ((MessageOccurrenceSpecification)occ2).getMessage();
- if(mess.getReceiveEvent().equals(occ2) && MessageSort.SYNCH_CALL_LITERAL.equals(mess.getMessageSort())) {
- // filter receive event, we prefer the corresponding start event at the same location
- continue;
- }
- }
- if(DurationConstraintHelper.coversSameLifeline(occ1, occ2)) {
- // we must link occurrences on a same lifeline
- return new OccurrenceSpecification[]{ occ1, occ2 };
- }
- }
- }
- return null;
- }
-
- public static List<Element> getCombinedFragmentAssociatedElement(CombinedFragment cf) {
- List<Element> elements = new LinkedList<Element>();
-
- for(InteractionOperand operand : cf.getOperands()) {
- // Add all elements related to this operand
- elements.addAll(getInteractionOperandAssociatedElement(operand));
- // Add this operand
- elements.add(operand);
- }
- return elements;
-
- }
-
- public static List<Element> getInteractionOperandAssociatedElement(InteractionOperand interactionOperand) {
- List<Element> elements = new LinkedList<Element>();
- for(InteractionFragment itf : interactionOperand.getFragments()) {
- if(itf instanceof CombinedFragment) {
- // add the combinedFragment
- elements.addAll(getCombinedFragmentAssociatedElement((CombinedFragment)itf));
- }
- elements.add(itf);
- if(itf instanceof MessageOccurrenceSpecification) {
- MessageOccurrenceSpecification mos = (MessageOccurrenceSpecification)itf;
- if(mos.getMessage() != null) {
- elements.add(mos.getMessage());
- }
- }
- }
- return elements;
- }
-
- public static void handleMessageSortChange(EditingDomain editingDomain, Notification notification, Message message, MessageSort expectedMessageSort) {
- //This restriction isn't needed anymore, as the Property View offers a refactoring
- //facility for the MessageSort. The refactoring is only available for AsynchCall to
- //AsynchSignal and vice-versa.
- //However, the modification of the MessageSort from the "Advanced" property view should still be forbidden.
-
- Object feature = notification.getFeature();
-
- if(UMLPackage.eINSTANCE.getMessage_MessageSort().equals(feature) && !expectedMessageSort.equals(notification.getNewValue())) {
- Object oldValue = notification.getOldValue();
- Object newValue = notification.getNewValue();
- if(oldValue instanceof MessageSort) {
- if(!((oldValue == MessageSort.ASYNCH_CALL_LITERAL && newValue == MessageSort.ASYNCH_SIGNAL_LITERAL) || (oldValue == MessageSort.ASYNCH_SIGNAL_LITERAL && newValue == MessageSort.ASYNCH_CALL_LITERAL))) {
- MessageDialog.openWarning(Display.getCurrent().getActiveShell(), BLOCK_SORT_MODIFICATION_TITLE, BLOCK_SORT_MODIFICATION_MSG);
- CommandHelper.executeCommandWithoutHistory(editingDomain, SetCommand.create(editingDomain, message, feature, notification.getOldValue()), true);
- return;
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- public static Set<Lifeline> getCoveredLifelines(Rectangle selectionRect, EditPart hostEditPart) {
- Set<Lifeline> coveredLifelines = new HashSet<Lifeline>();
-
- // retrieve all the edit parts in the registry
- Set<Entry<Object, EditPart>> allEditPartEntries = hostEditPart.getViewer().getEditPartRegistry().entrySet();
- for(Entry<Object, EditPart> epEntry : allEditPartEntries) {
- EditPart ep = epEntry.getValue();
-
- if(ep instanceof ShapeEditPart) {
- ShapeEditPart sep = (ShapeEditPart)ep;
- EObject elem = sep.getNotationView().getElement();
-
- if(elem instanceof Lifeline) {
- Rectangle figureBounds = getAbsoluteBounds(sep);
-
- if(selectionRect.intersects(figureBounds)) {
- coveredLifelines.add((Lifeline)elem);
- }
- }
- }
- }
- return coveredLifelines;
- }
-
- /**
- * retrieve all the interaction fragments and their related ift at least partially covered by the rectangle, including sub ift like
- * interaction operands in combined fragment.
- *
- * @param selectionRect
- * the rectangle where to look for ift.
- * @param hostEditPart
- * the host edit part used to retrieve all the edit parts in the registry.
- * @param ignoreSet
- * a set of ift to ignore.
- * @return
- * a set containing the covered ift or null if an ift not ignored is not fully covered.
- */
- @SuppressWarnings("unchecked")
- public static Set<InteractionFragment> getCoveredInteractionFragments(Rectangle selectionRect, EditPart hostEditPart, Set<InteractionFragment> ignoreSet) {
- Set<InteractionFragment> coveredInteractionFragments = new HashSet<InteractionFragment>();
-
- if(ignoreSet == null) {
- ignoreSet = new HashSet<InteractionFragment>();
- }
-
- // retrieve all the edit parts in the registry
- Set<Entry<Object, EditPart>> allEditPartEntries = hostEditPart.getViewer().getEditPartRegistry().entrySet();
- for(Entry<Object, EditPart> epEntry : allEditPartEntries) {
- EditPart ep = epEntry.getValue();
-
- if(ep instanceof ShapeEditPart) {
- ShapeEditPart sep = (ShapeEditPart)ep;
- EObject elem = sep.getNotationView().getElement();
-
- if(elem instanceof InteractionFragment && !ignoreSet.contains(elem)) {
- Rectangle figureBounds = getAbsoluteBounds(sep);
-
- // keep the fragment if its figure is completely in the selection
- // if it is inside but not completely this method return null
- if(selectionRect.contains(figureBounds)) {
- coveredInteractionFragments.add((InteractionFragment)elem);
- if(elem instanceof ExecutionSpecification) {
- ExecutionSpecification es = (ExecutionSpecification)elem;
- coveredInteractionFragments.add(es.getStart());
- coveredInteractionFragments.add(es.getFinish());
- }
- } else {
- Rectangle intersection = selectionRect.getIntersection(figureBounds);
- if(!intersection.equals(new Rectangle()) && !intersection.equals(selectionRect)) {
- return null;
- }
- }
- }
-
- } else if(ep instanceof ConnectionEditPart) {
- ConnectionEditPart cep = (ConnectionEditPart)ep;
- EObject elem = cep.getNotationView().getElement();
-
- // for connections, messages have ends that are ift but don't have theirs own edit parts
- // => use anchors to determine if they should be included in the set
- if(elem instanceof Message) {
- Message msg = (Message)elem;
- Connection msgFigure = cep.getConnectionFigure();
-
- Point sourcePoint = msgFigure.getSourceAnchor().getReferencePoint();
- Point targetPoint = msgFigure.getTargetAnchor().getReferencePoint();
-
- if(selectionRect.contains(sourcePoint)) {
- MessageEnd msgSendEnd = msg.getSendEvent();
- if(msgSendEnd instanceof InteractionFragment) {
- coveredInteractionFragments.add((InteractionFragment)msgSendEnd);
- }
- }
- if(selectionRect.contains(targetPoint)) {
- MessageEnd msgReceiveEnd = msg.getReceiveEvent();
- if(msgReceiveEnd instanceof InteractionFragment) {
- coveredInteractionFragments.add((InteractionFragment)msgReceiveEnd);
- }
- }
- }
- }
- }
- return coveredInteractionFragments;
- }
-
- /**
- * return a command to set the enclosing interaction or interaction operand of an interaction fragment.
- *
- * @param ed
- * The transactional editing domain.
- * @param ift
- * The interaction fragment.
- * @param io
- * the new enclosing interaction.
- * @return The command.
- */
- public static ICommand getSetEnclosingInteractionCommand(final TransactionalEditingDomain ed, final InteractionFragment ift, final EObject interaction) {
- return new AbstractTransactionalCommand(ed, "Set enclosing interaction command", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- setEnclosingInteraction(ift, interaction, false);
-
- return CommandResult.newOKCommandResult();
- }
- };
- }
-
- /**
- * Set the interaction or interaction operand which contains a fragment
- *
- * @param ift
- * fragment to update container
- * @param interaction
- * new containing interaction or interaction operand
- * @param forceIfCoregion
- * force the set even if fragment belong to a coregion. Use true only when you are sure the fragment no longer belongs to a coregion's
- * operand.
- */
- public static void setEnclosingInteraction(InteractionFragment ift, EObject interaction, boolean forceIfCoregion) {
- if(ift != null) {
- if(interaction instanceof Interaction) {
- if(!interaction.equals(ift.getEnclosingInteraction())) {
- // check case when mos looks outside but is in a coregion.
- if(!forceIfCoregion && ift instanceof MessageOccurrenceSpecification) {
- InteractionOperand operand = ift.getEnclosingOperand();
- if(operand != null) {
- Element cf = operand.getOwner();
- if(cf instanceof CombinedFragment && InteractionOperatorKind.PAR_LITERAL.equals(((CombinedFragment)cf).getInteractionOperator())) {
- // was in a coregion. Check whether other mos is still in the coregion
- Message mess = ((MessageOccurrenceSpecification)ift).getMessage();
- // find other mos
- MessageOccurrenceSpecification otherMos = null;
- if(ift.equals(mess.getSendEvent()) && mess.getReceiveEvent() instanceof MessageOccurrenceSpecification) {
- otherMos = (MessageOccurrenceSpecification)mess.getReceiveEvent();
- } else if(ift.equals(mess.getReceiveEvent()) && mess.getSendEvent() instanceof MessageOccurrenceSpecification) {
- otherMos = (MessageOccurrenceSpecification)mess.getSendEvent();
- }
- if(otherMos != null) {
- // check that it is in a coregion (specific code is in charge of taking it out in ReconnectMessageHelper)
- if(operand.equals(otherMos.getEnclosingOperand())) {
- return;
- }
- }
- }
- }
- }
- ift.setEnclosingOperand(null);
- ift.setEnclosingInteraction((Interaction)interaction);
- }
- } else if(interaction instanceof InteractionOperand) {
- if(!interaction.equals(ift.getEnclosingOperand())) {
- ift.setEnclosingInteraction(null);
- ift.setEnclosingOperand((InteractionOperand)interaction);
- }
- }
- }
- }
-
- /**
- * return a command to add a covered lifeline to an interaction fragment.
- *
- * @param ed
- * The transactional editing domain.
- * @param ift
- * The interaction fragment.
- * @param lifeline
- * the lifeline.
- * @return The command.
- */
- public static ICommand getAddCoveredLifelineCommand(final TransactionalEditingDomain ed, final InteractionFragment ift, final Lifeline lifeline) {
- return new AbstractTransactionalCommand(ed, "Add covered lifeline command", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- ift.getCovereds().add(lifeline);
- return CommandResult.newOKCommandResult();
- }
- };
- }
-
- /**
- * return a command to remove a previously covered lifeline of an interaction fragment.
- *
- * @param ed
- * The transactional editing domain.
- * @param ift
- * The interaction fragment.
- * @param lifeline
- * the lifeline.
- * @return The command.
- */
- public static ICommand getRemoveCoveredLifelineCommand(final TransactionalEditingDomain ed, final InteractionFragment ift, final Lifeline lifeline) {
- return new AbstractTransactionalCommand(ed, "Add covered lifeline command", null) {
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- ift.getCovereds().remove(lifeline);
- return CommandResult.newOKCommandResult();
- }
- };
- }
-
- /**
- * Create a command to update the enclosing interaction of a message end according to its new location.
- *
- * @param movedMos
- * the moved Message Occurrence Specification
- * @param newLocation
- * the new absolute location
- * @param editPart
- * any adit part of the corresponding diagram
- * @return the command or null if nothing changes
- */
- //@SuppressWarnings("unchecked")
- public static Command createUpdateEnclosingInteractionCommand(MessageOccurrenceSpecification movedMos, Point newLocation, GraphicalEditPart editPart) {
-
- // // calculate new bounds for the execution specification
- // Rectangle absoluteNewBounds = executionSpecificationEP.getFigure().getBounds().getCopy();
- //
- // executionSpecificationEP.getFigure().getParent().translateToAbsolute(absoluteNewBounds);
- //
- // absoluteNewBounds.translate(moveDelta);
- // absoluteNewBounds.resize(sizeDelta);
- //
- // int xCenter = absoluteNewBounds.getCenter().x;
- //
- // Rectangle top = new Rectangle(xCenter, absoluteNewBounds.y, 0, 0);
- // Rectangle bottom = new Rectangle(xCenter, absoluteNewBounds.bottom(), 0, 0);
- //
- // // associate es with its bounds, and start and finish event with the top and bottom of the bounds
- HashMap<InteractionFragment, Rectangle> iftToCheckForUpdate = new HashMap<InteractionFragment, Rectangle>();
- //
- // ExecutionSpecification es = (ExecutionSpecification)executionSpecificationEP.resolveSemanticElement();
-
- iftToCheckForUpdate.put(movedMos, new Rectangle(newLocation, new Dimension()));
-
- // iftToCheckForUpdate.put(es.getStart(), top);
- //
- // iftToCheckForUpdate.put(es.getFinish(), bottom);
- //
- // List<ConnectionEditPart> sourceConnectionEPs = executionSpecificationEP.getSourceConnections();
- //
- // // find possible ifts associated with messages connected to the moved es
- // for(ConnectionEditPart sourceConnectionEP : sourceConnectionEPs) {
- // EObject elem = sourceConnectionEP.getNotationView().getElement();
- //
- // // for connections, messages have ends that can be ift but don't have theirs own edit parts
- // // => use anchors to determine position
- // if(elem instanceof Message) {
- // Message msg = (Message)elem;
- // MessageEnd sendEvent = msg.getSendEvent();
- // if(sendEvent instanceof InteractionFragment) {
- // Connection msgFigure = sourceConnectionEP.getConnectionFigure();
- //
- // Point sourcePoint = msgFigure.getSourceAnchor().getLocation(msgFigure.getTargetAnchor().getReferencePoint());
- //
- // iftToCheckForUpdate.put((InteractionFragment)sendEvent, new Rectangle(sourcePoint.x + moveDelta.x, sourcePoint.y + moveDelta.y, 0, 0));
- // }
- // }
- // }
- //
- // List<ConnectionEditPart> targetConnectionEPs = executionSpecificationEP.getTargetConnections();
- //
- // for(ConnectionEditPart targetConnectionEP : targetConnectionEPs) {
- // EObject elem = targetConnectionEP.getNotationView().getElement();
- //
- // if(elem instanceof Message) {
- // Message msg = (Message)elem;
- // MessageEnd receiveEvent = msg.getReceiveEvent();
- // if(receiveEvent instanceof InteractionFragment) {
- // Connection msgFigure = targetConnectionEP.getConnectionFigure();
- //
- // Point targetPoint = msgFigure.getTargetAnchor().getLocation(msgFigure.getSourceAnchor().getReferencePoint());
- //
- // iftToCheckForUpdate.put((InteractionFragment)receiveEvent, new Rectangle(targetPoint.x + moveDelta.x, targetPoint.y + moveDelta.y, 0, 0));
- // }
- // }
- // }
-
- CompoundCommand cmd = new CompoundCommand();
-
- for(Map.Entry<InteractionFragment, Rectangle> entry : iftToCheckForUpdate.entrySet()) {
- InteractionFragment newEnclosingInteraction = findInteractionFragmentContainerAt(entry.getValue(), editPart);
- if(newEnclosingInteraction != null) {
- cmd.add(new ICommandProxy(getSetEnclosingInteractionCommand(editPart.getEditingDomain(), entry.getKey(), newEnclosingInteraction)));
- }
- }
-
- if(!cmd.isEmpty()) {
- return cmd;
- } else {
- return null;
- }
- }
-
- /**
- * Create a command to update the enclosing interaction of an execution specification according to its new bounds.
- *
- * @param executionSpecificationEP
- * the edit part of the execution specification
- * @param absoluteNewBounds
- * the new absolute bounds
- * @return the command or null if nothing changes
- */
- @SuppressWarnings("unchecked")
- public static Command createUpdateEnclosingInteractionCommand(ShapeNodeEditPart executionSpecificationEP, Point moveDelta, Dimension sizeDelta) {
-
- // calculate new bounds for the execution specification
- Rectangle absoluteNewBounds = executionSpecificationEP.getFigure().getBounds().getCopy();
-
- executionSpecificationEP.getFigure().getParent().translateToAbsolute(absoluteNewBounds);
-
- absoluteNewBounds.translate(moveDelta);
- absoluteNewBounds.resize(sizeDelta);
-
- int xCenter = absoluteNewBounds.getCenter().x;
-
- Rectangle top = new Rectangle(xCenter, absoluteNewBounds.y, 0, 0);
- Rectangle bottom = new Rectangle(xCenter, absoluteNewBounds.bottom(), 0, 0);
-
- // associate es with its bounds, and start and finish event with the top and bottom of the bounds
- HashMap<InteractionFragment, Rectangle> iftToCheckForUpdate = new HashMap<InteractionFragment, Rectangle>();
-
- ExecutionSpecification es = (ExecutionSpecification)executionSpecificationEP.resolveSemanticElement();
-
- iftToCheckForUpdate.put(es, absoluteNewBounds);
-
- iftToCheckForUpdate.put(es.getStart(), top);
-
- iftToCheckForUpdate.put(es.getFinish(), bottom);
-
- List<ConnectionEditPart> sourceConnectionEPs = executionSpecificationEP.getSourceConnections();
-
- // find possible ifts associated with messages connected to the moved es
- for(ConnectionEditPart sourceConnectionEP : sourceConnectionEPs) {
- EObject elem = sourceConnectionEP.getNotationView().getElement();
-
- // for connections, messages have ends that can be ift but don't have theirs own edit parts
- // => use anchors to determine position
- if(elem instanceof Message) {
- Message msg = (Message)elem;
- MessageEnd sendEvent = msg.getSendEvent();
- if(sendEvent instanceof InteractionFragment) {
- Connection msgFigure = sourceConnectionEP.getConnectionFigure();
-
- Point sourcePoint = msgFigure.getSourceAnchor().getLocation(msgFigure.getTargetAnchor().getReferencePoint());
-
- iftToCheckForUpdate.put((InteractionFragment)sendEvent, new Rectangle(sourcePoint.x + moveDelta.x, sourcePoint.y + moveDelta.y, 0, 0));
- }
- }
- }
-
- List<ConnectionEditPart> targetConnectionEPs = executionSpecificationEP.getTargetConnections();
-
- for(ConnectionEditPart targetConnectionEP : targetConnectionEPs) {
- EObject elem = targetConnectionEP.getNotationView().getElement();
-
- if(elem instanceof Message) {
- Message msg = (Message)elem;
- MessageEnd receiveEvent = msg.getReceiveEvent();
- if(receiveEvent instanceof InteractionFragment) {
- Connection msgFigure = targetConnectionEP.getConnectionFigure();
-
- Point targetPoint = msgFigure.getTargetAnchor().getLocation(msgFigure.getSourceAnchor().getReferencePoint());
-
- iftToCheckForUpdate.put((InteractionFragment)receiveEvent, new Rectangle(targetPoint.x + moveDelta.x, targetPoint.y + moveDelta.y, 0, 0));
- }
- }
- }
-
- CompoundCommand cmd = new CompoundCommand();
-
- for(Map.Entry<InteractionFragment, Rectangle> entry : iftToCheckForUpdate.entrySet()) {
- InteractionFragment newEnclosingInteraction = findInteractionFragmentContainerAt(entry.getValue(), executionSpecificationEP);
- if(newEnclosingInteraction != null) {
- cmd.add(new ICommandProxy(getSetEnclosingInteractionCommand(executionSpecificationEP.getEditingDomain(), entry.getKey(), newEnclosingInteraction)));
- }
- }
-
- if(!cmd.isEmpty()) {
- return cmd;
- } else {
- return null;
- }
- }
-
- /**
- * Find the edit part a connection should be reconnected to at a given reference point on a lifeline
- *
- * @param lifelinePart
- * lifeline part on which the reconnection must be performed
- * @param referencePoint
- * the reference point
- * @return lifeline or execution specification edit part to reconnect to (the most external in the lifeline)
- */
- public static GraphicalEditPart findPartToReconnectTo(LifelineEditPart lifelinePart, Point referencePoint) {
- Rectangle absoluteLifelineBounds = getAbsoluteBounds(lifelinePart);
- // inspect children nodes of lifeline
- List<?> children = lifelinePart.getChildren();
- GraphicalEditPart adequateExecutionPart = null;
- int maxDeltaWithMiddle = 0;
- for(Object child : children) {
- // children executions
- if(child instanceof ActionExecutionSpecificationEditPart || child instanceof BehaviorExecutionSpecificationEditPart || child instanceof CombinedFragment2EditPart) {
- GraphicalEditPart childPart = (GraphicalEditPart)child;
- Rectangle absoluteBounds = getAbsoluteBounds(childPart);
- // enlarge absolute bounds to contain also the right and bottom edges.
- absoluteBounds.expand(1, 1);
- if(absoluteBounds.contains(referencePoint)) {
- // this is an adequate execution part, take the most external one
- int deltaWithMiddle = Math.abs(absoluteBounds.getTop().x - absoluteLifelineBounds.getTop().x);
- if(deltaWithMiddle >= maxDeltaWithMiddle) {
- maxDeltaWithMiddle = deltaWithMiddle;
- adequateExecutionPart = childPart;
- }
- }
- }
- }
- if(adequateExecutionPart != null) {
- return adequateExecutionPart;
- }
- return lifelinePart;
- }
-
- /**
- * Find the range of possible locations an occurrence specification should be drawn in.
- *
- * @param lifelineEditPart
- * the lifeline on which the occurrence specification appears.
- * @param occSpec
- * the occurrence specification to find locations for.
- * @return rectangle within which the occurrence specification must be drawn (width is not significative)
- */
- public static Rectangle findPossibleLocationsForEvent(LifelineEditPart lifelineEditPart, OccurrenceSpecification occSpec) {
- // at least, we know the event is in the drawn lifeline
- Rectangle result = lifelineEditPart.getContentPane().getBounds().getCopy();
- lifelineEditPart.getFigure().translateToAbsolute(result);
-
-
- // find the containing pane
- IGraphicalEditPart containerPart = findDrawnContainerEditPart(lifelineEditPart, occSpec);
- IFigure drawnContentPane = getContentPaneThatCanContainFragments(containerPart);
- if(drawnContentPane != null) {
- // content pane is the smallest drawn owning rectangle
- Rectangle bounds = drawnContentPane.getBounds().getCopy();
- drawnContentPane.getParent().translateToAbsolute(bounds);
- // intersect with the lifeline's content
- result.intersect(bounds);
- }
-
- // we must search surrounding interaction fragments within uppestContainerToSearchInto
- EObject uppestContainerToSearchInto = containerPart.resolveSemanticElement();
-
- InteractionFragment after = InteractionFragmentHelper.findNextFragment(occSpec, uppestContainerToSearchInto);
- boolean foundNextFragment = false;
- while(!foundNextFragment && after != null) {
- Point bottom = findLocationOfEvent(lifelineEditPart, after);
- if(bottom != null && result.contains(bottom)) {
- int diff = bottom.y - result.bottom();
- result.resize(0, diff);
- foundNextFragment = true;
- } else {
- // fragment not represented on lifeline, search next fragment
- after = InteractionFragmentHelper.findNextFragment(after, uppestContainerToSearchInto);
- }
- }
- InteractionFragment before = InteractionFragmentHelper.findPreviousFragment(occSpec, uppestContainerToSearchInto);
- boolean foundPreviousFragment = false;
- while(!foundPreviousFragment && before != null) {
- Point top = findLocationOfEvent(lifelineEditPart, before);
- if(top != null && result.contains(top)) {
- int diff = top.y - result.y;
- result.translate(0, diff);
- result.resize(0, -diff);
- foundPreviousFragment = true;
- /*
- * In case before is contained in an interaction operand or
- * combined fragment which does not contain the searched event,
- * we must also take in account the bottom border of this node.
- */
- reduceByNodeContainingBefore(result, before, occSpec, lifelineEditPart);
- } else {
- // fragment not represented on lifeline, search next fragment
- before = InteractionFragmentHelper.findPreviousFragment(before, uppestContainerToSearchInto);
- }
- }
- return result;
- }
-
- /**
- * Reduce the possible bounds by removing the area of an eventual interaction operand or combined fragment which contains the fragment "before"
- * and not the occurrence specification for which we search a location.
- *
- * @param possibleBounds
- * bounds to reduce, in which the location will be possible
- * @param before
- * the fragment which happens before
- * @param occSpec
- * the occurrence specification for which we search a location
- * @param lifelineEditPart
- * the lifeline on which the occurrence specification appears.
- */
- private static void reduceByNodeContainingBefore(Rectangle possibleBounds, InteractionFragment before, OccurrenceSpecification occSpec, LifelineEditPart lifelineEditPart) {
- Element eventualNodeElement = before;
- // inspect each container of before, until it is common with occSpec
- while(!EcoreUtil.isAncestor(eventualNodeElement, occSpec)) {
- // test if eventualNodeElement has bounds excluding occSpec
- // search for the eventualNodeElement's edit part
- List<View> views = DiagramEditPartsUtil.findViews(eventualNodeElement, lifelineEditPart.getViewer());
- for(View view : views) {
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelineEditPart);
- // test if edit part is an adequate node
- if(part instanceof IGraphicalEditPart && getContentPaneThatCanContainFragments(part) != null) {
- Rectangle bounds = getAbsoluteBounds((IGraphicalEditPart)part);
- // reduce so that the bounds are excluded
- int newPossibleTop = bounds.bottom();
- if(possibleBounds.y < newPossibleTop) {
- int diff = newPossibleTop - possibleBounds.y;
- possibleBounds.translate(0, diff);
- possibleBounds.resize(0, -diff);
- }
- }
- }
- eventualNodeElement = eventualNodeElement.getOwner();
- }
- }
-
- /**
- * Get the content pane of an edit part that can directly or indirectly contain interaction fragments (this excludes lifeline, which references)
- *
- * @param containerPart
- * container edit part
- * @return its content pane if the container can contain fragments, null otherwise.
- */
- private static IFigure getContentPaneThatCanContainFragments(EditPart containerPart) {
- // test all owner edit parts which can contain an interaction fragment
- if(containerPart instanceof InteractionOperandEditPart) {
- return ((InteractionOperandEditPart)containerPart).getContentPane();
- } else if(containerPart instanceof CombinedFragmentEditPart) {
- return ((CombinedFragmentEditPart)containerPart).getContentPane();
- } else if(containerPart instanceof CombinedFragment2EditPart) {
- return ((CombinedFragment2EditPart)containerPart).getContentPane();
- } else if(containerPart instanceof ContinuationEditPart) {
- return ((ContinuationEditPart)containerPart).getContentPane();
- } else if(containerPart instanceof InteractionUseEditPart) {
- return ((InteractionUseEditPart)containerPart).getContentPane();
- } else if(containerPart instanceof InteractionEditPart) {
- return ((InteractionEditPart)containerPart).getContentPane();
- }
- return null;
- }
-
- /**
- * Find the smallest drawn edit part containing the occurrence specification.
- *
- * @param lifelineEditPart
- * support lifeline edit part
- * @param occSpec
- * occurrence specification to localize
- * @return a drawn edit part which element contains the occurrence specification or null
- */
- private static IGraphicalEditPart findDrawnContainerEditPart(LifelineEditPart lifelineEditPart, OccurrenceSpecification occSpec) {
- // find containing drawn edit parts
- Element owner = occSpec.getOwner();
- while(owner != null) {
- // search for the owner's edit part
- List<View> views = DiagramEditPartsUtil.findViews(owner, lifelineEditPart.getViewer());
- for(View view : views) {
- EditPart part = DiagramEditPartsUtil.getEditPartFromView(view, lifelineEditPart);
- // test if edit part can contain the occurrence specification
- if(part instanceof IGraphicalEditPart && getContentPaneThatCanContainFragments(part) != null) {
- return (IGraphicalEditPart)part;
- }
- }
- owner = owner.getOwner();
- }
- return null;
- }
-
- /**
- * Check whether the Lifeline is Create Message's target node
- * @param lifelineEP
- * @return boolean
- */
- public static boolean isCreateMessageEndLifeline(LifelineEditPart lifelineEP){
- List<Object> targetConnections = lifelineEP.getTargetConnections();
- if(targetConnections!=null && targetConnections.size()>0){
- for(int i = 0;i<targetConnections.size();i++){
- Object connection = targetConnections.get(i);
- if(connection instanceof Message4EditPart){
- return true;
- }
- }
- }
- return false;
- }
-
-
- /**
- * Find Time Observations editpart which are related to specific OccurenceSpecification
- * @param lifelinePart
- * @param oss
- * @return List<TimeObservationLabelEditPart>
- */
- public static List<TimeObservationLabelEditPart> findOccurenceSpecificationRelatedTimeObservationPart(LifelineEditPart lifelinePart,List<OccurrenceSpecification> oss){
- List<TimeObservationLabelEditPart> list = new ArrayList<TimeObservationLabelEditPart>();
- if(oss == null || oss.size() == 0){
- return list;
- }
- if(lifelinePart!=null&&lifelinePart.getTargetConnections().size()>0){
- for(Object targetConnection : lifelinePart.getTargetConnections()){
- if(targetConnection instanceof ObservationLinkEditPart){
- ObservationLinkEditPart observationLinkEditPart = (ObservationLinkEditPart)targetConnection;
- if(observationLinkEditPart.getSource() instanceof TimeObservationLabelEditPart){
- TimeObservationLabelEditPart source = (TimeObservationLabelEditPart)observationLinkEditPart.getSource();
- EObject timeElement = source.resolveSemanticElement();
- if(timeElement instanceof TimeObservation) {
- if(oss.contains(((TimeObservation)timeElement).getEvent())) {
- list.add(source);
- }
- }
- }
- }
- }
- }
- return list;
- }
-
- /**
- * Find Time Observations editpart which are related to specific OccurenceSpecification
- * @param lifelinePart
- * @param os
- * @return List<TimeObservationLabelEditPart>
- */
- public static List<TimeObservationLabelEditPart> findOccurenceSpecificationRelatedTimeObservationPart(LifelineEditPart lifelinePart,OccurrenceSpecification os){
- List<OccurrenceSpecification> oss = new ArrayList<OccurrenceSpecification>();
- oss.add(os);
- return findOccurenceSpecificationRelatedTimeObservationPart(lifelinePart, oss);
- }
-
- /**
- * Find specific editpart by semantic model
- * @param editPart
- * @param targetElement
- * @param targetClass
- * @return EditPart
- */
- public static EditPart getEditPart(EditPart editPart,
- EObject targetElement, Class targetClass) {
- if (editPart == null || targetElement == null || targetClass == null)
- return null;
- Map<?, ?> map = editPart.getViewer().getEditPartRegistry();
- for (Entry<?, ?> entry : map.entrySet()) {
- Object key = entry.getKey();
- if (!(key instanceof View)) {
- continue;
- }
- View view = (View) key;
- EObject tempElement = view.getElement();
- if (targetElement.equals(tempElement)) {
- Object value = entry.getValue();
- if (value.getClass() == targetClass) {
- return (EditPart) value;
- }
- }
- }
- return null;
- }
-
- /**
- * Intall observation link policy to specific editpart
- * @param editPart
- */
- public static void installObservationLinkPolicy(EditPart editPart) {
- String editPolicy = "observationlink";
- if (editPart instanceof LifelineEditPart
- || editPart instanceof TimeObservationLabelEditPart) {
- editPart.installEditPolicy(editPolicy,
- new ObservationLinkPolicy(editPart));
- }
- if (editPart instanceof DurationObservationEditPart) {
- editPart.installEditPolicy(editPolicy,
- new ObservationLinkPolicy(editPart));
- }
- if (editPart instanceof MessageEditPart
- || editPart instanceof Message2EditPart
- || editPart instanceof Message3EditPart
- || editPart instanceof Message4EditPart
- || editPart instanceof Message5EditPart
- || editPart instanceof Message6EditPart
- || editPart instanceof Message7EditPart) {
- editPart.installEditPolicy(editPolicy,
- new ObservationLinkPolicy(editPart));
- } else if (editPart instanceof MessageNameEditPart
- || editPart instanceof MessageName2EditPart
- || editPart instanceof MessageName3EditPart
- || editPart instanceof MessageName4EditPart
- || editPart instanceof MessageName5EditPart
- || editPart instanceof MessageName6EditPart
- || editPart instanceof MessageName7EditPart) {
- editPart.getParent().installEditPolicy(editPolicy,
- new ObservationLinkPolicy(editPart));
- } else if (editPart instanceof MessageSyncAppliedStereotypeEditPart
- || editPart instanceof MessageAsyncAppliedStereotypeEditPart
- || editPart instanceof MessageReplyAppliedStereotypeEditPart
- || editPart instanceof MessageCreateAppliedStereotypeEditPart
- || editPart instanceof MessageDeleteAppliedStereotypeEditPart
- || editPart instanceof MessageLostAppliedStereotypeEditPart
- || editPart instanceof MessageFoundAppliedStereotypeEditPart) {
- editPart.getParent().installEditPolicy(editPolicy,
- new ObservationLinkPolicy(editPart));
- }
- }
-
-}

Back to the top