use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicy method isValidConnection.
/**
* @param source
* @param target
* @param relationshipType
* @return True if valid connection source/target for connection type
*/
static boolean isValidConnection(IConnectable source, IConnectable target, EClass relationshipType) {
/*
* Diagram Connection from/to notes/groups/diagram refs.
* Allowed between notes, visual groups, diagram refs and ArchiMate components
*/
if (relationshipType == IArchimatePackage.eINSTANCE.getDiagramModelConnection()) {
// Not circular
if (source == target) {
return false;
}
// Notes
if (source instanceof IDiagramModelNote || target instanceof IDiagramModelNote) {
return true;
}
// Groups
if (source instanceof IDiagramModelGroup || target instanceof IDiagramModelGroup) {
return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
}
// Diagram Refs
if (source instanceof IDiagramModelReference || target instanceof IDiagramModelReference) {
return !(source instanceof IDiagramModelArchimateComponent) && !(target instanceof IDiagramModelArchimateComponent);
}
return false;
}
// Connection from Archimate concept to Archimate concept (but not from relation to relation)
if ((source instanceof IDiagramModelArchimateComponent && target instanceof IDiagramModelArchimateComponent) && !(source instanceof IDiagramModelArchimateConnection && target instanceof IDiagramModelArchimateConnection)) {
// Special case if relationshipType == null. Means that the Magic connector is being used
if (relationshipType == null) {
return true;
}
IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) source).getArchimateConcept();
IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) target).getArchimateConcept();
return ArchimateModelUtils.isValidRelationship(sourceConcept, targetConcept, relationshipType);
}
return false;
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicy method getReconnectCommand.
/**
* Create a ReconnectCommand
*/
protected Command getReconnectCommand(ReconnectRequest request, boolean isSourceCommand) {
IDiagramModelConnection connection = (IDiagramModelConnection) request.getConnectionEditPart().getModel();
// The re-connected object
IConnectable newObject = (IConnectable) getHost().getModel();
// Get the type of connection (plain) or relationship (if archimate connection) and check if it is valid
EClass type = connection.eClass();
if (connection instanceof IDiagramModelArchimateConnection) {
type = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship().eClass();
}
if (isSourceCommand) {
if (!isValidConnection(newObject, connection.getTarget(), type)) {
return null;
}
} else {
if (!isValidConnection(connection.getSource(), newObject, type)) {
return null;
}
}
/*
* Re-connect ArchiMate Connection to Archimate Component
* In this case we have to check for matching occurences on all diagrams
*/
if (connection instanceof IDiagramModelArchimateConnection && newObject instanceof IDiagramModelArchimateComponent) {
IArchimateRelationship relationship = ((IDiagramModelArchimateConnection) connection).getArchimateRelationship();
IArchimateConcept newConcept = ((IDiagramModelArchimateComponent) newObject).getArchimateConcept();
// Compound Command
CompoundCommand result = new CompoundCommand();
// Check for matching connections in this and other diagrams
for (IDiagramModel diagramModel : newConcept.getArchimateModel().getDiagramModels()) {
for (IDiagramModelArchimateConnection matchingConnection : DiagramModelUtils.findDiagramModelConnectionsForRelation(diagramModel, relationship)) {
IDiagramModelArchimateComponent matchingComponent = null;
// Same Diagram so use the new target
if (newObject.getDiagramModel() == diagramModel) {
matchingComponent = (IDiagramModelArchimateComponent) newObject;
} else // Different Diagram so find a match
{
List<IDiagramModelArchimateComponent> list = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, newConcept);
if (!list.isEmpty()) {
matchingComponent = list.get(0);
}
}
// Does the new object exist on the diagram? Yes, reconnect
if (matchingComponent != null) {
ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(matchingConnection);
if (isSourceCommand) {
cmd.setNewSource(matchingComponent);
} else {
cmd.setNewTarget(matchingComponent);
}
result.add(cmd);
} else // No, so delete the matching connection
{
result.add(DiagramCommandFactory.createDeleteDiagramConnectionCommand(matchingConnection));
}
}
}
return result.unwrap();
} else // Re-connect other cases
{
ReconnectDiagramConnectionCommand cmd = new ReconnectDiagramConnectionCommand(connection);
if (isSourceCommand) {
cmd.setNewSource(newObject);
} else {
cmd.setNewTarget(newObject);
}
return cmd;
}
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class MyImporter method createAndAddConnectionsToView.
protected void createAndAddConnectionsToView(IDiagramModel diagramModel, IArchimateRelationship relationship) {
List<IDiagramModelArchimateComponent> sources = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getSource());
List<IDiagramModelArchimateComponent> targets = DiagramModelUtils.findDiagramModelComponentsForArchimateConcept(diagramModel, relationship.getTarget());
for (IDiagramModelComponent dmcSource : sources) {
for (IDiagramModelComponent dmcTarget : targets) {
IDiagramModelArchimateConnection dmc = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
dmc.setArchimateRelationship(relationship);
dmc.connect((IDiagramModelObject) dmcSource, (IDiagramModelObject) dmcTarget);
idLookup.put(dmc.getId(), dmc);
}
}
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class MagicConnectionCreationTool method handleCreateConnection.
/**
* When this is called, a CreateConnectionRequest will already have been created.
* This CreateConnectionRequest will be passed to the ArchimateDiagramConnectionPolicy.
* ArchimateDiagramConnectionPolicy will, in turn, create a CreateArchimateConnectionCommand.
*
* So, at this point, we already have the source and target edit parts and model objects set in a Command.
* If we want to change this at all we will have to kludge it.
*/
@Override
protected boolean handleCreateConnection() {
// Clear the connection factory first
getFactory().clear();
// Do this first, here (we have to!)
fCanSetCurrentCommand = true;
Command endCommand = getCommand();
setCurrentCommand(endCommand);
// Get this now!
CreateConnectionRequest request = (CreateConnectionRequest) getTargetRequest();
EditPart sourceEditPart = request.getSourceEditPart();
EditPart targetEditPart = request.getTargetEditPart();
if (sourceEditPart == null || sourceEditPart == targetEditPart) {
eraseSourceFeedback();
return false;
}
IDiagramModelArchimateComponent sourceDiagramModelComponent = (IDiagramModelArchimateComponent) sourceEditPart.getModel();
// If targetEditPart is null then user clicked on the diagram or on a non-Archimate concept Editpart
if (targetEditPart == null) {
return createElementAndConnection(sourceDiagramModelComponent, request.getLocation());
}
// User clicked on Archimate target concept edit part
if (targetEditPart.getModel() instanceof IDiagramModelArchimateComponent) {
return createConnection(request, sourceDiagramModelComponent, (IDiagramModelArchimateComponent) targetEditPart.getModel());
}
eraseSourceFeedback();
return false;
}
use of com.archimatetool.model.IDiagramModelArchimateComponent in project archi by archimatetool.
the class MagicConnectionCreationTool method setTargetEditPart.
@Override
protected void setTargetEditPart(EditPart editpart) {
/*
* Set editpart to null if it's not an Archimate target concept so we can handle it as if we clicked on the canvas.
* This also disables unwanted connection target feedback.
*/
if (editpart != null && !(editpart.getModel() instanceof IDiagramModelArchimateComponent)) {
editpart = null;
}
/*
* Check whether we are trying to connect an element to a relation where the relation is already connected to that element
* If we are, set editpart to null to veto it.
*/
if (editpart != null) {
EditPart sourceEditPart = ((CreateConnectionRequest) getSourceRequest()).getSourceEditPart();
if (sourceEditPart != null) {
if (sourceEditPart.getModel() instanceof IDiagramModelArchimateComponent && editpart.getModel() instanceof IDiagramModelArchimateComponent) {
IArchimateConcept sourceConcept = ((IDiagramModelArchimateComponent) sourceEditPart.getModel()).getArchimateConcept();
IArchimateConcept targetConcept = ((IDiagramModelArchimateComponent) editpart.getModel()).getArchimateConcept();
if (ArchimateModelUtils.hasDirectRelationship(sourceConcept, targetConcept)) {
editpart = null;
}
}
}
}
super.setTargetEditPart(editpart);
}
Aggregations