Search in sources :

Example 1 with ModelType

use of org.eclipse.vorto.core.api.model.model.ModelType in project vorto by eclipse.

the class VortoModelProject method addModelElement.

@Override
public IModelElement addModelElement(ModelId modelId, InputStream inputStream) {
    try {
        final ModelType modelType = modelId.getModelType();
        IFolder folder = getFolderByType(modelId.getModelType());
        IFile file = folder.getFile(modelId.getFileName());
        if (file.exists()) {
            file.delete(true, new NullProgressMonitor());
        }
        file.create(inputStream, true, new NullProgressMonitor());
        if (modelType == ModelType.InformationModel) {
            return new InformationModelElement(this, file, modelParser);
        } else if (modelType == ModelType.Functionblock) {
            return new FunctionblockModelElement(this, file, modelParser);
        } else if (modelType == ModelType.Datatype) {
            return new DatatypeModelElement(this, file, modelParser);
        } else if (modelType == ModelType.Mapping) {
            return new MappingModelElement(this, file, modelParser);
        } else {
            throw new UnsupportedOperationException("Modeltype is not supported");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with ModelType

use of org.eclipse.vorto.core.api.model.model.ModelType in project vorto by eclipse.

the class AbstractModelElement method getReferences.

public Set<IModelElement> getReferences() {
    Set<IModelElement> references = new TreeSet<>();
    for (ModelReference modelReference : getModel().getReferences()) {
        for (ModelType possibleType : getPossibleReferenceTypes()) {
            ModelId modelId = ModelIdFactory.newInstance(possibleType, modelReference);
            IModelElement modelElementReference = this.modelProject.getModelElementById(modelId);
            if (modelElementReference != null) {
                references.add(modelElementReference);
                break;
            }
        }
    }
    return references;
}
Also used : TreeSet(java.util.TreeSet) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) ModelReference(org.eclipse.vorto.core.api.model.model.ModelReference)

Aggregations

ModelType (org.eclipse.vorto.core.api.model.model.ModelType)2 TreeSet (java.util.TreeSet)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)1 ModelReference (org.eclipse.vorto.core.api.model.model.ModelReference)1