Search in sources :

Example 36 with IFolder

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

the class TreeModelViewerDragDropHandler method moveTreeObjects.

/**
 * Move Tree Objects
 */
void moveTreeObjects(IFolder newParent, Object[] objects) {
    final CompoundCommand compoundCommand = new NonNotifyingCompoundCommand() {

        @Override
        public String getLabel() {
            return getCommands().size() > 1 ? Messages.TreeModelViewerDragDropHandler_0 : super.getLabel();
        }
    };
    for (Object object : objects) {
        if (object instanceof IFolder) {
            // This first - folders go in folders
            if (!newParent.getFolders().contains(object)) {
                compoundCommand.add(new MoveFolderCommand(newParent, (IFolder) object));
            }
        } else if (object instanceof IArchimateModelObject) {
            if (!newParent.getElements().contains(object)) {
                compoundCommand.add(new MoveObjectCommand(newParent, (IArchimateModelObject) object));
            }
        }
    }
    CommandStack stack = (CommandStack) newParent.getAdapter(CommandStack.class);
    stack.execute(compoundCommand);
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) MoveFolderCommand(com.archimatetool.editor.views.tree.commands.MoveFolderCommand) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) EObject(org.eclipse.emf.ecore.EObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) IFolder(com.archimatetool.model.IFolder) MoveObjectCommand(com.archimatetool.editor.views.tree.commands.MoveObjectCommand)

Example 37 with IFolder

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

the class AbstractModelView method getParentToRefreshFromNotification.

/**
 * @return The parent node to refresh when one of its children is added/removed/set
 */
protected Object getParentToRefreshFromNotification(Notification msg) {
    int type = msg.getEventType();
    Object element = null;
    if (type == Notification.REMOVE) {
        element = msg.getNotifier();
    } else if (type == Notification.ADD) {
        element = msg.getNewValue();
        if (element instanceof EObject) {
            element = ((EObject) element).eContainer();
        }
    } else if (type == Notification.SET) {
        // Name changed - need to refresh parent node because of using a ViewerSorter to sort on name
        if (msg.getFeature() == IArchimatePackage.Literals.NAMEABLE__NAME) {
            element = msg.getNotifier();
            if (element instanceof EObject) {
                element = ((EObject) element).eContainer();
            }
        }
    }
    return (element instanceof IFolder || element instanceof IArchimateModel) ? element : null;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateModel(com.archimatetool.model.IArchimateModel) IFolder(com.archimatetool.model.IFolder)

Example 38 with IFolder

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

the class DeleteCommandHandler method createCommands.

/**
 * Create the Delete Commands
 */
private void createCommands() {
    /*
         *  We need to ensure that the Delete Diagram Model Commands are called first in order to close
         *  any open diagram editors before removing their models from parent folders.
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
            if (compoundCommand != null) {
                Command cmd = new DeleteDiagramModelCommand((IDiagramModel) object);
                compoundCommand.add(cmd);
            } else {
                // $NON-NLS-1$
                System.err.println("Could not get CompoundCommand in " + getClass());
            }
        }
    }
    /*
         * Then the other types
         */
    for (Object object : fElementsToDelete) {
        if (object instanceof IDiagramModel) {
            // already done
            continue;
        }
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
        if (compoundCommand == null) {
            // sanity check
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in " + getClass());
            continue;
        }
        if (object instanceof IFolder) {
            Command cmd = new DeleteFolderCommand((IFolder) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateElement) {
            Command cmd = new DeleteArchimateElementCommand((IArchimateElement) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateRelationship) {
            Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelObject) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IDiagramModelConnection) {
            Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) object);
            compoundCommand.add(cmd);
        }
    }
}
Also used : DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) IDiagramModel(com.archimatetool.model.IDiagramModel) DeleteArchimateRelationshipCommand(com.archimatetool.editor.model.commands.DeleteArchimateRelationshipCommand) DeleteArchimateElementCommand(com.archimatetool.editor.model.commands.DeleteArchimateElementCommand) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) DeleteFolderCommand(com.archimatetool.editor.model.commands.DeleteFolderCommand) Command(org.eclipse.gef.commands.Command) DeleteDiagramModelCommand(com.archimatetool.editor.model.commands.DeleteDiagramModelCommand) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IFolder(com.archimatetool.model.IFolder)

Example 39 with IFolder

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

the class NewFolderAction method run.

@Override
public void run() {
    Object selected = getSelection().getFirstElement();
    if (selected instanceof IFolder) {
        IFolder parent = (IFolder) selected;
        // Create a new Folder, set its name
        IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
        folder.setName(Messages.NewFolderAction_1);
        folder.setType(FolderType.USER);
        // Execute Command
        Command cmd = new NewFolderCommand(parent, folder);
        CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
        commandStack.execute(cmd);
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) Command(org.eclipse.gef.commands.Command) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) IFolder(com.archimatetool.model.IFolder)

Example 40 with IFolder

use of com.archimatetool.model.IFolder in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelExporter method createAndSaveResourceForFolder.

/**
 * For each folder inside model, create a directory and a Resource to save it.
 * For each element, create a Resource to save it
 *
 * @param folderContainer Model or folder to work on
 * @param folder Directory in which to generate files
 * @throws IOException
 */
private void createAndSaveResourceForFolder(IFolderContainer folderContainer, File folder) throws IOException {
    // Save each children folders
    List<IFolder> allFolders = new ArrayList<IFolder>();
    allFolders.addAll(folderContainer.getFolders());
    for (IFolder tmpFolder : allFolders) {
        File tmpFolderFile = new File(folder, getNameFor(tmpFolder));
        tmpFolderFile.mkdirs();
        createAndSaveResource(new File(tmpFolderFile, IGraficoConstants.FOLDER_XML), tmpFolder);
        createAndSaveResourceForFolder(tmpFolder, tmpFolderFile);
    }
    // Save each children elements
    if (folderContainer instanceof IFolder) {
        // Save each children element
        List<EObject> allElements = new ArrayList<EObject>();
        allElements.addAll(((IFolder) folderContainer).getElements());
        for (EObject tmpElement : allElements) {
            createAndSaveResource(// $NON-NLS-1$ //$NON-NLS-2$
            new File(folder, tmpElement.getClass().getSimpleName() + "_" + ((IIdentifier) tmpElement).getId() + ".xml"), tmpElement);
        }
    }
    if (folderContainer instanceof IArchimateModel) {
        createAndSaveResource(new File(folder, IGraficoConstants.FOLDER_XML), folderContainer);
    }
}
Also used : IIdentifier(com.archimatetool.model.IIdentifier) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) File(java.io.File) IArchimateModel(com.archimatetool.model.IArchimateModel) 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