use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCreateCommand_CreatesLineConnectionCommand.
@Test
public void testGetConnectionCreateCommand_CreatesLineConnectionCommand() throws Exception {
setupSourcePolicy(IArchimateFactory.eINSTANCE.createBusinessActor());
CreateConnectionRequest request = new CreateConnectionRequest();
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelConnection()));
Command cmd = sourcePolicy.getConnectionCreateCommand(request);
assertNotNull(cmd);
assertTrue(cmd.getClass() == CreateDiagramConnectionCommand.class);
assertEquals(cmd, request.getStartCommand());
assertEquals(sourceDiagramObject, TestUtils.getPrivateField(cmd, "fSource"));
}
use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.
the class XMLModelImporter method addNodes.
// ========================================= Nodes ======================================
private void addNodes(IDiagramModelContainer parentContainer, Element parentElement) throws XMLModelParserException {
for (Element nodeElement : parentElement.getChildren(ELEMENT_NODE, ARCHIMATE3_NAMESPACE)) {
IDiagramModelObject dmo = null;
// This has an element ref so it's an ArchiMate element node
String elementRef = nodeElement.getAttributeValue(ATTRIBUTE_ELEMENTREF);
if (hasValue(elementRef)) {
IArchimateConcept concept = fConceptsLookup.get(elementRef);
if (!(concept instanceof IArchimateElement)) {
throw new XMLModelParserException(Messages.XMLModelImporter_5 + elementRef);
}
// Create new diagram node object
dmo = ArchimateDiagramModelFactory.createDiagramModelArchimateObject((IArchimateElement) concept);
} else // No element ref so this is another type of node, but what is it?
{
boolean isGroup = ATTRIBUTE_CONTAINER_TYPE.equals(nodeElement.getAttributeValue(ATTRIBUTE_TYPE, XSI_NAMESPACE));
boolean isLabel = ATTRIBUTE_LABEL_TYPE.equals(nodeElement.getAttributeValue(ATTRIBUTE_TYPE, XSI_NAMESPACE));
// Does the graphical node have children?
// Our notes cannot contain children, so if it does contain children it has to be a Group.
boolean hasChildren = nodeElement.getChildren(ELEMENT_NODE, ARCHIMATE3_NAMESPACE).size() > 0;
// Is it a label with view ref?
boolean isViewRef = isLabel && nodeElement.getChild(ELEMENT_VIEWREF, ARCHIMATE3_NAMESPACE) != null;
if (isGroup || hasChildren) {
ICreationFactory factory = new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelGroup());
IDiagramModelGroup group = (IDiagramModelGroup) factory.getNewObject();
dmo = group;
// Label
String name = getChildElementText(nodeElement, ELEMENT_LABEL, true);
if (name != null) {
dmo.setName(name);
}
// Documentation
String documentation = getChildElementText(nodeElement, ELEMENT_DOCUMENTATION, false);
if (documentation != null) {
group.setDocumentation(documentation);
}
} else // View Ref
if (isViewRef) {
IDiagramModelReference ref = IArchimateFactory.eINSTANCE.createDiagramModelReference();
dmo = ref;
// View reference
Element viewRefElement = nodeElement.getChild(ELEMENT_VIEWREF, ARCHIMATE3_NAMESPACE);
String viewRefID = viewRefElement.getAttributeValue(ATTRIBUTE_REF);
// The referenced diagram model will have to be set afterwards since we may not have created it yet
// so we use this a temp store
fDiagramRefsLookup.put(ref, viewRefID);
} else // A Note is our only other option
{
ICreationFactory factory = new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getDiagramModelNote());
IDiagramModelNote note = (IDiagramModelNote) factory.getNewObject();
dmo = note;
// Text
String text = getChildElementText(nodeElement, ELEMENT_LABEL, false);
if (text != null) {
note.setContent(text);
}
}
}
if (dmo != null) {
// Add Identifier before adding to model
String identifier = nodeElement.getAttributeValue(ATTRIBUTE_IDENTIFIER);
dmo.setId(identifier);
// Add the child first
parentContainer.getChildren().add(dmo);
// Get the absolute bounds as declared in the XML file
IBounds bounds = getNodeBounds(nodeElement);
// Convert the given absolute bounds into relative bounds if this is in a child object
if (parentContainer instanceof IDiagramModelObject) {
bounds = DiagramModelUtils.getRelativeBounds(bounds, (IDiagramModelObject) parentContainer);
}
dmo.setBounds(bounds);
// Style
addNodeStyle(dmo, nodeElement.getChild(ELEMENT_STYLE, ARCHIMATE3_NAMESPACE));
// Add to lookup
fConnectionsNodesLookup.put(dmo.getId(), dmo);
// Child nodes
if (dmo instanceof IDiagramModelContainer) {
addNodes((IDiagramModelContainer) dmo, nodeElement);
}
}
}
}
use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.
the class CreateDiagramArchimateConnectionWithDialogCommandTests method runOnceBeforeEachTest.
@Before
public void runOnceBeforeEachTest() {
CreateConnectionRequest request = new CreateConnectionRequest();
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
cmd = new CreateDiagramArchimateConnectionWithDialogCommand(request);
}
use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCreateCommand_CreatesNullCommand.
@Test
public void testGetConnectionCreateCommand_CreatesNullCommand() {
setupSourcePolicy(IArchimateFactory.eINSTANCE.createJunction());
CreateConnectionRequest request = new CreateConnectionRequest();
// Use a non-legal relationship
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getSpecializationRelationship()));
// Should be null
Command cmd = sourcePolicy.getConnectionCreateCommand(request);
assertNull(cmd);
}
use of com.archimatetool.editor.diagram.ArchimateDiagramModelFactory in project archi by archimatetool.
the class ArchimateDiagramConnectionPolicyTests method testGetConnectionCompleteCommand.
@Test
public void testGetConnectionCompleteCommand() throws Exception {
setupSourcePolicy(IArchimateFactory.eINSTANCE.createBusinessActor());
setupTargetPolicy(IArchimateFactory.eINSTANCE.createBusinessRole());
CreateConnectionRequest request = new CreateConnectionRequest();
request.setFactory(new ArchimateDiagramModelFactory(IArchimatePackage.eINSTANCE.getAssignmentRelationship()));
EditPart sourceEditPart = mock(EditPart.class);
when(sourceEditPart.getModel()).thenReturn(sourceDiagramObject);
request.setSourceEditPart(sourceEditPart);
Command startCommand = sourcePolicy.getConnectionCreateCommand(request);
assertNotNull(startCommand);
Command endCommand = targetPolicy.getConnectionCompleteCommand(request);
assertNotNull(endCommand);
assertEquals(startCommand, endCommand);
assertEquals(targetDiagramObject, TestUtils.getPrivateField(endCommand, "fTarget"));
}
Aggregations