Search in sources :

Example 31 with IDiagramModel

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

the class SaveArchimateModelAsTemplateWizard method createManifest.

private String createManifest() throws IOException {
    Document doc = new Document();
    Element root = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_MANIFEST);
    doc.setRootElement(root);
    // Type
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE, ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL);
    // Timestamp
    root.setAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TIMESTAMP, Long.toString(System.currentTimeMillis()));
    // Name
    Element elementName = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_NAME);
    elementName.setText(fTemplateName);
    root.addContent(elementName);
    // Description
    Element elementDescription = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_DESCRIPTION);
    elementDescription.setText(fTemplateDescription);
    root.addContent(elementDescription);
    // Thumbnails
    if (fIncludeThumbnails) {
        if (fSelectedDiagramModel != null) {
            int i = 1;
            for (IDiagramModel dm : fModel.getDiagramModels()) {
                if (dm == fSelectedDiagramModel) {
                    // $NON-NLS-1$
                    String keyThumb = TemplateManager.ZIP_ENTRY_THUMBNAILS + i + ".png";
                    Element elementKeyThumb = new Element(ITemplateXMLTags.XML_TEMPLATE_ELEMENT_KEY_THUMBNAIL);
                    elementKeyThumb.setText(keyThumb);
                    root.addContent(elementKeyThumb);
                    break;
                }
                i++;
            }
        }
    }
    return JDOMUtils.write2XMLString(doc);
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 32 with IDiagramModel

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

the class HTMLReportExporter method saveImages.

/**
 * Save diagram images
 */
private void saveImages(File imagesFolder) {
    // Use this to generate unique name for image file
    Hashtable<IDiagramModel, String> nameTable = new Hashtable<IDiagramModel, String>();
    int nameCount = 1;
    for (IDiagramModel dm : fModel.getDiagramModels()) {
        ModelReferencedImage geoImage = DiagramUtils.createModelReferencedImage(dm, 1, 10);
        Image image = geoImage.getImage();
        // Generate file name
        String diagramName = dm.getId();
        if (StringUtils.isSet(diagramName)) {
            // removed this because ids can have hyphens in them (when imported from TOG format)
            // Let's hope that ids are filename friendly...
            // diagramName = FileUtils.getValidFileName(diagramName);
            int j = 2;
            // $NON-NLS-1$
            String s = diagramName + ".png";
            while (nameTable.containsValue(s)) {
                // $NON-NLS-1$ //$NON-NLS-2$
                s = diagramName + "_" + j++ + ".png";
            }
            diagramName = s;
        } else {
            // $NON-NLS-1$//$NON-NLS-2$
            diagramName = Messages.HTMLReportExporter_1 + " " + nameCount++ + ".png";
        }
        nameTable.put(dm, diagramName);
        // Get and store the bounds of the top-left element in the figure to act as overall x,y offset
        Rectangle bounds = geoImage.getBounds();
        // Account for device zoom level
        bounds.performScale(ImageFactory.getDeviceZoom() / 100);
        diagramBoundsMap.put(dm, bounds);
        try {
            ImageLoader loader = new ImageLoader();
            loader.data = new ImageData[] { image.getImageData(ImageFactory.getDeviceZoom()) };
            File file = new File(imagesFolder, diagramName);
            loader.save(file.getAbsolutePath(), SWT.IMAGE_PNG);
        } finally {
            image.dispose();
        }
    }
}
Also used : ModelReferencedImage(com.archimatetool.editor.diagram.util.ModelReferencedImage) IDiagramModel(com.archimatetool.model.IDiagramModel) Hashtable(java.util.Hashtable) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ModelReferencedImage(com.archimatetool.editor.diagram.util.ModelReferencedImage) Image(org.eclipse.swt.graphics.Image) ImageLoader(org.eclipse.swt.graphics.ImageLoader) STGroupFile(org.stringtemplate.v4.STGroupFile) File(java.io.File)

Example 33 with IDiagramModel

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

