Skip to content

Commit

Permalink
Fixes #912 : If Ecore model is null return null for model id and empt…
Browse files Browse the repository at this point in the history
…y list for references. (#916)

Signed-off-by: Simon Pizonka <[email protected]>
  • Loading branch information
Ebolon authored and aedelmann committed May 4, 2018
1 parent 3969a78 commit d271504
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.vorto.core.api.model.model.Model;
import org.eclipse.vorto.core.api.model.model.ModelId;
import org.eclipse.vorto.core.api.model.model.ModelIdFactory;
import org.eclipse.vorto.core.api.model.model.ModelReference;
Expand Down Expand Up @@ -67,7 +68,11 @@ private Image getImage(String urlStr) {

@Override
public ModelId getId() {
return ModelIdFactory.newInstance(getModel());
Model model = getModel();
if(model != null) {
return ModelIdFactory.newInstance(model);
}
return null;
}

@Override
Expand All @@ -77,7 +82,11 @@ public String getDescription() {

public Set<IModelElement> getReferences() {
Set<IModelElement> references = new TreeSet<>();
for (ModelReference modelReference : getModel().getReferences()) {
Model model = getModel();
if(model == null) {
return references;
}
for (ModelReference modelReference : model.getReferences()) {
for(ModelType possibleType : getPossibleReferenceTypes()) {
ModelId modelId = ModelIdFactory.newInstance(possibleType, modelReference);
IModelElement modelElementReference = this.modelProject.getModelElementById(modelId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.vorto.core.api.model.model.ModelId;
import org.eclipse.vorto.core.ui.model.IModelElement;

public class DefaultTreeModelLabelProvider extends ColumnLabelProvider {
Expand Down Expand Up @@ -54,7 +55,9 @@ public Image getImage(Object element) {
@Override
public String getText(Object element) {
IModelElement modelElement = (IModelElement) element;
return modelElement.getId().getName();
ModelId modelId = modelElement.getId();
// return filename if model is invalid
return modelId != null ? modelId.getName() : modelElement.getModelFile().getName();
}

@Override
Expand Down

0 comments on commit d271504

Please sign in to comment.