Search in sources :

Example 16 with IDiagramModelArchimateComponent

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

Aggregations

IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)16 IArchimateConcept (com.archimatetool.model.IArchimateConcept)6 IDiagramModel (com.archimatetool.model.IDiagramModel)6 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)6 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)5 EClass (org.eclipse.emf.ecore.EClass)5 IConnectable (com.archimatetool.model.IConnectable)4 ArrayList (java.util.ArrayList)4 EditPart (org.eclipse.gef.EditPart)4 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)3 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)3 Command (org.eclipse.gef.commands.Command)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)2 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)2 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)2 IArchimateElement (com.archimatetool.model.IArchimateElement)2 EObject (org.eclipse.emf.ecore.EObject)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2