Search in sources :

Example 46 with IDiagramModel

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

the class CopySnapshot method createPasteObject.

private IDiagramModelObject createPasteObject(IDiagramModelContainer container, IDiagramModelObject snapshotObject) {
    // Don't paste invalid objects
    if (!isValidPasteComponent(fTargetDiagramModel, snapshotObject)) {
        return null;
    }
    IDiagramModelObject pasteObject = (IDiagramModelObject) snapshotObject.getCopy();
    createID(pasteObject);
    // Offset top level objects if container is diagram
    if (container instanceof IDiagramModel) {
        IDiagramModelObject originalObject = (IDiagramModelObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
        IBounds bounds = originalObject.getBounds().getCopy();
        Point pt = new Point(bounds.getX(), bounds.getY());
        translateToAbsolute(originalObject, pt);
        bounds.setX(pt.x + fXOffSet);
        bounds.setY(pt.y + fYOffSet);
        pasteObject.setBounds(bounds);
    }
    // If Archimate object
    if (pasteObject instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject dmo = (IDiagramModelArchimateObject) pasteObject;
        // Re-use original ArchiMate components
        if (!fDoCreateNewArchimateComponents) {
            IDiagramModelArchimateObject originalDiagramObject = (IDiagramModelArchimateObject) fOriginalToSnapshotComponentsMapping.getKey(snapshotObject);
            IArchimateElement element = originalDiagramObject.getArchimateElement();
            dmo.setArchimateElement(element);
        }
        // Provide new names if required
        if (fDoCreateNewArchimateComponents && isSourceAndTargetArchiMateModelSame()) {
            String name = dmo.getArchimateElement().getName();
            // $NON-NLS-1$
            dmo.getArchimateElement().setName(name + " " + Messages.CopySnapshot_1);
        }
    }
    // Add to Mapping
    fSnapshotToNewComponentMapping.put(snapshotObject, pasteObject);
    // Object is Container, so recurse
    if (snapshotObject instanceof IDiagramModelContainer) {
        for (IDiagramModelObject child : ((IDiagramModelContainer) snapshotObject).getChildren()) {
            IDiagramModelObject dmo = createPasteObject((IDiagramModelContainer) pasteObject, child);
            if (dmo != null) {
                ((IDiagramModelContainer) pasteObject).getChildren().add(dmo);
            }
        }
    }
    return pasteObject;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IBounds(com.archimatetool.model.IBounds) IArchimateElement(com.archimatetool.model.IArchimateElement) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) Point(org.eclipse.draw2d.geometry.Point) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer)

Example 47 with IDiagramModel

use of com.archimatetool.model.IDiagramModel 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 48 with IDiagramModel

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

the class JasperReportsExporter method writeDiagrams.

/**
 * Write the diagrams to temp files
 */
void writeDiagrams(File tmpFolder) {
    for (IDiagramModel dm : fModel.getDiagramModels()) {
        Image image = DiagramUtils.createImage(dm, 1, 10);
        // $NON-NLS-1$
        String diagramName = dm.getId() + ".png";
        try {
            ImageLoader loader = new ImageLoader();
            loader.data = new ImageData[] { image.getImageData(ImageFactory.getDeviceZoom()) };
            File file = new File(tmpFolder, diagramName);
            loader.save(file.getAbsolutePath(), SWT.IMAGE_PNG);
        } finally {
            image.dispose();
        }
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) File(java.io.File)

Example 49 with IDiagramModel

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

the class CreateMapViewCheatSheetAction method run.

public void run(String[] params, ICheatSheetManager manager) {
    IViewPart viewPart = ViewManager.showViewPart(ITreeModelView.ID, true);
    if (viewPart == null) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_0, Messages.CreateMapViewCheatSheetAction_1);
        return;
    }
    IArchimateModel model = viewPart.getAdapter(IArchimateModel.class);
    if (model == null) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_2, Messages.CreateMapViewCheatSheetAction_3);
        return;
    }
    EList<IDiagramModel> diagramModels = model.getDiagramModels();
    if (diagramModels.size() < 2) {
        MessageDialog.openWarning(Display.getCurrent().getActiveShell(), Messages.CreateMapViewCheatSheetAction_4, Messages.CreateMapViewCheatSheetAction_5);
        return;
    }
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    if (stack != null) {
        stack.execute(new NewMapViewCommand(model));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IViewPart(org.eclipse.ui.IViewPart) IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 50 with IDiagramModel

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

the class ArchimateModel method getDiagramModels.

/**
 * <!-- begin-user-doc -->
 * Return the Diagram Models - could be empty list
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<IDiagramModel> getDiagramModels() {
    EList<IDiagramModel> list = new BasicEList<IDiagramModel>();
    IFolder folder = getFolder(FolderType.DIAGRAMS);
    if (folder != null) {
        for (Iterator<EObject> iter = folder.eAllContents(); iter.hasNext(); ) {
            EObject eObject = iter.next();
            if (eObject instanceof IDiagramModel) {
                list.add((IDiagramModel) eObject);
            }
        }
    }
    return list;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) BasicEList(org.eclipse.emf.common.util.BasicEList) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) IFolder(com.archimatetool.model.IFolder)

Aggregations

IDiagramModel (com.archimatetool.model.IDiagramModel)68 Test (org.junit.Test)28 IArchimateElement (com.archimatetool.model.IArchimateElement)16 IArchimateModel (com.archimatetool.model.IArchimateModel)12 IArchimateRelationship (com.archimatetool.model.IArchimateRelationship)12 IDiagramModelArchimateObject (com.archimatetool.model.IDiagramModelArchimateObject)11 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)10 IDiagramModelArchimateConnection (com.archimatetool.model.IDiagramModelArchimateConnection)9 File (java.io.File)8 EObject (org.eclipse.emf.ecore.EObject)8 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)8 Image (org.eclipse.swt.graphics.Image)8 IArchimateConcept (com.archimatetool.model.IArchimateConcept)7 IDiagramModelReference (com.archimatetool.model.IDiagramModelReference)7 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 IDiagramModelArchimateComponent (com.archimatetool.model.IDiagramModelArchimateComponent)6 Command (org.eclipse.gef.commands.Command)6 GraphicalViewerImpl (org.eclipse.gef.ui.parts.GraphicalViewerImpl)6 Shell (org.eclipse.swt.widgets.Shell)6