blob: 0bd660ec500e4fdd4c124ab2f83b8b8976287c9c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*******************************************************************************
* Copyright (c) 2014 THALES GLOBAL SERVICES.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.internal.edit.commands;
import java.util.HashSet;
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.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
import org.eclipse.gmf.runtime.notation.Diagram;
import org.eclipse.gmf.runtime.notation.Edge;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.ui.internal.operation.CenterEdgeEndModelChangeOperation;
/**
* After an automatic layout, the edge centering could be broken. This command
* executes {@link CenterEdgeEndModelChangeOperation} on each edges potentially
* impacted by the given containerEditPart layout.
*
* @author Florian Barbin
*
*/
public class CenterEdgeLayoutCommand extends AbstractTransactionalCommand {
private GraphicalEditPart editPart;
/**
* Constructor.
*
* @param graphicalEditPart
* the graphical edit part layouted.
*/
public CenterEdgeLayoutCommand(GraphicalEditPart graphicalEditPart) {
super(graphicalEditPart.getEditingDomain(), "", null); //$NON-NLS-1$
editPart = graphicalEditPart;
}
@Override
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
Object model = editPart.getModel();
if (model instanceof View) {
View view = (View) model;
Set<Edge> edges = new HashSet<Edge>();
// if the entire diagram is layouted.
if (view instanceof Diagram) {
edges.addAll(((Diagram) view).getEdges());
}
// we select only related edges otherwise.
else {
ViewUtil.getAllRelatedEdgesForView(view, edges);
}
for (Edge edge : edges) {
CenterEdgeEndModelChangeOperation centerEdgeEndModelChangeOperation = new CenterEdgeEndModelChangeOperation(edge, false);
centerEdgeEndModelChangeOperation.execute();
}
}
return CommandResult.newOKCommandResult();
}
@Override
public void dispose() {
editPart = null;
super.dispose();
}
}
|