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;
}
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;
}
Aggregations