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