use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class DeleteCommandHandler method createCommands.
/**
* Create the Delete Commands
*/
private void createCommands() {
/*
* We need to ensure that the Delete Diagram Model Commands are called first in order to close
* any open diagram editors before removing their models from parent folders.
*/
for (Object object : fObjectsToDelete) {
if (object instanceof IDiagramModel) {
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
if (compoundCommand != null) {
Command cmd = new DeleteDiagramModelCommand((IDiagramModel) object);
compoundCommand.add(cmd);
} else {
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in " + getClass());
}
}
}
/*
* Then the other types
*/
for (Object object : fObjectsToDelete) {
if (object instanceof IDiagramModel) {
// already done
continue;
}
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
if (compoundCommand == null) {
// sanity check
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in " + getClass());
continue;
}
if (object instanceof IFolder) {
Command cmd = new DeleteFolderCommand((IFolder) object);
compoundCommand.add(cmd);
} else if (object instanceof IArchimateElement) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) object);
compoundCommand.add(cmd);
} else if (object instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) object);
compoundCommand.add(cmd);
} else if (object instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) object);
compoundCommand.add(cmd);
} else if (object instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) object);
compoundCommand.add(cmd);
}
}
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class RenameCommandHandler method getCompoundCommand.
/**
* Get, and if need be create, a CompoundCommand to which to add the object to be renamed command
*/
private static CompoundCommand getCompoundCommand(IAdapter object, Hashtable<CommandStack, CompoundCommand> commandMap) {
// Get the Command Stack registered to the object
CommandStack stack = (CommandStack) object.getAdapter(CommandStack.class);
if (stack == null) {
// $NON-NLS-1$
System.err.println("CommandStack was null in getCompoundCommand");
return null;
}
// Now get or create a Compound Command
CompoundCommand compoundCommand = commandMap.get(stack);
if (compoundCommand == null) {
compoundCommand = new NonNotifyingCompoundCommand(Messages.RenameCommandHandler_0);
commandMap.put(stack, compoundCommand);
}
return compoundCommand;
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class TreeModelViewerDragDropHandler method moveTreeObjects.
/**
* Move Tree Objects
*/
void moveTreeObjects(IFolder newParent, Object[] objects) {
final CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.TreeModelViewerDragDropHandler_0 : super.getLabel();
}
};
for (Object object : objects) {
if (object instanceof IFolder) {
// This first - folders go in folders
if (!newParent.getFolders().contains(object)) {
compoundCommand.add(new MoveFolderCommand(newParent, (IFolder) object));
}
} else if (object instanceof IArchimateModelObject) {
if (!newParent.getElements().contains(object)) {
compoundCommand.add(new MoveObjectCommand(newParent, (IArchimateModelObject) object));
}
}
}
CommandStack stack = (CommandStack) newParent.getAdapter(CommandStack.class);
stack.execute(compoundCommand);
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class ConstrainedLayoutEditPolicy method getChangeConstraintCommand.
/**
* Returns the <code>Command</code> for changing bounds for a group of
* children.
*
* @param request
* the ChangeBoundsRequest
* @return the Command
*
* @since 3.7
*/
protected Command getChangeConstraintCommand(ChangeBoundsRequest request) {
CompoundCommand resize = new CompoundCommand();
Command c;
GraphicalEditPart child;
List children = request.getEditParts();
for (int i = 0; i < children.size(); i++) {
child = (GraphicalEditPart) children.get(i);
c = createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintFor(request, child)));
resize.add(c);
}
return resize.unwrap();
}
use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.
the class UndoablePropertySheetEntry method resetPropertyValue.
/**
* @see org.eclipse.ui.views.properties.IPropertySheetEntry#resetPropertyValue()
*/
@Override
public void resetPropertyValue() {
CompoundCommand cc = new CompoundCommand();
if (getParent() == null)
// root does not have a default value
return;
// Use our parent's values to reset our values.
boolean change = false;
Object[] objects = getParent().getValues();
for (int i = 0; i < objects.length; i++) {
IPropertySource source = getPropertySource(objects[i]);
if (source.isPropertySet(getDescriptor().getId())) {
SetPropertyValueCommand restoreCmd = new SetPropertyValueCommand(getDescriptor().getDisplayName(), source, getDescriptor().getId(), SetPropertyValueCommand.DEFAULT_VALUE);
cc.add(restoreCmd);
change = true;
}
}
if (change) {
getCommandStack().execute(cc);
refreshFromRoot();
}
}
Aggregations