Search in sources :

Example 1 with IDiagramModelContainer

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

the class FixDefaultSizesHandler method getNewSize.

/**
 * Get a new size for a diagram object if width or height are not set
 * Child figures will affect the size.
 */
Dimension getNewSize(IDiagramModelObject dmo) {
    IBounds bounds = dmo.getBounds().getCopy();
    if (bounds.getWidth() != -1 && bounds.getHeight() != -1) {
        return new Dimension(bounds.getWidth(), bounds.getHeight());
    }
    // Calculate default size based on children
    if (dmo instanceof IDiagramModelContainer && ((IDiagramModelContainer) dmo).getChildren().size() > 0) {
        IDiagramModelContainer container = (IDiagramModelContainer) dmo;
        // Start with zero and build up from that...
        Dimension childrenSize = new Dimension();
        for (IDiagramModelObject child : container.getChildren()) {
            IBounds childbounds = child.getBounds().getCopy();
            Dimension size = getNewSize(child);
            childrenSize.width = Math.max(childbounds.getX() + size.width() + 10, childrenSize.width);
            childrenSize.height = Math.max(childbounds.getY() + size.height() + 10, childrenSize.height);
        }
        Dimension defaultSize = getDefaultSize(dmo);
        Dimension newSize = childrenSize.union(defaultSize);
        return newSize;
    }
    // No children...
    return getDefaultSize(dmo);
}
Also used : IBounds(com.archimatetool.model.IBounds) Dimension(org.eclipse.draw2d.geometry.Dimension) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 2 with IDiagramModelContainer

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

the class MagicConnectionCreationTool method createElementAndConnection.

/**
 * Create an Element and a connection in one go when user clicks on the canvas or in a non-Archimate Editpart
 */
private boolean createElementAndConnection(IDiagramModelArchimateComponent sourceDiagramModelComponent, Point location) {
    // Grab this now as it will disappear after menu is shown
    EditPartViewer viewer = getCurrentViewer();
    // What did we click on?
    GraphicalEditPart targetEditPart = (GraphicalEditPart) viewer.findObjectAt(getCurrentInput().getMouseLocation());
    // Target parent (default is the diagram itself)
    IDiagramModelContainer parent = sourceDiagramModelComponent.getDiagramModel();
    // If we clicked on a Group EditPart use that as parent
    if (targetEditPart instanceof GroupEditPart) {
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    } else // Or did we click on something else? Then use the parent of that
    if (targetEditPart instanceof AbstractBaseEditPart) {
        targetEditPart = (GraphicalEditPart) targetEditPart.getParent();
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    }
    boolean elementsFirst = Preferences.isMagicConnectorPolarity();
    boolean modKeyPressed = getCurrentInput().isModKeyDown(SWT.MOD1);
    elementsFirst ^= modKeyPressed;
    Menu menu = new Menu(getCurrentViewer().getControl());
    // User will hover over element, then connection
    if (elementsFirst) {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = false;
        addElementActions(menu, sourceDiagramModelComponent);
    } else // User will hover over connection, then element
    {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = true;
        addConnectionActions(menu, sourceDiagramModelComponent);
    }
    menu.setVisible(true);
    // Modal menu
    Display display = menu.getDisplay();
    while (!menu.isDisposed() && menu.isVisible()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    // SWT Menu does not fire Selection Event when Windows touch display is enabled
    if (PlatformUtils.isWindows()) {
        while (display.readAndDispatch()) ;
    }
    if (!menu.isDisposed()) {
        menu.dispose();
    }
    eraseSourceFeedback();
    // No selection
    if (getFactory().getElementType() == null || getFactory().getRelationshipType() == null) {
        getFactory().clear();
        return false;
    }
    // Create Compound Command first
    CompoundCommand cmd = new CreateElementCompoundCommand((FigureCanvas) viewer.getControl(), location.x, location.y);
    // If the EditPart's Figure is a Container, adjust the location to relative co-ords
    if (targetEditPart.getFigure() instanceof IContainerFigure) {
        ((IContainerFigure) targetEditPart.getFigure()).translateMousePointToRelative(location);
    } else // Or compensate for scrolled parent figure
    {
        IFigure contentPane = targetEditPart.getContentPane();
        contentPane.translateToRelative(location);
    }
    CreateNewDiagramObjectCommand cmd1 = new CreateNewDiagramObjectCommand(parent, getFactory().getElementType(), location);
    Command cmd2 = new CreateNewConnectionCommand(sourceDiagramModelComponent, cmd1.getNewObject(), getFactory().getRelationshipType());
    cmd.add(cmd1);
    cmd.add(cmd2);
    executeCommand(cmd);
    // Clear the factory
    getFactory().clear();
    return true;
}
Also used : AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) EditPartViewer(org.eclipse.gef.EditPartViewer) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) IContainerFigure(com.archimatetool.editor.diagram.figures.IContainerFigure) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) Menu(org.eclipse.swt.widgets.Menu) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Display(org.eclipse.swt.widgets.Display) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with IDiagramModelContainer

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

the class CopySnapshot method createSnapshotObject.

/*
     * Make snapshot copy of object
     */
private IDiagramModelObject createSnapshotObject(IDiagramModelObject originalObject) {
    IDiagramModelObject snapshotObject = (IDiagramModelObject) originalObject.getCopy();
    // Add to mapping
    fOriginalToSnapshotComponentsMapping.put(originalObject, snapshotObject);
    // Object is Container, so recurse
    if (snapshotObject instanceof IDiagramModelContainer) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) originalObject).getChildren()) {
            IDiagramModelObject dmo = createSnapshotObject(child);
            ((IDiagramModelContainer) snapshotObject).getChildren().add(dmo);
        }
    }
    return snapshotObject;
}
Also used : IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 4 with IDiagramModelContainer

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

the class CopySnapshot method translateToAbsolute.

/**
 * Translate an objects x,y position to absolute co-ordinates
 * @param object
 * @param pt
 */
private void translateToAbsolute(IDiagramModelObject object, Point pt) {
    if (object.eContainer() instanceof IDiagramModelContainer && !(object.eContainer() instanceof IDiagramModel)) {
        IDiagramModelObject parent = (IDiagramModelObject) object.eContainer();
        pt.performTranslate(parent.getBounds().getX(), parent.getBounds().getY());
        translateToAbsolute(parent, pt);
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 5 with IDiagramModelContainer

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

the class BringForwardAction method createCommand.

private Command createCommand(List<?> selection) {
    GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    CompoundCommand result = new CompoundCommand(Messages.BringForwardAction_0);
    for (Object object : selection) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart editPart = (GraphicalEditPart) object;
            Object model = editPart.getModel();
            // This can happen if we do things wrong
            if (viewer != editPart.getViewer()) {
                // $NON-NLS-1$
                System.err.println("Wrong selection for viewer in " + getClass());
            }
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelObject) {
                IDiagramModelObject diagramObject = (IDiagramModelObject) model;
                IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
                /*
                     * Parent can be null when objects are selected (with marquee tool) and transferred from one container
                     * to another and the Diagram Editor updates the enablement state of Actions.
                     */
                if (parent == null) {
                    continue;
                }
                List<IDiagramModelObject> modelChildren = parent.getChildren();
                int originalPos = modelChildren.indexOf(diagramObject);
                if (originalPos < modelChildren.size() - 1) {
                    result.add(new BringForwardCommand(parent, originalPos));
                }
            }
        }
    }
    return result.unwrap();
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

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