use of org.eclipse.gef.commands.CommandStack 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.CommandStack 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.CommandStack in project archi by archimatetool.
the class ArchimateTestModel method loadModelWithCommandStack.
/**
* Load the Archimate model with a Command Stack added
* @return The model
* @throws IOException
*/
public IArchimateModel loadModelWithCommandStack() throws IOException {
model = loadModel();
// Add a Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
return model;
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class ArchimateTestModel method createNewModel.
/**
* Replica of EditorModelManager#createNewModel()
* Adds Command Stack and ArchiveManager
*/
public IArchimateModel createNewModel() {
model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
// Add one default diagram model
addNewArchimateDiagramModel();
// Add a Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
// Add an Archive Manager
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
return model;
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class CreateMapViewCheatSheetAction method run.
@Override
public void run(String[] params, ICheatSheetManager manager) {
IViewPart viewPart = ViewManager.showViewPart(ITreeModelView.ID, true);
if (viewPart == null) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_0, Messages.CreateMapViewCheatSheetAction_1);
return;
}
IArchimateModel model = viewPart.getAdapter(IArchimateModel.class);
if (model == null) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_2, Messages.CreateMapViewCheatSheetAction_3);
return;
}
EList<IDiagramModel> diagramModels = model.getDiagramModels();
if (diagramModels.size() < 2) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_4, Messages.CreateMapViewCheatSheetAction_5);
return;
}
CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
if (stack != null) {
stack.execute(new NewMapViewCommand(model));
}
}
Aggregations