use of org.eclipse.gef.commands.CompoundCommand in project whole by wholeplatform.
the class WholeDragEditPartsTracker method getCommand.
protected Command getCommand() {
if (!isShareActive())
return super.getCommand();
CompoundCommand command = new CompoundCommand();
// $NON-NLS-1$
command.setDebugLabel("Drag Object Tracker");
Request request = getTargetRequest();
request.setType(REQ_SHARE);
if (!isMove()) {
if (getTargetEditPart() == null)
command.add(UnexecutableCommand.INSTANCE);
else
command.add(getTargetEditPart().getCommand(getTargetRequest()));
}
return command;
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DiagramEditorFindReplaceProvider method doReplaceStringCommands.
void doReplaceStringCommands(List<EditPart> editParts, List<String> newTexts) {
// Must match sizes
if (editParts.size() != newTexts.size() || editParts.isEmpty()) {
return;
}
CommandStack stack = (CommandStack) ((IAdapter) editParts.get(0).getModel()).getAdapter(CommandStack.class);
if (stack == null) {
return;
}
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(Messages.DiagramEditorFindReplaceProvider_0);
for (int i = 0; i < editParts.size(); i++) {
EditPart editPart = editParts.get(i);
String newText = newTexts.get(i);
Command command = createCommand(editPart, newText);
if (command != null) {
compoundCommand.add(command);
}
}
stack.execute(compoundCommand.unwrap());
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
Set<IArchimateConcept> archimateConcepts = new HashSet<IArchimateConcept>();
// Gather referenced model concepts
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
archimateConcepts.add(element);
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
archimateConcepts.add(relation);
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
archimateConcepts.add(r);
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
archimateConcepts.add(relation);
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
archimateConcepts.add(r);
}
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts)) {
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) {
// Element
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
// Diagram Model Objects
for (IDiagramModelObject dmo : ((IArchimateElement) archimateConcept).getReferencingDiagramObjects()) {
cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand(dmo);
compoundCommand.add(cmd);
}
} else if (archimateConcept instanceof IArchimateRelationship) {
// Relationship
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
// Diagram Model Connections
for (IDiagramModelArchimateConnection dmc : ((IArchimateRelationship) archimateConcept).getReferencingDiagramConnections()) {
cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand(dmc);
compoundCommand.add(cmd);
}
}
}
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
execute(compoundCommand);
}
});
}
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 CreateDiagramConnectionCommand method createBendPointsForCircularConnectionCommand.
/**
* Create a Command for adding bendpoints to a circular connection
* So it looks good
*/
public static Command createBendPointsForCircularConnectionCommand(IDiagramModelConnection connection) {
// Only works for IDiagramModelObject as source and target objects not for connections
if (!(connection.getSource() instanceof IDiagramModelObject) && !(connection.getTarget() instanceof IDiagramModelObject)) {
return null;
}
IDiagramModelObject source = (IDiagramModelObject) connection.getSource();
IDiagramModelObject target = (IDiagramModelObject) connection.getTarget();
int width = source.getBounds().getWidth();
if (width == -1) {
width = 100;
}
int height = target.getBounds().getHeight();
if (height == -1) {
height = 60;
}
width = (int) Math.max(100, width * 0.6);
height = (int) Math.max(60, height * 0.6);
CompoundCommand result = new CompoundCommand();
CreateBendpointCommand cmd = new CreateBendpointCommand();
cmd.setDiagramModelConnection(connection);
cmd.setRelativeDimensions(new Dimension(width, 0), new Dimension(width, 0));
result.add(cmd);
cmd = new CreateBendpointCommand();
cmd.setDiagramModelConnection(connection);
cmd.setRelativeDimensions(new Dimension(width, height), new Dimension(width, height));
result.add(cmd);
cmd = new CreateBendpointCommand();
cmd.setDiagramModelConnection(connection);
cmd.setRelativeDimensions(new Dimension(0, height), new Dimension(0, height));
result.add(cmd);
return result;
}
Aggregations