package org.gvt.action;
import org.gvt.util.PoIOptionsPack;
import org.gvt.ChisioMain;
import org.gvt.inspector.PoIQueryParamWithEntitiesDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.dialogs.MessageDialog;
import org.patika.mada.graph.Node;
import org.patika.mada.graph.GraphObject;
import org.patika.mada.algorithm.LocalPoIQuery;
import org.biopax.paxtools.model.level2.physicalEntity;
import org.biopax.paxtools.model.Model;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
/**
* This class creates the action for opening query properties window.
*
* @author Merve Cakir
*/
public class LocalPoIQueryAction extends AbstractLocalQueryAction
{
ChisioMain main;
/**
* Dialog options are stored, in order to use next time dialog is opened.
*/
PoIOptionsPack options;
/**
* Constructor
*/
public LocalPoIQueryAction(ChisioMain main)
{
super(main, "Local PoI Query");
this.setImageDescriptor(
ImageDescriptor.createFromFile(ChisioMain.class,
"icon/layout-inspector.png"));
setToolTipText(getText());
options = new PoIOptionsPack();
this.main = main;
}
public void run()
{
LocalPoI();
}
public void LocalPoI()
{
Model owlModel = this.main.getOwlModel();
if (owlModel == null)
{
MessageDialog.openError(main.getShell(), "Error!",
"Load or query a BioPAX model first!");
return;
}
//Source and target node sets
Set<Node> sourceNodes = new HashSet<Node>();
Set<Node> targetNodes = new HashSet<Node>();
//open dialog
PoIQueryParamWithEntitiesDialog dialog = new PoIQueryParamWithEntitiesDialog(main);
options = dialog.open(options);
if ( !options.isCancel() )
{
options.setCancel(true);
}
else
{
return;
}
//Get added source entities.
ArrayList<physicalEntity> sourceAddedEntities =
dialog.getSourceAddedEntities();
//Get the states of added entities.
Set<GraphObject> sourceSet =
main.getRootGraph().getRelatedStates(sourceAddedEntities);
//Replace any complex member with its corresponding complex.
main.getRootGraph().replaceComplexMembersWithComplexes(sourceSet);
for (GraphObject go : sourceSet)
{
if (go instanceof Node)
{
sourceNodes.add((Node) go);
}
}
//Get added target entities.
ArrayList<physicalEntity> targetAddedEntities =
dialog.getTargetAddedEntities();
//Get the states of added entities.
Set<GraphObject> targetSet =
main.getRootGraph().getRelatedStates(targetAddedEntities);
//Replace any complex member with its corresponding complex.
main.getRootGraph().replaceComplexMembersWithComplexes(targetSet);
for (GraphObject go : targetSet)
{
if (go instanceof Node)
{
targetNodes.add((Node) go);
}
}
LocalPoIQuery poi = null;
Set<GraphObject> result = new HashSet<GraphObject>();
//if length limit is selected and strict is unchecked.
if (options.getLimitType() && !options.isStrict())
{
poi = new LocalPoIQuery(sourceNodes, targetNodes,
true, options.getLengthLimit(), false);
}
//if length limit is selected and strict is checked.
else if (options.getLimitType() && options.isStrict())
{
poi = new LocalPoIQuery(sourceNodes, targetNodes,
true, options.getLengthLimit(), true);
}
//if shortest+k is selected and strict is unchecked.
else if (!options.getLimitType() && !options.isStrict())
{
poi = new LocalPoIQuery(sourceNodes, targetNodes,
false, options.getShortestPlusKLimit(), false);
}
//if shortest+k is selected and strict is checked.
else
{
poi = new LocalPoIQuery(sourceNodes, targetNodes,
false, options.getShortestPlusKLimit(), true);
}
//Add result of PoI to the result set
result.addAll(poi.run());
//if no result can be found, open dialog to warn.
if (result.size() == 0)
{
MessageDialog.openWarning(main.getShell(),
"No result!",
"No path can be found with specified parameters");
}
else
{
viewAndHighlightResult(result,
options.isCurrentView(),
"Paths of Interest");
}
}
}