use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class ObjectUIFactoryProviderTests method testGetProvider_EObject_DiagramModelArchimateObject.
@Test
public void testGetProvider_EObject_DiagramModelArchimateObject() {
IObjectUIProvider provider = new BusinessActorUIProvider();
factory.registerProvider(provider);
IDiagramModelArchimateObject eObject = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IArchimateElement element = IArchimateFactory.eINSTANCE.createBusinessActor();
eObject.setArchimateElement(element);
assertEquals(provider, factory.getProvider(eObject));
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class ArchimateContainerEditPolicy method createNewConnectionCommands.
/**
* When Archimate child objects are dragged out of a parent Archimate object check to see if new connections should be created
*
* TODO A3: If O1--C1--O2 and in parent. C1 is also connected to parent (and hidden).
* O1 or O2 is removed from parent - should add connection from C1 to parent?
* Or should it be only when O1 AND O2 are removed from parent?
*/
void createNewConnectionCommands(IDiagramModelArchimateObject parentObject, List<?> childEditParts, CompoundCommand command) {
IArchimateElement parentElement = parentObject.getArchimateElement();
for (Object o : childEditParts) {
IDiagramModelObject child = (IDiagramModelObject) ((EditPart) o).getModel();
// If it's an Archimate type child object...
if (child instanceof IDiagramModelArchimateObject) {
IDiagramModelArchimateObject childObject = (IDiagramModelArchimateObject) child;
IArchimateElement childElement = childObject.getArchimateElement();
// See if there are any (nested type) relationships between parent element and child element...
for (IArchimateRelationship relation : parentElement.getSourceRelationships()) {
if (relation.getTarget() == childElement && DiagramModelUtils.isNestedConnectionTypeRelationship(relation)) {
// And there's not a connection already there then add one
if (!DiagramModelUtils.hasDiagramModelArchimateConnection(parentObject, childObject, relation)) {
command.add(new CreateDiagramArchimateConnectionCommand(parentObject, childObject, relation));
}
}
}
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class ArchimateDNDEditPolicy method getDropCommand.
@Override
protected Command getDropCommand(DiagramDropRequest request) {
if (!(request.getData() instanceof IStructuredSelection)) {
return null;
}
// XY drop point
Point pt = getDropLocation(request);
int origin = pt.x;
int x = pt.x;
int y = pt.y;
fElementsToAdd = new ArrayList<IArchimateElement>();
fRelationsToAdd = new ArrayList<IArchimateRelationship>();
fDiagramRefsToAdd = new ArrayList<IDiagramModel>();
// Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
Object[] objects = ((IStructuredSelection) request.getData()).toArray();
getElementsToAdd(objects);
// Store the Diagram Model Components that will be added in this list
List<IDiagramModelArchimateComponent> diagramComponentsThatWereAdded = new ArrayList<IDiagramModelArchimateComponent>();
// Create a Compound Command - it has to be Non-Notifying or it's too slow (tested with Bill's UoB model!)
CompoundCommand result = new NonNotifyingCompoundCommand(Messages.ArchimateDNDEditPolicy_0);
// Add the Commands adding the Elements first
for (IArchimateElement element : fElementsToAdd) {
// Add Diagram object
IDiagramModelArchimateObject dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject(element);
// Set location
dmo.getBounds().setLocation(x, y);
// Store it
diagramComponentsThatWereAdded.add(dmo);
// Add Command
result.add(new AddDiagramObjectCommand(getTargetContainer(), dmo));
// Increase x,y
x += 150;
if (x > origin + 400) {
x = origin;
y += 100;
}
}
// Then any Diagram Model Ref Commands
for (IDiagramModel diagramModel : fDiagramRefsToAdd) {
result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
x += 150;
if (x > origin + 400) {
x = origin;
y += 100;
}
}
// Add selected Relations to create connections to those elements on the diagram that don't already have them
for (IArchimateRelationship relation : fRelationsToAdd) {
// Find existing source & target components on the diagram that the new connection will link to
List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
for (IDiagramModelComponent dcSource : sources) {
for (IDiagramModelComponent dcTarget : targets) {
if (dcSource instanceof IConnectable && dcTarget instanceof IConnectable) {
// Add a new connection between dcSource & dcTarget if there isn't already one on the diagram
if (dcTarget != dcSource && !DiagramModelUtils.hasDiagramModelArchimateConnection((IConnectable) dcSource, (IConnectable) dcTarget, relation)) {
// Check that source or target is not a hiden connection
if (!((dcSource instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcSource)) || (dcTarget instanceof IDiagramModelArchimateConnection && DiagramModelUtils.shouldBeHiddenConnection((IDiagramModelArchimateConnection) dcTarget)))) {
AddDiagramArchimateConnectionCommand cmd = new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dcTarget, relation);
result.add(cmd);
// Store it
diagramComponentsThatWereAdded.add(cmd.getConnection());
}
}
}
}
}
}
// Whether to add connections to elements
Boolean value = (Boolean) request.getExtendedData().get(ArchimateDiagramTransferDropTargetListener.ADD_ELEMENT_CONNECTIONS);
boolean addConnectionsToElements = value != null && value.booleanValue();
// Newly added concepts will need new connections to both existing and newly added concepts
for (IDiagramModelArchimateComponent dmComponent : diagramComponentsThatWereAdded) {
IArchimateConcept archimateConcept = dmComponent.getArchimateConcept();
for (IArchimateRelationship relation : ArchimateModelUtils.getAllRelationshipsForConcept(archimateConcept)) {
/*
* If the user holds down the Copy key (Ctrl on win/lnx, Alt on Mac) then linked connections
* are not added on drag and drop. However, any selected relations' linked objects are added.
*/
if (!addConnectionsToElements && !fRelationsToAdd.contains(relation)) {
continue;
}
// Find existing objects
List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getSource());
List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(getTargetDiagramModel(), relation.getTarget());
// Add new ones too
for (IDiagramModelArchimateComponent dmComponent2 : diagramComponentsThatWereAdded) {
if (dmComponent != dmComponent2) {
IArchimateConcept archimateConcept2 = dmComponent2.getArchimateConcept();
if (archimateConcept2 == relation.getSource()) {
// Only need to add sources, not targets
sources.add(dmComponent2);
}
}
}
// Make the Commands...
for (IDiagramModelComponent dcSource : sources) {
if (dcSource instanceof IConnectable && archimateConcept == relation.getTarget()) {
result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dcSource, (IConnectable) dmComponent, relation));
}
}
for (IDiagramModelComponent dcTarget : targets) {
if (dcTarget instanceof IConnectable && archimateConcept == relation.getSource()) {
result.add(new AddDiagramArchimateConnectionCommand((IConnectable) dmComponent, (IConnectable) dcTarget, relation));
}
}
}
}
// Then, if adding to an Archimate container type to create nesting, ask whether to add new relations if none exist...
if (ConnectionPreferences.createRelationWhenAddingModelTreeElement() && getTargetContainer() instanceof IDiagramModelArchimateObject) {
List<IDiagramModelArchimateObject> diagramObjectsThatWereAdded = new ArrayList<IDiagramModelArchimateObject>();
for (IDiagramModelArchimateComponent dmc : diagramComponentsThatWereAdded) {
if (dmc instanceof IDiagramModelArchimateObject) {
diagramObjectsThatWereAdded.add((IDiagramModelArchimateObject) dmc);
}
}
Command cmd = new CreateNestedArchimateConnectionsWithDialogCommand((IDiagramModelArchimateObject) getTargetContainer(), diagramObjectsThatWereAdded);
result.add(cmd);
}
// return the full compound command
return result;
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi by archimatetool.
the class MyImporter method createAndAddElementToView.
protected IDiagramModelArchimateObject createAndAddElementToView(IDiagramModel diagramModel, IArchimateElement element, int x, int y, int width, int height) {
IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo.setArchimateElement(element);
dmo.setBounds(x, y, width, height);
diagramModel.getChildren().add(dmo);
idLookup.put(dmo.getId(), dmo);
return dmo;
}
use of com.archimatetool.model.IDiagramModelArchimateObject in project archi-modelrepository-plugin by archi-contribs.
the class GraficoModelImporter method resolveProxies.
/**
* Iterate through all model objects, and resolve proxies on known classes
*/
private void resolveProxies() {
for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
EObject eObject = iter.next();
if (eObject instanceof IArchimateRelationship) {
// Resolve proxies for Relations
IArchimateRelationship relation = (IArchimateRelationship) eObject;
relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
} else if (eObject instanceof IDiagramModelArchimateObject) {
// Resolve proxies for Elements
IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
// Update cross-references
element.getArchimateElement().getReferencingDiagramObjects().add(element);
} else if (eObject instanceof IDiagramModelArchimateConnection) {
// Resolve proxies for Connections
IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
// Update cross-reference
archiConnection.getArchimateRelationship().getReferencingDiagramConnections().add(archiConnection);
} else if (eObject instanceof IDiagramModelReference) {
// Resolve proxies for Model References
IDiagramModelReference element = (IDiagramModelReference) eObject;
element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
}
}
}
Aggregations