Search in sources :

Example 11 with IDiagramModelContainer

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

the class BasicContainerEditPolicy method getOrphanChildrenCommand.

/*
     * This allows us to drag parts from a parent container to another.
     * This is the "remove" counterpart to the "add" Command created in DiagramLayoutPolicy.createAddCommand(EditPart, Object);
     * 
     * If you don't want a part to be removed, return null here.
     */
@Override
public Command getOrphanChildrenCommand(GroupRequest request) {
    CompoundCommand result = new CompoundCommand(Messages.BasicContainerEditPolicy_0);
    IDiagramModelContainer parent = (IDiagramModelContainer) getHost().getModel();
    for (Object o : request.getEditParts()) {
        EditPart editPart = (EditPart) o;
        IDiagramModelObject child = (IDiagramModelObject) editPart.getModel();
        result.add(new RemoveObjectCommand(parent, child));
    }
    return result;
}
Also used : EditPart(org.eclipse.gef.EditPart) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 12 with IDiagramModelContainer

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

the class DiagramLayoutPolicy method createAddCommand.

/*
     * This allows us to drag parts from a parent container to another.
     * This is the "add" counterpart to the "remove" Command created in BasicContainerEditPolicy.getOrphanChildrenCommand(GroupRequest);
     * 
     * If you don't want a part to be added, return null here.
     */
@Override
protected AddObjectCommand createAddCommand(ChangeBoundsRequest request, EditPart childEditPart, Object constraint) {
    IDiagramModelContainer parent = (IDiagramModelContainer) getHost().getModel();
    IDiagramModelObject child = (IDiagramModelObject) childEditPart.getModel();
    // Keep within box
    Rectangle bounds = (Rectangle) constraint;
    if (bounds.x < 0) {
        bounds.x = 0;
    }
    if (bounds.y < 0) {
        bounds.y = 0;
    }
    return new AddObjectCommand(parent, child, bounds);
}
Also used : Rectangle(org.eclipse.draw2d.geometry.Rectangle) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 13 with IDiagramModelContainer

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

the class AbstractFilteredEditPart method getFilteredModelChildren.

protected List<?> getFilteredModelChildren() {
    if (getModel() instanceof IDiagramModelContainer) {
        List<IDiagramModelObject> originalList = ((IDiagramModelContainer) getModel()).getChildren();
        IChildEditPartFilter[] filters = getRootEditPartFilterProvider().getEditPartFilters(IChildEditPartFilter.class);
        if (filters != null) {
            List<IDiagramModelObject> filteredList = new ArrayList<IDiagramModelObject>();
            for (IDiagramModelObject object : originalList) {
                boolean add = true;
                for (IChildEditPartFilter filter : filters) {
                    add = filter.isChildElementVisible(this, object);
                    if (!add) {
                        // no point in trying the next filter
                        break;
                    }
                }
                if (add) {
                    filteredList.add(object);
                }
            }
            return filteredList;
        }
        return originalList;
    }
    return Collections.EMPTY_LIST;
}
Also used : ArrayList(java.util.ArrayList) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 14 with IDiagramModelContainer

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

the class AbstractModelView method getDiagramElementsToUpdate.

/**
 * Find all elements contained in Diagram or Diagram objects including any child objects
 */
private void getDiagramElementsToUpdate(List<Object> list, IDiagramModelContainer container) {
    // ArchiMate element
    if (container instanceof IDiagramModelArchimateObject) {
        IArchimateElement element = ((IDiagramModelArchimateObject) container).getArchimateElement();
        if (!list.contains(element)) {
            list.add(element);
            getRelationshipsToUpdate(list, element);
        }
    }
    // Children
    for (IDiagramModelObject child : container.getChildren()) {
        if (child instanceof IDiagramModelContainer) {
            getDiagramElementsToUpdate(list, (IDiagramModelContainer) child);
        }
    }
}
Also used : IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 15 with IDiagramModelContainer

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

the class AbstractModelView method getElementsToUpdateFromNotification.

/**
 * @return All the tree element nodes that may need updating when a change occurs
 */
protected List<Object> getElementsToUpdateFromNotification(Notification msg) {
    int type = msg.getEventType();
    Object element = null;
    if (type == Notification.REMOVE) {
        element = msg.getOldValue();
    } else if (type == Notification.ADD) {
        element = msg.getNewValue();
    } else if (type == Notification.SET) {
        element = msg.getNotifier();
    }
    List<Object> list = new ArrayList<Object>();
    // If it's a diagram object or a diagram dig in and treat it separately
    if (element instanceof IDiagramModelContainer) {
        getDiagramElementsToUpdate(list, (IDiagramModelContainer) element);
        return list;
    }
    // If it's a diagram connection get the relationship
    if (element instanceof IDiagramModelArchimateConnection) {
        element = ((IDiagramModelArchimateConnection) element).getArchimateRelationship();
    }
    // Got either a folder, a relationship or an element
    if (element != null) {
        if (!list.contains(element)) {
            list.add(element);
        }
        // If an element, also add any attached relationships
        if (element instanceof IArchimateElement) {
            getRelationshipsToUpdate(list, (IArchimateElement) element);
        }
    }
    return list;
}
Also used : IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) ArrayList(java.util.ArrayList) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Aggregations

IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)15 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)13 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)6 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)4 IArchimateElement (com.archimatetool.model.IArchimateElement)3 ArrayList (java.util.ArrayList)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 IBounds (com.archimatetool.model.IBounds)2 IDiagramModel (com.archimatetool.model.IDiagramModel)2 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)2 ILockable (com.archimatetool.model.ILockable)2 EObject (org.eclipse.emf.ecore.EObject)2 GraphicalViewer (org.eclipse.gef.GraphicalViewer)2 CreateDiagramArchimateConnectionWithDialogCommand (com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand)1 AbstractBaseEditPart (com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart)1 GroupEditPart (com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart)1 IContainerFigure (com.archimatetool.editor.diagram.figures.IContainerFigure)1 IConnectable (com.archimatetool.model.IConnectable)1 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)1 IDiagramModelComponent (com.archimatetool.model.IDiagramModelComponent)1