Search in sources :

Example 21 with IFolder

use of com.archimatetool.model.IFolder in project archi by archimatetool.

the class MyImporter method createAndAddView.

protected IDiagramModel createAndAddView(IArchimateModel model, String name, String id) {
    IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    diagramModel.setName(name);
    diagramModel.setId(id);
    IFolder folder = model.getDefaultFolderForObject(diagramModel);
    folder.getElements().add(diagramModel);
    idLookup.put(diagramModel.getId(), diagramModel);
    return diagramModel;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IFolder(com.archimatetool.model.IFolder)

Example 22 with IFolder

use of com.archimatetool.model.IFolder in project archi by archimatetool.

the class ArchimateModel method getDiagramModels.

/**
 * <!-- begin-user-doc -->
 * Return the Diagram Models - could be empty list
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<IDiagramModel> getDiagramModels() {
    EList<IDiagramModel> list = new BasicEList<IDiagramModel>();
    IFolder folder = getFolder(FolderType.DIAGRAMS);
    if (folder != null) {
        for (Iterator<EObject> iter = folder.eAllContents(); iter.hasNext(); ) {
            EObject eObject = iter.next();
            if (eObject instanceof IDiagramModel) {
                list.add((IDiagramModel) eObject);
            }
        }
    }
    return list;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) BasicEList(org.eclipse.emf.common.util.BasicEList) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IFolder(com.archimatetool.model.IFolder)

Example 23 with IFolder

use of com.archimatetool.model.IFolder in project archi by archimatetool.

the class TreeModelViewerDragDropHandlerTests method moveTreeObjects_DropChildFolderOntoDifferentParent.

/**
 * Drag and dropping a folder onto a different parent
 */
@Test
public void moveTreeObjects_DropChildFolderOntoDifferentParent() {
    // Add a child folder to a parent folder
    IFolder sourceParentFolder = model.getFolder(FolderType.BUSINESS);
    IFolder childFolder = IArchimateFactory.eINSTANCE.createFolder();
    sourceParentFolder.getFolders().add(childFolder);
    // Check all is well
    assertEquals(1, sourceParentFolder.getFolders().size());
    assertTrue(sourceParentFolder.getFolders().contains(childFolder));
    // New target parent folder
    IFolder targetParentFolder = model.getFolder(FolderType.APPLICATION);
    assertTrue(targetParentFolder.getFolders().isEmpty());
    assertTrue(targetParentFolder.getElements().isEmpty());
    // Move child folder to the different target parent folder
    dragHandler.moveTreeObjects(targetParentFolder, new Object[] { childFolder });
    // Source should be empty
    assertTrue(sourceParentFolder.getFolders().isEmpty());
    // Target should be populated
    assertEquals(1, targetParentFolder.getFolders().size());
    assertEquals(childFolder, targetParentFolder.getFolders().get(0));
    // Elements should not be affected
    assertTrue(targetParentFolder.getElements().isEmpty());
}
Also used : IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

Example 24 with IFolder

use of com.archimatetool.model.IFolder in project archi by archimatetool.

the class TreeModelViewerDragDropHandlerTests method __doTestHasCommonAncestorFolderWithTheseFolders.

private void __doTestHasCommonAncestorFolderWithTheseFolders(IFolder parentFolder1, IFolder parentFolder2) {
    /*
        
        businessFolder 
                   |-- f2
                        |-- e1
                   |-- f3
                        |-- e2
        appFolder
                   |-- f4
                        |-- e3
                   |-- f5
                        |-- e4
         
         */
    IFolder f2 = IArchimateFactory.eINSTANCE.createFolder();
    IFolder f3 = IArchimateFactory.eINSTANCE.createFolder();
    parentFolder1.getFolders().add(f2);
    parentFolder1.getFolders().add(f3);
    IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    f2.getElements().add(e1);
    IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    f3.getElements().add(e2);
    IFolder f4 = IArchimateFactory.eINSTANCE.createFolder();
    IFolder f5 = IArchimateFactory.eINSTANCE.createFolder();
    parentFolder2.getFolders().add(f4);
    parentFolder2.getFolders().add(f5);
    IArchimateElement e3 = IArchimateFactory.eINSTANCE.createApplicationComponent();
    f4.getElements().add(e3);
    IArchimateElement e4 = IArchimateFactory.eINSTANCE.createApplicationComponent();
    f5.getElements().add(e4);
    // Same common ancestor
    assertTrue(dragHandler.hasCommonAncestorFolder(f2, f3));
    assertTrue(dragHandler.hasCommonAncestorFolder(f2, e1));
    assertTrue(dragHandler.hasCommonAncestorFolder(f3, e1));
    assertTrue(dragHandler.hasCommonAncestorFolder(e1, e2));
    // Different common ancestors
    assertFalse(dragHandler.hasCommonAncestorFolder(f2, f4));
    assertFalse(dragHandler.hasCommonAncestorFolder(f3, f5));
    assertFalse(dragHandler.hasCommonAncestorFolder(f3, e3));
    assertFalse(dragHandler.hasCommonAncestorFolder(e1, e4));
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IFolder(com.archimatetool.model.IFolder)

Example 25 with IFolder

use of com.archimatetool.model.IFolder in project archi by archimatetool.

the class TreeModelViewerDragDropHandlerTests method testIsValidTreeSelection.

@Test
public void testIsValidTreeSelection() {
    // Null selection is not valid
    StructuredSelection selection = null;
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Set up some data
    IFolder userFolder = IArchimateFactory.eINSTANCE.createFolder();
    model.getFolder(FolderType.DIAGRAMS).getFolders().add(userFolder);
    IFolder businessFolder = model.getFolder(FolderType.BUSINESS);
    IArchimateElement e1 = IArchimateFactory.eINSTANCE.createBusinessActor();
    businessFolder.getElements().add(e1);
    IArchimateElement e2 = IArchimateFactory.eINSTANCE.createBusinessActor();
    businessFolder.getElements().add(e2);
    // Elements from the same root parent are OK
    selection = new StructuredSelection(new Object[] { e1, e2 });
    assertTrue(dragHandler.isValidTreeSelection(selection));
    // Can't DnD a model
    selection = new StructuredSelection(new Object[] { model });
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Can DnD a user folder
    selection = new StructuredSelection(new Object[] { userFolder });
    assertTrue(dragHandler.isValidTreeSelection(selection));
    // Can't DnD a system folder
    selection = new StructuredSelection(new Object[] { businessFolder });
    assertFalse(dragHandler.isValidTreeSelection(selection));
    // Can't DnD Mixed parent models
    IArchimateModel model2 = IArchimateFactory.eINSTANCE.createArchimateModel();
    model2.setDefaults();
    IArchimateElement e3 = IArchimateFactory.eINSTANCE.createBusinessActor();
    model2.getFolder(FolderType.BUSINESS).getElements().add(e3);
    selection = new StructuredSelection(new Object[] { e1, e3 });
    assertFalse(dragHandler.isValidTreeSelection(selection));
}
Also used : StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder) Test(org.junit.Test)

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