use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class DeleteFromModelAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
List<IArchimateConcept> archimateConcepts = new ArrayList<IArchimateConcept>();
List<IDiagramModelComponent> diagramObjects = new ArrayList<IDiagramModelComponent>();
// Gather Model elements, relations
for (Object object : selection) {
if (object instanceof EditPart) {
Object model = ((EditPart) object).getModel();
if (model instanceof IDiagramModelArchimateObject) {
IArchimateElement element = ((IDiagramModelArchimateObject) model).getArchimateElement();
if (!archimateConcepts.contains(element)) {
archimateConcepts.add(element);
}
// Element's relationships
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(element)) {
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
} else if (model instanceof IDiagramModelArchimateConnection) {
IArchimateRelationship relation = ((IDiagramModelArchimateConnection) model).getArchimateRelationship();
if (!archimateConcepts.contains(relation)) {
archimateConcepts.add(relation);
}
// Relation's relationships
for (IArchimateRelationship r : ArchimateModelUtils.getAllRelationshipsForConcept(relation)) {
if (!archimateConcepts.contains(r)) {
archimateConcepts.add(r);
}
}
}
}
}
// Gather referenced diagram objects
for (IArchimateConcept archimateConcept : archimateConcepts) {
for (IDiagramModel diagramModel : archimateConcept.getArchimateModel().getDiagramModels()) {
for (IDiagramModelComponent dc : DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, archimateConcept)) {
diagramObjects.add(dc);
}
}
}
// Check whether any of these concepts are referenced in other diagrams
if (hasMoreThanOneReference(archimateConcepts, diagramObjects)) {
if (!MessageDialog.openQuestion(Display.getDefault().getActiveShell(), Messages.DeleteFromModelAction_0, Messages.DeleteFromModelAction_1 + // $NON-NLS-1$
"\n\n" + Messages.DeleteFromModelAction_2)) {
return;
}
}
// Create commands
CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(TEXT);
for (IArchimateConcept archimateConcept : archimateConcepts) {
if (archimateConcept instanceof IArchimateElement) {
Command cmd = new DeleteArchimateElementCommand((IArchimateElement) archimateConcept);
compoundCommand.add(cmd);
} else if (archimateConcept instanceof IArchimateRelationship) {
Command cmd = new DeleteArchimateRelationshipCommand((IArchimateRelationship) archimateConcept);
compoundCommand.add(cmd);
}
}
for (IDiagramModelComponent dc : diagramObjects) {
if (dc instanceof IDiagramModelObject) {
Command cmd = DiagramCommandFactory.createDeleteDiagramObjectCommand((IDiagramModelObject) dc);
compoundCommand.add(cmd);
} else if (dc instanceof IDiagramModelConnection) {
Command cmd = DiagramCommandFactory.createDeleteDiagramConnectionCommand((IDiagramModelConnection) dc);
compoundCommand.add(cmd);
}
}
execute(compoundCommand);
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class FillColorAction method run.
@Override
public void run() {
List<?> selection = getSelectedObjects();
IDiagramModelObject model = (IDiagramModelObject) getFirstValidSelectedModelObject(selection);
if (model == null) {
return;
}
ColorDialog colorDialog = new ColorDialog(getWorkbenchPart().getSite().getShell());
// Set default RGB on first selected object
RGB defaultRGB = null;
String s = model.getFillColor();
if (s == null) {
defaultRGB = ColorFactory.getDefaultFillColor(model).getRGB();
} else {
defaultRGB = ColorFactory.convertStringToRGB(s);
}
if (defaultRGB != null) {
colorDialog.setRGB(defaultRGB);
}
RGB newColor = colorDialog.open();
if (newColor != null) {
execute(createCommand(selection, newColor));
}
}
use of com.archimatetool.model.IDiagramModelObject 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();
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class CreateDiagramConnectionCommand method createBendPoints.
/**
* Adding a circular connection requires some bendpoints
*/
protected void createBendPoints() {
// TODO Only works for IDiagramModelObject as source and target objects not for connections
if (!(fConnection.getSource() instanceof IDiagramModelObject) && !(fConnection.getTarget() instanceof IDiagramModelObject)) {
return;
}
IDiagramModelObject source = (IDiagramModelObject) fConnection.getSource();
IDiagramModelObject target = (IDiagramModelObject) fConnection.getTarget();
int width = source.getBounds().getWidth();
if (width == -1) {
width = 100;
}
int height = target.getBounds().getHeight();
if (height == -1) {
height = 60;
}
width = (int) Math.max(100, width * 0.6);
height = (int) Math.max(60, height * 0.6);
CreateBendpointCommand cmd = new CreateBendpointCommand();
cmd.setDiagramModelConnection(fConnection);
cmd.setRelativeDimensions(new Dimension(width, 0), new Dimension(width, 0));
cmd.execute();
cmd.setRelativeDimensions(new Dimension(width, height), new Dimension(width, height));
cmd.execute();
cmd.setRelativeDimensions(new Dimension(0, height), new Dimension(0, height));
cmd.execute();
}
use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.
the class ResetAspectRatioAction method createCommand.
private Command createCommand(List<?> objects) {
CompoundCommand result = new CompoundCommand();
for (Object object : objects) {
if (object instanceof DiagramImageEditPart) {
DiagramImageEditPart part = (DiagramImageEditPart) object;
IDiagramModelObject model = part.getModel();
// Locked
if (model instanceof ILockable && ((ILockable) model).isLocked()) {
continue;
}
IBounds modelBounds = model.getBounds().getCopy();
int currentHeight = modelBounds.getHeight();
int currentWidth = modelBounds.getWidth();
// Already set to default height and width
if (currentHeight == -1 && currentWidth == -1) {
continue;
}
// Get original default size
DiagramImageFigure figure = part.getFigure();
Dimension size = figure.getDefaultSize();
if (size.height == 0 || size.width == 0) {
continue;
}
float originalRatio = ((float) size.height / (float) size.width);
float currentRatio = ((float) currentHeight / (float) currentWidth);
// If the ratio is different within tolerance
if (Math.abs(originalRatio - currentRatio) > 0.01) {
int width = currentWidth;
int height = currentHeight;
if (currentWidth < currentHeight) {
width = (int) (currentHeight / originalRatio);
} else {
height = (int) (currentWidth * originalRatio);
}
modelBounds.setWidth(width);
modelBounds.setHeight(height);
Command cmd = new SetConstraintObjectCommand(model, modelBounds);
result.add(cmd);
}
}
}
return result.unwrap();
}
Aggregations