Search in sources :

Example 1 with ICanvasModelConnection

use of com.archimatetool.canvas.model.ICanvasModelConnection in project archi by archimatetool.

the class CanvasModelFactory method getNewObject.

@Override
public Object getNewObject() {
    // Create the instance from the registered factory in case of extensions
    EObject object = fTemplate.getEPackage().getEFactoryInstance().create(fTemplate);
    // Sticky
    if (object instanceof ICanvasModelSticky) {
        ICanvasModelSticky sticky = (ICanvasModelSticky) object;
        if (fParam instanceof RGB) {
            String color = ColorFactory.convertRGBToString((RGB) fParam);
            sticky.setFillColor(color);
        }
        // $NON-NLS-1$
        sticky.setBorderColor("#C0C0C0");
    } else // Block
    if (object instanceof ICanvasModelBlock) {
        ICanvasModelBlock block = (ICanvasModelBlock) object;
        // $NON-NLS-1$
        block.setBorderColor("#000000");
    } else // Image
    if (object instanceof ICanvasModelImage) {
        ICanvasModelImage image = (ICanvasModelImage) object;
        // $NON-NLS-1$
        image.setBorderColor("#000000");
    } else // Canvas Connection
    if (object instanceof ICanvasModelConnection) {
        ICanvasModelConnection connection = (ICanvasModelConnection) object;
        if (fParam instanceof Integer) {
            connection.setType((Integer) fParam);
        }
    }
    IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider) ObjectUIFactory.INSTANCE.getProvider(object);
    if (object instanceof ITextAlignment) {
        ((IDiagramModelObject) object).setTextAlignment(provider.getDefaultTextAlignment());
    }
    if (object instanceof ITextPosition) {
        ((ITextPosition) object).setTextPosition(provider.getDefaultTextPosition());
    }
    // Add new bounds with a default user size
    if (object instanceof IDiagramModelObject) {
        Dimension size = provider.getDefaultSize();
        ((IDiagramModelObject) object).setBounds(0, 0, size.width, size.height);
    }
    return object;
}
Also used : ICanvasModelSticky(com.archimatetool.canvas.model.ICanvasModelSticky) ITextPosition(com.archimatetool.model.ITextPosition) ICanvasModelBlock(com.archimatetool.canvas.model.ICanvasModelBlock) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Dimension(org.eclipse.draw2d.geometry.Dimension) RGB(org.eclipse.swt.graphics.RGB) ICanvasModelConnection(com.archimatetool.canvas.model.ICanvasModelConnection) ITextAlignment(com.archimatetool.model.ITextAlignment) EObject(org.eclipse.emf.ecore.EObject) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) ICanvasModelImage(com.archimatetool.canvas.model.ICanvasModelImage)

Example 2 with ICanvasModelConnection

use of com.archimatetool.canvas.model.ICanvasModelConnection in project archi by archimatetool.

the class CanvasModelFactoryTests method testGetNewObjectConnection.

@Test
public void testGetNewObjectConnection() {
    ICreationFactory factory = new CanvasModelFactory(ICanvasPackage.eINSTANCE.getCanvasModelConnection(), 2);
    ICanvasModelConnection connection = (ICanvasModelConnection) factory.getNewObject();
    assertEquals("", connection.getName());
    assertEquals(2, connection.getType());
}
Also used : ICanvasModelConnection(com.archimatetool.canvas.model.ICanvasModelConnection) ICreationFactory(com.archimatetool.editor.diagram.ICreationFactory) Test(org.junit.Test)

Aggregations

ICanvasModelConnection (com.archimatetool.canvas.model.ICanvasModelConnection)2 ICanvasModelBlock (com.archimatetool.canvas.model.ICanvasModelBlock)1 ICanvasModelImage (com.archimatetool.canvas.model.ICanvasModelImage)1 ICanvasModelSticky (com.archimatetool.canvas.model.ICanvasModelSticky)1 ICreationFactory (com.archimatetool.editor.diagram.ICreationFactory)1 IGraphicalObjectUIProvider (com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider)1 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)1 ITextAlignment (com.archimatetool.model.ITextAlignment)1 ITextPosition (com.archimatetool.model.ITextPosition)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 EObject (org.eclipse.emf.ecore.EObject)1 RGB (org.eclipse.swt.graphics.RGB)1 Test (org.junit.Test)1