use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class DiagramModelArchimateConnectionTests method testAdd_Remove_ArchimateRelationshipToModel.
@Test
public void testAdd_Remove_ArchimateRelationshipToModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
dm.getChildren().add(source);
dm.getChildren().add(target);
connection.connect(source, target);
// Passing null uses a default folder in the model
IFolder expectedFolder = model.getDefaultFolderForObject(connection.getArchimateRelationship());
connection.addArchimateConceptToModel(null);
assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
connection.removeArchimateConceptFromModel();
assertNull(connection.getArchimateRelationship().eContainer());
expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
connection.addArchimateConceptToModel(expectedFolder);
assertSame(expectedFolder, connection.getArchimateRelationship().eContainer());
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class DiagramModelArchimateObjectTests method testAdd_Remove_ArchimateElementToModel.
@Test
public void testAdd_Remove_ArchimateElementToModel() {
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
dm.getChildren().add(object);
// Passing null uses a default folder in the model
IFolder expectedFolder = model.getDefaultFolderForObject(object.getArchimateElement());
object.addArchimateConceptToModel(null);
assertSame(expectedFolder, object.getArchimateElement().eContainer());
object.removeArchimateConceptFromModel();
assertNull(object.getArchimateElement().eContainer());
expectedFolder = IArchimateFactory.eINSTANCE.createFolder();
object.addArchimateConceptToModel(expectedFolder);
assertSame(expectedFolder, object.getArchimateElement().eContainer());
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class NewCanvasFromTemplateWizard method createNewCanvasFromTemplate.
private void createNewCanvasFromTemplate(File file) throws IncompatibleModelException, IOException {
// Ascertain if this is a zip file
boolean isArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
Resource resource = ArchimateResourceFactory.createNewResource(isArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
// Check model compatibility
ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
// Wrap in try/catch to load as much as possible
try {
resource.load(null);
} catch (IOException ex) {
// Error occured loading model. Was it a disaster?
try {
modelCompatibility.checkErrors();
}// Incompatible
catch (IncompatibleModelException ex1) {
fErrorMessage = NLS.bind(Messages.NewCanvasFromTemplateWizard_4, file) + "\n" + // $NON-NLS-1$
ex1.getMessage();
throw ex1;
}
}
// And then fix any backward compatibility issues
try {
modelCompatibility.fixCompatibility();
} catch (CompatibilityHandlerException ex) {
}
// Pull out the Canvas model
IArchimateModel templateModel = (IArchimateModel) resource.getContents().get(0);
IFolder folderViews = templateModel.getFolder(FolderType.DIAGRAMS);
ICanvasModel canvasModel = (ICanvasModel) folderViews.getElements().get(0);
// Create New UUIDs for elements...
TemplateUtils.generateNewUUIDs(canvasModel);
// Load the images from the template model's file now
if (isArchiveFormat) {
IArchiveManager archiveManager = (IArchiveManager) fFolder.getAdapter(IArchiveManager.class);
archiveManager.loadImagesFromModelFile(file);
}
Command cmd = new NewDiagramCommand(fFolder, canvasModel, Messages.NewCanvasFromTemplateWizard_5);
CommandStack commandStack = (CommandStack) fFolder.getAdapter(CommandStack.class);
commandStack.execute(cmd);
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class SaveCanvasAsTemplateWizard method saveModelToTempFile.
private File saveModelToTempFile() throws IOException {
// $NON-NLS-1$
File tmpFile = File.createTempFile("architemplate", null);
tmpFile.deleteOnExit();
// Create a new container Archimate model
IArchimateModel tempModel = IArchimateFactory.eINSTANCE.createArchimateModel();
tempModel.setDefaults();
// Remove this after default folders have been added, as we'll generate our own IDs
tempModel.eAdapters().clear();
tempModel.setId(EcoreUtil.generateUUID());
tempModel.setFile(tmpFile);
tempModel.setVersion(ModelVersion.VERSION);
tempModel.setName(Messages.SaveCanvasAsTemplateWizard_4);
// Get the Canvas copy
ICanvasModel copyCanvas = EcoreUtil.copy(fCanvasModel);
// Remove any unsupported elements
for (Iterator<EObject> iter = copyCanvas.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IDiagramModelReference) {
EcoreUtil.delete(eObject);
}
}
// Generate new IDs
TemplateUtils.generateNewUUIDs(copyCanvas);
// Add the canvas copy to a new Views folder
IFolder folder = tempModel.getDefaultFolderForObject(copyCanvas);
folder.getElements().add(copyCanvas);
// Use an Archive Manager to save it
IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(tempModel);
archiveManager.saveModel();
archiveManager.dispose();
return tmpFile;
}
use of com.archimatetool.model.IFolder in project archi by archimatetool.
the class TreeModelView method fillContextMenu.
/**
* Fill context menu when user right-clicks
* @param manager
*/
private void fillContextMenu(IMenuManager manager) {
IStructuredSelection selection = ((IStructuredSelection) getViewer().getSelection());
Object selected = selection.getFirstElement();
boolean isEmpty = selected == null;
if (isEmpty) {
manager.add(fActionNewModel);
manager.add(fActionOpenModel);
return;
}
// $NON-NLS-1$
MenuManager newMenu = new MenuManager(Messages.TreeModelView_1, "new");
manager.add(newMenu);
// $NON-NLS-1$
getSite().registerContextMenu(ID + ".new_menu", newMenu, getViewer());
manager.add(new Separator());
// Selected model
if (selected instanceof IArchimateModel) {
manager.add(fActionCloseModel);
manager.add(fActionSaveModel);
manager.add(new Separator());
}
// Selected Diagram
if (selected instanceof IDiagramModel) {
manager.add(fActionOpenDiagram);
// $NON-NLS-1$
manager.add(new Separator("open"));
}
if (selected instanceof IFolder) {
newMenu.add(fActionNewFolder);
newMenu.add(new Separator());
}
// Create "New" Actions
List<IAction> actions = TreeModelViewActionFactory.INSTANCE.getNewObjectActions(selected);
for (IAction action : actions) {
if (action == null) {
newMenu.add(new Separator());
} else {
newMenu.add(action);
}
}
// $NON-NLS-1$
newMenu.add(new Separator("new_additions"));
if (!isEmpty) {
manager.add(new Separator());
manager.add(fActionDelete);
manager.add(fActionRename);
// $NON-NLS-1$
manager.add(new Separator("start_collapse"));
// Expand selected
for (Object o : selection.toArray()) {
if (hasExpandableNodes(o)) {
manager.add(fActionExpandSelected);
break;
}
}
// Collapse selected
for (Object o : selection.toArray()) {
if (fTreeViewer.isExpandable(o) && fTreeViewer.getExpandedState(o)) {
manager.add(fActionCollapseSelected);
break;
}
}
// $NON-NLS-1$
manager.add(new Separator("end_collapse"));
if (DuplicateCommandHandler.canDuplicate(selection)) {
manager.add(fActionDuplicate);
}
// $NON-NLS-1$
manager.add(new Separator("start_extensions"));
manager.add(fActionGenerateView);
// $NON-NLS-1$
manager.add(new GroupMarker("append_extensions"));
// $NON-NLS-1$
manager.add(new Separator("end_extensions"));
// $NON-NLS-1$
manager.add(new Separator("start_properties"));
manager.add(fActionProperties);
// $NON-NLS-1$
manager.add(new GroupMarker("append_properties"));
// $NON-NLS-1$
manager.add(new Separator("end_properties"));
}
// Other plug-ins can contribute their actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
Aggregations