the class TreeModelView method eCoreChanged.

// =================================================================================
// React to ECore Model Changes
// =================================================================================
@Override
protected void eCoreChanged(Notification msg) {
    int type = msg.getEventType();
    Object notifier = msg.getNotifier();
    Object feature = msg.getFeature();
    // Attribute set
    if (type == Notification.SET) {
        // Viewpoint changed
        if (feature == IArchimatePackage.Literals.ARCHIMATE_DIAGRAM_MODEL__VIEWPOINT) {
            if (Preferences.STORE.getBoolean(IPreferenceConstants.VIEWPOINTS_FILTER_MODEL_TREE)) {
                if (notifier instanceof IDiagramModel) {
                    IArchimateModel model = ((IDiagramModel) notifier).getArchimateModel();
                    getViewer().refreshInBackground(model);
                }
            }
        } else {
            super.eCoreChanged(msg);
        }
    } else {
        super.eCoreChanged(msg);
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModelObject(com.archimatetool.model.IArchimateModelObject) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 34 with IDiagramModel

use of com.archimatetool.model.IDiagramModel in project archi-modelrepository-plugin by archi-contribs.

the class GraficoModelImporter method resolveProxies.

/**
 * Iterate through all model objects, and resolve proxies on known classes
 */
private void resolveProxies() {
    for (Iterator<EObject> iter = fModel.eAllContents(); iter.hasNext(); ) {
        EObject eObject = iter.next();
        if (eObject instanceof IArchimateRelationship) {
            // Resolve proxies for Relations
            IArchimateRelationship relation = (IArchimateRelationship) eObject;
            relation.setSource((IArchimateConcept) resolve(relation.getSource(), relation));
            relation.setTarget((IArchimateConcept) resolve(relation.getTarget(), relation));
        } else if (eObject instanceof IDiagramModelArchimateObject) {
            // Resolve proxies for Elements
            IDiagramModelArchimateObject element = (IDiagramModelArchimateObject) eObject;
            element.setArchimateElement((IArchimateElement) resolve(element.getArchimateElement(), element));
            // Update cross-references
            element.getArchimateElement().getReferencingDiagramObjects().add(element);
        } else if (eObject instanceof IDiagramModelArchimateConnection) {
            // Resolve proxies for Connections
            IDiagramModelArchimateConnection archiConnection = (IDiagramModelArchimateConnection) eObject;
            archiConnection.setArchimateRelationship((IArchimateRelationship) resolve(archiConnection.getArchimateRelationship(), archiConnection));
            // Update cross-reference
            archiConnection.getArchimateRelationship().getReferencingDiagramConnections().add(archiConnection);
        } else if (eObject instanceof IDiagramModelReference) {
            // Resolve proxies for Model References
            IDiagramModelReference element = (IDiagramModelReference) eObject;
            element.setReferencedModel((IDiagramModel) resolve(element.getReferencedModel(), element));
        }
    }
}
Also used : IDiagramModelReference(com.archimatetool.model.IDiagramModelReference) IDiagramModel(com.archimatetool.model.IDiagramModel) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IArchimateElement(com.archimatetool.model.IArchimateElement) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject)

Example 35 with IDiagramModel

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

the class EditorModelManager method openModel.

@Override
public IArchimateModel openModel(File file) {
    if (file == null || !file.exists()) {
        return null;
    }
    // If it is already loaded return it
    IArchimateModel model = locateLoadedModel(file);
    if (model != null) {
        return model;
    }
    model = loadModel(file);
    if (model != null) {
        // Open Views of newly opened model if set in Preferences
        if (Preferences.doOpenDiagramsOnLoad()) {
            for (IDiagramModel dm : model.getDiagramModels()) {
                EditorManager.openDiagramEditor(dm);
            }
        }
        firePropertyChange(this, PROPERTY_MODEL_OPENED, null, model);
    }
    return model;
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) IArchimateModel(com.archimatetool.model.IArchimateModel)

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