use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class ImportXMLProvider method run.
@Override
public void run(CommandLine commandLine) throws Exception {
if (!hasCorrectOptions(commandLine)) {
return;
}
// File
String value = commandLine.getOptionValue(OPTION_IMPORT_XML);
if (!StringUtils.isSet(value)) {
logError(Messages.ImportXMLProvider_1);
return;
}
File importFile = new File(value);
if (!importFile.exists()) {
logError(NLS.bind(Messages.ImportXMLProvider_2, value));
return;
}
// Validate file
logMessage(Messages.ImportXMLProvider_3);
XMLValidator validator = new XMLValidator();
validator.validateXML(importFile);
logMessage(Messages.ImportXMLProvider_4);
logMessage(NLS.bind(Messages.ImportXMLProvider_5, importFile.getPath()));
XMLModelImporter importer = new XMLModelImporter();
IArchimateModel model = importer.createArchiMateModel(importFile);
if (model == null) {
throw new IOException(Messages.ImportXMLProvider_6);
}
// Add an Archive Manager
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
// Add a Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
CommandLineState.setModel(model);
logMessage(Messages.ImportXMLProvider_7);
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class DeleteCommandHandlerTests method testDelete_More_Than_One_Model.
@Test
public void testDelete_More_Than_One_Model() throws IOException {
// Use another instance of the same model
ArchimateTestModel tm2 = new ArchimateTestModel(TEST_MODEL_FILE);
IArchimateModel model2 = tm2.loadModelWithCommandStack();
// Elements
String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
// Select them from both models
List<IArchimateElement> elements1 = new ArrayList<IArchimateElement>();
for (String id : elementIDs) {
elements1.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
}
List<IArchimateElement> elements2 = new ArrayList<IArchimateElement>();
for (String id : elementIDs) {
elements2.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model2, id));
}
List<IArchimateElement> allElements = new ArrayList<IArchimateElement>(elements1);
allElements.addAll(elements2);
assertEquals(8, allElements.size());
// Zap
DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, allElements.toArray());
commandHandler.delete();
// Test that they are all gone in the models and in the referenced diagrams
for (IArchimateElement element : elements1) {
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
for (IArchimateElement element : elements2) {
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
}
// And just for good measure, we'll undo it...once for each model
CommandStack commandStack1 = (CommandStack) model.getAdapter(CommandStack.class);
commandStack1.undo();
CommandStack commandStack2 = (CommandStack) model2.getAdapter(CommandStack.class);
commandStack2.undo();
// And find them all back again!
for (IArchimateElement element : elements1) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
for (IArchimateElement element : elements2) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNotNull(ArchimateModelUtils.getObjectByID(model2, element.getId()));
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class SaveModelProvider method saveModel.
private void saveModel(IArchimateModel model, File file) throws IOException {
// Set model version
model.setVersion(ModelVersion.VERSION);
// File
model.setFile(file);
// Use Archive Manager to save contents
IArchiveManager archiveManager = (IArchiveManager) model.getAdapter(IArchiveManager.class);
if (archiveManager == null) {
archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
}
archiveManager.saveModel();
// Set CommandStack Save point if we have one
CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
if (stack != null) {
stack.markSaveLocation();
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class UserPropertiesManagerDialog method okPressed.
@Override
protected void okPressed() {
super.okPressed();
CompoundCommand compoundCmd = new CompoundCommand(Messages.UserPropertiesManagerDialog_11) {
@Override
public void execute() {
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
doSuperExecute();
}
});
}
@Override
public void undo() {
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
doSuperUndo();
}
});
}
@Override
public void redo() {
BusyIndicator.showWhile(null, new Runnable() {
@Override
public void run() {
doSuperRedo();
}
});
}
void doSuperExecute() {
super.execute();
}
void doSuperUndo() {
super.undo();
}
void doSuperRedo() {
super.redo();
}
};
checkRenames(compoundCmd);
checkDeletions(compoundCmd);
CommandStack stack = (CommandStack) fArchimateModel.getAdapter(CommandStack.class);
stack.execute(compoundCmd.unwrap());
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class RenameCommandHandler method doRenameCommands.
/**
* Rename elements to matching newNames by issuing a CompundCommand(s) on the CommandStack(s)
* @param elements
* @param newNames
*/
public static void doRenameCommands(List<INameable> elements, List<String> newNames) {
// Must match sizes
if (elements.size() != newNames.size() || elements.isEmpty()) {
return;
}
/*
* If renaming elements from more than one model in the tree we need to use the
* Command Stack allocated to each model. And then allocate one CompoundCommand per Command Stack.
*/
Hashtable<CommandStack, CompoundCommand> commandMap = new Hashtable<CommandStack, CompoundCommand>();
for (int i = 0; i < elements.size(); i++) {
INameable element = elements.get(i);
String newName = newNames.get(i);
CompoundCommand compoundCommand = getCompoundCommand((IAdapter) element, commandMap);
if (compoundCommand != null) {
Command cmd = new // $NON-NLS-1$
EObjectFeatureCommand(// $NON-NLS-1$
Messages.RenameCommandHandler_0 + " " + element.getName(), // $NON-NLS-1$
element, IArchimatePackage.Literals.NAMEABLE__NAME, newName);
compoundCommand.add(cmd);
} else {
// $NON-NLS-1$
System.err.println("Could not get CompoundCommand in doRenameCommands");
}
}
// Execute the Commands on the CommandStack(s) - there could be more than one if more than one model open in the Tree
for (Entry<CommandStack, CompoundCommand> entry : commandMap.entrySet()) {
entry.getKey().execute(entry.getValue().unwrap());
}
}
Aggregations