use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class DeleteCommandHandlerTests method testDelete_Elements.
@Test
public void testDelete_Elements() {
String[] elementIDs = new String[] { "31a27739", "8ab84e91", "46d0abd5", "8ecabfc2" };
List<IArchimateElement> elements = new ArrayList<IArchimateElement>();
for (String id : elementIDs) {
elements.add((IArchimateElement) ArchimateModelUtils.getObjectByID(model, id));
}
// Ensure these elements are referenced in diagrams
for (IArchimateElement element : elements) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
}
// Delete them
DeleteCommandHandler commandHandler = new DeleteCommandHandler(treeModelViewer, elements.toArray());
commandHandler.delete();
// Test that they are all gone in the model and in the referenced diagrams
for (IArchimateElement element : elements) {
assertFalse(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
// And just for good measure, we'll undo it
CommandStack commandStack = (CommandStack) model.getAdapter(CommandStack.class);
commandStack.undo();
// And find them all back again!
for (IArchimateElement element : elements) {
assertTrue(DiagramModelUtils.isArchimateConceptReferencedInDiagrams(element));
assertNotNull(ArchimateModelUtils.getObjectByID(model, element.getId()));
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class AbstractDiagramEditor method setInput.
@Override
public void setInput(IEditorInput input) {
super.setInput(input);
// This first - set model
fDiagramModel = ((DiagramEditorInput) input).getDiagramModel();
// Listen to notifications from diagram model and main model for name changes to update part
eCoreAdapter.add(fDiagramModel, fDiagramModel.getArchimateModel());
// Edit Domain before init
// Use CommandStack from Model
DefaultEditDomain domain = new DefaultEditDomain(this) {
private CommandStack stack;
@Override
public CommandStack getCommandStack() {
if (stack == null) {
stack = (CommandStack) fDiagramModel.getAdapter(CommandStack.class);
}
return stack;
}
};
setEditDomain(domain);
// Part Name
setPartName(input.getName());
// Listen to App Prefs changes
ArchiPlugin.PREFERENCES.addPropertyChangeListener(appPreferencesListener);
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class DiagramEditorFindReplaceProvider method doReplaceStringCommand.
void doReplaceStringCommand(EditPart editPart, String newText) {
Command command = createCommand(editPart, newText);
CommandStack stack = (CommandStack) ((IAdapter) editPart.getModel()).getAdapter(CommandStack.class);
if (command != null && stack != null) {
stack.execute(command);
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class ConnectionRouterAction method run.
@Override
public void run() {
if (isChecked()) {
CommandStack stack = part.getAdapter(CommandStack.class);
stack.execute(new ConnectionRouterTypeCommand(diagramModel, getType()));
}
}
use of org.eclipse.gef.commands.CommandStack in project archi by archimatetool.
the class EditorModelManager method load.
@Override
public IArchimateModel load(File file) throws IOException {
if (file == null || !file.exists()) {
return null;
}
// Create the Resource
Resource resource = IArchiveManager.FACTORY.createResource(file);
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Load the model file
try {
resource.load(null);
} catch (IOException ex) {
// Error occured loading model.
try {
modelCompatibility.checkErrors();
} catch (IncompatibleModelException ex1) {
// $NON-NLS-1$
throw new IOException(NLS.bind(Messages.EditorModelManager_10, file) + "\n" + ex1.getMessage());
}
}
IArchimateModel model = (IArchimateModel) resource.getContents().get(0);
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
// Set file
model.setFile(file);
// Check defaults
model.setDefaults();
// New Command Stack
CommandStack cmdStack = new CommandStack();
model.setAdapter(CommandStack.class, cmdStack);
// New Archive Manager and load images
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
model.setAdapter(IArchiveManager.class, archiveManager);
archiveManager.loadImages();
return model;
}
Aggregations