use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class UsedInRelationshipsSection method createTableControl.
private void createTableControl(Composite parent) {
createLabel(parent, Messages.UsedInRelationshipsSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
// Table
Composite tableComp = createTableComposite(parent, SWT.NONE);
TableColumnLayout tableLayout = (TableColumnLayout) tableComp.getLayout();
fTableViewer = new TableViewer(tableComp, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
// Column
TableViewerColumn column = new TableViewerColumn(fTableViewer, SWT.NONE, 0);
tableLayout.setColumnData(column.getColumn(), new ColumnWeightData(100, false));
// On Mac shows alternate table row colours
fTableViewer.getTable().setLinesVisible(true);
// Help ID
PlatformUI.getWorkbench().getHelpSystem().setHelp(fTableViewer.getTable(), HELP_ID);
fTableViewer.setContentProvider(new IStructuredContentProvider() {
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public void dispose() {
}
public Object[] getElements(Object inputElement) {
return ArchimateModelUtils.getAllRelationshipsForConcept((IArchimateElement) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new UsedInRelationshipsTableLabelProvider(fTableViewer.getTable()));
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
if (isAlive(fArchimateElement)) {
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof IArchimateRelationship) {
IArchimateRelationship relation = (IArchimateRelationship) o;
ITreeModelView view = (ITreeModelView) ViewManager.findViewPart(ITreeModelView.ID);
if (view != null) {
view.getViewer().setSelection(new StructuredSelection(relation), true);
}
}
}
}
});
fTableViewer.setComparator(new ViewerComparator());
// DND
fTableViewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE | DND.DROP_LINK, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
// Drag started from the Table
LocalSelectionTransfer.getTransfer().setSelection(fTableViewer.getSelection());
event.doit = true;
}
public void dragSetData(DragSourceEvent event) {
// For consistency set the data to the selection even though
// the selection is provided by the LocalSelectionTransfer
// to the drop target adapter.
event.data = LocalSelectionTransfer.getTransfer().getSelection();
}
public void dragFinished(DragSourceEvent event) {
LocalSelectionTransfer.getTransfer().setSelection(null);
}
});
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class GenerateViewCommand method createDiagramModel.
private IArchimateDiagramModel createDiagramModel() {
// New Diagram
IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
dm.setName(fViewName);
dm.setViewpoint(fViewpoint.getID());
fParentFolder = fSelectedElements.get(0).getArchimateModel().getDefaultFolderForObject(dm);
fParentFolder.getElements().add(dm);
int x = 20;
int y = 20;
getElementsToAdd();
for (IArchimateElement element : fSelectedElements) {
createDiagramNode(element, dm, x, y);
y += 100;
}
x = 170;
y = 20;
for (IArchimateElement element : fAddedElements) {
if (!fSelectedElements.contains(element)) {
createDiagramNode(element, dm, x, y);
y += 80;
if (y > 700) {
y = 20;
x += 150;
}
}
}
// Add connections between elements first
for (IDiagramModelObject dmoSource : dm.getChildren()) {
IArchimateElement elementSource = ((IDiagramModelArchimateObject) dmoSource).getArchimateElement();
for (IArchimateRelationship relation : elementSource.getSourceRelationships()) {
for (IDiagramModelObject dmoTarget : dm.getChildren()) {
IArchimateElement elementTarget = ((IDiagramModelArchimateObject) dmoTarget).getArchimateElement();
// Don't add connections that are not connected to the main elements if option is set
if (!fAddAllConnections && !(fSelectedElements.contains(elementSource)) && !(fSelectedElements.contains(elementTarget))) {
continue;
}
if (relation.getTarget() == elementTarget) {
// Create connection
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(dmoSource, dmoTarget);
}
}
}
}
// Add connections to connections
for (Iterator<EObject> iter1 = dm.eAllContents(); iter1.hasNext(); ) {
EObject eObject1 = iter1.next();
if (eObject1 instanceof IDiagramModelArchimateConnection) {
IDiagramModelArchimateConnection connection = (IDiagramModelArchimateConnection) eObject1;
for (IDiagramModelObject dmo : dm.getChildren()) {
IArchimateElement element = ((IDiagramModelArchimateObject) dmo).getArchimateElement();
for (IArchimateRelationship relation : connection.getArchimateRelationship().getSourceRelationships()) {
if (relation.getTarget() == element) {
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(connection, dmo);
}
}
for (IArchimateRelationship relation : connection.getArchimateRelationship().getTargetRelationships()) {
if (relation.getSource() == element) {
IDiagramModelArchimateConnection newConnection = ArchimateDiagramModelFactory.createDiagramModelArchimateConnection(relation);
newConnection.connect(dmo, connection);
}
}
}
}
}
return dm;
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class DiagramModelExtraTests method testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects.
/**
* See {@link DiagramModelArchimateConnection#eInverseAdd(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
* See {@link DiagramModelArchimateConnection#eInverseRemove(org.eclipse.emf.ecore.InternalEObject, int, Class, org.eclipse.emf.common.notify.NotificationChain)}
*/
@Test
public void testDiagramModelArchimateConnection_eInverseAdd_Relationship_getReferencingDiagramObjects() {
IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element3 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element4 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
IArchimateRelationship relation3 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
relation1.setSource(element1);
relation1.setTarget(element2);
relation2.setSource(element2);
relation2.setTarget(element3);
relation3.setSource(element3);
relation3.setTarget(element4);
IDiagramModelArchimateObject dmo1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
IDiagramModelArchimateObject dmo4 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo1.setArchimateElement(element1);
dmo2.setArchimateElement(element2);
dmo3.setArchimateElement(element3);
dmo4.setArchimateElement(element4);
IDiagramModelArchimateConnection conn1 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
IDiagramModelArchimateConnection conn3 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
// conn3a shares a relationship with conn3
IDiagramModelArchimateConnection conn3a = IArchimateFactory.eINSTANCE.createDiagramModelArchimateConnection();
conn1.setArchimateRelationship(relation1);
conn2.setArchimateRelationship(relation2);
conn3.setArchimateRelationship(relation3);
// same
conn3a.setArchimateRelationship(relation3);
// Set up model and diagram model
IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
model.setDefaults();
IDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm).getElements().add(dm);
// Add some parents
IDiagramModelGroup parent1 = IArchimateFactory.eINSTANCE.createDiagramModelGroup();
dm.getChildren().add(parent1);
IDiagramModelArchimateObject parent2 = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
parent1.getChildren().add(parent2);
// Add the dmos
dm.getChildren().add(dmo1);
parent1.getChildren().add(dmo2);
parent2.getChildren().add(dmo3);
dm.getChildren().add(dmo4);
// Starts at sizes
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Connect
conn1.connect(dmo1, dmo2);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
conn2.connect(dmo2, dmo3);
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
conn3.connect(dmo3, dmo4);
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
conn3a.connect(dmo3, dmo4);
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Remove diagram model, should be the same
((IFolder) dm.eContainer()).getElements().remove(dm);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Add diagram model back again
model.getDefaultFolderForObject(dm).getElements().add(dm);
assertEquals(1, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(1, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(2, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
// Disconnect
conn1.disconnect();
conn2.disconnect();
conn3.disconnect();
conn3a.disconnect();
assertEquals(0, conn1.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn2.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3.getArchimateRelationship().getReferencingDiagramConnections().size());
assertEquals(0, conn3a.getArchimateRelationship().getReferencingDiagramConnections().size());
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class ArchimateModelUtilsTests method testGetAllRelationshipsForConcept.
@Test
public void testGetAllRelationshipsForConcept() {
IArchimateElement element1 = IArchimateFactory.eINSTANCE.createBusinessActor();
IArchimateElement element2 = IArchimateFactory.eINSTANCE.createBusinessRole();
IArchimateRelationship relation1 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
relation1.setSource(element1);
relation1.setTarget(element2);
assertEquals(1, ArchimateModelUtils.getAllRelationshipsForConcept(element1).size());
assertEquals(1, ArchimateModelUtils.getAllRelationshipsForConcept(element2).size());
IArchimateRelationship relation2 = IArchimateFactory.eINSTANCE.createAssociationRelationship();
relation2.setSource(element1);
relation2.setTarget(element2);
assertEquals(2, ArchimateModelUtils.getAllRelationshipsForConcept(element1).size());
assertEquals(2, ArchimateModelUtils.getAllRelationshipsForConcept(element2).size());
}
use of com.archimatetool.model.IArchimateRelationship in project archi by archimatetool.
the class ZestViewerContentProviderTests method testGetElements_Element.
@Test
public void testGetElements_Element() {
IArchimateElement inputElement = (IArchimateElement) tm.getObjectByID("521");
Object[] elements = provider.getElements(inputElement);
assertEquals(17, elements.length);
for (Object object : elements) {
assertTrue(object instanceof IArchimateRelationship);
}
}
Aggregations