use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
// Gather Model elements, relations
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
if (!archimateConcepts.contains(element)) {
archimateConcepts.add(element);
}
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
}
}
// Gather referenced diagram objects
for (IArchimateConcept archimateConcept : archimateConcepts) {
for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
diagramObjects.add(dc);
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
"\n\n" + Messages.DeleteFromModelAction_2)) {
return;
}
}
// Create commands
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
for (IArchimateConcept archimateConcept : archimateConcepts) {
if (archimateConcept instanceof IArchimateElement) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
} else if (archimateConcept instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
}
}
for (IDiagramModelComponent dc : diagramObjects) {
if (dc instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
compoundCommand.add(cmd);
} else if (dc instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
compoundCommand.add(cmd);
}
}
execute(compoundCommand);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DiagramEditorFindReplaceProvider method doRenameCommands.
void doRenameCommands(List<EditPart> editParts, List<String> newNames) {
// Must match sizes
if (editParts.size() != newNames.size() || editParts.isEmpty()) {
return;
}
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(Messages.DiagramEditorFindReplaceProvider_1);
for (int i = 0; i < editParts.size(); i++) {
INameable object = (INameable) editParts.get(i).getModel();
String newName = newNames.get(i);
compoundCommand.add(new EObjectFeatureCommand(NLS.bind(Messages.DiagramEditorFindReplaceProvider_0, object.getName()), object, IArchimatePackage.Literals.NAMEABLE__NAME, newName));
}
CommandStack stack = (CommandStack) ((IAdapter) editParts.get(0).getModel()).getAdapter(CommandStack.class);
if (stack != null) {
stack.execute(compoundCommand.unwrap());
}
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class BringForwardAction method createCommand.
private Command createCommand(List<?> selection) {
GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
CompoundCommand result = new CompoundCommand(Messages.BringForwardAction_0);
for (Object object : selection) {
if (object instanceof GraphicalEditPart) {
GraphicalEditPart editPart = (GraphicalEditPart) object;
Object model = editPart.getModel();
// This can happen if we do things wrong
if (viewer != editPart.getViewer()) {
// $NON-NLS-1$
System.err.println("Wrong selection for viewer in " + getClass());
}
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
if (model instanceof IDiagramModelObject) {
IDiagramModelObject diagramObject = (IDiagramModelObject) model;
IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
/*
* Parent can be null when objects are selected (with marquee tool) and transferred from one container
* to another and the Diagram Editor updates the enablement state of Actions.
*/
if (parent == null) {
continue;
}
List<IDiagramModelObject> modelChildren = parent.getChildren();
int originalPos = modelChildren.indexOf(diagramObject);
if (originalPos < modelChildren.size() - 1) {
result.add(new BringForwardCommand(parent, originalPos));
}
}
}
}
return result.unwrap();
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class ResetAspectRatioAction method createCommand.
private Command createCommand(List<?> objects) {
CompoundCommand result = new CompoundCommand();
for (Object object : objects) {
if (object instanceof DiagramImageEditPart) {
DiagramImageEditPart part = (DiagramImageEditPart) object;
IDiagramModelObject model = part.getModel();
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
IBounds modelBounds = model.getBounds().getCopy();
int currentHeight = modelBounds.getHeight();
int currentWidth = modelBounds.getWidth();
// Already set to default height and width
if (currentHeight == -1 && currentWidth == -1) {
continue;
}
// Get original default size
DiagramImageFigure figure = part.getFigure();
Dimension size = figure.getDefaultSize();
if (size.height == 0 || size.width == 0) {
continue;
}
float originalRatio = ((float) size.height / (float) size.width);
float currentRatio = ((float) currentHeight / (float) currentWidth);
// If the ratio is different within tolerance
if (Math.abs(originalRatio - currentRatio) > 0.01) {
int width = currentWidth;
int height = currentHeight;
if (currentWidth < currentHeight) {
width = (int) (currentHeight / originalRatio);
} else {
height = (int) (currentWidth * originalRatio);
}
modelBounds.setWidth(width);
modelBounds.setHeight(height);
Command cmd = new SetConstraintObjectCommand(model, modelBounds);
result.add(cmd);
}
}
}
return result.unwrap();
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DiagramCommandFactory method createDeleteDiagramConnectionCommand.
/**
* @param connection
* @return A new Delete Diagram Connection Command
*/
public static Command createDeleteDiagramConnectionCommand(IDiagramModelConnection connection) {
CompoundCommand result = new CompoundCommand();
__addDeleteDiagramConnectionCommands(connection, result);
return result.unwrap();
}
Aggregations