use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class CopySnapshot method getMinimumPoint.
// Find leftmost and topmost origin of top level objects
private Point getMinimumPoint(Set<IConnectable> selectedObjects) {
// flag values
int xOrigin = 99999, yOrigin = 99999;
for (IConnectable object : selectedObjects) {
if (object instanceof IDiagramModelObject) {
IDiagramModelObject dmo = (IDiagramModelObject) object;
Point pt = new Point(dmo.getBounds().getX(), dmo.getBounds().getY());
translateToAbsolute(dmo, pt);
// If this object has a parent that is also selected, ignore it
if (dmo.eContainer() instanceof IDiagramModelObject && selectedObjects.contains(dmo.eContainer())) {
continue;
}
if (pt.x < xOrigin) {
xOrigin = pt.x;
}
if (pt.y < yOrigin) {
yOrigin = pt.y;
}
}
}
return (xOrigin == 99999 || yOrigin == 99999) ? null : new Point(xOrigin, yOrigin);
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class CopySnapshot method createPasteObject.
private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
// Don't paste invalid objects
if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
return null;
}
IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
createID(pasteObject);
// Offset top level objects if container is diagram
if (container instanceof IDiagramModel) {
IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
IBounds bounds = originalObject.getBounds().getCopy();
Point pt = new Point(bounds.getX(), bounds.getY());
translateToAbsolute(originalObject, pt);
bounds.setX(pt.x + fXOffSet);
bounds.setY(pt.y + fYOffSet);
pasteObject.setBounds(bounds);
}
// If Archimate object
if (pasteObject instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
// Re-use original ArchiMate components
if (!fDoCreateNewArchimateComponents) {
IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
IArchimateElement element = originalDiagramObject.getArchimateElement();
dmo.setArchimateElement(element);
}
// Provide new names if required
if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
String name = dmo.getArchimateElement().getName();
// $NON-NLS-1$
dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
}
}
// Add to Mapping
fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
// Object is Container, so recurse
if (snapshotObject instanceof IDiagramModelContainer) {
for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
if (dmo != null) {
((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
}
}
}
return pasteObject;
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class CopySnapshot method getTopLevelObjectsToCopy.
/*
* Create a list of topmost objects to copy.
* This will eliminate duplicate selected children and give us only the top level objects to copy.
*/
private List<IDiagramModelObject> getTopLevelObjectsToCopy(List<IDiagramModelComponent> selected) {
List<IDiagramModelObject> objects = new ArrayList<IDiagramModelObject>();
for (IDiagramModelComponent component : selected) {
if (component instanceof IDiagramModelObject) {
if (!hasAncestorSelected((IDiagramModelObject) component, selected)) {
// if an ancestor is selected don't add that
objects.add((IDiagramModelObject) component);
}
}
}
/*
* Restore the relative Z-Order in this new list by original Z-order in original model
* If each has the same container parent
*/
Collections.sort(objects, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (o1 instanceof IDiagramModelObject && o2 instanceof IDiagramModelObject) {
IDiagramModelContainer parent1 = (IDiagramModelContainer) ((IDiagramModelObject) o1).eContainer();
IDiagramModelContainer parent2 = (IDiagramModelContainer) ((IDiagramModelObject) o2).eContainer();
if (parent1 == parent2) {
int index1 = parent1.getChildren().indexOf(o1);
int index2 = parent2.getChildren().indexOf(o2);
return index1 - index2;
}
}
return 0;
}
});
return objects;
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class CutAction method run.
@Override
public void run() {
// Copy and then Delete Selected objects
super.run();
BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
public void run() {
CompoundCommand result = new CompoundCommand(Messages.CutAction_1);
for (Object object : getSelectedObjects()) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) model);
result.add(cmd);
}
}
}
// Don't use unwrap because we want the "Cut" label
execute(result);
}
});
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class DefaultEditPartSizeAction method createDefaultSizeCommand.
private Command createDefaultSizeCommand(List<?> objects) {
CompoundCommand command = new CompoundCommand();
for (Object object : objects) {
if (object instanceof GraphicalEditPart) {
GraphicalEditPart part = (GraphicalEditPart) object;
if (part.getModel() instanceof IDiagramModelObject) {
IDiagramModelObject model = (IDiagramModelObject) part.getModel();
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
IFigure figure = part.getFigure();
if (figure instanceof IDiagramModelObjectFigure) {
Dimension defaultSize = ((IDiagramModelObjectFigure) figure).getDefaultSize();
IBounds bounds = model.getBounds().getCopy();
if (bounds.getWidth() != defaultSize.width || bounds.getHeight() != defaultSize.height) {
bounds.setWidth(defaultSize.width);
bounds.setHeight(defaultSize.height);
Command cmd = new SetConstraintObjectCommand(model, bounds);
command.add(cmd);
}
}
}
}
}
return command.unwrap();
}
Aggregations