Search in sources :

Example 31 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class ArchimateDiagramModelFactory method getNewObject.

public Object getNewObject() {
    if (fTemplate == null) {
        return null;
    }
    Object object = IArchimateFactory.eINSTANCE.create(fTemplate);
    // Connection created from Relationship Template
    if (object instanceof IArchimateRelationship) {
        return createDiagramModelArchimateConnection((IArchimateRelationship) object);
    } else // Archimate Diagram Object created from Archimate Element Template
    if (object instanceof IArchimateElement) {
        IArchimateElement element = (IArchimateElement) object;
        element.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate));
        return createDiagramModelArchimateObject(element);
    } else // Group
    if (object instanceof IDiagramModelGroup) {
        IDiagramModelGroup group = (IDiagramModelGroup) object;
        group.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate));
        ColorFactory.setDefaultColors(group);
        ((IDiagramModelGroup) object).setTextAlignment(ITextAlignment.TEXT_ALIGNMENT_LEFT);
    } else // Note
    if (object instanceof IDiagramModelNote) {
        ColorFactory.setDefaultColors((IDiagramModelObject) object);
        ((IDiagramModelNote) object).setTextAlignment(ITextAlignment.TEXT_ALIGNMENT_LEFT);
    } else // Connection
    if (object instanceof IDiagramModelConnection) {
        ColorFactory.setDefaultColors((IDiagramModelConnection) object);
    }
    return object;
}
Also used : IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelNote(com.archimatetool.model.IDiagramModelNote)

Example 32 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class SendBackwardAction method createCommand.

private Command createCommand(List<?> selection) {
    GraphicalViewer viewer = getWorkbenchPart().getAdapter(GraphicalViewer.class);
    CompoundCommand result = new CompoundCommand(TEXT);
    for (Object object : selection) {
        if (object instanceof GraphicalEditPart) {
            GraphicalEditPart editPart = (GraphicalEditPart) object;
            Object model = editPart.getModel();
            // This can happen if we do things wrong
            if (viewer != editPart.getViewer()) {
                // $NON-NLS-1$
                System.err.println("Wrong selection for Viewer in " + getClass());
            }
            // Locked
            if (model instanceof ILockable && ((ILockable) model).isLocked()) {
                continue;
            }
            if (model instanceof IDiagramModelObject) {
                IDiagramModelObject diagramObject = (IDiagramModelObject) model;
                IDiagramModelContainer parent = (IDiagramModelContainer) diagramObject.eContainer();
                /*
                     * Parent can be null when objects are selected (with marquee tool) and transferred from one container
                     * to another and the Diagram Editor updates the enablement state of Actions.
                     */
                if (parent == null) {
                    continue;
                }
                int originalPos = parent.getChildren().indexOf(diagramObject);
                if (originalPos > 0) {
                    result.add(new SendBackwardCommand(parent, originalPos));
                }
            }
        }
    }
    return result.unwrap();
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) ILockable(com.archimatetool.model.ILockable)

Example 33 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class HTMLReportExporter method writeDiagrams.

/**
 * Write diagrams
 */
private void writeDiagrams(File imagesFolder, File viewsFolder, ST stFrame) throws IOException {
    if (fModel.getDiagramModels().isEmpty()) {
        return;
    }
    // Save images
    saveImages(imagesFolder);
    for (IDiagramModel dm : fModel.getDiagramModels()) {
        // Add the necessary bounds in order to get correct absolute coordinates for the elements in the generated image
        Rectangle bounds = diagramBoundsMap.get(dm);
        // process the children
        for (IDiagramModelObject dmo : dm.getChildren()) {
            addNewBounds(dmo, bounds.x * -1, bounds.y * -1);
        }
        // $NON-NLS-1$
        File viewF = new File(viewsFolder, dm.getId() + ".html");
        // $NON-NLS-1$
        OutputStreamWriter viewW = new OutputStreamWriter(new FileOutputStream(viewF), "UTF8");
        // $NON-NLS-1$
        stFrame.remove("element");
        // $NON-NLS-1$
        stFrame.add("element", dm);
        // $NON-NLS-1$
        stFrame.remove("map");
        // $NON-NLS-1$
        stFrame.add("map", childBoundsMap);
        viewW.write(stFrame.render());
        viewW.close();
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) FileOutputStream(java.io.FileOutputStream) Rectangle(org.eclipse.draw2d.geometry.Rectangle) OutputStreamWriter(java.io.OutputStreamWriter) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) STGroupFile(org.stringtemplate.v4.STGroupFile) File(java.io.File)

Example 34 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class HTMLReportExporter method addNewBounds.

/**
 * Add new bounds for each diagram object in relation to its parent offset x,y
 */
private void addNewBounds(IDiagramModelObject dmo, int offsetX, int offsetY) {
    // Add new bounds caled to device zoom
    BoundsWithAbsolutePosition newBounds = new BoundsWithAbsolutePosition(dmo.getBounds(), ImageFactory.getDeviceZoom() / 100);
    // Add offset
    newBounds.setOffset(offsetX, offsetY);
    childBoundsMap.put(dmo.getId(), newBounds);
    // Children
    if (dmo instanceof IDiagramModelArchimateObject || dmo instanceof IDiagramModelGroup) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) dmo).getChildren()) {
            addNewBounds(child, newBounds.getX1(), newBounds.getY1());
        }
    }
}
Also used : IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelGroup(com.archimatetool.model.IDiagramModelGroup) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 35 with IDiagramModelObject

use of com.archimatetool.model.IDiagramModelObject in project archi by archimatetool.

the class DiagramModelObject method getCopy.

@Override
public EObject getCopy() {
    IDiagramModelObject newObject = (IDiagramModelObject) super.getCopy();
    newObject.getSourceConnections().clear();
    newObject.getTargetConnections().clear();
    return newObject;
}
Also used : IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Aggregations

IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)51 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)12 IDiagramModelContainer (com.archimatetool.model.IDiagramModelContainer)12 IDiagramModelConnection (com.archimatetool.model.IDiagramModelConnection)10 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)10 Test (org.junit.Test)10 IArchimateElement (com.archimatetool.model.IArchimateElement)9 Dimension (org.eclipse.draw2d.geometry.Dimension)9 IDiagramModel (com.archimatetool.model.IDiagramModel)8 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)7 IBounds (com.archimatetool.model.IBounds)6 Command (org.eclipse.gef.commands.Command)6 ILockable (com.archimatetool.model.ILockable)5 ArrayList (java.util.ArrayList)5 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)4 EObject (org.eclipse.emf.ecore.EObject)4 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)4 IArchimateModel (com.archimatetool.model.IArchimateModel)3 IDiagramModelGroup (com.archimatetool.model.IDiagramModelGroup)3 ILineObject (com.archimatetool.model.ILineObject)3