Search in sources :

Example 66 with IDiagramModel

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

the class TreeSelectionSynchroniser method selectionChanged.

@Override
public void selectionChanged(SelectionChangedEvent event) {
    if (isDispatching) {
        return;
    }
    fLastEvent = event;
    if (!Preferences.doLinkView() || !fDoSync) {
        return;
    }
    isDispatching = true;
    ISelection selection = event.getSelection();
    Object source = event.getSource();
    // Selection from Diagram Editor, so update the Tree if it is showing
    if (source instanceof GraphicalViewer && fTreeView != null) {
        List<Object> list = new ArrayList<Object>();
        for (Object o : ((IStructuredSelection) selection).toArray()) {
            if (o instanceof EditPart) {
                Object model = ((EditPart) o).getModel();
                // Archimate concept
                if (model instanceof IDiagramModelArchimateComponent) {
                    model = ((IDiagramModelArchimateComponent) model).getArchimateConcept();
                    list.add(model);
                } else // Diagram model
                if (model instanceof IDiagramModel) {
                    list.add(model);
                }
            }
        }
        // Select in tree
        fTreeView.getViewer().setSelection(new StructuredSelection(list), true);
    } else // Archimate objects selection from Tree View, so update any Archimate Diagram Editors
    if (source instanceof TreeViewer) {
        List<IArchimateConcept> list = new ArrayList<IArchimateConcept>();
        // Archimate elements
        for (Object o : ((IStructuredSelection) selection).toArray()) {
            if (o instanceof IArchimateConcept) {
                list.add((IArchimateConcept) o);
            }
        }
        // Select these in the Diagram Editors
        for (IDiagramModelEditor diagramEditor : fDiagramEditors) {
            if (diagramEditor instanceof IArchimateDiagramEditor) {
                ((IArchimateDiagramEditor) diagramEditor).selectArchimateConcepts(list.toArray(new IArchimateConcept[list.size()]));
            }
        }
    }
    isDispatching = false;
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) EditPart(org.eclipse.gef.EditPart) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDiagramModelEditor(com.archimatetool.editor.diagram.IDiagramModelEditor) IArchimateDiagramEditor(com.archimatetool.editor.diagram.IArchimateDiagramEditor) IDiagramModel(com.archimatetool.model.IDiagramModel) ISelection(org.eclipse.jface.viewers.ISelection) IDiagramModelArchimateComponent(com.archimatetool.model.IDiagramModelArchimateComponent) IArchimateConcept(com.archimatetool.model.IArchimateConcept) ArrayList(java.util.ArrayList) List(java.util.List)

Example 67 with IDiagramModel

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

the class TreeModelViewActionFactory method createNewArchimateDiagramAction.

private IAction createNewArchimateDiagramAction(final IFolder folder) {
    IAction action = new Action(Messages.TreeModelViewActionFactory_0) {

        @Override
        public void run() {
            // Create a new Diagram Model, set its name
            IDiagramModel diagramModel = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
            diagramModel.setName(Messages.TreeModelViewActionFactory_1);
            // Execute Command
            Command cmd = new NewDiagramCommand(folder, diagramModel, Messages.TreeModelViewActionFactory_1);
            CommandStack commandStack = (CommandStack) folder.getAdapter(CommandStack.class);
            commandStack.execute(cmd);
        }
    };
    action.setImageDescriptor(IArchiImages.ImageFactory.getImageDescriptor(IArchiImages.ICON_DIAGRAM));
    return action;
}
Also used : NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) CommandStack(org.eclipse.gef.commands.CommandStack) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) IDiagramModel(com.archimatetool.model.IDiagramModel) NewDiagramCommand(com.archimatetool.editor.views.tree.commands.NewDiagramCommand) Command(org.eclipse.gef.commands.Command) NewElementCommand(com.archimatetool.editor.views.tree.commands.NewElementCommand)

Example 68 with IDiagramModel

use of com.archimatetool.model.IDiagramModel 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)

Aggregations

IDiagramModel (com.archimatetool.model.IDiagramModel)68 Test (org.junit.Test)28 IArchimateElement (com.archimatetool.model.IArchimateElement)16 IArchimateModel (com.archimatetool.model.IArchimateModel)12 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)12 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)9 File (java.io.File)8 EObject (org.eclipse.emf.ecore.EObject)8 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 Image (org.eclipse.swt.graphics.Image)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)7 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)7 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Command (org.eclipse.gef.commands.Command)6 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)6 Shell (org.eclipse.swt.widgets.Shell)6