blob: 290e4d4b9e4f906865f14626c6b62a7b5ebdd65d [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.filter;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.visualisation.modelspace.datasource.GraphArc;
/**
* This class contains filters usable after the graph contents have been generated.
* @author Zoltan Ujhelyi
*
*/
public class PostFilter extends ViewerFilter {
private boolean hideContainment = false;
private boolean hideInheritance = false;
private boolean hideInstantiation = false;
/**
* @return the hideContainment
*/
public boolean isHideContainment() {
return hideContainment;
}
/**
* @param hideContainment the hideContainment to set
*/
public void setHideContainment(boolean hideContainment) {
this.hideContainment = hideContainment;
}
/**
* @return the hideInheritance
*/
public boolean isHideInheritance() {
return hideInheritance;
}
/**
* @param hideInheritance the hideInheritance to set
*/
public void setHideInheritance(boolean hideInheritance) {
this.hideInheritance = hideInheritance;
}
/**
* @return the hideInstantiation
*/
public boolean isHideInstantiation() {
return hideInstantiation;
}
/**
* @param hideInstantiation the hideInstantiation to set
*/
public void setHideInstantiation(boolean hideInstantiation) {
this.hideInstantiation = hideInstantiation;
}
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IModelElement){
IModelElement modelElement = (IModelElement) element;
//hide the root element
if (modelElement.getName().equals("root") &&
modelElement.getFullyQualifiedName().equals(""))
return false;
/*XXX this code should hide nodes not connected to other nodes but does not work because of a Zest bug
* GraphViewer view = (GraphViewer) viewer;
try {
//XXX this try block is needed because findGraphItem is buggy; see Bug 237489 in Zest Bugzilla
GraphItem findGraphItem = view.findGraphItem(element);
GraphNode node = (GraphNode)findGraphItem;
if (node.getSourceConnections().size()+node.getTargetConnections().size()==0) return true;
}catch(ArrayIndexOutOfBoundsException e) {}*/
}
if (element instanceof GraphArc) {
//hide the containment relations
if (hideContainment) {
String name = ((GraphArc) element).getName();
if (name != null && name.equals("contains")) return false;
}
if (hideInheritance) {
String name = ((GraphArc) element).getName();
if (name != null && name.equals("supertypeOf")) return false;
}
if (hideInstantiation) {
String name = ((GraphArc) element).getName();
if (name != null && name.equals("instanceOf")) return false;
}
}
return true;
}
}