use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class LoadModelFromFileProvider method loadModel.
static IArchimateModel loadModel(File file) throws IOException {
if (file == null || !file.exists()) {
return null;
}
// Ascertain if this is an archive file
boolean useArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
// Create the Resource
Resource resource = ArchimateResourceFactory.createNewResource(useArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Load model
resource.load(null);
IArchimateModel model = (IArchimateModel) resource.getContents().get(0);
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
model.setFile(file);
model.setDefaults();
// Add an Archive Manager and load images
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
archiveManager.loadImages();
// 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 NewFolderAction method run.
@Override
public void run() {
Object selected = getSelection().getFirstElement();
if (selected instanceof IFolder) {
IFolder parent = (IFolder) selected;
// Create a new Folder, set its name
IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
folder.setName(Messages.NewFolderAction_1);
folder.setType(FolderType.USER);
// Execute Command
Command cmd = new NewFolderCommand(parent, folder);
CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
}
use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.
the class TreeDirectEditManager method commit.
protected void commit(String value) {
CommandStack stack = entityPart.getViewer().getEditDomain().getCommandStack();
stack.execute(entityPart.getCommand(getDirectEditRequest(value)));
}
use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.
the class CutHandler method execute.
@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
if (bm.wIsSet("viewer") && ClipboardUtils.hasTextSeletion((IEntityPartViewer) bm.wGetValue("viewer"))) {
HandlersBehavior.copy(bm);
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
IEntity focusEntity = bm.wGet("focusEntity");
ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
Command command = focusPart.getCommand(TextualRequest.createDeleteRequest());
command.setLabel(getLabel(bm) + " text");
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
commandStack.execute(command);
return;
}
super.execute(bm);
}
use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.
the class ModelTransactionHandler method execute.
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
EntityEditDomainJob.asyncExec(getLabel(bm), viewer.getEditDomain(), (monitor) -> {
CommandStack commandStack = viewer.getEditDomain().getCommandStack();
ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
try {
bm.wEnterScope(ts);
mtc.setLabel(getLabel(bm));
mtc.begin();
run(bm);
mtc.commit();
if (mtc.canUndo())
commandStack.execute(mtc);
} catch (RollbackException e) {
// rollback done
} catch (RuntimeException e) {
mtc.rollbackIfNeeded();
throw e;
} finally {
ts.rollback();
bm.wExitScope();
}
});
}
Aggregations