diff options
| author | Laurent Redor | 2018-01-05 09:14:11 +0000 |
|---|---|---|
| committer | Laurent Redor | 2018-01-12 16:43:52 +0000 |
| commit | e160855597f3220d3b4769419e3a1ae39a3a2a6c (patch) | |
| tree | 06a92103e0f2d7540f3f9add398c0878895e41c1 | |
| parent | 533362d409704388f1bc34e2c158ca3b98e2f135 (diff) | |
| download | org.eclipse.sirius-e160855597f3220d3b4769419e3a1ae39a3a2a6c.tar.gz org.eclipse.sirius-e160855597f3220d3b4769419e3a1ae39a3a2a6c.tar.xz org.eclipse.sirius-e160855597f3220d3b4769419e3a1ae39a3a2a6c.zip | |
[529148] Add action to insert vertical blank space in sequence diagram
With this commit, it is now possible to insert vertical blank space in
sequence diagram by using a drag'n'drop in the ruler grid with Ctrl key
pressed.
In future, to allow insertion of horizontal blank space in sequence
diagram and, vertical and horizontal blank space in standard diagram,
the methods
SequenceEMFCommandFactory.buildInsertHorizontalBlankSpaceCommand(DDiagram,
int,
int)
UndoRedoCapableEMFCommandFactory.buildInsertVerticalBlankSpaceCommand(DDiagram,
int, int),
UndoRedoCapableEMFCommandFactory.buildInsertHorizontalBlankSpaceCommand(DDiagram,
int, int) will have to be implemented.
This commit uses a new SiriusRulerComposite to have a specific
RulerEditPartFactory to instantiate a specific SiriusRulerEditPart to
finally enable a specific SimpleDragTracker when Ctrl key is pressed.
This SimpleDragTracker, SiriusRulerDragTracker, draws the feedback and
executes the command returned by the SiriusRulerEditPart.
The SiriusRulerEditPart delegates the creation of the command to
IDiagramCommandFactory.
Currently, only insertion of vertical blank space in sequence diagram is
implemented.
Bug: 529148
Change-Id: I06e6a45eb24e93f955c8aa28c715ef0b869e9068
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
20 files changed, 543 insertions, 13 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/command/SequenceEMFCommandFactory.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/command/SequenceEMFCommandFactory.java index efb6a67897..08f6099aad 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/command/SequenceEMFCommandFactory.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/edit/command/SequenceEMFCommandFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES. * 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 @@ -10,20 +10,25 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.command; +import java.util.Collections; + import org.eclipse.emf.common.command.Command; import org.eclipse.emf.common.command.CompoundCommand; import org.eclipse.emf.common.command.IdentityCommand; import org.eclipse.emf.common.command.UnexecutableCommand; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.DDiagramElement; import org.eclipse.sirius.diagram.sequence.SequenceDDiagram; import org.eclipse.sirius.diagram.sequence.business.internal.elements.AbstractNodeEvent; +import org.eclipse.sirius.diagram.sequence.business.internal.elements.ISequenceEvent; import org.eclipse.sirius.diagram.sequence.business.internal.elements.Operand; import org.eclipse.sirius.diagram.sequence.business.internal.operation.FixGraphicalOrderingOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshGraphicalOrderingOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.RefreshSemanticOrderingsOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.SetVerticalRangeOperation; import org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation; +import org.eclipse.sirius.diagram.sequence.business.internal.operation.VerticalSpaceExpansion; import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.operation.ExecutionOperations; import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.part.ExecutionEditPart; import org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.part.OperandEditPart; @@ -81,6 +86,12 @@ public final class SequenceEMFCommandFactory extends UndoRedoCapableEMFCommandFa return result; } + @Override + public Command buildInsertVerticalBlankSpaceCommand(DDiagram diagram, int startY, int spaceToInsert) { + return CommandFactory.createRecordingCommand(sdep.getEditingDomain(), + new VerticalSpaceExpansion(sdep.getSequenceDiagram(), new Range(startY, startY + spaceToInsert), 0, Collections.<ISequenceEvent> emptyList())); + } + private Command getDeleteExecutionCommand(ExecutionEditPart executionPart, Command basicDelete) { TransactionalEditingDomain ted = sdep.getEditingDomain(); diff --git a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java index 81c7348667..72ec6ea66e 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java +++ b/plugins/org.eclipse.sirius.diagram.sequence.ui/src/org/eclipse/sirius/diagram/sequence/ui/tool/internal/util/DelegatingDiagramCommandFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2015 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2018 THALES GLOBAL SERVICES. * 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 @@ -354,4 +354,9 @@ public class DelegatingDiagramCommandFactory implements IDiagramCommandFactory { public UICallBack getUserInterfaceCallBack() { return baseFactory.getUserInterfaceCallBack(); } + + @Override + public Command buildInsertVerticalBlankSpaceCommand(DDiagram diagram, int startY, int spaceToInsert) { + return baseFactory.buildInsertVerticalBlankSpaceCommand(diagram, startY, spaceToInsert); + } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties index b81f735b33..37ec6a5d38 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram.ui/plugin.properties @@ -1,5 +1,5 @@ # ==================================================================== -# Copyright (c) 2007, 2017 THALES GLOBAL SERVICES. +# Copyright (c) 2007, 2018 THALES GLOBAL SERVICES. # 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 @@ -953,6 +953,7 @@ IDiagramOutlinePage_overviewTooltip = Overview Identifier_invalidNullObject = {0} cannot be null InitializeHiddenElementsCommand_label = Initialize hidden elements InitializeLayoutCommand_label = Initialize layout +InsertBlankSpace_cmdName = Insert blank space ItemProvider_elementBasedEdge = Element Based Edge ItemProvider_foregroundBackgroundLabel = {0} {1} to {2} ItemProvider_relationBasedEdge = Relation Based Edge diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java index 0d189a6cef..66a7aa23f3 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/DDiagramEditorImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2018 THALES GLOBAL SERVICES and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -64,7 +64,6 @@ import org.eclipse.gef.requests.ChangeBoundsRequest; import org.eclipse.gef.ui.actions.ActionRegistry; import org.eclipse.gef.ui.palette.PaletteViewer; import org.eclipse.gef.ui.parts.ScrollingGraphicalViewer; -import org.eclipse.gef.ui.rulers.RulerComposite; import org.eclipse.gmf.runtime.common.ui.action.IDisposableAction; import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker; import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds; @@ -1444,7 +1443,7 @@ public class DDiagramEditorImpl extends SiriusDiagramEditor implements DDiagramE * the parent composite */ protected void createOriginalGraphicalViewer(final Composite parent) { - setRulerComposite(new RulerComposite(parent, SWT.NONE)); + setRulerComposite(new SiriusRulerComposite(parent, SWT.NONE)); sGViewer = createScrollingGraphicalViewer(); sGViewer.createControl(getRulerComposite()); setGraphicalViewer(sGViewer); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerComposite.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerComposite.java index 07e8b4b4b0..9ef09d14dd 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerComposite.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerComposite.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2017 IBM Corporation and others. + * Copyright (c) 2003, 2018 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -65,7 +65,7 @@ import org.eclipse.swt.widgets.Listener; * property. * * Class copied from {@link RulerComposite} to associate a specific Sirius {@link RulerEditPartFactory} to the left - * ruler. + * ruler (see "SIRIUS CHANGED" comment in method {@link #createRulerContainer(int)}. * * @author Pratik Shah * @author Laurent Redor (lredor) @@ -170,7 +170,8 @@ public class SiriusRulerComposite extends RulerComposite { // Finish initializing the viewer viewer.setRootEditPart(new RulerRootEditPart(isHorizontal)); - viewer.setEditPartFactory(new RulerEditPartFactory(diagramViewer)); + // SIRIUS CHANGED : RulerEditPartFactory replaced by SiriusRulerEditPartFactory + viewer.setEditPartFactory(new SiriusRulerEditPartFactory(diagramViewer)); viewer.createControl(this); ((GraphicalEditPart) viewer.getRootEditPart()).getFigure().setBorder(new RulerBorder(isHorizontal)); viewer.setProperty(GraphicalViewer.class.toString(), diagramViewer); diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerDragTracker.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerDragTracker.java new file mode 100644 index 0000000000..b1782aac37 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerDragTracker.java @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.SharedCursors; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gef.editparts.ZoomManager; +import org.eclipse.gef.internal.ui.rulers.RulerDragTracker; +import org.eclipse.gef.internal.ui.rulers.RulerEditPart; +import org.eclipse.gef.tools.SimpleDragTracker; +import org.eclipse.sirius.diagram.ui.provider.Messages; +import org.eclipse.sirius.diagram.ui.tools.internal.figure.InsertBlankSpaceGuide; +import org.eclipse.swt.graphics.Cursor; + +/** + * A specific {@link RulerDragTracker} to insert vertical blank space instead of create guide. This + * {@link RulerDragTracker} is used when Ctrl key is pressed when user clicks in the ruler. + * + * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> + */ +@SuppressWarnings("restriction") +public class SiriusRulerDragTracker extends SimpleDragTracker { + /** + * The RulerEditPart associated to this drag tracker. + */ + protected RulerEditPart source; + + /** + * The location where the end-user starts to define the zone to insert blank space. + */ + private int startLocation; + + /** + * Same location as <code>startLocation</code> but with consideration of zoom (to correctly draw the feedback). + */ + private int startLocationForFeedback; + + /** + * The location where the end-user ends to define the zone to insert blank space. + */ + private int endLocation; + + /** + * The feedback figure representing the blank space to insert. + */ + private InsertBlankSpaceGuide blankSpaceGuide; + + /** + * Default constructor. + * + * @param source + * The RulerEditPart associated to this drag tracker. + */ + public SiriusRulerDragTracker(RulerEditPart source) { + this.source = source; + } + + @Override + protected Command getCommand() { + Command result = UnexecutableCommand.INSTANCE; + // The case (startLocation == 0 && endLocation == 0) corresponds to the case where the user do the first click + // (without moving). + if ((startLocation == 0 && endLocation == 0) || (startLocation != 0 && endLocation >= startLocation)) { + if (source.isHorizontal()) { + result = ((SiriusRulerEditPart) source).createInsertHorizontalBlankSpaceCommand(startLocation, endLocation - startLocation); + } else { + result = ((SiriusRulerEditPart) source).createInsertVerticalBlankSpaceCommand(startLocation, endLocation - startLocation); + } + } + return result; + } + + @Override + protected boolean handleButtonDown(int button) { + startLocation = getCurrentPosition(); + startLocationForFeedback = getCurrentPositionZoomed(); + return super.handleButtonDown(button); + } + + @Override + protected boolean handleDragInProgress() { + endLocation = getCurrentPosition(); + return super.handleDragInProgress(); + } + + /** + * Execute the command and clean up the recorded location. + * + * @see org.eclipse.gef.internal.ui.rulers.RulerDragTracker#handleButtonUp(int) + */ + @Override + protected boolean handleButtonUp(int button) { + boolean result = super.handleButtonUp(button); + // Clean up the recorded location. + startLocation = 0; + startLocationForFeedback = 0; + endLocation = 0; + return result; + } + + @Override + protected Cursor calculateCursor() { + if (getCommand().canExecute()) { + return source.isHorizontal() ? SharedCursors.SIZEWE : SharedCursors.SIZENS; + } + return SharedCursors.NO; + } + + @Override + protected void showSourceFeedback() { + if (blankSpaceGuide == null) { + blankSpaceGuide = new InsertBlankSpaceGuide(ColorConstants.blue, !source.isHorizontal()); + getFeedbackLayer().add(blankSpaceGuide); + } + Rectangle bounds = getFeedbackLayer().getBounds().getCopy(); + if (source.isHorizontal()) { + bounds.x = startLocationForFeedback; + bounds.width = getCurrentPositionZoomed() - startLocationForFeedback; + } else { + bounds.y = startLocationForFeedback; + bounds.height = getCurrentPositionZoomed() - startLocationForFeedback; + } + blankSpaceGuide.setBounds(bounds); + } + + @Override + protected void eraseSourceFeedback() { + if (blankSpaceGuide != null) { + getFeedbackLayer().remove(blankSpaceGuide); + blankSpaceGuide = null; + } + } + + /** + * Returns the layer used for displaying feedback. + * + * @return the feedback layer + */ + protected IFigure getFeedbackLayer() { + return ((SiriusRulerEditPart) source).getFeedbackLayer(); + } + + /** + * Return the current position in the ruler zoomed (ie if the location is 100 and the zoom is 200%, the returned + * value will be 200).<BR> + * Method copied from {@link org.eclipse.gef.internal.ui.rulers.RulerDragTracker#getCurrentPositionZoomed()}. + * + * @return the current position in the ruler. + */ + protected int getCurrentPositionZoomed() { + Point pt = getLocation(); + source.getFigure().translateToRelative(pt); + int position = source.isHorizontal() ? pt.x : pt.y; + return position; + } + + /** + * Return the current position in the ruler.<BR> + * Method copied from {@link org.eclipse.gef.internal.ui.rulers.RulerDragTracker#getCurrentPosition()}. + * + * @return the current position in the ruler. + */ + protected int getCurrentPosition() { + int position = getCurrentPositionZoomed(); + ZoomManager zoomManager = source.getZoomManager(); + if (zoomManager != null) { + position = (int) Math.round(position / zoomManager.getZoom()); + } + return position; + } + + @Override + protected String getCommandName() { + return Messages.InsertBlankSpace_cmdName; + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPart.java new file mode 100644 index 0000000000..9e396a2c0e --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPart.java @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor; + +import org.eclipse.draw2d.IFigure; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.DragTracker; +import org.eclipse.gef.LayerConstants; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gef.commands.UnexecutableCommand; +import org.eclipse.gef.editparts.LayerManager; +import org.eclipse.gef.internal.ui.rulers.RulerDragTracker; +import org.eclipse.gef.internal.ui.rulers.RulerEditPart; +import org.eclipse.gef.requests.SelectionRequest; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; +import org.eclipse.sirius.diagram.DDiagram; +import org.eclipse.sirius.diagram.Messages; +import org.eclipse.sirius.diagram.ui.tools.api.command.GMFCommandWrapper; +import org.eclipse.sirius.diagram.ui.tools.api.editor.DDiagramEditor; + +/** + * A specific {@link RulerEditPart} to use a specific {@link RulerDragTracker}, to insert blank space instead of create + * guide, if Ctrl key is pressed. + * + * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> + */ +@SuppressWarnings("restriction") +public class SiriusRulerEditPart extends RulerEditPart { + + /** + * Default constructor. + * + * @param model + * The primary model object that this EditPart represents + */ + public SiriusRulerEditPart(Object model) { + super(model); + } + + @Override + public DragTracker getDragTracker(Request request) { + DragTracker result = null; + if (request.getType().equals(REQ_SELECTION)) { + SelectionRequest selectionRequest = (SelectionRequest) request; + if (selectionRequest.getLastButtonPressed() != 1) { + result = null; + } else if (selectionRequest.isControlKeyPressed()) { + try { + if (isHorizontal()) { + createInsertHorizontalBlankSpaceCommand(0, 0); + } else { + createInsertVerticalBlankSpaceCommand(0, 0); + } + result = new SiriusRulerDragTracker(this); + } catch (UnsupportedOperationException e) { + // Do not return a SiriusRulerDragTracker in this case. + } + } + } + if (result == null) { + return super.getDragTracker(request); + } else { + return result; + } + } + + /** + * Create a command that inserts horizontal blank space in a diagram by shifting nodes. It is currently not + * implemented in Sirius core, probably done later. + * + * @param startLocation + * the initial location in pixel to insert blank space + * @param spaceToInsert + * the number of pixels to insert + * @return . + */ + public Command createInsertHorizontalBlankSpaceCommand(int startLocation, int spaceToInsert) { + return createInsertBlankSpaceCommand(startLocation, spaceToInsert, true); + } + + /** + * Create a command that inserts vertical blank space in a diagram by shifting nodes. + * + * @param startLocation + * the initial location in pixel to insert blank space + * @param spaceToInsert + * the number of pixels to insert + * @return . + */ + public Command createInsertVerticalBlankSpaceCommand(int startLocation, int spaceToInsert) { + return createInsertBlankSpaceCommand(startLocation, spaceToInsert, false); + } + + /** + * Create a command that inserts vertical blank space in a diagram by shifting nodes. + * + * @param startLocation + * the initial location in pixel to insert blank space + * @param spaceToInsert + * the number of pixels to insert + * @param horizontal + * true if the blank space must be inserted horizontally, false otherwise + * @return a command to add space. + */ + protected Command createInsertBlankSpaceCommand(int startLocation, int spaceToInsert, boolean horizontal) { + if (diagramViewer.getRootEditPart().getContents() instanceof IGraphicalEditPart) { + IGraphicalEditPart diagramEditPart = (IGraphicalEditPart) diagramViewer.getRootEditPart().getContents(); + TransactionalEditingDomain ted = diagramEditPart.getEditingDomain(); + Object property = diagramViewer.getProperty(DDiagramEditor.EDITOR_ID); + if (property instanceof DDiagramEditor) { + DDiagramEditor diagramEditor = (DDiagramEditor) property; + if (horizontal) { + // Currently not implemented. A new method buildInsertHorizontalBlankSpaceCommand must be added in + // IDiagramCommandFactory and implemented in UndoRedoCapableEMFCommandFactory for standard diagrams + // and in SequenceEMFCommandFactory for sequence diagrams. + throw new UnsupportedOperationException(Messages.UndoRedoCapableEMFCommandFactory_insertHorizontalBlankSpaceNotImplemented); + } else { + org.eclipse.emf.common.command.Command command = diagramEditor.getEmfCommandFactoryProvider().getCommandFactory(ted) + .buildInsertVerticalBlankSpaceCommand((DDiagram) diagramEditPart.getNotationView().getElement(), startLocation, spaceToInsert); + return new ICommandProxy(new GMFCommandWrapper(ted, command)); + } + } + } + return UnexecutableCommand.INSTANCE; + } + + + /** + * Returns the layer used for displaying feedback. + * + * @return the feedback layer + */ + public IFigure getFeedbackLayer() { + LayerManager lm = (LayerManager) diagramViewer.getEditPartRegistry().get(LayerManager.ID); + if (lm != null) { + return lm.getLayer(LayerConstants.FEEDBACK_LAYER); + } + return null; + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPartFactory.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPartFactory.java new file mode 100644 index 0000000000..c5c17dec22 --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/editor/SiriusRulerEditPartFactory.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.editor; + +import org.eclipse.gef.EditPart; +import org.eclipse.gef.GraphicalViewer; +import org.eclipse.gef.internal.ui.rulers.GuideEditPart; +import org.eclipse.gef.internal.ui.rulers.RulerEditPartFactory; + +/** + * A specific {@link RulerEditPartFactory} to instantiate a specific Sirius {@link GuideEditPart}. + * + * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> + */ +@SuppressWarnings("restriction") +public class SiriusRulerEditPartFactory extends RulerEditPartFactory { + + /** + * Default constructor. + * + * @param primaryViewer + * The associated graphical viewer. + */ + public SiriusRulerEditPartFactory(GraphicalViewer primaryViewer) { + super(primaryViewer); + } + + @Override + protected EditPart createRulerEditPart(EditPart parentEditPart, Object model) { + return new SiriusRulerEditPart(model); + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/InsertBlankSpaceGuide.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/InsertBlankSpaceGuide.java new file mode 100644 index 0000000000..cde6bf438b --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/figure/InsertBlankSpaceGuide.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2018 THALES GLOBAL SERVICES. + * 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: + * Obeo - initial API and implementation + *******************************************************************************/ +package org.eclipse.sirius.diagram.ui.tools.internal.figure; + +import org.eclipse.draw2d.Figure; +import org.eclipse.draw2d.Graphics; +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.swt.graphics.Color; + +/** + * A rectangle across the whole diagram, useful as feedback to insert blank space in diagram. + * + * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a> + */ +public class InsertBlankSpaceGuide extends Figure { + + private boolean horizontal = true; + + /** + * Creates a feedback figure with two horizontal guide placed at the given range. + * + * @param color + * the color of the line. + * @param horizontal + * true if this guide is horizontal, false otherwise. + */ + public InsertBlankSpaceGuide(Color color, boolean horizontal) { + setForegroundColor(color); + setBackgroundColor(color); + this.horizontal = horizontal; + } + + /** + * {@inheritDoc} + */ + @Override + protected void paintFigure(Graphics graphics) { + Rectangle rect = getBounds().getCopy(); + // Draw the starting line + if (horizontal) { + graphics.drawLine(getBounds().getTopLeft(), getBounds().getTopRight()); + } else { + graphics.drawLine(getBounds().getTopLeft(), getBounds().getBottomLeft()); + } + + // If the size is null, no need to fill it or to draw the bottom line. + // we have to reduce the height of the drawn rectangle to stay in the + // bounds of the figure. + if (horizontal && rect.height > 1 || !horizontal && rect.width > 1) { + if (horizontal) { + graphics.drawLine(rect.getBottomLeft(), rect.getBottomRight()); + } else { + graphics.drawLine(getBounds().getTopRight(), getBounds().getBottomRight()); + } + + // Fill rectangle with transparency + int alpha = graphics.getAlpha(); + graphics.setAlpha(25); + graphics.fillRectangle(rect); + graphics.setAlpha(alpha); + } + } +} diff --git a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java index 479e4c955b..926074fe07 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src/org/eclipse/sirius/diagram/ui/provider/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2017 Obeo and THALES GLOBAL SERVICES. + * Copyright (c) 2015, 2018 Obeo and THALES GLOBAL SERVICES. * 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 @@ -636,6 +636,9 @@ public final class Messages { public static String InitializeLayoutCommand_label; @TranslatableMessage + public static String InsertBlankSpace_cmdName; + + @TranslatableMessage public static String ItemProvider_elementBasedEdge; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.diagram/plugin.properties b/plugins/org.eclipse.sirius.diagram/plugin.properties index 3408ed85cd..80af09ce76 100644 --- a/plugins/org.eclipse.sirius.diagram/plugin.properties +++ b/plugins/org.eclipse.sirius.diagram/plugin.properties @@ -242,8 +242,12 @@ RevealDDiagramElementsLabel_revealLabel = Reveal label RevealDDiagramElementsLabel_revealLabels = Reveal labels SetEdgeActualMappingCommand_commandLabel = Set edge actual mapping UndoRedoCapableEMFCommandFactory_addDiagramVariableLabel = Add diagram variable +UndoRedoCapableEMFCommandFactory_addHorizontalSpaceNotImplemented = The addition of horizontal space is not implemented for this kind of diagram. +UndoRedoCapableEMFCommandFactory_addVerticalSpaceNotImplemented = The addition of vertical space is not implemented for this kind of diagram. UndoRedoCapableEMFCommandFactory_createNewDiagramLabel = Create new diagram UndoRedoCapableEMFCommandFactory_createRepresentationLabel = Create new representation +UndoRedoCapableEMFCommandFactory_insertHorizontalBlankSpaceNotImplemented = The insertion of horizontal blank space is not implemented for this kind of diagram. +UndoRedoCapableEMFCommandFactory_insertVerticalBlankSpaceNotImplemented = The insertion of vertical blank space is not implemented for this kind of diagram. UndoRedoCapableEMFCommandFactory_quickFixLabel = Quick fix UnpinElementsCommand_commandLabel = Unpin elements ValidStyleConstraint_validationErrorMsg = Conditional style {0} of {1} diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/command/IDiagramCommandFactory.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/command/IDiagramCommandFactory.java index cad3f1421f..1139cd0fa3 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/command/IDiagramCommandFactory.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/api/command/IDiagramCommandFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 20015 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES. * 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 @@ -457,4 +457,18 @@ public interface IDiagramCommandFactory extends ICommandFactory { * the context of the view. */ Command buildGenericToolCommandFromTool(EObject containerView, ToolDescription toolDesc); + + /** + * Create a command that shifts nodes to insert vertical blank space in a diagram. + * + * @param diagram + * the diagram in which insert blank space + * @param startX + * the initial location in pixel to insert blank space + * @param spaceToInsert + * the number of pixels to insert + * + * @return a command able to insert blank space (move all elements). + */ + Command buildInsertVerticalBlankSpaceCommand(DDiagram diagram, int startX, int spaceToInsert); } diff --git a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java index ac6f27d84d..0d293dbbac 100644 --- a/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java +++ b/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/tools/internal/command/UndoRedoCapableEMFCommandFactory.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2008, 2018 THALES GLOBAL SERVICES. * 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 @@ -665,4 +665,10 @@ public class UndoRedoCapableEMFCommandFactory extends AbstractCommandFactory imp builder.init(modelAccessor, domain, uiCallBack); return builder.buildCommand(); } + + @Override + public Command buildInsertVerticalBlankSpaceCommand(DDiagram diagram, int startY, int spaceToInsert) { + // Not implemented in "standard" diagram + throw new UnsupportedOperationException(Messages.UndoRedoCapableEMFCommandFactory_insertVerticalBlankSpaceNotImplemented); + } } diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/Messages.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/Messages.java index 15d0d24dad..e1bebc3315 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/Messages.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/Messages.java @@ -261,6 +261,12 @@ public final class Messages { public static String UndoRedoCapableEMFCommandFactory_createRepresentationLabel; @TranslatableMessage + public static String UndoRedoCapableEMFCommandFactory_insertHorizontalBlankSpaceNotImplemented; + + @TranslatableMessage + public static String UndoRedoCapableEMFCommandFactory_insertVerticalBlankSpaceNotImplemented; + + @TranslatableMessage public static String UndoRedoCapableEMFCommandFactory_quickFixLabel; @TranslatableMessage diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html index d81f0f09c8..24acbe8eaa 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.html @@ -126,6 +126,11 @@ </p> <h2 id="sirius6.0.0">Changes in Sirius 6.0.0</h2> <h3 id="UserVisibleChanges">User-Visible Changes</h3> + <ul> + <li><span class="label label-success">Added</span> A new feature allows user to insert vertical blank space in sequence diagram. You can refer to the + <a href="user/sequences/Sequence%20Diagrams.html#insert_vertical_blank_space">user documentation </a> for more details. + </li> + </ul> <h3 id="SpecifierVisibleChanges">Specifier-Visible Changes</h3> <h3 id="DeveloperVisibleChanges">Developer-Visible Changes</h3> <h4 id="Migrations">Migrations</h4> diff --git a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile index db23f36db4..9b0f85afea 100644 --- a/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile +++ b/plugins/org.eclipse.sirius.doc/doc/Release_Notes.textile @@ -8,6 +8,8 @@ h2(#sirius6.0.0). Changes in Sirius 6.0.0 h3. User-Visible Changes +* <span class="label label-success">Added</span> A new feature allows user to insert vertical blank space in sequence diagram. You can refer to the "user documentation ":user/sequences/Sequence%20Diagrams.html#insert_vertical_blank_space for more details. + h3. Specifier-Visible Changes h3. Developer-Visible Changes diff --git a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile index bcb641077c..d6310b0ae8 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile +++ b/plugins/org.eclipse.sirius.doc/doc/user/diagrams/Diagrams.textile @@ -42,7 +42,7 @@ h3. Managing Diagrams Opening existing diagrams and renaming or deleting them works exactly as for any other kind of representation. Refer to the general documentation about the _Modeling Project_ UI for details. -h4. Rulers & Grid +h4(#RulersGrid). Rulers & Grid Several behaviors concerning the diagram elements editing is conditioned by properties of the diagram accessible through the _Rulers & Grid_ tab of the _Properties_ view of the diagram. !images/properties_view_rulers_and_grid_tab.png! diff --git a/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.html b/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.html index 095f483752..7a0349d379 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.html +++ b/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.html @@ -24,6 +24,11 @@ </li> <li> <a href="#layout">Automatic Layout</a> + <ol style="list-style: disc;"> + <li> + <a href="#insert_vertical_blank_space">Manually insert vertical blank space</a> + </li> + </ol> </li> <li> <a href="#elements">Sequence Diagram Elements</a> @@ -135,6 +140,16 @@ <p>The <em>Arrange All</em> command which launches an automatic layout of all the elements on a diagram has been completely customized for sequence diagrams. Arranging a sequence diagram will keep the relative positions of all the elements, but reduce any un-needed vertical or horizontal spaces. All elements will be resized to the minimum size necessary, and “packed” towards the top-left corner of the diagram. This results in a diagram which uses the minimum space required to present all the elements, while keeping enough white-space between them to be easy to read. </p> + <h3 id="insert_vertical_blank_space">Manually insert vertical blank space</h3> + <p>It is also possible to manually insert vertical blank space to facilitate the organization of messages or to add new events in a sequence diagram. This feature is available on the vertical ruler by dragging the mouse with the Ctrl key pressed. + <br/>Below, an example where user inserts blank space before message m3: + <br/> + <img alt="Example where user inserts blank space before message m3" title="Example where user inserts blank space before message m3" border="0" src="images/insert_vertical_blank_space.png"/> + </p> + <p>To show ruler, you need to check the option + <em>Show Ruler</em> as explained in + <a href="../diagrams/Diagrams.html#RulersGrid">Rulers & Grid</a> chapter. + </p> <h2 id="elements">Sequence Diagram Elements</h2> <p>This section presents each type of elements specific to sequence diagrams which are supported by Sirius, and their specificities (if any). Note that not all sequence diagrams will support all kinds of elements; this depends on the diagram’s configuration.</p> <h3 id="Lifelines">Life-lines</h3> diff --git a/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.textile b/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.textile index cb96af6e03..80ddcf0856 100644 --- a/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.textile +++ b/plugins/org.eclipse.sirius.doc/doc/user/sequences/Sequence Diagrams.textile @@ -43,6 +43,14 @@ h2(#layout). Automatic Layout The _Arrange All_ command which launches an automatic layout of all the elements on a diagram has been completely customized for sequence diagrams. Arranging a sequence diagram will keep the relative positions of all the elements, but reduce any un-needed vertical or horizontal spaces. All elements will be resized to the minimum size necessary, and "packed" towards the top-left corner of the diagram. This results in a diagram which uses the minimum space required to present all the elements, while keeping enough white-space between them to be easy to read. +h3(#insert_vertical_blank_space). Manually insert vertical blank space + +It is also possible to manually insert vertical blank space to facilitate the organization of messages or to add new events in a sequence diagram. This feature is available on the vertical ruler by dragging the mouse with the Ctrl key pressed. +Below, an example where user inserts blank space before message m3: +!images/insert_vertical_blank_space.png(Example where user inserts blank space before message m3)! + +To show ruler, you need to check the option _Show Ruler_ as explained in "Rulers & Grid":../diagrams/Diagrams.html#RulersGrid chapter. + h2(#elements). Sequence Diagram Elements This section presents each type of elements specific to sequence diagrams which are supported by Sirius, and their specificities (if any). Note that not all sequence diagrams will support all kinds of elements; this depends on the diagram's configuration. diff --git a/plugins/org.eclipse.sirius.doc/doc/user/sequences/images/insert_vertical_blank_space.png b/plugins/org.eclipse.sirius.doc/doc/user/sequences/images/insert_vertical_blank_space.png Binary files differnew file mode 100644 index 0000000000..6aeb0cef35 --- /dev/null +++ b/plugins/org.eclipse.sirius.doc/doc/user/sequences/images/insert_vertical_blank_space.png |
