Search in sources :

Example 31 with IFolder

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());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 32 with IFolder

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());
}
Also used : IArchimateModel(com.archimatetool.model.IArchimateModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 33 with IFolder

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);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IncompatibleModelException(com.archimatetool.editor.model.compatibility.IncompatibleModelException) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 34 with IFolder

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;
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) EObject(org.eclipse.emf.ecore.EObject) ICanvasModel(com.archimatetool.canvas.model.ICanvasModel) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 35 with IFolder

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));
}
Also used : IAction(org.eclipse.jface.action.IAction) IDiagramModel(com.archimatetool.model.IDiagramModel) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) GroupMarker(org.eclipse.jface.action.GroupMarker) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IArchimateModel(com.archimatetool.model.IArchimateModel) Separator(org.eclipse.jface.action.Separator) IFolder(com.archimatetool.model.IFolder)

Aggregations

IFolder (com.archimatetool.model.IFolder)41 Test (org.junit.Test)19 EObject (org.eclipse.emf.ecore.EObject)13 IArchimateElement (com.archimatetool.model.IArchimateElement)11 IArchimateModel (com.archimatetool.model.IArchimateModel)11 ArrayList (java.util.ArrayList)6 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)5 IDiagramModel (com.archimatetool.model.IDiagramModel)5 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)4 Command (org.eclipse.gef.commands.Command)4 CommandStack (org.eclipse.gef.commands.CommandStack)4 File (java.io.File)3 ICanvasModel (com.archimatetool.canvas.model.ICanvasModel)2 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)2 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)2