use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class PasteAction method run.
@Override
public void run() {
if (!hasValidSelection()) {
setEnabled(false);
return;
}
IFolder parent = (IFolder) getSelection().getFirstElement();
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {
@Override
public String getLabel() {
return getCommands().size() > 1 ? Messages.PasteAction_1 : super.getLabel();
}
};
for (IArchimateModelObject selected : TreeModelCutAndPaste.INSTANCE.getObjects()) {
if (isAllowedToPaste(parent, selected)) {
if (selected instanceof IFolder) {
// This first - folders go in folders
compoundCommand.add(new MoveFolderCommand(parent, (IFolder) selected));
} else {
compoundCommand.add(new MoveObjectCommand(parent, selected));
}
}
}
CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
if (commandStack != null) {
commandStack.execute(compoundCommand);
TreeModelCutAndPaste.INSTANCE.clear();
((TreeViewer) getSelectionProvider()).expandToLevel(parent, 1);
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class TreeModelViewActionFactory method createNewFolderAction.
private IAction createNewFolderAction(final IFolder folder) {
IAction action = new Action(Messages.NewFolderAction_0) {
@Override
public void run() {
// Create a new Folder, set its name
IFolder newFolder = IArchimateFactory.eINSTANCE.createFolder();
newFolder.setName(Messages.NewFolderAction_1);
newFolder.setType(FolderType.USER);
// Execute Command
Command cmd = new NewFolderCommand(folder, newFolder);
CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
};
IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(folder);
action.setImageDescriptor(provider.getImageDescriptor());
return action;
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class TreeModelViewActionFactory method createNewArchimateDiagramAction.
private IAction createNewArchimateDiagramAction(final IFolder folder) {
IAction action = new Action(Messages.TreeModelViewActionFactory_0) {
@Override
public void run() {
// Create a new Diagram Model, set its name
IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
diagramModel.setName(Messages.TreeModelViewActionFactory_1);
// Execute Command
Command cmd = new NewDiagramCommand(folder, diagramModel, Messages.TreeModelViewActionFactory_1);
CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
};
action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_DIAGRAM));
return action;
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class TreeModelViewActionFactory method createNewElementAction.
private IAction createNewElementAction(final IFolder folder, final EClass eClass) {
IAction action = new Action(ArchiLabelProvider.INSTANCE.getDefaultName(eClass)) {
@Override
public void run() {
// Create a new Archimate Element, set its name
IArchimateElement element = (IArchimateElement) IArchimateFactory.eINSTANCE.create(eClass);
element.setName(getText());
// Execute Command
Command cmd = new NewElementCommand(folder, element);
CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
};
action.setImageDescriptor(ArchiLabelProvider.INSTANCE.getImageDescriptor(eClass));
return action;
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class DeleteCommandHandler method getCompoundCommand.
/**
* Get, and if need be create, a CompoundCommand to which to add the object to be deleted command
*/
private CompoundCommand getCompoundCommand(IAdapter object) {
// 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 " + getClass());
return null;
}
// Now get or create a Compound Command
CompoundCommand compoundCommand = fCommandMap.get(stack);
if (compoundCommand == null) {
compoundCommand = new DeleteElementsCompoundCommand(fObjectToSelectAfterDeletion);
fCommandMap.put(stack, compoundCommand);
}
return compoundCommand;
}
Aggregations