use of com.archimatetool.model.IDiagramModel in project archi by archimatetool.
the class UsedInViewsSection method createTableControl.
private void createTableControl(Composite parent) {
createLabel(parent, Messages.UsedInViewsSection_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);
// 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 DiagramModelUtils.findReferencedDiagramsForArchimateConcept((IArchimateConcept) inputElement).toArray();
}
});
fTableViewer.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((IDiagramModel) element).getName();
}
@Override
public Image getImage(Object element) {
return IArchiImages.ImageFactory.getImage(IArchiImages.ICON_DIAGRAM);
}
});
fTableViewer.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
if (!isAlive(fArchimateConcept)) {
return;
}
Object o = ((IStructuredSelection) event.getSelection()).getFirstElement();
if (o instanceof IDiagramModel) {
IDiagramModel diagramModel = (IDiagramModel) o;
IDiagramModelEditor editor = EditorManager.openDiagramEditor(diagramModel);
if (editor instanceof IArchimateDiagramEditor) {
((IArchimateDiagramEditor) editor).selectArchimateConcepts(new IArchimateConcept[] { fArchimateConcept });
}
}
}
});
fTableViewer.setComparator(new ViewerComparator());
}
use of com.archimatetool.model.IDiagramModel in project archi by archimatetool.
the class ArchimateModelTests method testGetDiagramModels.
@Test
public void testGetDiagramModels() {
EList<IDiagramModel> list = model.getDiagramModels();
assertNotNull(list);
assertTrue(list.isEmpty());
IDiagramModel dm1 = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm1).getElements().add(dm1);
IDiagramModel dm2 = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
model.getDefaultFolderForObject(dm2).getElements().add(dm2);
list = model.getDiagramModels();
assertEquals(2, list.size());
}
use of com.archimatetool.model.IDiagramModel 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.IDiagramModel in project archi by archimatetool.
the class CanvasDNDEditPolicy method getLocalDropCommand.
/**
* Handle dragging elements from the Models Tree
*/
protected Command getLocalDropCommand(DiagramDropRequest request) {
if (!(request.getData() instanceof IStructuredSelection)) {
return null;
}
// XY drop point
Point pt = getDropLocation(request);
// Origin
int origin = pt.x;
int x = pt.x;
int y = pt.y;
// Gather an actual list of elements dragged onto the container, omitting duplicates and anything already on the diagram
Object[] objects = ((IStructuredSelection) request.getData()).toArray();
List<IDiagramModel> list = getDiagramRefsToAdd(objects);
// Compound Command
CompoundCommand result = new CompoundCommand(Messages.CanvasDNDEditPolicy_2);
for (IDiagramModel diagramModel : list) {
result.add(new AddDiagramModelReferenceCommand(getTargetContainer(), diagramModel, x, y));
x += 150;
if (x > origin + 400) {
x = origin;
y += 100;
}
}
return result;
}
use of com.archimatetool.model.IDiagramModel in project archi by archimatetool.
the class TreeModelView method fillContextMenu.
/**
* Fill context menu when user right-clicks
* @param manager
*/
private void fillContextMenu(IMenuManager manager) {
IStructuredSelection selection = ((IStructuredSelection) getViewer().getSelection());
Object selected = selection.getFirstElement();
boolean isEmpty = selected == null;
if (isEmpty) {
manager.add(fActionNewModel);
manager.add(fActionOpenModel);
return;
}
// $NON-NLS-1$
MenuManager newMenu = new MenuManager(Messages.TreeModelView_1, "new");
manager.add(newMenu);
// $NON-NLS-1$
getSite().registerContextMenu(ID + ".new_menu", newMenu, getViewer());
manager.add(new Separator());
// Selected model
if (selected instanceof IArchimateModel) {
manager.add(fActionCloseModel);
manager.add(fActionSaveModel);
manager.add(new Separator());
}
// Selected Diagram
if (selected instanceof IDiagramModel) {
manager.add(fActionOpenDiagram);
// $NON-NLS-1$
manager.add(new Separator("open"));
}
if (selected instanceof IFolder) {
newMenu.add(fActionNewFolder);
newMenu.add(new Separator());
}
// Create "New" Actions
List<IAction> actions = TreeModelViewActionFactory.INSTANCE.getNewObjectActions(selected);
for (IAction action : actions) {
if (action == null) {
newMenu.add(new Separator());
} else {
newMenu.add(action);
}
}
// $NON-NLS-1$
newMenu.add(new Separator("new_additions"));
if (!isEmpty) {
manager.add(new Separator());
manager.add(fActionDelete);
manager.add(fActionRename);
// $NON-NLS-1$
manager.add(new Separator("start_collapse"));
// Expand selected
for (Object o : selection.toArray()) {
if (hasExpandableNodes(o)) {
manager.add(fActionExpandSelected);
break;
}
}
// Collapse selected
for (Object o : selection.toArray()) {
if (fTreeViewer.isExpandable(o) && fTreeViewer.getExpandedState(o)) {
manager.add(fActionCollapseSelected);
break;
}
}
// $NON-NLS-1$
manager.add(new Separator("end_collapse"));
if (DuplicateCommandHandler.canDuplicate(selection)) {
manager.add(fActionDuplicate);
}
// $NON-NLS-1$
manager.add(new Separator("start_extensions"));
manager.add(fActionGenerateView);
// $NON-NLS-1$
manager.add(new GroupMarker("append_extensions"));
// $NON-NLS-1$
manager.add(new Separator("end_extensions"));
// $NON-NLS-1$
manager.add(new Separator("start_properties"));
manager.add(fActionProperties);
// $NON-NLS-1$
manager.add(new GroupMarker("append_properties"));
// $NON-NLS-1$
manager.add(new Separator("end_properties"));
}
// Other plug-ins can contribute their actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
Aggregations