blob: 8bd25c7122739c1bd1768ccee0daedc8da97d8f0 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2014 Bosch Software Innovations GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v10.html
* The Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Bosch Software Innovations GmbH - Please refer to git log
*
*******************************************************************************/
package org.eclipse.vorto.api.common.project;
import java.io.File;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.vorto.functionblock.FunctionblockModel;
public class IoTModelProject implements IFunctionBlockProject {
private FunctionblockModel model;
private IProject project;
public IoTModelProject(IProject project) {
this.project = project;
model = parseFbModel();
}
public File getFbModelFile() {
File projectDir = project.getLocation().toFile();
String filePath = projectDir.getAbsolutePath() + "/src/models";
File fbModelDir = new File(filePath);
if (fbModelDir.exists() && fbModelDir.isDirectory()) {
for (File file : fbModelDir.listFiles()) {
if (file.getName().endsWith(".fbmodel")) {
return file;
}
}
}
return null;
}
@Override
public FunctionblockModel getFunctionBlockModel() {
return model;
}
private FunctionblockModel parseFbModel() {
File fbModelFile = getFunctionModelFile();
String modelFileUrl = project.getLocationURI() + "/src/models/"
+ fbModelFile.getName();
ResourceSet rs = new ResourceSetImpl();
Resource resource = rs.getResource(URI.createURI(modelFileUrl), true);
return (FunctionblockModel) resource.getContents().get(0);
}
public File getFunctionModelFile() {
return FunctionModelModelFileFinder.getFunctionModelFile(project);
}
public IProject getProject() {
return project;
}
@Override
public String getName() {
return project.getName();
}
@Override
public IFile getFile(String path) {
return project.getFile(path);
}
@Override
public void refresh(IProgressMonitor monitor) throws CoreException {
project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
}