Search in sources :

Example 1 with IContainerFigure

use of com.archimatetool.editor.diagram.figures.IContainerFigure in project archi by archimatetool.

the class AbstractDNDEditPolicy method getDropLocation.

/**
 * Return the actual drop location
 * @param request
 * @return the actual drop location
 */
protected Point getDropLocation(DiagramDropRequest request) {
    // XY drop point
    Point pt = request.getDropLocation();
    // Translate drop point
    IFigure figure = ((GraphicalEditPart) getHost()).getFigure();
    if (figure instanceof IContainerFigure) {
        ((IContainerFigure) figure).translateMousePointToRelative(pt);
    } else // Translate to relative content pane
    {
        IFigure contentPane = ((GraphicalEditPart) getHost()).getContentPane();
        contentPane.translateToRelative(pt);
    }
    return pt;
}
Also used : Point(org.eclipse.draw2d.geometry.Point) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IContainerFigure(com.archimatetool.editor.diagram.figures.IContainerFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with IContainerFigure

use of com.archimatetool.editor.diagram.figures.IContainerFigure 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)

Aggregations

IContainerFigure (com.archimatetool.editor.diagram.figures.IContainerFigure)2 IFigure (org.eclipse.draw2d.IFigure)2 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)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 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)1 Point (org.eclipse.draw2d.geometry.Point)1 EditPartViewer (org.eclipse.gef.EditPartViewer)1 Command (org.eclipse.gef.commands.Command)1 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)1 Display (org.eclipse.swt.widgets.Display)1 Menu (org.eclipse.swt.widgets.Menu)1