blob: afe2c02b61d773774feb2b3227b1305af1649235 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009 Zoltan Ujhelyi and Daniel Varro.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Zoltan Ujhelyi - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.visualisation.modelspace.datasource;
import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.viatra2.core.IEntity;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IModelManager;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.zest.core.viewers.IGraphEntityRelationshipContentProvider;
/**
* @author Zoltan Ujhelyi
*/
public class ReducedModelSpaceProvider extends AbstractModelSpaceProvider
implements IGraphEntityRelationshipContentProvider {
/*
* (non-Javadoc)
*
* @see
* org.eclipse.zest.core.viewers.IGraphEntityRelationshipContentProvider
* #getRelationships(java.lang.Object, java.lang.Object)
*/
public Object[] getRelationships(Object source, Object dest) {
if (modelManager == null) return new Object[0];
IEntity src = (IEntity) source;
IEntity dst = (IEntity) dest;
ArrayList<Object> relations = new ArrayList<Object>();
Collection<IRelation> relationsFrom = new ArrayList<IRelation>(src.getRelationsFrom());
relationsFrom.retainAll(dst.getRelationsTo());
for (IRelation relation : relationsFrom) {
if (!filter.isFiltered(relation)){
relations.add(relation);
}
}
if (dst.compareTo(src) != 0 && src.isDirectSubtypeOf(dst)) {
GraphArc arc = new GraphArc();
arc.setEntity1(src);
arc.setEntity2(dst);
arc.setMultiplicity(1);
arc.setName("supertypeOf");
relations.add(arc);
}
if (dst.getContents().contains(src)) {
GraphArc arc = new GraphArc();
arc.setEntity1(src);
arc.setEntity2(dst);
arc.setMultiplicity(1);
arc.setName("contains");
relations.add(arc);
}
if (src.isInstanceOf(dst)) {
GraphArc arc = new GraphArc();
arc.setEntity1(src);
arc.setEntity2(dst);
arc.setMultiplicity(1);
arc.setName("typeOf");
relations.add(arc);
}
return relations.toArray();
}
/**
* @param modelManager
* the modelManager to set
*/
public void setModelManager(IModelManager modelManager) {
this.modelManager = modelManager;
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java
* .lang.Object)
*/
public Object[] getElements(Object inputElement) {
if (modelManager != null) {
ArrayList<IModelElement> elements = new ArrayList<IModelElement>();
for (IModelElement element : modelManager.getEntities()) {
if (!filter.isFiltered(element)) elements.add(element);
}
return elements.toArray();
} else
return new ArrayList<Object>().toArray();
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface
* .viewers.Viewer, java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
}